~ubuntu-branches/ubuntu/oneiric/psi/oneiric

« back to all changes in this revision

Viewing changes to src/accountdlg.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2005-01-10 17:41:43 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 hoary)
  • Revision ID: james.westby@ubuntu.com-20050110174143-ltocv5zapl6blf5d
Tags: 0.9.3-1
* New upstream release
* Cleaned up debian/rules (some things are done by upstream Makefiles now)
* Fixed some lintian warnings:
  - removed executable bit from some .png files
  - moved psi.desktop to /usr/share/applications
* Updated menu files

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
                if (!s) {
 
325
                        if (pa->eventQueue()->count()) {
 
326
                                setOn(!s);
 
327
                                QMessageBox::information(listView(), AccountManageDlg::tr("Error"), AccountManageDlg::tr("Unable to disable the account, as it has pending events."));
 
328
                                return;
 
329
                        }
 
330
 
 
331
                        if (pa->isActive()) {
 
332
                                if (QMessageBox::information(listView(), AccountManageDlg::tr("Disable Account"), AccountManageDlg::tr("The account is currently active.\nDo you want to log out ?"),QMessageBox::Yes,QMessageBox::No | QMessageBox::Default | QMessageBox::Escape, QMessageBox::NoButton) == QMessageBox::Yes) {
 
333
                                        pa->logout();
 
334
                                }
 
335
                                else {
 
336
                                        setOn(!s);
 
337
                                        return;
 
338
                                }
 
339
                        }
 
340
                }
 
341
 
 
342
                if (pa->enabled()!=s)
 
343
                        pa->setEnabled(s);
 
344
        }
 
345
 
 
346
        int rtti() const
 
347
        {
 
348
                return 8109;
 
349
        }
 
350
 
 
351
        PsiAccount *pa;
 
352
};
 
353
 
 
354
AccountManageDlg::AccountManageDlg(PsiCon *_psi, const char *name)
 
355
:AccountManageUI(0, name, false, WDestructiveClose)
 
356
{
 
357
        psi = _psi;
 
358
        psi->dialogRegister(this);
 
359
 
 
360
        setCaption(CAP(caption()));
41
361
 
42
362
        // setup signals
 
363
        connect(pb_add, SIGNAL(clicked()), SLOT(add()));
43
364
        connect(pb_modify, SIGNAL(clicked()), SLOT(modify()));
44
 
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
 
365
        connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
 
366
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
367
 
45
368
        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);
 
369
        connect(lv_accs, SIGNAL(selectionChanged(QListViewItem *)), SLOT(qlv_selectionChanged(QListViewItem *)));
 
370
        connect(psi, SIGNAL(accountAdded(PsiAccount *)), SLOT(accountAdded(PsiAccount *)));
 
371
        connect(psi, SIGNAL(accountUpdated(PsiAccount *)), SLOT(accountUpdated(PsiAccount *)));
 
372
        connect(psi, SIGNAL(accountRemoved(PsiAccount *)), SLOT(accountRemoved(PsiAccount *)));
 
373
 
 
374
        lv_accs->setAllColumnsShowFocus(true);
 
375
        lv_accs->setResizeMode(QListView::LastColumn);
 
376
 
 
377
        PsiAccountListIt it(psi->accountList());
 
378
        for(PsiAccount *pa; (pa = it.current()); ++it) {
 
379
                new AccountManageItem(lv_accs, pa);
 
380
        }
58
381
 
59
382
        if(lv_accs->childCount() > 0)
60
 
                lv_accs->setSelected(lv_accs->firstChild(), TRUE);
 
383
                lv_accs->setSelected(lv_accs->firstChild(), true);
 
384
        else
 
385
                qlv_selectionChanged(0);
61
386
}
62
387
 
63
388
AccountManageDlg::~AccountManageDlg()
64
389
{
65
 
        accountmanage_ptr = 0;
66
 
}
67
 
 
68
 
/* static */ AccountManageDlg *AccountManageDlg::find()
69
 
{
70
 
        return accountmanage_ptr;
 
390
        psi->dialogUnregister(this);
 
391
}
 
392
 
 
393
void AccountManageDlg::qlv_selectionChanged(QListViewItem *lvi)
 
394
{
 
395
        AccountManageItem *i = (AccountManageItem *)lvi;
 
396
        bool ok = i ? true: false;
 
397
 
 
398
        pb_modify->setEnabled(ok);
 
399
        pb_remove->setEnabled(ok);
 
400
}
 
401
 
 
402
void AccountManageDlg::add()
 
403
{
 
404
        AccountAddDlg *w = new AccountAddDlg(psi, 0);
 
405
        w->show();
71
406
}
72
407
 
