Commit bfeff212 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Port to qt5keychain

parent 662c4ffb
Pipeline #41290 failed with stage
in 10 minutes and 30 seconds
......@@ -224,36 +224,23 @@ void AccountWidget::walletOpenedForLoading(QKeychain::Job *baseJob)
}
}
void AccountWidget::walletOpenedForSaving(bool success)
void AccountWidget::walletOpenedForSaving()
{
#if 0
//Move as async
if (success) {
if (mWallet && mWallet->isOpen()) {
// Remove the password from the wallet if the user doesn't want to store it
if (passwordEdit->password().isEmpty() && mWallet->hasFolder(QStringLiteral("pop3"))) {
mWallet->setFolder(QStringLiteral("pop3"));
mWallet->removeEntry(mIdentifier);
}
// Store the password in the wallet if the user wants that
else if (!passwordEdit->password().isEmpty()) {
if (!mWallet->hasFolder(QStringLiteral("pop3"))) {
mWallet->createFolder(QStringLiteral("pop3"));
}
mWallet->setFolder(QStringLiteral("pop3"));
mWallet->writePassword(mIdentifier, passwordEdit->password());
}
} else {
qCWarning(POP3RESOURCE_LOG) << "Wallet not open.";
}
if (passwordEdit->password().isEmpty()) {
auto deleteJob = new DeletePasswordJob(QStringLiteral("pop3"));
deleteJob->setKey(mIdentifier);
deleteJob->start();
} else {
// Should we alert the user here?
qCWarning(POP3RESOURCE_LOG) << "Failed to open wallet for saving the password.";
auto writeJob = new WritePasswordJob(QStringLiteral("pop3"), this);
connect(writeJob, &QKeychain::Job::finished, this, [](QKeychain::Job *baseJob) {
if (baseJob->error()) {
qCWarning(POP3RESOURCE_LOG) << "Error writing password using QKeychain:" << baseJob->errorString();
}
});
writeJob->setKey(mIdentifier);
writeJob->setTextData(passwordEdit->password());
writeJob->start();
}
delete mWallet;
mWallet = nullptr;
#endif
}
void AccountWidget::slotLeaveOnServerClicked()
......@@ -557,24 +544,10 @@ void AccountWidget::saveSettings()
const bool userWantsToDeletePassword
= passwordEdit->password().isEmpty() && userChangedPassword;
//Move to async
#if 0
if ((!passwordEdit->password().isEmpty() && userChangedPassword)
|| userWantsToDeletePassword) {
qCDebug(POP3RESOURCE_LOG) << mWallet << mWallet->isOpen();
if (mWallet && mWallet->isOpen()) {
// wallet is already open
walletOpenedForSaving(true);
} else {
// we need to open the wallet
qCDebug(POP3RESOURCE_LOG) << "we need to open the wallet";
mWallet = Wallet::openWallet(Wallet::NetworkWallet(), winId(),
Wallet::Synchronous);
if (mWallet) {
walletOpenedForSaving(true);
}
}
walletOpenedForSaving();
}
#endif
}
void AccountWidget::slotEnableLeaveOnServerDays(bool state)
......
......@@ -18,9 +18,6 @@ class Settings;
namespace MailTransport {
class ServerTest;
}
namespace KWallet {
class Wallet;
}
class KJob;
......@@ -56,7 +53,7 @@ private Q_SLOTS:
void targetCollectionReceived(Akonadi::Collection::List collections);
void localFolderRequestJobFinished(KJob *job);
void walletOpenedForLoading(QKeychain::Job *baseJob);
void walletOpenedForSaving(bool success);
void walletOpenedForSaving();
void slotAccepted();
private:
void setupWidgets();
......
......@@ -6,8 +6,8 @@
#include "settings.h"
#include "settingsadaptor.h"
#include <KWallet>
#include <qt5keychain/keychain.h>
using namespace QKeychain;
#include "pop3resource_debug.h"
Settings::Settings(const KSharedConfigPtr &config, Options options)
......@@ -32,17 +32,13 @@ void Settings::setResourceId(const QString &resourceIdentifier)
void Settings::setPassword(const QString &password)
{
using namespace KWallet;
Wallet *wallet = Wallet::openWallet(Wallet::NetworkWallet(), mWinId,
Wallet::Synchronous);
if (wallet && wallet->isOpen()) {
if (!wallet->hasFolder(QStringLiteral("pop3"))) {
wallet->createFolder(QStringLiteral("pop3"));
auto writeJob = new WritePasswordJob(QStringLiteral("pop3"), this);
connect(writeJob, &QKeychain::Job::finished, this, [](QKeychain::Job *baseJob) {
if (baseJob->error()) {
qCWarning(POP3RESOURCE_LOG) << "Error writing password using QKeychain:" << baseJob->errorString();
}
wallet->setFolder(QStringLiteral("pop3"));
wallet->writePassword(mResourceId, password);
} else {
qCWarning(POP3RESOURCE_LOG) << "Unable to open wallet!";
}
delete wallet;
});
writeJob->setKey(mIdentifier);
writeJob->setTextData(password);
writeJob->start();
}
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