~ubuntu-branches/ubuntu/edgy/psi/edgy

« back to all changes in this revision

Viewing changes to src/accountdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
** accountdlg.cpp - dialogs for manipulating Jabber accounts
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 program; if not, write to the Free Software
17
 
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 
**
19
 
****************************************************************************/
 
1
/*
 
2
 * accountdlg.cpp - dialogs for manipulating PsiAccounts
 
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
20
 
21
21
#include"accountdlg.h"
22
 
#include"common.h"
23
22
 
24
23
#include<qpushbutton.h>
25
24
#include<qlistview.h>
27
26
#include<qcheckbox.h>
28
27
#include<qlabel.h>
29
28
#include<qlayout.h>
30
 
 
31
 
 
32
 
static AccountManageDlg *accountmanage_ptr = 0;
33
 
 
34
 
AccountManageDlg::AccountManageDlg(JabSessionManager *_jsm, QWidget *parent, const char *name)
35
 
:AccountManageUI(parent, name, FALSE, WDestructiveClose)
36
 
{
37
 
        setCaption(CAP(tr("Jabber Accounts")));
38
 
 
39
 
        accountmanage_ptr = this;
40
 
        jsm = _jsm;
 
29
#include<qgroupbox.h>
 
30
#include<qcombobox.h>
 
31
#include<qradiobutton.h>
 
32
#include<qbuttongroup.h>
 
33
#include<qtabwidget.h>
 
34
#include<qwhatsthis.h>
 
35
#include<qurl.h>
 
36
#include<qca.h>
 
37
#include"psicon.h"
 
38
#include"psiaccount.h"
 
39
#include"common.h"
 
40
#include"im.h"
 
41
#include"xmpp_tasks.h"
 
42
#include"proxy.h"
 
43
#include"sslcertdlg.h"
 
44
#include"busywidget.h"
 
45
#include"iconwidget.h"
 
46
#include"fancylabel.h"
 
47
#include"base64.h"
 
48
 
 
49
using namespace XMPP;
 
50
 
 
51
//----------------------------------------------------------------------------
 
52
// MiniClient
 
53
//----------------------------------------------------------------------------
 
54
static QCA::Cert readCertXml(const QDomElement &e)
 
55
{
 
56
        QCA::Cert cert;
 
57
        // there should be one child data tag
 
58
        QDomElement data = e.elementsByTagName("data").item(0).toElement();
 
59
        if(!data.isNull())
 
60
                cert.fromDER(Base64::stringToArray(data.text()));
 
61
        return cert;
 
62
}
 
63
 
 
64
static QPtrList<QCA::Cert> getRootCerts(const QStringList &stores)
 
65
{
 
66
        QPtrList<QCA::Cert> list;
 
67
 
 
68
        for(QStringList::ConstIterator dit = stores.begin(); dit != stores.end(); ++dit) {
 
69
                QDir dir(*dit);
 
70
                dir.setNameFilter("*.xml");
 
71
                QStringList entries = dir.entryList();
 
72
                for(QStringList::ConstIterator it = entries.begin(); it != entries.end(); ++it) {
 
73
                        QFile f(dir.filePath(*it));
 
74
                        if(!f.open(IO_ReadOnly))
 
75
                                continue;
 
76
                        QDomDocument doc;
 
77
                        bool ok = doc.setContent(&f);
 
78
                        f.close();
 
79
                        if(!ok)
 
80
                                continue;
 
81
 
 
82
                        QDomElement base = doc.documentElement();
 
83
                        if(base.tagName() != "store")
 
84
                                continue;
 
85
                        QDomNodeList cl = base.elementsByTagName("certificate");
 
86
 
 
87
                        int num = 0;
 
88
                        for(int n = 0; n < (int)cl.count(); ++n) {
 
89
                                QCA::Cert *cert = new QCA::Cert(readCertXml(cl.item(n).toElement()));
 
90
                                if(cert->isNull()) {
 
91
                                        delete cert;
 
92
                                        continue;
 
93
                                }
 
94
 
 
95
                                ++num;
 
96
                                list.append(cert);
 
97
                        }
 
98
                }
 
99
        }
 
100
 
 
101
        return list;
 
102
}
 
103
 
 
104
MiniClient::MiniClient(QObject *parent)
 
105
:QObject(parent)
 
106
{
 
107
        _client = new Client;
 
108
        conn = 0;
 
109
        tls = 0;
 
110
        tlsHandler = 0;
 
111
        stream = 0;
 
112
        certList.setAutoDelete(true);
 
113
}
 
114
 
 
115
MiniClient::~MiniClient()
 
116
{
 
117
        delete _client;
 
118
        reset();
 
119
}
 
120
 
 
121
void MiniClient::reset()
 
122
{
 
123
        delete stream;
 
124
        stream = 0;
 
125
 
 
126
        delete tls;
 
127
        tls = 0;
 
128
        tlsHandler = 0;
 
129
 
 
130
        delete conn;
 
131
        conn = 0;
 
132
 
 
133
        certList.clear();
 
134
}
 
135
 
 
136
void MiniClient::connectToServer(const Jid &jid, bool ssl, const QString &_host, int _port, ProxyManager *pm, int proxy, QString *_pass)
 
137
{
 
138
        j = jid;
 
139
 
 
140
        QString host;
 
141
        int port;
 
142
        if(!_host.isEmpty()) {
 
143
                host = _host;
 
144
                port = _port;
 
145
        }
 
146
        else {
 
147
                host = jid.host();
 
148
                if(ssl)
 
149
                        port = 5223;
 
150
                else
 
151
                        port = 5222;
 
152
        }
 
153
 
 
154
        AdvancedConnector::Proxy p;
 
155
        if(proxy > 0) {
 
156
                const ProxyItem &pi = pm->getItem(proxy-1);
 
157
                if(pi.type == "http") // HTTP Connect
 
158
                        p.setHttpConnect(pi.settings.host, pi.settings.port);
 
159
                else if(pi.type == "socks") // SOCKS
 
160
                        p.setSocks(pi.settings.host, pi.settings.port);
 
161
                else if(pi.type == "poll") { // HTTP Poll
 
162
                        QUrl u = pi.settings.url;
 
163
                        if(u.query().isEmpty()) {
 
164
                                QString v = host + ':' + QString::number(port);
 
165
                                QUrl::encode(v);
 
166
                                u.setQuery(QString("server=") + v);
 
167
                        }
 
168
                        p.setHttpPoll(pi.settings.host, pi.settings.port, u.toString());
 
169
                        p.setPollInterval(2);
 
170
                }
 
171
 
 
172
                if(pi.settings.useAuth)
 
173
                        p.setUserPass(pi.settings.user, pi.settings.pass);
 
174
        }
 
175
 
 
176
        conn = new AdvancedConnector;
 
177
        if(ssl) {
 
178
                QStringList certDirs;
 
179
                certDirs += g.pathBase + "/certs";
 
180
                certList = getRootCerts(certDirs);
 
181
 
 
182
                tls = new QCA::TLS;
 
183
                tls->setCertificateStore(certList);
 
184
                tlsHandler = new QCATLSHandler(tls);
 
185
                connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
 
186
        }
 
187
        conn->setProxy(p);
 
188
        conn->setOptHostPort(host, port);
 
189
        conn->setOptSSL(ssl);
 
190
 
 
191
        stream = new ClientStream(conn, tlsHandler);
 
192
        stream->setOldOnly(true);
 
193
        connect(stream, SIGNAL(connected()), SLOT(cs_connected()));
 
194
        connect(stream, SIGNAL(securityLayerActivated(int)), SLOT(cs_securityLayerActivated(int)));
 
195
        connect(stream, SIGNAL(needAuthParams(bool, bool, bool)), SLOT(cs_needAuthParams(bool, bool, bool)));
 
196
        connect(stream, SIGNAL(authenticated()), SLOT(cs_authenticated()));
 
197
        connect(stream, SIGNAL(connectionClosed()), SLOT(cs_connectionClosed()));
 
198
        connect(stream, SIGNAL(delayedCloseFinished()), SLOT(cs_delayedCloseFinished()));
 
199
        connect(stream, SIGNAL(warning(int)), SLOT(cs_warning(int)));
 
200
        connect(stream, SIGNAL(error(int)), SLOT(cs_error(int)));
 
201
 
 
202
        if(_pass) {
 
203
                pass = *_pass;
 
204
                _client->connectToServer(stream, j);
 
205
        }
 
206
        else
 
207
                _client->connectToServer(stream, j, false);
 
208
}
 
209
 
 
210
void MiniClient::close()
 
211
{
 
212
        _client->close();
 
213
        reset();
 
214
}
 
215
 
 
216
Client *MiniClient::client()
 
217
{
 
218
        return _client;
 
219
}
 
220
 
 
221
void MiniClient::tls_handshaken()
 
222
{
 
223
        QCA::Cert cert = tls->peerCertificate();
 
224
        int r = tls->certificateValidityResult();
 
225
        if(r != QCA::TLS::Valid) {
 
226
                QString str = PsiAccount::resultToString(r);
 
227
                while(1) {
 
228
                        int n = QMessageBox::warning(0,
 
229
                                tr("Server Authentication"),
 
230
                                tr("The %1 certificate failed the authenticity test.").arg(j.host()) + '\n' + tr("Reason: %1").arg(str),
 
231
                                tr("&Details..."),
 
232
                                tr("Co&ntinue"),
 
233
                                tr("&Cancel"), 0, 2);
 
234
                        if(n == 0) {
 
235
                                SSLCertDlg::showCert(cert, r);
 
236
                        }
 
237
                        else if(n == 1) {
 
238
                                tlsHandler->continueAfterHandshake();
 
239
                                break;
 
240
                        }
 
241
                        else if(n == 2) {
 
242
                                close();
 
243
                                error();
 
244
                                break;
 
245
                        }
 
246
                }
 
247
        }
 
248
        else
 
249
                tlsHandler->continueAfterHandshake();
 
250
}
 
251
 
 
252
void MiniClient::cs_connected()
 
253
{
 
254
}
 
255
 
 
256
void MiniClient::cs_securityLayerActivated(int)
 
257
{
 
258
}
 
259
 
 
260
void MiniClient::cs_needAuthParams(bool, bool, bool)
 
261
{
 
262
        stream->setPassword(pass);
 
263
        stream->continueAfterParams();
 
264
}
 
265
 
 
266
void MiniClient::cs_authenticated()
 
267
{
 
268
        _client->start(j.host(), j.user(), "", "");
 
269
        handshaken();
 
270
}
 
271
 
 
272
void MiniClient::cs_connectionClosed()
 
273
{
 
274
        cs_error(-1);
 
275
}
 
276
 
 
277
void MiniClient::cs_delayedCloseFinished()
 
278
{
 
279
}
 
280
 
 
281
void MiniClient::cs_warning(int)
 
282
{
 
283
        stream->continueAfterWarning();
 
284
}
 
285
 
 
286
void MiniClient::cs_error(int err)
 
287
{
 
288
        QString str;
 
289
        bool reconn;
 
290
 
 
291
        PsiAccount::getErrorInfo(err, conn, stream, tlsHandler, &str, &reconn);
 
292
        close();
 
293
 
 
294
        QMessageBox::critical(0, tr("Server Error"), tr("There was an error communicating with the Jabber server.\nDetails: %1").arg(str));
 
295
        error();
 
296
}
 
297
 
 
298
//----------------------------------------------------------------------------
 
299
// AccountManageDlg
 
300
//----------------------------------------------------------------------------
 
301
class AccountManageItem : public QCheckListItem
 
302
{
 
303
public:
 
304
        AccountManageItem(QListView *par, PsiAccount *_pa)
 
305
        :QCheckListItem(par,"",CheckBox)
 
306
        {
 
307
                pa = _pa;
 
308
                updateInfo();
 
309
        }
 
310
 
 
311
        void updateInfo()
 
312
        {
 
313
                const UserAccount &acc = pa->userAccount();
 
314
                setText(0, pa->name());
 
315
                setPixmap(0, IconsetFactory::icon("psi/account"));
 
316
                Jid j = acc.jid;
 
317
                setText(1, acc.opt_host ? acc.host : j.host());
 
318
                setText(2, pa->isActive() ? AccountManageDlg::tr("Active") : AccountManageDlg::tr("Not active"));
 
319
                setOn(pa->enabled());
 
320
        }
 
321
        
 
322
        void stateChange( bool s)
 
323
        {
 
324
 
 
325
                if(s || !pa->isActive() && !pa->eventQueue()->count()){
 
326
                        if(pa->enabled()!=s) pa->setEnabled(s);
 
327
                }else{
 
328
                        setOn(!s);
 
329
                        if(pa->isActive())
 
330
                                QMessageBox::information(listView(), AccountManageDlg::tr("Error"), AccountManageDlg::tr("Unable to disable the account, as it is currently active."));
 
331
                        else
 
332
                                QMessageBox::information(listView(), AccountManageDlg::tr("Error"), AccountManageDlg::tr("Unable to disable the account, as it has pending events."));
 
333
                }
 
334
        }
 
335
 
 
336
        int rtti() const
 
337
        {
 
338
                return 8109;
 
339
        }
 
340
 
 
341
        PsiAccount *pa;
 
342
};
 
343
 
 
344
AccountManageDlg::AccountManageDlg(PsiCon *_psi, const char *name)
 
345
:AccountManageUI(0, name, false, WDestructiveClose)
 
346
{
 
347
        psi = _psi;
 
348
        psi->dialogRegister(this);
 
349
 
 
350
        setCaption(CAP(caption()));
41
351
 
42
352
        // setup signals
 
353
        connect(pb_add, SIGNAL(clicked()), SLOT(add()));
43
354
        connect(pb_modify, SIGNAL(clicked()), SLOT(modify()));
44
 
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
 
355
        connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
 
356
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
357
 
45
358
        connect(lv_accs, SIGNAL(doubleClicked(QListViewItem *)), SLOT(modify(QListViewItem *)));
46
 
 
47
 
        connect(jsm, SIGNAL(sessionUpdate(JabSession *)), SLOT(sessionUpdate(JabSession *)));
48
 
 
49
 
        lv_accs->setAllColumnsShowFocus(TRUE);
50
 
 
51
 
        QPtrList<JabSession> list = jsm->getList();
52
 
        QPtrListIterator<JabSession> it(list);
53
 
        for(JabSession *s; (s = it.current()); ++it)
54
 
                new AccountViewItem(lv_accs, s);
55
 
 
56
 
        pb_add->setEnabled(FALSE);
57
 
        pb_remove->setEnabled(FALSE);
 
359
        connect(lv_accs, SIGNAL(selectionChanged(QListViewItem *)), SLOT(qlv_selectionChanged(QListViewItem *)));
 
360
        connect(psi, SIGNAL(accountAdded(PsiAccount *)), SLOT(accountAdded(PsiAccount *)));
 
361
        connect(psi, SIGNAL(accountUpdated(PsiAccount *)), SLOT(accountUpdated(PsiAccount *)));
 
362
        connect(psi, SIGNAL(accountRemoved(PsiAccount *)), SLOT(accountRemoved(PsiAccount *)));
 
363
 
 
364
        lv_accs->setAllColumnsShowFocus(true);
 
365
        lv_accs->setResizeMode(QListView::LastColumn);
 
366
 
 
367
        PsiAccountListIt it(psi->accountList());
 
368
        for(PsiAccount *pa; (pa = it.current()); ++it) {
 
369
                new AccountManageItem(lv_accs, pa);
 
370
        }
58
371
 
59
372
        if(lv_accs->childCount() > 0)
60
 
                lv_accs->setSelected(lv_accs->firstChild(), TRUE);
 
373
                lv_accs->setSelected(lv_accs->firstChild(), true);
 
374
        else
 
375
                qlv_selectionChanged(0);
61
376
}
62
377
 
63
378
AccountManageDlg::~AccountManageDlg()
64
379
{
65
 
        accountmanage_ptr = 0;
66
 
}
67
 
 
68
 
/* static */ AccountManageDlg *AccountManageDlg::find()
69
 
