diff --git a/kded/CMakeLists.txt b/kded/CMakeLists.txt --- a/kded/CMakeLists.txt +++ b/kded/CMakeLists.txt @@ -27,6 +27,7 @@ ui/passwordchooserwidget.cpp ui/vaultcreationwizard.cpp ui/vaultconfigurationwizard.cpp + ui/mountdialog.cpp ../common/vaultinfo.cpp ) @@ -43,6 +44,7 @@ ui/passwordchooserwidget.ui ui/vaultcreationwizard.ui ui/vaultconfigurationwizard.ui + ui/mountdialog.ui ) add_library ( diff --git a/kded/service.cpp b/kded/service.cpp --- a/kded/service.cpp +++ b/kded/service.cpp @@ -33,6 +33,9 @@ #include "ui/vaultcreationwizard.h" #include "ui/vaultconfigurationwizard.h" +#include "ui/mountdialog.h" + +#include K_PLUGIN_FACTORY_WITH_JSON(PlasmaVaultServiceFactory, "plasmavault.json", @@ -182,52 +185,10 @@ } -template -class PasswordMountDialog: protected KPasswordDialog { //_ -public: - PasswordMountDialog(Vault *vault, Function function) - : m_vault(vault) - , m_function(function) - { - } - - void show() - { - KPasswordDialog::show(); - } - -private: - bool checkPassword() override - { - auto future = m_vault->open({ { KEY_PASSWORD, password() } }); - - const auto result = AsynQt::await(future); - - if (result) { - m_function(); - return true; - - } else { - showErrorMessage(result.error().message()); - return false; - } - } - - void hideEvent(QHideEvent *) override - { - deleteLater(); - } - - Vault *m_vault; - Function m_function; -}; - -template -void showPasswordMountDialog(Vault *vault, Function &&function) +void showPasswordMountDialog(Vault *vault, const std::function &function) { - auto dialog = new PasswordMountDialog( - vault, std::forward(function)); - dialog->show(); + auto dialog = new MountDialog(vault, function); + dialog->open(); } //^ diff --git a/kded/ui/mountdialog.h b/kded/ui/mountdialog.h new file mode 100644 --- /dev/null +++ b/kded/ui/mountdialog.h @@ -0,0 +1,46 @@ +/* + * 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 . + */ +#ifndef MOUNTDIALOG_H +#define MOUNTDIALOG_H + +#include +#include + +#include "ui_mountdialog.h" + +namespace PlasmaVault { + class Vault; +} + +class MountDialog : public QDialog +{ +public: + MountDialog(PlasmaVault::Vault *vault, const std::function &function); + +protected: + void accept() override; + +private: + PlasmaVault::Vault *m_vault; + std::function m_function; + Ui_MountDialog m_ui; +}; + +#endif diff --git a/kded/ui/mountdialog.cpp b/kded/ui/mountdialog.cpp new file mode 100644 --- /dev/null +++ b/kded/ui/mountdialog.cpp @@ -0,0 +1,50 @@ +/* + * 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 + + +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.errorLabelStatic->setVisible(false); + m_ui.vaultName->setText(QString(" \"%1\"").arg(vault->name())); +} + +void MountDialog::accept() +{ + QString pwd = m_ui.password->password(); + auto future = m_vault->open({ { KEY_PASSWORD, pwd } }); + const auto result = AsynQt::await(future); + + if (result) { + m_function(); + QDialog::accept(); + } else { + m_ui.errorLabel->setText(result.error().message()); + m_ui.errorLabel->setVisible(true); + m_ui.errorLabelStatic->setVisible(true); + } +} diff --git a/kded/ui/mountdialog.ui b/kded/ui/mountdialog.ui new file mode 100644 --- /dev/null +++ b/kded/ui/mountdialog.ui @@ -0,0 +1,136 @@ + + + MountDialog + + + + 0 + 0 + 309 + 183 + + + + + + + Please type password to open vault: + + + + + + + + 0 + 0 + + + + + + + + + + Password: + + + password + + + + + + + QLineEdit::Password + + + + + + + + + + + Vault could not open: + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + false + + + + + + + + KPasswordLineEdit + QLineEdit +
kpasswordlineedit.h
+
+
+ + + + buttonBox + accepted() + MountDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + MountDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + +