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
master
sniperbeamer 16 years ago
parent 0c2b90b57f
commit 2ffd4a6fba
  1. 25
      src/main.cpp
  2. 16
      src/main.h
  3. 16
      src/mainwindow.cpp
  4. 1
      src/mainwindow.h

@ -58,6 +58,10 @@ int main(int argc, char **argv)
#else #else
QApplication* app = new QApplication(argc,argv); QApplication* app = new QApplication(argc,argv);
#endif #endif
EventListener* eventListener = new EventListener();
app->installEventFilter(eventListener);
QApplication::setQuitOnLastWindowClosed(false);
AppDir = QApplication::applicationFilePath(); AppDir = QApplication::applicationFilePath();
AppDir.truncate(AppDir.lastIndexOf("/")); AppDir.truncate(AppDir.lastIndexOf("/"));
@ -188,11 +192,16 @@ int main(int argc, char **argv)
installTranslator(); installTranslator();
EventListener* eventListener = new EventListener(); #ifdef Q_WS_MAC
app->installEventFilter(eventListener); 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()); KeepassMainWindow *mainWin = new KeepassMainWindow(args.file(), args.startMinimized(), args.startLocked());
#ifdef Q_WS_MAC
eventListener->setMainWin(mainWin);
#endif
int r=app->exec(); int r=app->exec();
delete mainWin; delete mainWin;
@ -289,5 +298,15 @@ bool EventListener::eventFilter(QObject*, QEvent* event){
EventOccurred = true; EventOccurred = true;
} }
#ifdef Q_WS_MAC
if (event->type() == QEvent::FileOpen) {
QString filename = static_cast<QFileOpenEvent*>(event)->file();
if (pMainWindow)
pMainWindow->openFile(filename);
else
pFile = filename;
}
#endif
return false; return false;
} }

@ -20,6 +20,8 @@
#ifndef _MAIN_H_ #ifndef _MAIN_H_
#define _MAIN_H_ #define _MAIN_H_
#include "mainwindow.h"
QString findPlugin(const QString& filename); QString findPlugin(const QString& filename);
void loadImages(); void loadImages();
void initAppPaths(int argc, char **argv); void initAppPaths(int argc, char **argv);
@ -37,6 +39,7 @@ public:
bool startMinimized() {return StartMinimized;} bool startMinimized() {return StartMinimized;}
bool startLocked() {return StartLocked;} bool startLocked() {return StartLocked;}
bool help() {return Help;} bool help() {return Help;}
void setFile(const QString& filename) {File = filename;};
private: private:
QString Error; QString Error;
QString File; QString File;
@ -50,6 +53,19 @@ private:
class EventListener : public QObject { class EventListener : public QObject {
Q_OBJECT 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: protected:
bool eventFilter(QObject*, QEvent* event); bool eventFilter(QObject*, QEvent* event);
}; };

@ -584,11 +584,13 @@ void KeepassMainWindow::OnFileNewKdb(){
} }
} }
// TODO Kxdb void KeepassMainWindow::openFile(const QString& filename) {
/* if(FileOpen) {
void KeepassMainWindow::OnFileNewKxdb(){ if(!closeDatabase())
return;
}
openDatabase(filename);
} }
*/
void KeepassMainWindow::OnFileOpen(){ void KeepassMainWindow::OnFileOpen(){
/*QFileDialog FileDlg(this,tr("Open Database..."),QDir::homePath()); /*QFileDialog FileDlg(this,tr("Open Database..."),QDir::homePath());
@ -599,10 +601,8 @@ void KeepassMainWindow::OnFileOpen(){
if(!FileDlg.selectedFiles().size())return;*/ if(!FileDlg.selectedFiles().size())return;*/
QString filename=KpxFileDialogs::openExistingFile(this,"MainWindow_FileOpen", QString filename=KpxFileDialogs::openExistingFile(this,"MainWindow_FileOpen",
tr("Open Database..."),QStringList()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)")); tr("Open Database..."),QStringList()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)"));
if(filename.isEmpty())return; if (!filename.isEmpty())
if(FileOpen) openFile(filename);
if(!closeDatabase())return;
openDatabase(filename);
} }
void KeepassMainWindow::OnFileClose(){ void KeepassMainWindow::OnFileClose(){

@ -39,6 +39,7 @@ class KeepassMainWindow : public QMainWindow, private Ui_MainWindow{
public slots: public slots:
void OnUnLockWorkspace(); void OnUnLockWorkspace();
void openFile(const QString& filename);
signals: signals:
void entryChanged(); void entryChanged();