Commit b80ee599 authored by Kees vd Broek's avatar Kees vd Broek Committed by Ivan Čukić

Fix PWD dialog

Summary:
Make password dialog have error-handling built in.

BUG: 385985
BUG: 385445

This will show the error directly in the dialog and refuse to close
until the mount was successful (or user presses cancel).

Test Plan: {F5518252}

Reviewers: #plasma, ivan

Subscribers: abetts, colomar, jensreuterberg, ngraham, cfeck, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D8787
parent 5f04a5f0
......@@ -27,6 +27,7 @@ set (
ui/passwordchooserwidget.cpp
ui/vaultcreationwizard.cpp
ui/vaultconfigurationwizard.cpp
ui/mountdialog.cpp
../common/vaultinfo.cpp
)
......@@ -43,6 +44,7 @@ ki18n_wrap_ui (
ui/passwordchooserwidget.ui
ui/vaultcreationwizard.ui
ui/vaultconfigurationwizard.ui
ui/mountdialog.ui
)
add_library (
......
......@@ -33,6 +33,9 @@
#include "ui/vaultcreationwizard.h"
#include "ui/vaultconfigurationwizard.h"
#include "ui/mountdialog.h"
#include <functional>
K_PLUGIN_FACTORY_WITH_JSON(PlasmaVaultServiceFactory,
"plasmavault.json",
......@@ -182,52 +185,10 @@ void PlasmaVaultService::onVaultMessageChanged(const QString &message)
}
template <typename Function>
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 <typename Function>
void showPasswordMountDialog(Vault *vault, Function &&function)
void showPasswordMountDialog(Vault *vault, const std::function<void()> &function)
{
auto dialog = new PasswordMountDialog<Function>(
vault, std::forward<Function>(function));
dialog->show();
auto dialog = new MountDialog(vault, function);
dialog->open();
}
//^
......
/*
* Copyright 2017 by Kees vd Broek <cryptodude@libertymail.net>
*
* 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 "mountdialog.h"
#include "engine/vault.h"
#include <QCloseEvent>
MountDialog::MountDialog(PlasmaVault::Vault *vault, const std::function<void()> &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);
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();
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);
}
}
/*
* Copyright 2017 by Kees vd Broek <cryptodude@libertymail.net>
*
* 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 MOUNTDIALOG_H
#define MOUNTDIALOG_H
#include <QDialog>
#include <functional>
#include "ui_mountdialog.h"
namespace PlasmaVault {
class Vault;
}
class MountDialog : public QDialog
{
public:
MountDialog(PlasmaVault::Vault *vault, const std::function<void()> &function);
protected:
void accept() override;
private:
PlasmaVault::Vault *m_vault;
std::function<void()> m_function;
Ui_MountDialog m_ui;
};
#endif
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MountDialog</class>
<widget class="QDialog" name="MountDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>488</width>
<height>198</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<property name="horizontalSpacing">
<number>16</number>
</property>
<item row="1" column="1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Please enter the password to open this vault:</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="vaultName">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="2" column="0">
<widget class="QLabel" name="pwdLabel">
<property name="text">
<string>Password:</string>
</property>
<property name="buddy">
<cstring>password</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="KPasswordLineEdit" name="password">
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="icon">
<property name="minimumSize">
<size>
<width>64</width>
<height>64</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="4" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="1">
<widget class="QLabel" name="errorLabel">
<property name="text">
<string/>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
<property name="centerButtons">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KPasswordLineEdit</class>
<extends>QWidget</extends>
<header>kpasswordlineedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>MountDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>MountDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
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