Commit 366358a1 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Continue to port to qtr5keychain

parent e348ebb6
Pipeline #41693 passed with stage
in 10 minutes and 55 seconds
......@@ -18,7 +18,8 @@
#include <KMessageBox>
#include <KStringHandler>
#include <KWallet/KWallet>
#include <qt5keychain/keychain.h>
using namespace QKeychain;
using namespace MailTransport;
using namespace KWallet;
......@@ -31,7 +32,6 @@ Transport::Transport(const QString &cfgGroup)
d->passwordDirty = false;
d->storePasswordInFile = false;
d->needsWalletMigration = false;
d->passwordNeedsUpdateFromWallet = false;
load();
}
......@@ -169,20 +169,6 @@ void Transport::usrRead()
}
if (d->passwordLoaded) {
if (d->passwordNeedsUpdateFromWallet) {
d->passwordNeedsUpdateFromWallet = false;
// read password if wallet is open, defer otherwise
if (Wallet::isOpen(Wallet::NetworkWallet())) {
// Don't read the password right away because this can lead
// to reentrancy problems in KDBusServiceStarter when an application
// run in Kontact creates the transports (due to a QEventLoop in the
// synchronous KWallet openWallet call).
QTimer::singleShot(0, this, &Transport::readPassword);
} else {
d->passwordLoaded = false;
}
}
return;
}
......@@ -253,17 +239,24 @@ void Transport::readPassword()
}
d->passwordLoaded = true;
// finally try to open the wallet and read the password
KWallet::Wallet *wallet = TransportManager::self()->wallet();
if (wallet) {
QString pwd;
if (wallet->readPassword(QString::number(id()), pwd) == 0) {
setPassword(pwd);
} else {
d->password.clear();
d->passwordLoaded = false;
}
auto readJob = new ReadPasswordJob(WALLET_FOLDER, this);
connect(readJob, &Job::finished, this, &Transport::readTransportPasswordFinished);
readJob->setKey(QString::number(id()));
readJob->start();
}
void Transport::readTransportPasswordFinished(QKeychain::Job *baseJob)
{
auto *job = qobject_cast<ReadPasswordJob *>(baseJob);
Q_ASSERT(job);
if (job->error()) {
d->password.clear();
d->passwordLoaded = false;
qWarning() << "We have an error during reading password " << job->errorString();
} else {
setPassword(job->textData());
}
}
bool Transport::needsWalletMigration() const
......
......@@ -12,7 +12,9 @@
#include <transporttype.h>
class TransportPrivate;
namespace QKeychain {
class Job;
}
namespace MailTransport {
class TransportType;
......@@ -137,6 +139,7 @@ private Q_SLOTS:
void readPassword();
private:
void readTransportPasswordFinished(QKeychain::Job *baseJob);
TransportPrivate *const d;
};
} // namespace MailTransport
......
......@@ -23,7 +23,6 @@ public:
bool passwordDirty;
bool storePasswordInFile;
bool needsWalletMigration;
bool passwordNeedsUpdateFromWallet;
};
#endif
......@@ -405,42 +405,6 @@ void TransportManager::removeTransport(int id)
void TransportManagerPrivate::readConfig()
{
QList<Transport *> oldTransports = transports;
transports.clear();
QRegularExpression re(QStringLiteral("^Transport (.+)$"));
const QStringList groups = config->groupList().filter(re);
for (const QString &s : groups) {
QRegularExpressionMatch match = re.match(s);
if (!match.hasMatch()) {
continue;
}
Transport *t = nullptr;
// see if we happen to have that one already
for (Transport *old : oldTransports) {
if (old->currentGroup() == QLatin1String("Transport ") + match.captured(1)) {
qCDebug(MAILTRANSPORT_LOG) << "reloading existing transport:" << s;
t = old;
t->d->passwordNeedsUpdateFromWallet = true;
t->load();
oldTransports.removeAll(old);
break;
}
}
if (!t) {
t = new Transport(match.captured(1));
}
if (t->id() <= 0) {
t->setId(createId());
t->save();
}
transports.append(t);
}
qDeleteAll(oldTransports);
oldTransports.clear();
// read default transport
KConfigGroup group(config, "General");
defaultTransportId = group.readEntry("default-transport", 0);
......
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