73
408
void AccountManageDlg::modify()
74
409
{
75
 
        QListViewItem *lvi = lv_accs->currentItem();
76
 
        if(!lvi)
77
 
                return;
78
 
 
79
 
        modify(lvi);
 
410
        modify(lv_accs->currentItem());
80
411
}
81
412
 
82
413
void AccountManageDlg::modify(QListViewItem *lvi)
83
414
{
84
 
        signalModify(lvi->text(0));
85
 
}
86
 
 
87
 
void AccountManageDlg::updateEntry(JabSession *s)
88
 
{
89
 
        AccountViewItem *i;
 
415
        AccountManageItem *i = (AccountManageItem *)lvi;
 
416
        if(!i)
 
417
                return;
 
418
 
 
419
        psi->modifyAccount(i->pa);
 
420
}
 
421
 
 
422
void AccountManageDlg::remove()
 
423
{
 
424
        AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
 
425
        if(!i)
 
426
                return;
 
427
 
 
428
        if(i->pa->isActive()) {
 
429
                QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
 
430
                return;
 
431
        }
 
432
 
 
433
        AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
 
434
        int n = w->exec();
 
435
        if(n != QDialog::Accepted) {
 
436
                delete w;
 
437
                return;
 
438
        }
 
439
        delete w;
 
440
        psi->removeAccount(i->pa);
 
441
}
 
442
 
 
443
void AccountManageDlg::accountAdded(PsiAccount *pa)
 
444
{
 
445
        new AccountManageItem(lv_accs, pa);
 
446
}
 
447
 
 
448
void AccountManageDlg::accountUpdated(PsiAccount *pa)
 
449
{
 
450
        AccountManageItem *i;
90
451
        QListViewItemIterator it(lv_accs);
91
 
        for(; (i = (AccountViewItem *)it.current()) ; ++it) {
92
 
                if(i->s == s)
 
452
        for(; (i = (AccountManageItem *)it.current()) ; ++it) {
 
453
                if(i->pa == pa)
93
454
                        break;
94
455
        }
95
456
        if(!i)
98
459
        i->updateInfo();
99
460
}
100
461
 
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();
 
462
void AccountManageDlg::accountRemoved(PsiAccount *pa)
 
463
{
 
464
        AccountManageItem *i;
 
465
        QListViewItemIterator it(lv_accs);
 
466
        for(; (i = (AccountManageItem *)it.current()) ; ++it) {
 
467
                if(i->pa == pa)
 
468
                        break;
 
469
        }
 
470
        if(!i)
 
471
                return;
 
472
 
 
473
        delete i;
 
474
 
 
475
        qlv_selectionChanged(lv_accs->currentItem());
 
476
}
 
477
 
 
478
 
 
479
//----------------------------------------------------------------------------
 
480
// AccountAddDlg
 
481
//----------------------------------------------------------------------------
 
482
AccountAddDlg::AccountAddDlg(PsiCon *_psi, QWidget *parent, const char *name)
 
483
:AccountAddUI(parent, name, false, WDestructiveClose)
 
484
{
 
485
        psi = _psi;
 
486
        psi->dialogRegister(this);
 
487
 
 
488
        setCaption(CAP(caption()));
 
489
 
 
490
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
491
        connect(pb_add, SIGNAL(clicked()), SLOT(add()));
 
492
        connect(le_name, SIGNAL(textChanged(const QString &)), SLOT(setAddButton(const QString &)));
 
493
 
 
494
        QWhatsThis::add(ck_reg,
 
495
                tr("Check this option if you don't yet have a Jabber account "
 
496
                "and you want to register one.  Note that this will only work "
 
497
                "on servers that allow anonymous registration."));
 
498
 
 
499
        QString def = tr("Default");
 
500
        QString aname = def;
 
501
        int n = 0;
 
502
        while(1) {
 
503
                bool taken = false;
 
504
                PsiAccountListIt it(psi->accountList());
 
505
                for(PsiAccount *pa; (pa = it.current()); ++it) {
 
506
                        if(aname == pa->name()) {
 
507
                                taken = true;
 
508
                                break;
 
509
                        }
 
510
                }
 
511
 
 
512
                if(!taken)
 
513
                        break;
 
514
                aname = def + '_' + QString::number(++n);
 
515
        }
 
516
 
 
517
        le_name->setText(aname);
 
518
        le_name->setFocus();
 
519
}
 
520
 
 
521
AccountAddDlg::~AccountAddDlg()
 
522
{
 
523
        psi->dialogUnregister(this);
 
524
}
 
525
 
 
526
void AccountAddDlg::add()
 
527
{
 
528
        QString def = le_name->text();
 
529
        QString aname = def;
 
530
        int n = 0;
 
531
        while(1) {
 
532
                bool taken = false;
 
533
                PsiAccountListIt it(psi->accountList());
 
534
                for(PsiAccount *pa; (pa = it.current()); ++it) {
 
535
                        if(aname == pa->name()) {
 
536
                                taken = true;
 
537
                                break;
 
538
                        }
 
539
                }
 
540
 
 
541
                if(!taken)
 
542
                        break;
 
543
                aname = def + '_' + QString::number(++n);
 
544
        }
 
545
        le_name->setText( aname );
 
546
 
 
547
        if(ck_reg->isChecked()) {
 
548
                AccountRegDlg *w = new AccountRegDlg(psi->proxy(), this);
 
549
                int n = w->exec();
 
550
                if(n != QDialog::Accepted) {
 
551
                        delete w;
 
552
                        return;
 
553
                }
 
554
 
 
555
                Jid jid = w->jid;
 
556
                QString pass = w->pass;
 
557
                bool opt_host = w->opt_host;
 
558
                QString host = w->sp_host;
 
559
                int port = w->sp_port;
 
560
                bool ssl = w->ssl;
 
561
                int proxy = w->proxy;
 
562
 
 
563
                delete w;
 
564
 
 
565
                psi->createAccount(le_name->text(), jid, pass, opt_host, host, port, ssl, proxy);
 
566
        }
 
567
        else {
 
568
                psi->createAccount(le_name->text());
 
569
        }
 
570
 
 
571
        close();
 
572
}
 
573
 
 
574
void AccountAddDlg::setAddButton(const QString &s)
 
575
{
 
576
        pb_add->setEnabled(!s.isEmpty());
 
577
}
 
578
 
 
579
 
 
580
//----------------------------------------------------------------------------
 
581
// AccountModifyDlg
 
582
//----------------------------------------------------------------------------
 
583
AccountModifyDlg::AccountModifyDlg(PsiAccount *_pa, QWidget *parent, const char *name)
 
584
:AccountModifyUI(parent, name, false, WDestructiveClose)
 
585
{
 
586
        pa = _pa;
 
587
        connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
 
588
        pa->dialogRegister(this);
 
589
 
 
590
        setCaption(CAP(caption()));
 
591
        setIcon(IconsetFactory::icon("psi/account"));
 
592
 
 
593
        const UserAccount &acc = pa->userAccount();
135
594
 
136
595
        connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
137
596
        connect(ck_pass, SIGNAL(toggled(bool)), le_pass, SLOT(setEnabled(bool)));
 
597
        connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
 
598
        connect(pb_key, SIGNAL(clicked()), SLOT(chooseKey()));
 
599
        connect(pb_keyclear, SIGNAL(clicked()), SLOT(clearKey()));
138
600
        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);
 
601
 
 
602
        le_pass->setEnabled(false);
 
603
        le_host->setEnabled(false);
 
604
        le_port->setEnabled(false);
 
605
 
 
606
        gb_pgp->setEnabled(false);
 
607
        connect(ck_pp, SIGNAL(toggled(bool)), SLOT(optpp_toggled(bool)));
 
608
        le_pp->setEnabled(false);
 
609
 
 
610
        connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
 
611
        connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
 
612
 
 
613
        le_name->setText(acc.name);
 
614
        le_jid->setText(acc.jid);
 
615
 
 
616
        ck_ssl->setChecked(acc.opt_ssl);
 
617
        connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
 
618
 
 
619
        if(acc.opt_pass) {
 
620
                ck_pass->setChecked(true);
 
621
                le_pass->setText(acc.pass);
 
622
        }
 
623
 
 
624
        ck_host->setChecked(acc.opt_host);
 
625
        le_host->setText(acc.host);
 
626
        le_port->setText(QString::number(acc.port));
 
627
 
 
628
        le_resource->setText(acc.resource);
 
629
        le_priority->setText(QString::number(acc.priority));
 
630
 
 
631
        ck_plain->setChecked(acc.opt_plain);
 
632
        ck_auto->setChecked(acc.opt_auto);
 
633
        ck_reconn->setChecked(acc.opt_reconn);
 
634
        ck_log->setChecked(acc.opt_log);
 
635
        ck_keepAlive->setChecked(acc.opt_keepAlive);
 
636
        ck_ignoreSSLWarnings->setChecked(acc.opt_ignoreSSLWarnings);
 
637
        le_dtProxy->setText(acc.dtProxy.full());
 
638
 
 
639
        keyID = acc.pgpSecretKeyID;
 
640
        updateUserID();
 
641
        if(pa->psi()->pgp()) {
 
642
                gb_pgp->setEnabled(true);
 
643
                if(acc.opt_passphrase) {
 
644
                        ck_pp->setChecked(true);
 
645
                        le_pp->setText(acc.pgpPassphrase);
157
646
                }
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
 
 
 
647
        }
 
648
 
 
649
        pc = pa->psi()->proxy()->createProxyChooser(gb_proxy);
 
650
        replaceWidget(lb_proxychooser, pc);
 
651
        pc->fixTabbing(le_pp, ck_ssl);
 
652
        pc->setCurrentItem(acc.proxy_index);
 
653
 
 
654
        if(le_name->text().isEmpty())
 
655
                le_name->setFocus();
 
656
        else if(le_jid->text().isEmpty())
 
657
                le_jid->setFocus();
 
658
        else
166
659
                pb_save->setFocus();
167
 
        }
