Skip to content

Commit

Permalink
Switch tab when locking a database and move Lock Database actions in …
Browse files Browse the repository at this point in the history
…Database menu
  • Loading branch information
yamabiiko committed Jul 3, 2021
1 parent 007b595 commit c5c7cd2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
19 changes: 19 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ void DatabaseTabWidget::addDatabaseTab(const QString& filePath,
updateLastDatabases(filePath);
}

/**
* Tries to lock the database at the given index and if
* it succeeds proceed to switch to the first unlocked database tab
*/
void DatabaseTabWidget::lockAndSwitchToFirstUnlockedDatabase(int index)
{
if (index == -1) {
index = currentIndex();
}
if (databaseWidgetFromIndex(index)->lock()) {
for (int i = 0, c = count(); i < c; ++i) {
if (!databaseWidgetFromIndex(i)->isLocked()) {
setCurrentIndex(i);
return;
}
}
}
}

/**
* Add a new database tab containing the given DatabaseWidget
* @param filePath
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class DatabaseTabWidget : public QTabWidget
bool hasLockableDatabases() const;

public slots:
void lockAndSwitchToFirstUnlockedDatabase(int index = -1);
void addDatabaseTab(const QString& filePath,
bool inBackground = false,
const QString& password = {},
Expand Down
23 changes: 20 additions & 3 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ MainWindow::MainWindow()
autoTypeButton->setPopupMode(QToolButton::MenuButtonPopup);
}

auto databaseLockMenu = new QMenu({}, this);
databaseLockMenu->addAction(m_ui->actionLockDatabases);
m_ui->actionLockDatabase->setMenu(databaseLockMenu);
auto databaseLockButton = qobject_cast<QToolButton*>(m_ui->toolBar->widgetForAction(m_ui->actionLockDatabase));
if (databaseLockButton) {
databaseLockButton->setPopupMode(QToolButton::MenuButtonPopup);
}

restoreGeometry(config()->get(Config::GUI_MainWindowGeometry).toByteArray());
restoreState(config()->get(Config::GUI_MainWindowState).toByteArray());

Expand Down Expand Up @@ -262,7 +270,8 @@ MainWindow::MainWindow()
setShortcut(m_ui->actionDatabaseSave, QKeySequence::Save, Qt::CTRL + Qt::Key_S);
setShortcut(m_ui->actionDatabaseSaveAs, QKeySequence::SaveAs, Qt::CTRL + Qt::SHIFT + Qt::Key_S);
setShortcut(m_ui->actionDatabaseClose, QKeySequence::Close, Qt::CTRL + Qt::Key_W);
m_ui->actionLockDatabases->setShortcut(Qt::CTRL + Qt::Key_L);
m_ui->actionMenuLockDatabase->setShortcut(Qt::CTRL + Qt::Key_L);
m_ui->actionLockDatabases->setShortcut(Qt::CTRL + Qt::SHIFT + Qt::Key_L);
setShortcut(m_ui->actionQuit, QKeySequence::Quit, Qt::CTRL + Qt::Key_Q);
setShortcut(m_ui->actionEntryNew, QKeySequence::New, Qt::CTRL + Qt::Key_N);
m_ui->actionEntryEdit->setShortcut(Qt::CTRL + Qt::Key_E);
Expand Down Expand Up @@ -368,8 +377,9 @@ MainWindow::MainWindow()
m_ui->actionReports->setIcon(icons()->icon("reports"));
m_ui->actionDatabaseSettings->setIcon(icons()->icon("document-edit"));
m_ui->actionDatabaseSecurity->setIcon(icons()->icon("database-change-key"));
m_ui->actionLockDatabases->setIcon(icons()->icon("database-lock-all"));
m_ui->actionLockDatabase->setIcon(icons()->icon("database-lock"));
m_ui->actionMenuLockDatabase->setIcon(icons()->icon("database-lock"));
m_ui->actionLockDatabases->setIcon(icons()->icon("database-lock-all"));
m_ui->actionQuit->setIcon(icons()->icon("application-exit"));
m_ui->actionDatabaseMerge->setIcon(icons()->icon("database-merge"));
m_ui->menuImport->setIcon(icons()->icon("document-import"));
Expand Down Expand Up @@ -457,10 +467,15 @@ MainWindow::MainWindow()
connect(m_ui->actionImportOpVault, SIGNAL(triggered()), m_ui->tabWidget, SLOT(importOpVaultDatabase()));
connect(m_ui->actionExportCsv, SIGNAL(triggered()), m_ui->tabWidget, SLOT(exportToCsv()));
connect(m_ui->actionExportHtml, SIGNAL(triggered()), m_ui->tabWidget, SLOT(exportToHtml()));
connect(
m_ui->actionLockDatabase, SIGNAL(triggered()), m_ui->tabWidget, SLOT(lockAndSwitchToFirstUnlockedDatabase()));
connect(m_ui->actionMenuLockDatabase,
SIGNAL(triggered()),
m_ui->tabWidget,
SLOT(lockAndSwitchToFirstUnlockedDatabase()));
connect(m_ui->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget, SLOT(lockDatabases()));
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(appExit()));

m_actionMultiplexer.connect(m_ui->actionLockDatabase, SIGNAL(triggered()), SLOT(lock()));
m_actionMultiplexer.connect(m_ui->actionEntryNew, SIGNAL(triggered()), SLOT(createEntry()));
m_actionMultiplexer.connect(m_ui->actionEntryClone, SIGNAL(triggered()), SLOT(cloneEntry()));
m_actionMultiplexer.connect(m_ui->actionEntryEdit, SIGNAL(triggered()), SLOT(switchToEntryEdit()));
Expand Down Expand Up @@ -854,6 +869,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionDatabaseSaveAs->setEnabled(true);
m_ui->actionDatabaseSaveBackup->setEnabled(true);
m_ui->actionLockDatabase->setEnabled(true);
m_ui->actionMenuLockDatabase->setEnabled(true);
m_ui->menuExport->setEnabled(true);
m_ui->actionExportCsv->setEnabled(true);
m_ui->actionExportHtml->setEnabled(true);
Expand Down Expand Up @@ -911,6 +927,7 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionDatabaseSaveAs->setEnabled(false);
m_ui->actionDatabaseSaveBackup->setEnabled(false);
m_ui->actionLockDatabase->setEnabled(false);
m_ui->actionMenuLockDatabase->setEnabled(false);
m_ui->menuExport->setEnabled(false);
m_ui->actionExportCsv->setEnabled(false);
m_ui->actionExportHtml->setEnabled(false);
Expand Down
18 changes: 13 additions & 5 deletions src/gui/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@
<addaction name="actionDatabaseSaveBackup"/>
<addaction name="actionDatabaseClose"/>
<addaction name="separator"/>
<addaction name="actionMenuLockDatabase"/>
<addaction name="actionLockDatabases"/>
<addaction name="separator"/>
<addaction name="actionReports"/>
<addaction name="actionDatabaseSettings"/>
<addaction name="actionDatabaseSecurity"/>
Expand Down Expand Up @@ -349,7 +352,6 @@
<property name="title">
<string>&amp;Tools</string>
</property>
<addaction name="actionLockDatabases"/>
<addaction name="actionPasswordGenerator"/>
<addaction name="actionSettings"/>
</widget>
Expand Down Expand Up @@ -414,8 +416,6 @@
<addaction name="actionEntryCopyURL"/>
<addaction name="actionEntryAutoType"/>
<addaction name="separator"/>
<addaction name="actionLockDatabases"/>
<addaction name="separator"/>
<addaction name="actionPasswordGenerator"/>
<addaction name="actionSettings"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -759,15 +759,23 @@
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Lock selected database</string>
<string>&amp;Lock Selected Database</string>
</property>
</action>
<action name="actionMenuLockDatabase">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Lock Selected Database</string>
</property>
</action>
<action name="actionLockDatabases">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Lock Databases</string>
<string>&amp;Lock All Databases</string>
</property>
</action>
<action name="actionEntryCopyTitle">
Expand Down

0 comments on commit c5c7cd2

Please sign in to comment.