Search in sources :

Example 1 with Preferences

use of com.fsck.k9.Preferences in project k-9 by k9mail.

the class MigrationTo42 method from41MoveFolderPreferences.

public static void from41MoveFolderPreferences(MigrationsHelper migrationsHelper) {
    try {
        LocalStore localStore = migrationsHelper.getLocalStore();
        Storage storage = migrationsHelper.getStorage();
        long startTime = System.currentTimeMillis();
        StorageEditor editor = storage.edit();
        List<? extends Folder> folders = localStore.getPersonalNamespaces(true);
        for (Folder folder : folders) {
            if (folder instanceof LocalFolder) {
                LocalFolder lFolder = (LocalFolder) folder;
                lFolder.save(editor);
            }
        }
        editor.commit();
        long endTime = System.currentTimeMillis();
        Timber.i("Putting folder preferences for %d folders back into Preferences took %d ms", folders.size(), endTime - startTime);
    } catch (Exception e) {
        Timber.e(e, "Could not replace Preferences in upgrade from DB_VERSION 41");
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) Storage(com.fsck.k9.preferences.Storage) LocalStore(com.fsck.k9.mailstore.LocalStore) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 2 with Preferences

use of com.fsck.k9.Preferences in project k-9 by k9mail.

the class MessageListFragment method changeSort.

/**
     * Change the sort type and sort order used for the message list.
     *
     * @param sortType
     *         Specifies which field to use for sorting the message list.
     * @param sortAscending
     *         Specifies the sort order. If this argument is {@code null} the default search order
     *         for the sort type is used.
     */
// FIXME: Don't save the changes in the UI thread
private void changeSort(SortType sortType, Boolean sortAscending) {
    this.sortType = sortType;
    Account account = this.account;
    if (account != null) {
        account.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = account.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        account.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = account.isSortAscending(SortType.SORT_DATE);
        account.save(preferences);
    } else {
        K9.setSortType(this.sortType);
        if (sortAscending == null) {
            this.sortAscending = K9.isSortAscending(this.sortType);
        } else {
            this.sortAscending = sortAscending;
        }
        K9.setSortAscending(this.sortType, this.sortAscending);
        sortDateAscending = K9.isSortAscending(SortType.SORT_DATE);
        StorageEditor editor = preferences.getStorage().edit();
        K9.save(editor);
        editor.commit();
    }
    reSort();
}
Also used : Account(com.fsck.k9.Account) StorageEditor(com.fsck.k9.preferences.StorageEditor)

Example 3 with Preferences

use of com.fsck.k9.Preferences in project k-9 by k9mail.

the class MessagingController method checkMail.

/**
     * Checks mail for one or multiple accounts. If account is null all accounts
     * are checked.
     */
public void checkMail(final Context context, final Account account, final boolean ignoreLastCheckedTime, final boolean useManualWakeLock, final MessagingListener listener) {
    TracingWakeLock twakeLock = null;
    if (useManualWakeLock) {
        TracingPowerManager pm = TracingPowerManager.getPowerManager(context);
        twakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "K9 MessagingController.checkMail");
        twakeLock.setReferenceCounted(false);
        twakeLock.acquire(K9.MANUAL_WAKE_LOCK_TIMEOUT);
    }
    final TracingWakeLock wakeLock = twakeLock;
    for (MessagingListener l : getListeners()) {
        l.checkMailStarted(context, account);
    }
    putBackground("checkMail", listener, new Runnable() {

        @Override
        public void run() {
            try {
                Timber.i("Starting mail check");
                Preferences prefs = Preferences.getPreferences(context);
                Collection<Account> accounts;
                if (account != null) {
                    accounts = new ArrayList<>(1);
                    accounts.add(account);
                } else {
                    accounts = prefs.getAvailableAccounts();
                }
                for (final Account account : accounts) {
                    checkMailForAccount(context, account, ignoreLastCheckedTime, listener);
                }
            } catch (Exception e) {
                Timber.e(e, "Unable to synchronize mail");
                addErrorMessage(account, null, e);
            }
            putBackground("finalize sync", null, new Runnable() {

                @Override
                public void run() {
                    Timber.i("Finished mail sync");
                    if (wakeLock != null) {
                        wakeLock.release();
                    }
                    for (MessagingListener l : getListeners()) {
                        l.checkMailFinished(context, account);
                    }
                }
            });
        }
    });
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) TracingPowerManager(com.fsck.k9.mail.power.TracingPowerManager) ArrayList(java.util.ArrayList) Collection(java.util.Collection) Preferences(com.fsck.k9.Preferences) TracingWakeLock(com.fsck.k9.mail.power.TracingPowerManager.TracingWakeLock) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Example 4 with Preferences

