Add lock selected database action on toolbar

Closes #6445

Switch tab when locking a database and move Lock Database actions to the Database section of the toolbar.
This commit is contained in:
Lorenzo Tucci 2021-07-02 11:33:12 +02:00 committed by Jonathan White
parent 456726556d
commit c88d8c870f
10 changed files with 90 additions and 17 deletions

View File

@ -146,6 +146,8 @@ License: MIT
Files: share/icons/application/scalable/actions/chevron-double-down.svg
share/icons/application/scalable/actions/chevron-double-right.svg
share/icons/application/scalable/actions/database-lock.svg
share/icons/application/scalable/actions/database-lock-all.svg
share/icons/application/scalable/actions/document-close.svg
share/icons/application/scalable/actions/document-edit.svg
share/icons/application/scalable/actions/document-export.svg

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path style="stroke-width:.65502" d="M7.275.645a2.949 2.949 0 0 0-1.404.298c-1.34.571-2.058 2.064-1.918 3.475-.085.269.215.925-.248.816-.77-.119-1.655.327-1.71 1.176-.016 2.092-.004 4.183-.009 6.276-.119.769.329 1.654 1.176 1.712 1.855.012 3.711.006 5.567.004v-1.308H3.297v-6.55h7.861v4.106h1.301c0-1.252.002-2.504.008-3.755.137-.804-.444-1.689-1.309-1.66h-.656c-.021-.693.062-1.395-.09-2.077C10.112 1.7 8.71.688 7.275.645zm-.048 1.314c.465-.001.929.17 1.28.475.869.681.665 1.836.686 2.8H5.32c-.139-.22-.017-.701-.058-1.02-.153-1.14.789-2.292 1.965-2.255zm.097 6.559c-.37-.04-.752.069-1.025.373-.834.75-.195 2.3.928 2.238.736.016 1.37-.659 1.308-1.393-.008-.676-.594-1.153-1.21-1.218z" transform="translate(-.218 .136) scale(1.04251)"/><path style="fill:#000;fill-opacity:1;fill-rule:evenodd;stroke-width:.857645" d="M11.773 18.34c-1.322.064-2.213-1.618-1.424-2.677.676-1.116 2.527-.937 2.994.27.513 1.094-.357 2.434-1.57 2.406zm5.146 2.572v-8.576H6.627v8.576h10.292zm0-10.292c1.038-.032 1.855.99 1.715 1.993-.01 2.84.019 5.68-.014 8.519-.096.979-1.095 1.626-2.034 1.495-3.378-.006-6.757.012-10.135-.009-1.032-.072-1.677-1.125-1.54-2.094.007-2.788-.01-5.577.01-8.365.068-1.003 1.084-1.67 2.038-1.539.432.09.635-.048.526-.498-.025-1.262-.04-2.616.77-3.67 1.263-1.913 4.126-2.424 5.971-1.064 1.326.884 1.959 2.516 1.835 4.071v1.161h.858zm-5.146-4.288c-1.49-.044-2.739 1.385-2.573 2.85v1.438h5.146c-.053-1.126.231-2.4-.575-3.336a2.578 2.578 0 0 0-1.998-.952z" transform="matrix(.99434 0 0 .99434 3.623 .679)"/></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1 +1 @@
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="mdi-lock-outline" width="24" height="24" viewBox="0 0 24 24"><path d="M12,17C10.89,17 10,16.1 10,15C10,13.89 10.89,13 12,13A2,2 0 0,1 14,15A2,2 0 0,1 12,17M18,20V10H6V20H18M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V10C4,8.89 4.89,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z" /></svg>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M12 17a2 2 0 0 1-2-2c0-1.11.89-2 2-2a2 2 0 0 1 2 2 2 2 0 0 1-2 2m6 3V10H6v10h12m0-12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V10c0-1.11.89-2 2-2h1V6a5 5 0 0 1 5-5 5 5 0 0 1 5 5v2h1m-6-5a3 3 0 0 0-3 3v2h6V6a3 3 0 0 0-3-3z"/></svg>

Before

Width:  |  Height:  |  Size: 583 B

After

Width:  |  Height:  |  Size: 307 B

View File

@ -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>

View File

@ -5142,10 +5142,6 @@ Are you sure you want to continue with this file?</source>
<source>Download &amp;Favicon</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Lock Databases</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;CSV File</source>
<translation type="unfinished"></translation>
@ -5298,6 +5294,14 @@ We recommend you use the AppImage available on our downloads page.</source>
<source>Restore Entry(s)</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>&amp;Lock Database</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Lock &amp;All Databases</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>ManageDatabase</name>

View File

