diff --git a/kded/ui/mountdialog.cpp b/kded/ui/mountdialog.cpp index 5a395d6..ffb253a 100644 --- a/kded/ui/mountdialog.cpp +++ b/kded/ui/mountdialog.cpp @@ -1,63 +1,64 @@ /* * Copyright 2017 by Kees vd Broek * * 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 . */ #include "mountdialog.h" #include "engine/vault.h" #include +#include MountDialog::MountDialog(PlasmaVault::Vault *vault, const std::function &function) : m_vault(vault), m_function(function) { m_ui.setupUi(this); m_ui.errorLabel->setVisible(false); m_ui.vaultName->setText(vault->name()); QStyleOption option; option.initFrom(this); const int iconSize = style()->pixelMetric(QStyle::PM_MessageBoxIconSize, &option, this); m_ui.icon->setPixmap(QIcon::fromTheme(QStringLiteral("dialog-password")).pixmap(iconSize)); } void MountDialog::accept() { setCursor(Qt::WaitCursor); setEnabled(false); m_ui.password->lineEdit()->setCursor(Qt::WaitCursor); QString pwd = m_ui.password->password(); auto future = m_vault->open({ { KEY_PASSWORD, pwd } }); const auto result = AsynQt::await(future); unsetCursor(); setEnabled(true); m_ui.password->lineEdit()->unsetCursor(); if (result) { m_function(); QDialog::accept(); } else { qDebug() << "We've got an error" << result.error().message(); // m_ui.errorLabel->setText(i18n("Failed to open: %1").arg(result.error().message())); m_ui.errorLabel->setText(i18n("Failed to open: %1", result.error().message())); m_ui.errorLabel->setVisible(true); } } diff --git a/kded/ui/vaultconfigurationwizard.cpp b/kded/ui/vaultconfigurationwizard.cpp index 12b081f..1e454ef 100644 --- a/kded/ui/vaultconfigurationwizard.cpp +++ b/kded/ui/vaultconfigurationwizard.cpp @@ -1,183 +1,184 @@ /* * Copyright 2017 by Ivan Cukic * * 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 . */ #include "vaultconfigurationwizard.h" #include "ui_vaultconfigurationwizard.h" #include #include #include #include +#include #include "dialogdsl.h" #include "vault.h" using namespace DialogDsl; using namespace DialogDsl::operators; #include "backendchooserwidget.h" #include "activitieslinkingwidget.h" #include "cryfscypherchooserwidget.h" #include "directorychooserwidget.h" #include "noticewidget.h" #include "namechooserwidget.h" #include "passwordchooserwidget.h" using PlasmaVault::Vault; class VaultConfigurationWizard::Private { public: VaultConfigurationWizard *const q; Vault *vault; Ui::VaultConfigurationWizard ui; QStackedLayout *layout; steps currentSteps; QVector currentModuleDialogs; steps defaultSteps { i18n("General") / step { nameChooser(), directoryChooser(DirectoryChooserWidget::RequireEmptyMountPoint) }, i18n("Activities") / step { activitiesChooser() } /* i18n("Dismantle") / step { notice( "dismantle-message", i18n("Note that Plasma Vault will not delete any of the files,\n\ the dismantling process only removes the vault from Plasma.\n\ You will need to remove the files manually."), NoticeWidget::ShowAlways) } */ }; Logic logic { { "encfs" / i18n("EncFS"), defaultSteps }, { "cryfs" / i18n("CryFS"), defaultSteps } }; Private(Vault *vault, VaultConfigurationWizard *parent) : q(parent) , vault(vault) { ui.setupUi(parent); ui.message->hide(); layout = new QStackedLayout(); layout->setContentsMargins(0, 0, 0, 0); ui.container->setLayout(layout); auto tabs = new QTabWidget(); layout->addWidget(tabs); // Loading the backends auto modules = logic[Key(vault->backend().toLatin1())]; Vault::Payload payload { { KEY_NAME, QVariant(vault->name()) }, { KEY_MOUNT_POINT, QVariant(vault->mountPoint()) }, { KEY_ACTIVITIES, QVariant(vault->activities()) } }; for (const auto& module: modules) { DialogModule *stepWidget = new CompoundDialogModule(module); stepWidget->init(payload); tabs->addTab(stepWidget, module.title()); currentModuleDialogs << stepWidget; } } void setVaultOpened(bool vaultOpened) { bool configurationEnabled = !vaultOpened; ui.buttons->button(QDialogButtonBox::Ok)->setEnabled(configurationEnabled); ui.frameUnlockVault->setVisible(!configurationEnabled); ui.container->setEnabled(configurationEnabled); } void saveConfiguration() { Vault::Payload collectedPayload; qDebug() << "Getting the data"; for (const auto* module: currentModuleDialogs) { qDebug() << "Data: " << module->fields(); collectedPayload.unite(module->fields()); } const auto name = collectedPayload[KEY_NAME].toString(); const PlasmaVault::MountPoint mountPoint(collectedPayload[KEY_MOUNT_POINT].toString()); const auto activities = collectedPayload[KEY_ACTIVITIES].toStringList(); if (name.isEmpty() || mountPoint.isEmpty()) return; vault->setName(name); vault->setMountPoint(mountPoint); vault->setActivities(activities); } }; VaultConfigurationWizard::VaultConfigurationWizard(Vault *vault, QWidget *parent) : QDialog(parent) , d(new Private(vault, this)) { setWindowTitle(i18n("Configure")); d->setVaultOpened(vault->isOpened()); connect(d->ui.buttonCloseVault, &QPushButton::clicked, this, [=] () { vault->close(); }); connect(vault, &Vault::isOpenedChanged, this, [=] (bool isOpened) { d->setVaultOpened(isOpened); }); connect(d->ui.buttons, &QDialogButtonBox::accepted, this, [=] { d->saveConfiguration(); }); } VaultConfigurationWizard::~VaultConfigurationWizard() { }