Option to automatically reopen databases which were last opened.

This commit is contained in:
Francois Ferrand 2013-04-22 21:33:42 +02:00
parent 7ff475977e
commit 850c7c7ecf
6 changed files with 47 additions and 21 deletions

View File

@ -88,6 +88,7 @@ void Config::init(const QString& fileName)
m_settings.reset(new QSettings(fileName, QSettings::IniFormat));
m_defaults.insert("RememberLastDatabases", true);
m_defaults.insert("AutoReopenLastDatabases", true);
m_defaults.insert("ModifiedOnExpandedStateChanges", true);
m_defaults.insert("AutoSaveAfterEveryChange", false);
m_defaults.insert("AutoSaveOnExit", false);

View File

@ -66,16 +66,7 @@ DatabaseTabWidget::~DatabaseTabWidget()
void DatabaseTabWidget::toggleTabbar()
{
if (count() > 1) {
if (!tabBar()->isVisible()) {
tabBar()->show();
}
}
else {
if (tabBar()->isVisible()) {
tabBar()->hide();
}
}
tabBar()->setVisible(count() > 1);
}
void DatabaseTabWidget::newDatabase()
@ -148,7 +139,7 @@ void DatabaseTabWidget::openDatabase(const QString& fileName, const QString& pw,
insertDatabase(db, dbStruct);
updateLastDatabases(dbStruct.filePath);
updateRecentDatabases(dbStruct.filePath);
if (!pw.isNull() || !keyFile.isEmpty()) {
dbStruct.dbWidget->switchToOpenDatabase(dbStruct.filePath, pw, keyFile);
@ -235,8 +226,25 @@ void DatabaseTabWidget::deleteDatabase(Database* db)
delete db;
}
void DatabaseTabWidget::reopenLastDatabases()
{
if (config()->get("AutoReopenLastDatabases", false).toBool()) {
int index = count();
Q_FOREACH (const QString & database, config()->get("LastOpenDatabases", QVariant()).toStringList())
openDatabase(database);
setCurrentIndex(index);
}
}
bool DatabaseTabWidget::closeAllDatabases()
{
QStringList reloadDatabases;
if (config()->get("AutoReopenLastDatabases", false).toBool()) {
for (int i = 0; i < count(); i ++)
reloadDatabases << indexDatabaseManagerStruct(i).filePath;
}
config()->set("LastOpenDatabases", reloadDatabases);
while (!m_dbList.isEmpty()) {
if (!closeDatabase()) {
return false;
@ -299,7 +307,7 @@ void DatabaseTabWidget::saveDatabaseAs(Database* db)
dbStruct.fileName = fileInfo.fileName();
dbStruct.dbWidget->updateFilename(dbStruct.filePath);
updateTabName(db);
updateLastDatabases(dbStruct.filePath);
updateRecentDatabases(dbStruct.filePath);
}
else {
QMessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
@ -545,7 +553,7 @@ void DatabaseTabWidget::modified()
}
}
void DatabaseTabWidget::updateLastDatabases(const QString& filename)
void DatabaseTabWidget::updateRecentDatabases(const QString& filename)
{
if (!config()->get("RememberLastDatabases").toBool()) {
config()->set("LastDatabases", QVariant());

View File

@ -65,6 +65,7 @@ public Q_SLOTS:
void saveDatabaseAs(int index = -1);
bool closeDatabase(int index = -1);
void closeDatabaseFromSender();
void reopenLastDatabases();
bool closeAllDatabases();
void changeMasterKey();
void changeDatabaseSettings();
@ -93,7 +94,7 @@ private:
DatabaseManagerStruct indexDatabaseManagerStruct(int index);
Database* databaseFromDatabaseWidget(DatabaseWidget* dbWidget);
void insertDatabase(Database* db, const DatabaseManagerStruct& dbStruct);
void updateLastDatabases(const QString& filename);
void updateRecentDatabases(const QString& filename);
void connectDatabase(Database* newDb, Database* oldDb = Q_NULLPTR);
KeePass2Writer m_writer;

View File

@ -227,6 +227,8 @@ MainWindow::MainWindow()
m_actionMultiplexer.connect(m_ui->actionSearch, SIGNAL(triggered()),
SLOT(toggleSearch()));
m_ui->tabWidget->reopenLastDatabases();
}
MainWindow::~MainWindow()

View File

@ -63,8 +63,12 @@ SettingsWidget::SettingsWidget(QWidget* parent)
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)),
this, SLOT(enableAutoSaveOnExit(bool)));
connect(m_generalUi->rememberLastDatabasesCheckBox, SIGNAL(toggled(bool)),
m_generalUi->autoReopenLastDatabases, SLOT(setEnabled(bool)));
connect(m_secUi->clearClipboardCheckBox, SIGNAL(toggled(bool)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
}
SettingsWidget::~SettingsWidget()
@ -82,6 +86,7 @@ void SettingsWidget::addSettingsPage(ISettingsPage *page)
void SettingsWidget::loadSettings()
{
m_generalUi->rememberLastDatabasesCheckBox->setChecked(config()->get("RememberLastDatabases").toBool());
m_generalUi->autoReopenLastDatabases->setChecked(config()->get("AutoReopenLastDatabases").toBool());
m_generalUi->modifiedExpandedChangedCheckBox->setChecked(config()->get("ModifiedOnExpandedStateChanges").toBool());
m_generalUi->autoSaveAfterEveryChangeCheckBox->setChecked(config()->get("AutoSaveAfterEveryChange").toBool());
m_generalUi->autoSaveOnExitCheckBox->setChecked(config()->get("AutoSaveOnExit").toBool());
@ -104,6 +109,8 @@ void SettingsWidget::loadSettings()
void SettingsWidget::saveSettings()
{
config()->set("RememberLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked());
config()->set("AutoReopenLastDatabases", m_generalUi->rememberLastDatabasesCheckBox->isChecked()
&& m_generalUi->autoReopenLastDatabases->isChecked());
config()->set("ModifiedOnExpandedStateChanges", m_generalUi->modifiedExpandedChangedCheckBox->isChecked());
config()->set("AutoSaveAfterEveryChange", m_generalUi->autoSaveAfterEveryChangeCheckBox->isChecked());
config()->set("AutoSaveOnExit", m_generalUi->autoSaveOnExitCheckBox->isChecked());

View File

@ -7,21 +7,21 @@
<x>0</x>
<y>0</y>
<width>456</width>
<height>146</height>
<height>172</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
<property name="text">
<string>Remember last databases</string>
<string>Remember recent databases</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QCheckBox" name="modifiedExpandedChangedCheckBox">
<property name="text">
<string>Mark as modified on expanded state changes</string>
@ -31,30 +31,37 @@
</property>
</widget>
</item>
<item row="3" column="0">
<item row="4" column="0">
<widget class="QCheckBox" name="autoSaveAfterEveryChangeCheckBox">
<property name="text">
<string>Automatically save after every change</string>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QCheckBox" name="autoSaveOnExitCheckBox">
<property name="text">
<string>Automatically save on exit</string>
</property>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Global Auto-Type shortcut</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item row="5" column="1">
<widget class="ShortcutWidget" name="autoTypeShortcutWidget"/>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="autoReopenLastDatabases">
<property name="text">
<string>Automatically reopen last databases</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>