168
 
        else
169
 
                le_name->setFocus();
 
660
 
 
661
        // QWhatsThis helpers
 
662
        QWhatsThis::add(ck_plain,
 
663
                tr("Normally, Psi logs in using the <i>digest</i> authentication "
 
664
                "method.  Check this box to force a plain text login "
 
665
                "to the Jabber server. Use this option only if you have "
 
666
                "problems connecting with the normal login procedure, as it "
 
667
                "makes your connection potentially vulnerable to "
 
668
                "attacks."));
 
669
        QWhatsThis::add(ck_auto,
 
670
                tr("Automatically login to this account on Psi startup.  Useful if "
 
671
                "you have Psi automatically launched when an Internet "
 
672
                "connection is detected."));
 
673
        QWhatsThis::add(ck_reconn,
 
674
                tr("Makes Psi try to reconnect if the connection was broken.  "
 
675
                "Useful, if you have an unstable connection and have to "
 
676
                "reconnect often."));
 
677
        QWhatsThis::add(ck_log,
 
678
                tr("Keep a log of message history.  Disable this "
 
679
                "option if you want to conserve disk space or if you need "
 
680
                "maximum security."));
 
681
        QWhatsThis::add(ck_keepAlive,
 
682
                tr("Sends so called \"Keep-alive\" packets periodically.  "
 
683
                "It is useful if your connection is set to be "
 
684
                "automatically disconnected after a certain period of "
 
685
                "inactivity (for example, by your ISP) and you want to keep it "
 
686
                "up all the time."));
 
687
        QWhatsThis::add(ck_ignoreSSLWarnings,
 
688
                tr("Ignores all the SSL warnings, for example, about "
 
689
                "incorrect certificates.  Useful if your server doesn't "
 
690
                "use a validated SSL certificate and you are "
 
691
                "annoyed with warnings."));
 
692
        QWhatsThis::add(ck_ssl,
 
693
                tr("Check this option to use an encrypted SSL connection to "
 
694
                "the Jabber server.  You may use this option if your "
 
695
                "server supports it and if you have the necessary QSSL "
 
696
                "plugin installed.  For more information, check the "
 
697
                "Psi homepage."));
 
698
        QWhatsThis::add(ck_pass,
 
699
                tr("Check this option if you want Psi to remember your Jabber "
 
700
                "account password. Don't use this feature if you want "
 
701
                "maximum security and don't want to be compromised even "
 
702
                "if someone would break in your system and steal your "
 
703
                "configuration files."));
 
704
        QWhatsThis::add(ck_host,
 
705
                tr("Use this option for manual configuration of your Jabber host "
 
706
                "if it is not the same as the host you are connecting to.  This option is mostly useful "
 
707
                "if you have some sort of proxy route on your "
 
708
                "local machine (i.e. you connect to localhost), but your "
 
709
                "account is registered on an external server."));
 
710
        QWhatsThis::add(le_resource,
 
711
                tr("You can have multiple clients connected to the Jabber server "
 
712
                "with your single account.  Each login is distinguished by a \"resource\" "
 
713
                "name, which you can specify in this field."));
 
714
        QWhatsThis::add(le_priority,
 
715
                tr("<p>You can have multiple clients connected to the Jabber "
 
716
                "server with your single account.  In such a situation, "
 
717
                "the client with the highest priority (that is specified in "
 
718
                "this field) will be the one that will receive "
 
719
                "all incoming events.</p>"
 
720
                "<p>For example, if you have a permanent connection "
 
721
                "to the Internet at your work location, and have a dial-up at home, "
 
722
                "you can have your Jabber client permanently running at work "
 
723
                "with a low priority, and you can still use the same account "
 
724
                "from home, using a client with higher priority to "
 
725
                "temporary \"disable\" the lower priority client at work.</p>"));
 
726
 
 
727
        resize(minimumSize());
170
728
}
171
729
 
