FdoSecrets: only emit completed signal when the action actually finishes

This commit is contained in:
Aetf 2019-12-13 15:28:45 -05:00 committed by Jonathan White
parent af14929af1
commit adb29dd0e4
10 changed files with 71 additions and 15 deletions

View File

@ -49,6 +49,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();
}

View File

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

View File

@ -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 {};
}
@ -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)

View File

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

View File

@ -47,6 +47,8 @@ namespace FdoSecrets
, m_insdieEnsureDefaultAlias(false)
, m_serviceWatcher(nullptr)
{
connect(
m_databases, &DatabaseTabWidget::databaseUnlockDialogFinished, this, &Service::doneUnlockDatabaseInDialog);
}
Service::~Service()
@ -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()
@ -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();

View File

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

View File

@ -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)
@ -90,6 +90,6 @@ void DatabaseOpenDialog::complete(bool accepted)
} else {
reject();
}
emit dialogFinished(accepted);
emit dialogFinished(accepted, m_dbWidget);
clearForms();
}

View File

@ -50,7 +50,7 @@ public:
void clearForms();
signals:
void dialogFinished(bool);
void dialogFinished(bool accepted, DatabaseWidget* dbWidget);
public slots:
void complete(bool accepted);

View File

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

View File

@ -90,6 +90,7 @@ signals:
void tabNameChanged();
void messageGlobal(const QString&, MessageWidget::MessageType type);
void messageDismissGlobal();
void databaseUnlockDialogFinished(bool accepted, DatabaseWidget* dbWidget);
private slots:
void toggleTabbar();