[office/kmymoney] /: Migrate to QtKeyChain from KWallet
Dawid Wróbel
null at kde.org
Mon Oct 10 17:06:44 BST 2022
Git commit 80a6a4b251e4e5efaecccc11a990e739708879d2 by Dawid Wróbel, on behalf of Dawid Wróbel.
Committed on 10/10/2022 at 16:06.
Pushed by wrobelda into branch 'master'.
Migrate to QtKeyChain from KWallet
M +3 -1 CMakeLists.txt
M +1 -1 doc/firsttime.docbook
M +23 -0 kmymoney/misc/CMakeLists.txt
A +103 -0 kmymoney/misc/kmmkeychain.cpp [License: BSD]
A +41 -0 kmymoney/misc/kmmkeychain.h [License: BSD]
M +1 -0 kmymoney/mymoney/CMakeLists.txt
M +1 -1 kmymoney/plugins/ofx/import/CMakeLists.txt
M +13 -1 kmymoney/plugins/ofx/import/dialogs/CMakeLists.txt
M +14 -33 kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.cpp
M +0 -1 kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.h
M +10 -13 kmymoney/plugins/ofx/import/dialogs/konlinebankingstatus.cpp
M +16 -54 kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.cpp
M +0 -7 kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.h
M +31 -36 kmymoney/plugins/ofx/import/ofximporter.cpp
M +2 -2 vcpkg.json
https://invent.kde.org/office/kmymoney/commit/80a6a4b251e4e5efaecccc11a990e739708879d2
diff --git a/CMakeLists.txt b/CMakeLists.txt
index ae64e8fda..293d3d844 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -112,12 +112,14 @@ endif()
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} REQUIRED COMPONENTS Core DBus Widgets Svg Xml Test PrintSupport)
find_package(Qt${QT_MAJOR_VERSION} ${QT_MIN_VERSION} OPTIONAL_COMPONENTS Sql Concurrent QuickWidgets WebEngineWidgets WebKitWidgets)
-find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive CoreAddons Config ConfigWidgets I18n Completion KCMUtils ItemModels ItemViews Service Wallet XmlGui TextWidgets Notifications KIO)
+find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Archive CoreAddons Config ConfigWidgets I18n Completion KCMUtils ItemModels ItemViews Service XmlGui TextWidgets Notifications KIO)
find_package(KF5 ${KF5_MIN_VERSION} OPTIONAL_COMPONENTS DocTools Holidays Contacts Activities)
if (DEFINED AKONADI_MIN_VERSION)
find_package(KF5 ${AKONADI_MIN_VERSION} OPTIONAL_COMPONENTS Akonadi IdentityManagement)
endif()
+find_package(Qt5Keychain CONFIG REQUIRED)
+
if(LibAlkimia5_DIR)
set(_LibAlkimia5_DIR ${LibAlkimia5_DIR})
endif()
diff --git a/doc/firsttime.docbook b/doc/firsttime.docbook
index f34e39553..f2a3fcae5 100644
--- a/doc/firsttime.docbook
+++ b/doc/firsttime.docbook
@@ -853,7 +853,7 @@
<para>
These instructions are solely for moving your &kmymoney; data and settings.
However, there may be important items which are stored by &kde; and not by
- &kmymoney;, such as passwords stored in kwallet. Moving other parts of
+ &kmymoney;, such as passwords stored in Keychain. Moving other parts of
your &kde; setup is beyond the scope of this manual, although many of the
relevant files are also stored under <envar>$KDEHOME</envar>.
</para>
diff --git a/kmymoney/misc/CMakeLists.txt b/kmymoney/misc/CMakeLists.txt
index f6ba43878..e41efa062 100644
--- a/kmymoney/misc/CMakeLists.txt
+++ b/kmymoney/misc/CMakeLists.txt
@@ -18,6 +18,10 @@ set( kmm_webconnect_SRCS
webconnect.cpp
)
+set ( kmm_keychain_SRCS
+ kmmkeychain.cpp
+)
+
if( "${HAVE_UNISTD_H}" AND "${HAVE_PWD_H}" )
set( kmm_utils_platformtools_SRCS
platformtools_gnu.cpp
@@ -40,6 +44,10 @@ set( kmm_webconnect_HEADER
webconnect.h
)
+set ( kmm_keychain_HEADER
+ kmmkeychain.h
+)
+
set( kmm_utils_platformtools_HEADER
platformtools.h
)
@@ -51,6 +59,7 @@ set( kmm_url_HEADER
set( kmm_textbrowser_HEADER
kmmtextbrowser.h
)
+
set( kmm_printer_SRCS
kmm_printer.cpp
)
@@ -64,6 +73,7 @@ add_library(kmm_utils_platformtools STATIC ${kmm_utils_platformtools_SRCS})
add_library(kmm_url STATIC ${kmm_url_SRCS})
add_library(kmm_textbrowser STATIC ${kmm_textbrowser_SRCS})
add_library(kmm_webconnect ${kmm_webconnect_SRCS})
+add_library(kmm_keychain ${kmm_keychain_SRCS})
add_library(kmm_printer ${kmm_printer_SRCS})
add_library(kmm_selections ${kmm_selections_SRCS})
@@ -89,6 +99,12 @@ target_link_libraries( kmm_webconnect
KF5::I18n
)
+target_link_libraries( kmm_keychain
+ PUBLIC
+ Qt::Core
+ Qt5Keychain::Qt5Keychain
+)
+
target_link_libraries( kmm_utils_platformtools
PUBLIC
Qt::Core
@@ -132,6 +148,11 @@ set_target_properties(kmm_webconnect PROPERTIES
)
generate_export_header(kmm_webconnect)
+set_target_properties(kmm_keychain PROPERTIES
+ VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR}
+ )
+generate_export_header(kmm_keychain)
+
if(ENABLE_GPG)
if(WIN32)
@@ -162,6 +183,7 @@ generate_export_header(kmm_gpgfile)
install(TARGETS
kmm_printer
kmm_webconnect
+ kmm_keychain
kmm_selections
kmm_gpgfile
${INSTALL_TARGETS_DEFAULT_ARGS} )
@@ -170,6 +192,7 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/kmm_printer_export.h
${CMAKE_CURRENT_BINARY_DIR}/kmm_selections_export.h
${CMAKE_CURRENT_BINARY_DIR}/kmm_webconnect_export.h
+ ${CMAKE_CURRENT_BINARY_DIR}/kmm_keychain_export.h
${CMAKE_CURRENT_BINARY_DIR}/kmm_gpgfile_export.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR}/kmymoney COMPONENT Devel)
diff --git a/kmymoney/misc/kmmkeychain.cpp b/kmymoney/misc/kmmkeychain.cpp
new file mode 100644
index 000000000..2299f4a7e
--- /dev/null
+++ b/kmymoney/misc/kmmkeychain.cpp
@@ -0,0 +1,103 @@
+/*
+ SPDX-FileCopyrightText: 2021 Igor Bugaev <freedbrt at gmail.com>
+ SPDX-FileCopyrightText: 2022 Dawid Wróbel <me at dawidwrobel.com>
+ SPDX-License-Identifier: BSD-3-Clause
+*/
+
+#include <QDebug>
+#include <QEventLoop>
+
+#include "kmmkeychain.h"
+
+KMMKeychain::KMMKeychain(QObject* parent)
+ : QObject(parent)
+ , m_readCredentialJob(QLatin1String("org.kde.kmymoney"))
+ , m_writeCredentialJob(QLatin1String("org.kde.kmymoney"))
+ , m_deleteCredentialJob(QLatin1String("org.kde.kmymoney"))
+{
+ m_readCredentialJob.setAutoDelete(false);
+ m_writeCredentialJob.setAutoDelete(false);
+ m_deleteCredentialJob.setAutoDelete(false);
+}
+
+void KMMKeychain::readKey(const QString& key)
+{
+ m_readCredentialJob.setKey(key);
+
+ QObject::connect(&m_readCredentialJob, &QKeychain::ReadPasswordJob::finished, [=]() {
+ if (m_readCredentialJob.error()) {
+ auto errorMessage = QString("%1/%2 key read failed: %2")
+ .arg(m_readCredentialJob.service())
+ .arg(m_readCredentialJob.key())
+ .arg(qPrintable(m_readCredentialJob.errorString()));
+
+ qDebug() << errorMessage;
+ Q_EMIT error(errorMessage);
+ } else {
+ qDebug() << QString("%1/%2 key read succeeded").arg(m_readCredentialJob.service()).arg(m_readCredentialJob.key());
+ Q_EMIT keyRestored(key, m_readCredentialJob.textData());
+ }
+ });
+
+ m_readCredentialJob.start();
+}
+
+QString KMMKeychain::readKeySynchronous(const QString& key)
+{
+ QString value = QString("");
+
+ QEventLoop loop;
+ connect(this, &KMMKeychain::keyRestored, [&](const QString, const QString textData) {
+ value = textData;
+ });
+ connect(this, &KMMKeychain::error, &loop, &QEventLoop::quit);
+ connect(this, &KMMKeychain::keyRestored, &loop, &QEventLoop::quit);
+
+ readKey(key);
+ loop.exec();
+
+ return value;
+}
+
+void KMMKeychain::writeKey(const QString& key, const QString& value)
+{
+ m_writeCredentialJob.setKey(key);
+
+ QObject::connect(&m_writeCredentialJob, &QKeychain::WritePasswordJob::finished, [=]() {
+ if (m_writeCredentialJob.error()) {
+ auto errorMessage = QString("%1/%2 key write failed: %2")
+ .arg(m_writeCredentialJob.service())
+ .arg(m_writeCredentialJob.key())
+ .arg(qPrintable(m_writeCredentialJob.errorString()));
+
+ qDebug() << errorMessage;
+ Q_EMIT error(errorMessage);
+ } else {
+ Q_EMIT keyStored(key);
+ }
+ });
+
+ m_writeCredentialJob.setTextData(value);
+ m_writeCredentialJob.start();
+}
+
+void KMMKeychain::deleteKey(const QString& key)
+{
+ m_deleteCredentialJob.setKey(key);
+
+ QObject::connect(&m_deleteCredentialJob, &QKeychain::DeletePasswordJob::finished, [=]() {
+ if (m_deleteCredentialJob.error()) {
+ auto errorMessage = QString("%1/%2 key delete failed: %2")
+ .arg(m_deleteCredentialJob.service())
+ .arg(m_deleteCredentialJob.key())
+ .arg(qPrintable(m_deleteCredentialJob.errorString()));
+
+ qDebug() << errorMessage;
+ Q_EMIT error(errorMessage);
+ } else {
+ Q_EMIT keyDeleted(key);
+ }
+ });
+
+ m_deleteCredentialJob.start();
+}
diff --git a/kmymoney/misc/kmmkeychain.h b/kmymoney/misc/kmmkeychain.h
new file mode 100644
index 000000000..206899450
--- /dev/null
+++ b/kmymoney/misc/kmmkeychain.h
@@ -0,0 +1,41 @@
+/*
+ SPDX-FileCopyrightText: 2021 Igor Bugaev <freedbrt at gmail.com>
+ SPDX-FileCopyrightText: 2022 Dawid Wróbel <me at dawidwrobel.com>
+ SPDX-License-Identifier: BSD-3-Clause
+*/
+
+#ifndef KMMKEYCHAIN_H
+#define KMMKEYCHAIN_H
+
+#include <QObject>
+
+#include <qt5keychain/keychain.h>
+
+#include "kmm_keychain_export.h"
+
+class KMM_KEYCHAIN_EXPORT KMMKeychain : public QObject
+{
+ Q_OBJECT
+public:
+ KMMKeychain(QObject* parent = nullptr);
+
+ void readKey(const QString& key);
+ QString readKeySynchronous(const QString& key);
+
+ void writeKey(const QString& key, const QString& value);
+
+ void deleteKey(const QString& key);
+
+Q_SIGNALS:
+ void keyStored(const QString& key);
+ void keyRestored(const QString& key, const QString& value);
+ void keyDeleted(const QString& key);
+ void error(const QString& errorText);
+
+private:
+ QKeychain::ReadPasswordJob m_readCredentialJob;
+ QKeychain::WritePasswordJob m_writeCredentialJob;
+ QKeychain::DeletePasswordJob m_deleteCredentialJob;
+};
+
+#endif // KMMKEYCHAIN_H
diff --git a/kmymoney/mymoney/CMakeLists.txt b/kmymoney/mymoney/CMakeLists.txt
index 8554eb929..17e57a82e 100644
--- a/kmymoney/mymoney/CMakeLists.txt
+++ b/kmymoney/mymoney/CMakeLists.txt
@@ -128,6 +128,7 @@ target_link_libraries(kmm_mymoney
# TODO: fix this
KF5::XmlGui
PRIVATE
+ kmm_keychain
onlinetask_interfaces
$<$<BOOL:${USE_MODELTEST}>:Qt::Test>
)
diff --git a/kmymoney/plugins/ofx/import/CMakeLists.txt b/kmymoney/plugins/ofx/import/CMakeLists.txt
index f05134484..ad5e1b750 100644
--- a/kmymoney/plugins/ofx/import/CMakeLists.txt
+++ b/kmymoney/plugins/ofx/import/CMakeLists.txt
@@ -25,7 +25,7 @@ target_link_libraries(ofximporter
kmm_mymoney
kmm_widgets
kmm_plugin
- KF5::Wallet
+ kmm_keychain
Qt::Xml
Alkimia::alkimia
libofx::libofx
diff --git a/kmymoney/plugins/ofx/import/dialogs/CMakeLists.txt b/kmymoney/plugins/ofx/import/dialogs/CMakeLists.txt
index 66b5b3208..6fc836d9a 100644
--- a/kmymoney/plugins/ofx/import/dialogs/CMakeLists.txt
+++ b/kmymoney/plugins/ofx/import/dialogs/CMakeLists.txt
@@ -13,4 +13,16 @@ set(ofximporter_dialogs_UI
ki18n_wrap_ui(ofximporter_dialogs_la_SOURCES
${ofximporter_dialogs_UI})
add_library(ofximporter_dialogs STATIC ${ofximporter_dialogs_la_SOURCES})
-target_link_libraries(ofximporter_dialogs kmm_widgets libofx::libofx KF5::WidgetsAddons KF5::I18n KF5::CoreAddons KF5::KIOCore KF5::KIOWidgets KF5::Wallet Qt::Widgets Qt::Xml)
+target_link_libraries(
+ ofximporter_dialogs
+ kmm_widgets
+ libofx::libofx
+ KF5::WidgetsAddons
+ KF5::I18n
+ KF5::CoreAddons
+ KF5::KIOCore
+ KF5::KIOWidgets
+ Qt::Widgets
+ Qt::Xml
+ kmm_keychain
+)
diff --git a/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.cpp b/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.cpp
index 7e328b897..cc6bc9b35 100644
--- a/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.cpp
+++ b/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.cpp
@@ -1,5 +1,6 @@
/*
SPDX-FileCopyrightText: 2006 Ace Jones <acejones at users.sourceforge.net>
+ SPDX-FileCopyrightText: 2022 Dawid Wróbel <me at dawidwrobel.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -22,32 +23,31 @@
// ----------------------------------------------------------------------------
// KDE Includes
+#include <KComboBox>
+#include <KListWidgetSearchLine>
#include <KLocalizedString>
#include <KMessageBox>
-#include <KListWidgetSearchLine>
-#include <KComboBox>
#include <KUrlRequester>
-#include <KWallet>
// ----------------------------------------------------------------------------
// Project Includes
#include "../ofxpartner.h"
+#include "kmmkeychain.h"
#include "kmymoneysettings.h"
#include "mymoneyofxconnector.h"
#include "passwordtoggle.h"
-using KWallet::Wallet;
-
class KOnlineBankingSetupWizard::Private
{
public:
- Private() : m_prevPage(-1), m_wallet(0), m_walletIsOpen(false) {}
+ Private()
+ : m_prevPage(-1)
+ {
+ }
QFile m_fpTrace;
QTextStream m_trace;
- int m_prevPage;
- Wallet *m_wallet;
- bool m_walletIsOpen;
+ int m_prevPage;
};
KOnlineBankingSetupWizard::KOnlineBankingSetupWizard(QWidget *parent):
@@ -134,18 +134,6 @@ void KOnlineBankingSetupWizard::applicationSelectionChanged()
checkNextButton();
}
-void KOnlineBankingSetupWizard::walletOpened(bool ok)
-{
- if (ok && (d->m_wallet->hasFolder(KWallet::Wallet::PasswordFolder()) ||
- d->m_wallet->createFolder(KWallet::Wallet::PasswordFolder())) &&
- d->m_wallet->setFolder(KWallet::Wallet::PasswordFolder())) {
- d->m_walletIsOpen = true;
- } else {
- qDebug("Wallet was not opened");
- }
- m_storePassword->setEnabled(d->m_walletIsOpen);
-}
-
void KOnlineBankingSetupWizard::checkNextButton()
{
bool enableButton = false;
@@ -184,11 +172,6 @@ void KOnlineBankingSetupWizard::newPage(int id)
switch (d->m_prevPage) {
case 0:
ok = finishFiPage();
- // open the KDE wallet if not already opened
- if (ok && !d->m_wallet) {
- d->m_wallet = Wallet::openWallet(Wallet::NetworkWallet(), winId(), Wallet::Asynchronous);
- connect(d->m_wallet, &KWallet::Wallet::walletOpened, this, &KOnlineBankingSetupWizard::walletOpened);
- }
focus = m_editUsername;
break;
case 1:
@@ -564,14 +547,12 @@ bool KOnlineBankingSetupWizard::chosenSettings(MyMoneyKeyValueContainer& setting
if (!hVer.isEmpty())
settings.setValue("kmmofx-headerVersion", hVer);
if (m_storePassword->isChecked()) {
- if (d->m_walletIsOpen) {
- QString key = OFX_PASSWORD_KEY(settings.value("url"), settings.value("uniqueId"));
- d->m_wallet->writePassword(key, settings.value("password"));
- settings.deletePair("password");
- }
- } else {
- settings.deletePair("password");
+ const QString key = OFX_PASSWORD_KEY(settings.value("url"), settings.value("uniqueId"));
+ auto keyChain = new KMMKeychain();
+ keyChain->writeKey(key, settings.value("password"));
}
+ settings.deletePair("password");
+
result = true;
}
}
diff --git a/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.h b/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.h
index 199a698cd..aafe6f1d6 100644
--- a/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.h
+++ b/kmymoney/plugins/ofx/import/dialogs/konlinebankingsetupwizard.h
@@ -69,7 +69,6 @@ public:
protected Q_SLOTS:
void checkNextButton();
void newPage(int id);
- void walletOpened(bool ok);
void applicationSelectionChanged();
protected:
diff --git a/kmymoney/plugins/ofx/import/dialogs/konlinebankingstatus.cpp b/kmymoney/plugins/ofx/import/dialogs/konlinebankingstatus.cpp
index 9aab6f91c..a91b6d094 100644
--- a/kmymoney/plugins/ofx/import/dialogs/konlinebankingstatus.cpp
+++ b/kmymoney/plugins/ofx/import/dialogs/konlinebankingstatus.cpp
@@ -1,5 +1,6 @@
/*
SPDX-FileCopyrightText: 2008 Thomas Baumgart <ipwizard at users.sourceforge.net>
+ SPDX-FileCopyrightText: 2022 Dawid Wróbel <me at dawidwrobel.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -22,17 +23,15 @@
#include <KLed>
#include <KLocalizedString>
#include <KProtocolManager>
-#include <KWallet>
// ----------------------------------------------------------------------------
// Project Includes
-#include "mymoneykeyvaluecontainer.h"
+#include "kmmkeychain.h"
#include "mymoneyaccount.h"
+#include "mymoneykeyvaluecontainer.h"
#include "mymoneyofxconnector.h"
-using KWallet::Wallet;
-
KOnlineBankingStatus::KOnlineBankingStatus(const MyMoneyAccount& acc, QWidget *parent) :
KOnlineBankingStatusDecl(parent),
m_appId(0)
@@ -94,20 +93,18 @@ KOnlineBankingStatus::KOnlineBankingStatus(const MyMoneyAccount& acc, QWidget *p
m_invertAmount->setChecked(settings.value("kmmofx-invertamount").toLower() == QStringLiteral("yes"));
m_fixBuySellSignage->setChecked(settings.value("kmmofx-fixbuysellsignage").toLower() == QStringLiteral("yes"));
- QString key = OFX_PASSWORD_KEY(settings.value("url"), settings.value("uniqueId"));
+ const QString key = OFX_PASSWORD_KEY(settings.value("url"), settings.value("uniqueId"));
QString pwd;
- // if we don't find a password in the wallet, we use the old method
+ // if we don't find a password in the KeyChain, we use the old method
// and retrieve it from the settings stored in the KMyMoney data storage.
- if (Wallet::keyDoesNotExist(Wallet::NetworkWallet(), Wallet::PasswordFolder(), key)) {
+ auto keyChain = new KMMKeychain();
+ pwd = keyChain->readKeySynchronous(key);
+
+ if (pwd.isEmpty()) {
pwd = settings.value("password");
- } else {
- Wallet *wallet = openSynchronousWallet();
- if (wallet) {
- wallet->setFolder(Wallet::PasswordFolder());
- wallet->readPassword(key, pwd);
- }
}
+
m_password->setPassword(pwd);
m_storePassword->setChecked(!pwd.isEmpty());
}
diff --git a/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.cpp b/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.cpp
index e06f89174..1f447eb81 100644
--- a/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.cpp
+++ b/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.cpp
@@ -1,5 +1,6 @@
/*
SPDX-FileCopyrightText: 2002 Ace Jones <acejones at users.sourceforge.net>
+ SPDX-FileCopyrightText: 2022 Dawid Wróbel <me at dawidwrobel.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -26,21 +27,19 @@
// ----------------------------------------------------------------------------
// KDE Includes
-#include <KLocalizedString>
#include <KComboBox>
-#include <KPasswordDialog>
-#include <KWallet>
-#include <KMainWindow>
#include <KLineEdit>
+#include <KLocalizedString>
+#include <KMainWindow>
+#include <KPasswordDialog>
// ----------------------------------------------------------------------------
// Project Includes
+#include "kmmkeychain.h"
#include "mymoneyaccount.h"
-#include "mymoneykeyvaluecontainer.h"
#include "mymoneyenums.h"
-
-using KWallet::Wallet;
+#include "mymoneykeyvaluecontainer.h"
OfxHeaderVersion::OfxHeaderVersion(KComboBox* combo, const QString& headerVersion) :
m_combo(combo)
@@ -209,20 +208,18 @@ QString MyMoneyOfxConnector::username() const
}
QString MyMoneyOfxConnector::password() const
{
- // if we don't find a password in the wallet, we use the old method
+ const QString key = OFX_PASSWORD_KEY(m_fiSettings.value("url"), m_fiSettings.value("uniqueId"));
+
+ auto keyChain = new KMMKeychain();
+ QString pwd = keyChain->readKeySynchronous(key);
+
+ // if we don't find a password in the Keychain, we use the old method
// and retrieve it from the settings stored in the KMyMoney data storage.
- // in case we don't have a password on file, we ask the user
- QString key = OFX_PASSWORD_KEY(m_fiSettings.value("url"), m_fiSettings.value("uniqueId"));
- QString pwd = m_fiSettings.value("password");
-
- // now check for the wallet
- Wallet *wallet = openSynchronousWallet();
- if (wallet
- && !Wallet::keyDoesNotExist(Wallet::NetworkWallet(), Wallet::PasswordFolder(), key)) {
- wallet->setFolder(Wallet::PasswordFolder());
- wallet->readPassword(key, pwd);
+ if (pwd.isEmpty()) {
+ pwd = m_fiSettings.value("password");
}
+ // in case we don't have a password on file, we ask the user
if (pwd.isEmpty()) {
QPointer<KPasswordDialog> dlg = new KPasswordDialog(0);
dlg->setPrompt(i18n("Enter your password for account <b>%1</b>", m_account.name()));
@@ -230,6 +227,7 @@ QString MyMoneyOfxConnector::password() const
pwd = dlg->password();
delete dlg;
}
+
return pwd;
}
QString MyMoneyOfxConnector::accountnum() const
@@ -757,39 +755,3 @@ MyMoneyOfxConnector::Tag MyMoneyOfxConnector::investmentTransaction(const MyMone
return Tag("ERROR").element("DETAILS", "This transaction contains an unsupported action type");
}
#endif
-
-KWallet::Wallet *openSynchronousWallet()
-{
- using KWallet::Wallet;
-
- // first handle the simple case in which we already use the wallet but need the object again in
- // this case the wallet access permission dialog will no longer appear so we don't need to pass
- // a valid window id or do anything special since the function call should return immediately
- const bool alreadyUsingTheWallet = Wallet::users(Wallet::NetworkWallet()).contains("KMyMoney");
- if (alreadyUsingTheWallet) {
- return Wallet::openWallet(Wallet::NetworkWallet(), 0, Wallet::Synchronous);
- }
-
- // search for a suitable parent for the wallet that needs to be deactivated while the
- // wallet access permission dialog is not dismissed with either accept or reject
- KWallet::Wallet *wallet = 0;
- QWidget *parentWidgetForWallet = 0;
- if (qApp->activeModalWidget()) {
- parentWidgetForWallet = qApp->activeModalWidget();
- } else if (qApp->activeWindow()) {
- parentWidgetForWallet = qApp->activeWindow();
- } else {
- QList<KMainWindow *> mainWindowList = KMainWindow::memberList();
- if (!mainWindowList.isEmpty())
- parentWidgetForWallet = mainWindowList.front();
- }
- // only open the wallet synchronously if we have a valid parent otherwise crashes could occur
- if (parentWidgetForWallet) {
- // while the wallet is being opened disable the widget to prevent input processing
- const bool enabled = parentWidgetForWallet->isEnabled();
- parentWidgetForWallet->setEnabled(false);
- wallet = Wallet::openWallet(Wallet::NetworkWallet(), parentWidgetForWallet->winId(), Wallet::Synchronous);
- parentWidgetForWallet->setEnabled(enabled);
- }
- return wallet;
-}
diff --git a/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.h b/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.h
index e1b7c46a1..66caf1864 100644
--- a/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.h
+++ b/kmymoney/plugins/ofx/import/dialogs/mymoneyofxconnector.h
@@ -124,11 +124,4 @@ private:
MyMoneyKeyValueContainer m_fiSettings;
};
-// open a synchronous wallet in a safe way (the function is here because the wallet is only used in the OFX plugin)
-namespace KWallet
-{
-class Wallet;
-}
-KWallet::Wallet *openSynchronousWallet();
-
#endif // OFXCONNECTOR_H
diff --git a/kmymoney/plugins/ofx/import/ofximporter.cpp b/kmymoney/plugins/ofx/import/ofximporter.cpp
index c87943ecf..1aad2d13e 100644
--- a/kmymoney/plugins/ofx/import/ofximporter.cpp
+++ b/kmymoney/plugins/ofx/import/ofximporter.cpp
@@ -1,7 +1,7 @@
/*
SPDX-FileCopyrightText: 2005 Ace Jones acejones @users.sourceforge.net
SPDX-FileCopyrightText: 2010-2019 Thomas Baumgart tbaumgart @kde.org
- SPDX-FileCopyrightText: 2021 Dawid Wróbel <me at dawidwrobel.com>
+ SPDX-FileCopyrightText: 2021-2022 Dawid Wróbel <me at dawidwrobel.com>
SPDX-License-Identifier: GPL-2.0-or-later
*/
@@ -21,35 +21,33 @@
// ----------------------------------------------------------------------------
// KDE Includes
-#include <KPluginFactory>
-#include <QUrl>
-#include <KMessageBox>
#include <KActionCollection>
+#include <KConfigGroup>
#include <KLocalizedString>
-#include <KWallet>
+#include <KMessageBox>
+#include <KPluginFactory>
#include <KSharedConfig>
-#include <KConfigGroup>
+#include <QUrl>
// ----------------------------------------------------------------------------
// Project Includes
-#include <libofx/libofx.h>
-#include "konlinebankingstatus.h"
-#include "konlinebankingsetupwizard.h"
+#include "importinterface.h"
+#include "kmmkeychain.h"
+#include "kmymoneyutils.h"
#include "kofxdirectconnectdlg.h"
+#include "konlinebankingsetupwizard.h"
+#include "konlinebankingstatus.h"
#include "mymoneyaccount.h"
#include "mymoneyexception.h"
#include "mymoneystatement.h"
#include "mymoneystatementreader.h"
#include "statementinterface.h"
-#include "importinterface.h"
-#include "viewinterface.h"
#include "ui_importoption.h"
-#include "kmymoneyutils.h"
-
-//#define DEBUG_LIBOFX
+#include "viewinterface.h"
+#include <libofx/libofx.h>
-using KWallet::Wallet;
+// #define DEBUG_LIBOFX
typedef enum {
UniqueIdUnknown = -1,
@@ -60,9 +58,18 @@ typedef enum {
class OFXImporter::Private
{
public:
- Private() : m_valid(false), m_preferName(PreferId), m_uniqueIdSource(UniqueIdUnknown), m_walletIsOpen(false), m_invertAmount(false), m_fixBuySellSignage(false),
- m_statusDlg(nullptr), m_wallet(nullptr), m_action(nullptr),
- m_updateStartDate(QDate(1900,1,1)), m_timestampOffset(0) {}
+ Private()
+ : m_valid(false)
+ , m_preferName(PreferId)
+ , m_uniqueIdSource(UniqueIdUnknown)
+ , m_invertAmount(false)
+ , m_fixBuySellSignage(false)
+ , m_statusDlg(nullptr)
+ , m_action(nullptr)
+ , m_updateStartDate(QDate(1900, 1, 1))
+ , m_timestampOffset(0)
+ {
+ }
bool m_valid;
enum NamePreference {
@@ -70,8 +77,7 @@ public:
PreferName,
PreferMemo,
} m_preferName;
- UniqueTransactionIdSource m_uniqueIdSource;
- bool m_walletIsOpen;
+ UniqueTransactionIdSource m_uniqueIdSource;
bool m_invertAmount;
bool m_fixBuySellSignage;
QList<MyMoneyStatement> m_statementlist;
@@ -81,7 +87,6 @@ public:
QStringList m_warnings;
QStringList m_errors;
KOnlineBankingStatus* m_statusDlg;
- Wallet *m_wallet;
QAction* m_action;
QDate m_updateStartDate;
int m_timestampOffset;
@@ -877,22 +882,12 @@ MyMoneyKeyValueContainer OFXImporter::onlineBankingSettings(const MyMoneyKeyValu
kvp.deletePair(QStringLiteral("kmmofx-headerVersion"));
kvp.deletePair(QStringLiteral("password"));
- d->m_wallet = openSynchronousWallet();
- if (d->m_wallet && (d->m_wallet->hasFolder(KWallet::Wallet::PasswordFolder()) ||
- d->m_wallet->createFolder(KWallet::Wallet::PasswordFolder())) &&
- d->m_wallet->setFolder(KWallet::Wallet::PasswordFolder())) {
- QString key = OFX_PASSWORD_KEY(kvp.value(QStringLiteral("url")), kvp.value(QStringLiteral("uniqueId")));
- if (d->m_statusDlg->m_storePassword->isChecked()) {
- d->m_wallet->writePassword(key, d->m_statusDlg->m_password->password());
- } else {
- if (d->m_wallet->hasEntry(key)) {
- d->m_wallet->removeEntry(key);
- }
- }
+ const QString key = OFX_PASSWORD_KEY(kvp.value(QStringLiteral("url")), kvp.value(QStringLiteral("uniqueId")));
+ auto keyChain = new KMMKeychain();
+ if (d->m_statusDlg->m_storePassword->isChecked()) {
+ keyChain->writeKey(key, d->m_statusDlg->m_password->password());
} else {
- if (d->m_statusDlg->m_storePassword->isChecked()) {
- kvp.setValue(QStringLiteral("password"), d->m_statusDlg->m_password->password());
- }
+ keyChain->deleteKey(key);
}
if (!d->m_statusDlg->appId().isEmpty())
diff --git a/vcpkg.json b/vcpkg.json
index 283dbb610..903faf1ff 100644
--- a/vcpkg.json
+++ b/vcpkg.json
@@ -20,11 +20,11 @@
"kf5notifications",
"kf5service",
"kf5textwidgets",
- "kf5wallet",
"kf5xmlgui",
"libalkimia",
"qt5-base",
- "qt5-svg"
+ "qt5-svg",
+ "qtkeychain"
],
"features": {
"encryption": {
More information about the kde-doc-english
mailing list