Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FdoSecrets: only emit completed signal when the action actually finishes #4074

Merged
merged 1 commit into from
Jan 2, 2020
Merged
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
8 changes: 8 additions & 0 deletions src/fdosecrets/objects/Collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ namespace FdoSecrets
connect(backend, &DatabaseWidget::databaseUnlocked, this, &Collection::onDatabaseLockChanged);
connect(backend, &DatabaseWidget::databaseLocked, this, &Collection::onDatabaseLockChanged);

// get notified whenever unlock db dialog finishes
connect(parent, &Service::doneUnlockDatabaseInDialog, this, [this](bool accepted, DatabaseWidget* dbWidget) {
if (!dbWidget || dbWidget != m_backend) {
return;
}
emit doneUnlockCollection(accepted);
});

reloadBackend();
}

Expand Down
2 changes: 2 additions & 0 deletions src/fdosecrets/objects/Collection.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace FdoSecrets
void aliasAdded(const QString& alias);
void aliasRemoved(const QString& alias);

void doneUnlockCollection(bool accepted);

public:
DBusReturn<void> setProperties(const QVariantMap& properties);

Expand Down
37 changes: 31 additions & 6 deletions src/fdosecrets/objects/Prompt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ namespace FdoSecrets

MessageBox::OverrideParent override(findWindow(windowId));
// only need to delete in backend, collection will react itself.
service()->doCloseDatabase(m_collection->backend());
auto accepted = service()->doCloseDatabase(m_collection->backend());

emit completed(false, {});
emit completed(!accepted, {});

return {};
}
Expand Down Expand Up @@ -189,19 +189,44 @@ namespace FdoSecrets

MessageBox::OverrideParent override(findWindow(windowId));

QList<QDBusObjectPath> unlocked;
for (const auto& c : asConst(m_collections)) {
if (c) {
connect(c, &Collection::doneUnlockCollection, this, &UnlockCollectionsPrompt::collectionUnlockFinished);
c->doUnlock();
unlocked << c->objectPath();
}
}

emit completed(false, QVariant::fromValue(unlocked));

return {};
}

void UnlockCollectionsPrompt::collectionUnlockFinished(bool accepted)
{
auto coll = qobject_cast<Collection*>(sender());
if (!coll) {
return;
}

if (!m_collections.contains(coll)) {
// should not happen
coll->disconnect(this);
return;
}

// one shot
coll->disconnect(this);

if (accepted) {
m_unlocked << coll->objectPath();
} else {
m_numRejected += 1;
}

// if we've get all
if (m_numRejected + m_unlocked.size() == m_collections.size()) {
emit completed(m_unlocked.isEmpty(), QVariant::fromValue(m_unlocked));
}
}

DeleteItemPrompt::DeleteItemPrompt(Service* parent, Item* item)
: PromptBase(parent)
, m_item(item)
Expand Down
5 changes: 5 additions & 0 deletions src/fdosecrets/objects/Prompt.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,13 @@ namespace FdoSecrets

DBusReturn<void> prompt(const QString& windowId) override;

private slots:
void collectionUnlockFinished(bool accepted);

private:
QList<QPointer<Collection>> m_collections;
QList<QDBusObjectPath> m_unlocked;
int m_numRejected = 0;
};

class Item;
Expand Down
11 changes: 6 additions & 5 deletions src/fdosecrets/objects/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ namespace FdoSecrets
, m_insdieEnsureDefaultAlias(false)
, m_serviceWatcher(nullptr)
{
connect(
m_databases, &DatabaseTabWidget::databaseUnlockDialogFinished, this, &Service::doneUnlockDatabaseInDialog);
}

Service::~Service()
Expand Down Expand Up @@ -447,9 +449,9 @@ namespace FdoSecrets
return m_sessions;
}

void Service::doCloseDatabase(DatabaseWidget* dbWidget)
bool Service::doCloseDatabase(DatabaseWidget* dbWidget)
{
m_databases->closeDatabaseTab(dbWidget);
return m_databases->closeDatabaseTab(dbWidget);
}

