Fix saving order of open databases

* Order of previously open databases are preserved when closing the application
* The active database on closing remains active after startup
* Nested open previous databases and remember key files under the remember previously open databases setting
* Fix #1675
This commit is contained in:
Jonathan White 2019-03-21 17:39:02 -04:00
parent 28a3824d2d
commit 72f0e9ba77
6 changed files with 135 additions and 62 deletions

View File

@ -112,6 +112,10 @@ namespace Bootstrap
mainWindow.openDatabase(filename); mainWindow.openDatabase(filename);
} }
} }
auto lastActiveFile = config()->get("LastActiveDatabase").toString();
if (!lastActiveFile.isEmpty()) {
mainWindow.openDatabase(lastActiveFile);
}
} }
} }

View File

@ -81,7 +81,8 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
// clang-format off // clang-format off
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)), SLOT(autoSaveToggled(bool))); connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)), SLOT(autoSaveToggled(bool)));
connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)), SLOT(systrayToggled(bool))); connect(m_generalUi->systrayShowCheckBox, SIGNAL(toggled(bool)), SLOT(systrayToggled(bool)));
connect(m_generalUi->toolbarHideCheckBox, SIGNAL(toggled(bool)), SLOT(enableToolbarSettings(bool))); connect(m_generalUi->toolbarHideCheckBox, SIGNAL(toggled(bool)), SLOT(toolbarSettingsToggled(bool)));
connect(m_generalUi->rememberLastDatabasesCheckBox, SIGNAL(toggled(bool)), SLOT(rememberDatabasesToggled(bool)));
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)), connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool))); m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
@ -294,11 +295,13 @@ void ApplicationSettingsWidget::saveSettings()
// Security: clear storage if related settings are disabled // Security: clear storage if related settings are disabled
if (!config()->get("RememberLastDatabases").toBool()) { if (!config()->get("RememberLastDatabases").toBool()) {
config()->set("LastDatabases", QVariant()); config()->set("LastDatabases", {});
config()->set("OpenPreviousDatabasesOnStartup", {});
config()->set("LastActiveDatabase", {});
} }
if (!config()->get("RememberLastKeyFiles").toBool()) { if (!config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastKeyFiles", QVariant()); config()->set("LastKeyFiles", {});
config()->set("LastDir", ""); config()->set("LastDir", "");
} }
@ -330,9 +333,20 @@ void ApplicationSettingsWidget::systrayToggled(bool checked)
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked); m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
} }
void ApplicationSettingsWidget::enableToolbarSettings(bool checked) void ApplicationSettingsWidget::toolbarSettingsToggled(bool checked)
{ {
m_generalUi->toolbarMovableCheckBox->setEnabled(!checked); m_generalUi->toolbarMovableCheckBox->setEnabled(!checked);
m_generalUi->toolButtonStyleComboBox->setEnabled(!checked); m_generalUi->toolButtonStyleComboBox->setEnabled(!checked);
m_generalUi->toolButtonStyleLabel->setEnabled(!checked); m_generalUi->toolButtonStyleLabel->setEnabled(!checked);
} }
void ApplicationSettingsWidget::rememberDatabasesToggled(bool checked)
{
if (!checked) {
m_generalUi->rememberLastKeyFilesCheckBox->setChecked(false);
m_generalUi->openPreviousDatabasesOnStartupCheckBox->setChecked(false);
}
m_generalUi->rememberLastKeyFilesCheckBox->setEnabled(checked);
m_generalUi->openPreviousDatabasesOnStartupCheckBox->setEnabled(checked);
}

View File

@ -55,7 +55,8 @@ private slots:
void reject(); void reject();
void autoSaveToggled(bool checked); void autoSaveToggled(bool checked);
void systrayToggled(bool checked); void systrayToggled(bool checked);
void enableToolbarSettings(bool checked); void toolbarSettingsToggled(bool checked);
void rememberDatabasesToggled(bool checked);
private: private:
QWidget* const m_secWidget; QWidget* const m_secWidget;

View File