{
70
 
        return accountmanage_ptr;
 
380
        psi->dialogUnregister(this);
 
381
}
 
382
 
 
383
void AccountManageDlg::qlv_selectionChanged(QListViewItem *lvi)
 
384
{
 
385
        AccountManageItem *i = (AccountManageItem *)lvi;
 
386
        bool ok = i ? true: false;
 
387
 
 
388
        pb_modify->setEnabled(ok);
 
389
        pb_remove->setEnabled(ok);
 
390
}
 
391
 
 
392
void AccountManageDlg::add()
 
393
{
 
394
        AccountAddDlg *w = new AccountAddDlg(psi, 0);
 
395
        w->show();
71
396
}
72
397
 
73
398
void AccountManageDlg::modify()
74
399
{
75
 
        QListViewItem *lvi = lv_accs->currentItem();
76
 
        if(!lvi)
77
 
                return;
78
 
 
79
 
        modify(lvi);
 
400
        modify(lv_accs->currentItem());
80
401
}
81
402
 
82
403
void AccountManageDlg::modify(QListViewItem *lvi)
83
404
{
84
 
        signalModify(lvi->text(0));
85
 
}
86
 
 
87
 
void AccountManageDlg::updateEntry(JabSession *s)
88
 
{
89
 
        AccountViewItem *i;
 
405
        AccountManageItem *i = (AccountManageItem *)lvi;
 
406
        if(!i)
 
407
                return;
 
408
 
 
409
        psi->modifyAccount(i->pa);
 
410
}
 