Collection* Service::doNewDatabase()
Expand All @@ -472,11 +474,10 @@ namespace FdoSecrets

void Service::doSwitchToChangeDatabaseSettings(DatabaseWidget* dbWidget)
{
// switch selected to current
// unlock if needed
if (dbWidget->isLocked()) {
m_databases->unlockDatabaseInDialog(dbWidget, DatabaseOpenDialog::Intent::None);
return;
}
// switch selected to current
m_databases->setCurrentWidget(dbWidget);
m_databases->changeDatabaseSettings();

Expand Down
14 changes: 13 additions & 1 deletion src/fdosecrets/objects/Service.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ namespace FdoSecrets
*/
void error(const QString& msg);

/**
* Finish signal for async action doUnlockDatabaseInDialog
* @param accepted If false, the action is canceled by the user
* @param dbWidget The unlocked the dbWidget if succeed
*/
void doneUnlockDatabaseInDialog(bool accepted, DatabaseWidget* dbWidget);

public:
/**
* List of sessions
Expand All @@ -101,9 +108,14 @@ namespace FdoSecrets
}

public slots:
void doCloseDatabase(DatabaseWidget* dbWidget);
bool doCloseDatabase(DatabaseWidget* dbWidget);
Collection* doNewDatabase();
void doSwitchToChangeDatabaseSettings(DatabaseWidget* dbWidget);

/**
* Async, connect to signal doneUnlockDatabaseInDialog for finish notification
* @param dbWidget
*/
void doUnlockDatabaseInDialog(DatabaseWidget* dbWidget);

private slots:
Expand Down
4 changes: 2 additions & 2 deletions src/gui/DatabaseOpenDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void DatabaseOpenDialog::setTargetDatabaseWidget(DatabaseWidget* dbWidget)
disconnect(this, nullptr, m_dbWidget, nullptr);
}
m_dbWidget = dbWidget;
connect(this, SIGNAL(dialogFinished(bool)), dbWidget, SLOT(unlockDatabase(bool)));
connect(this, &DatabaseOpenDialog::dialogFinished, dbWidget, &DatabaseWidget::unlockDatabase);
}

void DatabaseOpenDialog::setIntent(DatabaseOpenDialog::Intent intent)
Expand Down Expand Up @@ -90,6 +90,6 @@ void DatabaseOpenDialog::complete(bool accepted)
} else {
reject();
}
emit dialogFinished(accepted);
emit dialogFinished(accepted, m_dbWidget);
clearForms();
}
2 changes: 1 addition & 1 deletion src/gui/DatabaseOpenDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class DatabaseOpenDialog : public QDialog
void clearForms();

signals:
void dialogFinished(bool);
void dialogFinished(bool accepted, DatabaseWidget* dbWidget);

public slots:
void complete(bool accepted);
Expand Down
2 changes: 2 additions & 0 deletions src/gui/DatabaseTabWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ DatabaseTabWidget::DatabaseTabWidget(QWidget* parent)
connect(autoType(), SIGNAL(globalAutoTypeTriggered()), SLOT(performGlobalAutoType()));
connect(autoType(), SIGNAL(autotypePerformed()), SLOT(relockPendingDatabase()));
connect(autoType(), SIGNAL(autotypeRejected()), SLOT(relockPendingDatabase()));
connect(m_databaseOpenDialog.data(), &DatabaseOpenDialog::dialogFinished,
this, &DatabaseTabWidget::databaseUnlockDialogFinished);
// clang-format on

#ifdef Q_OS_MACOS
Expand Down
1 change: 1 addition & 0 deletions src/gui/DatabaseTabWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public slots:
void tabNameChanged();
void messageGlobal(const QString&, MessageWidget::MessageType type);
void messageDismissGlobal();
void databaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget);

private slots:
void toggleTabbar();
Expand Down