File indexing completed on 2024-12-15 04:55:35
0001 /* 0002 SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "importimapsettingsakonadipassword.h" 0008 #include "sieveeditor_debug.h" 0009 #include "sieveserversettings.h" 0010 0011 using namespace QKeychain; 0012 0013 ImportImapSettingsAkonadiPassword::ImportImapSettingsAkonadiPassword(QObject *parent) 0014 : AbstractImapSettingsPassword(parent) 0015 { 0016 } 0017 0018 ImportImapSettingsAkonadiPassword::~ImportImapSettingsAkonadiPassword() = default; 0019 0020 void ImportImapSettingsAkonadiPassword::readSieveServerPasswordFinished(QKeychain::Job *baseJob) 0021 { 0022 auto job = qobject_cast<ReadPasswordJob *>(baseJob); 0023 Q_ASSERT(job); 0024 if (!job->error()) { 0025 mCurrentConfig.sieveImapAccountSettings.setPassword(job->textData()); 0026 } else { 0027 qCWarning(SIEVEEDITOR_LOG) << "An error occurred while reading password: " << job->errorString(); 0028 } 0029 0030 if (mReuseImapSettings) { 0031 mCurrentConfig.sieveSettings.password = mCurrentConfig.sieveImapAccountSettings.password(); 0032 Q_EMIT importPasswordDone(mCurrentConfig, mFileName); 0033 } else { 0034 loadImapAccountSettings(); 0035 } 0036 } 0037 0038 void ImportImapSettingsAkonadiPassword::readSieveServerCustomPasswordFinished(Job *baseJob) 0039 { 0040 auto job = qobject_cast<ReadPasswordJob *>(baseJob); 0041 Q_ASSERT(job); 0042 if (!job->error()) { 0043 mCurrentConfig.sieveSettings.password = job->textData(); 0044 } else { 0045 qCWarning(SIEVEEDITOR_LOG) << "An error occurred while reading password: " << job->errorString(); 0046 } 0047 Q_EMIT importPasswordDone(mCurrentConfig, mFileName); 0048 } 0049 0050 void ImportImapSettingsAkonadiPassword::loadImapAccountSettings() 0051 { 0052 auto readJob = new ReadPasswordJob(QStringLiteral("imap"), this); 0053 connect(readJob, &Job::finished, this, &ImportImapSettingsAkonadiPassword::readSieveServerCustomPasswordFinished); 0054 readJob->setKey(QStringLiteral("custom_sieve_") + mFileName); 0055 readJob->start(); 0056 } 0057 0058 void ImportImapSettingsAkonadiPassword::importPasswords(const SieveEditorUtil::SieveServerConfig &_config, const QString &filename, bool reuseImapSettings) 0059 { 0060 mCurrentConfig = _config; 0061 mReuseImapSettings = reuseImapSettings; 0062 mFileName = filename; 0063 auto readJob = new ReadPasswordJob(QStringLiteral("imap"), this); 0064 connect(readJob, &Job::finished, this, &ImportImapSettingsAkonadiPassword::readSieveServerPasswordFinished); 0065 readJob->setKey(mFileName); 0066 readJob->start(); 0067 } 0068 0069 #include "moc_importimapsettingsakonadipassword.cpp"