From 509328343f490192b93b7bfe51df7e1da82478a8 Mon Sep 17 00:00:00 2001 From: Felix Geyer Date: Mon, 26 Dec 2011 19:17:11 +0100 Subject: [PATCH] Show KeyOpenDialog with show() instead of exec(). --- src/gui/DatabaseManager.cpp | 56 ++++++++++++++++++++++++++----------- src/gui/DatabaseManager.h | 7 +++++ 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/src/gui/DatabaseManager.cpp b/src/gui/DatabaseManager.cpp index e187d4f26..495adfab6 100644 --- a/src/gui/DatabaseManager.cpp +++ b/src/gui/DatabaseManager.cpp @@ -62,14 +62,12 @@ void DatabaseManager::openDatabase() void DatabaseManager::openDatabase(const QString& fileName) { - DatabaseManagerStruct dbStruct; - QScopedPointer file(new QFile(fileName)); // TODO error handling if (!file->open(QIODevice::ReadWrite)) { if (!file->open(QIODevice::ReadOnly)) { // can only open read-only - dbStruct.readOnly = true; + m_curDbStruct.readOnly = true; } else { // can't open @@ -77,22 +75,47 @@ void DatabaseManager::openDatabase(const QString& fileName) } } - Database* db; + m_curDbStruct.file = file.take(); + m_curDbStruct.fileName = QFileInfo(fileName).absoluteFilePath(); - do { - QScopedPointer keyDialog(new KeyOpenDialog(fileName, m_window)); - if (keyDialog->exec() == QDialog::Rejected) { - return; - } + openDatabaseDialog(); +} - file->reset(); - db = m_reader.readDatabase(file.data(), keyDialog->key()); - } while (!db); +void DatabaseManager::openDatabaseDialog() +{ + m_curKeyDialog = new KeyOpenDialog(m_curDbStruct.fileName, m_window); + connect(m_curKeyDialog, SIGNAL(accepted()), SLOT(openDatabaseRead())); + connect(m_curKeyDialog, SIGNAL(rejected()), SLOT(openDatabaseCleanup())); + m_curKeyDialog->setModal(true); + m_curKeyDialog->show(); +} - dbStruct.file = file.take(); - dbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget); +void DatabaseManager::openDatabaseRead() +{ + m_curDbStruct.file->reset(); + Database* db = m_reader.readDatabase(m_curDbStruct.file, m_curKeyDialog->key()); + delete m_curKeyDialog; + m_curKeyDialog = 0; - insertDatabase(db, dbStruct); + if (!db) { + openDatabaseDialog(); + } + else { + m_curDbStruct.dbWidget = new DatabaseWidget(db, m_tabWidget); + insertDatabase(db, m_curDbStruct); + m_curDbStruct = DatabaseManagerStruct(); + } +} + +void DatabaseManager::openDatabaseCleanup() +{ + delete m_curKeyDialog; + m_curKeyDialog = 0; + + if (m_curDbStruct.file) { + delete m_curDbStruct.file; + } + m_curDbStruct = DatabaseManagerStruct(); } void DatabaseManager::closeDatabase(Database* db) @@ -151,6 +174,7 @@ void DatabaseManager::saveDatabaseAs(Database* db) dbStruct.file->flush(); dbStruct.modified = false; + dbStruct.fileName = QFileInfo(fileName).absoluteFilePath(); updateTabName(db); } } @@ -200,7 +224,7 @@ void DatabaseManager::updateTabName(Database* db) tabName = db->metadata()->name(); } - m_tabWidget->setTabToolTip(index, fileInfo.absoluteFilePath()); + m_tabWidget->setTabToolTip(index, dbStruct.fileName); } else { if (db->metadata()->name().isEmpty()) { diff --git a/src/gui/DatabaseManager.h b/src/gui/DatabaseManager.h index 9f93614da..aa48b24f9 100644 --- a/src/gui/DatabaseManager.h +++ b/src/gui/DatabaseManager.h @@ -24,6 +24,7 @@ #include "format/KeePass2Reader.h" #include "format/KeePass2Writer.h" +class KeyOpenDialog; class QFile; class QTabWidget; @@ -33,6 +34,7 @@ struct DatabaseManagerStruct QFile* file; QWidget* dbWidget; + QString fileName; bool modified; bool readOnly; }; @@ -57,6 +59,9 @@ public Q_SLOTS: private Q_SLOTS: void updateTabName(Database* db); + void openDatabaseDialog(); + void openDatabaseRead(); + void openDatabaseCleanup(); private: int databaseIndex(Database* db); @@ -68,6 +73,8 @@ private: KeePass2Reader m_reader; KeePass2Writer m_writer; QHash m_dbList; + DatabaseManagerStruct m_curDbStruct; + KeyOpenDialog* m_curKeyDialog; }; #endif // KEEPASSX_DATABASEMANAGER_H