示例#1
0
 /** Clear list of status presets. */
 public void clearSavedStatuses() {
   savedStatuses.clear();
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               StatusTable.getInstance().clear();
             }
           });
 }
示例#2
0
 public void onAccountsChanged(final Collection<String> accounts) {
   Application.getInstance()
       .runOnUiThread(
           new Runnable() {
             @Override
             public void run() {
               for (OnAccountChangedListener accountListener :
                   Application.getInstance().getUIListeners(OnAccountChangedListener.class))
                 accountListener.onAccountsChanged(accounts);
             }
           });
 }
示例#3
0
 /**
  * Remove status from presets.
  *
  * @param statusMode
  * @param statusText
  */
 public void removeSavedStatus(final SavedStatus savedStatus) {
   if (!savedStatuses.remove(savedStatus)) return;
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               StatusTable.getInstance()
                   .remove(savedStatus.getStatusMode(), savedStatus.getStatusText());
             }
           });
 }
示例#4
0
 /**
  * Save status in presets.
  *
  * @param statusMode
  * @param statusText
  */
 private void addSavedStatus(final StatusMode statusMode, final String statusText) {
   SavedStatus savedStatus = new SavedStatus(statusMode, statusText);
   if (savedStatuses.contains(savedStatus)) return;
   savedStatuses.add(savedStatus);
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               StatusTable.getInstance().write(statusMode, statusText);
             }
           });
 }
示例#5
0
  private AccountManager() {
    this.application = Application.getInstance();
    accountItems = new HashMap<String, AccountItem>();
    enabledAccounts = new HashSet<String>();
    savedStatuses = new ArrayList<SavedStatus>();
    authorizationErrorProvider =
        new BaseAccountNotificationProvider<AccountAuthorizationError>(
            R.drawable.ic_stat_auth_failed);
    passwordRequestProvider =
        new BaseAccountNotificationProvider<PasswordRequest>(R.drawable.ic_stat_request);

    TypedArray accountAvatars =
        application.getResources().obtainTypedArray(R.array.account_avatars);
    colors = accountAvatars.length();
    accountAvatars.recycle();

    TypedArray types = application.getResources().obtainTypedArray(R.array.account_types);
    accountTypes = new ArrayList<AccountType>();
    for (int index = 0; index < types.length(); index++) {
      int id = types.getResourceId(index, 0);
      TypedArray values = application.getResources().obtainTypedArray(id);
      AccountProtocol protocol = AccountProtocol.valueOf(values.getString(0));
      if (Application.SDK_INT < 8 && protocol == AccountProtocol.wlm) {
        values.recycle();
        continue;
      }
      ArrayList<String> servers = new ArrayList<String>();
      servers.add(values.getString(9));
      for (int i = 10; i < values.length(); i++) servers.add(values.getString(i));
      accountTypes.add(
          new AccountType(
              id,
              protocol,
              values.getString(1),
              values.getString(2),
              values.getString(3),
              values.getDrawable(4),
              values.getBoolean(5, false),
              values.getString(6),
              values.getInt(7, 5222),
              values.getBoolean(8, false),
              servers));
      values.recycle();
    }
    types.recycle();
    away = false;
    xa = false;
  }