@ -49,33 +49,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
<property name="text">
<string>Remember last databases</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="rememberLastKeyFilesCheckBox">
<property name="text">
<string>Remember last key files and security dongles</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
<property name="text">
<string>Load previous databases on startup</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QCheckBox" name="systrayMinimizeOnStartup"> <widget class="QCheckBox" name="systrayMinimizeOnStartup">
<property name="text"> <property name="text">
@ -83,6 +56,88 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
<property name="text">
<string>Remember previously used databases</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="rememberDbSubLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="toolbarMovableSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="openPreviousDatabasesOnStartupCheckBox">
<property name="text">
<string>Load previously open databases on startup</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="rememberDbSubLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item>
<spacer name="toolbarMovableSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="rememberLastKeyFilesCheckBox">
<property name="text">
<string>Remember database key files and security dongles</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QCheckBox" name="checkForUpdatesOnStartupCheckBox"> <widget class="QCheckBox" name="checkForUpdatesOnStartupCheckBox">
<property name="text"> <property name="text">
@ -218,7 +273,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -245,7 +300,7 @@
<item> <item>
<layout class="QHBoxLayout" name="toolButtonStyleLayout"> <layout class="QHBoxLayout" name="toolButtonStyleLayout">
<property name="spacing"> <property name="spacing">
<number>15</number> <number>0</number>
</property> </property>
<item> <item>
<spacer name="toolButtonStyleSpacer"> <spacer name="toolButtonStyleSpacer">
@ -257,7 +312,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -274,8 +329,11 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="styleSheet">
<string notr="true">margin-right: 5px</string>
</property>
<property name="text"> <property name="text">
<string>Button style</string> <string>Button style:</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -326,7 +384,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -377,7 +435,7 @@
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>40</width> <width>20</width>
<height>20</height> <height>20</height>
</size> </size>
</property> </property>
@ -407,7 +465,7 @@
<item> <item>
<layout class="QHBoxLayout" name="languageLabelLayout_2"> <layout class="QHBoxLayout" name="languageLabelLayout_2">
<property name="spacing"> <property name="spacing">
<number>15</number> <number>8</number>
</property> </property>
<item alignment="Qt::AlignRight"> <item alignment="Qt::AlignRight">
<widget class="QLabel" name="languageLabel_2"> <widget class="QLabel" name="languageLabel_2">
@ -418,7 +476,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="text"> <property name="text">
<string>Language</string> <string>Language:</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@ -903,24 +903,27 @@ void MainWindow::saveWindowInformation()
bool MainWindow::saveLastDatabases() bool MainWindow::saveLastDatabases()
{ {
bool accept; if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
m_openDatabases.clear(); auto currentDbWidget = m_ui->tabWidget->currentDatabaseWidget();
bool openPreviousDatabasesOnStartup = config()->get("OpenPreviousDatabasesOnStartup").toBool(); if (currentDbWidget) {
config()->set("LastActiveDatabase", currentDbWidget->database()->filePath());
if (openPreviousDatabasesOnStartup) { } else {
connect( config()->set("LastActiveDatabase", {});
m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&)));
} }
accept = m_ui->tabWidget->closeAllDatabaseTabs(); QStringList openDatabases;
for (int i=0; i < m_ui->tabWidget->count(); ++i) {
if (openPreviousDatabasesOnStartup) { auto dbWidget = m_ui->tabWidget->databaseWidgetFromIndex(i);
disconnect( openDatabases.append(dbWidget->database()->filePath());
m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&)));
config()->set("LastOpenedDatabases", m_openDatabases);
} }
return accept; config()->set("LastOpenedDatabases", openDatabases);
} else {
config()->set("LastActiveDatabase", {});
config()->set("LastOpenedDatabases", {});
}
return m_ui->tabWidget->closeAllDatabaseTabs();
} }
void MainWindow::updateTrayIcon() void MainWindow::updateTrayIcon()
@ -985,11 +988,6 @@ void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard
} }
} }
void MainWindow::rememberOpenDatabases(const QString& filePath)
{
m_openDatabases.prepend(filePath);
}
void MainWindow::applySettingsChanges() void MainWindow::applySettingsChanges()
{ {
int timeout = config()->get("security/lockdatabaseidlesec").toInt() * 1000; int timeout = config()->get("security/lockdatabaseidlesec").toInt() * 1000;

View File

@ -105,7 +105,6 @@ private slots:
void updateCopyAttributesMenu(); void updateCopyAttributesMenu();
void showEntryContextMenu(const QPoint& globalPos); void showEntryContextMenu(const QPoint& globalPos);
void showGroupContextMenu(const QPoint& globalPos); void showGroupContextMenu(const QPoint& globalPos);
void rememberOpenDatabases(const QString& filePath);
void applySettingsChanges(); void applySettingsChanges();
void trayIconTriggered(QSystemTrayIcon::ActivationReason reason); void trayIconTriggered(QSystemTrayIcon::ActivationReason reason);
void lockDatabasesAfterInactivity(); void lockDatabasesAfterInactivity();
@ -137,7 +136,6 @@ private:
QAction* m_searchWidgetAction; QAction* m_searchWidgetAction;
QActionGroup* m_lastDatabasesActions; QActionGroup* m_lastDatabasesActions;
QActionGroup* m_copyAdditionalAttributeActions; QActionGroup* m_copyAdditionalAttributeActions;
QStringList m_openDatabases;
InactivityTimer* m_inactivityTimer; InactivityTimer* m_inactivityTimer;
InactivityTimer* m_touchIDinactivityTimer; InactivityTimer* m_touchIDinactivityTimer;
int m_countDefaultAttributes; int m_countDefaultAttributes;