diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ KIO Parts Solid - Wallet WidgetsAddons GlobalAccel DBusAddons @@ -44,14 +43,20 @@ find_package(Phonon4Qt5 4.6.60 REQUIRED) include_directories(${PHONON_INCLUDES}) +find_package(KF5Wallet ${KF5_MIN_VERSION}) +set_package_properties(KF5Wallet PROPERTIES DESCRIPTION "Support for storing network proxy passwords safely" + URL "https://utils.kde.org/projects/kwalletmanager/" + TYPE RECOMMENDED) find_package(Qca-qt5 2.1.0) set_package_properties(Qca-qt5 PROPERTIES DESCRIPTION "Support for encryption" URL "http://download.kde.org/stable/qca-qt5/" TYPE OPTIONAL) + check_include_file("stropts.h" HAVE_STROPTS_H) check_include_file("byteswap.h" HAVE_BYTESWAP_H) check_include_file("sys/endian.h" HAVE_SYS_ENDIAN_H) +set(HAVE_KWALLET ${KF5Wallet_FOUND}) set(HAVE_QCA2 ${Qca-qt5_FOUND}) configure_file(config-konversation.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-konversation.h ) diff --git a/config-konversation.h.cmake b/config-konversation.h.cmake --- a/config-konversation.h.cmake +++ b/config-konversation.h.cmake @@ -1,3 +1,4 @@ +#cmakedefine01 HAVE_KWALLET #cmakedefine HAVE_QCA2 1 #cmakedefine HAVE_STROPTS_H 1 #cmakedefine HAVE_SYS_ENDIAN_H 1 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -224,7 +224,6 @@ KF5::KIOWidgets KF5::Parts KF5::Solid - KF5::Wallet KF5::WidgetsAddons KF5::GlobalAccel KF5::DBusAddons @@ -235,6 +234,9 @@ KF5::ItemViews Phonon::phonon4qt5) +if (KF5Wallet_FOUND) + target_link_libraries(konversation KF5::Wallet) +endif() if (Qca-qt5_FOUND) target_link_libraries(konversation qca-qt5) endif () diff --git a/src/application.h b/src/application.h --- a/src/application.h +++ b/src/application.h @@ -26,6 +26,8 @@ #include "identity.h" #include "ircqueue.h" +#include + #include class ConnectionManager; @@ -53,10 +55,12 @@ } } +#if HAVE_KWALLET namespace KWallet { class Wallet; } +#endif class Application : public QApplication @@ -130,8 +134,10 @@ static void openUrl(const QString& url); +#if HAVE_KWALLET /// The wallet used to store passwords. Opens the wallet if it's closed. KWallet::Wallet* wallet(); +#endif void abortScheduledRestart() { m_restartScheduled = false; } @@ -165,7 +171,9 @@ void updateProxySettings(); +#if HAVE_KWALLET void closeWallet(); +#endif protected: bool event(QEvent* event); @@ -188,7 +196,9 @@ Konversation::NotificationHandler* m_notificationHandler; - KWallet::Wallet* m_wallet; +#if HAVE_KWALLET + KWallet::Wallet* m_wallet = nullptr; +#endif QNetworkConfigurationManager* m_networkConfigurationManager; }; diff --git a/src/application.cpp b/src/application.cpp --- a/src/application.cpp +++ b/src/application.cpp @@ -1,5 +1,4 @@ -/* - This program is free software; you can redistribute it and/or modify +/* This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -63,7 +62,6 @@ m_scriptLauncher = 0; quickConnectDialog = 0; osd = 0; - m_wallet = NULL; m_images = 0; m_sound = 0; m_dccTransferManager = 0; @@ -96,7 +94,10 @@ //delete identDBus; delete osd; osd = 0; + +#if HAVE_KWALLET closeWallet(); +#endif delete m_networkConfigurationManager; @@ -1327,8 +1328,9 @@ proxy.setHostName(Preferences::self()->proxyAddress()); proxy.setPort(Preferences::self()->proxyPort()); proxy.setUser(Preferences::self()->proxyUsername()); - QString password; +#if HAVE_KWALLET + QString password; if(wallet()) { int ret = wallet()->readPassword(QStringLiteral("ProxyPassword"), password); @@ -1338,16 +1340,20 @@ qCritical() << "Failed to read the proxy password from the wallet, error code:" << ret; } } - proxy.setPassword(password); +#else + proxy.setUser(Preferences::self()->proxyPassword()); +#endif + QNetworkProxy::setApplicationProxy(proxy); } else { QNetworkProxy::setApplicationProxy(QNetworkProxy::DefaultProxy); } } +#if HAVE_KWALLET KWallet::Wallet* Application::wallet() { if(!m_wallet) @@ -1384,12 +1390,15 @@ return m_wallet; } +#endif +#if HAVE_KWALLET void Application::closeWallet() { delete m_wallet; m_wallet = NULL; } +#endif diff --git a/src/config/connectionbehavior_config.cpp b/src/config/connectionbehavior_config.cpp --- a/src/config/connectionbehavior_config.cpp +++ b/src/config/connectionbehavior_config.cpp @@ -51,6 +51,7 @@ { if(kcfg_ProxyEnabled->isChecked () && m_passwordChanged) { +#if HAVE_KWALLET if(Application::instance()->wallet()) { int ret = Application::instance()->wallet()->writePassword("ProxyPassword", m_ProxyPassword->text()); @@ -60,6 +61,7 @@ qCritical() << "Failed to write the proxy password to the wallet, error code:" << ret; } } +#endif } setPasswordChanged(false); @@ -71,6 +73,7 @@ if(Preferences::self()->proxyEnabled()) { +#if HAVE_KWALLET if(Application::instance()->wallet()) { int ret = Application::instance()->wallet()->readPassword("ProxyPassword", password); @@ -80,6 +83,7 @@ qCritical() << "Failed to read the proxy password from the wallet, error code:" << ret; } } +#endif } m_ProxyPassword->setText(password);