use of com.fsck.k9.Preferences in project k-9 by k9mail.

the class FolderSettings method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String folderName = (String) getIntent().getSerializableExtra(EXTRA_FOLDER_NAME);
    String accountUuid = getIntent().getStringExtra(EXTRA_ACCOUNT);
    Account mAccount = Preferences.getPreferences(this).getAccount(accountUuid);
    try {
        LocalStore localStore = mAccount.getLocalStore();
        mFolder = localStore.getFolder(folderName);
        mFolder.open(Folder.OPEN_MODE_RW);
    } catch (MessagingException me) {
        Timber.e(me, "Unable to edit folder %s preferences", folderName);
        return;
    }
    boolean isPushCapable = false;
    try {
        Store store = mAccount.getRemoteStore();
        isPushCapable = store.isPushCapable();
    } catch (Exception e) {
        Timber.e(e, "Could not get remote store");
    }
    addPreferencesFromResource(R.xml.folder_settings_preferences);
    String displayName = FolderInfoHolder.getDisplayName(this, mAccount, mFolder.getName());
    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(displayName);
    mInTopGroup = (CheckBoxPreference) findPreference(PREFERENCE_IN_TOP_GROUP);
    mInTopGroup.setChecked(mFolder.isInTopGroup());
    mIntegrate = (CheckBoxPreference) findPreference(PREFERENCE_INTEGRATE);
    mIntegrate.setChecked(mFolder.isIntegrate());
    mDisplayClass = (ListPreference) findPreference(PREFERENCE_DISPLAY_CLASS);
    mDisplayClass.setValue(mFolder.getDisplayClass().name());
    mDisplayClass.setSummary(mDisplayClass.getEntry());
    mDisplayClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mDisplayClass.findIndexOfValue(summary);
            mDisplayClass.setSummary(mDisplayClass.getEntries()[index]);
            mDisplayClass.setValue(summary);
            return false;
        }
    });
    mSyncClass = (ListPreference) findPreference(PREFERENCE_SYNC_CLASS);
    mSyncClass.setValue(mFolder.getRawSyncClass().name());
    mSyncClass.setSummary(mSyncClass.getEntry());
    mSyncClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mSyncClass.findIndexOfValue(summary);
            mSyncClass.setSummary(mSyncClass.getEntries()[index]);
            mSyncClass.setValue(summary);
            return false;
        }
    });
    mPushClass = (ListPreference) findPreference(PREFERENCE_PUSH_CLASS);
    mPushClass.setEnabled(isPushCapable);
    mPushClass.setValue(mFolder.getRawPushClass().name());
    mPushClass.setSummary(mPushClass.getEntry());
    mPushClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mPushClass.findIndexOfValue(summary);
            mPushClass.setSummary(mPushClass.getEntries()[index]);
            mPushClass.setValue(summary);
            return false;
        }
    });
    mNotifyClass = (ListPreference) findPreference(PREFERENCE_NOTIFY_CLASS);
    mNotifyClass.setValue(mFolder.getRawNotifyClass().name());
    mNotifyClass.setSummary(mNotifyClass.getEntry());
    mNotifyClass.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {

        public boolean onPreferenceChange(Preference preference, Object newValue) {
            final String summary = newValue.toString();
            int index = mNotifyClass.findIndexOfValue(summary);
            mNotifyClass.setSummary(mNotifyClass.getEntries()[index]);
            mNotifyClass.setValue(summary);
            return false;
        }
    });
}
Also used : MessagingException(com.fsck.k9.mail.MessagingException) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) Store(com.fsck.k9.mail.Store) LocalStore(com.fsck.k9.mailstore.LocalStore) LocalStore(com.fsck.k9.mailstore.LocalStore) MessagingException(com.fsck.k9.mail.MessagingException)

