Commit a13da523 authored by Ivan Čukić's avatar Ivan Čukić 👁

Added support for vanishing vaults

In the case of Vaults on removable drives, when the drive is not
attached (vault encrypted data is not accessible), the applet
will show the vault as disabled.
parent 1a372606
......@@ -29,5 +29,8 @@
<arg name="vault" type="s" direction="in"/>
</method>
<method name="updateStatus">
</method>
</interface>
</node>
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -43,6 +43,8 @@ public:
Dismantling = 6,
Dismantled = 7,
DeviceMissing = 254,
Error = 255
};
// Q_ENUM(Status); // VaultInfo is not a QObject or anything like that
......
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -161,10 +161,13 @@ public:
emit q->statusChanged(data->status = VaultInfo::Dismantled);
} else {
QDir deviceDir(device.data());
const auto newStatus =
isOpened() ? VaultInfo::Opened :
isInitialized() ? VaultInfo::Closed :
VaultInfo::NotInitialized;
!deviceDir.exists() ? VaultInfo::DeviceMissing :
isOpened() ? VaultInfo::Opened :
isInitialized() ? VaultInfo::Closed :
VaultInfo::NotInitialized;
if (oldStatus == newStatus) return;
......@@ -248,7 +251,6 @@ public:
const QDir mountPointDir(vaultData.mountPoint.data());
return
// If the backend is not known, we need to fail
!Backend::availableBackends().contains(vaultData.backendName) ?
......@@ -747,6 +749,14 @@ VaultInfo Vault::info() const
return vaultInfo;
}
void Vault::updateStatus()
{
d->updateStatus();
}
} // namespace PlasmaVault
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -91,6 +91,8 @@ public:
// TODO: Replace this with shared_ptr and enable_shared_from_this?
void scheduleDeletion();
void updateStatus();
public Q_SLOTS:
QString message() const;
VaultInfo::Status status() const;
......
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -493,5 +493,15 @@ void PlasmaVaultService::deleteVault(const QString &device, const QString &name)
}
void PlasmaVaultService::updateStatus()
{
for (const auto& device: d->knownVaults.keys()) {
auto vault = d->knownVaults[device];
vault->updateStatus();
}
}
#include "service.moc"
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -54,6 +54,8 @@ public Q_SLOTS:
Q_SCRIPTABLE void deleteVault(const QString &device, const QString &name);
Q_SCRIPTABLE void updateStatus();
Q_SIGNALS:
void registered();
......
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -35,6 +35,7 @@ MouseArea {
property bool isOpened: false
property bool isBusy: false
property bool isEnabled: false
property bool isOfflineOnly: false
......@@ -44,7 +45,9 @@ MouseArea {
actionsList.visible = false;
}
property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.source()
onIsEnabledChanged: if (!isEnabled) { collapse(); }
property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.actionsModel()
hoverEnabled: true
height: units.iconSizes.medium + 2 * units.smallSpacing
......@@ -101,6 +104,8 @@ MouseArea {
iconName: isOpened ? "media-eject" : "media-mount"
enabled: vaultItem.isEnabled
onClicked: {
vaultsModelActions.toggle(vaultItem.device);
collapse();
......@@ -199,6 +204,8 @@ MouseArea {
visible: !actionsList.visible
onClicked: {
if (!vaultItem.isEnabled) return;
actionsList.visible = !actionsList.visible;
if (actionsList.visible) {
vaultItem.itemExpanded(vaultItem);
......
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -26,38 +26,17 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtras
Item {
// For quick mockups in plasmoidviewer
// property var vaultsModel: ListModel {
// ListElement {
// name: "TestVault"
// icon: "folder-decrypted"
// device: ""
// mountPoint: ""
// isBusy: false
// isOpened: true
// activities: []
// status: 1 // VaultInfo::Opened
// message: ""
// }
// }
property var vaultsModel: plasmoid.nativeInterface.vaultsModel
property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.source()
property var vaultsModelActions: plasmoid.nativeInterface.vaultsModel.actionsModel()
property var expandedItem: null
Binding {
target: plasmoid
property: "busy"
value: vaultsModelActions.isBusy
}
Plasmoid.busy: vaultsModelActions.isBusy
Binding {
target: plasmoid
property: "icon"
value: {
return vaultsModelActions.hasError ? "plasmavault_error" : "plasmavault";
}
Plasmoid.icon: vaultsModelActions.hasError ? "plasmavault_error" : "plasmavault";
Plasmoid.onExpandedChanged: {
plasmoid.nativeInterface.vaultsModel.reloadDevices();
}
Plasmoid.fullRepresentation: ColumnLayout {
......@@ -72,8 +51,6 @@ Item {
// text: i18nd("plasmavault-kde", "Encrypted vaults")
// }
ListView {
id: vaultsList
......@@ -98,6 +75,7 @@ Item {
name: model.name
message: model.message
isOpened: model.isOpened
isEnabled: model.isEnabled
device: model.device
isOfflineOnly: model.isOfflineOnly
......
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -241,14 +241,13 @@ QVariant VaultsModel::data(const QModelIndex &index, int role) const
case VaultIcon:
{
QFileInfo fileInfo(vault.device);
if (!fileInfo.exists()) {
return "document-close";
} else switch (vault.status) {
switch (vault.status) {
case VaultInfo::Error:
return "document-close";
case VaultInfo::DeviceMissing:
return "document-close";
case VaultInfo::NotInitialized:
return "folder-gray";
......@@ -277,6 +276,10 @@ QVariant VaultsModel::data(const QModelIndex &index, int role) const
case VaultMessage:
return vault.message;
case VaultIsEnabled:
return !(vault.status == VaultInfo::Error) &&
!(vault.status == VaultInfo::DeviceMissing);
}
return {};
......@@ -296,7 +299,8 @@ QHash<int, QByteArray> VaultsModel::roleNames() const
{ VaultActivities, "activities" },
{ VaultIsOfflineOnly, "isOfflineOnly" },
{ VaultStatus, "status" },
{ VaultMessage, "message" }
{ VaultMessage, "message" },
{ VaultIsEnabled, "isEnabled" }
};
}
......@@ -308,6 +312,11 @@ void VaultsModel::refresh()
}
void VaultsModel::reloadDevices()
{
d->service.updateStatus();
}
void VaultsModel::open(const QString &device)
{
......@@ -432,9 +441,14 @@ bool SortedVaultsModelProxy::filterAcceptsRow(int sourceRow,
QObject *SortedVaultsModelProxy::source() const
QObject *SortedVaultsModelProxy::actionsModel() const
{
return sourceModel();
}
void SortedVaultsModelProxy::reloadDevices()
{
static_cast<VaultsModel*>(sourceModel())->reloadDevices();
}
/*
* Copyright 2017 by Ivan Cukic <ivan.cukic (at) kde.org>
* Copyright 2017, 2018, 2019 by Ivan Cukic <ivan.cukic (at) kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -38,6 +38,9 @@ public:
explicit VaultsModel(QObject *parent = nullptr);
~VaultsModel() override;
// This forces detection of removable drives
void reloadDevices();
int rowCount(const QModelIndex &parent) const override;
QVariant data(const QModelIndex &index, int role) const override;
......@@ -54,12 +57,11 @@ public:
VaultStatus, ///< Status of the vault, @see VaultInfo::Status
VaultActivities, ///< To which activities does this vault belong to
VaultIsOfflineOnly, ///< Should the networking be off when this vault is mounted
VaultMessage ///< Message to be shown for the vault
VaultMessage, ///< Message to be shown for the vault
VaultIsEnabled ///< Can the vault be mounted
};
public Q_SLOTS:
// Refresh the model. This should be done automatically, no need to call
// this function
void refresh();
// Open (unlock) a vault
......@@ -110,7 +112,10 @@ public:
const QModelIndex &sourceParent) const override;
public Q_SLOTS:
QObject *source() const;
QObject *actionsModel() const;
// This forces detection of removable drives
void reloadDevices();
private:
VaultsModel *m_source;
......
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