aboutsummaryrefslogtreecommitdiffstats
path: root/frontends/verilog
ModeNameSize
-rw-r--r--.gitignore83logstatsplain
-rw-r--r--Makefile.inc891logstatsplain
-rw-r--r--const2ast.cc7426logstatsplain
-rw-r--r--preproc.cc13467logstatsplain
-rw-r--r--verilog_frontend.cc19600logstatsplain
-rw-r--r--verilog_frontend.h2994logstatsplain
-rw-r--r--verilog_lexer.l14132logstatsplain
-rw-r--r--verilog_parser.y69285logstatsplain
f='#n86'>86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
/*
 * Copyright (C) 2015 Vincent Breitmoser <v.breitmoser@mugenguild.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.sufficientlysecure.keychain.ui.adapter;


import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

import android.content.Context;
import android.database.Cursor;
import android.graphics.PorterDuff;
import android.support.v4.widget.CursorAdapter;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKey;
import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing;
import org.sufficientlysecure.keychain.pgp.KeyRing;
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
import org.sufficientlysecure.keychain.ui.util.Highlighter;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;

public class KeyAdapter extends CursorAdapter {

    protected String mQuery;
    protected LayoutInflater mInflater;

    // These are the rows that we will retrieve.
    public static final String[] PROJECTION = new String[]{
            KeyRings._ID,
            KeyRings.MASTER_KEY_ID,
            KeyRings.USER_ID,
            KeyRings.IS_REVOKED,
            KeyRings.IS_EXPIRED,
            KeyRings.VERIFIED,
            KeyRings.HAS_ANY_SECRET,
            KeyRings.HAS_DUPLICATE_USER_ID,
            KeyRings.HAS_ENCRYPT,
            KeyRings.FINGERPRINT,
            KeyRings.CREATION,
    };

    public static final int INDEX_MASTER_KEY_ID = 1;
    public static final int INDEX_USER_ID = 2;
    public static final int INDEX_IS_REVOKED = 3;
    public static final int INDEX_IS_EXPIRED = 4;
    public static final int INDEX_VERIFIED = 5;
    public static final int INDEX_HAS_ANY_SECRET = 6;
    public static final int INDEX_HAS_DUPLICATE_USER_ID = 7;
    public static final int INDEX_HAS_ENCRYPT = 8;
    public static final int INDEX_FINGERPRINT = 9;
    public static final int INDEX_CREATION = 10;

    public KeyAdapter(Context context, Cursor c, int flags) {
        super(context, c, flags);

        mInflater = LayoutInflater.from(context);
    }

    public void setSearchQuery(String query) {
        mQuery = query;
    }

    public static class KeyItemViewHolder {
        public Long mMasterKeyId;
        public TextView mMainUserId;
        public TextView mMainUserIdRest;
        public ImageView mStatus;
        public View mSlinger;
        public ImageButton mSlingerButton;

        public KeyItemViewHolder(View view) {
            mMainUserId = (TextView) view.findViewById(R.id.key_list_item_name);
            mMainUserIdRest = (TextView) view.findViewById(R.id.key_list_item_email);
            mStatus = (ImageView) view.findViewById(R.id.key_list_item_status_icon);
            mSlinger = view.findViewById(R.id.key_list_item_slinger_view);
            mSlingerButton = (ImageButton) view.findViewById(R.id.key_list_item_slinger_button);
        }

        public void setData(Context context, Cursor cursor, Highlighter highlighter) {

            { // set name and stuff, common to both key types
                String userId = cursor.getString(INDEX_USER_ID);
                KeyRing.UserId userIdSplit = KeyRing.splitUserId(userId);
                if (userIdSplit.name != null) {
                    mMainUserId.setText(highlighter.highlight(userIdSplit.name));
                } else {
                    mMainUserId.setText(R.string.user_id_no_name);
                }
                if (userIdSplit.email != null) {
                    mMainUserIdRest.setText(highlighter.highlight(userIdSplit.email));
                    mMainUserIdRest.setVisibility(View.VISIBLE);
                } else {
                    mMainUserIdRest.setVisibility(View.GONE);
                }
            }

            { // set edit button and status, specific by key type

                long masterKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
                boolean isSecret = cursor.getInt(INDEX_HAS_ANY_SECRET) != 0;
                boolean isRevoked = cursor.getInt(INDEX_IS_REVOKED) > 0;
                boolean isExpired = cursor.getInt(INDEX_IS_EXPIRED) != 0;
                boolean isVerified = cursor.getInt(INDEX_VERIFIED) > 0;
                // boolean hasDuplicate = cursor.getInt(INDEX_HAS_DUPLICATE_USER_ID) == 1;

                mMasterKeyId = masterKeyId;

                // Note: order is important!
                if (isRevoked) {
                    KeyFormattingUtils
                            .setStatusImage(context, mStatus, null, State.REVOKED, R.color.bg_gray);
                    mStatus.setVisibility(View.VISIBLE);
                    mSlinger.setVisibility(View.GONE);
                    mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
                    mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
                } else if (isExpired) {
                    KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.bg_gray);
                    mStatus.setVisibility(View.VISIBLE);
                    mSlinger.setVisibility(View.GONE);
                    mMainUserId.setTextColor(context.getResources().getColor(R.color.bg_gray));
                    mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.bg_gray));
                } else if (isSecret) {
                    mStatus.setVisibility(View.GONE);
                    if (mSlingerButton.hasOnClickListeners()) {
                        mSlinger.setVisibility(View.VISIBLE);
                    }
                    mMainUserId.setTextColor(context.getResources().getColor(R.color.black));
                    mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
                } else {
                    // this is a public key - show if it's verified
                    if (isVerified) {
                        KeyFormattingUtils.setStatusImage(context, mStatus, State.VERIFIED);
                        mStatus.setVisibility(View.VISIBLE);
                    } else {
                        KeyFormattingUtils.setStatusImage(context, mStatus, State.UNVERIFIED);
                        mStatus.setVisibility(View.VISIBLE);
                    }
                    mSlinger.setVisibility(View.GONE);
                    mMainUserId.setTextColor(context.getResources().getColor(R.color.black));
                    mMainUserIdRest.setTextColor(context.getResources().getColor(R.color.black));
                }
            }

        }

    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        View view = mInflater.inflate(R.layout.key_list_item, parent, false);
        KeyItemViewHolder holder = new KeyItemViewHolder(view);
        view.setTag(holder);
        holder.mSlingerButton.setColorFilter(context.getResources().getColor(R.color.tertiary_text_light),
                PorterDuff.Mode.SRC_IN);
        return view;
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        Highlighter highlighter = new Highlighter(context, mQuery);
        KeyItemViewHolder h = (KeyItemViewHolder) view.getTag();
        h.setData(context, cursor, highlighter);
    }

    public boolean isSecretAvailable(int id) {
        if (!mCursor.moveToPosition(id)) {
            throw new IllegalStateException("couldn't move cursor to position " + id);
        }

        return mCursor.getInt(INDEX_HAS_ANY_SECRET) != 0;
    }

    public long getMasterKeyId(int id) {
        if (!mCursor.moveToPosition(id)) {
            throw new IllegalStateException("couldn't move cursor to position " + id);
        }

        return mCursor.getLong(INDEX_MASTER_KEY_ID);
    }

    @Override
    public KeyItem getItem(int position) {
        Cursor c = getCursor();
        if (c.isClosed() || !c.moveToPosition(position)) {
            return null;
        }
        return new KeyItem(c);
    }

    @Override
    public long getItemId(int position) {
        // prevent a crash on rapid cursor changes
        if (getCursor().isClosed()) {
            return 0L;
        }
        return super.getItemId(position);
    }

    public static class KeyItem {

        public final String mUserIdFull;
        public final KeyRing.UserId mUserId;
        public final long mKeyId;
        public final boolean mHasDuplicate;
        public final Date mCreation;
        public final String mFingerprint;

        private KeyItem(Cursor cursor) {
            String userId = cursor.getString(INDEX_USER_ID);
            mUserId = KeyRing.splitUserId(userId);
            mUserIdFull = userId;
            mKeyId = cursor.getLong(INDEX_MASTER_KEY_ID);
            mHasDuplicate = cursor.getLong(INDEX_HAS_DUPLICATE_USER_ID) > 0;
            mCreation = new Date(cursor.getLong(INDEX_CREATION) * 1000);
            mFingerprint = KeyFormattingUtils.convertFingerprintToHex(
                    cursor.getBlob(INDEX_FINGERPRINT));
        }

        public KeyItem(CanonicalizedPublicKeyRing ring) {
            CanonicalizedPublicKey key = ring.getPublicKey();
            String userId = key.getPrimaryUserIdWithFallback();
            mUserId = KeyRing.splitUserId(userId);
            mUserIdFull = userId;
            mKeyId = ring.getMasterKeyId();
            mHasDuplicate = false;
            mCreation = key.getCreationTime();
            mFingerprint = KeyFormattingUtils.convertFingerprintToHex(
                    ring.getFingerprint());
        }

        public String getReadableName() {
            if (mUserId.name != null) {
                return mUserId.name;
            } else {
                return mUserId.email;
            }
        }

        public boolean hasDuplicate() {
            return mHasDuplicate;
        }

        public String getCreationDate(Context context) {
            Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
            creationCal.setTime(mCreation);
            // convert from UTC to time zone of device
            creationCal.setTimeZone(TimeZone.getDefault());

            return context.getString(R.string.label_creation) + ": "
                    + DateFormat.getDateFormat(context).format(creationCal.getTime());
        }

    }

}