diff --git a/CMakeLists.txt b/CMakeLists.txt index 3708667a7..ef8d0b01f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ 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 new file mode 100644 index 000000000..ae99e13ae --- /dev/null +++ b/README-DBus.md @@ -0,0 +1,40 @@ +## 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 80ca54a49..eebb52710 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -193,7 +193,7 @@ 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,6 +211,13 @@ 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 e98830b09..9b4252ebf 100644 --- a/src/config-keepassx.h.cmake +++ b/src/config-keepassx.h.cmake @@ -18,6 +18,7 @@ #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 915676e3c..0b8e83bb0 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -64,6 +64,13 @@ #include "gui/SettingsWidget.h" #include "gui/PasswordGeneratorWidget.h" +#ifdef WITH_XC_DBUS +#if defined(Q_OS_LINUX) +#include +#include "gui/MainWindowAdaptor.h" +#endif +#endif + #ifdef WITH_XC_HTTP class HttpPlugin: public ISettingsPage { @@ -168,6 +175,16 @@ MainWindow::MainWindow() , m_appExiting(false) { m_ui->setupUi(this); + #ifdef WITH_XC_DBUS + #if defined(Q_OS_LINUX) + 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 setAcceptDrops(true); @@ -1123,3 +1140,8 @@ void MainWindow::dropEvent(QDropEvent* event) } } } + +void MainWindow::closeAllDatabases() +{ + m_ui->tabWidget->closeAllDatabases(); +} diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index f3b288003..a616d878f 100644 --- a/src/gui/MainWindow.h +++ b/src/gui/MainWindow.h @@ -37,6 +37,10 @@ class InactivityTimer; class MainWindow : public QMainWindow { Q_OBJECT + +#if defined(Q_OS_LINUX) + Q_CLASSINFO("D-Bus Interface", "org.keepassxc.MainWindow") +#endif public: MainWindow(); @@ -62,6 +66,7 @@ public slots: void showYubiKeyPopup(); void hideYubiKeyPopup(); void bringToFront(); + void closeAllDatabases(); protected: void closeEvent(QCloseEvent* event) override; diff --git a/src/gui/MainWindowAdaptor.cpp b/src/gui/MainWindowAdaptor.cpp new file mode 100644 index 000000000..5d1838d27 --- /dev/null +++ b/src/gui/MainWindowAdaptor.cpp @@ -0,0 +1,65 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c MainWindowAdaptor -a MainWindowAdaptor.h:MainWindowAdaptor.cpp org.keepassxc.MainWindow.xml + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * Do not edit! All changes made to it will be lost. + */ + +#include "MainWindowAdaptor.h" +#include +#include +#include +#include +#include +#include +#include + +/* + * Implementation of adaptor class MainWindowAdaptor + */ + +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::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 new file mode 100644 index 000000000..32af2819e --- /dev/null +++ b/src/gui/MainWindowAdaptor.h @@ -0,0 +1,63 @@ +/* + * This file was generated by qdbusxml2cpp version 0.7 + * Command line was: qdbusxml2cpp -c MainWindowAdaptor -a MainWindowAdaptor.h:MainWindowAdaptor.cpp org.keepassxc.MainWindow.xml + * + * qdbusxml2cpp is Copyright (C) 2015 The Qt Company Ltd. + * + * This is an auto-generated file. + * This file may have been hand-edited. Look for HAND-EDIT comments + * before re-generating it. + */ + +#ifndef MAINWINDOWADAPTOR_H_1486736200 +#define MAINWINDOWADAPTOR_H_1486736200 + +#include +#include +class QByteArray; +template class QList; +template class QMap; +class QString; +class QStringList; +class QVariant; + +/* + * Adaptor class for interface org.keepassxc.MainWindow + */ +class MainWindowAdaptor: public QDBusAbstractAdaptor +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.keepassxc.MainWindow") + Q_CLASSINFO("D-Bus Introspection", "" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" + "") +public: + MainWindowAdaptor(QObject *parent); + virtual ~MainWindowAdaptor(); + +public: // PROPERTIES +public Q_SLOTS: // METHODS + void appExit(); + void closeAllDatabases(); + 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 +}; + +#endif diff --git a/src/gui/org.keepassxc.MainWindow.xml b/src/gui/org.keepassxc.MainWindow.xml new file mode 100644 index 000000000..506339e2c --- /dev/null +++ b/src/gui/org.keepassxc.MainWindow.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + +