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

Added option to switch off networking when a vault is mounted

parent de34b6a9
......@@ -58,6 +58,7 @@ find_package (
KIO
Plasma
WidgetsAddons
NetworkManagerQt
)
find_package (KF5SysGuard REQUIRED)
......
......@@ -50,10 +50,13 @@ public:
QString name;
QString device;
QString mountPoint;
QStringList activities;
Status status;
QString message;
QStringList activities;
bool isOfflineOnly;
inline bool isInitialized() const
{
......@@ -92,9 +95,12 @@ inline QDebug &operator<< (QDebug &debug,
<< vaultInfo.name
<< vaultInfo.device
<< vaultInfo.mountPoint
<< (quint16)vaultInfo.status
<< vaultInfo.activities
<< vaultInfo.message
<< vaultInfo.activities
<< vaultInfo.isOfflineOnly
;
return debug;
}
......@@ -109,9 +115,12 @@ inline QDBusArgument &operator<< (QDBusArgument &argument,
<< vaultInfo.name
<< vaultInfo.device
<< vaultInfo.mountPoint
<< (quint16)vaultInfo.status
<< vaultInfo.activities
<< vaultInfo.message
<< vaultInfo.activities
<< vaultInfo.isOfflineOnly
;
argument.endStructure();
return argument;
......@@ -128,9 +137,12 @@ inline const QDBusArgument &operator>> (const QDBusArgument &argument,
>> vaultInfo.name
>> vaultInfo.device
>> vaultInfo.mountPoint
>> status
>> vaultInfo.activities
>> vaultInfo.message
>> vaultInfo.activities
>> vaultInfo.isOfflineOnly
;
vaultInfo.status = (VaultInfo::Status)status;
argument.endStructure();
......
......@@ -25,6 +25,8 @@ set (
ui/namechooserwidget.cpp
ui/noticewidget.cpp
ui/passwordchooserwidget.cpp
ui/offlineonlywidget.cpp
ui/vaultcreationwizard.cpp
ui/vaultconfigurationwizard.cpp
......@@ -41,6 +43,8 @@ ki18n_wrap_ui (
ui/namechooserwidget.ui
ui/noticewidget.ui
ui/passwordchooserwidget.ui
ui/offlineonlywidget.ui
ui/vaultcreationwizard.ui
ui/vaultconfigurationwizard.ui
)
......@@ -77,6 +81,7 @@ target_link_libraries (
KF5::SysGuard
KF5::WidgetsAddons
KF5::ProcessCore
KF5::NetworkManagerQt
)
......
......@@ -50,6 +50,7 @@
#define CFG_MOUNT_POINT "mountPoint"
#define CFG_BACKEND "backend"
#define CFG_ACTIVITIES "activities"
#define CFG_OFFLINEONLY "offlineOnly"
namespace PlasmaVault {
......@@ -67,10 +68,13 @@ public:
struct Data {
QString name;
MountPoint mountPoint;
VaultInfo::Status status;
QStringList activities;
QString message;
QStringList activities;
bool isOfflineOnly;
QString backendName;
Backend::Ptr backend;
};
......@@ -128,7 +132,9 @@ public:
vaultConfig.writeEntry(CFG_MOUNT_POINT, data->mountPoint.data());
vaultConfig.writeEntry(CFG_NAME, data->name);
vaultConfig.writeEntry(CFG_BACKEND, data->backend->name());
vaultConfig.writeEntry(CFG_ACTIVITIES, data->activities);
vaultConfig.writeEntry(CFG_OFFLINEONLY, data->isOfflineOnly);
org::kde::KDirNotify::emitFilesAdded(
QUrl::fromLocalFile(data->mountPoint.data()));
......@@ -149,6 +155,7 @@ public:
// vaultConfig.deleteEntry(CFG_NAME);
// vaultConfig.deleteEntry(CFG_BACKEND);
// vaultConfig.deleteEntry(CFG_ACTIVITIES);
// vaultConfig.deleteEntry(CFG_OFFLINEONLY);
emit q->statusChanged(VaultInfo::Error);
}
......@@ -178,6 +185,7 @@ public:
Data vaultData;
const QString backendName = payload[KEY_BACKEND].toString();
const QStringList activities = payload[KEY_ACTIVITIES].toStringList();
const bool isOfflineOnly = payload[KEY_OFFLINEONLY].toBool();
// status should never be in this state, if we got an error,
// d->data should not be valid
......@@ -185,10 +193,11 @@ public:
// Reading the mount data from the config
const KConfigGroup vaultConfig(config, device.data());
vaultData.name = vaultConfig.readEntry(CFG_NAME, name);
vaultData.mountPoint = MountPoint(vaultConfig.readEntry(CFG_MOUNT_POINT, mountPoint.data()));
vaultData.backendName = vaultConfig.readEntry(CFG_BACKEND, backendName);
vaultData.activities = vaultConfig.readEntry(CFG_ACTIVITIES, activities);
vaultData.name = vaultConfig.readEntry(CFG_NAME, name);
vaultData.mountPoint = MountPoint(vaultConfig.readEntry(CFG_MOUNT_POINT, mountPoint.data()));
vaultData.backendName = vaultConfig.readEntry(CFG_BACKEND, backendName);
vaultData.activities = vaultConfig.readEntry(CFG_ACTIVITIES, activities);
vaultData.isOfflineOnly = vaultConfig.readEntry(CFG_OFFLINEONLY, isOfflineOnly);
const QDir mountPointDir(vaultData.mountPoint);
......@@ -271,12 +280,15 @@ Vault::Vault(const Device &device, QObject *parent)
this, [&] {
qDebug() << "Saving vault info:"
<< d->data->name
<< d->data->mountPoint
<< d->data->activities
<< d->data->mountPoint;
<< d->data->isOfflineOnly
;
KConfigGroup vaultConfig(d->config, d->device.data());
vaultConfig.writeEntry(CFG_MOUNT_POINT, d->data->mountPoint.data());
vaultConfig.writeEntry(CFG_NAME, d->data->name);
vaultConfig.writeEntry(CFG_ACTIVITIES, d->data->activities);
vaultConfig.writeEntry(CFG_OFFLINEONLY, d->data->isOfflineOnly);
d->config->sync();
......@@ -575,6 +587,20 @@ void Vault::setActivities(const QStringList &activities)
bool Vault::isOfflineOnly() const
{
return d->data->isOfflineOnly;
}
void Vault::setIsOfflineOnly(bool isOfflineOnly)
{
d->data->isOfflineOnly = isOfflineOnly;
emit isOfflineOnlyChanged(isOfflineOnly);
saveConfiguration();
}
QString Vault::name() const
{
return d->data->name;
......@@ -619,11 +645,16 @@ bool Vault::isBusy() const
VaultInfo Vault::info() const
{
VaultInfo vaultInfo;
vaultInfo.device = device();
vaultInfo.name = name();
vaultInfo.status = status();
vaultInfo.activities = activities();
vaultInfo.message = message();
vaultInfo.device = device();
vaultInfo.name = name();
vaultInfo.status = status();
vaultInfo.message = message();
vaultInfo.activities = activities();
vaultInfo.isOfflineOnly = isOfflineOnly();
return vaultInfo;
}
......
......@@ -36,12 +36,16 @@ class QDBusArgument;
namespace PlasmaVault {
#define KEY_NAME "vault-name"
#define KEY_BACKEND "vault-backend"
#define KEY_PASSWORD "vault-password"
#define KEY_DEVICE "vault-device"
#define KEY_MOUNT_POINT "vault-mount-point"
#define KEY_ACTIVITIES "vault-activities"
// Main keys
#define KEY_NAME "vault-name"
#define KEY_BACKEND "vault-backend"
#define KEY_PASSWORD "vault-password"
#define KEY_DEVICE "vault-device"
#define KEY_MOUNT_POINT "vault-mount-point"
// Additional options
#define KEY_ACTIVITIES "vault-activities"
#define KEY_OFFLINEONLY "vault-offline-only"
class Vault: public QObject {
Q_OBJECT
......@@ -56,8 +60,10 @@ class Vault: public QObject {
Q_PROPERTY(bool isBusy READ isBusy NOTIFY isBusyChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QStringList activities READ activities NOTIFY activitiesChanged)
Q_PROPERTY(QString message READ message NOTIFY messageChanged)
Q_PROPERTY(QString message READ message NOTIFY messageChanged)
Q_PROPERTY(QStringList activities READ activities NOTIFY activitiesChanged)
Q_PROPERTY(bool isOfflineOnly READ isOfflineOnly NOTIFY isOfflineOnlyChanged)
public:
Vault(const Device &device, QObject *parent = nullptr);
......@@ -100,6 +106,9 @@ public Q_SLOTS:
QStringList activities() const;
void setActivities(const QStringList &activities);
bool isOfflineOnly() const;
void setIsOfflineOnly(bool isOfflineOnly);
void saveConfiguration();
Q_SIGNALS:
......@@ -111,6 +120,8 @@ Q_SIGNALS:
void activitiesChanged(const QStringList &activities);
void messageChanged(const QString &message);
void nameChanged(const QString &name);
void isOfflineOnlyChanged(bool isOfflineOnly);
void infoChanged();
public:
......
......@@ -34,6 +34,8 @@
#include "ui/vaultcreationwizard.h"
#include "ui/vaultconfigurationwizard.h"
#include <NetworkManagerQt/Manager>
K_PLUGIN_FACTORY_WITH_JSON(PlasmaVaultServiceFactory,
"plasmavault.json",
registerPlugin<PlasmaVaultService>();)
......@@ -45,6 +47,11 @@ public:
QHash<Device, Vault*> knownVaults;
KActivities::Consumer kamd;
QVector<QString> devicesInhibittingNetworking;
struct {
bool networkingEnabled;
} savedNetworkingStatus;
Vault* vaultFor(const QString &device_) const
{
const Device device(device_);
......@@ -236,10 +243,19 @@ void PlasmaVaultService::openVault(const QString &device)
if (auto vault = d->vaultFor(device)) {
if (vault->isOpened()) return;
if (vault->isOfflineOnly()) {
if (d->devicesInhibittingNetworking.isEmpty()) {
d->savedNetworkingStatus.networkingEnabled =
NetworkManager::isNetworkingEnabled();
NetworkManager::setNetworkingEnabled(false);
}
d->devicesInhibittingNetworking << device;
}
showPasswordMountDialog(vault,
[this, vault] {
emit vaultChanged(vault->info());
});
[this, vault] {
emit vaultChanged(vault->info());
});
}
}
......@@ -251,6 +267,13 @@ void PlasmaVaultService::closeVault(const QString &device)
if (!vault->isOpened()) return;
vault->close();
if (!d->devicesInhibittingNetworking.isEmpty()) {
d->devicesInhibittingNetworking.removeAll(device);
if (d->devicesInhibittingNetworking.isEmpty()) {
NetworkManager::setNetworkingEnabled(d->savedNetworkingStatus.networkingEnabled);
}
}
}
}
......
/*
* Copyright 2017 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
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "offlineonlywidget.h"
#include "ui_offlineonlywidget.h"
#include <KSharedConfig>
#include <KConfigGroup>
class OfflineOnlyChooserWidget::Private {
public:
Ui::OfflineOnlyChooserWidget ui;
KSharedConfig::Ptr config;
};
OfflineOnlyChooserWidget::OfflineOnlyChooserWidget()
: DialogDsl::DialogModule(true)
, d(new Private())
{
d->ui.setupUi(this);
}
OfflineOnlyChooserWidget::~OfflineOnlyChooserWidget()
{
}
PlasmaVault::Vault::Payload OfflineOnlyChooserWidget::fields() const
{
return {
{ KEY_OFFLINEONLY, d->ui.checkShouldBeOffline->isChecked() }
};
}
void OfflineOnlyChooserWidget::init(const PlasmaVault::Vault::Payload &payload)
{
d->ui.checkShouldBeOffline->setChecked(
payload[KEY_OFFLINEONLY].toBool());
}
/*
* Copyright 2017 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
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PLASMAVAULT_KDED_UI_OFFLINEONLY_WIDGET_H
#define PLASMAVAULT_KDED_UI_OFFLINEONLY_WIDGET_H
#include "dialogdsl.h"
class OfflineOnlyChooserWidget: public DialogDsl::DialogModule {
Q_OBJECT
public:
OfflineOnlyChooserWidget();
~OfflineOnlyChooserWidget();
PlasmaVault::Vault::Payload fields() const override;
void init(const PlasmaVault::Vault::Payload &payload) override;
private:
class Private;
QScopedPointer<Private> d;
};
inline DialogDsl::ModuleFactory offlineOnlyChooser()
{
return [=] {
return new OfflineOnlyChooserWidget();
};
}
#endif // include guard
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OfflineOnlyChooserWidget</class>
<widget class="QWidget" name="OfflineOnlyChooserWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>652</width>
<height>20</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="checkShouldBeOffline">
<property name="text">
<string>Go offline while this vault is open (switch off networking and bluetooth)</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -39,6 +39,7 @@ using namespace DialogDsl::operators;
#include "noticewidget.h"
#include "namechooserwidget.h"
#include "passwordchooserwidget.h"
#include "offlineonlywidget.h"
using PlasmaVault::Vault;
......@@ -60,8 +61,9 @@ public:
directoryChooser(DirectoryChooserWidget::RequireEmptyMountPoint)
},
i18n("Activities") / step {
activitiesChooser()
i18n("Advanced") / step {
activitiesChooser(),
offlineOnlyChooser()
}
/*
......@@ -107,7 +109,8 @@ public:
Vault::Payload payload {
{ KEY_NAME, QVariant(vault->name()) },
{ KEY_MOUNT_POINT, QVariant(vault->mountPoint()) },
{ KEY_ACTIVITIES, QVariant(vault->activities()) }
{ KEY_ACTIVITIES, QVariant(vault->activities()) },
{ KEY_OFFLINEONLY, QVariant(vault->isOfflineOnly()) }
};
for (const auto& module: modules) {
......@@ -138,12 +141,14 @@ public:
const auto name = collectedPayload[KEY_NAME].toString();
const PlasmaVault::MountPoint mountPoint(collectedPayload[KEY_MOUNT_POINT].toString());
const auto activities = collectedPayload[KEY_ACTIVITIES].toStringList();
const auto isOfflineOnly = collectedPayload[KEY_OFFLINEONLY].toBool();
if (name.isEmpty() || mountPoint.isEmpty()) return;
vault->setName(name);
vault->setMountPoint(mountPoint);
vault->setActivities(activities);
vault->setIsOfflineOnly(isOfflineOnly);
}
};
......
......@@ -38,6 +38,7 @@ using namespace DialogDsl::operators;
#include "directorypairchooserwidget.h"
#include "noticewidget.h"
#include "passwordchooserwidget.h"
#include "offlineonlywidget.h"
class VaultCreationWizard::Private {
public:
......@@ -81,7 +82,10 @@ public:
},
step { passwordChooser() },
step { directoryPairChooser(DirectoryPairChooserWidget::RequireEmptyDirectories) },
step { activitiesChooser() }
step {
activitiesChooser(),
offlineOnlyChooser()
}
}
},
......@@ -106,7 +110,8 @@ public:
step { directoryPairChooser(DirectoryPairChooserWidget::RequireEmptyDirectories) },
step {
cryfsCypherChooser(),
activitiesChooser()
activitiesChooser(),
offlineOnlyChooser()
}
}
}
......
......@@ -36,6 +36,8 @@ MouseArea {
property bool isOpened: false
property bool isBusy: false
property bool isOfflineOnly: false
signal itemExpanded(variant item);
function collapse() {
......@@ -78,6 +80,7 @@ MouseArea {
source: {
return vaultItem.message != "" ? "emblem-error" :
vaultItem.isOpened ? "emblem-mounted" :
vaultItem.isOfflineOnly ? "network-disconnect" :
""
}
}
......
......@@ -78,6 +78,7 @@ Item {
message: model.message
isOpened: model.isOpened
device: model.device
isOfflineOnly: model.isOfflineOnly
width: parent.width
......
......@@ -272,6 +272,9 @@ QVariant VaultsModel::data(const QModelIndex &index, int role) const
case VaultActivities:
return vault.activities;
case VaultIsOfflineOnly:
return vault.isOfflineOnly;
case VaultMessage:
return vault.message;
}
......@@ -291,6 +294,7 @@ QHash<int, QByteArray> VaultsModel::roleNames() const
{ VaultIsBusy, "isBusy" },
{ VaultIsOpened, "isOpened" },
{ VaultActivities, "activities" },
{ VaultIsOfflineOnly, "isOfflineOnly" },
{ VaultStatus, "status" },
{ VaultMessage, "message" }
};
......
......@@ -53,6 +53,7 @@ public:
VaultIsOpened, ///< Is the vault open
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 forthe vault
};
......
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