diff --git a/plasma/package/contents/ui/main.qml b/plasma/package/contents/ui/main.qml --- a/plasma/package/contents/ui/main.qml +++ b/plasma/package/contents/ui/main.qml @@ -35,7 +35,7 @@ Plasmoid.icon: vaultsModelActions.hasError ? "plasmavault_error" : "plasmavault"; - Plasmoid.status: vaultsModelActions.count > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus + Plasmoid.status: vaultsModelActions.hasOpen ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus Plasmoid.onExpandedChanged: { plasmoid.nativeInterface.vaultsModel.reloadDevices(); diff --git a/plasma/vaultsmodel.h b/plasma/vaultsmodel.h --- a/plasma/vaultsmodel.h +++ b/plasma/vaultsmodel.h @@ -33,6 +33,7 @@ Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) Q_PROPERTY(bool hasError READ hasError NOTIFY hasErrorChanged) + Q_PROPERTY(bool hasOpen READ hasOpen NOTIFY hasOpenChanged) Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged) public: @@ -89,10 +90,12 @@ bool isBusy() const; bool hasError() const; + bool hasOpen() const; Q_SIGNALS: void isBusyChanged(bool isBusy); void hasErrorChanged(bool hasError); + void hasOpenChanged(bool hasOpen); void rowCountChanged(int count); private: diff --git a/plasma/vaultsmodel.cpp b/plasma/vaultsmodel.cpp --- a/plasma/vaultsmodel.cpp +++ b/plasma/vaultsmodel.cpp @@ -85,6 +85,7 @@ vaultKeys.clear(); busyVaults.clear(); errorVaults.clear(); + openVaults.clear(); for (const auto& vault: vaultList) { vaults[vault.device] = vault; @@ -97,6 +98,10 @@ if (!vault.message.isEmpty()) { errorVaults << vault.device; } + + if (vault.isOpened()) { + openVaults << vault.device; + } } q->endResetModel(); @@ -107,6 +112,7 @@ emit q->isBusyChanged(busyVaults.count() != 0); emit q->hasErrorChanged(errorVaults.count() != 0); + emit q->hasOpenChanged(openVaults.count() != 0); }); } @@ -191,6 +197,21 @@ } } + // Lets see whether this warrants updates to the open flag + if (vaultInfo.isOpened() && !openVaults.contains(device)) { + openVaults << device; + if (openVaults.count() == 1) { + emit q->hasOpenChanged(true); + } + } + + if (!vaultInfo.isOpened() && openVaults.contains(device)) { + openVaults.remove(device); + if (openVaults.count() == 0) { + emit q->hasOpenChanged(false); + } + } + vaults[device] = vaultInfo; q->dataChanged(q->index(row), q->index(row)); } @@ -404,6 +425,13 @@ +bool VaultsModel::hasOpen() const +{ + return !d->openVaults.isEmpty(); +} + + + SortedVaultsModelProxy::SortedVaultsModelProxy(QObject *parent) diff --git a/plasma/vaultsmodel_p.h b/plasma/vaultsmodel_p.h --- a/plasma/vaultsmodel_p.h +++ b/plasma/vaultsmodel_p.h @@ -49,6 +49,7 @@ QSet busyVaults; QSet errorVaults; + QSet openVaults; VaultsModel *const q; };