Merge pull request #283 from didier13150/feature/dbus

Add DBus support
This commit is contained in:
Janek Bevendorff 2018-01-28 14:12:33 +01:00 committed by GitHub
commit 2849e19d49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 185 additions and 8 deletions

View File

@ -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)
@ -194,7 +195,6 @@ add_feature_info(KeePassHTTP WITH_XC_HTTP "Browser integration compatible with C
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")
if(WITH_XC_HTTP)
add_subdirectory(http)
set(keepasshttp_LIB keepasshttp)

View File

@ -24,11 +24,6 @@
#include <QShortcut>
#include <QTimer>
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS)
#include <QList>
#include <QtDBus/QtDBus>
#endif
#include "config-keepassx.h"
#include "autotype/AutoType.h"
@ -61,6 +56,12 @@
#include "browser/BrowserOptionDialog.h"
#endif
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS)
#include <QList>
#include <QtDBus/QtDBus>
#include "gui/MainWindowAdaptor.h"
#endif
#include "gui/SettingsWidget.h"
#include "gui/PasswordGeneratorWidget.h"
@ -168,6 +169,13 @@ MainWindow::MainWindow()
, m_appExiting(false)
{
m_ui->setupUi(this);
#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.KeePassXC.MainWindow");
#endif
setAcceptDrops(true);
@ -1123,3 +1131,13 @@ void MainWindow::dropEvent(QDropEvent* event)
}
}
}
void MainWindow::closeAllDatabases()
{
m_ui->tabWidget->closeAllDatabases();
}
void MainWindow::lockAllDatabases()
{
lockDatabasesAfterInactivity();
}

View File

@ -37,6 +37,10 @@ class InactivityTimer;
class MainWindow : public QMainWindow
{
Q_OBJECT
#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS)
Q_CLASSINFO("D-Bus Interface", "org.keepassxc.KeePassXC.MainWindow")
#endif
public:
MainWindow();
@ -62,10 +66,12 @@ public slots:
void showYubiKeyPopup();
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);

View File

@ -0,0 +1,63 @@
/*
* 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.
*
* 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)
{
setAutoRelaySignals(true);
}
MainWindowAdaptor::~MainWindowAdaptor()
{
}
void MainWindowAdaptor::appExit()
{
QMetaObject::invokeMethod(parent(), "appExit");
}
void MainWindowAdaptor::closeAllDatabases()
{
QMetaObject::invokeMethod(parent(), "closeAllDatabases");
}
void MainWindowAdaptor::lockAllDatabases()
{
QMetaObject::invokeMethod(parent(), "lockAllDatabases");
}
void MainWindowAdaptor::openDatabase(const QString &fileName)
{
QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName));
}
void MainWindowAdaptor::openDatabase(const QString &fileName, const QString &pw)
{
QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName), Q_ARG(QString, pw));
}
void MainWindowAdaptor::openDatabase(const QString &fileName, const QString &pw, const QString &keyFile)
{
QMetaObject::invokeMethod(parent(), "openDatabase", Q_ARG(QString, fileName), Q_ARG(QString, pw), Q_ARG(QString, keyFile));
}

View File

@ -0,0 +1,67 @@
/*
* 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.
*
* 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
#define MAINWINDOWADAPTOR_H
#include <QtCore/QObject>
#include <QtDBus/QtDBus>
QT_BEGIN_NAMESPACE
class QByteArray;
template<class T> class QList;
template<class Key, class Value> class QMap;
class QString;
class QStringList;
class QVariant;
QT_END_NAMESPACE
/*
* 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=\"lockAllDatabases\"/>\n"
" <method name=\"closeAllDatabases\"/>\n"
" </interface>\n"
"")
public:
MainWindowAdaptor(QObject *parent);
virtual ~MainWindowAdaptor();
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);
signals:
};
#endif

View File

@ -0,0 +1,23 @@
<!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.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="lockAllDatabases">
</method>
<method name="closeAllDatabases">
</method>
</interface>
</node>