@ -179,6 +179,33 @@ 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();
}
auto dbWidget = databaseWidgetFromIndex(index);
if (!dbWidget) {
return;
}
if (dbWidget->isLocked()) {
// Database is already locked, act like lock all databases instead
lockDatabases();
} else if (dbWidget->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

View File

@ -47,6 +47,7 @@ public:
bool hasLockableDatabases() const;
public slots:
void lockAndSwitchToFirstUnlockedDatabase(int index = -1);
void addDatabaseTab(const QString& filePath,
bool inBackground = false,
const QString& password = {},

View File

@ -168,6 +168,15 @@ MainWindow::MainWindow()
autoTypeButton->setPopupMode(QToolButton::MenuButtonPopup);
}
auto databaseLockMenu = new QMenu({}, this);
databaseLockMenu->addAction(m_ui->actionLockAllDatabases);
m_ui->actionLockDatabaseToolbar->setMenu(databaseLockMenu);
auto databaseLockButton =
qobject_cast<QToolButton*>(m_ui->toolBar->widgetForAction(m_ui->actionLockDatabaseToolbar));
if (databaseLockButton) {
databaseLockButton->setPopupMode(QToolButton::MenuButtonPopup);
}
restoreGeometry(config()->get(Config::GUI_MainWindowGeometry).toByteArray());
restoreState(config()->get(Config::GUI_MainWindowState).toByteArray());
@ -261,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->actionLockDatabase->setShortcut(Qt::CTRL + Qt::Key_L);
m_ui->actionLockAllDatabases->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);
@ -369,7 +379,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->actionLockDatabaseToolbar->setIcon(icons()->icon("database-lock"));
m_ui->actionLockAllDatabases->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"));
@ -460,7 +472,10 @@ 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->actionLockDatabases, SIGNAL(triggered()), m_ui->tabWidget, SLOT(lockDatabases()));
connect(
m_ui->actionLockDatabase, SIGNAL(triggered()), m_ui->tabWidget, SLOT(lockAndSwitchToFirstUnlockedDatabase()));
connect(m_ui->actionLockDatabaseToolbar, SIGNAL(triggered()), m_ui->actionLockDatabase, SIGNAL(triggered()));
connect(m_ui->actionLockAllDatabases, SIGNAL(triggered()), m_ui->tabWidget, SLOT(lockDatabases()));
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(appExit()));
m_actionMultiplexer.connect(m_ui->actionEntryNew, SIGNAL(triggered()), SLOT(createEntry()));
@ -781,7 +796,9 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionDatabaseOpen->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
m_ui->menuRecentDatabases->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
m_ui->menuImport->setEnabled(inDatabaseTabWidgetOrWelcomeWidget);
m_ui->actionLockDatabases->setEnabled(m_ui->tabWidget->hasLockableDatabases());
m_ui->actionLockDatabase->setEnabled(m_ui->tabWidget->hasLockableDatabases());
m_ui->actionLockDatabaseToolbar->setEnabled(m_ui->tabWidget->hasLockableDatabases());
m_ui->actionLockAllDatabases->setEnabled(m_ui->tabWidget->hasLockableDatabases());
if (inDatabaseTabWidget && m_ui->tabWidget->currentIndex() != -1) {
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
@ -924,6 +941,9 @@ void MainWindow::setMenuActionState(DatabaseWidget::Mode mode)
m_ui->actionExportCsv->setEnabled(false);
m_ui->actionExportHtml->setEnabled(false);
m_ui->actionDatabaseMerge->setEnabled(false);
// Only disable the action in the database menu so that the
// menu remains active in the toolbar, if necessary
m_ui->actionLockDatabase->setEnabled(false);
m_searchWidgetAction->setEnabled(false);
break;
@ -1392,7 +1412,7 @@ void MainWindow::updateTrayIcon()
menu->addAction(actionToggle);
actionToggle->setIcon(icons()->icon("keepassxc-monochrome-dark"));
menu->addAction(m_ui->actionLockDatabases);
menu->addAction(m_ui->actionLockAllDatabases);
#ifdef Q_OS_MACOS
auto actionQuit = new QAction(tr("Quit KeePassXC"), menu);

View File

@ -216,7 +216,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>21</height>
<height>22</height>
</rect>
</property>
<property name="contextMenuPolicy">
@ -254,6 +254,9 @@
<addaction name="actionDatabaseSaveBackup"/>
<addaction name="actionDatabaseClose"/>
<addaction name="separator"/>
<addaction name="actionLockDatabase"/>
<addaction name="actionLockAllDatabases"/>
<addaction name="separator"/>
<addaction name="actionReports"/>
<addaction name="actionDatabaseSettings"/>
<addaction name="actionDatabaseSecurity"/>
@ -355,7 +358,6 @@
<property name="title">
<string>&amp;Tools</string>
</property>
<addaction name="actionLockDatabases"/>
<addaction name="actionPasswordGenerator"/>
<addaction name="actionSettings"/>
</widget>
@ -409,6 +411,7 @@
</attribute>
<addaction name="actionDatabaseOpen"/>
<addaction name="actionDatabaseSave"/>
<addaction name="actionLockDatabaseToolbar"/>
<addaction name="separator"/>
<addaction name="actionEntryNew"/>
<addaction name="actionEntryEdit"/>
@ -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"/>
@ -773,12 +774,20 @@
<string>Open &amp;URL</string>
</property>
</action>
<action name="actionLockDatabases">
<action name="actionLockDatabase">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Lock Databases</string>
<string>&amp;Lock Database</string>
</property>
</action>
<action name="actionLockAllDatabases">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Lock &amp;All Databases</string>
</property>
</action>
<action name="actionEntryCopyTitle">
@ -1084,6 +1093,14 @@
<string notr="true">Ctrl+R</string>
</property>
</action>
<action name="actionLockDatabaseToolbar">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>&amp;Lock Database</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

@ -1384,7 +1384,7 @@ void TestGui::testDatabaseLocking()
QString origDbName = m_tabWidget->tabText(0);
MessageBox::setNextAnswer(MessageBox::Cancel);
triggerAction("actionLockDatabases");
triggerAction("actionLockAllDatabases");
QCOMPARE(m_tabWidget->tabText(0), origDbName + " [Locked]");