2 * This file is part of Secret Notes.
3 * Copyright (C) 2010 Janusz Sobczak
5 * Secret Notes is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * Secret Notes is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with Secret Notes. If not, see <http://www.gnu.org/licenses/>.
18 #include <qmessagebox.h>
19 #include "passworddialog.h"
20 #include "ui_passworddialog.h"
21 #include <QPushButton>
24 PasswordDialog::PasswordDialog(QWidget *parent, const char *password) :
26 ui(new Ui::PasswordDialog),
27 oldPassword(password),
28 verifyOldPassword(true)
31 enableOKButton(false);
34 PasswordDialog::~PasswordDialog()
40 void PasswordDialog::changeEvent(QEvent *e)
42 QDialog::changeEvent(e);
44 case QEvent::LanguageChange:
45 ui->retranslateUi(this);
52 void PasswordDialog::hideOldPassword(bool hide)
54 ui->oldEdit->setVisible(!hide);
55 ui->oldLabel->setVisible(!hide);
56 verifyOldPassword = !hide;
59 QString PasswordDialog::getPassword()
61 return ui->newEdit->text();
64 void PasswordDialog::on_oldEdit_textChanged(QString text)
66 isOldPasswordCorrect = (text == oldPassword);
67 enableOKButton((!verifyOldPassword || isOldPasswordCorrect) &&
68 isNewPasswordCorrect);
71 void PasswordDialog::on_newEdit_textChanged(QString text)
73 isNewPasswordCorrect = (text.length() > 0 &&
74 text == ui->newAgainEdit->text());
75 enableOKButton((!verifyOldPassword || isOldPasswordCorrect) &&
76 isNewPasswordCorrect);
80 void PasswordDialog::on_newAgainEdit_textChanged(QString text)
82 isNewPasswordCorrect = (text.length() > 0 &&
83 text == ui->newEdit->text());
84 enableOKButton((!verifyOldPassword || isOldPasswordCorrect) &&
85 isNewPasswordCorrect);
88 void PasswordDialog::enableOKButton(bool ena)
90 ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ena);