From 29c42eb1a347df853b61b0dc5236e35b0f88c4ae Mon Sep 17 00:00:00 2001 From: cketti Date: Wed, 30 Mar 2011 04:57:05 +0200 Subject: [PATCH] More structure for the XML export (folder settings) --- src/com/fsck/k9/mail/store/LocalStore.java | 10 ++++ .../fsck/k9/preferences/StorageExporter.java | 60 +++++++++++++++++-- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/src/com/fsck/k9/mail/store/LocalStore.java b/src/com/fsck/k9/mail/store/LocalStore.java index e90e5a64e..3b0137a00 100644 --- a/src/com/fsck/k9/mail/store/LocalStore.java +++ b/src/com/fsck/k9/mail/store/LocalStore.java @@ -87,6 +87,16 @@ public class LocalStore extends Store implements Serializable { HEADERS_TO_SAVE.add("Content-Disposition"); HEADERS_TO_SAVE.add("User-Agent"); } + + public static final Set FOLDER_SETTINGS_KEYS = new HashSet(); + static { + FOLDER_SETTINGS_KEYS.add("displayMode"); + FOLDER_SETTINGS_KEYS.add("syncMode"); + FOLDER_SETTINGS_KEYS.add("pushMode"); + FOLDER_SETTINGS_KEYS.add("inTopGroup"); + FOLDER_SETTINGS_KEYS.add("integrate"); + } + /* * a String containing the columns getMessages expects to work with * in the correct order. diff --git a/src/com/fsck/k9/preferences/StorageExporter.java b/src/com/fsck/k9/preferences/StorageExporter.java index b3208b981..08f1d6e6c 100644 --- a/src/com/fsck/k9/preferences/StorageExporter.java +++ b/src/com/fsck/k9/preferences/StorageExporter.java @@ -19,6 +19,7 @@ import com.fsck.k9.Account; import com.fsck.k9.K9; import com.fsck.k9.Preferences; import com.fsck.k9.helper.Utility; +import com.fsck.k9.mail.store.LocalStore; public class StorageExporter { @@ -30,9 +31,12 @@ public class StorageExporter { private static final String SETTINGS_ELEMENT = "settings"; private static final String ACCOUNTS_ELEMENT = "accounts"; private static final String ACCOUNT_ELEMENT = "account"; + private static final String UUID_ATTRIBUTE = "uuid"; private static final String IDENTITIES_ELEMENT = "identities"; private static final String IDENTITY_ELEMENT = "identity"; - private static final String UUID_ATTRIBUTE = "uuid"; + private static final String FOLDERS_ELEMENT = "folders"; + private static final String FOLDER_ELEMENT = "folder"; + private static final String NAME_ATTRIBUTE = "name"; private static final String VALUE_ELEMENT = "value"; private static final String KEY_ATTRIBUTE = "key"; @@ -137,6 +141,7 @@ public class StorageExporter { Map prefs) throws IOException { Set identities = new HashSet(); + Set folders = new HashSet(); serializer.startTag(null, ACCOUNT_ELEMENT); serializer.attribute(null, UUID_ATTRIBUTE, accountUuid); @@ -152,12 +157,19 @@ public class StorageExporter { continue; } if (comps.length == 3) { - String identityKey = comps[1]; - String identityIndex = comps[2]; + String secondPart = comps[1]; + String thirdPart = comps[2]; - if (Account.IDENTITY_KEYS.contains(identityKey)) { + if (Account.IDENTITY_KEYS.contains(secondPart)) { // This is an identity key. Save identity index for later... - identities.add(identityIndex); + identities.add(thirdPart); + // ... but don't write it now. + continue; + } + + if (LocalStore.FOLDER_SETTINGS_KEYS.contains(thirdPart)) { + // This is a folder key. Save folder name for later... + folders.add(secondPart); // ... but don't write it now. continue; } @@ -185,6 +197,14 @@ public class StorageExporter { serializer.endTag(null, IDENTITIES_ELEMENT); } + if (folders.size() > 0) { + serializer.startTag(null, FOLDERS_ELEMENT); + for (String folder : folders) { + writeFolder(serializer, accountUuid, folder, prefs); + } + serializer.endTag(null, FOLDERS_ELEMENT); + } + serializer.endTag(null, ACCOUNT_ELEMENT); } @@ -216,4 +236,34 @@ public class StorageExporter { } serializer.endTag(null, IDENTITY_ELEMENT); } + + private static void writeFolder(XmlSerializer serializer, String accountUuid, + String folder, Map prefs) throws IOException { + + serializer.startTag(null, FOLDER_ELEMENT); + serializer.attribute(null, NAME_ATTRIBUTE, folder); + for (Map.Entry entry : prefs.entrySet()) { + String key = entry.getKey(); + String value = entry.getValue().toString(); + String[] comps = key.split("\\."); + if (comps.length >= 3) { + String keyUuid = comps[0]; + String folderName = comps[1]; + String folderKey = comps[2]; + if (!keyUuid.equals(accountUuid) || !folderName.equals(folder) + || !LocalStore.FOLDER_SETTINGS_KEYS.contains(folderKey)) { + continue; + } + } else { + // Skip non-folder config entries + continue; + } + + serializer.startTag(null, VALUE_ELEMENT); + serializer.attribute(null, KEY_ATTRIBUTE, comps[2]); + serializer.text(value); + serializer.endTag(null, VALUE_ELEMENT); + } + serializer.endTag(null, FOLDER_ELEMENT); + } }