2
* accountmanagedlg.cpp - dialogs for manipulating PsiAccounts
3
* Copyright (C) 2001, 2002 Justin Karneges
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.
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.
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
22
#include <QInputDialog>
23
#include <QMessageBox>
24
#include <QPushButton>
27
#include <q3listview.h>
28
#include <q3buttongroup.h>
30
#include "psiaccount.h"
32
#include "xmpp_tasks.h"
35
#include "miniclient.h"
36
#include "accountadddlg.h"
37
#include "accountmanagedlg.h"
38
#include "ui_accountremove.h"
39
#include "psicontactlist.h"
44
//----------------------------------------------------------------------------
46
//----------------------------------------------------------------------------
48
class AccountRemoveDlg : public QDialog, public Ui::AccountRemove
52
AccountRemoveDlg(ProxyManager *, const UserAccount &, QWidget *parent=0);
57
//void closeEvent(QCloseEvent *);
66
void client_handshaken();
68
void client_disconnected();
69
void unreg_finished();
78
class AccountRemoveDlg::Private
85
ProxyManager *proxyman;
88
AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent)
95
d->proxyman = proxyman;
97
setWindowTitle(CAP(caption()));
99
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
100
connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
102
d->bg = new QButtonGroup(0);
103
d->bg->addButton(rb_remove, 0);
104
d->bg->addButton(rb_removeAndUnreg, 1);
105
connect(d->bg, SIGNAL(buttonClicked(int)), SLOT(bg_clicked(int)));
106
rb_remove->setChecked(true);
109
pb_close->setFocus();
111
client = new MiniClient;
112
connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
113
connect(client, SIGNAL(error()), SLOT(client_error()));
114
connect(client, SIGNAL(disconnected()), SLOT(client_disconnected()));
117
AccountRemoveDlg::~AccountRemoveDlg()
125
/*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
131
void AccountRemoveDlg::done(int r)
133
if(busy->isActive()) {
134
int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the unregistration?"), tr("&Yes"), tr("&No"));
141
void AccountRemoveDlg::bg_clicked(int x)
144
lb_pass->setEnabled(false);
145
le_pass->setEnabled(false);
148
lb_pass->setEnabled(true);
149
le_pass->setEnabled(true);
154
void AccountRemoveDlg::remove()
156
bool unreg = rb_removeAndUnreg->isChecked();
159
if(!d->acc.pass.isEmpty() && le_pass->text() != d->acc.pass) {
160
QMessageBox::information(this, tr("Error"), tr("Password does not match account. Please try again."));
166
int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to remove <b>%1</b> ?").arg(d->acc.name), tr("&Yes"), tr("&No"));
176
gb_account->setEnabled(false);
177
pb_remove->setEnabled(false);
180
QString pass = le_pass->text();
181
j.setResource(d->acc.resource);
182
client->connectToServer(j, d->acc.legacy_ssl_probe, d->acc.ssl == UserAccount::SSL_Legacy, d->acc.ssl == UserAccount::SSL_Yes, d->acc.opt_host ? d->acc.host : QString(), d->acc.port, d->proxyman, d->acc.proxy_index, &pass);
185
void AccountRemoveDlg::client_handshaken()
187
// Workaround for servers that do not send a response to the remove request
188
client->setErrorOnDisconnect(false);
190
// try to unregister an account
191
JT_Register *reg = new JT_Register(client->client()->rootTask());
192
connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
197
void AccountRemoveDlg::client_error()
200
gb_account->setEnabled(true);
201
pb_remove->setEnabled(true);
204
void AccountRemoveDlg::unreg_finished()
206
JT_Register *reg = (JT_Register *)sender();
212
QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
216
else if(reg->statusCode() != Task::ErrDisc) {
217
gb_account->setEnabled(true);
218
pb_remove->setEnabled(true);
219
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error unregistering the account.\nReason: %1")).arg(reg->statusString()));
223
void AccountRemoveDlg::client_disconnected()
225
// Workaround for servers that do not send a response to the remove request
227
QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
231
//----------------------------------------------------------------------------
233
//----------------------------------------------------------------------------
234
class AccountManageItem : public Q3CheckListItem
237
AccountManageItem(Q3ListView *par, PsiAccount *_pa)
238
:Q3CheckListItem(par,"",CheckBox)
246
const UserAccount &acc = pa->userAccount();
247
setText(0, pa->name());
248
//setPixmap(0, IconsetFactory::icon("psi/account"));
250
setText(1, acc.opt_host && acc.host.length() ? acc.host : j.host());
251
setText(2, pa->isActive() ? AccountManageDlg::tr("Active") : AccountManageDlg::tr("Not active"));
252
setOn(pa->enabled());
255
void stateChange( bool s)
257
if (pa->enabled()!=s)
270
AccountManageDlg::AccountManageDlg(PsiCon *_psi)
276
psi->dialogRegister(this);
278
setWindowTitle(CAP(caption()));
281
connect(pb_add, SIGNAL(clicked()), SLOT(add()));
282
connect(pb_modify, SIGNAL(clicked()), SLOT(modify()));
283
connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
284
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
286
connect(lv_accs, SIGNAL(doubleClicked(Q3ListViewItem *)), SLOT(modify(Q3ListViewItem *)));
287
connect(lv_accs, SIGNAL(selectionChanged(Q3ListViewItem *)), SLOT(qlv_selectionChanged(Q3ListViewItem *)));
288
connect(psi, SIGNAL(accountAdded(PsiAccount *)), SLOT(accountAdded(PsiAccount *)));
289
connect(psi, SIGNAL(accountUpdated(PsiAccount *)), SLOT(accountUpdated(PsiAccount *)));
290
connect(psi, SIGNAL(accountRemoved(PsiAccount *)), SLOT(accountRemoved(PsiAccount *)));
292
lv_accs->setAllColumnsShowFocus(true);
293
lv_accs->setResizeMode(Q3ListView::LastColumn);
295
foreach(PsiAccount* pa, psi->contactList()->accounts())
296
new AccountManageItem(lv_accs, pa);
298
if(lv_accs->childCount() > 0)
299
lv_accs->setSelected(lv_accs->firstChild(), true);
301
qlv_selectionChanged(0);
304
AccountManageDlg::~AccountManageDlg()
306
psi->dialogUnregister(this);
309
void AccountManageDlg::qlv_selectionChanged(Q3ListViewItem *lvi)
311
AccountManageItem *i = (AccountManageItem *)lvi;
312
bool ok = i ? true: false;
314
pb_modify->setEnabled(ok);
315
pb_remove->setEnabled(ok);
318
void AccountManageDlg::add()
320
AccountAddDlg *w = new AccountAddDlg(psi, 0);
324
void AccountManageDlg::modify()
326
modify(lv_accs->currentItem());
329
void AccountManageDlg::modify(Q3ListViewItem *lvi)
331
AccountManageItem *i = (AccountManageItem *)lvi;
338
void AccountManageDlg::remove()
340
AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
344
if(i->pa->isActive()) {
345
QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
349
AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
351
if(n != QDialog::Accepted) {
356
psi->removeAccount(i->pa);
359
void AccountManageDlg::accountAdded(PsiAccount *pa)
361
new AccountManageItem(lv_accs, pa);
364
void AccountManageDlg::accountUpdated(PsiAccount *pa)
366
AccountManageItem *i;
367
Q3ListViewItemIterator it(lv_accs);
368
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
378
void AccountManageDlg::accountRemoved(PsiAccount *pa)
380
AccountManageItem *i;
381
Q3ListViewItemIterator it(lv_accs);
382
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
391
qlv_selectionChanged(lv_accs->currentItem());
394
#include "accountmanagedlg.moc"