mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-23 17:22:16 -05:00
Merge branch 'development' of https://github.com/adithyaphilip/open-keychain into adithyaphilip-development
Conflicts: OpenKeychain/src/main/res/values/strings.xml
This commit is contained in:
commit
bb2d80bfc8
@ -762,6 +762,13 @@ public abstract class OperationResult implements Parcelable {
|
||||
MSG_DEL_CONSOLIDATE (LogLevel.DEBUG, R.string.msg_del_consolidate),
|
||||
MSG_DEL_OK (LogLevel.OK, R.plurals.msg_del_ok),
|
||||
MSG_DEL_FAIL (LogLevel.WARN, R.plurals.msg_del_fail),
|
||||
|
||||
//export log
|
||||
MSG_EXPORT_LOG(LogLevel.START,R.string.msg_export_log_start),
|
||||
MSG_EXPORT_LOG_EXPORT_ERROR_NO_FILE(LogLevel.ERROR,R.string.msg_export_log_error_no_file),
|
||||
MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN(LogLevel.ERROR,R.string.msg_export_log_error_fopen),
|
||||
MSG_EXPORT_LOG_EXPORT_ERROR_WRITING(LogLevel.ERROR,R.string.msg_export_log_error_writing),
|
||||
MSG_EXPORT_LOG_EXPORT_SUCCESS (LogLevel.OK, R.string.msg_export_log_success),
|
||||
;
|
||||
|
||||
public final int mMsgId;
|
||||
|
@ -22,9 +22,13 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
@ -33,11 +37,19 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.LogLevel;
|
||||
import org.sufficientlysecure.keychain.operations.results.OperationResult.SubLogEntryParcel;
|
||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||
import org.sufficientlysecure.keychain.util.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class LogDisplayFragment extends ListFragment implements OnItemClickListener {
|
||||
|
||||
@ -46,6 +58,12 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
||||
OperationResult mResult;
|
||||
|
||||
public static final String EXTRA_RESULT = "log";
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
@ -70,6 +88,183 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
||||
|
||||
getListView().setFastScrollEnabled(true);
|
||||
getListView().setDividerHeight(0);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.log_display, menu);
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.menu_log_display_export_log:
|
||||
exportLog();
|
||||
break;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void exportLog() {
|
||||
|
||||
showExportLogDialog(new File(Constants.Path.APP_DIR, "export.log"));
|
||||
}
|
||||
|
||||
private void writeToLogFile(final OperationResult.OperationLog operationLog, final File f) {
|
||||
OperationResult.OperationLog currLog = new OperationResult.OperationLog();
|
||||
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG, 0);
|
||||
|
||||
boolean error = false;
|
||||
|
||||
PrintWriter pw = null;
|
||||
try {
|
||||
pw = new PrintWriter(f);
|
||||
pw.print(getPrintableOperationLog(operationLog, ""));
|
||||
if (pw.checkError()) {//IOException
|
||||
Log.e(Constants.TAG, "Log Export I/O Exception " + f.getAbsolutePath());
|
||||
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_WRITING, 1);
|
||||
error = true;
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Constants.TAG, "File not found for exporting log " + f.getAbsolutePath());
|
||||
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_FOPEN, 1);
|
||||
error = true;
|
||||
}
|
||||
if (pw != null) {
|
||||
pw.close();
|
||||
if (!error && pw.checkError()) {//check if it is only pw.close() which generated error
|
||||
currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_ERROR_WRITING, 1);
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error) currLog.add(OperationResult.LogType.MSG_EXPORT_LOG_EXPORT_SUCCESS, 1);
|
||||
|
||||
int opResultCode = error ? OperationResult.RESULT_ERROR : OperationResult.RESULT_OK;
|
||||
OperationResult opResult = new LogExportResult(opResultCode, currLog);
|
||||
opResult.createNotify(getActivity()).show();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an indented String of an entire OperationLog
|
||||
*
|
||||
* @param opLog log to be converted to indented, printable format
|
||||
* @param basePadding padding to add at the start of all log entries, made for use with SubLogs
|
||||
* @return printable, indented version of passed operationLog
|
||||
*/
|
||||
private String getPrintableOperationLog(OperationResult.OperationLog opLog, String basePadding) {
|
||||
String log = "";
|
||||
for (Iterator<LogEntryParcel> logIterator = opLog.iterator(); logIterator.hasNext(); ) {
|
||||
log += getPrintableLogEntry(logIterator.next(), basePadding) + "\n";
|
||||
}
|
||||
log = log.substring(0, log.length() - 1);//gets rid of extra new line
|
||||
return log;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an indented String of a LogEntryParcel including any sub-logs it may contain
|
||||
*
|
||||
* @param entryParcel log entryParcel whose String representation is to be obtained
|
||||
* @return indented version of passed log entryParcel in a readable format
|
||||
*/
|
||||
private String getPrintableLogEntry(OperationResult.LogEntryParcel entryParcel,
|
||||
String basePadding) {
|
||||
|
||||
final String indent = " ";//4 spaces = 1 Indent level
|
||||
|
||||
String padding = basePadding;
|
||||
for (int i = 0; i < entryParcel.mIndent; i++) {
|
||||
padding += indent;
|
||||
}
|
||||
String logText = padding;
|
||||
|
||||
switch (entryParcel.mType.mLevel) {
|
||||
case DEBUG:
|
||||
logText += "[DEBUG]";
|
||||
break;
|
||||
case INFO:
|
||||
logText += "[INFO]";
|
||||
break;
|
||||
case WARN:
|
||||
logText += "[WARN]";
|
||||
break;
|
||||
case ERROR:
|
||||
logText += "[ERROR]";
|
||||
break;
|
||||
case START:
|
||||
logText += "[START]";
|
||||
break;
|
||||
case OK:
|
||||
logText += "[OK]";
|
||||
break;
|
||||
case CANCELLED:
|
||||
logText += "[CANCELLED]";
|
||||
break;
|
||||
}
|
||||
|
||||
// special case: first parameter may be a quantity
|
||||
if (entryParcel.mParameters != null && entryParcel.mParameters.length > 0
|
||||
&& entryParcel.mParameters[0] instanceof Integer) {
|
||||
logText += getResources().getQuantityString(entryParcel.mType.getMsgId(),
|
||||
(Integer) entryParcel.mParameters[0],
|
||||
entryParcel.mParameters);
|
||||
} else {
|
||||
logText += getResources().getString(entryParcel.mType.getMsgId(),
|
||||
entryParcel.mParameters);
|
||||
}
|
||||
|
||||
if (entryParcel instanceof SubLogEntryParcel) {
|
||||
OperationResult subResult = ((SubLogEntryParcel) entryParcel).getSubResult();
|
||||
LogEntryParcel subEntry = subResult.getLog().getLast();
|
||||
if (subEntry != null) {
|
||||
//the first line of log of subResult is same as entryParcel, so replace logText
|
||||
logText = getPrintableOperationLog(subResult.getLog(), padding);
|
||||
}
|
||||
}
|
||||
|
||||
return logText;
|
||||
}
|
||||
|
||||
private void showExportLogDialog(final File exportFile) {
|
||||
|
||||
String title = this.getString(R.string.title_export_log);
|
||||
|
||||
String message = this.getString(R.string.specify_file_to_export_log_to);
|
||||
|
||||
FileHelper.saveFile(new FileHelper.FileDialogCallback() {
|
||||
@Override
|
||||
public void onFileSelected(File file, boolean checked) {
|
||||
writeToLogFile(mResult.getLog(), file);
|
||||
}
|
||||
}, this.getActivity().getSupportFragmentManager(), title, message, exportFile, null);
|
||||
}
|
||||
|
||||
private static class LogExportResult extends OperationResult {
|
||||
|
||||
public static Creator<LogExportResult> CREATOR = new Creator<LogExportResult>() {
|
||||
public LogExportResult createFromParcel(final Parcel source) {
|
||||
return new LogExportResult(source);
|
||||
}
|
||||
|
||||
public LogExportResult[] newArray(final int size) {
|
||||
return new LogExportResult[size];
|
||||
}
|
||||
};
|
||||
|
||||
public LogExportResult(int result, OperationLog log) {
|
||||
super(result, log);
|
||||
}
|
||||
|
||||
/**
|
||||
* trivial but necessary to implement the Parcelable protocol.
|
||||
*/
|
||||
public LogExportResult(Parcel source) {
|
||||
super(source);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -109,7 +304,7 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
||||
mSecondImg = secondImg;
|
||||
}
|
||||
}
|
||||
|
||||
// Check if convertView.setPadding is redundant
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LogEntryParcel entry = getItem(position);
|
||||
@ -132,7 +327,6 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe
|
||||
if (entry instanceof SubLogEntryParcel) {
|
||||
ih.mSub.setVisibility(View.VISIBLE);
|
||||
convertView.setClickable(false);
|
||||
|
||||
convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0);
|
||||
|
||||
OperationResult result = ((SubLogEntryParcel) entry).getSubResult();
|
||||
|
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_action_save_white.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-hdpi/ic_action_save_white.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 394 B |
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_action_save_white.png
Normal file
BIN
OpenKeychain/src/main/res/drawable-mdpi/ic_action_save_white.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 362 B |
Binary file not shown.
After Width: | Height: | Size: 441 B |
Binary file not shown.
After Width: | Height: | Size: 495 B |
11
OpenKeychain/src/main/res/menu/log_display.xml
Normal file
11
OpenKeychain/src/main/res/menu/log_display.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/menu_log_display_export_log"
|
||||
android:icon="@drawable/ic_action_save_white"
|
||||
android:title="@string/menu_export_log"
|
||||
app:showAsAction="ifRoom|withText" />
|
||||
|
||||
</menu>
|
@ -43,6 +43,7 @@
|
||||
<string name="title_advanced_key_info">"Advanced Key Info"</string>
|
||||
<string name="title_keys">"Keys"</string>
|
||||
<string name="title_delete_secret_key">"Delete YOUR key \'%s\'?"</string>
|
||||
<string name="title_export_log">"Export Log"</string>
|
||||
|
||||
<!-- section -->
|
||||
<string name="section_user_ids">"Identities"</string>
|
||||
@ -114,6 +115,7 @@
|
||||
<string name="menu_export_all_keys">"Export all keys"</string>
|
||||
<string name="menu_advanced">"Show advanced info"</string>
|
||||
<string name="menu_certify_fingerprint">"Confirm via fingerprint comparison"</string>
|
||||
<string name="menu_export_log">"Export Log"</string>
|
||||
|
||||
<!-- label -->
|
||||
<string name="label_message">"Message"</string>
|
||||
@ -236,6 +238,8 @@
|
||||
<string name="key_creation_el_gamal_info">"Note: only subkeys support ElGamal."</string>
|
||||
<string name="key_not_found">"Couldn't find key %08X."</string>
|
||||
|
||||
<string name="specify_file_to_export_log_to">"Please specify file to export to. \nWARNING: File will be overwritten if it exists."</string>
|
||||
|
||||
<plurals name="bad_keys_encountered">"
|
||||
<item quantity="one">"%d bad secret key ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead.""</item>
|
||||
<item quantity="other">"%d bad secret keys ignored. Perhaps you exported with the option\n --export-secret-subkeys\nMake sure you export with\n --export-secret-keys\ninstead.""</item>
|
||||
@ -1155,6 +1159,13 @@
|
||||
|
||||
<string name="msg_download_query_failed">"An error occurred when searching for keys."</string>
|
||||
|
||||
<!-- Messages for Export Log operation -->
|
||||
<string name="msg_export_log_start">"Exporting log"</string>
|
||||
<string name="msg_export_log_error_fopen">"Error opening file"</string>
|
||||
<string name="msg_export_log_error_no_file">"No file name specified!"</string>
|
||||
<string name="msg_export_log_error_writing">"I/O error writing to file!"</string>
|
||||
<string name="msg_export_log_success">"Log exported successfully!"</string>
|
||||
|
||||
<!-- PassphraseCache -->
|
||||
<string name="passp_cache_notif_click_to_clear">"Click to clear cached passphrases"</string>
|
||||
<string name="passp_cache_notif_n_keys">"OpenKeychain has cached %d passphrases"</string>
|
||||
|
Loading…
Reference in New Issue
Block a user