Commit 85d07ddd authored by Alexander Volkov's avatar Alexander Volkov

Make KWallet an optional dependency

Summary:
KWallet is too KDE-specific and hard dependency on it
creates obstacles when using libksane outside of KDE.

Reviewers: sars, trufanov, mlaurent, dfaure

Reviewed By: sars

Differential Revision: https://phabricator.kde.org/D9254
parent b7e99256
......@@ -41,11 +41,17 @@ find_package(Qt5 ${REQUIRED_QT_VERSION} NO_MODULE REQUIRED Core Widgets)
# Required KF5 frameworks
find_package(KF5I18n ${KF5_VERSION} REQUIRED)
find_package(KF5Wallet ${KF5_VERSION} REQUIRED)
find_package(KF5WidgetsAddons ${KF5_VERSION} REQUIRED)
find_package(KF5TextWidgets ${KF5_VERSION} REQUIRED)
# ...
# Optional KF5 frameworks
find_package(KF5Wallet ${KF5_VERSION})
set_package_properties(KF5Wallet PROPERTIES DESCRIPTION "Safe desktop-wide storage for passwords"
TYPE OPTIONAL
PURPOSE "Required to have permanent storage of passwords for scanners"
)
# Check if sane API is available.
if (NOT WIN32)
find_package(Sane)
......
add_definitions(-DTRANSLATION_DOMAIN=\"libksane\")
if (KF5Wallet_FOUND)
add_definitions(-DHAVE_KF5WALLET)
set(WALLET_LIB KF5::Wallet)
endif()
include_directories(${SANE_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/options
......@@ -49,9 +53,9 @@ target_link_libraries(KF5Sane
${SANE_LIBRARY}
KF5::I18n
KF5::Wallet
KF5::WidgetsAddons
KF5::TextWidgets
${WALLET_LIB}
)
set_target_properties(KF5Sane
......
......@@ -44,7 +44,9 @@
#include <QIcon>
#include <kpassworddialog.h>
#ifdef HAVE_KF5WALLET
#include <kwallet.h>
#endif
#include "ksaneoption.h"
#include "ksaneoptbutton.h"
......@@ -328,7 +330,9 @@ bool KSaneWidget::openDevice(const QString &deviceName)
SANE_Word numSaneOptions;
SANE_Int res;
KPasswordDialog *dlg;
#ifdef HAVE_KF5WALLET
KWallet::Wallet *saneWallet;
#endif
QString myFolderName = QStringLiteral("ksane");
QMap<QString, QString> wallet_entry;
......@@ -351,6 +355,7 @@ bool KSaneWidget::openDevice(const QString &deviceName)
// prepare wallet for authentication and create password dialog
if (status == SANE_STATUS_ACCESS_DENIED) {
#ifdef HAVE_KF5WALLET
saneWallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), winId());
if (saneWallet) {
......@@ -365,7 +370,9 @@ bool KSaneWidget::openDevice(const QString &deviceName)
dlg->setPassword(wallet_entry[QStringLiteral("password")]);
dlg->setKeepPassword(true);
}
} else {
} else
#endif
{
dlg = new KPasswordDialog(this, KPasswordDialog::ShowUsernameLine);
}
dlg->setPrompt(i18n("Authentication required for resource: %1", deviceName));
......@@ -388,6 +395,7 @@ bool KSaneWidget::openDevice(const QString &deviceName)
status = sane_open(deviceName.toLatin1().constData(), &d->m_saneHandle);
#ifdef HAVE_KF5WALLET
// store password in wallet on successful authentication
if (dlg->keepPassword() && status != SANE_STATUS_ACCESS_DENIED) {
QMap<QString, QString> entry;
......@@ -397,6 +405,7 @@ bool KSaneWidget::openDevice(const QString &deviceName)
saneWallet->writeMap(deviceName, entry);
}
}
#endif
}
if (status != SANE_STATUS_GOOD) {
......
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