From 98a89e4f2c973683aef8f57eb527d3b7110d6287 Mon Sep 17 00:00:00 2001 From: thez3ro Date: Tue, 16 Jan 2018 00:49:32 +0100 Subject: [PATCH] add function for locking DBs from DBus, fix #687 --- CMakeLists.txt | 1 - README-DBus.md | 40 ------------------- src/CMakeLists.txt | 9 +---- src/config-keepassx.h.cmake | 1 - src/gui/MainWindow.cpp | 34 +++++++--------- src/gui/MainWindow.h | 9 +++-- src/gui/MainWindowAdaptor.cpp | 14 +++---- src/gui/MainWindowAdaptor.h | 16 +++++--- ...=> org.keepassxc.KeePassXC.MainWindow.xml} | 4 +- 9 files changed, 40 insertions(+), 88 deletions(-) delete mode 100644 README-DBus.md rename src/gui/{org.keepassxc.MainWindow.xml => org.keepassxc.KeePassXC.MainWindow.xml} (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index ef8d0b01f..3708667a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,6 @@ option(WITH_XC_BROWSER "Include browser integration with keepassxc-browser." OFF option(WITH_XC_HTTP "Include KeePassHTTP-compatible browser integration (deprecated, implies WITH_NETWORKING)." OFF) option(WITH_XC_YUBIKEY "Include YubiKey support." OFF) option(WITH_XC_SSHAGENT "Include SSH agent support." OFF) -option(WITH_XC_DBUS "Include DBus support." OFF) if(WITH_XC_HTTP) message(WARNING "KeePassHTTP support has been deprecated and will be removed in a future version. Please use WITH_XC_BROWSER instead!\n" diff --git a/README-DBus.md b/README-DBus.md deleted file mode 100644 index ae99e13ae..000000000 --- a/README-DBus.md +++ /dev/null @@ -1,40 +0,0 @@ -## Using D-BUS feature - -* Open keepassxc database: without password and key file - - qdbus org.keepassxc.MainWindow /keepassxc org.keepassxc.MainWindow.openDatabase /path/to/database.kdbx - -* Open keepassxc database: with password but without key file - - qdbus org.keepassxc.MainWindow /keepassxc org.keepassxc.MainWindow.openDatabase /path/to/database.kdbx passwd - -* Open keepassxc database: with password and key file - - qdbus org.keepassxc.MainWindow /keepassxc org.keepassxc.MainWindow.openDatabase /path/to/database.kdbx passwd /path/to/key - -* Close all keepassxc databases - - qdbus org.keepassxc.MainWindow /keepassxc org.keepassxc.MainWindow.closeAllDatabases - -* Exit keepassxc - - qdbus org.keepassxc.MainWindow /keepassxc org.keepassxc.MainWindow.exit - -## Develop - -* Regenerate XML file for DBus ( If MainWindow class public methods were modified ) - - cd src/gui - - qdbusxml2cpp -c MainWindowAdaptor -a MainWindowAdaptor.h:MainWindowAdaptor.cpp org.keepassxc.MainWindow.xml - -* It can be usefull to know how to generate the XML adaptor - -* * Generate template from sources - - qdbuscpp2xml -M -s MainWindow.h -o org.keepassxc.MainWindow.xml - -* * Make sure interface name is org.keepassxc.MainWindow - - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index eebb52710..acc01e2bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -174,6 +174,7 @@ if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "OpenB set(keepassx_SOURCES ${keepassx_SOURCES} core/ScreenLockListenerDBus.h core/ScreenLockListenerDBus.cpp + gui/MainWindowAdaptor.cpp ) endif() if(MINGW) @@ -193,7 +194,6 @@ add_feature_info(KeePassXC-Browser WITH_XC_BROWSER "Browser integration with Kee add_feature_info(KeePassHTTP WITH_XC_HTTP "Browser integration compatible with ChromeIPass and PassIFox (deprecated, implies Networking)") add_feature_info(SSHAgent WITH_XC_SSHAGENT "SSH agent integration compatible with KeeAgent") add_feature_info(YubiKey WITH_XC_YUBIKEY "YubiKey HMAC-SHA1 challenge-response") -add_feature_info(DBus WITH_XC_DBUS "Take keepassxc control by DBus") if(WITH_XC_HTTP) add_subdirectory(http) @@ -211,13 +211,6 @@ if(WITH_XC_BROWSER) set(keepassxcbrowser_LIB keepassxcbrowser) endif() -if(UNIX AND NOT APPLE AND WITH_XC_DBUS) - set(keepassx_SOURCES - ${keepassx_SOURCES} - gui/MainWindowAdaptor.cpp - ) -endif() - add_subdirectory(autotype) add_subdirectory(cli) diff --git a/src/config-keepassx.h.cmake b/src/config-keepassx.h.cmake index 9b4252ebf..e98830b09 100644 --- a/src/config-keepassx.h.cmake +++ b/src/config-keepassx.h.cmake @@ -18,7 +18,6 @@ #cmakedefine WITH_XC_HTTP #cmakedefine WITH_XC_YUBIKEY #cmakedefine WITH_XC_SSHAGENT -#cmakedefine WITH_XC_DBUS #cmakedefine KEEPASSXC_DIST #cmakedefine KEEPASSXC_DIST_TYPE "@KEEPASSXC_DIST_TYPE@" diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 0b8e83bb0..b25f9d554 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -24,11 +24,6 @@ #include #include -#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) -#include -#include -#endif - #include "config-keepassx.h" #include "autotype/AutoType.h" @@ -61,15 +56,14 @@ #include "browser/BrowserOptionDialog.h" #endif -#include "gui/SettingsWidget.h" -#include "gui/PasswordGeneratorWidget.h" - -#ifdef WITH_XC_DBUS -#if defined(Q_OS_LINUX) -#include +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) +#include +#include #include "gui/MainWindowAdaptor.h" #endif -#endif + +#include "gui/SettingsWidget.h" +#include "gui/PasswordGeneratorWidget.h" #ifdef WITH_XC_HTTP class HttpPlugin: public ISettingsPage @@ -175,16 +169,13 @@ MainWindow::MainWindow() , m_appExiting(false) { m_ui->setupUi(this); - #ifdef WITH_XC_DBUS - #if defined(Q_OS_LINUX) + +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) new MainWindowAdaptor(this); QDBusConnection dbus = QDBusConnection::sessionBus(); dbus.registerObject("/keepassxc", this); - dbus.registerService("org.keepassxc.MainWindow"); - #else - qWarning("DBus is not available on this system"); - #endif - #endif + dbus.registerService("org.keepassxc.KeePassXC.MainWindow"); +#endif setAcceptDrops(true); @@ -1145,3 +1136,8 @@ void MainWindow::closeAllDatabases() { m_ui->tabWidget->closeAllDatabases(); } + +void MainWindow::lockAllDatabases() +{ + lockDatabasesAfterInactivity(); +} \ No newline at end of file diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index a616d878f..fd31fab0b 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -38,8 +38,8 @@ class MainWindow : public QMainWindow { Q_OBJECT -#if defined(Q_OS_LINUX) - Q_CLASSINFO("D-Bus Interface", "org.keepassxc.MainWindow") +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) + Q_CLASSINFO("D-Bus Interface", "org.keepassxc.KeePassXC.MainWindow") #endif public: @@ -67,10 +67,11 @@ public slots: void hideYubiKeyPopup(); void bringToFront(); void closeAllDatabases(); + void lockAllDatabases(); protected: - void closeEvent(QCloseEvent* event) override; - void changeEvent(QEvent* event) override; + void closeEvent(QCloseEvent* event) override; + void changeEvent(QEvent* event) override; private slots: void setMenuActionState(DatabaseWidget::Mode mode = DatabaseWidget::None); diff --git a/src/gui/MainWindowAdaptor.cpp b/src/gui/MainWindowAdaptor.cpp index 5d1838d27..8b229ce34 100644 --- a/src/gui/MainWindowAdaptor.cpp +++ b/src/gui/MainWindowAdaptor.cpp @@ -1,5 +1,5 @@ /* - * This file was generated by qdbusxml2cpp version 0.7 + * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c MainWindowAdaptor -a MainWindowAdaptor.h:MainWindowAdaptor.cpp org.keepassxc.MainWindow.xml * * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. @@ -24,42 +24,40 @@ MainWindowAdaptor::MainWindowAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) { - // constructor setAutoRelaySignals(true); } MainWindowAdaptor::~MainWindowAdaptor() { - // destructor } void MainWindowAdaptor::appExit() { - // handle method call org.keepassxc.MainWindow.appExit QMetaObject::invokeMethod(parent(), "appExit"); } void MainWindowAdaptor::closeAllDatabases() { - // handle method call org.keepassxc.MainWindow.closeAllDatabases QMetaObject::invokeMethod(parent(), "closeAllDatabases"); } +void MainWindowAdaptor::lockAllDatabases() +{ + QMetaObject::invokeMethod(parent(), "lockAllDatabases"); +} + void MainWindowAdaptor::openDatabase(const QString &fileName) { - // handle method call org.keepassxc.MainWindow.openDatabase QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName)); } void MainWindowAdaptor::openDatabase(const QString &fileName, const QString &pw) { - // handle method call org.keepassxc.MainWindow.openDatabase QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName), Q_ARG(QString, pw)); } void MainWindowAdaptor::openDatabase(const QString &fileName, const QString &pw, const QString &keyFile) { - // handle method call org.keepassxc.MainWindow.openDatabase QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName), Q_ARG(QString, pw), Q_ARG(QString, keyFile)); } diff --git a/src/gui/MainWindowAdaptor.h b/src/gui/MainWindowAdaptor.h index 32af2819e..06e0ce87e 100644 --- a/src/gui/MainWindowAdaptor.h +++ b/src/gui/MainWindowAdaptor.h @@ -1,5 +1,5 @@ /* - * This file was generated by qdbusxml2cpp version 0.7 + * This file was generated by qdbusxml2cpp version 0.8 * Command line was: qdbusxml2cpp -c MainWindowAdaptor -a MainWindowAdaptor.h:MainWindowAdaptor.cpp org.keepassxc.MainWindow.xml * * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. @@ -9,17 +9,19 @@ * before re-generating it. */ -#ifndef MAINWINDOWADAPTOR_H_1486736200 -#define MAINWINDOWADAPTOR_H_1486736200 +#ifndef MAINWINDOWADAPTOR_H +#define MAINWINDOWADAPTOR_H #include #include +QT_BEGIN_NAMESPACE class QByteArray; template class QList; template class QMap; class QString; class QStringList; class QVariant; +QT_END_NAMESPACE /* * Adaptor class for interface org.keepassxc.MainWindow @@ -43,6 +45,7 @@ class MainWindowAdaptor: public QDBusAbstractAdaptor " \n" " \n" " \n" +" \n" " \n" " \n" "") @@ -50,14 +53,15 @@ public: MainWindowAdaptor(QObject *parent); virtual ~MainWindowAdaptor(); -public: // PROPERTIES -public Q_SLOTS: // METHODS +public: +public slots: void appExit(); void closeAllDatabases(); + void lockAllDatabases(); void openDatabase(const QString &fileName); void openDatabase(const QString &fileName, const QString &pw); void openDatabase(const QString &fileName, const QString &pw, const QString &keyFile); -Q_SIGNALS: // SIGNALS +signals: }; #endif diff --git a/src/gui/org.keepassxc.MainWindow.xml b/src/gui/org.keepassxc.KeePassXC.MainWindow.xml similarity index 86% rename from src/gui/org.keepassxc.MainWindow.xml rename to src/gui/org.keepassxc.KeePassXC.MainWindow.xml index 506339e2c..635a66b93 100644 --- a/src/gui/org.keepassxc.MainWindow.xml +++ b/src/gui/org.keepassxc.KeePassXC.MainWindow.xml @@ -1,6 +1,6 @@ - + @@ -15,6 +15,8 @@ + +