Commit 51949fb4 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to make it async

parent b8df8805
......@@ -19,7 +19,8 @@
#include "abstractimapsettingspassword.h"
AbstractImapSettingsPassword::AbstractImapSettingsPassword()
AbstractImapSettingsPassword::AbstractImapSettingsPassword(QObject *parent)
: QObject(parent)
{
}
......@@ -29,7 +30,7 @@ AbstractImapSettingsPassword::~AbstractImapSettingsPassword()
void AbstractImapSettingsPassword::importPasswords(SieveEditorUtil::SieveServerConfig &config, const QString &filename, bool reuseImapSettings)
{
Q_UNUSED(config);
Q_UNUSED(filename);
Q_UNUSED(reuseImapSettings);
Q_UNUSED(config)
Q_UNUSED(filename)
Q_UNUSED(reuseImapSettings)
}
......@@ -23,14 +23,17 @@
#include <sieveeditorutil.h>
#include "libsieveeditor_private_export.h"
class LIBSIEVEEDITOR_TESTS_EXPORT AbstractImapSettingsPassword
class LIBSIEVEEDITOR_TESTS_EXPORT AbstractImapSettingsPassword : public QObject
{
Q_OBJECT
public:
AbstractImapSettingsPassword();
virtual ~AbstractImapSettingsPassword();
explicit AbstractImapSettingsPassword(QObject *parent = nullptr);
~AbstractImapSettingsPassword() override;
virtual void importPasswords(SieveEditorUtil::SieveServerConfig &config, const QString &filename, bool reuseImapSettings);
Q_SIGNALS:
void importPasswordDone();
void importPasswordDone(const QString &filename);
protected:
QString mFileName;
};
#endif // ABSTRACTIMAPSETTINGSPASSWORD_H
......@@ -31,6 +31,8 @@
ImportImapSettingsAkonadiCheckJob::ImportImapSettingsAkonadiCheckJob(QObject *parent)
: AbstractImapSettingsCheckJob(parent)
{
connect(mPasswordImporter, &AbstractImapSettingsPassword::importPasswordDone,
this, &ImportImapSettingsAkonadiCheckJob::slotImportNextServerSieveDone);
}
ImportImapSettingsAkonadiCheckJob::~ImportImapSettingsAkonadiCheckJob()
......@@ -58,14 +60,30 @@ void ImportImapSettingsAkonadiCheckJob::start()
loadSieveServerSettings();
}
void ImportImapSettingsAkonadiCheckJob::slotImportNextServerSieveDone(const QString &filename)
{
if (mCurrentSieveServerConfig.isValid()) {
Q_EMIT importSetting(filename, mCurrentSieveServerConfig);
mSettingsWereImported = true;
}
}
void ImportImapSettingsAkonadiCheckJob::loadSieveServerSettings()
{
QMap<QString, QString>::const_iterator i = mSieveServerLst.constBegin();
while (i != mSieveServerLst.constEnd()) {
importSettings(i.key(), i.value());
++i;
mSieveServerMapIterator = mSieveServerLst.constBegin();
if (mSieveServerMapIterator != mSieveServerLst.constEnd()) {
importSettings(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
}
}
void ImportImapSettingsAkonadiCheckJob::importNextServerSieve()
{
++mSieveServerMapIterator;
if(mSieveServerMapIterator != mSieveServerLst.constEnd()) {
importSettings(mSieveServerMapIterator.key(), mSieveServerMapIterator.value());
} else {
checkNoSettingsImported();
}
checkNoSettingsImported();
}
void ImportImapSettingsAkonadiCheckJob::importSettings(const QString &directory, const QString &filename)
......@@ -74,9 +92,10 @@ void ImportImapSettingsAkonadiCheckJob::importSettings(const QString &directory,
//qCDebug(SIEVEEDITOR_LOG) << "importSettings filename:" << filePath;
if (!QFileInfo::exists(filePath)) {
qCWarning(SIEVEEDITOR_LOG) << "Unable to open file " << filePath;
importNextServerSieve();
return;
}
SieveEditorUtil::SieveServerConfig config;
mCurrentSieveServerConfig = {};
const bool isKolabSettings = filePath.contains(QLatin1String("/akonadi_kolab_resource"));
KSharedConfigPtr resourceConfig = KSharedConfig::openConfig(filePath);
......@@ -88,51 +107,47 @@ void ImportImapSettingsAkonadiCheckJob::importSettings(const QString &directory,
const QString userName = networkGroup.readEntry(QStringLiteral("UserName"), QString());
const QString imapServerName = networkGroup.readEntry(QStringLiteral("ImapServer"), QString());
const int imapPort = networkGroup.readEntry(QStringLiteral("ImapPort"), isKolabSettings ? 143 : 993);
config.sieveImapAccountSettings.setUserName(userName);
config.sieveImapAccountSettings.setServerName(imapServerName);
config.sieveImapAccountSettings.setPort(imapPort);
config.sieveImapAccountSettings.setAuthenticationType(
mCurrentSieveServerConfig.sieveImapAccountSettings.setUserName(userName);
mCurrentSieveServerConfig.sieveImapAccountSettings.setServerName(imapServerName);
mCurrentSieveServerConfig.sieveImapAccountSettings.setPort(imapPort);
mCurrentSieveServerConfig.sieveImapAccountSettings.setAuthenticationType(
static_cast<KSieveUi::SieveImapAccountSettings::AuthenticationMode>(
networkGroup.readEntry(QStringLiteral("Authentication"),
static_cast<int>(KSieveUi::SieveImapAccountSettings::Plain))));
const QString encryption = networkGroup.readEntry(QStringLiteral("Safety"));
if (encryption == QLatin1String("SSL")) {
config.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::SSLorTLS);
mCurrentSieveServerConfig.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::SSLorTLS);
} else if (encryption == QLatin1String("STARTTLS")) {
config.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::STARTTLS);
mCurrentSieveServerConfig.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::STARTTLS);
} else if (encryption == QLatin1String("None")) {
config.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::Unencrypted);
mCurrentSieveServerConfig.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::Unencrypted);
} else if (encryption.isEmpty()) { //Default value
if (isKolabSettings) {
config.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::STARTTLS);
mCurrentSieveServerConfig.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::STARTTLS);
} else {
config.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::Unencrypted);
mCurrentSieveServerConfig.sieveImapAccountSettings.setEncryptionMode(KSieveUi::SieveImapAccountSettings::EncryptionMode::Unencrypted);
}
} else {
qCWarning(SIEVEEDITOR_LOG) << "Unknown encryption mode " << encryption;
}
const int sievePort = sieveGroup.readEntry(QStringLiteral("SievePort"), 4190);
if (sievePort != -1) {
config.sieveSettings.port = sievePort;
mCurrentSieveServerConfig.sieveSettings.port = sievePort;
}
if (reuseImapSettings) {
config.sieveSettings.serverName = imapServerName;
config.sieveSettings.userName = userName;
config.sieveSettings.authenticationType
mCurrentSieveServerConfig.sieveSettings.serverName = imapServerName;
mCurrentSieveServerConfig.sieveSettings.userName = userName;
mCurrentSieveServerConfig.sieveSettings.authenticationType
= static_cast<MailTransport::Transport::EnumAuthenticationType::type>(sieveGroup.readEntry(QStringLiteral("Authentication"),
static_cast<int>(MailTransport::Transport::EnumAuthenticationType::PLAIN)));
} else {
const QString sieveCustomUserName = sieveGroup.readEntry(QStringLiteral("SieveCustomUsername"));
config.sieveSettings.userName = sieveCustomUserName;
config.sieveSettings.serverName = imapServerName; //FIXME
mCurrentSieveServerConfig.sieveSettings.userName = sieveCustomUserName;
mCurrentSieveServerConfig.sieveSettings.serverName = imapServerName; //FIXME
//TODO
}
Q_ASSERT_X(mPasswordImporter, "Missing mPasswordImporter", "You must create a mPasswordImporter");
mPasswordImporter->importPasswords(config, filename, reuseImapSettings);
if (config.isValid()) {
Q_EMIT importSetting(filename, config);
mSettingsWereImported = true;
}
mPasswordImporter->importPasswords(mCurrentSieveServerConfig, filename, reuseImapSettings);
}
}
......
......@@ -37,8 +37,12 @@ public:
private:
inline Q_REQUIRED_RESULT bool resourceCanHaveSieveSupport(const QString &filename) const;
void loadSieveServerSettings();
void slotImportNextServerSieveDone(const QString &filename);
void importNextServerSieve();
void importSettings(const QString &directory, const QString &filename);
QMultiMap<QString, QString> mSieveServerLst;
QMap<QString, QString>::const_iterator mSieveServerMapIterator;
SieveEditorUtil::SieveServerConfig mCurrentSieveServerConfig;
};
#endif // IMPORTIMAPSETTINGSAKONADICHECKJOB_H
......@@ -21,8 +21,8 @@
#include "sieveserversettings.h"
#include <KWallet>
ImportImapSettingsAkonadiPassword::ImportImapSettingsAkonadiPassword()
: AbstractImapSettingsPassword()
ImportImapSettingsAkonadiPassword::ImportImapSettingsAkonadiPassword(QObject *parent)
: AbstractImapSettingsPassword(parent)
{
}
......@@ -32,6 +32,7 @@ ImportImapSettingsAkonadiPassword::~ImportImapSettingsAkonadiPassword()
void ImportImapSettingsAkonadiPassword::importPasswords(SieveEditorUtil::SieveServerConfig &config, const QString &filename, bool reuseImapSettings)
{
mFileName = filename;
KWallet::Wallet *wallet = SieveServerSettings::self()->wallet();
QString password;
QString customPassword;
......@@ -55,4 +56,5 @@ void ImportImapSettingsAkonadiPassword::importPasswords(SieveEditorUtil::SieveSe
}
}
}
Q_EMIT importPasswordDone(mFileName);
}
......@@ -24,8 +24,9 @@
class ImportImapSettingsAkonadiPassword : public AbstractImapSettingsPassword
{
Q_OBJECT
public:
ImportImapSettingsAkonadiPassword();
explicit ImportImapSettingsAkonadiPassword(QObject *parent = nullptr);
~ImportImapSettingsAkonadiPassword() override;
void importPasswords(SieveEditorUtil::SieveServerConfig &config, const QString &filename, bool reuseImapSettings) override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment