diff --git a/CMakeLists.txt b/CMakeLists.txt index 27006e527..41816c007 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,280 +1,281 @@ # SPDX-FileCopyrightText: none # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.16 FATAL_ERROR) set(RELEASE_SERVICE_VERSION_MAJOR "23") set(RELEASE_SERVICE_VERSION_MINOR "07") set(RELEASE_SERVICE_VERSION_MICRO "70") # The RELEASE_SERVICE_VERSION is used by Gpg4win to add the Gpg4win version if (NOT RELEASE_SERVICE_VERSION) set(RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}") endif() if(RELEASE_SERVICE_VERSION_MICRO LESS 10) set(KDE_APPLICATIONS_COMPACT_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}${RELEASE_SERVICE_VERSION_MINOR}0${RELEASE_SERVICE_VERSION_MICRO}") else() set(KDE_APPLICATIONS_COMPACT_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}${RELEASE_SERVICE_VERSION_MINOR}${RELEASE_SERVICE_VERSION_MICRO}") endif() set(KLEOPATRA_VERSION_MAJOR "3") set(KLEOPATRA_VERSION_MINOR "1") set(KLEOPATRA_VERSION_MICRO "26") set(kleopatra_version "${KLEOPATRA_VERSION_MAJOR}.${KLEOPATRA_VERSION_MINOR}.${KLEOPATRA_VERSION_MICRO}.${KDE_APPLICATIONS_COMPACT_VERSION}") # The following is for Windows set(kleopatra_version_win "${KLEOPATRA_VERSION_MAJOR}.${KLEOPATRA_VERSION_MINOR}.${KLEOPATRA_VERSION_MICRO}") set(kleopatra_fileversion_win "${KLEOPATRA_VERSION_MAJOR},${KLEOPATRA_VERSION_MINOR},${KLEOPATRA_VERSION_MICRO},0") if (NOT KLEOPATRA_DISTRIBUTION_TEXT) # This is only used on Windows for the file attributes of Kleopatra set(KLEOPATRA_DISTRIBUTION_TEXT "KDE") endif() project(kleopatra VERSION ${kleopatra_version}) option(DISABLE_KWATCHGNUPG "Don't build the kwatchgnupg tool [default=OFF]" OFF) # Standalone build. Find / include everything necessary. set(KF_MIN_VERSION "5.104.0") set(KIDENTITYMANAGEMENT_VERSION "5.23.40") set(KMAILTRANSPORT_VERSION "5.23.40") set(KMIME_VERSION "5.23.40") set(LIBKLEO_VERSION "5.23.41") set(QT_REQUIRED_VERSION "5.15.2") if (QT_MAJOR_VERSION STREQUAL "6") set(QT_REQUIRED_VERSION "6.4.0") endif() set(GPGME_REQUIRED_VERSION "1.16.0") set(LIBASSUAN_REQUIRED_VERSION "2.4.2") set(GPG_ERROR_REQUIRED_VERSION "1.36") if (WIN32) set(KF5_WANT_VERSION "5.70.0") set(KMIME_WANT_VERSION "5.12.0") else () set(KF5_WANT_VERSION ${KF_MIN_VERSION}) set(KMIME_WANT_VERSION ${KMIME_VERSION}) endif () set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(ECM ${KF5_WANT_VERSION} CONFIG REQUIRED) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH}) set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH}) include(ECMInstallIcons) include(ECMSetupVersion) include(ECMAddTests) include(GenerateExportHeader) include(ECMGenerateHeaders) include(FeatureSummary) include(CheckFunctionExists) include(KDEInstallDirs) include(KDECMakeSettings) include(KDECompilerSettings NO_POLICY_SCOPE) include(ECMAddAppIcon) include(ECMQtDeclareLoggingCategory) include(ECMDeprecationSettings) include(KDEClangFormat) if (QT_MAJOR_VERSION STREQUAL "6") set(QT_REQUIRED_VERSION "6.4.0") set(KF_MIN_VERSION "5.240.0") set(KF_MAJOR_VERSION "6") else() set(KF_MIN_VERSION "5.104.0") set(KF_MAJOR_VERSION "5") endif() # Find KF5 packages find_package(KF${KF_MAJOR_VERSION} ${KF5_WANT_VERSION} REQUIRED COMPONENTS Codecs Config ConfigWidgets CoreAddons Crash I18n IconThemes ItemModels KIO WidgetsAddons WindowSystem XmlGui + KCMUtils OPTIONAL_COMPONENTS DocTools ) set_package_properties(KF${KF_MAJOR_VERSION}DocTools PROPERTIES DESCRIPTION "Documentation tools" PURPOSE "Required to generate Kleopatra documentation." TYPE OPTIONAL) # Optional packages if (WIN32) # Only a replacement available for Windows so this # is required on other platforms. find_package(KF${KF_MAJOR_VERSION}DBusAddons ${KF5_WANT_VERSION} CONFIG) set_package_properties(KF${KF_MAJOR_VERSION}DBusAddons PROPERTIES DESCRIPTION "Support library to work with DBus" PURPOSE "DBus session integration" URL "https://inqlude.org/libraries/kdbusaddons.html" TYPE OPTIONAL) else() find_package(KF${KF_MAJOR_VERSION}DBusAddons ${KF5_WANT_VERSION} CONFIG REQUIRED) set(_kleopatra_dbusaddons_libs KF${KF_MAJOR_VERSION}::DBusAddons) endif() set(HAVE_QDBUS ${Qt${QT_MAJOR_VERSION}DBus_FOUND}) find_package(Gpgmepp ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) if (Gpgmepp_VERSION VERSION_GREATER_EQUAL "1.19.0") set(GPGMEPP_SUPPORTS_SET_CURVE 1) endif() if (QT_MAJOR_VERSION STREQUAL "6") find_package(QGpgmeQt6 ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) else() find_package(QGpgme ${GPGME_REQUIRED_VERSION} CONFIG REQUIRED) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.17.0") set(QGPGME_SUPPORTS_CHANGING_EXPIRATION_OF_COMPLETE_KEY 1) set(QGPGME_CRYPTOCONFIGENTRY_HAS_DEFAULT_VALUE 1) set(QGPGME_SUPPORTS_WKDLOOKUP 1) set(QGPGME_SUPPORTS_IMPORT_WITH_FILTER 1) set(QGPGME_SUPPORTS_IMPORT_WITH_KEY_ORIGIN 1) set(QGPGME_SUPPORTS_SECRET_KEY_EXPORT 1) set(QGPGME_SUPPORTS_SECRET_SUBKEY_EXPORT 1) set(QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID 1) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.18.0") set(QGPGME_SUPPORTS_KEY_REVOCATION 1) set(QGPGME_SUPPORTS_KEY_REFRESH 1) set(QGPGME_SUPPORTS_SET_FILENAME 1) set(QGPGME_SUPPORTS_SET_PRIMARY_UID 1) endif() if (QGpgme_VERSION VERSION_GREATER_EQUAL "1.19.0") set(QGPGME_SUPPORTS_DEFERRED_IMPORT_JOB 1) set(QGPGME_SUPPORTS_ARCHIVE_JOBS 1) set(QGPGME_JOB_HAS_NEW_PROGRESS_SIGNALS 1) endif() if (QT_MAJOR_VERSION STREQUAL "6") find_package(Qt6Core5Compat) endif() # Kdepimlibs packages find_package(KPim${KF_MAJOR_VERSION}Libkleo ${LIBKLEO_VERSION} CONFIG REQUIRED) find_package(KPim${KF_MAJOR_VERSION}Mime ${KMIME_WANT_VERSION} CONFIG REQUIRED) find_package(KPim${KF_MAJOR_VERSION}IdentityManagement ${KIDENTITYMANAGEMENT_VERSION} CONFIG) find_package(KPim${KF_MAJOR_VERSION}MailTransport ${KMAILTRANSPORT_VERSION} CONFIG) find_package(KPim${KF_MAJOR_VERSION}MailTransportAkonadi ${KMAILTRANSPORT_VERSION} CONFIG) find_package(Qt${QT_MAJOR_VERSION} ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test Network PrintSupport) find_package(LibAssuan ${LIBASSUAN_REQUIRED_VERSION} REQUIRED) set_package_properties(LibAssuan PROPERTIES TYPE REQUIRED PURPOSE "Needed for Kleopatra to act as the GnuPG UI Server" ) find_package(LibGpgError ${GPG_ERROR_REQUIRED_VERSION} REQUIRED) set_package_properties(LibGpgError PROPERTIES TYPE REQUIRED ) set(kleopatra_release FALSE) if(NOT kleopatra_release) find_package(Git) if(GIT_FOUND) execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RESULT_VARIABLE rc ERROR_QUIET) if(rc EQUAL 0) execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --format=%h ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE Kleopatra_WC_REVISION) string(REGEX REPLACE "\n" "" Kleopatra_WC_REVISION "${Kleopatra_WC_REVISION}") execute_process(COMMAND ${GIT_EXECUTABLE} log -1 --oneline --format=%cI ${CMAKE_CURRENT_SOURCE_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE Kleopatra_WC_LAST_CHANGED_DATE) string(REGEX REPLACE "^([0-9]+)-([0-9]+)-([0-9]+)T([0-9]+):([0-9]+):([0-9]+).*$" "\\1\\2\\3T\\4\\5\\6" Kleopatra_WC_LAST_CHANGED_DATE "${Kleopatra_WC_LAST_CHANGED_DATE}") set(kleopatra_version "${kleopatra_version}+git${Kleopatra_WC_LAST_CHANGED_DATE}~${Kleopatra_WC_REVISION}") endif() endif() endif() configure_file(${CMAKE_CURRENT_SOURCE_DIR}/version-kleopatra.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/version-kleopatra.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config-kleopatra.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-kleopatra.h) include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ) if (WIN32) # On Windows, we need to use stuff deprecated since Qt 5.11, e.g. from QDesktopWidget ecm_set_disabled_deprecation_versions(QT 5.10.0 KF 5.103.0) else () ecm_set_disabled_deprecation_versions(QT 6.4 KF 5.103.0) endif () if(CMAKE_COMPILER_IS_GNUCXX) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-missing-braces -Wno-parentheses -Wno-ignored-qualifiers") endif() if(MINGW) # we do not care about different signedness of passed pointer arguments add_compile_options($<$:-Wno-pointer-sign>) endif() add_definitions(-DQT_NO_EMIT) remove_definitions(-DQT_NO_FOREACH) # Disable the use of QStringBuilder for operator+ to prevent crashes when # returning the result of concatenating string temporaries in lambdas. We do # this for example in some std::transform expressions. # This is a known issue: https://bugreports.qt.io/browse/QTBUG-47066 # Alternatively, one would always have to remember to force the lambdas to # return a QString instead of QStringBuilder, but that's just too easy to # forget and, unfortunately, the compiler doesn't issue a warning if one forgets # this. So, it's just too dangerous. # One can still use QStringBuilder explicitly with the operator% if necessary. remove_definitions(-DQT_USE_FAST_OPERATOR_PLUS) remove_definitions(-DQT_USE_QSTRINGBUILDER) kde_enable_exceptions() option(USE_UNITY_CMAKE_SUPPORT "Use UNITY cmake support (speedup compile time)" OFF) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT OFF) if (USE_UNITY_CMAKE_SUPPORT) set(COMPILE_WITH_UNITY_CMAKE_SUPPORT ON) endif() add_subdirectory(pics) add_subdirectory(src) if(BUILD_TESTING) add_subdirectory(tests) add_subdirectory(autotests) endif() ecm_qt_install_logging_categories( EXPORT KLEOPATRA FILE kleopatra.categories DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR} ) ki18n_install(po) if(KF${KF_MAJOR_VERSION}DocTools_FOUND) kdoctools_install(po) add_subdirectory(doc) endif() feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES) # add clang-format target for all our real source files file(GLOB_RECURSE ALL_CLANG_FORMAT_SOURCE_FILES *.cpp *.h *.c) kde_clang_format(${ALL_CLANG_FORMAT_SOURCE_FILES}) diff --git a/src/conf/CMakeLists.txt b/src/conf/CMakeLists.txt index b7e8a3898..18c9d8baa 100644 --- a/src/conf/CMakeLists.txt +++ b/src/conf/CMakeLists.txt @@ -1,76 +1,76 @@ include_directories(${kleopatra_SOURCE_DIR}/src) set(_kcm_kleopatra_libkleopatraclient_extra_SRCS smimevalidationconfigurationwidget.cpp smimevalidationconfigurationpage.cpp cryptooperationsconfigwidget.cpp cryptooperationsconfigpage.cpp smimevalidationconfigurationwidget.h smimevalidationconfigurationpage.h cryptooperationsconfigwidget.h cryptooperationsconfigpage.h smartcardconfigpage.cpp smartcardconfigpage.h ) ki18n_wrap_ui(_kcm_kleopatra_libkleopatraclient_extra_SRCS smimevalidationconfigurationwidget.ui ) kconfig_add_kcfg_files(_kcm_kleopatra_libkleopatraclient_extra_SRCS ${kleopatra_SOURCE_DIR}/src/kcfg/smimevalidationpreferences.kcfgc ) set(_kcm_kleopatra_libkleopatraclient_extra_LIBS kleopatraclientgui) set(kcm_kleopatra_PART_SRCS dirservconfigpage.cpp appearanceconfigpage.cpp appearanceconfigwidget.cpp gnupgsystemconfigurationpage.cpp dirservconfigpage.h appearanceconfigpage.h appearanceconfigwidget.h gnupgsystemconfigurationpage.h labelledwidget.cpp labelledwidget.h labelledwidget.cpp labelledwidget.h ${kleopatra_BINARY_DIR}/src/kleopatra_debug.cpp ${_kcm_kleopatra_libkleopatraclient_extra_SRCS} ) ki18n_wrap_ui(kcm_kleopatra_PART_SRCS appearanceconfigwidget.ui smimevalidationconfigurationwidget.ui ) kconfig_add_kcfg_files(kcm_kleopatra_PART_SRCS ${kleopatra_SOURCE_DIR}/src/kcfg/tooltippreferences.kcfgc ${kleopatra_SOURCE_DIR}/src/kcfg/emailoperationspreferences.kcfgc ${kleopatra_SOURCE_DIR}/src/kcfg/fileoperationspreferences.kcfgc ${kleopatra_SOURCE_DIR}/src/kcfg/tagspreferences.kcfgc ${kleopatra_SOURCE_DIR}/src/kcfg/settings.kcfgc ) add_library(kcm_kleopatra_static STATIC ${kcm_kleopatra_PART_SRCS}) set_property(TARGET kcm_kleopatra_static PROPERTY POSITION_INDEPENDENT_CODE ON) target_link_libraries(kcm_kleopatra_static KPim${KF_MAJOR_VERSION}::Libkleo KF${KF_MAJOR_VERSION}::IconThemes KF${KF_MAJOR_VERSION}::I18n KF${KF_MAJOR_VERSION}::WidgetsAddons - KF${KF_MAJOR_VERSION}::ConfigWidgets + KF${KF_MAJOR_VERSION}::KCMUtils ${_kcm_kleopatra_extra_libs} ${_kleopatra_dbusaddons_libs} ${_kcm_kleopatra_libkleopatraclient_extra_LIBS} ) if (NOT WIN32) add_library(kleopatra_config_gnupgsystem MODULE kcm_gnupgsystemconfigurationpage.cpp) target_link_libraries(kleopatra_config_gnupgsystem kcm_kleopatra_static KF${KF_MAJOR_VERSION}::CoreAddons) install(TARGETS kleopatra_config_gnupgsystem DESTINATION ${KDE_INSTALL_PLUGINDIR}/pim${QT_MAJOR_VERSION}/kcms/kleopatra) endif() diff --git a/src/conf/appearanceconfigpage.cpp b/src/conf/appearanceconfigpage.cpp index e71e9d196..871973697 100644 --- a/src/conf/appearanceconfigpage.cpp +++ b/src/conf/appearanceconfigpage.cpp @@ -1,45 +1,55 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/appearanceconfigpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2004, 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "appearanceconfigpage.h" #include "appearanceconfigwidget.h" #include using namespace Kleo; using namespace Kleo::Config; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) AppearanceConfigurationPage::AppearanceConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule(parent, args) +#else +AppearanceConfigurationPage::AppearanceConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto lay = new QVBoxLayout(this); mWidget = new AppearanceConfigWidget(this); +#else + auto lay = new QVBoxLayout(widget()); + mWidget = new AppearanceConfigWidget(widget()); +#endif lay->addWidget(mWidget); connect(mWidget, &AppearanceConfigWidget::changed, this, &Kleo::Config::AppearanceConfigurationPage::markAsChanged); } void AppearanceConfigurationPage::load() { mWidget->load(); } void AppearanceConfigurationPage::save() { mWidget->save(); } void AppearanceConfigurationPage::defaults() { mWidget->defaults(); } diff --git a/src/conf/appearanceconfigpage.h b/src/conf/appearanceconfigpage.h index fcd8d8170..39e25296e 100644 --- a/src/conf/appearanceconfigpage.h +++ b/src/conf/appearanceconfigpage.h @@ -1,40 +1,44 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/appearanceconfigpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2004, 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include namespace Kleo { namespace Config { class AppearanceConfigWidget; /** * "Appearance" configuration page for kleopatra's configuration dialog */ class AppearanceConfigurationPage : public KCModule { Q_OBJECT public: +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) explicit AppearanceConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); +#else + explicit AppearanceConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif public Q_SLOTS: void load() override; void save() override; void defaults() override; private: AppearanceConfigWidget *mWidget; }; } } diff --git a/src/conf/cryptooperationsconfigpage.cpp b/src/conf/cryptooperationsconfigpage.cpp index 2f8c34637..4688a1390 100644 --- a/src/conf/cryptooperationsconfigpage.cpp +++ b/src/conf/cryptooperationsconfigpage.cpp @@ -1,45 +1,55 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/cryptooperationsconfigpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "cryptooperationsconfigpage.h" #include "cryptooperationsconfigwidget.h" #include using namespace Kleo; using namespace Kleo::Config; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) CryptoOperationsConfigurationPage::CryptoOperationsConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule(parent, args) +#else +CryptoOperationsConfigurationPage::CryptoOperationsConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto lay = new QVBoxLayout(this); - lay->setContentsMargins(0, 0, 0, 0); mWidget = new CryptoOperationsConfigWidget(this); +#else + auto lay = new QVBoxLayout(widget()); + mWidget = new CryptoOperationsConfigWidget(widget()); +#endif + lay->setContentsMargins(0, 0, 0, 0); lay->addWidget(mWidget); connect(mWidget, &CryptoOperationsConfigWidget::changed, this, &Kleo::Config::CryptoOperationsConfigurationPage::markAsChanged); } void CryptoOperationsConfigurationPage::load() { mWidget->load(); } void CryptoOperationsConfigurationPage::save() { mWidget->save(); } void CryptoOperationsConfigurationPage::defaults() { mWidget->defaults(); } diff --git a/src/conf/cryptooperationsconfigpage.h b/src/conf/cryptooperationsconfigpage.h index 5c0dcef6e..dbeafe94a 100644 --- a/src/conf/cryptooperationsconfigpage.h +++ b/src/conf/cryptooperationsconfigpage.h @@ -1,40 +1,44 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/cryptooperationsconfigpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include namespace Kleo { namespace Config { class CryptoOperationsConfigWidget; /** * "Crypto Operations" configuration page for kleopatra's configuration dialog */ class CryptoOperationsConfigurationPage : public KCModule { Q_OBJECT public: +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) explicit CryptoOperationsConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); +#else + explicit CryptoOperationsConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif public Q_SLOTS: void load() override; void save() override; void defaults() override; private: CryptoOperationsConfigWidget *mWidget; }; } } diff --git a/src/conf/dirservconfigpage.cpp b/src/conf/dirservconfigpage.cpp index 4862c0dcd..9925fc59d 100644 --- a/src/conf/dirservconfigpage.cpp +++ b/src/conf/dirservconfigpage.cpp @@ -1,478 +1,529 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/dirservconfigpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2004, 2008 Klarälvdalens Datakonsult AB SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "dirservconfigpage.h" #include "labelledwidget.h" #include #include #include #include #include #include #include #include #include "kleopatra_debug.h" #include #include #include #include #include #include #include #include #include #include #include using namespace Kleo; using namespace QGpgME; // Option for configuring X.509 servers (available via gpgconf since GnuPG 2.3.5 and 2.2.34) static const char s_x509services_componentName[] = "dirmngr"; static const char s_x509services_entryName[] = "ldapserver"; // Legacy option for configuring X.509 servers (deprecated with GnuPG 2.2.28 and 2.3.2) static const char s_x509services_legacy_componentName[] = "gpgsm"; static const char s_x509services_legacy_entryName[] = "keyserver"; static const char s_pgpservice_componentName[] = "dirmngr"; static const char s_pgpservice_entryName[] = "keyserver"; // legacy config entry used until GnuPG 2.2 static const char s_pgpservice_legacy_componentName[] = "gpg"; static const char s_pgpservice_legacy_entryName[] = "keyserver"; static const char s_timeout_componentName[] = "dirmngr"; static const char s_timeout_entryName[] = "ldaptimeout"; static const char s_maxitems_componentName[] = "dirmngr"; static const char s_maxitems_entryName[] = "max-replies"; class DirectoryServicesConfigurationPage::Private { DirectoryServicesConfigurationPage *q = nullptr; public: Private(DirectoryServicesConfigurationPage *q); void load(); void save(); void defaults(); private: enum EntryMultiplicity { SingleValue, ListValue }; enum ShowError { DoNotShowError, DoShowError }; void setX509ServerEntry(const std::vector &servers); void load(const Kleo::Settings &settings); QGpgME::CryptoConfigEntry *configEntry(const char *componentName, const char *entryName, QGpgME::CryptoConfigEntry::ArgType argType, EntryMultiplicity multiplicity, ShowError showError); Kleo::LabelledWidget mOpenPGPKeyserverEdit; Kleo::DirectoryServicesWidget *mDirectoryServices = nullptr; Kleo::LabelledWidget mTimeout; Kleo::LabelledWidget mMaxItems; QCheckBox *mFetchMissingSignerKeysCB = nullptr; QGpgME::CryptoConfigEntry *mOpenPGPServiceEntry = nullptr; QGpgME::CryptoConfigEntry *mTimeoutConfigEntry = nullptr; QGpgME::CryptoConfigEntry *mMaxItemsConfigEntry = nullptr; QGpgME::CryptoConfig *mConfig = nullptr; }; DirectoryServicesConfigurationPage::Private::Private(DirectoryServicesConfigurationPage *q) { mConfig = QGpgME::cryptoConfig(); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto glay = new QGridLayout(q); +#else + auto glay = new QGridLayout(q->widget()); +#endif glay->setContentsMargins(0, 0, 0, 0); // OpenPGP keyserver int row = 0; { auto l = new QHBoxLayout{}; l->setContentsMargins(0, 0, 0, 0); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) mOpenPGPKeyserverEdit.createWidgets(q); +#else + mOpenPGPKeyserverEdit.createWidgets(q->widget()); +#endif mOpenPGPKeyserverEdit.label()->setText(i18n("OpenPGP keyserver:")); l->addWidget(mOpenPGPKeyserverEdit.label()); l->addWidget(mOpenPGPKeyserverEdit.widget()); glay->addLayout(l, row, 0, 1, 3); connect(mOpenPGPKeyserverEdit.widget(), &QLineEdit::textEdited, q, &DirectoryServicesConfigurationPage::markAsChanged); } // X.509 servers if (Settings{}.cmsEnabled()) { ++row; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto groupBox = new QGroupBox{i18n("X.509 Directory Services"), q}; +#else + auto groupBox = new QGroupBox{i18n("X.509 Directory Services"), q->widget()}; +#endif auto groupBoxLayout = new QVBoxLayout{groupBox}; if (gpgme_check_version("1.16.0")) { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) mDirectoryServices = new Kleo::DirectoryServicesWidget(q); +#else + mDirectoryServices = new Kleo::DirectoryServicesWidget(q->widget()); +#endif if (QLayout *l = mDirectoryServices->layout()) { l->setContentsMargins(0, 0, 0, 0); } groupBoxLayout->addWidget(mDirectoryServices); connect(mDirectoryServices, &DirectoryServicesWidget::changed, q, &DirectoryServicesConfigurationPage::markAsChanged); } else { // QGpgME does not properly support keyserver flags for X.509 keyservers (added in GnuPG 2.2.28); // disable the configuration to prevent the configuration from being corrupted +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) groupBoxLayout->addWidget(new QLabel{i18n("Configuration of directory services is not possible " "because the used gpgme libraries are too old."), q}); +#else + groupBoxLayout->addWidget(new QLabel{i18n("Configuration of directory services is not possible " + "because the used gpgme libraries are too old."), + q->widget()}); + +#endif } glay->addWidget(groupBox, row, 0, 1, 3); } // LDAP timeout ++row; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) mTimeout.createWidgets(q); +#else + mTimeout.createWidgets(q->widget()); +#endif mTimeout.label()->setText(i18n("LDAP &timeout (minutes:seconds):")); mTimeout.widget()->setDisplayFormat(QStringLiteral("mm:ss")); connect(mTimeout.widget(), &QTimeEdit::timeChanged, q, &DirectoryServicesConfigurationPage::markAsChanged); glay->addWidget(mTimeout.label(), row, 0); glay->addWidget(mTimeout.widget(), row, 1); // Max number of items returned by queries ++row; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) mMaxItems.createWidgets(q); +#else + mMaxItems.createWidgets(q->widget()); +#endif mMaxItems.label()->setText(i18n("&Maximum number of items returned by query:")); mMaxItems.widget()->setMinimum(0); #if QT_DEPRECATED_SINCE(5, 14) connect(mMaxItems.widget(), qOverload(&QSpinBox::valueChanged), q, &DirectoryServicesConfigurationPage::markAsChanged); #else connect(mMaxItems.widget(), &QSpinBox::valueChanged, q, &DirectoryServicesConfigurationPage::markAsChanged); #endif glay->addWidget(mMaxItems.label(), row, 0); glay->addWidget(mMaxItems.widget(), row, 1); #if QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID ++row; mFetchMissingSignerKeysCB = new QCheckBox{q}; mFetchMissingSignerKeysCB->setText(i18nc("@option:check", "Retrieve missing certification keys when importing new keys")); mFetchMissingSignerKeysCB->setToolTip( xi18nc("@info:tooltip", "If enabled, then Kleopatra will automatically try to retrieve the keys " "that were used to certify the user IDs of newly imported OpenPGP keys.")); connect(mFetchMissingSignerKeysCB, &QCheckBox::toggled, q, &DirectoryServicesConfigurationPage::markAsChanged); glay->addWidget(mFetchMissingSignerKeysCB, row, 0, 1, 3); #endif glay->setRowStretch(++row, 1); glay->setColumnStretch(2, 1); } static auto readKeyserverConfigs(const CryptoConfigEntry *configEntry) { std::vector servers; if (configEntry) { const auto urls = configEntry->urlValueList(); servers.reserve(urls.size()); std::transform(std::begin(urls), std::end(urls), std::back_inserter(servers), &KeyserverConfig::fromUrl); } return servers; } void DirectoryServicesConfigurationPage::Private::load(const Kleo::Settings &settings) { if (mDirectoryServices) { mDirectoryServices->clear(); // gpgsm uses the deprecated keyserver option in gpgsm.conf additionally to the ldapserver option in dirmngr.conf; // we (try to) read servers from both entries, but always write to the newest existing entry const auto *const newEntry = configEntry(s_x509services_componentName, s_x509services_entryName, CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoNotShowError); const auto *const legacyEntry = configEntry(s_x509services_legacy_componentName, s_x509services_legacy_entryName, CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoNotShowError); auto entry = newEntry ? newEntry : legacyEntry; if (entry) { const auto additionalServers = readKeyserverConfigs(legacyEntry); auto servers = readKeyserverConfigs(newEntry); std::copy(std::begin(additionalServers), std::end(additionalServers), std::back_inserter(servers)); mDirectoryServices->setKeyservers(servers); mDirectoryServices->setReadOnly(entry->isReadOnly()); } else { qCWarning(KLEOPATRA_LOG) << "Unknown or wrong typed config entries" << s_x509services_componentName << "/" << s_x509services_entryName << "and" << s_x509services_legacy_componentName << "/" << s_x509services_legacy_entryName; mDirectoryServices->setDisabled(true); } } { // gpg prefers the deprecated keyserver option in gpg.conf over the keyserver option in dirmngr.conf; // therefore, we use the deprecated keyserver option if it is set or if the new option doesn't exist (gpg < 2.1.9) auto const newEntry = configEntry(s_pgpservice_componentName, s_pgpservice_entryName, CryptoConfigEntry::ArgType_String, SingleValue, DoNotShowError); auto const legacyEntry = configEntry(s_pgpservice_legacy_componentName, s_pgpservice_legacy_entryName, CryptoConfigEntry::ArgType_String, SingleValue, DoNotShowError); mOpenPGPServiceEntry = ((legacyEntry && legacyEntry->isSet()) || !newEntry) ? legacyEntry : newEntry; if (!mOpenPGPServiceEntry) { qCWarning(KLEOPATRA_LOG) << "Unknown or wrong typed config entries" << s_pgpservice_componentName << "/" << s_pgpservice_entryName << "and" << s_pgpservice_legacy_componentName << "/" << s_pgpservice_legacy_entryName; } else if (mOpenPGPServiceEntry == legacyEntry) { qCDebug(KLEOPATRA_LOG) << "Using config entry" << s_pgpservice_legacy_componentName << "/" << s_pgpservice_legacy_entryName; } else { qCDebug(KLEOPATRA_LOG) << "Using config entry" << s_pgpservice_componentName << "/" << s_pgpservice_entryName; } mOpenPGPKeyserverEdit.widget()->setText(mOpenPGPServiceEntry && mOpenPGPServiceEntry->isSet() ? mOpenPGPServiceEntry->stringValue() : QString()); mOpenPGPKeyserverEdit.setEnabled(mOpenPGPServiceEntry && !mOpenPGPServiceEntry->isReadOnly()); #if QGPGME_CRYPTOCONFIGENTRY_HAS_DEFAULT_VALUE if (newEntry && !newEntry->defaultValue().isNull()) { mOpenPGPKeyserverEdit.widget()->setPlaceholderText(newEntry->defaultValue().toString()); } else #endif { if (GpgME::engineInfo(GpgME::GpgEngine).engineVersion() < "2.1.16") { mOpenPGPKeyserverEdit.widget()->setPlaceholderText(QStringLiteral("hkp://keys.gnupg.net")); } else { mOpenPGPKeyserverEdit.widget()->setPlaceholderText(QStringLiteral("hkps://hkps.pool.sks-keyservers.net")); } } } // read LDAP timeout // first try to read the config entry as int (GnuPG 2.3) mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_entryName, CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError); if (!mTimeoutConfigEntry) { // if this fails, then try to read the config entry as unsigned int (GnuPG <= 2.2) mTimeoutConfigEntry = configEntry(s_timeout_componentName, s_timeout_entryName, CryptoConfigEntry::ArgType_UInt, SingleValue, DoShowError); } if (mTimeoutConfigEntry) { const int ldapTimeout = mTimeoutConfigEntry->argType() == CryptoConfigEntry::ArgType_Int ? mTimeoutConfigEntry->intValue() : static_cast(mTimeoutConfigEntry->uintValue()); const QTime time = QTime(0, 0, 0, 0).addSecs(ldapTimeout); //qCDebug(KLEOPATRA_LOG) <<"timeout:" << mTimeoutConfigEntry->uintValue() <<" ->" << time; mTimeout.widget()->setTime(time); } mTimeout.setEnabled(mTimeoutConfigEntry && !mTimeoutConfigEntry->isReadOnly()); // read max-replies config entry // first try to read the config entry as int (GnuPG 2.3) mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_entryName, CryptoConfigEntry::ArgType_Int, SingleValue, DoNotShowError); if (!mMaxItemsConfigEntry) { // if this fails, then try to read the config entry as unsigned int (GnuPG <= 2.2) mMaxItemsConfigEntry = configEntry(s_maxitems_componentName, s_maxitems_entryName, CryptoConfigEntry::ArgType_UInt, SingleValue, DoShowError); } if (mMaxItemsConfigEntry) { const int value = mMaxItemsConfigEntry->argType() == CryptoConfigEntry::ArgType_Int ? mMaxItemsConfigEntry->intValue() : static_cast(mMaxItemsConfigEntry->uintValue()); mMaxItems.widget()->blockSignals(true); // KNumInput emits valueChanged from setValue! mMaxItems.widget()->setValue(value); mMaxItems.widget()->blockSignals(false); } mMaxItems.setEnabled(mMaxItemsConfigEntry && !mMaxItemsConfigEntry->isReadOnly()); #if QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID mFetchMissingSignerKeysCB->setChecked(settings.retrieveSignerKeysAfterImport()); mFetchMissingSignerKeysCB->setEnabled(!settings.isImmutable(QStringLiteral("RetrieveSignerKeysAfterImport"))); #else Q_UNUSED(settings) #endif } void DirectoryServicesConfigurationPage::Private::load() { load(Settings{}); } namespace { void updateIntegerConfigEntry(QGpgME::CryptoConfigEntry *configEntry, int value) { if (!configEntry) { return; } if (configEntry->argType() == CryptoConfigEntry::ArgType_Int) { if (configEntry->intValue() != value) { configEntry->setIntValue(value); } } else { const auto newValue = static_cast(value); if (configEntry->uintValue() != newValue) { configEntry->setUIntValue(newValue); } } } } void DirectoryServicesConfigurationPage::Private::setX509ServerEntry(const std::vector &servers) { const auto newEntry = configEntry(s_x509services_componentName, s_x509services_entryName, CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoNotShowError); const auto legacyEntry = configEntry(s_x509services_legacy_componentName, s_x509services_legacy_entryName, CryptoConfigEntry::ArgType_LDAPURL, ListValue, DoNotShowError); if ((newEntry && newEntry->isReadOnly()) || (legacyEntry && legacyEntry->isReadOnly())) { // do not change the config entries if either config entry is read-only return; } QList urls; urls.reserve(servers.size()); std::transform(std::begin(servers), std::end(servers), std::back_inserter(urls), std::mem_fn(&KeyserverConfig::toUrl)); if (newEntry) { // write all servers to the new config entry newEntry->setURLValueList(urls); // and clear the legacy config entry if (legacyEntry) { legacyEntry->setURLValueList({}); } } else if (legacyEntry) { // write all servers to the legacy config entry if the new entry is not available legacyEntry->setURLValueList(urls); } else { qCWarning(KLEOPATRA_LOG) << "Could not store the X.509 servers. Unknown or wrong typed config entries" << s_x509services_componentName << "/" << s_x509services_entryName << "and" << s_x509services_legacy_componentName << "/" << s_x509services_legacy_entryName; } } void DirectoryServicesConfigurationPage::Private::save() { if (mDirectoryServices && mDirectoryServices->isEnabled()) { setX509ServerEntry(mDirectoryServices->keyservers()); } if (mOpenPGPServiceEntry) { const auto keyserver = mOpenPGPKeyserverEdit.widget()->text().trimmed(); if (keyserver.isEmpty()) { mOpenPGPServiceEntry->resetToDefault(); } else { const auto keyserverUrl = keyserver.contains(QLatin1String{"://"}) ? keyserver : (QLatin1String{"hkps://"} + keyserver); mOpenPGPServiceEntry->setStringValue(keyserverUrl); } } const QTime time{mTimeout.widget()->time()}; updateIntegerConfigEntry(mTimeoutConfigEntry, time.minute() * 60 + time.second()); updateIntegerConfigEntry(mMaxItemsConfigEntry, mMaxItems.widget()->value()); mConfig->sync(true); #if QGPGME_SUPPORTS_RECEIVING_KEYS_BY_KEY_ID Settings settings; settings.setRetrieveSignerKeysAfterImport(mFetchMissingSignerKeysCB->isChecked()); settings.save(); #endif } void DirectoryServicesConfigurationPage::Private::defaults() { // these guys don't have a default, to clear them: if (mDirectoryServices && mDirectoryServices->isEnabled()) { setX509ServerEntry({}); } if (mOpenPGPServiceEntry && !mOpenPGPServiceEntry->isReadOnly()) { mOpenPGPServiceEntry->setStringValue(QString()); } // these presumably have a default, use that one: if (mTimeoutConfigEntry && !mTimeoutConfigEntry->isReadOnly()) { mTimeoutConfigEntry->resetToDefault(); } if (mMaxItemsConfigEntry && !mMaxItemsConfigEntry->isReadOnly()) { mMaxItemsConfigEntry->resetToDefault(); } Settings settings; settings.setRetrieveSignerKeysAfterImport(settings.findItem(QStringLiteral("RetrieveSignerKeysAfterImport"))->getDefault().toBool()); load(settings); } // Find config entry for ldap servers. Implements runtime checks on the configuration option. CryptoConfigEntry *DirectoryServicesConfigurationPage::Private::configEntry(const char *componentName, const char *entryName, CryptoConfigEntry::ArgType argType, EntryMultiplicity multiplicity, ShowError showError) { CryptoConfigEntry *const entry = Kleo::getCryptoConfigEntry(mConfig, componentName, entryName); if (!entry) { if (showError == DoShowError) { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) KMessageBox::error(q, i18n("Backend error: gpgconf does not seem to know the entry for %1/%2", QLatin1String(componentName), QLatin1String(entryName))); +#else + KMessageBox::error( + q->widget(), + i18n("Backend error: gpgconf does not seem to know the entry for %1/%2", QLatin1String(componentName), QLatin1String(entryName))); +#endif } return nullptr; } if (entry->argType() != argType || entry->isList() != bool(multiplicity)) { if (showError == DoShowError) { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) KMessageBox::error(q, i18n("Backend error: gpgconf has wrong type for %1/%2: %3 %4", QLatin1String(componentName), QLatin1String(entryName), entry->argType(), entry->isList())); +#else + KMessageBox::error(q->widget(), + i18n("Backend error: gpgconf has wrong type for %1/%2: %3 %4", + QLatin1String(componentName), + QLatin1String(entryName), + entry->argType(), + entry->isList())); +#endif } return nullptr; } return entry; } +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule{parent, args} +#else +DirectoryServicesConfigurationPage::DirectoryServicesConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif , d{new Private{this}} { } DirectoryServicesConfigurationPage::~DirectoryServicesConfigurationPage() = default; void DirectoryServicesConfigurationPage::load() { d->load(); } void DirectoryServicesConfigurationPage::save() { d->save(); } void DirectoryServicesConfigurationPage::defaults() { d->defaults(); } diff --git a/src/conf/dirservconfigpage.h b/src/conf/dirservconfigpage.h index da9377a21..492be1694 100644 --- a/src/conf/dirservconfigpage.h +++ b/src/conf/dirservconfigpage.h @@ -1,37 +1,41 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/dirservconfigpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2004, 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include #include /** * "Directory Services" configuration page for kleopatra's configuration dialog * The user can configure LDAP servers in this page, to be used for listing/fetching * remote certificates in kleopatra. */ class DirectoryServicesConfigurationPage : public KCModule { Q_OBJECT public: - explicit DirectoryServicesConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = {}); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) + explicit DirectoryServicesConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); +#else + explicit DirectoryServicesConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif ~DirectoryServicesConfigurationPage() override; public Q_SLOTS: void load() override; void save() override; void defaults() override; private: class Private; const std::unique_ptr d; friend class DirectoryServicesConfigurationPage::Private; }; diff --git a/src/conf/gnupgsystemconfigurationpage.cpp b/src/conf/gnupgsystemconfigurationpage.cpp index 5fe36d63e..cac845252 100644 --- a/src/conf/gnupgsystemconfigurationpage.cpp +++ b/src/conf/gnupgsystemconfigurationpage.cpp @@ -1,65 +1,78 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/gnupgsystemconfigurationpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "gnupgsystemconfigurationpage.h" #include #include #include #include using namespace Kleo::Config; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) GnuPGSystemConfigurationPage::GnuPGSystemConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule(parent, args) +#else +GnuPGSystemConfigurationPage::GnuPGSystemConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto lay = new QVBoxLayout(this); +#else + auto lay = new QVBoxLayout(widget()); +#endif lay->setContentsMargins(0, 0, 0, 0); QGpgME::CryptoConfig *const config = QGpgME::cryptoConfig(); mWidget = new CryptoConfigModule(config, CryptoConfigModule::TabbedLayout, +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) this); +#else + widget()); +#endif lay->addWidget(mWidget); connect(mWidget, &CryptoConfigModule::changed, this, &Kleo::Config::GnuPGSystemConfigurationPage::markAsChanged); } GnuPGSystemConfigurationPage::~GnuPGSystemConfigurationPage() { // ### correct here? if (QGpgME::CryptoConfig *const config = QGpgME::cryptoConfig()) { config->clear(); } } void GnuPGSystemConfigurationPage::load() { mWidget->reset(); } void GnuPGSystemConfigurationPage::save() { mWidget->save(); #if 0 // Tell other apps (e.g. kmail) that the gpgconf data might have changed QDBusMessage message = QDBusMessage::createSignal(QString(), "org.kde.kleo.CryptoConfig", "changed"); QDBusConnection::sessionBus().send(message); #endif } void GnuPGSystemConfigurationPage::defaults() { mWidget->defaults(); } diff --git a/src/conf/gnupgsystemconfigurationpage.h b/src/conf/gnupgsystemconfigurationpage.h index 481df4109..79de9857f 100644 --- a/src/conf/gnupgsystemconfigurationpage.h +++ b/src/conf/gnupgsystemconfigurationpage.h @@ -1,40 +1,44 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/gnupgsystemconfigurationpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include namespace Kleo { class CryptoConfigModule; } namespace Kleo { namespace Config { class GnuPGSystemConfigurationPage : public KCModule { Q_OBJECT public: +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) explicit GnuPGSystemConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); +#else + explicit GnuPGSystemConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif ~GnuPGSystemConfigurationPage() override; public Q_SLOTS: void load() override; void save() override; void defaults() override; private: Kleo::CryptoConfigModule *mWidget; }; } } diff --git a/src/conf/kleopageconfigdialog.cpp b/src/conf/kleopageconfigdialog.cpp index 5e95d8c22..110cea190 100644 --- a/src/conf/kleopageconfigdialog.cpp +++ b/src/conf/kleopageconfigdialog.cpp @@ -1,244 +1,247 @@ /* kleopageconfigdialog.cpp This file is part of Kleopatra SPDX-FileCopyrightText: 2016 Bundesamt für Sicherheit in der Informationstechnik SPDX-FileContributor: Intevation GmbH SPDX-License-Identifier: GPL-2.0-only It is derived from KCMultidialog which is: SPDX-FileCopyrightText: 2000 Matthias Elter SPDX-FileCopyrightText: 2003 Daniel Molkentin SPDX-FileCopyrightText: 2003, 2006 Matthias Kretz SPDX-FileCopyrightText: 2004 Frans Englich SPDX-FileCopyrightText: 2006 Tobias Koenig SPDX-License-Identifier: LGPL-2.0-or-later */ -#include - #include "kleopageconfigdialog.h" +#include "kcmutils_version.h" +#include #include #include #include #include #include #include #include #include #include #include #include "kleopatra_debug.h" KleoPageConfigDialog::KleoPageConfigDialog(QWidget *parent) : KPageDialog(parent) { setModal(false); QDialogButtonBox *buttonBox = new QDialogButtonBox(this); buttonBox->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::RestoreDefaults | QDialogButtonBox::Cancel | QDialogButtonBox::Apply | QDialogButtonBox::Ok | QDialogButtonBox::Reset); KGuiItem::assign(buttonBox->button(QDialogButtonBox::Ok), KStandardGuiItem::ok()); KGuiItem::assign(buttonBox->button(QDialogButtonBox::Cancel), KStandardGuiItem::cancel()); KGuiItem::assign(buttonBox->button(QDialogButtonBox::RestoreDefaults), KStandardGuiItem::defaults()); KGuiItem::assign(buttonBox->button(QDialogButtonBox::Apply), KStandardGuiItem::apply()); KGuiItem::assign(buttonBox->button(QDialogButtonBox::Reset), KStandardGuiItem::reset()); KGuiItem::assign(buttonBox->button(QDialogButtonBox::Help), KStandardGuiItem::help()); buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false); buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false); connect(buttonBox->button(QDialogButtonBox::Apply), &QAbstractButton::clicked, this, &KleoPageConfigDialog::slotApplyClicked); connect(buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked, this, &KleoPageConfigDialog::slotOkClicked); connect(buttonBox->button(QDialogButtonBox::RestoreDefaults), &QAbstractButton::clicked, this, &KleoPageConfigDialog::slotDefaultClicked); connect(buttonBox->button(QDialogButtonBox::Help), &QAbstractButton::clicked, this, &KleoPageConfigDialog::slotHelpClicked); connect(buttonBox->button(QDialogButtonBox::Reset), &QAbstractButton::clicked, this, &KleoPageConfigDialog::slotUser1Clicked); setButtonBox(buttonBox); connect(this, &KPageDialog::currentPageChanged, this, &KleoPageConfigDialog::slotCurrentPageChanged); } void KleoPageConfigDialog::slotCurrentPageChanged(KPageWidgetItem *current, KPageWidgetItem *previous) { if (!previous) { return; } blockSignals(true); setCurrentPage(previous); KCModule *previousModule = qobject_cast(previous->widget()); bool canceled = false; if (previousModule && mChangedModules.contains(previousModule)) { const int queryUser = KMessageBox::warningTwoActionsCancel( this, i18n("The settings of the current module have changed.\n" "Do you want to apply the changes or discard them?"), i18n("Apply Settings"), KStandardGuiItem::apply(), KStandardGuiItem::discard(), KStandardGuiItem::cancel()); if (queryUser == KMessageBox::ButtonCode::PrimaryAction) { previousModule->save(); } else if (queryUser == KMessageBox::ButtonCode::SecondaryAction) { previousModule->load(); } canceled = queryUser == KMessageBox::Cancel; } if (!canceled) { mChangedModules.removeAll(previousModule); setCurrentPage(current); } blockSignals(false); clientChanged(); } void KleoPageConfigDialog::apply() { QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply); applyButton->setFocus(); for (KCModule *module : mChangedModules) { module->save(); } mChangedModules.clear(); Q_EMIT configCommitted(); clientChanged(); } void KleoPageConfigDialog::slotDefaultClicked() { const KPageWidgetItem *item = currentPage(); if (!item) { return; } KCModule *module = qobject_cast(item->widget()); if (!module) { return; } module->defaults(); clientChanged(); } void KleoPageConfigDialog::slotUser1Clicked() { const KPageWidgetItem *item = currentPage(); if (!item) { return; } KCModule *module = qobject_cast(item->widget()); if (!module) { return; } module->load(); mChangedModules.removeAll(module); clientChanged(); } void KleoPageConfigDialog::slotApplyClicked() { apply(); } void KleoPageConfigDialog::slotOkClicked() { apply(); accept(); } void KleoPageConfigDialog::slotHelpClicked() { const KPageWidgetItem *item = currentPage(); if (!item) { return; } const QString docPath = mHelpUrls.value(item->name()); QUrl docUrl; #ifdef Q_OS_WIN docUrl = QUrl(QLatin1String("https://docs.kde.org/index.php?branch=stable5&language=") + QLocale().name() + QLatin1String("&application=kleopatra")); #else docUrl = QUrl(QStringLiteral("help:/")).resolved(QUrl(docPath)); // same code as in KHelpClient::invokeHelp #endif if (docUrl.scheme() == QLatin1String("help") || docUrl.scheme() == QLatin1String("man") || docUrl.scheme() == QLatin1String("info")) { // Warning: Don't assume that the program needs to be in PATH. On Windows, it will also be found next to the calling process. QProcess::startDetached(QStringLiteral("khelpcenter"), QStringList() << docUrl.toString()); } else { QDesktopServices::openUrl(docUrl); } } void KleoPageConfigDialog::addModule(const QString &name, const QString &docPath, const QString &icon, KCModule *module) { mModules << module; - +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) KPageWidgetItem *item = addPage(module, name); +#else + KPageWidgetItem *item = addPage(module->widget(), name); +#endif item->setIcon(QIcon::fromTheme(icon)); connect(module, SIGNAL(changed(bool)), this, SLOT(moduleChanged(bool))); mHelpUrls.insert(name, docPath); } void KleoPageConfigDialog::moduleChanged(bool state) { KCModule *module = qobject_cast(sender()); qCDebug(KLEOPATRA_LOG) << "Module changed: " << state << " mod " << module; if (mChangedModules.contains(module)) { if (!state) { mChangedModules.removeAll(module); } else { return; } } if (state) { mChangedModules << module; } clientChanged(); } void KleoPageConfigDialog::clientChanged() { const KPageWidgetItem *item = currentPage(); if (!item) { return; } KCModule *module = qobject_cast(item->widget()); if (!module) { return; } qCDebug(KLEOPATRA_LOG) << "Client changed: " << " mod " << module; bool change = mChangedModules.contains(module); QPushButton *resetButton = buttonBox()->button(QDialogButtonBox::Reset); if (resetButton) { resetButton->setEnabled(change); } QPushButton *applyButton = buttonBox()->button(QDialogButtonBox::Apply); if (applyButton) { applyButton->setEnabled(change); } } diff --git a/src/conf/smartcardconfigpage.cpp b/src/conf/smartcardconfigpage.cpp index b8a4260db..7e160213c 100644 --- a/src/conf/smartcardconfigpage.cpp +++ b/src/conf/smartcardconfigpage.cpp @@ -1,116 +1,133 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/smartcardconfigpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "smartcardconfigpage.h" #include #include #include #include #include #include #include #include using namespace Kleo; using namespace Kleo::Config; using namespace QGpgME; class SmartCardConfigurationPage::Private { public: Private(SmartCardConfigurationPage *q); static CryptoConfigEntry *readerPortConfigEntry(const CryptoConfig *config = nullptr); public: ReaderPortSelection *const mReaderPort; }; SmartCardConfigurationPage::Private::Private(SmartCardConfigurationPage *qq) +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) : mReaderPort{new ReaderPortSelection{qq}} +#else + : mReaderPort{new ReaderPortSelection{qq->widget()}} +#endif { } // static CryptoConfigEntry *SmartCardConfigurationPage::Private::readerPortConfigEntry(const CryptoConfig *config) { if (!config) { config = QGpgME::cryptoConfig(); } return Kleo::getCryptoConfigEntry(config, "scdaemon", "reader-port"); } +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) SmartCardConfigurationPage::SmartCardConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule{parent, args} +#else +SmartCardConfigurationPage::SmartCardConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif , d{std::make_unique(this)} { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto mainLayout = new QVBoxLayout{this}; +#else + auto mainLayout = new QVBoxLayout{widget()}; +#endif mainLayout->setContentsMargins(0, 0, 0, 0); { auto l = new QHBoxLayout{}; l->setContentsMargins(0, 0, 0, 0); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto label = new QLabel{i18n("Smart card reader to use:"), this}; +#else + auto label = new QLabel{i18n("Smart card reader to use:"), widget()}; +#endif label->setBuddy(d->mReaderPort); l->addWidget(label); l->addWidget(d->mReaderPort, 1); mainLayout->addLayout(l); connect(d->mReaderPort, &ReaderPortSelection::valueChanged, this, &SmartCardConfigurationPage::markAsChanged); } mainLayout->addStretch(); load(); } SmartCardConfigurationPage::~SmartCardConfigurationPage() = default; void SmartCardConfigurationPage::load() { const auto *const entry = d->readerPortConfigEntry(); if (entry) { d->mReaderPort->setEnabled(!entry->isReadOnly()); d->mReaderPort->setValue(entry->stringValue()); } else { d->mReaderPort->setEnabled(false); d->mReaderPort->setValue(i18n("Cannot be configured with Kleopatra")); } } void SmartCardConfigurationPage::save() { auto config = QGpgME::cryptoConfig(); auto const entry = d->readerPortConfigEntry(config); if (entry && !entry->isReadOnly()) { entry->setStringValue(d->mReaderPort->value()); } config->sync(true); } void SmartCardConfigurationPage::defaults() { const auto *const entry = d->readerPortConfigEntry(); if (entry && !entry->isReadOnly()) { d->mReaderPort->setValue({}); } } diff --git a/src/conf/smartcardconfigpage.h b/src/conf/smartcardconfigpage.h index d7954f80d..f33be8b1d 100644 --- a/src/conf/smartcardconfigpage.h +++ b/src/conf/smartcardconfigpage.h @@ -1,39 +1,43 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/smartcardconfigpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2022 g10 Code GmbH SPDX-FileContributor: Ingo Klöcker SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include #include namespace Kleo { namespace Config { class SmartCardConfigurationPage : public KCModule { Q_OBJECT public: - explicit SmartCardConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = {}); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) + explicit SmartCardConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); +#else + explicit SmartCardConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif ~SmartCardConfigurationPage() override; void load() override; void save() override; void defaults() override; private: class Private; std::unique_ptr d; }; } } diff --git a/src/conf/smimevalidationconfigurationpage.cpp b/src/conf/smimevalidationconfigurationpage.cpp index b0e690cf3..3ec893a95 100644 --- a/src/conf/smimevalidationconfigurationpage.cpp +++ b/src/conf/smimevalidationconfigurationpage.cpp @@ -1,44 +1,57 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/smimevalidationconfigurationpage.cpp This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #include #include "smimevalidationconfigurationpage.h" #include "smimevalidationconfigurationwidget.h" #include using namespace Kleo::Config; +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) SMimeValidationConfigurationPage::SMimeValidationConfigurationPage(QWidget *parent, const QVariantList &args) : KCModule(parent, args) +#else +SMimeValidationConfigurationPage::SMimeValidationConfigurationPage(QObject *parent, const KPluginMetaData &data, const QVariantList &args) + : KCModule(parent, data, args) +#endif { +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) auto lay = new QVBoxLayout(this); +#else + auto lay = new QVBoxLayout(widget()); +#endif lay->setContentsMargins(0, 0, 0, 0); +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) mWidget = new SMimeValidationConfigurationWidget(this); +#else + mWidget = new SMimeValidationConfigurationWidget(widget()); +#endif lay->addWidget(mWidget); connect(mWidget, &SMimeValidationConfigurationWidget::changed, this, &Kleo::Config::SMimeValidationConfigurationPage::markAsChanged); } void SMimeValidationConfigurationPage::load() { mWidget->load(); } void SMimeValidationConfigurationPage::save() { mWidget->save(); } void SMimeValidationConfigurationPage::defaults() { mWidget->defaults(); } diff --git a/src/conf/smimevalidationconfigurationpage.h b/src/conf/smimevalidationconfigurationpage.h index eaa0344d9..9764cb277 100644 --- a/src/conf/smimevalidationconfigurationpage.h +++ b/src/conf/smimevalidationconfigurationpage.h @@ -1,36 +1,39 @@ /* -*- mode: c++; c-basic-offset:4 -*- conf/smimevalidationconfigurationpage.h This file is part of Kleopatra, the KDE keymanager SPDX-FileCopyrightText: 2008 Klarälvdalens Datakonsult AB SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once - +#include "kcmutils_version.h" #include namespace Kleo { namespace Config { class SMimeValidationConfigurationWidget; class SMimeValidationConfigurationPage : public KCModule { Q_OBJECT public: +#if KCMUTILS_VERSION < QT_VERSION_CHECK(5, 240, 0) explicit SMimeValidationConfigurationPage(QWidget *parent = nullptr, const QVariantList &args = QVariantList()); - +#else + explicit SMimeValidationConfigurationPage(QObject *parent, const KPluginMetaData &data = {}, const QVariantList &args = QVariantList()); +#endif public Q_SLOTS: void load() override; void save() override; void defaults() override; private: SMimeValidationConfigurationWidget *mWidget; }; } }