Skip to content

Commit

Permalink
Add lock selected database action on toolbar
Browse files Browse the repository at this point in the history
Switch tab when locking a database and move Lock Database actions in Database menu
  • Loading branch information
yamabiiko authored and droidmonkey committed Nov 23, 2021
1 parent d3b28f8 commit 078e37c
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 7 deletions.
102 changes: 102 additions & 0 deletions share/icons/application/scalable/actions/database-lock-all.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 54 additions & 1 deletion share/icons/application/scalable/actions/database-lock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions share/icons/icons.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<file>application/scalable/actions/configure.svg</file>
<file>application/scalable/actions/database-change-key.svg</file>
<file>application/scalable/actions/database-lock.svg</file>
<file>application/scalable/actions/database-lock-all.svg</file>
<file>application/scalable/actions/database-merge.svg</file>
<file>application/scalable/actions/dialog-close.svg</file>
<file>application/scalable/actions/dialog-ok.svg</file>
Expand Down
19 changes: 19 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,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 @@ -47,6 +47,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
25 changes: 23 additions & 2 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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 @@ -261,7 +269,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 @@ -369,7 +378,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"));
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 @@ -460,6 +471,12 @@ 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()));

Expand Down Expand Up @@ -864,6 +881,8 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionDatabaseSave->setEnabled(m_ui->tabWidget->canSave());
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 @@ -920,6 +939,8 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionDatabaseSave->setEnabled(false);
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
25 changes: 21 additions & 4 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 @@ -355,7 +358,6 @@
<property name="title">
<string>&amp;Tools</string>
</property>
<addaction name="actionLockDatabases"/>
<addaction name="actionPasswordGenerator"/>
<addaction name="actionSettings"/>
</widget>
Expand Down Expand Up @@ -409,6 +411,7 @@
</attribute>
<addaction name="actionDatabaseOpen"/>
<addaction name="actionDatabaseSave"/>
<addaction name="actionLockDatabase"/>
<addaction name="separator"/>
<addaction name="actionEntryNew"/>
<addaction name="actionEntryEdit"/>
Expand All @@ -419,8 +422,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 @@ -773,12 +774,28 @@
<string>Open &amp;URL</string>
</property>
</action>
<action name="actionLockDatabase">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<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 078e37c

Please sign in to comment.