1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 00:58:50 -05:00

No longer export global settings when exporting one account

This commit is contained in:
Jesse Vincent 2011-03-27 12:03:23 +08:00
parent 52825f409f
commit 9deeaf9c11
6 changed files with 24 additions and 21 deletions

View File

@ -659,7 +659,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
onRecreate(realAccount); onRecreate(realAccount);
break; break;
case R.id.export: case R.id.export:
onExport(realAccount); onExport(false, realAccount);
break; break;
} }
return true; return true;
@ -708,7 +708,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
onSearchRequested(); onSearchRequested();
break; break;
case R.id.export_all: case R.id.export_all:
onExport(null); onExport(true, null);
break; break;
case R.id.import_settings: case R.id.import_settings:
onImport(); onImport();
@ -1110,7 +1110,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
public void onExport(final Account account) { public void onExport(final boolean includeGlobals, final Account account) {
// TODO, prompt to allow a user to choose which accounts to export // TODO, prompt to allow a user to choose which accounts to export
HashSet<String> accountUuids; HashSet<String> accountUuids;
@ -1119,7 +1119,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
accountUuids.add(account.getUuid()); accountUuids.add(account.getUuid());
} }
ExportHelper.exportSettings(this, accountUuids, new ExportListener() { ExportHelper.exportSettings(this, includeGlobals, accountUuids, new ExportListener() {
@Override @Override
public void canceled() { public void canceled() {

View File

@ -42,7 +42,7 @@ public class AsyncUIProcessor {
public void execute(Runnable runnable) { public void execute(Runnable runnable) {
threadPool.execute(runnable); threadPool.execute(runnable);
} }
public void exportSettings(final Activity activity, final String storageFormat, final Set<String> accountUuids, final ExportListener listener) { public void exportSettings(final Activity activity, final String storageFormat, final boolean includeGlobals, final Set<String> accountUuids, final ExportListener listener) {
threadPool.execute(new Runnable() { threadPool.execute(new Runnable() {
@Override @Override
@ -55,7 +55,7 @@ public class AsyncUIProcessor {
dir.mkdirs(); dir.mkdirs();
File file = Utility.createUniqueFile(dir, "settings.k9s"); File file = Utility.createUniqueFile(dir, "settings.k9s");
String fileName = file.getAbsolutePath(); String fileName = file.getAbsolutePath();
StorageExporter.exportPreferences(activity, storageFormat, accountUuids, fileName, null, listener); StorageExporter.exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, listener);
} catch (Exception e) { } catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception during export", e); Log.w(K9.LOG_TAG, "Exception during export", e);
listener.failure(e.getLocalizedMessage(), e); listener.failure(e.getLocalizedMessage(), e);

View File

@ -12,10 +12,10 @@ import com.fsck.k9.R;
import com.fsck.k9.preferences.StorageFormat; import com.fsck.k9.preferences.StorageFormat;
public class ExportHelper { public class ExportHelper {
public static void exportSettings(final Activity activity, final Set<String> accountUuids, final ExportListener listener) { public static void exportSettings(final Activity activity, final boolean includeGlobals, final Set<String> accountUuids, final ExportListener listener) {
// Once there are more file formats, build a UI to select which one to use. For now, use the encrypted/encoded format: // Once there are more file formats, build a UI to select which one to use. For now, use the encrypted/encoded format:
String storageFormat = StorageFormat.ENCRYPTED_XML_FILE; String storageFormat = StorageFormat.ENCRYPTED_XML_FILE;
AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, storageFormat, accountUuids, new ExportListener() { AsyncUIProcessor.getInstance(activity.getApplication()).exportSettings(activity, storageFormat, includeGlobals, accountUuids, new ExportListener() {
@Override @Override
public void canceled() { public void canceled() {

View File

@ -8,5 +8,5 @@ import android.content.Context;
public interface IStorageExporter { public interface IStorageExporter {
public boolean needsKey(); public boolean needsKey();
public void exportPreferences(Context context, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException; public void exportPreferences(Context context, boolean includeGlobals, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException;
} }

View File

@ -16,16 +16,16 @@ import com.fsck.k9.activity.ExportListener;
import com.fsck.k9.activity.PasswordEntryDialog; import com.fsck.k9.activity.PasswordEntryDialog;
public class StorageExporter { public class StorageExporter {
private static void exportPreferences(Activity activity, String storageFormat, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) { private static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, final ExportListener listener) {
try { try {
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat); IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
if (storageExporter == null) { if (storageExporter == null) {
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null); throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
} }
if (storageExporter.needsKey() && encryptionKey == null) { if (storageExporter.needsKey() && encryptionKey == null) {
gatherPassword(activity, storageExporter, accountUuids, fileName, os, listener); gatherPassword(activity, storageExporter, includeGlobals, accountUuids, fileName, os, listener);
} else { } else {
finishExport(activity, storageExporter, accountUuids, fileName, os, encryptionKey, listener); finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, encryptionKey, listener);
} }
} }
@ -36,15 +36,15 @@ public class StorageExporter {
} }
} }
public static void exportPreferences(Activity activity, String storageFormat, Set<String> accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException { public static void exportPreferences(Activity activity, String storageFormat, boolean includeGlobals, Set<String> accountUuids, String fileName, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
exportPreferences(activity, storageFormat, accountUuids, fileName, null, encryptionKey, listener); exportPreferences(activity, storageFormat, includeGlobals, accountUuids, fileName, null, encryptionKey, listener);
} }
public static void exportPrefererences(Activity activity, String storageFormat, HashSet<String> accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException { public static void exportPrefererences(Activity activity, String storageFormat, boolean includeGlobals, HashSet<String> accountUuids, OutputStream os, String encryptionKey, final ExportListener listener) throws StorageImportExportException {
exportPreferences(activity, storageFormat, accountUuids, null, os, encryptionKey, listener); exportPreferences(activity, storageFormat, includeGlobals, accountUuids, null, os, encryptionKey, listener);
} }
private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final Set<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) { private static void gatherPassword(final Activity activity, final IStorageExporter storageExporter, final boolean includeGlobals, final Set<String> accountUuids, final String fileName, final OutputStream os, final ExportListener listener) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
@ -58,7 +58,7 @@ public class StorageExporter {
@Override @Override
public void run() { public void run() {
try { try {
finishExport(activity, storageExporter, accountUuids, fileName, os, chosenPassword, listener); finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener);
} catch (Exception e) { } catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception while finishing export", e); Log.w(K9.LOG_TAG, "Exception while finishing export", e);
if (listener != null) { if (listener != null) {
@ -82,7 +82,7 @@ public class StorageExporter {
} }
private static void finishExport(Activity activity, IStorageExporter storageExporter, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException { private static void finishExport(Activity activity, IStorageExporter storageExporter, boolean includeGlobals, Set<String> accountUuids, String fileName, OutputStream os, String encryptionKey, ExportListener listener) throws StorageImportExportException {
boolean needToClose = false; boolean needToClose = false;
if (listener != null) { if (listener != null) {
listener.started(); listener.started();
@ -96,7 +96,7 @@ public class StorageExporter {
os = new FileOutputStream(outFile); os = new FileOutputStream(outFile);
} }
if (os != null) { if (os != null) {
storageExporter.exportPreferences(activity, accountUuids, os, encryptionKey); storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey);
if (listener != null) { if (listener != null) {
if (fileName != null) { if (fileName != null) {
listener.success(fileName); listener.success(fileName);

View File

@ -16,7 +16,7 @@ import com.fsck.k9.K9;
import com.fsck.k9.Preferences; import com.fsck.k9.Preferences;
public class StorageExporterEncryptedXml implements IStorageExporter { public class StorageExporterEncryptedXml implements IStorageExporter {
public void exportPreferences(Context context, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException { public void exportPreferences(Context context, boolean includeGlobals, Set<String> accountUuids, OutputStream os, String encryptionKey) throws StorageImportExportException {
try { try {
Log.i(K9.LOG_TAG, "Exporting preferences"); Log.i(K9.LOG_TAG, "Exporting preferences");
K9Krypto krypto = new K9Krypto(encryptionKey, K9Krypto.MODE.ENCRYPT); K9Krypto krypto = new K9Krypto(encryptionKey, K9Krypto.MODE.ENCRYPT);
@ -53,6 +53,9 @@ public class StorageExporterEncryptedXml implements IStorageExporter {
//Log.i(K9.LOG_TAG, "Skipping key " + key + " which is not for any current account"); //Log.i(K9.LOG_TAG, "Skipping key " + key + " which is not for any current account");
continue; continue;
} }
} else if (!includeGlobals) {
// Skip global config entries if the user didn't request them
continue;
} }
String keyEnc = krypto.encrypt(key); String keyEnc = krypto.encrypt(key);
String valueEnc = krypto.encrypt(value); String valueEnc = krypto.encrypt(value);