172
730
AccountModifyDlg::~AccountModifyDlg()
173
731
{
174
 
}
175
 
 
176
 
/*static*/ AccountModifyDlg * AccountModifyDlg::find(const QString &accname)
177
 
{
178
 
        return (AccountModifyDlg *)UniqueWindowBank::find("AccountModifyDlg", accname.lower());
 
732
        pa->dialogUnregister(this);
 
733
}
 
734
 
 
735
void AccountModifyDlg::updateUserID()
 
736
{
 
737
        if(keyID.isEmpty()) {
 
738
                setKeyID(false);
 
739
        }
 
740
        else {
 
741
                QString userID = QString::null;
 
742
                if(pa->psi()->pgp()) {
 
743
                        OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
 
744
                        for(OpenPGP::KeyList::ConstIterator it = list.begin(); it != list.end(); ++it) {
 
745
                                const OpenPGP::Key &k = *it;
 
746
                                if(k.keyID() == keyID) {
 
747
                                        userID = k.userID();
 
748
                                        break;
 
749
                                }
 
750
                        }
 
751
                }
 
752
                if(userID.isNull())
 
753
                        setKeyID(true, tr("Unknown Key: %1").arg(keyID.left(8)));
 
754
                else
 
755
                        setKeyID(true, userID);
 
756
        }
 
757
}
 
758
 
 
759
void AccountModifyDlg::setKeyID(bool b, const QString &s)
 
760
{
 
761
        if(b) {
 
762
                lb_keyname->setText(s);
 
763
                lb_keyname->setMinimumWidth(100);
 
764
                lb_keyicon->setEnabled(true);
 
765
                lb_keyname->setEnabled(true);
 
766
                pb_keyclear->setEnabled(true);
 
767
                ck_pp->setEnabled(true);
 
768
        }
 
769
        else {
 
770
                lb_keyname->setText(tr("No Key Selected"));
 
771
                lb_keyicon->setEnabled(false);
 
772
                lb_keyname->setEnabled(false);
 
773
                pb_keyclear->setEnabled(false);
 
774
                ck_pp->setChecked(false);
 
775
                ck_pp->setEnabled(false);
 
776
        }
 
777
}
 
778
 
 
779
void AccountModifyDlg::pgpToggled(bool b)
 
780
{
 
781
        if(b) {
 
782
                gb_pgp->setEnabled(true);
 
783
        }
 
784
        else {
 
785
                gb_pgp->setEnabled(false);
 
786
                ck_pp->setChecked(false);
 
787
        }
 
788
        updateUserID();
 
789
}
 
790
 
 
791
void AccountModifyDlg::optpp_toggled(bool b)
 
792
{
 
793
        if(b)
 
794
                le_pp->setEnabled(true);
 
795
        else {
 
796
                le_pp->setEnabled(false);
 
797
                le_pp->setText("");
 
798
        }
 
799
}
 
800
 
 
801
void AccountModifyDlg::setPassword(const QString &pw)
 
802
{
 
803
        le_pass->setText(pw);
179
804
}
180
805
 
181
806
void AccountModifyDlg::sslToggled(bool on)
182
807
{
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);
 
808
        if(on && !QCA::isSupported(QCA::CAP_TLS)) {
 
809
                QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS.  Plugin not found."));
 
810
                ck_ssl->setChecked(false);
186
811
                return;
187
812
        }
188
813
 
189
814
        le_port->setText(on ? "5223": "5222");
190
815
}
191
816
 
 
817
void AccountModifyDlg::hostToggled(bool on)
 
818
{
 
819
        le_host->setEnabled(on);
 
820
        le_port->setEnabled(on);
 
821
}
 
822
 
 
823
void AccountModifyDlg::chooseKey()
 
824
{
 
825
        OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
 
826
        PGPKeyDlg *w = new PGPKeyDlg(list, keyID, this);
 
827
        w->setCaption(tr("Secret Key"));
 
828
        int r = w->exec();
 
829
        QString key;
 
830
        if(r == QDialog::Accepted)
 
831
                key = w->keyID();
 
832
        delete w;
 
833
 
 
834
        if(!key.isEmpty()) {
 
835
                keyID = key;
 
836
                updateUserID();
 
837
                ck_pp->setChecked(false);
 
838
        }
 
839
}
 
840
 
 
841
void AccountModifyDlg::clearKey()
 
842
{
 
843
        setKeyID(false);
 
844
        keyID = "";
 
845
}
 
846
 
 
847
void AccountModifyDlg::detailsVCard()
 
848
{
 
849
        pa->changeVCard();
 
850
}
 
851
 
 
852
void AccountModifyDlg::detailsChangePW()
 
853
{
 
854
        pa->changePW();
 
855
}
 
