diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 459a1540..b5d15060 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 00000000..688fc1d2
--- /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 00000000..a5242c14
--- /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 49487cd3..118edd15 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()) {