diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results')
4 files changed, 324 insertions, 10 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java new file mode 100644 index 000000000..49bc613bd --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/CertifyResult.java @@ -0,0 +1,151 @@ +/* + * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> + * Copyright (C) 2014 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.service.results; + +import android.app.Activity; +import android.content.Intent; +import android.os.Parcel; +import android.os.Parcelable; +import android.view.View; + +import com.github.johnpersano.supertoasts.SuperCardToast; +import com.github.johnpersano.supertoasts.SuperToast; +import com.github.johnpersano.supertoasts.SuperToast.Duration; +import com.github.johnpersano.supertoasts.util.OnClickWrapper; +import com.github.johnpersano.supertoasts.util.Style; + +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.LogDisplayActivity; +import org.sufficientlysecure.keychain.ui.LogDisplayFragment; + +public class CertifyResult extends OperationResult { + + int mCertifyOk, mCertifyError; + + public CertifyResult(int result, OperationLog log) { + super(result, log); + } + + public CertifyResult(int result, OperationLog log, int certifyOk, int certifyError) { + this(result, log); + mCertifyOk = certifyOk; + mCertifyError = certifyError; + } + + /** Construct from a parcel - trivial because we have no extra data. */ + public CertifyResult(Parcel source) { + super(source); + mCertifyOk = source.readInt(); + mCertifyError = source.readInt(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + dest.writeInt(mCertifyOk); + dest.writeInt(mCertifyError); + } + + public static Creator<CertifyResult> CREATOR = new Creator<CertifyResult>() { + public CertifyResult createFromParcel(final Parcel source) { + return new CertifyResult(source); + } + + public CertifyResult[] newArray(final int size) { + return new CertifyResult[size]; + } + }; + + public SuperCardToast createNotify(final Activity activity) { + + int resultType = getResult(); + + String str; + int duration, color; + + // Not an overall failure + if ((resultType & OperationResult.RESULT_ERROR) == 0) { + String withWarnings; + + duration = Duration.EXTRA_LONG; + color = Style.GREEN; + withWarnings = ""; + + // Any warnings? + if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_warnings); + } + if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { + duration = 0; + color = Style.ORANGE; + withWarnings += activity.getString(R.string.with_cancelled); + } + + // New and updated keys + str = activity.getResources().getQuantityString( + R.plurals.certify_keys_ok, mCertifyOk, mCertifyOk, withWarnings); + if (mCertifyError > 0) { + // definitely switch to warning-style message in this case! + duration = 0; + color = Style.RED; + str += " " + activity.getResources().getQuantityString( + R.plurals.certify_keys_with_errors, mCertifyError, mCertifyError); + } + + } else { + duration = 0; + color = Style.RED; + str = activity.getResources().getQuantityString(R.plurals.certify_error, + mCertifyError, mCertifyError); + } + + boolean button = getLog() != null && !getLog().isEmpty(); + SuperCardToast toast = new SuperCardToast(activity, + button ? SuperToast.Type.BUTTON : SuperToast.Type.STANDARD, + Style.getStyle(color, SuperToast.Animations.POPUP)); + toast.setText(str); + toast.setDuration(duration); + toast.setIndeterminate(duration == 0); + toast.setSwipeToDismiss(true); + // If we have a log and it's non-empty, show a View Log button + if (button) { + toast.setButtonIcon(R.drawable.ic_action_view_as_list, + activity.getResources().getString(R.string.view_log)); + toast.setButtonTextColor(activity.getResources().getColor(R.color.black)); + toast.setTextColor(activity.getResources().getColor(R.color.black)); + toast.setOnClickWrapper(new OnClickWrapper("supercardtoast", + new SuperToast.OnClickListener() { + @Override + public void onClick(View view, Parcelable token) { + Intent intent = new Intent( + activity, LogDisplayActivity.class); + intent.putExtra(LogDisplayFragment.EXTRA_RESULT, CertifyResult.this); + activity.startActivity(intent); + } + } + )); + } + + return toast; + + } + +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java new file mode 100644 index 000000000..e76d1bd41 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/GetKeyResult.java @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2014 Dominik Schürmann <dominik@dominikschuermann.de> + * Copyright (C) 2014 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.service.results; + +import android.os.Parcel; + +public class GetKeyResult extends OperationResult { + + public int mNonPgpPartsCount; + + public int getNonPgpPartsCount() { + return mNonPgpPartsCount; + } + + public void setNonPgpPartsCount(int nonPgpPartsCount) { + mNonPgpPartsCount = nonPgpPartsCount; + } + + public GetKeyResult(int result, OperationLog log) { + super(result, log); + } + + public static final int RESULT_ERROR_NO_VALID_KEYS = RESULT_ERROR + 8; + public static final int RESULT_ERROR_NO_PGP_PARTS = RESULT_ERROR + 16; + public static final int RESULT_ERROR_QUERY_TOO_SHORT = RESULT_ERROR + 32; + public static final int RESULT_ERROR_TOO_MANY_RESPONSES = RESULT_ERROR + 64; + public static final int RESULT_ERROR_TOO_SHORT_OR_TOO_MANY_RESPONSES = RESULT_ERROR + 128; + public static final int RESULT_ERROR_QUERY_FAILED = RESULT_ERROR + 256; + + public GetKeyResult(Parcel source) { + super(source); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + super.writeToParcel(dest, flags); + } + + public static Creator<GetKeyResult> CREATOR = new Creator<GetKeyResult>() { + public GetKeyResult createFromParcel(final Parcel source) { + return new GetKeyResult(source); + } + + public GetKeyResult[] newArray(final int size) { + return new GetKeyResult[size]; + } + }; +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java index 188162aec..b54dcc5d6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/ImportKeyResult.java @@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.ui.LogDisplayFragment; public class ImportKeyResult extends OperationResult { public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret; + public final long[] mImportedMasterKeyIds; // At least one new key public static final int RESULT_OK_NEWKEYS = 8; @@ -69,21 +70,28 @@ public class ImportKeyResult extends OperationResult { return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING; } + public long[] getImportedMasterKeyIds() { + return mImportedMasterKeyIds; + } + public ImportKeyResult(Parcel source) { super(source); mNewKeys = source.readInt(); mUpdatedKeys = source.readInt(); mBadKeys = source.readInt(); mSecret = source.readInt(); + mImportedMasterKeyIds = source.createLongArray(); } public ImportKeyResult(int result, OperationLog log, - int newKeys, int updatedKeys, int badKeys, int secret) { + int newKeys, int updatedKeys, int badKeys, int secret, + long[] importedMasterKeyIds) { super(result, log); mNewKeys = newKeys; mUpdatedKeys = updatedKeys; mBadKeys = badKeys; mSecret = secret; + mImportedMasterKeyIds = importedMasterKeyIds; } @Override @@ -93,6 +101,7 @@ public class ImportKeyResult extends OperationResult { dest.writeInt(mUpdatedKeys); dest.writeInt(mBadKeys); dest.writeInt(mSecret); + dest.writeLongArray(mImportedMasterKeyIds); } public static Creator<ImportKeyResult> CREATOR = new Creator<ImportKeyResult>() { @@ -124,12 +133,12 @@ public class ImportKeyResult extends OperationResult { if ((resultType & ImportKeyResult.RESULT_WARNINGS) > 0) { duration = 0; color = Style.ORANGE; - withWarnings += activity.getString(R.string.import_with_warnings); + withWarnings += activity.getString(R.string.with_warnings); } if ((resultType & ImportKeyResult.RESULT_CANCELLED) > 0) { duration = 0; color = Style.ORANGE; - withWarnings += activity.getString(R.string.import_with_cancelled); + withWarnings += activity.getString(R.string.with_cancelled); } // New and updated keys @@ -162,8 +171,8 @@ public class ImportKeyResult extends OperationResult { color = Style.RED; if (isFailNothing()) { str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0 - ? R.string.import_error_nothing_cancelled - : R.string.import_error_nothing); + ? R.string.import_error_nothing_cancelled + : R.string.import_error_nothing); } else { str = activity.getResources().getQuantityString(R.plurals.import_error, mBadKeys); } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java index 29924ee5d..e3f2c1cc5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/service/results/OperationResult.java @@ -93,6 +93,11 @@ public abstract class OperationResult implements Parcelable { } public OperationLog getLog() { + // If there is only a single entry, and it's a compound one, return that log + if (mLog.isSingleCompound()) { + return ((SubLogEntryParcel) mLog.getFirst()).getSubResult().getLog(); + } + // Otherwse, return our regular log return mLog; } @@ -106,7 +111,7 @@ public abstract class OperationResult implements Parcelable { mType = type; mParameters = parameters; mIndent = indent; - Log.v(Constants.TAG, "log: " + this.toString()); + Log.v(Constants.TAG, "log: " + this); } public LogEntryParcel(Parcel source) { @@ -122,6 +127,7 @@ public abstract class OperationResult implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(0); dest.writeInt(mType.ordinal()); dest.writeSerializable(mParameters); dest.writeInt(mIndent); @@ -129,7 +135,12 @@ public abstract class OperationResult implements Parcelable { public static final Creator<LogEntryParcel> CREATOR = new Creator<LogEntryParcel>() { public LogEntryParcel createFromParcel(final Parcel source) { - return new LogEntryParcel(source); + // Actually create LogEntryParcel or SubLogEntryParcel depending on type indicator + if (source.readInt() == 0) { + return new LogEntryParcel(source); + } else { + return new SubLogEntryParcel(source); + } } public LogEntryParcel[] newArray(final int size) { @@ -139,7 +150,7 @@ public abstract class OperationResult implements Parcelable { @Override public String toString() { - return "LogEntryParcel{" + + return getClass().getSimpleName() + "{" + "mLevel=" + mType.mLevel + ", mType=" + mType + ", mParameters=" + Arrays.toString(mParameters) + @@ -148,6 +159,42 @@ public abstract class OperationResult implements Parcelable { } } + public static class SubLogEntryParcel extends LogEntryParcel { + + OperationResult mSubResult; + + public SubLogEntryParcel(OperationResult subResult, LogType type, int indent, Object... parameters) { + super(type, indent, parameters); + mSubResult = subResult; + + Log.v(Constants.TAG, "log: " + this); + } + + public SubLogEntryParcel(Parcel source) { + super(source); + mSubResult = source.readParcelable(SubLogEntryParcel.class.getClassLoader()); + } + + public OperationResult getSubResult() { + return mSubResult; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeInt(1); + dest.writeInt(mType.ordinal()); + dest.writeSerializable(mParameters); + dest.writeInt(mIndent); + dest.writeParcelable(mSubResult, 0); + } + + } + public SuperCardToast createNotify(final Activity activity) { int color; @@ -517,13 +564,36 @@ public abstract class OperationResult implements Parcelable { MSG_SE_SIGCRYPTING (LogLevel.DEBUG, R.string.msg_se_sigcrypting), MSG_SE_SYMMETRIC (LogLevel.INFO, R.string.msg_se_symmetric), - MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success), + MSG_CRT_CERTIFYING (LogLevel.DEBUG, R.string.msg_crt_certifying), + MSG_CRT_CERTIFY_ALL (LogLevel.DEBUG, R.string.msg_crt_certify_all), + MSG_CRT_CERTIFY_SOME (LogLevel.DEBUG, R.plurals.msg_crt_certify_some), + MSG_CRT_ERROR_MASTER_NOT_FOUND (LogLevel.ERROR, R.string.msg_crt_error_master_not_found), + MSG_CRT_ERROR_NOTHING (LogLevel.ERROR, R.string.msg_crt_error_nothing), + MSG_CRT_ERROR_UNLOCK (LogLevel.ERROR, R.string.msg_crt_error_unlock), + MSG_CRT (LogLevel.START, R.string.msg_crt), + MSG_CRT_MASTER_FETCH (LogLevel.DEBUG, R.string.msg_crt_master_fetch), + MSG_CRT_SAVE (LogLevel.DEBUG, R.string.msg_crt_save), + MSG_CRT_SAVING (LogLevel.DEBUG, R.string.msg_crt_saving), MSG_CRT_SUCCESS (LogLevel.OK, R.string.msg_crt_success), + MSG_CRT_UNLOCK (LogLevel.DEBUG, R.string.msg_crt_unlock), + MSG_CRT_WARN_NOT_FOUND (LogLevel.WARN, R.string.msg_crt_warn_not_found), + MSG_CRT_WARN_CERT_FAILED (LogLevel.WARN, R.string.msg_crt_warn_cert_failed), + MSG_CRT_WARN_SAVE_FAILED (LogLevel.WARN, R.string.msg_crt_warn_save_failed), + + MSG_CRT_UPLOAD_SUCCESS (LogLevel.OK, R.string.msg_crt_upload_success), MSG_ACC_SAVED (LogLevel.INFO, R.string.api_settings_save_msg), - MSG_NO_VALID_ENC (LogLevel.ERROR, R.string.error_invalid_data) + MSG_NO_VALID_ENC (LogLevel.ERROR, R.string.error_invalid_data), + // get key + MSG_GET_SUCCESS(LogLevel.OK, R.string.msg_download_success), + MSG_GET_NO_VALID_KEYS(LogLevel.ERROR, R.string.msg_download_no_valid_keys), + MSG_GET_NO_PGP_PARTS(LogLevel.ERROR, R.string.msg_download_no_pgp_parts), + MSG_GET_QUERY_TOO_SHORT(LogLevel.ERROR, R.string.msg_download_query_too_short), + MSG_GET_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_too_many_responses), + MSG_GET_QUERY_TOO_SHORT_OR_TOO_MANY_RESPONSES(LogLevel.ERROR, R.string.msg_download_query_too_short_or_too_many_responses), + MSG_GET_QUERY_FAILED(LogLevel.ERROR, R.string.msg_download_query_failed) ; public final int mMsgId; @@ -574,6 +644,19 @@ public abstract class OperationResult implements Parcelable { mParcels.add(new OperationResult.LogEntryParcel(type, indent, (Object[]) null)); } + public void add(OperationResult subResult, int indent) { + OperationLog subLog = subResult.getLog(); + mParcels.add(new SubLogEntryParcel(subResult, subLog.getFirst().mType, indent, subLog.getFirst().mParameters)); + } + + boolean isSingleCompound() { + return mParcels.size() == 1 && getFirst() instanceof SubLogEntryParcel; + } + + public void clear() { + mParcels.clear(); + } + public boolean containsType(LogType type) { for(LogEntryParcel entry : new IterableIterator<LogEntryParcel>(mParcels.iterator())) { if (entry.mType == type) { @@ -604,6 +687,13 @@ public abstract class OperationResult implements Parcelable { return mParcels.isEmpty(); } + public LogEntryParcel getFirst() { + if (mParcels.isEmpty()) { + return null; + } + return mParcels.get(0); + } + public LogEntryParcel getLast() { if (mParcels.isEmpty()) { return null; |