From a627870bbb067996f3995513c2cff5b088cc27b2 Mon Sep 17 00:00:00 2001 From: Keith Bennett Date: Sat, 22 Mar 2014 14:03:05 +0000 Subject: [PATCH] Added a new DatabaseWidget modal state. Commit d8857bf4 attempted to fix currentMode() while the DB had not yet been opened. However, the fix meant that the title bar always displayed the state as being "locked". This change works around the issue by introducing a new modal state for when the DB is not yet open. --- src/gui/DatabaseTabWidget.cpp | 14 ++++++++++---- src/gui/DatabaseWidget.cpp | 6 ++++-- src/gui/DatabaseWidget.h | 1 + src/gui/MainWindow.cpp | 1 + src/http/Service.cpp | 2 ++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/gui/DatabaseTabWidget.cpp b/src/gui/DatabaseTabWidget.cpp index 5c364f3c9..545a2bd82 100644 --- a/src/gui/DatabaseTabWidget.cpp +++ b/src/gui/DatabaseTabWidget.cpp @@ -229,7 +229,8 @@ void DatabaseTabWidget::checkReloadDatabases() ReloadBehavior reloadBehavior = ReloadBehavior(config()->get("ReloadBehavior").toInt()); if ( (reloadBehavior == AlwaysAsk) - || (reloadBehavior == ReloadUnmodified && mode == DatabaseWidget::EditMode) + || (reloadBehavior == ReloadUnmodified && (mode == DatabaseWidget::EditMode + || mode == DatabaseWidget::OpenMode)) || (reloadBehavior == ReloadUnmodified && dbStruct.modified)) { int res = QMessageBox::warning(this, fi.exists() ? tr("Database file changed") : tr("Database file removed"), tr("Do you want to discard your changes and reload?"), @@ -296,7 +297,8 @@ bool DatabaseTabWidget::closeDatabase(Database* db) if (dbName.right(1) == "*") { dbName.chop(1); } - if (dbStruct.dbWidget->currentMode() == DatabaseWidget::EditMode && db->hasKey()) { + if ((dbStruct.dbWidget->currentMode() == DatabaseWidget::EditMode || + dbStruct.dbWidget->currentMode() == DatabaseWidget::OpenMode) && db->hasKey()) { QMessageBox::StandardButton result = MessageBox::question( this, tr("Close?"), @@ -631,7 +633,9 @@ bool DatabaseTabWidget::hasLockableDatabases() i.next(); DatabaseWidget::Mode mode = i.value().dbWidget->currentMode(); - if ((mode == DatabaseWidget::ViewMode || mode == DatabaseWidget::EditMode) + if ((mode == DatabaseWidget::ViewMode || + mode == DatabaseWidget::EditMode || + mode == DatabaseWidget::OpenMode) && i.value().dbWidget->dbHasKey()) { return true; } @@ -647,7 +651,9 @@ void DatabaseTabWidget::lockDatabases() i.next(); DatabaseWidget::Mode mode = i.value().dbWidget->currentMode(); - if ((mode == DatabaseWidget::ViewMode || mode == DatabaseWidget::EditMode) + if ((mode == DatabaseWidget::ViewMode || + mode == DatabaseWidget::EditMode || + mode == DatabaseWidget::OpenMode) && i.value().dbWidget->dbHasKey()) { i.value().dbWidget->lock(); updateTabName(i.key()); diff --git a/src/gui/DatabaseWidget.cpp b/src/gui/DatabaseWidget.cpp index 9ddbddd7e..5202611a0 100644 --- a/src/gui/DatabaseWidget.cpp +++ b/src/gui/DatabaseWidget.cpp @@ -173,10 +173,12 @@ DatabaseWidget::Mode DatabaseWidget::currentMode() else if (currentWidget() == m_mainWidget) { return DatabaseWidget::ViewMode; } - else if (currentWidget() == m_unlockDatabaseWidget || - currentWidget() == m_databaseOpenWidget) { + else if (currentWidget() == m_unlockDatabaseWidget) { return DatabaseWidget::LockedMode; } + else if (currentWidget() == m_databaseOpenWidget) { + return DatabaseWidget::OpenMode; + } else { return DatabaseWidget::EditMode; } diff --git a/src/gui/DatabaseWidget.h b/src/gui/DatabaseWidget.h index 894d9811c..a6b06348c 100644 --- a/src/gui/DatabaseWidget.h +++ b/src/gui/DatabaseWidget.h @@ -55,6 +55,7 @@ public: None, ViewMode, EditMode, + OpenMode, LockedMode }; diff --git a/src/gui/MainWindow.cpp b/src/gui/MainWindow.cpp index 7c11d5b13..aa7330950 100644 --- a/src/gui/MainWindow.cpp +++ b/src/gui/MainWindow.cpp @@ -394,6 +394,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode) } case DatabaseWidget::EditMode: case DatabaseWidget::LockedMode: + case DatabaseWidget::OpenMode: Q_FOREACH (QAction* action, m_ui->menuEntries->actions()) { action->setEnabled(false); } diff --git a/src/http/Service.cpp b/src/http/Service.cpp index eea204df8..7de986df6 100644 --- a/src/http/Service.cpp +++ b/src/http/Service.cpp @@ -76,6 +76,7 @@ bool Service::isDatabaseOpened() const switch(dbWidget->currentMode()) { case DatabaseWidget::None: case DatabaseWidget::LockedMode: + case DatabaseWidget::OpenMode: break; case DatabaseWidget::ViewMode: @@ -93,6 +94,7 @@ bool Service::openDatabase() switch(dbWidget->currentMode()) { case DatabaseWidget::None: case DatabaseWidget::LockedMode: + case DatabaseWidget::OpenMode: break; case DatabaseWidget::ViewMode: