FdoSecrets: fix crash when enabling the plugin on a non-exposed database

This commit is contained in:
Aetf 2019-11-14 16:06:10 -05:00 committed by Jonathan White
parent e2c95f75f1
commit a66f8ec04d
2 changed files with 22 additions and 9 deletions

View File

@ -74,6 +74,10 @@ namespace FdoSecrets
public: public:
DBusReturn<void> setProperties(const QVariantMap& properties); DBusReturn<void> setProperties(const QVariantMap& properties);
bool isValid() const {
return backend();
}
DBusReturn<void> removeAlias(QString alias); DBusReturn<void> removeAlias(QString alias);
DBusReturn<void> addAlias(QString alias); DBusReturn<void> addAlias(QString alias);
const QSet<QString> aliases() const; const QSet<QString> aliases() const;
@ -106,6 +110,7 @@ namespace FdoSecrets
private slots: private slots:
void onDatabaseLockChanged(); void onDatabaseLockChanged();
void onDatabaseExposedGroupChanged(); void onDatabaseExposedGroupChanged();
// force reload info from backend, potentially delete self
void reloadBackend(); void reloadBackend();
private: private:

View File

@ -93,7 +93,24 @@ namespace FdoSecrets
void Service::onDatabaseTabOpened(DatabaseWidget* dbWidget, bool emitSignal) void Service::onDatabaseTabOpened(DatabaseWidget* dbWidget, bool emitSignal)
{ {
// The Collection will monitor the database's exposed group.
// When the Collection finds that no exposed group, it will delete itself.
// Thus the service also needs to monitor it and recreate the collection if the user changes
// from no exposed to exposed something.
if (!dbWidget->isLocked()) {
monitorDatabaseExposedGroup(dbWidget);
}
connect(dbWidget, &DatabaseWidget::databaseUnlocked, this, [this, dbWidget]() {
monitorDatabaseExposedGroup(dbWidget);
});
auto coll = new Collection(this, dbWidget); auto coll = new Collection(this, dbWidget);
// Creation may fail if the database is not exposed.
// This is okay, because we monitor the expose settings above
if (!coll->isValid()) {
coll->deleteLater();
return;
}
m_collections << coll; m_collections << coll;
m_dbToCollection[dbWidget] = coll; m_dbToCollection[dbWidget] = coll;
@ -127,15 +144,6 @@ namespace FdoSecrets
emit collectionDeleted(coll); emit collectionDeleted(coll);
}); });
// a special case: the database changed from no expose to expose something.
// in this case, there is no collection out there monitoring it, so create a new collection
if (!dbWidget->isLocked()) {
monitorDatabaseExposedGroup(dbWidget);
}
connect(dbWidget, &DatabaseWidget::databaseUnlocked, this, [this, dbWidget]() {
monitorDatabaseExposedGroup(dbWidget);
});
if (emitSignal) { if (emitSignal) {
emit collectionCreated(coll); emit collectionCreated(coll);
} }