From 679398be00bc6a68d91fbf40a8aed31cac493623 Mon Sep 17 00:00:00 2001 From: Tobias Tangemann Date: Thu, 10 May 2012 16:42:17 +0200 Subject: [PATCH] Handle OSX Finder events --- src/CMakeLists.txt | 2 ++ src/core/KeePassApp.cpp | 47 +++++++++++++++++++++++++++++++++++++++++ src/core/KeePassApp.h | 33 +++++++++++++++++++++++++++++ src/main.cpp | 4 +++- 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/core/KeePassApp.cpp create mode 100644 src/core/KeePassApp.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 459a1540b..b5d15060f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) configure_file( config-keepassx.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-keepassx.h ) set(keepassx_SOURCES + core/KeePassApp.cpp core/Config.cpp core/Database.cpp core/DatabaseIcons.cpp @@ -86,6 +87,7 @@ set(keepassx_SOURCES ) set(keepassx_MOC + core/KeePassApp.h core/Database.h core/Entry.h core/EntryAttachments.h diff --git a/src/core/KeePassApp.cpp b/src/core/KeePassApp.cpp new file mode 100644 index 000000000..688fc1d2f --- /dev/null +++ b/src/core/KeePassApp.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2012 Tobias Tangemann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "KeePassApp.h" + +#include +#include + +KeePassApp::KeePassApp(int &argc, char **argv) : + QApplication(argc, argv), + mainWindow(NULL) +{ +} + +KeePassApp::~KeePassApp() +{ +} + +void KeePassApp::setMainWindow(MainWindow *mainWindow) +{ + this->mainWindow = mainWindow; +} + +bool KeePassApp::event(QEvent *event) +{ + // Handle Apple QFileOpenEvent from finder (double click on .kdbx file) + if (event->type() == QEvent::FileOpen && mainWindow) { + mainWindow->openDatabase(static_cast(event)->file(), QString(), QString()); + return true; + } + + return (QApplication::event(event)); +} \ No newline at end of file diff --git a/src/core/KeePassApp.h b/src/core/KeePassApp.h new file mode 100644 index 000000000..a5242c146 --- /dev/null +++ b/src/core/KeePassApp.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2012 Tobias Tangemann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include +#include "gui/MainWindow.h" + +class KeePassApp : public QApplication +{ + Q_OBJECT +private: + MainWindow *mainWindow; + +public: + KeePassApp(int &argc, char **argv); + ~KeePassApp(); + + void setMainWindow(MainWindow *mainWindow); + bool event(QEvent *event); +}; \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 49487cd39..118edd154 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,12 +21,13 @@ #include "crypto/Crypto.h" #include "gui/MainWindow.h" +#include "core/KeePassApp.h" #include "keys/CompositeKey.h" #include "keys/PasswordKey.h" int main(int argc, char** argv) { - QApplication app(argc, argv); + KeePassApp app(argc, argv); // don't set applicationName or organizationName as that changes // QDesktopServices::storageLocation() @@ -50,6 +51,7 @@ int main(int argc, char** argv) } MainWindow mainWindow; + app.setMainWindow(&mainWindow); mainWindow.show(); if (!filename.isEmpty()) {