From fda8f32fd7afc56abd720fa01e7dea42febfc6a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sun, 18 Dec 2011 15:04:59 +0100 Subject: [PATCH] Finalize PreferencesPanel --- src/view/PasswordDialog.cpp | 84 +++++++++++++++++++++++++++++++++++++ src/view/PasswordDialog.hpp | 45 ++++++++++++++++++++ 2 files changed, 129 insertions(+) create mode 100644 src/view/PasswordDialog.cpp create mode 100644 src/view/PasswordDialog.hpp diff --git a/src/view/PasswordDialog.cpp b/src/view/PasswordDialog.cpp new file mode 100644 index 0000000..7b483fe --- /dev/null +++ b/src/view/PasswordDialog.cpp @@ -0,0 +1,84 @@ +/* + Copyright 2010-2011 Grégory Soutadé + + This file is part of KissCount. + + KissCount 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 3 of the License, or + (at your option) any later version. + + KissCount 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 KissCount. If not, see . +*/ + +#include "PasswordDialog.hpp" +#include +#include + +PasswordDialog::PasswordDialog(KissCount* kiss, wxUI *parent) : QDialog(0, Qt::Dialog), _kiss(kiss), _wxUI(parent) +{ + QGridLayout *gridBagSizer; + + gridBagSizer = new QGridLayout(this); + + setWindowTitle(_("Change password")); + setModal(true); + + gridBagSizer->addWidget(new QLabel(_("Old password")), 0, 0); + _oldPassword = new QLineEdit(); + gridBagSizer->addWidget(_oldPassword, 0, 1); + + gridBagSizer->addWidget(new QLabel(_("New password")), 1, 0); + _newPassword = new QLineEdit(); + gridBagSizer->addWidget(_newPassword, 1, 1); + + gridBagSizer->addWidget(new QLabel(_("Confirm password")), 2, 0); + _confirmPassword = new QLineEdit(); + gridBagSizer->addWidget(_confirmPassword, 2, 1); + + _oldPassword->setEchoMode(QLineEdit::Password); + _newPassword->setEchoMode(QLineEdit::Password); + _confirmPassword->setEchoMode(QLineEdit::Password); + + QPushButton* ok = new QPushButton(_("OK")); + QPushButton* cancel = new QPushButton(_("Cancel")); + gridBagSizer->addWidget(ok, 4, 1); + gridBagSizer->addWidget(cancel, 4, 2); + + connect(ok, SIGNAL(clicked()), this, SLOT(OnOK())); + connect(cancel, SIGNAL(clicked()), this, SLOT(OnCancel())); +} + +void PasswordDialog::OnOK() +{ + User* user = _kiss->GetUser(); + + if (!_kiss->IsValidUser(user->_name, _oldPassword->text())) + { + QMessageBox::critical(0, _("Error"), _("Invalid old password")); + return; + } + + if (_newPassword->text() != _confirmPassword->text()) + { + QMessageBox::critical(0, _("Error"), _("Please retype new password")); + return; + } + + _kiss->ChangePassword(_newPassword->text()); + + QMessageBox::information(0, "KissCount", _("Password changed")); + + close(); +} + +void PasswordDialog::OnCancel() +{ + close(); +} diff --git a/src/view/PasswordDialog.hpp b/src/view/PasswordDialog.hpp new file mode 100644 index 0000000..286a854 --- /dev/null +++ b/src/view/PasswordDialog.hpp @@ -0,0 +1,45 @@ +/* + Copyright 2010-2011 Grégory Soutadé + + This file is part of KissCount. + + KissCount 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 3 of the License, or + (at your option) any later version. + + KissCount 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 KissCount. If not, see . +*/ + +#ifndef PASSWORDDIALOG_H +#define PASSWORDDIALOG_H + +#include +#include +#include + +#include "wxUI.hpp" + +class PasswordDialog : public QDialog +{ + Q_OBJECT; + +public: + PasswordDialog(KissCount* kiss, wxUI *parent); + +private slots: + void OnOK(); + void OnCancel(); + +private: + KissCount* _kiss; + wxUI* _wxUI; + QLineEdit* _oldPassword, *_newPassword, *_confirmPassword; +}; +#endif