856
 
192
857
void AccountModifyDlg::save()
193
858
{
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) {
 
859
        UserAccount acc = pa->userAccount();
 
860
 
 
861
        if(le_name->text().isEmpty()) {
204
862
                QMessageBox::information(this, tr("Error"), tr("You must specify a name for the account before you may save it."));
205
863
                return;
206
864
        }
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
 
        }
 
865
 
 
866
        Jid newJid( le_jid->text() );
 
867
        if ( newJid.user().isEmpty() || newJid.host().isEmpty() ) {
 
868
                QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
 
869
                return;
 
870
        }
 
871
 
 
872
        // do not allow duplicate account names
 
873
        QString def = le_name->text();
 
874
        QString aname = def;
 
875
        int n = 0;
 
876
        {
 
877
                PsiAccountListIt it(pa->psi()->accountList());
 
878
                for(PsiAccount *pa; (pa = it.current()); ++it)
 
879
                        if(aname == pa->name())
 
880
                                n++;
 
881
        }
 
882
 
 
883
        if ( aname == acc.name )
 
884
                n--;
 
885
 
 
886
        if ( n )
 
887
                aname = def + '_' + QString::number(++n);
 
888
        le_name->setText( aname );
219
889
 
220
890
        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();
 
891
        acc.jid = le_jid->text();
225
892
        acc.opt_pass = ck_pass->isChecked();
226
893
        if(acc.opt_pass)
227
894
                acc.pass = le_pass->text();
228
895
        else
229
896
                acc.pass = "";
 
897
 
 
898
        acc.opt_host = ck_host->isChecked();
 
899
        acc.host = le_host->text();
 
900
        acc.port = le_port->text().toInt();
 
901
 
230
902
        acc.resource = le_resource->text();
231
903
        acc.priority = le_priority->text().toInt();
232
904
 
 
905
        acc.opt_ssl = ck_ssl->isChecked();
233
906
        acc.opt_plain = ck_plain->isChecked();
234
907
        acc.opt_auto = ck_auto->isChecked();
 
908
        acc.opt_reconn = ck_reconn->isChecked();
235
909
        acc.opt_log = ck_log->isChecked();
236
910
        acc.opt_keepAlive = ck_keepAlive->isChecked();
237
 
 
238
 
        s->update(newUser);
 
911
        acc.opt_ignoreSSLWarnings = ck_ignoreSSLWarnings->isChecked();
 
912
        acc.dtProxy = le_dtProxy->text();
 
913
 
 
914
        acc.pgpSecretKeyID = keyID;
 
915
        acc.opt_passphrase = ck_pp->isChecked();
 
916
        if(acc.opt_passphrase)
 
917
                acc.pgpPassphrase = le_pp->text();
 
918
        else
 
919
                acc.pgpPassphrase = "";
 
920
 
 
921
        acc.proxy_index = pc->currentItem();
 
922
 
 
923
        if(pa->isActive()) {
 
924
                QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
 
925
        }
 
926
 
 
927
        pa->setUserAccount(acc);
239
928
 
240
929
        accept();
241
930
}
242
931
 
243
 
void AccountModifyDlg::doRegister()
244
 
