mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2024-10-01 01:26:01 -04:00
Add DBus support: control keepassxc on desktop events (load database when log in, close all databases when log out)
This commit is contained in:
parent
46c58b3202
commit
e560650bf3
@ -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"
|
||||
|
40
README-DBus.md
Normal file
40
README-DBus.md
Normal file
@ -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
|
||||
|
||||
<interface name="org.keepassxc.MainWindow">
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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@"
|
||||
|
@ -64,6 +64,13 @@
|
||||
#include "gui/SettingsWidget.h"
|
||||
#include "gui/PasswordGeneratorWidget.h"
|
||||
|
||||
#ifdef WITH_XC_DBUS
|
||||
#if defined(Q_OS_LINUX)
|
||||
#include <QtDBus>
|
||||
#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();
|
||||
}
|
||||
|
@ -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;
|
||||
|
65
src/gui/MainWindowAdaptor.cpp
Normal file
65
src/gui/MainWindowAdaptor.cpp
Normal file
@ -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 <QtCore/QMetaObject>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
/*
|
||||
* 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));
|
||||
}
|
||||
|
63
src/gui/MainWindowAdaptor.h
Normal file
63
src/gui/MainWindowAdaptor.h
Normal file
@ -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 <QtCore/QObject>
|
||||
#include <QtDBus/QtDBus>
|
||||
class QByteArray;
|
||||
template<class T> class QList;
|
||||
template<class Key, class Value> 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", ""
|
||||
" <interface name=\"org.keepassxc.MainWindow\">\n"
|
||||
" <method name=\"openDatabase\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"fileName\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"pw\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"keyFile\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"openDatabase\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"fileName\"/>\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"pw\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"openDatabase\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"fileName\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"appExit\"/>\n"
|
||||
" <method name=\"closeAllDatabases\"/>\n"
|
||||
" </interface>\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
|
21
src/gui/org.keepassxc.MainWindow.xml
Normal file
21
src/gui/org.keepassxc.MainWindow.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
|
||||
<node>
|
||||
<interface name="org.keepassxc.MainWindow">
|
||||
<method name="openDatabase">
|
||||
<arg name="fileName" type="s" direction="in"/>
|
||||
<arg name="pw" type="s" direction="in"/>
|
||||
<arg name="keyFile" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="openDatabase">
|
||||
<arg name="fileName" type="s" direction="in"/>
|
||||
<arg name="pw" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="openDatabase">
|
||||
<arg name="fileName" type="s" direction="in"/>
|
||||
</method>
|
||||
<method name="appExit">
|
||||
</method>
|
||||
<method name="closeAllDatabases">
|
||||
</method>
|
||||
</interface>
|
||||
</node>
|
Loading…
Reference in New Issue
Block a user