Commit 2befe1ff authored by Ivan Čukić's avatar Ivan Čukić 👁

Unassign activity from vault on activity deletion

Summary: CCBUG: 420784

Reviewers: ngraham, davidedmundson, mart

Reviewed By: mart

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D29379
parent fbd32235
......@@ -128,12 +128,24 @@ PlasmaVaultService::PlasmaVaultService(QObject * parent, const QVariantList&)
connect(this, &KDEDModule::moduleRegistered,
this, &PlasmaVaultService::slotRegistered);
// Close vaults that don't belong to the current activity
connect(&d->kamd, &KActivities::Consumer::currentActivityChanged,
this, &PlasmaVaultService::onCurrentActivityChanged);
this, &PlasmaVaultService::onCurrentActivityChanged);
// When an activity is deleted, remove it from all the vaults
connect(&d->kamd, &KActivities::Consumer::activityRemoved,
this, &PlasmaVaultService::onActivityRemoved);
// When activities are loaded, remove activities that no longer exist
// the vaults
connect(&d->kamd, &KActivities::Consumer::activitiesChanged,
this, &PlasmaVaultService::onActivitiesChanged);
for (const Device &device: Vault::availableDevices()) {
registerVault(new Vault(device, this));
}
onActivitiesChanged(d->kamd.activities());
}
......@@ -432,19 +444,6 @@ void PlasmaVaultService::openVaultInFileManager(const QString &device)
void PlasmaVaultService::onCurrentActivityChanged(
const QString &currentActivity)
{
for (auto* vault: d->knownVaults.values()) {
const auto vaultActivities = vault->activities();
if (!vaultActivities.isEmpty() && !vaultActivities.contains(currentActivity)) {
vault->close();
}
}
}
bool PlasmaVaultService::hasOpenVaults() const
{
return !d->openVaults.isEmpty();
......@@ -503,5 +502,52 @@ void PlasmaVaultService::updateStatus()
}
void PlasmaVaultService::onActivitiesChanged(const QStringList &knownActivities)
{
if (knownActivities == QStringList{ "00000000-0000-0000-0000-000000000000" }) return;
qDebug() << "Known activities:" << knownActivities;
for (auto* vault: d->knownVaults.values()) {
auto vaultActivities = vault->activities();
const auto removedBegin = std::remove_if(
vaultActivities.begin(), vaultActivities.end(),
[&knownActivities] (const QString &vaultActivity) {
return !knownActivities.contains(vaultActivity);
});
if (removedBegin != vaultActivities.end()) {
vaultActivities.erase(removedBegin, vaultActivities.end());
vault->setActivities(vaultActivities);
vault->saveConfiguration();
}
}
}
void PlasmaVaultService::onCurrentActivityChanged(const QString &currentActivity)
{
for (auto* vault: d->knownVaults.values()) {
const auto vaultActivities = vault->activities();
if (!vaultActivities.isEmpty() && !vaultActivities.contains(currentActivity)) {
vault->close();
}
}
}
void PlasmaVaultService::onActivityRemoved(const QString &removedActivity)
{
for (auto* vault: d->knownVaults.values()) {
auto vaultActivities = vault->activities();
if (vaultActivities.removeAll(removedActivity) > 0) {
vault->setActivities(vaultActivities);
vault->saveConfiguration();
emit vaultChanged(vault->info());
}
}
}
#include "service.moc"
......@@ -75,7 +75,9 @@ private Q_SLOTS:
void onVaultMessageChanged(const QString &message);
void onVaultInfoChanged();
void onActivitiesChanged(const QStringList &knownActivities);
void onCurrentActivityChanged(const QString &currentActivity);
void onActivityRemoved(const QString &removedActivity);
private:
class Private;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment