Commit f8c69245 authored by Nate Graham's avatar Nate Graham 🔩
Browse files

Dynamically show and hide based on whether or not any vaults are configured

Summary:
Currently, the Vaults icon is always visible in the System Tray. However most tray icons
dynamically show and hide themselves based on whether or not they're relevant and in use,
which results in a nice clean clutter-free System Tray. So it would be nice for Vaults
to do the same.

This patch implements that behavior by making `rowCount` a property that gets updated
based on vault creation and deletion, and making the icon only appear in the tray when at
last one vault has been created.  People who prefer to have it always visible can of course
override this in the System Tray settings, but the auto-hide behavior in this patch is probably
a better default for most.

Test Plan:
1. Have no vaults -> icon is only in the popup
2. Create a vault -> icon appears in the tray
3. Delete the vault -> icon disappears from the tray and lives in the popup again

Reviewers: broulik, ivan, #plasma, #vdg

Reviewed By: ivan, #plasma

Subscribers: plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D26447
parent b984ad94
......@@ -35,6 +35,8 @@ Item {
Plasmoid.icon: vaultsModelActions.hasError ? "plasmavault_error" : "plasmavault";
Plasmoid.status: vaultsModelActions.count > 0 ? PlasmaCore.Types.ActiveStatus : PlasmaCore.Types.PassiveStatus
Plasmoid.onExpandedChanged: {
plasmoid.nativeInterface.vaultsModel.reloadDevices();
}
......
......@@ -78,6 +78,7 @@ void VaultsModel::Private::loadData()
// Asynchronously load the devices
DBus::asyncCall<VaultInfoList>(&service, "availableDevices") |
onSuccess([this] (const VaultInfoList &vaultList) {
const int oldSize = vaultKeys.size();
q->beginResetModel();
vaults.clear();
......@@ -100,6 +101,10 @@ void VaultsModel::Private::loadData()
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 @@ void VaultsModel::Private::onVaultAdded(const PlasmaVault::VaultInfo &vaultInfo)
vaults[device] = vaultInfo;
vaultKeys << device;
q->endInsertRows();
emit q->rowCountChanged(vaultKeys.size());
}
......@@ -141,6 +147,7 @@ void VaultsModel::Private::onVaultRemoved(const QString &device)
vaultKeys.removeAt(row);
vaults.remove(device);
q->endRemoveRows();
emit q->rowCountChanged(vaultKeys.size());
}
......
......@@ -33,6 +33,7 @@ class VaultsModel: public QAbstractListModel {
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);
......@@ -41,7 +42,7 @@ public:
// 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 @@ public Q_SLOTS:
Q_SIGNALS:
void isBusyChanged(bool isBusy);
void hasErrorChanged(bool hasError);
void rowCountChanged(int count);
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