From 287cbcd48095033def9ef29b0c3a7a09631f84ba Mon Sep 17 00:00:00 2001 From: Johan Ouwerkerk Date: Sat, 6 Feb 2021 19:38:51 +0100 Subject: [PATCH] feat!: register Keysmith with D-Bus This change provides the most basic D-Bus support in Keysmith. At start up, Keysmith will now register itself and abort if another instance is already running. Full support for the xdg D-Bus activation specification (such as URI opening) is not yet implemented. By default this feature is disabled on Android, but enabled on 'all' other platforms. Explicit control may be exercised by running CMake with -DBUILD_DBUS_INTERFACE=. Issues: #18 --- CMakeLists.txt | 5 +++++ src/CMakeLists.txt | 14 +++++++++++++- src/keysmith-features.h.in | 12 ++++++++++++ src/main.cpp | 9 +++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/keysmith-features.h.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f4f434d..0bd77cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,11 @@ if(NOT BUILD_EXTERNAL AND (NOT ANDROID OR DEFINED BUILD_EXTERNAL)) find_package(sodium ${SODIUM_MIN_VERSION} REQUIRED) endif() +if (BUILD_DBUS_INTERFACE OR (NOT ANDROID AND NOT DEFINED BUILD_DBUS_INTERFACE)) + find_package(KF5DBusAddons ${KF5_MIN_VERSION} REQUIRED) + set(ENABLE_DBUS_INTERFACE ON) +endif() + ################ Find testing dependencies ########## if (BUILD_TESTING) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ff4c8bc..9b9a5ec 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ # SPDX-License-Identifier: BSD-2-Clause # SPDX-FileCopyrightText: 2019 Bhushan Shah # SPDX-FileCopyrightText: 2019 Friedrich W. H. Kossebau -# SPDX-FileCopyrightText: 2019-2020 Johan Ouwerkerk +# SPDX-FileCopyrightText: 2019-2021 Johan Ouwerkerk # SPDX-FileCopyrightText: 2020 Nicolas Fella # SPDX-FileCopyrightText: 2021 Devin Lin # @@ -19,6 +19,14 @@ add_subdirectory(app) configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/version.h.in" "${CMAKE_CURRENT_BINARY_DIR}/version.h") +# +# The features header should be namespaced, or at least it *must not* be called 'features.h'. +# Reason is that the GNU C++ standard library implementation also refers to a 'features.h' +# and compilation will blow up very badly inside 'os_defines.h' if it does not get the +# 'features.h' it was (really) looking for. +# +configure_file ("${CMAKE_CURRENT_SOURCE_DIR}/keysmith-features.h.in" "${CMAKE_CURRENT_BINARY_DIR}/keysmith-features.h") + set(keysmith_SRCS main.cpp ) @@ -33,6 +41,10 @@ target_link_libraries(keysmith ${keysmith_internal_libs} ) +if (ENABLE_DBUS_INTERFACE) + target_link_libraries(keysmith KF5::DBusAddons) +endif() + if(ANDROID) kirigami_package_breeze_icons(ICONS application-quit diff --git a/src/keysmith-features.h.in b/src/keysmith-features.h.in new file mode 100644 index 0000000..baf0df5 --- /dev/null +++ b/src/keysmith-features.h.in @@ -0,0 +1,12 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2021 Johan Ouwerkerk + */ +#ifndef KEYSMITH_FEATURES_H +#define KEYSMITH_FEATURES_H + +// record support for optional features at configure (cmake) time + +#cmakedefine ENABLE_DBUS_INTERFACE true + +#endif diff --git a/src/main.cpp b/src/main.cpp index 304db9a..4e321cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -23,6 +23,7 @@ #include "validators/issuervalidator.h" #include "validators/secretvalidator.h" +#include "keysmith-features.h" #include "version.h" /* @@ -34,6 +35,10 @@ static QQmlDebuggingEnabler enabler; #endif +#ifdef ENABLE_DBUS_INTERFACE +#include +#endif + Q_DECL_EXPORT int main(int argc, char *argv[]) { QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling); @@ -72,6 +77,10 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) app::Proxy proxy(&app); +#ifdef ENABLE_DBUS_INTERFACE + KDBusService service(KDBusService::Unique); +#endif + QQmlApplicationEngine engine; engine.rootContext()->setContextObject(new KLocalizedContext(&engine));