From 2ffd4a6fbacfd51ae8aa9ddede093252c80f34a3 Mon Sep 17 00:00:00 2001 From: sniperbeamer Date: Sun, 22 Mar 2009 18:01:53 +0000 Subject: [PATCH] Fix: Database is not opened when double-clicking on a *.kdb file [Mac OS] git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@300 b624d157-de02-0410-bad0-e51aec6abb33 --- src/main.cpp | 25 ++++++++++++++++++++++--- src/main.h | 16 ++++++++++++++++ src/mainwindow.cpp | 16 ++++++++-------- src/mainwindow.h | 1 + 4 files changed, 47 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 2924bae..738f14d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,6 +58,10 @@ int main(int argc, char **argv) #else QApplication* app = new QApplication(argc,argv); #endif + EventListener* eventListener = new EventListener(); + app->installEventFilter(eventListener); + + QApplication::setQuitOnLastWindowClosed(false); AppDir = QApplication::applicationFilePath(); AppDir.truncate(AppDir.lastIndexOf("/")); @@ -188,11 +192,16 @@ int main(int argc, char **argv) installTranslator(); - EventListener* eventListener = new EventListener(); - app->installEventFilter(eventListener); +#ifdef Q_WS_MAC + if (args.file().isEmpty() && !eventListener->file().isEmpty()) { + args.setFile(eventListener->file()); + } +#endif - QApplication::setQuitOnLastWindowClosed(false); KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked()); +#ifdef Q_WS_MAC + eventListener->setMainWin(mainWin); +#endif int r=app->exec(); delete mainWin; @@ -289,5 +298,15 @@ bool EventListener::eventFilter(QObject*, QEvent* event){ EventOccurred = true; } +#ifdef Q_WS_MAC + if (event->type() == QEvent::FileOpen) { + QString filename = static_cast(event)->file(); + if (pMainWindow) + pMainWindow->openFile(filename); + else + pFile = filename; + } +#endif + return false; } diff --git a/src/main.h b/src/main.h index 423a3c5..bb2a1a2 100644 --- a/src/main.h +++ b/src/main.h @@ -20,6 +20,8 @@ #ifndef _MAIN_H_ #define _MAIN_H_ +#include "mainwindow.h" + QString findPlugin(const QString& filename); void loadImages(); void initAppPaths(int argc, char **argv); @@ -37,6 +39,7 @@ public: bool startMinimized() {return StartMinimized;} bool startLocked() {return StartLocked;} bool help() {return Help;} + void setFile(const QString& filename) {File = filename;}; private: QString Error; QString File; @@ -50,6 +53,19 @@ private: class EventListener : public QObject { Q_OBJECT +#ifdef Q_WS_MAC + public: + EventListener() { pMainWindow = NULL; }; + inline QString file() { return pFile; }; + inline void setMainWin(KeepassMainWindow* mainWin) { + pMainWindow = mainWin; + }; + + private: + QString pFile; + KeepassMainWindow* pMainWindow; +#endif + protected: bool eventFilter(QObject*, QEvent* event); }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 5c90d96..8fc01a2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -584,11 +584,13 @@ void KeepassMainWindow::OnFileNewKdb(){ } } -// TODO Kxdb -/* -void KeepassMainWindow::OnFileNewKxdb(){ +void KeepassMainWindow::openFile(const QString& filename) { + if(FileOpen) { + if(!closeDatabase()) + return; + } + openDatabase(filename); } -*/ void KeepassMainWindow::OnFileOpen(){ /*QFileDialog FileDlg(this,tr("Open Database..."),QDir::homePath()); @@ -599,10 +601,8 @@ void KeepassMainWindow::OnFileOpen(){ if(!FileDlg.selectedFiles().size())return;*/ QString filename=KpxFileDialogs::openExistingFile(this,"MainWindow_FileOpen", tr("Open Database..."),QStringList()<