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);
break;
case R.id.export:
onExport(realAccount);
onExport(false, realAccount);
break;
}
return true;
@ -708,7 +708,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
onSearchRequested();
break;
case R.id.export_all:
onExport(null);
onExport(true, null);
break;
case R.id.import_settings:
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
HashSet<String> accountUuids;
@ -1119,7 +1119,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
accountUuids.add(account.getUuid());
}
ExportHelper.exportSettings(this, accountUuids, new ExportListener() {
ExportHelper.exportSettings(this, includeGlobals, accountUuids, new ExportListener() {
@Override
public void canceled() {

View file

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

View file

@ -12,10 +12,10 @@ import com.fsck.k9.R;
import com.fsck.k9.preferences.StorageFormat;
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:
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
public void canceled() {

View file

@ -8,5 +8,5 @@ import android.content.Context;
public interface IStorageExporter {
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;
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 {
IStorageExporter storageExporter = StorageFormat.createExporter(storageFormat);
if (storageExporter == null) {
throw new StorageImportExportException(activity.getString(R.string.settings_unknown_version, storageFormat), null);
}
if (storageExporter.needsKey() && encryptionKey == null) {
gatherPassword(activity, storageExporter, accountUuids, fileName, os, listener);
gatherPassword(activity, storageExporter, includeGlobals, accountUuids, fileName, os, listener);
} 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 {
exportPreferences(activity, storageFormat, accountUuids, fileName, null, encryptionKey, listener);
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, 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 {
exportPreferences(activity, storageFormat, accountUuids, null, os, encryptionKey, listener);
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, 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() {
@Override
@ -58,7 +58,7 @@ public class StorageExporter {
@Override
public void run() {
try {
finishExport(activity, storageExporter, accountUuids, fileName, os, chosenPassword, listener);
finishExport(activity, storageExporter, includeGlobals, accountUuids, fileName, os, chosenPassword, listener);
} catch (Exception e) {
Log.w(K9.LOG_TAG, "Exception while finishing export", e);
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;
if (listener != null) {
listener.started();
@ -96,7 +96,7 @@ public class StorageExporter {
os = new FileOutputStream(outFile);
}
if (os != null) {
storageExporter.exportPreferences(activity, accountUuids, os, encryptionKey);
storageExporter.exportPreferences(activity, includeGlobals, accountUuids, os, encryptionKey);
if (listener != null) {
if (fileName != null) {
listener.success(fileName);

View file

@ -16,7 +16,7 @@ import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
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 {
Log.i(K9.LOG_TAG, "Exporting preferences");
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");
continue;
}
} else if (!includeGlobals) {
// Skip global config entries if the user didn't request them
continue;
}
String keyEnc = krypto.encrypt(key);
String valueEnc = krypto.encrypt(value);