{
 
932
 
 
933
//----------------------------------------------------------------------------
 
934
// AccountRegDlg
 
935
//----------------------------------------------------------------------------
 
936
AccountRegDlg::AccountRegDlg(ProxyManager *_proxyman, QWidget *parent, const char *name)
 
937
:AccountRegUI(parent, name, false)
 
938
{
 
939
        setCaption(CAP(caption()));
 
940
 
 
941
        le_host->setEnabled(false);
 
942
        le_port->setEnabled(false);
 
943
 
 
944
        connect(pb_reg, SIGNAL(clicked()), SLOT(reg()));
 
945
        connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
 
946
        connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
 
947
 
 
948
        proxyman = _proxyman;
 
949
        pc = proxyman->createProxyChooser(gb_proxy);
 
950
        replaceWidget(lb_proxychooser, pc);
 
951
        pc->fixTabbing(le_confirm, ck_ssl);
 
952
        pc->setCurrentItem(0);
 
953
 
 
954
        le_port->setText("5222");
 
955
        le_host->setFocus();
 
956
 
 
957
        client = new MiniClient;
 
958
        connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
 
959
        connect(client, SIGNAL(error()), SLOT(client_error()));
 
960
}
 
961
 
 
962
AccountRegDlg::~AccountRegDlg()
 
963
{
 
964
        delete client;
 
965
}
 
966
 
 
967
/*void AccountRegDlg::closeEvent(QCloseEvent *e)
 
968
{
 
969
        e->ignore();
 
970
        reject();
 
971
}*/
 
972
 
 
973
void AccountRegDlg::done(int r)
 
974
{
 
975
        if(busy->isActive()) {
 
976
                int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the registration?"), tr("&Yes"), tr("&No"));
 
977
                if(n != 0)
 
978
                        return;
 
979
        }
 
980
        QDialog::done(r);
 
981
}
 
982
 
 
983
void AccountRegDlg::sslToggled(bool on)
 
984
{
 
985
        if(on && !QCA::isSupported(QCA::CAP_TLS)) {
 
986
                QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS.  Plugin not found."));
 
987
                ck_ssl->setChecked(false);
 
988
                return;
 
989
        }
 
990
 
 
991
        le_port->setText(on ? "5223": "5222");
 
992
}
 
993
 
 
994
void AccountRegDlg::hostToggled(bool on)
 
995
{
 
996
        le_host->setEnabled(on);
 
997
        le_port->setEnabled(on);
 
998
}
 
999
 
 
1000
void AccountRegDlg::reg()
 
1001
{
 
1002
        // sanity check
 
1003
        Jid j(le_jid->text());
 
1004
        if ( j.user().isEmpty() || j.host().isEmpty() ) {
 
1005
                QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
 
1006
                return;
 
1007
        }
 
1008
 
245
1009
        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
 
 
 
1010
                QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can register."));
 
1011
                return;
 
1012
        }
 
1013
 
 
1014
        if(le_pass->text() != le_confirm->text()) {
 
1015
                QMessageBox::information(this, tr("Error"), tr("Password and confirmation do not match.  Please enter them again."));
 
1016
                le_pass->setText("");
 
1017
                le_confirm->setText("");
 
1018
                le_pass->setFocus();
 
1019
                return;
 
1020
        }
 
1021
 
 
1022
        busy->start();
 
1023
        block();
 
1024
 
 
1025
        jid = j;
 
1026
        ssl = ck_ssl->isChecked();
 
1027
        pass = le_pass->text();
 
1028
        opt_host = ck_host->isChecked();
 
1029
        sp_host = le_host->text();
 
1030
        sp_port = le_port->text().toInt();
 
1031
 
 
1032
        client->connectToServer(jid, ssl, opt_host ? sp_host : QString(), sp_port, proxyman, pc->currentItem(), 0);
 
1033
}
 
1034
 
 
1035
void AccountRegDlg::client_handshaken()
 
1036
{
 
1037
        // try to register an account
 
1038
        JT_Register *reg = new JT_Register(client->client()->rootTask());
 
1039
        connect(reg, SIGNAL(finished()), SLOT(reg_finished()));
 
1040
        reg->reg(jid.user(), pass);
 
1041
        reg->go(true);
 
1042
}
 
1043
 
 
1044
void AccountRegDlg::client_error()
 
1045
{
 
1046
        busy->stop();
 
1047
        unblock();
 
1048
}
 
1049
 
 
1050
void AccountRegDlg::reg_finished()
 
1051
{
 
1052
        JT_Register *reg = (JT_Register *)sender();
 
1053
 
 
1054
        client->close();
 
1055
        busy->stop();
 
1056
 
 
1057
        if(reg->success()) {
 
1058
                QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
 
1059
                proxy = pc->currentItem();
 
1060
                accept();
 
1061
                return;
 
1062
        }
 
1063
        else if(reg->statusCode() != Task::ErrDisc) {
 
1064
                unblock();
 
1065
                QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(reg->statusString()));
 
1066
        }
 
1067
}
 
1068
 
 
1069
void AccountRegDlg::block()
 
1070
{
 
1071
        gb_account->setEnabled(false);
 
1072
        gb_proxy->setEnabled(false);
 
1073
        gb_advanced->setEnabled(false);
 
1074
        pb_reg->setEnabled(false);
 
1075
}
 
1076
 
 
1077
void AccountRegDlg::unblock()
 
1078
{
 
1079
        gb_account->setEnabled(true);
 
1080
        gb_proxy->setEnabled(true);
 
1081
        gb_advanced->setEnabled(true);
 
1082
        pb_reg->setEnabled(true);
 
1083
        le_jid->setFocus();
 
1084
}
 
1085
 
 
1086
 
 
1087
//----------------------------------------------------------------------------
 
1088
// AccountRemoveDlg
 
1089
//----------------------------------------------------------------------------
 
1090
class AccountRemoveDlg::Private
 
1091
{
 
1092
public:
 
1093
        Private() {}
 
1094
 
 
1095
        UserAccount acc;
 
1096
        QButtonGroup *bg;
 
1097
        ProxyManager *proxyman;
 
1098
};
 
