diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 80ca54a49..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) @@ -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) diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 915676e3c..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,6 +56,12 @@ #include "browser/BrowserOptionDialog.h" #endif +#if defined(Q_OS_UNIX) && !defined(Q_OS_MAC) && !defined(QT_NO_DBUS) +#include +#include +#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(); +} \ No newline at end of file diff --git a/src/gui/MainWindow.h b/src/gui/MainWindow.h index f3b288003..fd31fab0b 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_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); diff --git a/src/gui/MainWindowAdaptor.cpp b/src/gui/MainWindowAdaptor.cpp new file mode 100644 index 000000000..8b229ce34 --- /dev/null +++ b/src/gui/MainWindowAdaptor.cpp @@ -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 +#include +#include +#include +#include +#include +#include + +/* + * 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)); +} + diff --git a/src/gui/MainWindowAdaptor.h b/src/gui/MainWindowAdaptor.h new file mode 100644 index 000000000..06e0ce87e --- /dev/null +++ b/src/gui/MainWindowAdaptor.h @@ -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 +#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 + */ +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" +" \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 diff --git a/src/gui/org.keepassxc.KeePassXC.MainWindow.xml b/src/gui/org.keepassxc.KeePassXC.MainWindow.xml new file mode 100644 index 000000000..635a66b93 --- /dev/null +++ b/src/gui/org.keepassxc.KeePassXC.MainWindow.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + +