Skip to content

Commit

Permalink
Fix annoyances with access control dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
varjolintu committed Apr 24, 2020
1 parent 7f98323 commit 871bc6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/browser/BrowserService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ BrowserService::BrowserService(DatabaseTabWidget* parent)
, m_bringToFrontRequested(false)
, m_prevWindowState(WindowState::Normal)
, m_keepassBrowserUUID(Tools::hexToUuid("de887cc3036343b8974b5911b8816224"))
, m_previousMode(DatabaseWidget::Mode::LockedMode)
{
// Don't connect the signals when used from DatabaseSettingsWidgetBrowser (parent is nullptr)
if (m_dbTabWidget) {
Expand Down Expand Up @@ -803,10 +804,16 @@ QList<Entry*> BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm,
return {};
}

bool bDatabaseChanged = false;
m_dialogActive = true;
BrowserAccessControlDialog accessControlDialog;

connect(m_dbTabWidget, SIGNAL(databaseLocked(DatabaseWidget*)), &accessControlDialog, SLOT(reject()));
connect(m_dbTabWidget, &DatabaseTabWidget::activateDatabaseChanged, [&bDatabaseChanged]() {
bDatabaseChanged = true;
});
connect(m_dbTabWidget, SIGNAL(activateDatabaseChanged(DatabaseWidget*)), &accessControlDialog, SLOT(reject()));

connect(&accessControlDialog, &BrowserAccessControlDialog::disableAccess, [&](QTableWidgetItem* item) {
auto entry = pwEntriesToConfirm[item->row()];
BrowserEntryConfig config;
Expand Down Expand Up @@ -850,7 +857,12 @@ QList<Entry*> BrowserService::confirmEntries(QList<Entry*>& pwEntriesToConfirm,
}

m_dialogActive = false;
hideWindow();

// Only hide the window if database hasn't been changed when the dialog is visible
if (!bDatabaseChanged) {
hideWindow();
}

return allowedEntries;
}

Expand Down Expand Up @@ -1301,9 +1313,14 @@ void BrowserService::activateDatabaseChanged(DatabaseWidget* dbWidget)
if (dbWidget) {
auto currentMode = dbWidget->currentMode();
if (currentMode == DatabaseWidget::Mode::ViewMode || currentMode == DatabaseWidget::Mode::EditMode) {
emit databaseUnlocked();
// Only emit the signal when switching from locked database to an open one
if (!browserSettings()->searchInAllDatabases() || m_previousMode == DatabaseWidget::Mode::LockedMode) {
emit databaseUnlocked();
}
} else {
emit databaseLocked();
}

m_previousMode = currentMode;
}
}
2 changes: 2 additions & 0 deletions src/browser/BrowserService.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define BROWSERSERVICE_H

#include "core/Entry.h"
#include "gui/DatabaseWidget.h"
#include "gui/DatabaseTabWidget.h"
#include <QObject>
#include <QtCore>
Expand Down Expand Up @@ -148,6 +149,7 @@ public slots:
bool m_bringToFrontRequested;
WindowState m_prevWindowState;
QUuid m_keepassBrowserUUID;
DatabaseWidget::Mode m_previousMode;

friend class TestBrowser;
};
Expand Down

0 comments on commit 871bc6c

Please sign in to comment.