Commit 54a7b6cb authored by Ivan Čukić's avatar Ivan Čukić 👁

Go offline as soon as the password prompt is shown

With offline vaults, go offline while the user enters the
password, not only while the vault is mounted
parent fd3d8064
......@@ -269,6 +269,8 @@ void PlasmaVaultService::onVaultStatusChanged(VaultInfo::Status status)
devicesInhibittingNetworking.contains(vault->device());
if (status == VaultInfo::Opened && !alreadyInhibiting) {
auto deviceOpeningHandle = "{opening}" + vault->device();
devicesInhibittingNetworking.removeAll(deviceOpeningHandle);
devicesInhibittingNetworking << vault->device();
}
......@@ -276,8 +278,6 @@ void PlasmaVaultService::onVaultStatusChanged(VaultInfo::Status status)
devicesInhibittingNetworking.removeAll(vault->device());
}
// qDebug() << "Vaults inhibitting networking: " << devicesInhibittingNetworking;
// Now, let's handle the networking part
if (!devicesInhibittingNetworking.isEmpty()) {
NetworkManager::setNetworkingEnabled(false);
......@@ -307,9 +307,18 @@ void PlasmaVaultService::onVaultMessageChanged(const QString &message)
}
void showPasswordMountDialog(Vault *vault, const std::function<void()> &function)
template <typename OnAccepted, typename OnRejected>
void showPasswordMountDialog(Vault *vault,
OnAccepted onAccepted,
OnRejected onRejected)
{
auto dialog = new MountDialog(vault, function);
auto dialog = new MountDialog(vault);
QObject::connect(dialog, &QDialog::accepted,
vault, onAccepted);
QObject::connect(dialog, &QDialog::rejected,
vault, onRejected);
dialog->open();
}
//^
......@@ -321,10 +330,43 @@ void PlasmaVaultService::openVault(const QString &device)
if (auto vault = d->vaultFor(device)) {
if (vault->isOpened()) return;
if (vault->isOfflineOnly()) {
d->saveNetworkingState();
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
auto deviceOpeningHandle = "{opening}" + vault->device();
// We need to check whether this vault
// should be added or removed from the
// inhibitors list
const bool alreadyInhibiting =
devicesInhibittingNetworking.contains(deviceOpeningHandle);
if (!alreadyInhibiting) {
devicesInhibittingNetworking << deviceOpeningHandle;
}
NetworkManager::setNetworkingEnabled(false);
}
auto stopInhibiting = [this, vault] {
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
auto deviceOpeningHandle = "{opening}" + vault->device();
devicesInhibittingNetworking.removeAll(deviceOpeningHandle);
};
showPasswordMountDialog(vault,
[this, vault] {
emit vaultChanged(vault->info());
});
[this, vault, stopInhibiting] {
emit vaultChanged(vault->info());
stopInhibiting();
},
[this, vault, stopInhibiting] {
stopInhibiting();
if (vault->status() != VaultInfo::Opened) {
d->restoreNetworkingState();
}
}
);
}
}
......@@ -370,10 +412,18 @@ void PlasmaVaultService::openVaultInFileManager(const QString &device)
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint()), nullptr);
} else {
showPasswordMountDialog(vault, [this, vault] {
emit vaultChanged(vault->info());
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint()), nullptr);
});
showPasswordMountDialog(vault,
[this, vault] {
emit vaultChanged(vault->info());
new KRun(QUrl::fromLocalFile((QString)vault->mountPoint()), nullptr);
},
[this, vault] {
if (vault->status() != VaultInfo::Opened) {
auto& devicesInhibittingNetworking = d->savedNetworkingState->devicesInhibittingNetworking;
devicesInhibittingNetworking.removeAll(vault->device());
d->restoreNetworkingState();
}
});
}
}
}
......
......@@ -26,9 +26,8 @@
#include <KMessageWidget>
MountDialog::MountDialog(PlasmaVault::Vault *vault, const std::function<void()> &function)
: m_vault(vault),
m_function(function)
MountDialog::MountDialog(PlasmaVault::Vault *vault)
: m_vault(vault)
{
m_ui.setupUi(this);
......@@ -67,7 +66,6 @@ void MountDialog::accept()
m_ui.password->lineEdit()->unsetCursor();
if (result) {
m_function();
QDialog::accept();
} else {
qDebug() << "We've got an error" << result.error().message();
......
......@@ -34,14 +34,13 @@ namespace PlasmaVault {
class MountDialog : public QDialog
{
public:
MountDialog(PlasmaVault::Vault *vault, const std::function<void()> &function);
MountDialog(PlasmaVault::Vault *vault);
protected:
void accept() override;
private:
PlasmaVault::Vault *m_vault;
std::function<void()> m_function;
Ui_MountDialog m_ui;
KMessageWidget* m_errorLabel;
};
......
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