1099
 
 
1100
AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent, const char *name)
 
1101
:AccountRemoveUI(parent, name, false)
 
1102
{
 
1103
        d = new Private;
 
1104
        d->acc = acc;
 
1105
        d->proxyman = proxyman;
 
1106
 
 
1107
        setCaption(CAP(caption()));
 
1108
 
 
1109
        connect(pb_close, SIGNAL(clicked()), SLOT(close()));
 
1110
        connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
 
1111
 
 
1112
        d->bg = new QButtonGroup(0);
 
1113
        d->bg->insert(rb_remove, 0);
 
1114
        d->bg->insert(rb_removeAndUnreg, 1);
 
1115
        connect(d->bg, SIGNAL(clicked(int)), SLOT(bg_clicked(int)));
 
1116
        d->bg->setButton(0);
 
1117
        bg_clicked(0);
 
1118
 
 
1119
        pb_close->setFocus();
 
1120
 
 
1121
        client = new MiniClient;
 
1122
        connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
 
1123
        connect(client, SIGNAL(error()), SLOT(client_error()));
 
1124
}
 
1125
 
 
1126
AccountRemoveDlg::~AccountRemoveDlg()
 
1127
{
 
1128
        delete client;
 
1129
 
 
1130
        delete d->bg;
 
1131
        delete d;
 
1132
}
 
1133
 
 
1134
/*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
 
1135
{
 
1136
        e->ignore();
 
1137
        reject();
 
1138
}*/
 
1139
 
 
1140
void AccountRemoveDlg::done(int r)
 
1141
{
 
1142
        if(busy->isActive()) {
 
1143
                int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the unregistration?"), tr("&Yes"), tr("&No"));
 
1144
                if(n != 0)
 
1145
                        return;
 
1146
        }
 
1147
        QDialog::done(r);
 
1148
}
 
1149
 
 
1150
void AccountRemoveDlg::bg_clicked(int x)
 
1151
{
 
1152
        if(x == 0) {
 
1153
                lb_pass->setEnabled(false);
 
1154
                le_pass->setEnabled(false);
 
1155
        }
 
1156
        else if(x == 1) {
 
1157
                lb_pass->setEnabled(true);
 
1158
                le_pass->setEnabled(true);
 
1159
                le_pass->setFocus();
 
1160
        }
 
1161
}
 
1162
 
 
1163
void AccountRemoveDlg::remove()
 
1164
{
 
1165
        bool unreg = rb_removeAndUnreg->isChecked();
 
1166
 
 
1167
        if(unreg) {
 
1168
                if(le_pass->text() != d->acc.pass) {
 
1169
                        QMessageBox::information(this, tr("Error"), tr("Password does not match account.  Please try again."));
 
1170
                        le_pass->setFocus();
 
1171
                        return;
 
1172
                }
 
1173
        }
 
1174
 
 
1175
        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
1176
        if(n != 0)
264
1177
                return;
265
1178
 
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
 
{
 
1179
        if(!unreg) {
 
1180
                accept();
 
1181
                return;
 
1182
        }
 
1183
 
315
1184
        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();
 
1185
        gb_account->setEnabled(false);
 
1186
        pb_remove->setEnabled(false);
 
1187
 
 
1188
        Jid j = d->acc.jid;
 
1189
        j.setResource(d->acc.resource);
 
1190
        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);
 
1191
}
 
1192
 
 
1193
void AccountRemoveDlg::client_handshaken()
 
1194
{
 
1195
        // try to unregister an account
 
1196
        JT_Register *reg = new JT_Register(client->client()->rootTask());
 
1197
        connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
 
1198
        reg->unreg();
 
1199
        reg->go(true);
 
1200
}
 
1201
 
 
1202
void AccountRemoveDlg::client_error()
 
1203
{
 
1204
        busy->stop();
 
1205
        gb_account->setEnabled(true);
 
1206
        pb_remove->setEnabled(true);
 
1207
}
 
1208
 
 
1209
void AccountRemoveDlg::unreg_finished()
 
1210
{
 
1211
        JT_Register *reg = (JT_Register *)sender();
 
1212
 
 
1213
        client->close();
 
1214
        busy->stop();
 
1215
 
 
1216
        if(reg->success()) {
 
1217
                QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
 
1218
                accept();
 
1219
                return;
 
1220
        }
 
1221
        else if(reg->statusCode() != Task::ErrDisc) {
 
1222
                gb_account->setEnabled(true);
 
1223
                pb_remove->setEnabled(true);
 
1224
                QMessageBox::critical(this, tr("Error"), QString(tr("There was an error unregistering the account.\nReason: %1")).arg(reg->statusString()));
 
1225
        }
365
1226
}