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,6 +35,8 @@ Plasmoid.icon: vaultsModelActions.hasError ? "plasmavault_error" : "plasmavault"; + Plasmoid.status: vaultsModelActions.count > 0 ? 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,15 +33,16 @@ Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged) Q_PROPERTY(bool hasError READ hasError NOTIFY hasErrorChanged) + Q_PROPERTY(int count READ rowCount NOTIFY rowCountChanged) public: explicit VaultsModel(QObject *parent = nullptr); ~VaultsModel() override; // This forces detection of removable drives void reloadDevices(); - int rowCount(const QModelIndex &parent) const override; + int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role) const override; @@ -92,6 +93,7 @@ Q_SIGNALS: void isBusyChanged(bool isBusy); void hasErrorChanged(bool hasError); + void rowCountChanged(int count); private: class Private; diff --git a/plasma/vaultsmodel.cpp b/plasma/vaultsmodel.cpp --- a/plasma/vaultsmodel.cpp +++ b/plasma/vaultsmodel.cpp @@ -78,6 +78,7 @@ // Asynchronously load the devices DBus::asyncCall(&service, "availableDevices") | onSuccess([this] (const VaultInfoList &vaultList) { + const int oldSize = vaultKeys.size(); q->beginResetModel(); vaults.clear(); @@ -100,6 +101,10 @@ q->endResetModel(); + if (vaultKeys.size() != oldSize) { + emit q->rowCountChanged(vaultKeys.size()); + } + emit q->isBusyChanged(busyVaults.count() != 0); emit q->hasErrorChanged(errorVaults.count() != 0); }); @@ -127,6 +132,7 @@ vaults[device] = vaultInfo; vaultKeys << device; q->endInsertRows(); + emit q->rowCountChanged(vaultKeys.size()); } @@ -141,6 +147,7 @@ vaultKeys.removeAt(row); vaults.remove(device); q->endRemoveRows(); + emit q->rowCountChanged(vaultKeys.size()); }