Commit db2986a2 authored by Ivan Čukić's avatar Ivan Čukić 👁
Browse files

Added d-bus functions to close all open vaults

parent 51a6a567
......@@ -50,6 +50,7 @@ using AsynQt::Expected;
class PlasmaVaultService::Private {
public:
QHash<Device, Vault*> knownVaults;
QSet<Device> openVaults;
KActivities::Consumer kamd;
struct NetworkingState {
......@@ -60,6 +61,7 @@ public:
Expected<NetworkingState, int> savedNetworkingState =
Expected<NetworkingState, int>::error(0);
void saveNetworkingState()
{
// Ignore the request if we already have a saved state
......@@ -74,6 +76,7 @@ public:
});
}
void restoreNetworkingState()
{
// Ignore the request if we do not have a state saved
......@@ -86,7 +89,6 @@ public:
}
Vault* vaultFor(const QString &device_) const
{
const Device device(device_);
......@@ -191,6 +193,10 @@ void PlasmaVaultService::registerVault(Vault *vault)
this, &PlasmaVaultService::onVaultInfoChanged);
emit vaultAdded(vault->info());
if (vault->status() == VaultInfo::Opened) {
d->openVaults << vault->device();
}
}
......@@ -199,6 +205,18 @@ void PlasmaVaultService::onVaultStatusChanged(VaultInfo::Status status)
{
const auto vault = qobject_cast<Vault*>(sender());
if (status == VaultInfo::Opened) {
d->openVaults << vault->device();
if (d->openVaults.size() == 1) {
emit hasOpenVaultsChanged(true);
}
} else {
d->openVaults.remove(vault->device());
if (d->openVaults.isEmpty()) {
emit hasOpenVaultsChanged(false);
}
}
if (vault->isOfflineOnly()) {
d->saveNetworkingState();
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
......@@ -336,5 +354,30 @@ void PlasmaVaultService::onCurrentActivityChanged(
}
bool PlasmaVaultService::hasOpenVaults() const
{
return !d->openVaults.isEmpty();
}
void PlasmaVaultService::closeAllVaults()
{
for (const auto& device: d->openVaults) {
closeVault(device.data());
}
}
void PlasmaVaultService::forceCloseAllVaults()
{
for (const auto& device: d->openVaults) {
forceCloseVault(device.data());
}
}
#include "service.moc"
......@@ -42,13 +42,17 @@ public Q_SLOTS:
Q_SCRIPTABLE void requestNewVault();
Q_SCRIPTABLE void openVault(const QString &device);
Q_SCRIPTABLE void closeVault(const QString &device);
Q_SCRIPTABLE void forceCloseVault(const QString &device);
Q_SCRIPTABLE void configureVault(const QString &device);
Q_SCRIPTABLE void forceCloseVault(const QString &device);
Q_SCRIPTABLE void openVaultInFileManager(const QString &device);
Q_SCRIPTABLE PlasmaVault::VaultInfoList availableDevices() const;
Q_SCRIPTABLE bool hasOpenVaults() const;
Q_SCRIPTABLE void closeAllVaults();
Q_SCRIPTABLE void forceCloseAllVaults();
Q_SIGNALS:
void registered();
......@@ -56,6 +60,8 @@ Q_SIGNALS:
Q_SCRIPTABLE void vaultRemoved(const QString &device);
Q_SCRIPTABLE void vaultChanged(const PlasmaVault::VaultInfo &vaultData);
Q_SCRIPTABLE void hasOpenVaultsChanged(bool hasOpenVaults);
private Q_SLOTS:
void slotRegistered(const QDBusObjectPath &path);
......
Supports Markdown
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