Example 5 with Preferences

use of com.fsck.k9.Preferences in project k-9 by k9mail.

the class SettingsExporter method exportPreferences.

static void exportPreferences(Context context, OutputStream os, boolean includeGlobals, Set<String> accountUuids) throws SettingsImportExportException {
    try {
        XmlSerializer serializer = Xml.newSerializer();
        serializer.setOutput(os, "UTF-8");
        serializer.startDocument(null, Boolean.TRUE);
        // Output with indentation
        serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
        serializer.startTag(null, ROOT_ELEMENT);
        serializer.attribute(null, VERSION_ATTRIBUTE, Integer.toString(Settings.VERSION));
        serializer.attribute(null, FILE_FORMAT_ATTRIBUTE, Integer.toString(FILE_FORMAT_VERSION));
        Timber.i("Exporting preferences");
        Preferences preferences = Preferences.getPreferences(context);
        Storage storage = preferences.getStorage();
        Set<String> exportAccounts;
        if (accountUuids == null) {
            List<Account> accounts = preferences.getAccounts();
            exportAccounts = new HashSet<>();
            for (Account account : accounts) {
                exportAccounts.add(account.getUuid());
            }
        } else {
            exportAccounts = accountUuids;
        }
        Map<String, Object> prefs = new TreeMap<String, Object>(storage.getAll());
        if (includeGlobals) {
            serializer.startTag(null, GLOBAL_ELEMENT);
            writeSettings(serializer, prefs);
            serializer.endTag(null, GLOBAL_ELEMENT);
        }
        serializer.startTag(null, ACCOUNTS_ELEMENT);
        for (String accountUuid : exportAccounts) {
            Account account = preferences.getAccount(accountUuid);
            writeAccount(serializer, account, prefs);
        }
        serializer.endTag(null, ACCOUNTS_ELEMENT);
        serializer.endTag(null, ROOT_ELEMENT);
        serializer.endDocument();
        serializer.flush();
    } catch (Exception e) {
        throw new SettingsImportExportException(e.getLocalizedMessage(), e);
    }
}
Also used : Account(com.fsck.k9.Account) TreeMap(java.util.TreeMap) InvalidSettingValueException(com.fsck.k9.preferences.Settings.InvalidSettingValueException) IOException(java.io.IOException) Preferences(com.fsck.k9.Preferences) XmlSerializer(org.xmlpull.v1.XmlSerializer)

Aggregations

Preferences (com.fsck.k9.Preferences)18 Account (com.fsck.k9.Account)17 Test (org.junit.Test)15 StorageEditor (com.fsck.k9.preferences.StorageEditor)9 Storage (com.fsck.k9.preferences.Storage)6 Map (java.util.Map)5 Preferences (org.apereo.portal.soffit.model.v1_0.Preferences)5 Preferences (org.orcid.jaxb.model.record_v2.Preferences)5 SharedPreferences (android.content.SharedPreferences)4 MessagingException (com.fsck.k9.mail.MessagingException)4 SearchAccount (com.fsck.k9.search.SearchAccount)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Intent (android.content.Intent)3 MatrixCursor (android.database.MatrixCursor)3 Uri (android.net.Uri)3 Address (com.fsck.k9.mail.Address)3 NetworkType (com.fsck.k9.mail.NetworkType)3 LocalStore (com.fsck.k9.mailstore.LocalStore)3 IOException (java.io.IOException)3