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
This commit is contained in:
parent
0c2b90b57f
commit
2ffd4a6fba
25
src/main.cpp
25
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<QFileOpenEvent*>(event)->file();
|
||||
if (pMainWindow)
|
||||
pMainWindow->openFile(filename);
|
||||
else
|
||||
pFile = filename;
|
||||
}
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
16
src/main.h
16
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);
|
||||
};
|
||||
|
|
|
@ -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()<<tr("KeePass Databases (*.kdb)")<< tr("All Files (*)"));
|
||||
if(filename.isEmpty())return;
|
||||
if(FileOpen)
|
||||
if(!closeDatabase())return;
|
||||
openDatabase(filename);
|
||||
if (!filename.isEmpty())
|
||||
openFile(filename);
|
||||
}
|
||||
|
||||
void KeepassMainWindow::OnFileClose(){
|
||||
|
|
|
@ -39,6 +39,7 @@ class KeepassMainWindow : public QMainWindow, private Ui_MainWindow{
|
|||
|
||||
public slots:
|
||||
void OnUnLockWorkspace();
|
||||
void openFile(const QString& filename);
|
||||
|
||||
signals:
|
||||
void entryChanged();
|
||||
|
|
Loading…
Reference in New Issue