Use a signal to connect to a slot in main window.

Coding style fixes.

http://gitorious.org/keepassx/keepassx/merge_requests/10
This commit is contained in:
Florian Geyer 2012-05-17 23:59:31 +02:00 committed by Felix Geyer
parent 679398be00
commit d445bf1ecd
4 changed files with 22 additions and 25 deletions

View File

@ -17,12 +17,10 @@
#include "KeePassApp.h"
#include <QtGui/QMessageBox>
#include <QtGui/QFileOpenEvent>
KeePassApp::KeePassApp(int &argc, char **argv) :
QApplication(argc, argv),
mainWindow(NULL)
KeePassApp::KeePassApp(int& argc, char** argv)
: QApplication(argc, argv)
{
}
@ -30,18 +28,13 @@ 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<QFileOpenEvent*>(event)->file(), QString(), QString());
return true;
}
// Handle Apple QFileOpenEvent from finder (double click on .kdbx file)
if (event->type() == QEvent::FileOpen) {
Q_EMIT openDatabase(static_cast<QFileOpenEvent*>(event)->file());
return true;
}
return (QApplication::event(event));
}
}

View File

@ -20,14 +20,14 @@
class KeePassApp : public QApplication
{
Q_OBJECT
private:
MainWindow *mainWindow;
Q_OBJECT
public:
KeePassApp(int &argc, char **argv);
~KeePassApp();
KeePassApp(int& argc, char** argv);
~KeePassApp();
void setMainWindow(MainWindow *mainWindow);
bool event(QEvent *event);
};
bool event(QEvent *event);
Q_SIGNALS:
void openDatabase(const QString& filename);
};

View File

@ -33,7 +33,10 @@ class MainWindow : public QMainWindow
public:
MainWindow();
~MainWindow();
void openDatabase(const QString& fileName, const QString& pw, const QString& keyFile);
public Q_SLOTS:
void openDatabase(const QString& fileName, const QString& pw = QString(),
const QString& keyFile = QString());
protected:
void closeEvent(QCloseEvent* event);

View File

@ -51,9 +51,10 @@ int main(int argc, char** argv)
}
MainWindow mainWindow;
app.setMainWindow(&mainWindow);
mainWindow.show();
QObject::connect(&app, SIGNAL(openDatabase(QString)), &mainWindow, SLOT(openDatabase(QString)));
if (!filename.isEmpty()) {
mainWindow.openDatabase(filename, password, QString());
}