示例#6
0
  public void OpenFileToolbar() {
    JFileChooser fileChooser = new JFileChooser();
    int returnVal = fileChooser.showOpenDialog(this);
    if (returnVal == JFileChooser.APPROVE_OPTION) {
      File file = fileChooser.getSelectedFile();
      try {
        opentFile(file.getPath());

        Workspaces workspaces = Application.getInstance().getWorkspaces();
        Map<String, Workspaces.ViewFrame> frames = workspaces.getOpenFrames();
        Object[] objFrames = frames.values().toArray();
        ViewFrame[] viewFrames = new ViewFrame[objFrames.length];
        for (int i = 0; i < objFrames.length; i++) {
          viewFrames[i] = (ViewFrame) objFrames[i];
          if (viewFrames[i].isSelected()) viewFrames[i].setTitle(file.getPath());
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
示例#7
0
 /**
  * Remove user`s account. Don't call any callbacks.
  *
  * @param account
  */
 private void removeAccountWithoutCallback(final String account) {
   final AccountItem accountItem = getAccount(account);
   boolean wasEnabled = accountItem.isEnabled();
   accountItem.setEnabled(false);
   accountItem.updateConnection(true);
   if (wasEnabled) {
     if (accountItem.getRawStatusMode().isOnline()) onAccountOffline(accountItem);
     onAccountDisabled(accountItem);
   }
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               AccountTable.getInstance().remove(account, accountItem.getId());
             }
           });
   accountItems.remove(account);
   enabledAccounts.remove(account);
   for (OnAccountRemovedListener listener :
       application.getManagers(OnAccountRemovedListener.class))
     listener.onAccountRemoved(accountItem);
   removeAuthorizationError(account);
 }
示例#8
0
 static {
   instance = new AccountManager();
   Application.getInstance().addManager(instance);
 }
示例#9
0
 /**
  * Save account item to database.
  *
  * @param accountItem
  */
 void requestToWriteAccount(final AccountItem accountItem) {
   final AccountProtocol protocol = accountItem.getConnectionSettings().getProtocol();
   final boolean custom = accountItem.getConnectionSettings().isCustom();
   final String host = accountItem.getConnectionSettings().getHost();
   final int port = accountItem.getConnectionSettings().getPort();
   final String serverName = accountItem.getConnectionSettings().getServerName();
   final String userName = accountItem.getConnectionSettings().getUserName();
   final String resource = accountItem.getConnectionSettings().getResource();
   final boolean storePassword = accountItem.isStorePassword();
   final String password = accountItem.getConnectionSettings().getPassword();
   final int colorIndex = accountItem.getColorIndex();
   final int priority = accountItem.getPriority();
   final StatusMode statusMode = accountItem.getRawStatusMode();
   final String statusText = accountItem.getStatusText();
   final boolean enabled = accountItem.isEnabled();
   final boolean saslEnabled = accountItem.getConnectionSettings().isSaslEnabled();
   final TLSMode tlsMode = accountItem.getConnectionSettings().getTlsMode();
   final boolean compression = accountItem.getConnectionSettings().useCompression();
   final ProxyType proxyType = accountItem.getConnectionSettings().getProxyType();
   final String proxyHost = accountItem.getConnectionSettings().getProxyHost();
   final int proxyPort = accountItem.getConnectionSettings().getProxyPort();
   final String proxyUser = accountItem.getConnectionSettings().getProxyUser();
   final String proxyPassword = accountItem.getConnectionSettings().getProxyPassword();
   final boolean syncable = accountItem.isSyncable();
   final KeyPair keyPair = accountItem.getKeyPair();
   final Date lastSync = accountItem.getLastSync();
   final ArchiveMode archiveMode = accountItem.getArchiveMode();
   Application.getInstance()
       .runInBackground(
           new Runnable() {
             @Override
             public void run() {
               accountItem.setId(
                   AccountTable.getInstance()
                       .write(
                           accountItem.getId(),
                           protocol,
                           custom,
                           host,
                           port,
                           serverName,
                           userName,
                           resource,
                           storePassword,
                           password,
                           colorIndex,
                           priority,
                           statusMode,
                           statusText,
                           enabled,
                           saslEnabled,
                           tlsMode,
                           compression,
                           proxyType,
                           proxyHost,
                           proxyPort,
                           proxyUser,
                           proxyPassword,
                           syncable,
                           keyPair,
                           lastSync,
                           archiveMode));
             }
           });
 }
示例#10
0
  @Override
  public void onLoad() {
    final Collection<SavedStatus> savedStatuses = new ArrayList<SavedStatus>();
    final Collection<AccountItem> accountItems = new ArrayList<AccountItem>();
    Cursor cursor = StatusTable.getInstance().list();
    try {
      if (cursor.moveToFirst()) {
        do {
          savedStatuses.add(
              new SavedStatus(
                  StatusTable.getStatusMode(cursor), StatusTable.getStatusText(cursor)));
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    cursor = AccountTable.getInstance().list();
    try {
      if (cursor.moveToFirst()) {
        do {
          AccountItem accountItem =
              new AccountItem(
                  AccountTable.getProtocol(cursor),
                  AccountTable.isCustom(cursor),
                  AccountTable.getHost(cursor),
                  AccountTable.getPort(cursor),
                  AccountTable.getServerName(cursor),
                  AccountTable.getUserName(cursor),
                  AccountTable.getResource(cursor),
                  AccountTable.isStorePassword(cursor),
                  AccountTable.getPassword(cursor),
                  AccountTable.getColorIndex(cursor),
                  AccountTable.getPriority(cursor),
                  AccountTable.getStatusMode(cursor),
                  AccountTable.getStatusText(cursor),
                  AccountTable.isEnabled(cursor),
                  AccountTable.isSaslEnabled(cursor),
                  AccountTable.getTLSMode(cursor),
                  AccountTable.isCompression(cursor),
                  AccountTable.getProxyType(cursor),
                  AccountTable.getProxyHost(cursor),
                  AccountTable.getProxyPort(cursor),
                  AccountTable.getProxyUser(cursor),
                  AccountTable.getProxyPassword(cursor),
                  AccountTable.isSyncable(cursor),
                  AccountTable.getKeyPair(cursor),
                  AccountTable.getLastSync(cursor),
                  AccountTable.getArchiveMode(cursor));
          accountItem.setId(AccountTable.getId(cursor));
          accountItems.add(accountItem);
        } while (cursor.moveToNext());
      }
    } finally {
      cursor.close();
    }

    Application.getInstance()
        .runOnUiThread(
            new Runnable() {
              @Override
              public void run() {
                onLoaded(savedStatuses, accountItems);
              }
            });
  }