void WriteMail::updateAccountSelection(QMailMessage::MessageType messageType, const QMailAccountId &suggestedId) { m_accountSelection->clear(); QMailAccountIdList accountIds = sendingAccounts(messageType); m_accountSelection->setEnabled(accountIds.count() > 1); if (accountIds.isEmpty()) { return; } int suggestedIndex = -1; int preferredIndex = -1; foreach (QMailAccountId id, accountIds) { QMailAccount a(id); if (a.id() == suggestedId) { suggestedIndex = m_accountSelection->count(); } if (a.status() & QMailAccount::PreferredSender) { preferredIndex = m_accountSelection->count(); } m_accountSelection->addItem(a.name(), a.id()); }
void AccountSettings::editAccount(QMailAccount *account) { QMailAccountConfiguration config; if (account->id().isValid()) { config = QMailAccountConfiguration(account->id()); } else { account->setStatus(QMailAccount::UserEditable, true); account->setStatus(QMailAccount::UserRemovable, true); } QDialog *editAccountView; bool wasPreferred(account->status() & QMailAccount::PreferredSender); EditAccount *e = new EditAccount(this, "EditAccount"); e->setAccount(account, &config); editAccountView = e; editAccountView->setMinimumSize(QSize(400,400)); int ret = editAccountView->exec(); delete editAccountView; if (ret == QDialog::Accepted) { QMailAccountId previousPreferredId; if ((account->status() & QMailAccount::PreferredSender) && !wasPreferred) { // This account is now preferred - see if there is a predecessor that must be deselected QMailAccountKey preferredKey(QMailAccountKey::status(QMailAccount::PreferredSender, QMailDataComparator::Includes)); QMailAccountKey typeKey(QMailAccountKey::messageType(account->messageType())); QMailAccountIdList previousIds = QMailStore::instance()->queryAccounts(preferredKey & typeKey); if (!previousIds.isEmpty()) previousPreferredId = previousIds.first(); } preExisting = account->id().isValid(); if (preExisting) { QMailStore::instance()->updateAccount(account, &config); } else { QMailStore::instance()->addAccount(account, &config); accountView->setCurrentIndex(accountModel->index(accountModel->rowCount() - 1, 0)); } if ((account->status() & QMailAccount::PreferredSender) && !wasPreferred) { if (previousPreferredId.isValid()) { QMailAccount previousAccount(previousPreferredId); previousAccount.setStatus(QMailAccount::PreferredSender, false); QMailStore::instance()->updateAccount(&previousAccount); QMessageBox::warning(this, tr("New default account"), tr("<qt>Your previous default mail account has been unchecked</qt>"), QMessageBox::Ok); } } QTimer::singleShot(0, this, SLOT(testConfiguration())); } }