diff --git a/resources/pop3/accountwidget.h b/resources/pop3/accountwidget.h --- a/resources/pop3/accountwidget.h +++ b/resources/pop3/accountwidget.h @@ -25,6 +25,8 @@ #include "ui_popsettings.h" +class Settings; + namespace MailTransport { class ServerTest; } @@ -39,7 +41,7 @@ Q_OBJECT public: - AccountWidget(const QString &identifier, QWidget *parent); + AccountWidget(Settings &settings, const QString &identifier, QWidget *parent); ~AccountWidget() override; void loadSettings(); @@ -82,6 +84,7 @@ KWallet::Wallet *mWallet = nullptr; QString mInitalPassword; QString mIdentifier; + Settings &mSettings; }; #endif diff --git a/resources/pop3/accountwidget.cpp b/resources/pop3/accountwidget.cpp --- a/resources/pop3/accountwidget.cpp +++ b/resources/pop3/accountwidget.cpp @@ -69,10 +69,11 @@ }; } -AccountWidget::AccountWidget(const QString &identifier, QWidget *parent) +AccountWidget::AccountWidget(Settings &settings, const QString &identifier, QWidget *parent) : QWidget(parent) , mValidator(this) , mIdentifier(identifier) + , mSettings(settings) { mValidator.setRegExp(QRegExp(QLatin1String("[A-Za-z0-9-_:.]*"))); @@ -143,59 +144,59 @@ void AccountWidget::loadSettings() { - if (Settings::self()->name().isEmpty()) { + if (mSettings.name().isEmpty()) { nameEdit->setText(i18n("POP3 Account")); } else { - nameEdit->setText(Settings::self()->name()); + nameEdit->setText(mSettings.name()); } nameEdit->setFocus(); - loginEdit->setText(!Settings::self()->login().isEmpty() ? Settings::self()->login() + loginEdit->setText(!mSettings.login().isEmpty() ? mSettings.login() : KUser().loginName()); hostEdit->setText( - !Settings::self()->host().isEmpty() ? Settings::self()->host() + !mSettings.host().isEmpty() ? mSettings.host() : KEMailSettings().getSetting(KEMailSettings::InServer)); - hostEdit->setText(Settings::self()->host()); - portEdit->setValue(Settings::self()->port()); - precommand->setText(Settings::self()->precommand()); - usePipeliningCheck->setChecked(Settings::self()->pipelining()); - leaveOnServerCheck->setChecked(Settings::self()->leaveOnServer()); - leaveOnServerDaysCheck->setEnabled(Settings::self()->leaveOnServer()); - leaveOnServerDaysCheck->setChecked(Settings::self()->leaveOnServerDays() >= 1); - leaveOnServerDaysSpin->setValue(Settings::self()->leaveOnServerDays() >= 1 - ? Settings::self()->leaveOnServerDays() : 7); - leaveOnServerCountCheck->setEnabled(Settings::self()->leaveOnServer()); - leaveOnServerCountCheck->setChecked(Settings::self()->leaveOnServerCount() >= 1); - leaveOnServerCountSpin->setValue(Settings::self()->leaveOnServerCount() >= 1 - ? Settings::self()->leaveOnServerCount() : 100); - leaveOnServerSizeCheck->setEnabled(Settings::self()->leaveOnServer()); - leaveOnServerSizeCheck->setChecked(Settings::self()->leaveOnServerSize() >= 1); - leaveOnServerSizeSpin->setValue(Settings::self()->leaveOnServerSize() >= 1 - ? Settings::self()->leaveOnServerSize() : 10); - filterOnServerCheck->setChecked(Settings::self()->filterOnServer()); - filterOnServerSizeSpin->setValue(Settings::self()->filterCheckSize()); - intervalCheck->setChecked(Settings::self()->intervalCheckEnabled()); - intervalSpin->setValue(Settings::self()->intervalCheckInterval()); - intervalSpin->setEnabled(Settings::self()->intervalCheckEnabled()); - - const int authenticationMethod = Settings::self()->authenticationMethod(); + hostEdit->setText(mSettings.host()); + portEdit->setValue(mSettings.port()); + precommand->setText(mSettings.precommand()); + usePipeliningCheck->setChecked(mSettings.pipelining()); + leaveOnServerCheck->setChecked(mSettings.leaveOnServer()); + leaveOnServerDaysCheck->setEnabled(mSettings.leaveOnServer()); + leaveOnServerDaysCheck->setChecked(mSettings.leaveOnServerDays() >= 1); + leaveOnServerDaysSpin->setValue(mSettings.leaveOnServerDays() >= 1 + ? mSettings.leaveOnServerDays() : 7); + leaveOnServerCountCheck->setEnabled(mSettings.leaveOnServer()); + leaveOnServerCountCheck->setChecked(mSettings.leaveOnServerCount() >= 1); + leaveOnServerCountSpin->setValue(mSettings.leaveOnServerCount() >= 1 + ? mSettings.leaveOnServerCount() : 100); + leaveOnServerSizeCheck->setEnabled(mSettings.leaveOnServer()); + leaveOnServerSizeCheck->setChecked(mSettings.leaveOnServerSize() >= 1); + leaveOnServerSizeSpin->setValue(mSettings.leaveOnServerSize() >= 1 + ? mSettings.leaveOnServerSize() : 10); + filterOnServerCheck->setChecked(mSettings.filterOnServer()); + filterOnServerSizeSpin->setValue(mSettings.filterCheckSize()); + intervalCheck->setChecked(mSettings.intervalCheckEnabled()); + intervalSpin->setValue(mSettings.intervalCheckInterval()); + intervalSpin->setEnabled(mSettings.intervalCheckEnabled()); + + const int authenticationMethod = mSettings.authenticationMethod(); authCombo->setCurrentIndex(authCombo->findData(authenticationMethod)); - encryptionNone->setChecked(!Settings::self()->useSSL() && !Settings::self()->useTLS()); - encryptionSSL->setChecked(Settings::self()->useSSL()); - encryptionTLS->setChecked(Settings::self()->useTLS()); - proxyCheck->setChecked(Settings::self()->useProxy()); + encryptionNone->setChecked(!mSettings.useSSL() && !mSettings.useTLS()); + encryptionSSL->setChecked(mSettings.useSSL()); + encryptionTLS->setChecked(mSettings.useTLS()); + proxyCheck->setChecked(mSettings.useProxy()); slotEnableLeaveOnServerDays(leaveOnServerDaysCheck->isEnabled() - ? Settings::self()->leaveOnServerDays() >= 1 : false); + ? mSettings.leaveOnServerDays() >= 1 : false); slotEnableLeaveOnServerCount(leaveOnServerCountCheck->isEnabled() - ? Settings::self()->leaveOnServerCount() >= 1 : false); + ? mSettings.leaveOnServerCount() >= 1 : false); slotEnableLeaveOnServerSize(leaveOnServerSizeCheck->isEnabled() - ? Settings::self()->leaveOnServerSize() >= 1 : false); + ? mSettings.leaveOnServerSize() >= 1 : false); // We need to fetch the collection, as the CollectionRequester needs the name // of it to work correctly - Collection targetCollection(Settings::self()->targetCollection()); + Collection targetCollection(mSettings.targetCollection()); if (targetCollection.isValid()) { CollectionFetchJob *fetchJob = new CollectionFetchJob(targetCollection, CollectionFetchJob::Base, @@ -545,32 +546,32 @@ void AccountWidget::saveSettings() { - Settings::self()->setName(nameEdit->text()); - Settings::self()->setIntervalCheckEnabled(intervalCheck->checkState() == Qt::Checked); - Settings::self()->setIntervalCheckInterval(intervalSpin->value()); - Settings::self()->setHost(hostEdit->text().trimmed()); - Settings::self()->setPort(portEdit->value()); - Settings::self()->setLogin(loginEdit->text().trimmed()); - Settings::self()->setPrecommand(precommand->text()); - Settings::self()->setUseSSL(encryptionSSL->isChecked()); - Settings::self()->setUseTLS(encryptionTLS->isChecked()); - Settings::self()->setAuthenticationMethod(authCombo->itemData(authCombo->currentIndex()).toInt()); - Settings::self()->setUseProxy(proxyCheck->isChecked()); - Settings::self()->setPipelining(usePipeliningCheck->isChecked()); - Settings::self()->setLeaveOnServer(leaveOnServerCheck->isChecked()); - Settings::self()->setLeaveOnServerDays(leaveOnServerCheck->isChecked() + mSettings.setName(nameEdit->text()); + mSettings.setIntervalCheckEnabled(intervalCheck->checkState() == Qt::Checked); + mSettings.setIntervalCheckInterval(intervalSpin->value()); + mSettings.setHost(hostEdit->text().trimmed()); + mSettings.setPort(portEdit->value()); + mSettings.setLogin(loginEdit->text().trimmed()); + mSettings.setPrecommand(precommand->text()); + mSettings.setUseSSL(encryptionSSL->isChecked()); + mSettings.setUseTLS(encryptionTLS->isChecked()); + mSettings.setAuthenticationMethod(authCombo->itemData(authCombo->currentIndex()).toInt()); + mSettings.setUseProxy(proxyCheck->isChecked()); + mSettings.setPipelining(usePipeliningCheck->isChecked()); + mSettings.setLeaveOnServer(leaveOnServerCheck->isChecked()); + mSettings.setLeaveOnServerDays(leaveOnServerCheck->isChecked() ? (leaveOnServerDaysCheck->isChecked() ? leaveOnServerDaysSpin->value() : -1) : 0); - Settings::self()->setLeaveOnServerCount(leaveOnServerCheck->isChecked() + mSettings.setLeaveOnServerCount(leaveOnServerCheck->isChecked() ? (leaveOnServerCountCheck->isChecked() ? leaveOnServerCountSpin->value() : -1) : 0); - Settings::self()->setLeaveOnServerSize(leaveOnServerCheck->isChecked() + mSettings.setLeaveOnServerSize(leaveOnServerCheck->isChecked() ? (leaveOnServerSizeCheck->isChecked() ? leaveOnServerSizeSpin->value() : -1) : 0); - Settings::self()->setFilterOnServer(filterOnServerCheck->isChecked()); - Settings::self()->setFilterCheckSize(filterOnServerSizeSpin->value()); - Settings::self()->setTargetCollection(folderRequester->collection().id()); - Settings::self()->save(); + mSettings.setFilterOnServer(filterOnServerCheck->isChecked()); + mSettings.setFilterCheckSize(filterOnServerSizeSpin->value()); + mSettings.setTargetCollection(folderRequester->collection().id()); + mSettings.save(); // Now, either save the password or delete it from the wallet. For both, we need // to open it. diff --git a/resources/pop3/jobs.h b/resources/pop3/jobs.h --- a/resources/pop3/jobs.h +++ b/resources/pop3/jobs.h @@ -35,12 +35,13 @@ } class SlaveBaseJob; +class Settings; class POPSession : public QObject { Q_OBJECT public: - explicit POPSession(const QString &password); + explicit POPSession(Settings &settings, const QString &password); ~POPSession(); bool connectSlave(); @@ -70,6 +71,7 @@ QPointer mSlave; SlaveBaseJob *mCurrentJob = nullptr; QString mPassword; + Settings &mSettings; }; class SlaveBaseJob : public KJob diff --git a/resources/pop3/jobs.cpp b/resources/pop3/jobs.cpp --- a/resources/pop3/jobs.cpp +++ b/resources/pop3/jobs.cpp @@ -29,9 +29,10 @@ #include "pop3resource_debug.h" #include -POPSession::POPSession(const QString &password) +POPSession::POPSession(Settings &settings, const QString &password) : mCurrentJob(nullptr) , mPassword(password) + , mSettings(settings) { KIO::Scheduler::connect(SIGNAL(slaveError(KIO::Slave*,int,QString)), this, SLOT(slotSlaveError(KIO::Slave*,int,QString))); } @@ -78,10 +79,10 @@ KIO::MetaData m; m.insert(QStringLiteral("progress"), QStringLiteral("off")); - m.insert(QStringLiteral("tls"), Settings::self()->useTLS() ? QStringLiteral("on") : QStringLiteral("off")); - m.insert(QStringLiteral("pipelining"), (Settings::self()->pipelining()) ? QStringLiteral("on") : QStringLiteral("off")); - m.insert(QStringLiteral("useProxy"), Settings::self()->useProxy() ? QStringLiteral("on") : QStringLiteral("off")); - int type = Settings::self()->authenticationMethod(); + m.insert(QStringLiteral("tls"), mSettings.useTLS() ? QStringLiteral("on") : QStringLiteral("off")); + m.insert(QStringLiteral("pipelining"), (mSettings.pipelining()) ? QStringLiteral("on") : QStringLiteral("off")); + m.insert(QStringLiteral("useProxy"), mSettings.useProxy() ? QStringLiteral("on") : QStringLiteral("off")); + int type = mSettings.authenticationMethod(); switch (type) { case MailTransport::Transport::EnumAuthenticationType::PLAIN: case MailTransport::Transport::EnumAuthenticationType::LOGIN: @@ -132,16 +133,16 @@ { QUrl url; - if (Settings::self()->useSSL()) { + if (mSettings.useSSL()) { url.setScheme(QStringLiteral("pop3s")); } else { url.setScheme(QStringLiteral("pop3")); } - url.setUserName(Settings::self()->login()); + url.setUserName(mSettings.login()); url.setPassword(mPassword); - url.setHost(Settings::self()->host()); - url.setPort(Settings::self()->port()); + url.setHost(mSettings.host()); + url.setPort(mSettings.port()); return url; } diff --git a/resources/pop3/pop3config.cpp b/resources/pop3/pop3config.cpp --- a/resources/pop3/pop3config.cpp +++ b/resources/pop3/pop3config.cpp @@ -19,35 +19,35 @@ #include -#include "settings.h" #include "accountwidget.h" +#include "settings.h" class Pop3Config : public Akonadi::AgentConfigurationBase { Q_OBJECT public: Pop3Config(const KSharedConfigPtr &config, QWidget *parent, const QVariantList &args) : Akonadi::AgentConfigurationBase(config, parent, args) - , mSettings(new Settings(config)) - , mWidget(new AccountWidget(identifier(), parent)) + , mSettings(config, Settings::Option::NoOption) + , mWidget(mSettings, identifier(), parent) { - connect(mWidget.data(), &AccountWidget::okEnabled, this, &Akonadi::AgentConfigurationBase::enableOkButton); + connect(&mWidget, &AccountWidget::okEnabled, this, &Akonadi::AgentConfigurationBase::enableOkButton); } void load() override { Akonadi::AgentConfigurationBase::load(); - mWidget->loadSettings(); + mWidget.loadSettings(); } bool save() const override { - mWidget->saveSettings(); + const_cast(this)->mWidget.saveSettings(); return Akonadi::AgentConfigurationBase::save(); } - QScopedPointer mSettings; - QScopedPointer mWidget; + Settings mSettings; + AccountWidget mWidget; }; AKONADI_AGENTCONFIG_FACTORY(Pop3ConfigFactory, "pop3config.json", Pop3Config) diff --git a/resources/pop3/pop3resource.h b/resources/pop3/pop3resource.h --- a/resources/pop3/pop3resource.h +++ b/resources/pop3/pop3resource.h @@ -24,6 +24,8 @@ #include #include +#include "settings.h" + class DeleteJob; namespace Akonadi { @@ -197,6 +199,8 @@ // Current deletion job in process DeleteJob *mDeleteJob = nullptr; + + Settings mSettings; }; #endif diff --git a/resources/pop3/pop3resource.cpp b/resources/pop3/pop3resource.cpp --- a/resources/pop3/pop3resource.cpp +++ b/resources/pop3/pop3resource.cpp @@ -51,19 +51,20 @@ : ResourceBase(id) , mState(Idle) , mIntervalTimer(new QTimer(this)) + , mSettings(KSharedConfig::openConfig()) + { - new Settings(KSharedConfig::openConfig()); Akonadi::AttributeFactory::registerAttribute(); setNeedsNetwork(true); - Settings::self()->setResourceId(identifier()); - if (Settings::self()->name().isEmpty()) { + mSettings.setResourceId(identifier()); + if (mSettings.name().isEmpty()) { if (name() == identifier()) { - Settings::self()->setName(i18n("POP3 Account")); + mSettings.setName(i18n("POP3 Account")); } else { - Settings::self()->setName(name()); + mSettings.setName(name()); } } - setName(Settings::self()->name()); + setName(mSettings.name()); resetState(); connect(this, &POP3Resource::abortRequested, this, &POP3Resource::slotAbortRequested); @@ -74,7 +75,7 @@ POP3Resource::~POP3Resource() { - Settings::self()->save(); + mSettings.save(); delete mWallet; mWallet = nullptr; } @@ -87,8 +88,8 @@ void POP3Resource::updateIntervalTimer() { - if (Settings::self()->intervalCheckEnabled() && mState == Idle) { - mIntervalTimer->start(Settings::self()->intervalCheckInterval() * 1000 * 60); + if (mSettings.intervalCheckEnabled() && mState == Idle) { + mIntervalTimer->start(mSettings.intervalCheckInterval() * 1000 * 60); } else { mIntervalTimer->stop(); } @@ -194,17 +195,17 @@ nullptr, KPasswordDialog::ShowUsernameLine); dlg->setModal(true); - dlg->setUsername(Settings::self()->login()); + dlg->setUsername(mSettings.login()); dlg->setPassword(mPassword); dlg->setPrompt(queryText); dlg->setWindowTitle(name()); dlg->addCommentLine(i18n("Account:"), name()); bool gotIt = false; if (dlg->exec()) { mPassword = dlg->password(); - Settings::self()->setLogin(dlg->username()); - Settings::self()->save(); + mSettings.setLogin(dlg->username()); + mSettings.save(); if (!dlg->password().isEmpty()) { mSavePassword = true; } @@ -236,7 +237,7 @@ { qCDebug(POP3RESOURCE_LOG) << "================ Starting state FetchTargetCollection =========="; Q_EMIT status(Running, i18n("Preparing transmission from \"%1\".", name())); - Collection targetCollection(Settings::self()->targetCollection()); + Collection targetCollection(mSettings.targetCollection()); if (targetCollection.isValid()) { CollectionFetchJob *fetchJob = new CollectionFetchJob(targetCollection, CollectionFetchJob::Base); @@ -253,8 +254,8 @@ } case Precommand: qCDebug(POP3RESOURCE_LOG) << "================ Starting state Precommand ====================="; - if (!Settings::self()->precommand().isEmpty()) { - PrecommandJob *precommandJob = new PrecommandJob(Settings::self()->precommand(), this); + if (!mSettings.precommand().isEmpty()) { + PrecommandJob *precommandJob = new PrecommandJob(mSettings.precommand(), this); connect(precommandJob, &PrecommandJob::result, this, &POP3Resource::precommandResult); precommandJob->start(); Q_EMIT status(Running, i18n("Executing precommand.")); @@ -267,14 +268,14 @@ qCDebug(POP3RESOURCE_LOG) << "================ Starting state RequestPassword ================"; // Don't show any wallet or password prompts when we are unit-testing - if (!Settings::self()->unitTestPassword().isEmpty()) { - mPassword = Settings::self()->unitTestPassword(); + if (!mSettings.unitTestPassword().isEmpty()) { + mPassword = mSettings.unitTestPassword(); advanceState(Connect); break; } - const bool passwordNeeded = Settings::self()->authenticationMethod() != MailTransport::Transport::EnumAuthenticationType::GSSAPI; - const bool loadPasswordFromWallet = !mAskAgain && passwordNeeded && !Settings::self()->login().isEmpty() + const bool passwordNeeded = mSettings.authenticationMethod() != MailTransport::Transport::EnumAuthenticationType::GSSAPI; + const bool loadPasswordFromWallet = !mAskAgain && passwordNeeded && !mSettings.login().isEmpty() && mPassword.isEmpty(); if (loadPasswordFromWallet) { mWallet = Wallet::openWallet(Wallet::NetworkWallet(), winIdForDialogs(), @@ -286,7 +287,7 @@ QString detail; if (mAskAgain) { detail = i18n("You are asked here because the previous login was not successful."); - } else if (Settings::self()->login().isEmpty()) { + } else if (mSettings.login().isEmpty()) { detail = i18n("You are asked here because the username you supplied is empty."); } else if (!mWallet) { detail = i18n("You are asked here because the wallet password storage is disabled."); @@ -303,7 +304,7 @@ case Connect: qCDebug(POP3RESOURCE_LOG) << "================ Starting state Connect ========================"; Q_ASSERT(!mPopSession); - mPopSession = new POPSession(mPassword); + mPopSession = new POPSession(mSettings, mPassword); connect(mPopSession, &POPSession::slaveError, this, &POP3Resource::slotSessionError); advanceState(Login); break; @@ -341,7 +342,7 @@ // currently on ther server, minus the ones we have already downloaded (we // remember which UIDs we have downloaded in the settings) QList idsToDownload = mIdsToSizeMap.keys(); - const QStringList alreadyDownloadedUIDs = Settings::self()->seenUidList(); + const QStringList alreadyDownloadedUIDs = mSettings.seenUidList(); foreach (const QString &uidOnServer, mIdsToUidsMap) { if (alreadyDownloadedUIDs.contains(uidOnServer)) { const int idOfUIDOnServer = mUidsToIdsMap.value(uidOnServer, -1); @@ -459,7 +460,7 @@ if (job->error()) { if (!mTestLocalInbox) { mTestLocalInbox = true; - Settings::self()->setTargetCollection(-1); + mSettings.setTargetCollection(-1); advanceState(FetchTargetCollection); return; } else { @@ -502,7 +503,7 @@ if (job->error() == KIO::ERR_CANNOT_LOGIN) { mAskAgain = true; } - cancelSync(i18n("Unable to login to the server %1.", Settings::self()->host()) + cancelSync(i18n("Unable to login to the server %1.", mSettings.host()) +QLatin1Char('\n') + job->errorString()); } else { advanceState(List); @@ -538,7 +539,7 @@ qCDebug(POP3RESOURCE_LOG) << "UidsToIdsMap size" << mUidsToIdsMap.size(); mUidListValid = !mIdsToUidsMap.isEmpty() || mIdsToSizeMap.isEmpty(); - if (Settings::self()->leaveOnServer() && !mUidListValid) { + if (mSettings.leaveOnServer() && !mUidListValid) { // FIXME: this needs a proper parent window KMessageBox::sorry(nullptr, i18n("Your POP3 server (Account: %1) does not support " @@ -605,14 +606,14 @@ QString statusMessage; const int totalMessages = mIdsToDownload.size() + mDownloadedIDs.size(); int bytesRemainingOnServer = 0; - foreach (const QString &alreadyDownloadedUID, Settings::self()->seenUidList()) { + foreach (const QString &alreadyDownloadedUID, mSettings.seenUidList()) { const int alreadyDownloadedID = mUidsToIdsMap.value(alreadyDownloadedUID, -1); if (alreadyDownloadedID != -1) { bytesRemainingOnServer += mIdsToSizeMap.value(alreadyDownloadedID); } } - if (Settings::self()->leaveOnServer() && bytesRemainingOnServer > 0) { + if (mSettings.leaveOnServer() && bytesRemainingOnServer > 0) { statusMessage = i18n("Fetching message %1 of %2 (%3 of %4 KB) for %5 " "(%6 KB remain on the server).", mDownloadedIDs.size() + 1, totalMessages, @@ -675,8 +676,8 @@ { const QString uid = mIdsToUidsMap.value(id); if (!uid.isEmpty()) { - const QList seenUIDs = Settings::self()->seenUidList(); - const QList timeOfSeenUids = Settings::self()->seenUidTimeList(); + const QList seenUIDs = mSettings.seenUidList(); + const QList timeOfSeenUids = mSettings.seenUidTimeList(); Q_ASSERT(seenUIDs.size() == timeOfSeenUids.size()); const int index = seenUIDs.indexOf(uid); if (index != -1 && (index < timeOfSeenUids.size())) { @@ -709,7 +710,7 @@ QList idsToDeleteFromServer; // By default, we delete all messages. But if we have "leave on server" // rules, we can save some messages. - if (Settings::self()->leaveOnServer()) { + if (mSettings.leaveOnServer()) { idsToDeleteFromServer = mIdsToSizeMap.keys(); if (!mIdsToSaveValid) { mIdsToSaveValid = true; @@ -723,9 +724,9 @@ // If the time-limited leave rule is checked, add the newer messages to // the list of messages to keep - if (Settings::self()->leaveOnServerDays() > 0) { + if (mSettings.leaveOnServerDays() > 0) { const int secondsPerDay = 86400; - time_t timeLimit = time(nullptr) - (secondsPerDay * Settings::self()->leaveOnServerDays()); + time_t timeLimit = time(nullptr) - (secondsPerDay * mSettings.leaveOnServerDays()); foreach (int idToDelete, idsOnServer) { const int msgTime = idToTime(idToDelete); if (msgTime >= timeLimit) { @@ -745,8 +746,8 @@ // // Delete more old messages if there are more than mLeaveOnServerCount // - if (Settings::self()->leaveOnServerCount() > 0) { - const int numToDelete = mIdsToSave.count() - Settings::self()->leaveOnServerCount(); + if (mSettings.leaveOnServerCount() > 0) { + const int numToDelete = mIdsToSave.count() - mSettings.leaveOnServerCount(); if (numToDelete > 0 && numToDelete < mIdsToSave.count()) { // Get rid of the first numToDelete messages for (int i = 0; i < numToDelete; i++) { @@ -760,8 +761,8 @@ // // Delete more old messages until we're under mLeaveOnServerSize MBs // - if (Settings::self()->leaveOnServerSize() > 0) { - const qint64 limitInBytes = Settings::self()->leaveOnServerSize() * (1024 * 1024); + if (mSettings.leaveOnServerSize() > 0) { + const qint64 limitInBytes = mSettings.leaveOnServerSize() * (1024 * 1024); qint64 sizeOnServerAfterDeletion = 0; for (int id : qAsConst(mIdsToSave)) { sizeOnServerAfterDeletion += mIdsToSizeMap.value(id); @@ -806,8 +807,8 @@ // Remove all deleted messages from the list of already downloaded messages, // as it is no longer necessary to store them (they just waste space) - QList seenUIDs = Settings::self()->seenUidList(); - QList timeOfSeenUids = Settings::self()->seenUidTimeList(); + QList seenUIDs = mSettings.seenUidList(); + QList timeOfSeenUids = mSettings.seenUidTimeList(); Q_ASSERT(seenUIDs.size() == timeOfSeenUids.size()); foreach (int deletedId, mDeletedIDs) { const QString deletedUID = mIdsToUidsMap.value(deletedId); @@ -823,9 +824,9 @@ mIdsToUidsMap.remove(deletedId); mIdsToSizeMap.remove(deletedId); } - Settings::self()->setSeenUidList(seenUIDs); - Settings::self()->setSeenUidTimeList(timeOfSeenUids); - Settings::self()->save(); + mSettings.setSeenUidList(seenUIDs); + mSettings.setSeenUidTimeList(timeOfSeenUids); + mSettings.save(); mDeleteJob = nullptr; if (!mIdsWaitingToDelete.isEmpty()) { @@ -885,8 +886,8 @@ void POP3Resource::saveSeenUIDList() { - QList seenUIDs = Settings::self()->seenUidList(); - QList timeOfSeenUIDs = Settings::self()->seenUidTimeList(); + QList seenUIDs = mSettings.seenUidList(); + QList timeOfSeenUIDs = mSettings.seenUidTimeList(); // // Find the messages that we have successfully stored, but did not actually get @@ -942,9 +943,9 @@ // Now save it in the settings // qCDebug(POP3RESOURCE_LOG) << "The seen UID list has" << seenUIDs.size() << "entries"; - Settings::self()->setSeenUidList(seenUIDs); - Settings::self()->setSeenUidTimeList(timeOfSeenUIDs); - Settings::self()->save(); + mSettings.setSeenUidList(seenUIDs); + mSettings.setSeenUidTimeList(timeOfSeenUIDs); + mSettings.save(); } void POP3Resource::cancelSync(const QString &errorMessage, bool error) diff --git a/resources/pop3/settings.h b/resources/pop3/settings.h --- a/resources/pop3/settings.h +++ b/resources/pop3/settings.h @@ -22,6 +22,7 @@ #include "settingsbase.h" #include +#include /** * Extended settings class that allows setting the password over dbus, which is used by the @@ -32,17 +33,24 @@ Q_OBJECT Q_CLASSINFO("D-Bus Interface", "org.kde.Akonadi.POP3.Wallet") public: - Settings(const KSharedConfigPtr &config); + enum class Option { + NoOption = 0, + ExportToDBus = 1 + }; + Q_DECLARE_FLAGS(Options, Option) + + explicit Settings(const KSharedConfigPtr &config, Options options = Option::ExportToDBus); void setWindowId(WId id); void setResourceId(const QString &resourceIdentifier); - static Settings *self(); public Q_SLOTS: Q_SCRIPTABLE void setPassword(const QString &password); private: WId mWinId; QString mResourceId; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(Settings::Options) + #endif diff --git a/resources/pop3/settings.cpp b/resources/pop3/settings.cpp --- a/resources/pop3/settings.cpp +++ b/resources/pop3/settings.cpp @@ -22,39 +22,14 @@ #include #include "pop3resource_debug.h" -class SettingsHelper -{ -public: - SettingsHelper() : q(nullptr) - { - } - - ~SettingsHelper() - { - qCWarning(POP3RESOURCE_LOG) << q; - delete q; - q = nullptr; - } - - Settings *q; -}; - -Q_GLOBAL_STATIC(SettingsHelper, s_globalSettings) - -Settings *Settings::self() -{ - Q_ASSERT_X(s_globalSettings->q, "Settings::self()", "You must create an instance first!"); - return s_globalSettings->q; -} - -Settings::Settings(const KSharedConfigPtr &config) +Settings::Settings(const KSharedConfigPtr &config, Options options) : SettingsBase(config) { - Q_ASSERT(!s_globalSettings->q); - s_globalSettings->q = this; - new SettingsAdaptor(this); - QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"), this, - QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableContents); + if (options & Option::ExportToDBus) { + new SettingsAdaptor(this); + QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"), this, + QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableContents); + } } void Settings::setWindowId(WId id)