Ejemplo n.º 1
0
  private static long getFolderId(Account account, String folderName) {
    long folderId = 0;
    try {
      LocalStore localStore = account.getLocalStore();
      LocalFolder folder = localStore.getFolder(folderName);
      folder.open(OpenMode.READ_ONLY);
      folderId = folder.getId();
    } catch (MessagingException e) {
      // FIXME
      e.printStackTrace();
    }

    return folderId;
  }
Ejemplo n.º 2
0
 private void onClearFolder(Account account, String folderName) {
   // There has to be a cheaper way to get at the localFolder object than this
   LocalFolder localFolder = null;
   try {
     if (account == null || folderName == null || !account.isAvailable(FolderList.this)) {
       Log.i(K9.LOG_TAG, "not clear folder of unavailable account");
       return;
     }
     localFolder = account.getLocalStore().getFolder(folderName);
     localFolder.open(Folder.OpenMode.READ_WRITE);
     localFolder.clearAllMessages();
   } catch (Exception e) {
     Log.e(K9.LOG_TAG, "Exception while clearing folder", e);
   } finally {
     if (localFolder != null) {
       localFolder.close();
     }
   }
 }
Ejemplo n.º 3
0
  private void saveSettings() throws MessagingException {
    mFolder.setInTopGroup(mInTopGroup.isChecked());
    mFolder.setIntegrate(mIntegrate.isChecked());
    // We call getPushClass() because display class changes can affect push class when push class is
    // set to inherit
    FolderClass oldPushClass = mFolder.getPushClass();
    FolderClass oldDisplayClass = mFolder.getDisplayClass();
    mFolder.setDisplayClass(FolderClass.valueOf(mDisplayClass.getValue()));
    mFolder.setSyncClass(FolderClass.valueOf(mSyncClass.getValue()));
    mFolder.setPushClass(FolderClass.valueOf(mPushClass.getValue()));

    mFolder.save();

    FolderClass newPushClass = mFolder.getPushClass();
    FolderClass newDisplayClass = mFolder.getDisplayClass();

    if (oldPushClass != newPushClass
        || (newPushClass != FolderClass.NO_CLASS && oldDisplayClass != newDisplayClass)) {
      MailService.actionRestartPushers(getApplication(), null);
    }
  }
Ejemplo n.º 4
0
  @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(OpenMode.READ_WRITE);
    } catch (MessagingException me) {
      Log.e(K9.LOG_TAG, "Unable to edit folder " + folderName + " preferences", me);
      return;
    }

    boolean isPushCapable = false;
    Store store = null;
    try {
      store = mAccount.getRemoteStore();
      isPushCapable = store.isPushCapable();
    } catch (Exception e) {
      Log.e(K9.LOG_TAG, "Could not get remote store", e);
    }

    addPreferencesFromResource(R.xml.folder_settings_preferences);

    Preference category = findPreference(PREFERENCE_TOP_CATERGORY);
    category.setTitle(folderName);

    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;
          }
        });
  }