Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Startup Issues #2830

Merged
merged 2 commits into from Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/core/Bootstrap.cpp
Expand Up @@ -112,6 +112,10 @@ namespace Bootstrap
mainWindow.openDatabase(filename);
}
}
auto lastActiveFile = config()->get("LastActiveDatabase").toString();
if (!lastActiveFile.isEmpty()) {
mainWindow.openDatabase(lastActiveFile);
}
}
}

Expand Down
22 changes: 18 additions & 4 deletions src/gui/ApplicationSettingsWidget.cpp
Expand Up @@ -81,7 +81,8 @@ ApplicationSettingsWidget::ApplicationSettingsWidget(QWidget* parent)
// clang-format off
connect(m_generalUi->autoSaveAfterEveryChangeCheckBox, SIGNAL(toggled(bool)), SLOT(autoSaveToggled(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)),
m_secUi->clearClipboardSpinBox, SLOT(setEnabled(bool)));
Expand Down Expand Up @@ -294,11 +295,13 @@ void ApplicationSettingsWidget::saveSettings()

// Security: clear storage if related settings are disabled
if (!config()->get("RememberLastDatabases").toBool()) {
config()->set("LastDatabases", QVariant());
config()->set("LastDatabases", {});
config()->set("OpenPreviousDatabasesOnStartup", {});
config()->set("LastActiveDatabase", {});
}

if (!config()->get("RememberLastKeyFiles").toBool()) {
config()->set("LastKeyFiles", QVariant());
config()->set("LastKeyFiles", {});
config()->set("LastDir", "");
}

Expand Down Expand Up @@ -330,9 +333,20 @@ void ApplicationSettingsWidget::systrayToggled(bool checked)
m_generalUi->systrayMinimizeToTrayCheckBox->setEnabled(checked);
}

void ApplicationSettingsWidget::enableToolbarSettings(bool checked)
void ApplicationSettingsWidget::toolbarSettingsToggled(bool checked)
{
m_generalUi->toolbarMovableCheckBox->setEnabled(!checked);
m_generalUi->toolButtonStyleComboBox->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);
}
3 changes: 2 additions & 1 deletion src/gui/ApplicationSettingsWidget.h
Expand Up @@ -55,7 +55,8 @@ private slots:
void reject();
void autoSaveToggled(bool checked);
void systrayToggled(bool checked);
void enableToolbarSettings(bool checked);
void toolbarSettingsToggled(bool checked);
void rememberDatabasesToggled(bool checked);

private:
QWidget* const m_secWidget;
Expand Down
104 changes: 81 additions & 23 deletions src/gui/ApplicationSettingsWidgetGeneral.ui
Expand Up @@ -50,38 +50,93 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
<property name="text">
<string>Remember last databases</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Minimize window at application startup</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="rememberLastKeyFilesCheckBox">
<widget class="QCheckBox" name="rememberLastDatabasesCheckBox">
<property name="text">
<string>Remember last key files and security dongles</string>
<string>Remember previously used databases</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>
<layout class="QHBoxLayout" name="rememberDbSubLayout_2">
<property name="spacing">
<number>0</number>
</property>
</widget>
<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>
<widget class="QCheckBox" name="systrayMinimizeOnStartup">
<property name="text">
<string>Minimize window at application startup</string>
<layout class="QHBoxLayout" name="rememberDbSubLayout">
<property name="spacing">
<number>0</number>
</property>
</widget>
<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>
<widget class="QCheckBox" name="checkForUpdatesOnStartupCheckBox">
Expand Down Expand Up @@ -218,7 +273,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
Expand All @@ -245,7 +300,7 @@
<item>
<layout class="QHBoxLayout" name="toolButtonStyleLayout">
<property name="spacing">
<number>15</number>
<number>0</number>
</property>
<item>
<spacer name="toolButtonStyleSpacer">
Expand All @@ -257,7 +312,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
Expand All @@ -274,8 +329,11 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true">margin-right: 5px</string>
</property>
<property name="text">
<string>Button style</string>
<string>Button style:</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -326,7 +384,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
Expand Down Expand Up @@ -377,7 +435,7 @@
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<width>20</width>
<height>20</height>
</size>
</property>
Expand Down Expand Up @@ -407,7 +465,7 @@
<item>
<layout class="QHBoxLayout" name="languageLabelLayout_2">
<property name="spacing">
<number>15</number>
<number>8</number>
</property>
<item alignment="Qt::AlignRight">
<widget class="QLabel" name="languageLabel_2">
Expand All @@ -418,7 +476,7 @@
</sizepolicy>
</property>
<property name="text">
<string>Language</string>
<string>Language:</string>
</property>
</widget>
</item>
Expand Down
13 changes: 9 additions & 4 deletions src/gui/DatabaseTabWidget.cpp
Expand Up @@ -137,10 +137,15 @@ void DatabaseTabWidget::openDatabase()
* database has been opened already.
*
* @param filePath database file path
* @param password optional, password to unlock database
* @param inBackground optional, don't focus tab after opening
* @param password optional, password to unlock database
* @param keyfile optional, path to keyfile to unlock database
*
*/
void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackground, const QString& password)
void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
bool inBackground,
const QString& password,
const QString& keyfile)
{
QFileInfo fileInfo(filePath);
QString canonicalFilePath = fileInfo.canonicalFilePath();
Expand All @@ -154,7 +159,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun
Q_ASSERT(dbWidget);
if (dbWidget && dbWidget->database()->filePath() == canonicalFilePath) {
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password);
dbWidget->performUnlockDatabase(password, keyfile);
}
if (!inBackground) {
// switch to existing tab if file is already open
Expand All @@ -167,7 +172,7 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath, bool inBackgroun
auto* dbWidget = new DatabaseWidget(QSharedPointer<Database>::create(filePath), this);
addDatabaseTab(dbWidget, inBackground);
if (!password.isEmpty()) {
dbWidget->performUnlockDatabase(password);
dbWidget->performUnlockDatabase(password, keyfile);
}
updateLastDatabases(filePath);
}
Expand Down
5 changes: 4 additions & 1 deletion src/gui/DatabaseTabWidget.h
Expand Up @@ -48,7 +48,10 @@ class DatabaseTabWidget : public QTabWidget
bool hasLockableDatabases() const;

