| 1 | /*
|
|---|
| 2 | * changepwdlg.cpp - dialog for changing password
|
|---|
| 3 | * Copyright (C) 2001, 2002 Justin Karneges
|
|---|
| 4 | *
|
|---|
| 5 | * This program is free software; you can redistribute it and/or
|
|---|
| 6 | * modify it under the terms of the GNU General Public License
|
|---|
| 7 | * as published by the Free Software Foundation; either version 2
|
|---|
| 8 | * of the License, or (at your option) any later version.
|
|---|
| 9 | *
|
|---|
| 10 | * This program 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.
|
|---|
| 14 | *
|
|---|
| 15 | * You should have received a copy of the GNU General Public License
|
|---|
| 16 | * along with this library; if not, write to the Free Software
|
|---|
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 18 | *
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include"changepwdlg.h"
|
|---|
| 22 |
|
|---|
| 23 | #include<qlayout.h>
|
|---|
| 24 | #include<qlabel.h>
|
|---|
| 25 | #include<qpushbutton.h>
|
|---|
| 26 | #include<qlineedit.h>
|
|---|
| 27 | #include<qmessagebox.h>
|
|---|
| 28 | #include"profiles.h"
|
|---|
| 29 | #include"psiaccount.h"
|
|---|
| 30 | #include"busywidget.h"
|
|---|
| 31 | #include"im.h"
|
|---|
| 32 | #include"xmpp_tasks.h"
|
|---|
| 33 | #include"accountdlg.h"
|
|---|
| 34 | #include"iconwidget.h"
|
|---|
| 35 |
|
|---|
| 36 | using namespace XMPP;
|
|---|
| 37 |
|
|---|
| 38 | ChangePasswordDlg::ChangePasswordDlg(PsiAccount *_pa, QWidget *parent, const char *name)
|
|---|
| 39 | :ChangePasswordUI(parent, name, FALSE, WDestructiveClose)
|
|---|
| 40 | {
|
|---|
| 41 | pa = _pa;
|
|---|
| 42 | pa->dialogRegister(this);
|
|---|
| 43 |
|
|---|
| 44 | connect(pa, SIGNAL(disconnected()), SLOT(disc()));
|
|---|
| 45 |
|
|---|
| 46 | setCaption(CAP(caption()));
|
|---|
| 47 |
|
|---|
| 48 | connect(pb_close, SIGNAL(clicked()), SLOT(close()));
|
|---|
| 49 | connect(pb_apply, SIGNAL(clicked()), SLOT(apply()));
|
|---|
| 50 | }
|
|---|
| 51 |
|
|---|
| 52 | ChangePasswordDlg::~ChangePasswordDlg()
|
|---|
| 53 | {
|
|---|
| 54 | pa->dialogUnregister(this);
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /*void ChangePasswordDlg::closeEvent(QCloseEvent *e)
|
|---|
| 58 | {
|
|---|
| 59 | e->ignore();
|
|---|
| 60 | reject();
|
|---|
| 61 | }*/
|
|---|
| 62 |
|
|---|
| 63 | void ChangePasswordDlg::done(int r)
|
|---|
| 64 | {
|
|---|
| 65 | if(busy->isActive())
|
|---|
| 66 | return;
|
|---|
| 67 | QDialog::done(r);
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | void ChangePasswordDlg::apply()
|
|---|
| 71 | {
|
|---|
| 72 | // sanity check
|
|---|
| 73 | if(le_pwcur->text().isEmpty() || le_pwnew->text().isEmpty() || le_pwver->text().isEmpty()) {
|
|---|
| 74 | QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can proceed."));
|
|---|
| 75 | return;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | if(le_pwcur->text() != pa->userAccount().pass) {
|
|---|
| 79 | QMessageBox::information(this, tr("Error"), tr("You entered your old password incorrectly. Try again."));
|
|---|
| 80 | le_pwcur->setText("");
|
|---|
| 81 | le_pwcur->setFocus();
|
|---|
| 82 | return;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | if(le_pwnew->text() != le_pwver->text()) {
|
|---|
| 86 | QMessageBox::information(this, tr("Error"), tr("New password and confirmation do not match. Please enter them again."));
|
|---|
| 87 | le_pwnew->setText("");
|
|---|
| 88 | le_pwver->setText("");
|
|---|
| 89 | le_pwnew->setFocus();
|
|---|
| 90 | return;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | busy->start();
|
|---|
| 94 | blockWidgets();
|
|---|
| 95 |
|
|---|
| 96 | JT_Register *reg = new JT_Register(pa->client()->rootTask());
|
|---|
| 97 | connect(reg, SIGNAL(finished()), SLOT(finished()));
|
|---|
| 98 | Jid j = pa->userAccount().jid;
|
|---|
| 99 | reg->reg(j.user(), le_pwnew->text());
|
|---|
| 100 | reg->go(true);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | void ChangePasswordDlg::finished()
|
|---|
| 104 | {
|
|---|
| 105 | busy->stop();
|
|---|
| 106 |
|
|---|
| 107 | JT_Register *reg = (JT_Register *)sender();
|
|---|
| 108 | QString err = reg->statusString();
|
|---|
| 109 | int code = reg->statusCode();
|
|---|
| 110 | bool ok = reg->success();
|
|---|
| 111 | if(ok) {
|
|---|
| 112 | UserAccount acc = pa->userAccount();
|
|---|
| 113 | acc.pass = le_pwnew->text();
|
|---|
| 114 | pa->setUserAccount(acc);
|
|---|
| 115 | AccountModifyDlg *amd = (AccountModifyDlg *)pa->dialogFind("AccountModifyDlg");
|
|---|
| 116 | if(amd)
|
|---|
| 117 | amd->setPassword(acc.pass);
|
|---|
| 118 |
|
|---|
| 119 | QMessageBox::information(this, tr("Success"), tr("Successfully changed password."));
|
|---|
| 120 | close();
|
|---|
| 121 | }
|
|---|
| 122 | else {
|
|---|
| 123 | // ignore task disconnect error
|
|---|
| 124 | if(code == Task::ErrDisc)
|
|---|
| 125 | return;
|
|---|
| 126 |
|
|---|
| 127 | QMessageBox::critical(this, tr("Error"), QString(tr("There was an error when trying to set the password.\nReason: %1")).arg(err) );
|
|---|
| 128 | restoreWidgets();
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 |
|
|---|
| 132 | void ChangePasswordDlg::disc()
|
|---|
| 133 | {
|
|---|
| 134 | busy->stop();
|
|---|
| 135 | close();
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | void ChangePasswordDlg::blockWidgets()
|
|---|
| 139 | {
|
|---|
| 140 | lb_pwcur->setEnabled(false);
|
|---|
| 141 | lb_pwnew->setEnabled(false);
|
|---|
| 142 | lb_pwver->setEnabled(false);
|
|---|
| 143 | le_pwcur->setEnabled(false);
|
|---|
| 144 | le_pwnew->setEnabled(false);
|
|---|
| 145 | le_pwver->setEnabled(false);
|
|---|
| 146 | pb_close->setEnabled(false);
|
|---|
| 147 | pb_apply->setEnabled(false);
|
|---|
| 148 | }
|
|---|
| 149 |
|
|---|
| 150 | void ChangePasswordDlg::restoreWidgets()
|
|---|
| 151 | {
|
|---|
| 152 | lb_pwcur->setEnabled(true);
|
|---|
| 153 | lb_pwnew->setEnabled(true);
|
|---|
| 154 | lb_pwver->setEnabled(true);
|
|---|
| 155 | le_pwcur->setEnabled(true);
|
|---|
| 156 | le_pwnew->setEnabled(true);
|
|---|
| 157 | le_pwver->setEnabled(true);
|
|---|
| 158 | pb_close->setEnabled(true);
|
|---|
| 159 | pb_apply->setEnabled(true);
|
|---|
| 160 | }
|
|---|