File indexing completed on 2024-11-24 04:44:33

0001 /*
0002    SPDX-FileCopyrightText: 2010 Thomas McGuire <mcguire@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "settings.h"
0008 #include "settingsadaptor.h"
0009 #include <qt6keychain/keychain.h>
0010 using namespace QKeychain;
0011 #include "pop3resource_debug.h"
0012 
0013 Settings::Settings(const KSharedConfigPtr &config, Options options)
0014     : SettingsBase(config)
0015 {
0016     if (options & Option::ExportToDBus) {
0017         new SettingsAdaptor(this);
0018         QDBusConnection::sessionBus().registerObject(QStringLiteral("/Settings"),
0019                                                      this,
0020                                                      QDBusConnection::ExportAdaptors | QDBusConnection::ExportScriptableContents);
0021     }
0022 }
0023 
0024 void Settings::setWindowId(WId id)
0025 {
0026     mWinId = id;
0027 }
0028 
0029 void Settings::setResourceId(const QString &resourceIdentifier)
0030 {
0031     mResourceId = resourceIdentifier;
0032 }
0033 
0034 void Settings::setPassword(const QString &password)
0035 {
0036     auto writeJob = new WritePasswordJob(QStringLiteral("pop3"), this);
0037     connect(writeJob, &QKeychain::Job::finished, this, [](QKeychain::Job *baseJob) {
0038         if (baseJob->error()) {
0039             qCWarning(POP3RESOURCE_LOG) << "Error writing password using QKeychain:" << baseJob->errorString();
0040         }
0041     });
0042     writeJob->setKey(mResourceId);
0043     writeJob->setTextData(password);
0044     writeJob->start();
0045 }
0046 
0047 #include "moc_settings.cpp"