Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/fdosecrets/objects/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,15 @@ namespace FdoSecrets
m_unlockingAnyDatabase = false;
m_unlockingDb.remove(dbWidget);
} else {
// The database may have been unlocked externally while the unlock dialog
// was open, in which case no future databaseUnlocked signal will arrive.
if (dbWidget && !dbWidget->isLocked()) {
emit doneUnlockDatabaseInDialog(true, dbWidget);
m_unlockingAnyDatabase = false;
m_unlockingDb.remove(dbWidget);
return;
}

// delay the done signal to when the database is actually done with unlocking
// this is a oneshot connection to prevent superfluous signals
auto conn = connect(dbWidget, &DatabaseWidget::databaseUnlocked, this, [dbWidget, this]() {
Expand Down
20 changes: 20 additions & 0 deletions src/gui/DatabaseOpenDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ QSharedPointer<Database> DatabaseOpenDialog::database() const
return m_db;
}

void DatabaseOpenDialog::completeExternalUnlock(DatabaseWidget* dbWidget)
{
if (!dbWidget) {
return;
}

hide();

// The database is already unlocked, so do not route this completion back through
// DatabaseWidget::unlockDatabase() and replace the database a second time.
if (m_currentDbWidget) {
disconnect(this, &DatabaseOpenDialog::dialogFinished, m_currentDbWidget, nullptr);
}

emit dialogFinished(true, dbWidget);
clearForms();

QDialog::done(QDialog::Accepted);
}

void DatabaseOpenDialog::done(int result)
{
hide();
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseOpenDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class DatabaseOpenDialog : public QDialog
Intent intent() const;
QSharedPointer<Database> database() const;
void clearForms();
void completeExternalUnlock(DatabaseWidget* dbWidget);
void showMessage(const QString& text, MessageWidget::MessageType type, int autoHideTimeout);

signals:
Expand Down
20 changes: 19 additions & 1 deletion src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,12 @@ void DatabaseTabWidget::unlockDatabaseInDialog(DatabaseWidget* dbWidget,
const QString& filePath)
{
m_databaseOpenDialog->clearForms();

// Keep the requested targets outside the dialog because the dialog can be
// cleared while an external unlock is still in progress.
m_databaseOpenDialogTargets.clear();
m_databaseOpenDialogTargets.append(dbWidget);

m_databaseOpenDialog->setIntent(intent);
m_databaseOpenDialog->setTarget(dbWidget, filePath);
displayUnlockDialog();
Expand All @@ -774,13 +780,15 @@ void DatabaseTabWidget::unlockDatabaseInDialog(DatabaseWidget* dbWidget,
void DatabaseTabWidget::unlockAnyDatabaseInDialog(DatabaseOpenDialog::Intent intent)
{
m_databaseOpenDialog->clearForms();
m_databaseOpenDialogTargets.clear();
m_databaseOpenDialog->setIntent(intent);

// add a tab to the dialog for each open unlocked database
// add a tab to the dialog for each open locked database
for (int i = 0, c = count(); i < c; ++i) {
auto* dbWidget = databaseWidgetFromIndex(i);
if (dbWidget && dbWidget->isLocked()) {
m_databaseOpenDialog->addDatabaseTab(dbWidget);
m_databaseOpenDialogTargets.append(dbWidget);
}
}
// default to the current tab
Expand Down Expand Up @@ -836,6 +844,7 @@ void DatabaseTabWidget::handleDatabaseUnlockDialogFinished(bool accepted, Databa

// signal other objects that the dialog finished
emit databaseUnlockDialogFinished(accepted, dbWidget);
m_databaseOpenDialogTargets.clear();
}

/**
Expand Down Expand Up @@ -904,9 +913,18 @@ void DatabaseTabWidget::emitDatabaseLockChanged()
} else {
emit databaseUnlocked(dbWidget);
m_databaseOpenInProgress = false;

if (m_databaseOpenDialog->isVisible() && isDatabaseOpenDialogTarget(dbWidget)) {
m_databaseOpenDialog->completeExternalUnlock(dbWidget);
}
}
}

bool DatabaseTabWidget::isDatabaseOpenDialogTarget(DatabaseWidget* dbWidget) const
{
return dbWidget && m_databaseOpenDialogTargets.contains(dbWidget);
}

void DatabaseTabWidget::performGlobalAutoType(const QString& search)
{
auto currentDbWidget = currentDatabaseWidget();
Expand Down
2 changes: 2 additions & 0 deletions src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,12 @@ private slots:
void updateLastDatabases(const QSharedPointer<Database>& database);
bool warnOnExport();
void displayUnlockDialog();
bool isDatabaseOpenDialogTarget(DatabaseWidget* dbWidget) const;

QPointer<DatabaseWidgetStateSync> m_dbWidgetStateSync;
QPointer<DatabaseWidget> m_dbWidgetPendingLock;
QPointer<DatabaseOpenDialog> m_databaseOpenDialog;
QList<QPointer<DatabaseWidget>> m_databaseOpenDialogTargets;
QPointer<ImportWizard> m_importWizard;
QTimer m_lockDelayTimer;
bool m_databaseOpenInProgress;
Expand Down