411
 
 
412
void AccountManageDlg::remove()
 
413
{
 
414
        AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
 
415
        if(!i)
 
416
                return;
 
417
 
 
418
        if(i->pa->isActive()) {
 
419
                QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
 
420
                return;
 
421
        }
 
422
 
 
423
        AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
 
424
        int n = w->exec();
 
425
        if(n != QDialog::Accepted) {
 
426
                delete w;
 
427
                return;
 
428
        }
 
429
        delete w;
 
430
        psi->removeAccount(i->pa);
 
431
}
 
432
 
 
433
void AccountManageDlg::accountAdded(PsiAccount *pa)
 
434
{
 
435
        new AccountManageItem(lv_accs, pa);
 
436
}
 
437
 
 
438
void AccountManageDlg::accountUpdated(PsiAccount *pa)
 
439
{
 
440
        AccountManageItem *i;
90
441
        QListViewItemIterator it(lv_accs);
91
 
        for(; (i = (AccountViewItem *)it.current()) ; ++it) {
92
 
                if(i->s == s)
 
442
        for(; (i = (AccountManageItem *)it.current()) ; ++it) {
 
443
                if(i->pa == pa)
93
444
                        break;
94
445
        }
95
446
        if(!i)
98
449
        i->updateInfo();
99
450
}
100
451
 
101
 
void AccountManageDlg::sessionUpdate(JabSession *s)
102
 
{
103
 
        updateEntry(s);
104
 
}
105
 
 
106
 
 
107
 
AccountViewItem::AccountViewItem(QListView *par, JabSession *_s)
108
 
:QListViewItem(par)
109
 
{
110
 
        s = _s;
111
 
 
112
 
        updateInfo();
113
 
}
114
 
 
115
 
void AccountViewItem::updateInfo()
116
 
{
117
 
        setText(0, s->name());
118
 
        setPixmap(0, *pix_account);
119
 
        setText(1, s->acc()->host);
120
 
        setText(2, s->serv()->isActive() ? "Active" : "Not active");
121
 
}
122
 
 
123
 
 
124
 
AccountModifyDlg::AccountModifyDlg(JabSession *_s, bool _haveSSL, QWidget *parent, const char *name)
125
 
:AccountModifyUI(parent, name, FALSE, WDestructiveClose), UniqueWindow(TRUE, "AccountModifyDlg", this, _s->acc()->name)
126
 
{
127
 
        setCaption(tr("Account Properties"));
128
 
        setIcon(*pix_account);
129
 
 
130
 
        resize(width(), sizeHint().height());
131
 
 
132
 
        s = _s;
133
 
        haveSSL = _haveSSL;
134
 
        UserAccount &acc = *s->acc();
 
452
void AccountManageDlg::accountRemoved(PsiAccount *pa)
 
453
{
 
454
        AccountManageItem *i;
 
455
        QListViewItemIterator it(lv_accs);
 
456
        for(; (i = (AccountManageItem *)it.current()) ; ++it) {
 
457
                if(i->pa == pa)
 
458
                        break;
 
459
        }
 
460
        if(!i)
 
461
                return;
 
462
 
 
463
        delete i;
 
464
 
 
465
        qlv_selectionChanged(lv_accs->currentItem());
 
466
}
 
467
 
 
468
 
 
469
//----------------------------------------------------------------------------
 
470
// AccountAddDlg
 
471
//----------------------------------------------------------------------------
 
472
AccountAddDlg::AccountAddDlg(PsiCon *_psi, QWidget *parent, const char *name)
 
473
:AccountAddUI(parent, name, false, WDestructiveClose)
 
474
{
 
475
        psi = _psi;
 
476
        psi->dialogRegister(this);
 
477
 
 
478
        setCaption(CAP(caption()));
 
479
 
 
480
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
481
        connect(pb_add, SIGNAL(clicked()), SLOT(add()));
 
482
        connect(le_name, SIGNAL(textChanged(const QString &)), SLOT(setAddButton(const QString &)));
 
483
 
 
484
        QWhatsThis::add(ck_reg,
 
485
                tr("Check this option if you don't yet have a Jabber account "
 
486
                "and you want to register one.  Note that this will only work "
 
487
                "on servers that allow anonymous registration."));
 
488
 
 
489
        QString def = tr("Default");
 
490
        QString aname = def;
 
491
        int n = 0;
 
492
        while(1) {
 
493
                bool taken = false;
 
494
                PsiAccountListIt it(psi->accountList());
 
495
                for(PsiAccount *pa; (pa = it.current()); ++it) {
 
496
                        if(aname == pa->name()) {
 
497
                                taken = true;
 
498
                                break;
 
499
                        }
 
500
                }
 
501
 
 
502
                if(!taken)
 
503
                        break;
 
504
                aname = def + '_' + QString::number(++n);
 
505
        }
 
506
 
 
507
        le_name->setText(aname);
 
508
        le_name->setFocus();
 
509
}
 
510
 
 
511
AccountAddDlg::~AccountAddDlg()
 
512
{
 
513
        psi->dialogUnregister(this);
 
514
}
 
515
 
 
516
void AccountAddDlg::add()
 
517
{
 
518
        QString def = le_name->text();
 
519
        QString aname = def;
 
520
        int n = 0;
 
521
        while(1) {
 
522
                bool taken = false;
 
523
                PsiAccountListIt it(psi->accountList());
 
524
                for(PsiAccount *pa; (pa = it.current()); ++it) {
 
525
                        if(aname == pa->name()) {
 
526
                                taken = true;
 
527
                                break;
 
528
                        }
 
529
                }
 
530
 
 
531
                if(!taken)
 
532
                        break;
 
533
                aname = def + '_' + QString::number(++n);
 
534
        }
 
535
        le_name->setText( aname );
 
536
 
 
537
        if(ck_reg->isChecked()) {
 
538
                AccountRegDlg *w = new AccountRegDlg(psi->proxy(), this);
 
539
                int n = w->exec();
 
540
                if(n != QDialog::Accepted) {
 
541
                        delete w;
 
542
                        return;
 
543
                }
 
544
 
 
545
                Jid jid = w->jid;
 
546
                QString pass = w->pass;
 
547
                bool opt_host = w->opt_host;
 
548
                QString host = w->sp_host;
 
549
                int port = w->sp_port;
 
550
                bool ssl = w->ssl;
 
551
                int proxy = w->proxy;
 
552
 
 
553
                delete w;
 
554
 
 
555
                psi->createAccount(le_name->text(), jid, pass, opt_host, host, port, ssl, proxy);
 
556
        }
 
557
        else {
 
558
                psi->createAccount(le_name->text());
 
559
        }
 
560
 
 
561
        close();
 
562
}
 
563
 
 
564
void AccountAddDlg::setAddButton(const QString &s)
 
565
{
 
566
        pb_add->setEnabled(!s.isEmpty());
 
567
}
 
568
 
 
569
 
 
570
//----------------------------------------------------------------------------
 
571
// AccountModifyDlg
 
572
//----------------------------------------------------------------------------
 
573
AccountModifyDlg::AccountModifyDlg(PsiAccount *_pa, QWidget *parent, const char *name)
 
574
:AccountModifyUI(parent, name, false, WDestructiveClose)
 
575
{
 
576
        pa = _pa;
 
577
        connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
 
578
        pa->dialogRegister(this);
 
579
 
 
580
        setCaption(CAP(caption()));
 
581
        setIcon(IconsetFactory::icon("psi/account"));
 
582
 
 
583
        const UserAccount &acc = pa->userAccount();
135
584
 
136
585
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
137
586
        connect(ck_pass, SIGNAL(toggled(bool)), le_pass, SLOT(setEnabled(bool)));
 
587
        connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
 
588
        connect(pb_key, SIGNAL(clicked()), SLOT(chooseKey()));
 
589
        connect(pb_keyclear, SIGNAL(clicked()), SLOT(clearKey()));
138
590
        connect(pb_save, SIGNAL(clicked()), SLOT(save()));
139
 
        connect(pb_reg, SIGNAL(clicked()), SLOT(doRegister()));
140
 
 
141
 
        le_pass->setEnabled(FALSE);
142
 
 
143
 
        pb_unreg->setEnabled(FALSE);
144
 
 
145
 
        if(!acc.name.isEmpty()) {
146
 
                le_name->setText(acc.name);
147
 
                le_host->setText(acc.host);
148
 
                le_port->setText(QString::number(acc.port));
149
 
                if(acc.opt_ssl && haveSSL)
150
 
                        ck_ssl->setChecked(acc.opt_ssl);
151
 
                connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
152
 
 
153
 
                le_user->setText(acc.user);
154
 
                if(acc.opt_pass) {
155
 
                        ck_pass->setChecked(TRUE);
156
 
                        le_pass->setText(acc.pass);
 
591
 
 
592
        le_pass->setEnabled(false);
 
593
        le_host->setEnabled(false);
 
594
        le_port->setEnabled(false);
 
595
 
 
596
        gb_pgp->setEnabled(false);
 
597
        connect(ck_pp, SIGNAL(toggled(bool)), SLOT(optpp_toggled(bool)));
 
598
        le_pp->setEnabled(false);
 
599
 
 
600
        connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
 
601
        connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
 
602
 
 
603
        le_name->setText(acc.name);
 
604
        le_jid->setText(acc.jid);
 
605
 
 
606
        ck_ssl->setChecked(acc.opt_ssl);
 
607
        connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
 
608
 
 
609
        if(acc.opt_pass) {
 
610
                ck_pass->setChecked(true);
 
611
                le_pass->setText(acc.pass);
 
612
        }
 
613
 
 
614
        ck_host->setChecked(acc.opt_host);
 
615
        le_host->setText(acc.host);
 
616
        le_port->setText(QString::number(acc.port));
 
617
 
 
618
        le_resource->setText(acc.resource);
 
619
        le_priority->setText(QString::number(acc.priority));
 
620
 
 
621
        ck_plain->setChecked(acc.opt_plain);
 
622
        ck_auto->setChecked(acc.opt_auto);
 
623
        ck_reconn->setChecked(acc.opt_reconn);
 
624
        ck_log->setChecked(acc.opt_log);
 
625
        ck_keepAlive->setChecked(acc.opt_keepAlive);
 
626
        ck_ignoreSSLWarnings->setChecked(acc.opt_ignoreSSLWarnings);
 
627
        le_dtProxy->setText(acc.dtProxy.full());
 
628
 
 
629
        keyID = acc.pgpSecretKeyID;
 
630
        updateUserID();
 
631
        if(pa->psi()->pgp()) {
 
632
                gb_pgp->setEnabled(true);
 
633
                if(acc.opt_passphrase) {
 
634
                        ck_pp->setChecked(true);
 
635
                        le_pp->setText(acc.pgpPassphrase);
157
636
                }
158
 
                le_resource->setText(acc.resource);
159
 
                le_priority->setText(QString::number(acc.priority));
160
 
 
161
 
                ck_plain->setChecked(acc.opt_plain);
162
 
                ck_auto->setChecked(acc.opt_auto);
163
 
                ck_log->setChecked(acc.opt_log);
164
 
                ck_keepAlive->setChecked(acc.opt_keepAlive);
165
 
 
 
637
        }
 
638
 
 
639
        pc = pa->psi()->proxy()->createProxyChooser(gb_proxy);
 
640
        replaceWidget(lb_proxychooser, pc);
 
641
        pc->fixTabbing(le_pp, ck_ssl);
 
642
        pc->setCurrentItem(acc.proxy_index);
 
643
 
 
644
        if(le_name->text().isEmpty())
 
645
                le_name->setFocus();
 
646
        else if(le_jid->text().isEmpty())
 
647
                le_jid->setFocus();
 
648
        else
166
649
                pb_save->setFocus();
167
 
        }
168
 
        else
169
 
                le_name->setFocus();
 
650
 
 
651
        // QWhatsThis helpers
 
652
        QWhatsThis::add(ck_plain,
 
653
                tr("Normally, Psi logs in using the <i>digest</i> authentication "
 
654
                "method.  Check this box to force a plain text login "
 
655
                "to the Jabber server. Use this option only if you have "
 
656
                "problems connecting with the normal login procedure, as it "
 
657
                "makes your connection potentially vulnerable to "
 
658
                "attacks."));
 
659
        QWhatsThis::add(ck_auto,
 
660
                tr("Automatically login to this account on Psi startup.  Useful if "
 
661
                "you have Psi automatically launched when an Internet "
 
662
                "connection is detected."));
 
663
        QWhatsThis::add(ck_reconn,
 
664
                tr("Makes Psi try to reconnect if the connection was broken.  "
 
665
                "Useful, if you have an unstable connection and have to "
 
666
                "reconnect often."));
 
667
        QWhatsThis::add(ck_log,
 
668
                tr("Keep a log of message history.  Disable this "
 
669
                "option if you want to conserve disk space or if you need "
 
670
                "maximum security."));
 
671
        QWhatsThis::add(ck_keepAlive,
 
672
                tr("Sends so called \"Keep-alive\" packets periodically.  "
 
673
                "It is useful if your connection is set to be "
 
674
                "automatically disconnected after a certain period of "
 
675
                "inactivity (for example, by your ISP) and you want to keep it "
 
676
                "up all the time."));
 
677
        QWhatsThis::add(ck_ignoreSSLWarnings,
 
678
                tr("Ignores all the SSL warnings, for example, about "
 
679
                "incorrect certificates.  Useful if your server doesn't "
 
680
                "use a validated SSL certificate and you are "
 
681
                "annoyed with warnings."));
 
682
        QWhatsThis::add(ck_ssl,
 
683
                tr("Check this option to use an encrypted SSL connection to "
 
684
                "the Jabber server.  You may use this option if your "
 
685
                "server supports it and if you have the necessary QSSL "
 
686
                "plugin installed.  For more information, check the "
 
687
                "Psi homepage."));
 
688
        QWhatsThis::add(ck_pass,
 
689
                tr("Check this option if you want Psi to remember your Jabber "
 
690
                "account password. Don't use this feature if you want "
 
691
                "maximum security and don't want to be compromised even "
 
692
                "if someone would break in your system and steal your "
 
693
                "configuration files."));
 
694
        QWhatsThis::add(ck_host,
 
695
                tr("Use this option for manual configuration of your Jabber host "
 
696
                "if it is not the same as the host you are connecting to.  This option is mostly useful "
 
697
                "if you have some sort of proxy route on your "
 
698
                "local machine (i.e. you connect to localhost), but your "
 
699
                "account is registered on an external server."));
 
700
        QWhatsThis::add(le_resource,
 
701
                tr("You can have multiple clients connected to the Jabber server "
 
702
                "with your single account.  Each login is distinguished by a \"resource\" "
 
703
                "name, which you can specify in this field."));
 
704
        QWhatsThis::add(le_priority,
 
705
                tr("<p>You can have multiple clients connected to the Jabber "
 
706
                "server with your single account.  In such a situation, "
 
707
                "the client with the highest priority (that is specified in "
 
708
                "this field) will be the one that will receive "
 
709
                "all incoming events.</p>"
 
710
                "<p>For example, if you have a permanent connection "
 
711
                "to the Internet at your work location, and have a dial-up at home, "
 
712
                "you can have your Jabber client permanently running at work "
 
713
                "with a low priority, and you can still use the same account "
 
714
                "from home, using a client with higher priority to "
 
715
                "temporary \"disable\" the lower priority client at work.</p>"));
 
716
 
 
717
        resize(minimumSize());
170
718
}
171
719
 
172
720
AccountModifyDlg::~AccountModifyDlg()
173
721
{
174
 
}
175
 
 
176
 
/*static*/ AccountModifyDlg * AccountModifyDlg::find(const QString &accname)
177
 
{
178
 
        return (AccountModifyDlg *)UniqueWindowBank::find("AccountModifyDlg", accname.lower());
 
722
        pa->dialogUnregister(this);
 
723
}
 
724
 
 
725
void AccountModifyDlg::updateUserID()
 
726
{
 
727
        if(keyID.isEmpty()) {
 
728
                setKeyID(false);
 
729
        }
 
730
        else {
 
731
                QString userID = QString::null;
 
732
                if(pa->psi()->pgp()) {
 
733
                        OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
 
734
                        for(OpenPGP::KeyList::ConstIterator it = list.begin(); it != list.end(); ++it) {
 
735
                                const OpenPGP::Key &k = *it;
 
736
                                if(k.keyID() == keyID) {
 
737
                                        userID = k.userID();
 
738
                                        break;
 
739
                                }
 
740
                        }
 
741
                }
 
742
                if(userID.isNull())
 
743
                        setKeyID(true, tr("Unknown Key: %1").arg(keyID.left(8)));
 
744
                else
 
745
                        setKeyID(true, userID);
 
746
        }
 
747
}
 
748
 
 
749
void AccountModifyDlg::setKeyID(bool b, const QString &s)
 
750
{
 
751
        if(b) {
 
752
                lb_keyname->setText(s);
 
753
                lb_keyname->setMinimumWidth(100);
 
754
                lb_keyicon->setEnabled(true);
 
755
                lb_keyname->setEnabled(true);
 
756
                pb_keyclear->setEnabled(true);
 
757
                ck_pp->setEnabled(true);
 
758
        }
 
759
        else {
 
760
                lb_keyname->setText(tr("No Key Selected"));
 
761
                lb_keyicon->setEnabled(false);
 
762
                lb_keyname->setEnabled(false);
 
763
                pb_keyclear->setEnabled(false);
 
764
                ck_pp->setChecked(false);
 
765
                ck_pp->setEnabled(false);
 
766
        }
 
767
}
 
768
 
 
769
void AccountModifyDlg::pgpToggled(bool b)
 
770
{
 
771
        if(b) {
 
772
                gb_pgp->setEnabled(true);
 
773
        }
 
774
        else {
 
775
                gb_pgp->setEnabled(false);
 
776
                ck_pp->setChecked(false);
 
777
        }
 
778
        updateUserID();
 
779
}
 
780
 
 
781
void AccountModifyDlg::optpp_toggled(bool b)
 
782
{
 
783
        if(b)
 
784
                le_pp->setEnabled(true);
 
785
        else {
 
786
                le_pp->setEnabled(false);
 
787
                le_pp->setText("");
 
788
        }
 
789
}
 
790
 
 
791
void AccountModifyDlg::setPassword(const QString &pw)
 
792
{
 
793
        le_pass->setText(pw);
179
794
}
180
795
 
181
796
void AccountModifyDlg::sslToggled(bool on)
182
797
{
183
 
        if(on && !haveSSL) {
184
 
                QMessageBox::information(this, tr("OpenSSL error"), QString("<qt>") + tr("Sorry, but you must have <b>OpenSSL v0.9.6b</b> or compatible installed to use this feature.") + "</qt>");
185
 
                ck_ssl->setChecked(FALSE);
 
798
        if(on && !QCA::isSupported(QCA::CAP_TLS)) {
 
799
                QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS.  Plugin not found."));
 
800
                ck_ssl->setChecked(false);
186
801
                return;
187
802
        }
188
803
 
189
804
        le_port->setText(on ? "5223": "5222");
190
805
}
191
806
 
 
807
void AccountModifyDlg::hostToggled(bool on)
 
808
{
 
809
        le_host->setEnabled(on);
 
810
        le_port->setEnabled(on);
 
811
}
 
812
 
 
813
void AccountModifyDlg::chooseKey()
 
814
{
 
815
        OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
 
816
        PGPKeyDlg *w = new PGPKeyDlg(list, keyID, this);
 
817
        w->setCaption(tr("Secret Key"));
 
818
        int r = w->exec();
 
819
        QString key;
 
820
        if(r == QDialog::Accepted)
 
821
                key = w->keyID();
 
822
        delete w;
 
823
 
 
824
        if(!key.isEmpty()) {
 
825
                keyID = key;
 
826
                updateUserID();
 
827
                ck_pp->setChecked(false);
 
828
        }
 
829
}
 
830
 
 
831
void AccountModifyDlg::clearKey()
 
832
{
 
833
        setKeyID(false);
 
834
        keyID = "";
 
835
}
 
836
 
 
837
void AccountModifyDlg::detailsVCard()
 
838
{
 
839
        pa->changeVCard();
 
840
}
 
841
 
 
842
void AccountModifyDlg::detailsChangePW()
 
843
{
 
844
        pa->changePW();
 
845
}
 
846
 
192
847
void AccountModifyDlg::save()
193
848
{
194
 
        if(s->serv()->isActive()) {
195
 
                QMessageBox::information(this, tr("Error"), tr("Please disconnect from this account before trying to modify it."));
196
 
                return;
197
 
        }
198
 
 
199
 
        UserAccount &acc = *s->acc();
200
 
 
201
 
        QString before = acc.name.lower();
202
 
        QString after = le_name->text().lower();
203
 
        if(after.length() == 0) {
 
849
        UserAccount acc = pa->userAccount();
 
850
 
 
851
        if(le_name->text().isEmpty()) {
204
852
                QMessageBox::information(this, tr("Error"), tr("You must specify a name for the account before you may save it."));
205
853
                return;
206
854
        }
207
 
        if(before != after) {
208
 
                JabSessionManager *jsm = (JabSessionManager *)s->parent();
209
 
                if(jsm->find(after)) {
210
 
                        QMessageBox::information(this, tr("Error"), tr("There is already an account with this name.  Please select a different name."));
211
 
                        return;
212
 
                }
213
 
        }
214
 
 
215
 
        bool newUser = FALSE;
216
 
        if(acc.user != le_user->text() || acc.host != le_host->text() || acc.port != le_port->text().toInt()) {
217
 
                newUser = TRUE;
218
 
        }
 
855
 
 
856
        Jid newJid( le_jid->text() );
 
857
        if ( newJid.user().isEmpty() || newJid.host().isEmpty() ) {
 
858
                QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
 
859
                return;
 
860
        }
 
861
 
 
862
        // do not allow duplicate account names
 
863
        QString def = le_name->text();
 
864
        QString aname = def;
 
865
        int n = 0;
 
866
        {
 
867
                PsiAccountListIt it(pa->psi()->accountList());
 
868
                for(PsiAccount *pa; (pa = it.current()); ++it)
 
869
                        if(aname == pa->name())
 
870
                                n++;
 
871
        }
 
872
 
 
873
        if ( aname == acc.name )
 
874
                n--;
 
875
 
 
876
        if ( n )
 
877
                aname = def + '_' + QString::number(++n);
 
878
        le_name->setText( aname );
219
879
 
220
880
        acc.name = le_name->text();
221
 
        acc.host = le_host->text();
222
 
        acc.port = le_port->text().toInt();
223
 
        acc.opt_ssl = ck_ssl->isChecked();
224
 
        acc.user = le_user->text();
 
881
        acc.jid = le_jid->text();
225
882
        acc.opt_pass = ck_pass->isChecked();
226
883
        if(acc.opt_pass)
227
884
                acc.pass = le_pass->text();
228
885
        else
229
886
                acc.pass = "";
 
887
 
 
888
        acc.opt_host = ck_host->isChecked();
 
889
        acc.host = le_host->text();
 
890
        acc.port = le_port->text().toInt();
 
891
 
230
892
        acc.resource = le_resource->text();
231
893
        acc.priority = le_priority->text().toInt();
232
894
 
 
895
        acc.opt_ssl = ck_ssl->isChecked();
233
896
        acc.opt_plain = ck_plain->isChecked();
234
897
        acc.opt_auto = ck_auto->isChecked();
 
898
        acc.opt_reconn = ck_reconn->isChecked();
235
899
        acc.opt_log = ck_log->isChecked();
236
900
        acc.opt_keepAlive = ck_keepAlive->isChecked();
237
 
 
238
 
        s->update(newUser);
 
901
        acc.opt_ignoreSSLWarnings = ck_ignoreSSLWarnings->isChecked();
 
902
        acc.dtProxy = le_dtProxy->text();
 
903
 
 
904
        acc.pgpSecretKeyID = keyID;
 
905
        acc.opt_passphrase = ck_pp->isChecked();
 
906
        if(acc.opt_passphrase)
 
907
                acc.pgpPassphrase = le_pp->text();
 
908
        else
 
909
                acc.pgpPassphrase = "";
 
910
 
 
911
        acc.proxy_index = pc->currentItem();
 
912
 
 
913
        if(pa->isActive()) {
 
914
                QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
 
915
        }
 
916
 
 
917
        pa->setUserAccount(acc);
239
918
 
240
919
        accept();
241
920
}
242
921
 
243
 
void AccountModifyDlg::doRegister()
244
 
{
 
922
 
 
923
//----------------------------------------------------------------------------
 
924
// AccountRegDlg
 
925
//----------------------------------------------------------------------------
 
926
AccountRegDlg::AccountRegDlg(ProxyManager *_proxyman, QWidget *parent, const char *name)
 
927
:AccountRegUI(parent, name, false)
 
928
{
 
929
        setCaption(CAP(caption()));
 
930
 
 
931
        le_host->setEnabled(false);
 
932
        le_port->setEnabled(false);
 
933
 
 
934
        connect(pb_reg, SIGNAL(clicked()), SLOT(reg()));
 
935
        connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
 
936
        connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
 
937
 
 
938
        proxyman = _proxyman;
 
939
        pc = proxyman->createProxyChooser(gb_proxy);
 
940
        replaceWidget(lb_proxychooser, pc);
 
941
        pc->fixTabbing(le_confirm, ck_ssl);
 
942
        pc->setCurrentItem(0);
 
943
 
 
944
        le_port->setText("5222");
 
945
        le_host->setFocus();
 
946
 
 
947
        client = new MiniClient;
 
948
        connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
 
949
        connect(client, SIGNAL(error()), SLOT(client_error()));
 
950
}
 
951
 
 
952
AccountRegDlg::~AccountRegDlg()
 
953
{
 
954
        delete client;
 
955
}
 
956
 
 
957
/*void AccountRegDlg::closeEvent(QCloseEvent *e)
 
958
{
 
959
        e->ignore();
 
960
        reject();
 
961
}*/
 
962
 
 
963
void AccountRegDlg::done(int r)
 
964
{
 
965
        if(busy->isActive()) {
 
966
                int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the registration?"), tr("&Yes"), tr("&No"));
 
967
                if(n != 0)
 
968
                        return;
 
969
        }
 
970
        QDialog::done(r);
 
971
}
 
972
 
 
973
void AccountRegDlg::sslToggled(bool on)
 
974
{
 
975
        if(on && !QCA::isSupported(QCA::CAP_TLS)) {
 
976
                QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS.  Plugin not found."));
 
977
                ck_ssl->setChecked(false);
 
978
                return;
 
979
        }
 
980
 
 
981
        le_port->setText(on ? "5223": "5222");
 
982
}
 
983
 
 
984
void AccountRegDlg::hostToggled(bool on)
 
985
{
 
986
        le_host->setEnabled(on);
 
987
        le_port->setEnabled(on);
 
988
}
 
989
 
 
990
void AccountRegDlg::reg()
 
991
{
 
992
        // sanity check
 
993
        Jid j(le_jid->text());
 
994
        if ( j.user().isEmpty() || j.host().isEmpty() ) {
 
995
                QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
 
996
                return;
 
997
        }
 
998
 
245
999
        if(le_pass->text().isEmpty()) {
246
 
                QMessageBox::warning(this, tr("Error"), tr("You must specify a password for the new account."));
247
 
                return;
248
 
        }
249
 
 
250
 
        int n = QMessageBox::information(this, tr("Warning"),tr(
251
 
                "You have elected to create a new account on the specified server.\n"
252
 
                "Please note that this may not work on all servers, which means you may\n"
253
 
                "have to sign up with the host some other way instead (like through the web).\n"
254
 
                "\n"
255
 
                "Think about it like this:  if you were running a mail server, would you\n"
256
 
                "allow anonymous users to sign up for accounts on your system?  Probably not.\n"
257
 
                "For now though (Spring 2002), most hosts (like jabber.com and jabber.org) allow\n"
258
 
                "anonymous signups.  Check jabberview.com for a nice list of free hosts.\n"
259
 
                "\n"
260
 
                "Click on \"Yes\" to attempt to register an account.\n"),
261
 
                tr("&Yes"), tr("&No"));
262
 
 
 
1000
                QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can register."));
 
1001
                return;
 
1002
        }
 
1003
 
 
1004
        if(le_pass->text() != le_confirm->text()) {
 
1005
                QMessageBox::information(this, tr("Error"), tr("Password and confirmation do not match.  Please enter them again."));
 
1006
                le_pass->setText("");
 
1007
                le_confirm->setText("");
 
1008
                le_pass->setFocus();
 
1009
                return;
 
1010
        }
 
1011
 
 
1012
        busy->start();
 
1013
        block();
 
1014
 
 
1015
        jid = j;
 
1016
        ssl = ck_ssl->isChecked();
 
1017
        pass = le_pass->text();
 
1018
        opt_host = ck_host->isChecked();
 
1019
        sp_host = le_host->text();
 
1020
        sp_port = le_port->text().toInt();
 
1021
 
 
1022
        client->connectToServer(jid, ssl, opt_host ? sp_host : QString(), sp_port, proxyman, pc->currentItem(), 0);
 
1023
}
 
1024
 
 
1025
void AccountRegDlg::client_handshaken()
 
1026
{
 
1027
        // try to register an account
 
1028
        JT_Register *reg = new JT_Register(client->client()->rootTask());
 
1029
        connect(reg, SIGNAL(finished()), SLOT(reg_finished()));
 
1030
        reg->reg(jid.user(), pass);
 
1031
        reg->go(true);
 
1032
}
 
1033
 
 
1034
void AccountRegDlg::client_error()
 
1035
{
 
1036
        busy->stop();
 
1037
        unblock();
 
1038
}
 
1039
 
 
1040
void AccountRegDlg::reg_finished()
 
1041
{
 
1042
        JT_Register *reg = (JT_Register *)sender();
 
1043
 
 
1044
        client->close();
 
1045
        busy->stop();
 
1046
 
 
1047
        if(reg->success()) {
 
1048
                QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
 
1049
                proxy = pc->currentItem();
 
1050
                accept();
 
1051
                return;
 
1052
        }
 
1053
        else if(reg->statusCode() != Task::ErrDisc) {
 
1054
                unblock();
 
1055
                QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(reg->statusString()));
 
1056
        }
 
1057
}
 
1058
 
 
1059
void AccountRegDlg::block()
 
1060
{
 
1061
        gb_account->setEnabled(false);
 
1062
        gb_proxy->setEnabled(false);
 
1063
        gb_advanced->setEnabled(false);
 
1064
        pb_reg->setEnabled(false);
 
1065
}
 
1066
 
 
1067
void AccountRegDlg::unblock()
 
1068
{
 
1069
        gb_account->setEnabled(true);
 
1070
        gb_proxy->setEnabled(true);
 
1071
        gb_advanced->setEnabled(true);
 
1072
        pb_reg->setEnabled(true);
 
1073
        le_jid->setFocus();
 
1074
}
 
1075
 
 
1076
 
 
1077
//----------------------------------------------------------------------------
 
1078
// AccountRemoveDlg
 
1079
//----------------------------------------------------------------------------
 
1080
class AccountRemoveDlg::Private
 
1081
{
 
1082
public:
 
1083
        Private() {}
 
1084
 
 
1085
        UserAccount acc;
 
1086
        QButtonGroup *bg;
 
1087
        ProxyManager *proxyman;
 
1088
};
 
1089
 
 
1090
AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent, const char *name)
 
1091
:AccountRemoveUI(parent, name, false)
 
1092
{
 
1093
        d = new Private;
 
1094
        d->acc = acc;
 
1095
        d->proxyman = proxyman;
 
1096
 
 
1097
        setCaption(CAP(caption()));
 
1098
 
 
1099
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
1100
        connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
 
1101
 
 
1102
        d->bg = new QButtonGroup(0);
 
1103
        d->bg->insert(rb_remove, 0);
 
1104
        d->bg->insert(rb_removeAndUnreg, 1);
 
1105
        connect(d->bg, SIGNAL(clicked(int)), SLOT(bg_clicked(int)));
 
1106
        d->bg->setButton(0);
 
1107
        bg_clicked(0);
 
1108
 
 
1109
        pb_close->setFocus();
 
1110
 
 
1111
        client = new MiniClient;
 
1112
        connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
 
1113
        connect(client, SIGNAL(error()), SLOT(client_error()));
 
1114
}
 
1115
 
 
1116
AccountRemoveDlg::~AccountRemoveDlg()
 
1117
{
 
1118
        delete client;
 
1119
 
 
1120
        delete d->bg;
 
1121
        delete d;
 
1122
}
 
1123
 
 
1124
/*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
 
1125
{
 
1126
        e->ignore();
 
1127
        reject();
 
1128
}*/
 
1129
 
 
1130
void AccountRemoveDlg::done(int r)
 
1131
{
 
1132
        if(busy->isActive()) {
 
1133
                int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the unregistration?"), tr("&Yes"), tr("&No"));
 
1134
                if(n != 0)
 
1135
                        return;
 
1136
        }
 
1137
        QDialog::done(r);
 
1138
}
 
1139
 
 
1140
void AccountRemoveDlg::bg_clicked(int x)
 
1141
{
 
1142
        if(x == 0) {
 
1143
                lb_pass->setEnabled(false);
 
1144
                le_pass->setEnabled(false);
 
1145
        }
 
1146
        else if(x == 1) {
 
1147
                lb_pass->setEnabled(true);
 
1148
                le_pass->setEnabled(true);
 
1149
                le_pass->setFocus();
 
1150
        }
 
1151
}
 
1152
 
 
1153
void AccountRemoveDlg::remove()
 
1154
{
 
1155
        bool unreg = rb_removeAndUnreg->isChecked();
 
1156
 
 
1157
        if(unreg) {
 
1158
                if(le_pass->text() != d->acc.pass) {
 
1159
                        QMessageBox::information(this, tr("Error"), tr("Password does not match account.  Please try again."));
 
1160
                        le_pass->setFocus();
 
1161
                        return;
 
1162
                }
 
1163
        }
 
1164
 
 
1165
        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"));
263
1166
        if(n != 0)
264
1167
                return;
265
1168
 
266
 
        // get the form opts that we need
267
 
        QString host = le_host->text();
268
 
        int port = le_port->text().toInt();
269
 
        bool opt_ssl = ck_ssl->isChecked();
270
 
        QString user = le_user->text();
271
 
        QString pass = le_pass->text();
272
 
 
273
 
        // we should probably verify they are ok
274
 
 
275
 
        // perform a registration
276
 
        AccountRegisterDlg::reg(this, host, port, opt_ssl, user, pass);
277
 
}
278
 
 
279
 
 
280
 
AccountRegisterDlg::AccountRegisterDlg(QWidget *par, const char *name)
281
 
:QDialog(par, name, TRUE)
282
 
{
283
 
        setCaption(tr("Account Registration"));
284
 
 
285
 
        QVBoxLayout *vb = new QVBoxLayout(this, 4);
286
 
        QHBoxLayout *hb = new QHBoxLayout(vb);
287
 
        QLabel *l = new QLabel(tr("Registering account..."), this);
288
 
        hb->addWidget(l);
289
 
        busy = new BusyWidget(this);
290
 
        hb->addWidget(busy);
291
 
        QPushButton *pb_cancel = new QPushButton(tr("&Cancel"), this);
292
 
        hb->addWidget(pb_cancel);
293
 
        connect(pb_cancel, SIGNAL(clicked()), SLOT(cancel()));
294
 
        pb_cancel->setFocus();
295
 
 
296
 
        jab = new Jabber;
297
 
        connect(jab, SIGNAL(accRegisterFinished(bool, const QString &)), SLOT(accRegisterFinished(bool, const QString &)));
298
 
        connect(jab, SIGNAL(error(JabError *)), SLOT(jab_error(JabError *)));
299
 
}
300
 
 
301
 
AccountRegisterDlg::~AccountRegisterDlg()
302
 
{
303
 
        delete jab;
304
 
}
305
 
 
306
 
void AccountRegisterDlg::closeEvent(QCloseEvent *e)
307
 
{
308
 
        stop();
309
 
 
310
 
        QDialog::closeEvent(e);
311
 
}
312
 
 
313
 
void AccountRegisterDlg::start(const QString &host, int port, bool opt_ssl, const QString &user, const QString &pass)
314
 
{
 
1169
        if(!unreg) {
 
1170
                accept();
 
1171
                return;
 
1172
        }
 
1173
 
315
1174
        busy->start();
316
 
 
317
 
        jab->setSSLEnabled(opt_ssl);
318
 
        jab->setHost(host, port);
319
 
        jab->setAccount(user, pass, "");
320
 
        jab->accRegister();
321
 
}
322
 
 
323
 
void AccountRegisterDlg::stop()
324
 
{
325
 
        jab->disc();
326
 
}
327
 
 
328
 
void AccountRegisterDlg::cancel()
329
 
{
330
 
        stop();
331
 
        reject();
332
 
}
333
 
 
334
 
bool AccountRegisterDlg::reg(QWidget *par, const QString &host, int port, bool opt_ssl, const QString &user, const QString &pass)
335
 
{
336
 
        AccountRegisterDlg *w = new AccountRegisterDlg(par);
337
 
        w->start(host, port, opt_ssl, user, pass);
338
 
        w->exec();
339
 
        delete w;
340
 
 
341
 
        return TRUE;
342
 
}
343
 
 
344
 
void AccountRegisterDlg::accRegisterFinished(bool ok, const QString &errMsg)
345
 
{
346
 
        jab->disc();
347
 
        busy->stop();
348
 
 
349
 
        if(ok)
350
 
                QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
351
 
        else
352
 
                QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(errMsg));
353
 
 
354
 
        accept();
355
 
}
356
 
 
357
 
void AccountRegisterDlg::jab_error(JabError *err)
358
 
{
359
 
        jab->disc();
360
 
        busy->stop();
361
 
 
362
 
        QMessageBox::critical(this, tr("Error"), QString(tr("There was an error communicating with the Jabber server.\nReason: %1")).arg(err->msg));
363
 
 
364
 
        accept();
 
1175
        gb_account->setEnabled(false);
 
1176
        pb_remove->setEnabled(false);
 
1177
 
 
1178
        Jid j = d->acc.jid;
 
1179
        j.setResource(d->acc.resource);
 
1180
        client->connectToServer(j, d->acc.opt_ssl, d->acc.opt_host ? d->acc.host : QString(), d->acc.port, d->proxyman, d->acc.proxy_index, &d->acc.pass);
 
1181
}
 
1182
 
 
1183
void AccountRemoveDlg::client_handshaken()
 
1184
{
 
1185
        // try to unregister an account
 
1186
        JT_Register *reg = new JT_Register(client->client()->rootTask());
 
1187
        connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
 
1188
        reg->unreg();
 
1189
        reg->go(true);
 
1190
}
 
1191
 
 
1192
void AccountRemoveDlg::client_error()
 
1193
{
 
1194
        busy->stop();
 
1195
        gb_account->setEnabled(true);
 
1196
        pb_remove->setEnabled(true);
 
1197
}
 
1198
 
 
1199
void AccountRemoveDlg::unreg_finished()
 
1200
{
 
1201
        JT_Register *reg = (JT_Register *)sender();
 
1202
 
 
1203
        client->close();
 
1204
        busy->stop();
 
1205
 
 
1206
        if(reg->success()) {
 
1207
                QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
 
1208
                accept();
 
1209
                return;
 
1210
        }
 
1211
        else if(reg->statusCode() != Task::ErrDisc) {
 
1212
                gb_account->setEnabled(true);
 
1213
                pb_remove->setEnabled(true);
 
1214
                QMessageBox::critical(this, tr("Error"), QString(tr("There was an error unregistering the account.\nReason: %1")).arg(reg->statusString()));
 
1215
        }
365
1216
}