public slots:
void addDatabaseTab(const QString& filePath, bool inBackground = false, const QString& password = {});
void addDatabaseTab(const QString& filePath,
bool inBackground = false,
const QString& password = {},
const QString& keyfile = {});
void addDatabaseTab(DatabaseWidget* dbWidget, bool inBackground = false);
bool closeDatabaseTab(int index);
bool closeDatabaseTab(DatabaseWidget* dbWidget);
Expand Down
59 changes: 19 additions & 40 deletions src/gui/MainWindow.cpp
Expand Up @@ -494,28 +494,9 @@ void MainWindow::clearLastDatabases()
}
}

void MainWindow::openDatabase(const QString& filePath, const QString& pw, const QString& keyFile)
void MainWindow::openDatabase(const QString& filePath, const QString& password, const QString& keyfile)
{
if (pw.isEmpty() && keyFile.isEmpty()) {
m_ui->tabWidget->addDatabaseTab(filePath);
return;
}

auto db = QSharedPointer<Database>::create();
auto key = QSharedPointer<CompositeKey>::create();
if (!pw.isEmpty()) {
key->addKey(QSharedPointer<PasswordKey>::create(pw));
}
if (!keyFile.isEmpty()) {
auto fileKey = QSharedPointer<FileKey>::create();
fileKey->load(keyFile);
key->addKey(fileKey);
}
if (db->open(filePath, key, nullptr, false)) {
auto* dbWidget = new DatabaseWidget(db, this);
m_ui->tabWidget->addDatabaseTab(dbWidget);
dbWidget->switchToMainView(true);
}
m_ui->tabWidget->addDatabaseTab(filePath, false, password, keyfile);
}

void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
Expand Down Expand Up @@ -920,24 +901,27 @@ void MainWindow::saveWindowInformation()

bool MainWindow::saveLastDatabases()
{
bool accept;
m_openDatabases.clear();
bool openPreviousDatabasesOnStartup = config()->get("OpenPreviousDatabasesOnStartup").toBool();

if (openPreviousDatabasesOnStartup) {
connect(
m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&)));
}
if (config()->get("OpenPreviousDatabasesOnStartup").toBool()) {
auto currentDbWidget = m_ui->tabWidget->currentDatabaseWidget();
if (currentDbWidget) {
config()->set("LastActiveDatabase", currentDbWidget->database()->filePath());
} else {
config()->set("LastActiveDatabase", {});
}

accept = m_ui->tabWidget->closeAllDatabaseTabs();
QStringList openDatabases;
for (int i=0; i < m_ui->tabWidget->count(); ++i) {
auto dbWidget = m_ui->tabWidget->databaseWidgetFromIndex(i);
openDatabases.append(dbWidget->database()->filePath());
}

if (openPreviousDatabasesOnStartup) {
disconnect(
m_ui->tabWidget, SIGNAL(databaseClosed(const QString&)), this, SLOT(rememberOpenDatabases(const QString&)));
config()->set("LastOpenedDatabases", m_openDatabases);
config()->set("LastOpenedDatabases", openDatabases);
} else {
config()->set("LastActiveDatabase", {});
config()->set("LastOpenedDatabases", {});
}

return accept;
return m_ui->tabWidget->closeAllDatabaseTabs();
}

void MainWindow::updateTrayIcon()
Expand Down Expand Up @@ -1002,11 +986,6 @@ void MainWindow::setShortcut(QAction* action, QKeySequence::StandardKey standard
}
}

void MainWindow::rememberOpenDatabases(const QString& filePath)
{
m_openDatabases.prepend(filePath);
}

void MainWindow::applySettingsChanges()
{
int timeout = config()->get("security/lockdatabaseidlesec").toInt() * 1000;
Expand Down