2
* accountdlg.cpp - dialogs for manipulating PsiAccounts
3
* Copyright (C) 2001, 2002 Justin Karneges
5
* This program is free software; you can redistribute it and/or
6
* modify it under the terms of the GNU General Public License
7
* as published by the Free Software Foundation; either version 2
8
* of the License, or (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this library; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
#include"accountdlg.h"
23
#include<qpushbutton.h>
31
#include<qradiobutton.h>
32
#include<qbuttongroup.h>
33
#include<qtabwidget.h>
34
#include<qwhatsthis.h>
38
#include"psiaccount.h"
41
#include"xmpp_tasks.h"
43
#include"sslcertdlg.h"
44
#include"busywidget.h"
45
#include"iconwidget.h"
46
#include"fancylabel.h"
51
//----------------------------------------------------------------------------
53
//----------------------------------------------------------------------------
54
static QCA::Cert readCertXml(const QDomElement &e)
57
// there should be one child data tag
58
QDomElement data = e.elementsByTagName("data").item(0).toElement();
60
cert.fromDER(Base64::stringToArray(data.text()));
64
static QPtrList<QCA::Cert> getRootCerts(const QStringList &stores)
66
QPtrList<QCA::Cert> list;
68
for(QStringList::ConstIterator dit = stores.begin(); dit != stores.end(); ++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))
77
bool ok = doc.setContent(&f);
82
QDomElement base = doc.documentElement();
83
if(base.tagName() != "store")
85
QDomNodeList cl = base.elementsByTagName("certificate");
88
for(int n = 0; n < (int)cl.count(); ++n) {
89
QCA::Cert *cert = new QCA::Cert(readCertXml(cl.item(n).toElement()));
104
MiniClient::MiniClient(QObject *parent)
107
_client = new Client;
112
certList.setAutoDelete(true);
115
MiniClient::~MiniClient()
121
void MiniClient::reset()
136
void MiniClient::connectToServer(const Jid &jid, bool ssl, const QString &_host, int _port, ProxyManager *pm, int proxy, QString *_pass)
142
if(!_host.isEmpty()) {
154
AdvancedConnector::Proxy p;
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);
166
u.setQuery(QString("server=") + v);
168
p.setHttpPoll(pi.settings.host, pi.settings.port, u.toString());
169
p.setPollInterval(2);
172
if(pi.settings.useAuth)
173
p.setUserPass(pi.settings.user, pi.settings.pass);
176
conn = new AdvancedConnector;
178
QStringList certDirs;
179
certDirs += g.pathBase + "/certs";
180
certList = getRootCerts(certDirs);
183
tls->setCertificateStore(certList);
184
tlsHandler = new QCATLSHandler(tls);
185
connect(tlsHandler, SIGNAL(tlsHandshaken()), SLOT(tls_handshaken()));
188
conn->setOptHostPort(host, port);
189
conn->setOptSSL(ssl);
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)));
204
_client->connectToServer(stream, j);
207
_client->connectToServer(stream, j, false);
210
void MiniClient::close()
216
Client *MiniClient::client()
221
void MiniClient::tls_handshaken()
223
QCA::Cert cert = tls->peerCertificate();
224
int r = tls->certificateValidityResult();
225
if(r != QCA::TLS::Valid) {
226
QString str = PsiAccount::resultToString(r);
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),
233
tr("&Cancel"), 0, 2);
235
SSLCertDlg::showCert(cert, r);
238
tlsHandler->continueAfterHandshake();
249
tlsHandler->continueAfterHandshake();
252
void MiniClient::cs_connected()
256
void MiniClient::cs_securityLayerActivated(int)
260
void MiniClient::cs_needAuthParams(bool, bool, bool)
262
stream->setPassword(pass);
263
stream->continueAfterParams();
266
void MiniClient::cs_authenticated()
268
_client->start(j.host(), j.user(), "", "");
272
void MiniClient::cs_connectionClosed()
277
void MiniClient::cs_delayedCloseFinished()
281
void MiniClient::cs_warning(int)
283
stream->continueAfterWarning();
286
void MiniClient::cs_error(int err)
291
PsiAccount::getErrorInfo(err, conn, stream, tlsHandler, &str, &reconn);
294
QMessageBox::critical(0, tr("Server Error"), tr("There was an error communicating with the Jabber server.\nDetails: %1").arg(str));
298
//----------------------------------------------------------------------------
300
//----------------------------------------------------------------------------
301
class AccountManageItem : public QCheckListItem
304
AccountManageItem(QListView *par, PsiAccount *_pa)
305
:QCheckListItem(par,"",CheckBox)
313
const UserAccount &acc = pa->userAccount();
314
setText(0, pa->name());
315
//setPixmap(0, IconsetFactory::icon("psi/account"));
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());
322
void stateChange( bool s)
324
if (pa->enabled()!=s)
337
AccountManageDlg::AccountManageDlg(PsiCon *_psi, const char *name)
338
:AccountManageUI(0, name, false, WDestructiveClose)
341
psi->dialogRegister(this);
343
setCaption(CAP(caption()));
346
connect(pb_add, SIGNAL(clicked()), SLOT(add()));
347
connect(pb_modify, SIGNAL(clicked()), SLOT(modify()));
348
connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
349
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
351
connect(lv_accs, SIGNAL(doubleClicked(QListViewItem *)), SLOT(modify(QListViewItem *)));
352
connect(lv_accs, SIGNAL(selectionChanged(QListViewItem *)), SLOT(qlv_selectionChanged(QListViewItem *)));
353
connect(psi, SIGNAL(accountAdded(PsiAccount *)), SLOT(accountAdded(PsiAccount *)));
354
connect(psi, SIGNAL(accountUpdated(PsiAccount *)), SLOT(accountUpdated(PsiAccount *)));
355
connect(psi, SIGNAL(accountRemoved(PsiAccount *)), SLOT(accountRemoved(PsiAccount *)));
357
lv_accs->setAllColumnsShowFocus(true);
358
lv_accs->setResizeMode(QListView::LastColumn);
360
PsiAccountListIt it(psi->accountList());
361
for(PsiAccount *pa; (pa = it.current()); ++it) {
362
new AccountManageItem(lv_accs, pa);
365
if(lv_accs->childCount() > 0)
366
lv_accs->setSelected(lv_accs->firstChild(), true);
368
qlv_selectionChanged(0);
371
AccountManageDlg::~AccountManageDlg()
373
psi->dialogUnregister(this);
376
void AccountManageDlg::qlv_selectionChanged(QListViewItem *lvi)
378
AccountManageItem *i = (AccountManageItem *)lvi;
379
bool ok = i ? true: false;
381
pb_modify->setEnabled(ok);
382
pb_remove->setEnabled(ok);
385
void AccountManageDlg::add()
387
AccountAddDlg *w = new AccountAddDlg(psi, 0);
391
void AccountManageDlg::modify()
393
modify(lv_accs->currentItem());
396
void AccountManageDlg::modify(QListViewItem *lvi)
398
AccountManageItem *i = (AccountManageItem *)lvi;
402
psi->modifyAccount(i->pa);
405
void AccountManageDlg::remove()
407
AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
411
if(i->pa->isActive()) {
412
QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
416
AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
418
if(n != QDialog::Accepted) {
423
psi->removeAccount(i->pa);
426
void AccountManageDlg::accountAdded(PsiAccount *pa)
428
new AccountManageItem(lv_accs, pa);
431
void AccountManageDlg::accountUpdated(PsiAccount *pa)
433
AccountManageItem *i;
434
QListViewItemIterator it(lv_accs);
435
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
445
void AccountManageDlg::accountRemoved(PsiAccount *pa)
447
AccountManageItem *i;
448
QListViewItemIterator it(lv_accs);
449
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
458
qlv_selectionChanged(lv_accs->currentItem());
462
//----------------------------------------------------------------------------
464
//----------------------------------------------------------------------------
465
AccountAddDlg::AccountAddDlg(PsiCon *_psi, QWidget *parent, const char *name)
466
:AccountAddUI(parent, name, false, WDestructiveClose)
469
psi->dialogRegister(this);
471
setCaption(CAP(caption()));
473
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
474
connect(pb_add, SIGNAL(clicked()), SLOT(add()));
475
connect(le_name, SIGNAL(textChanged(const QString &)), SLOT(setAddButton(const QString &)));
477
QWhatsThis::add(ck_reg,
478
tr("Check this option if you don't yet have a Jabber account "
479
"and you want to register one. Note that this will only work "
480
"on servers that allow anonymous registration."));
482
QString def = tr("Default");
487
PsiAccountListIt it(psi->accountList());
488
for(PsiAccount *pa; (pa = it.current()); ++it) {
489
if(aname == pa->name()) {
497
aname = def + '_' + QString::number(++n);
500
le_name->setText(aname);
504
AccountAddDlg::~AccountAddDlg()
506
psi->dialogUnregister(this);
509
void AccountAddDlg::add()
511
QString def = le_name->text();
516
PsiAccountListIt it(psi->accountList());
517
for(PsiAccount *pa; (pa = it.current()); ++it) {
518
if(aname == pa->name()) {
526
aname = def + '_' + QString::number(++n);
528
le_name->setText( aname );
530
if(ck_reg->isChecked()) {
531
AccountRegDlg *w = new AccountRegDlg(psi->proxy(), this);
533
if(n != QDialog::Accepted) {
539
QString pass = w->pass;
540
bool opt_host = w->opt_host;
541
QString host = w->sp_host;
542
int port = w->sp_port;
544
int proxy = w->proxy;
548
psi->createAccount(le_name->text(), jid, pass, opt_host, host, port, ssl, proxy);
551
psi->createAccount(le_name->text());
557
void AccountAddDlg::setAddButton(const QString &s)
559
pb_add->setEnabled(!s.isEmpty());
563
//----------------------------------------------------------------------------
565
//----------------------------------------------------------------------------
566
AccountModifyDlg::AccountModifyDlg(PsiAccount *_pa, QWidget *parent, const char *name)
567
:AccountModifyUI(parent, name, false, WDestructiveClose)
570
connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
571
pa->dialogRegister(this);
573
setCaption(CAP(caption()));
574
setIcon(IconsetFactory::icon("psi/account"));
576
const UserAccount &acc = pa->userAccount();
578
connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
579
connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
580
connect(pb_key, SIGNAL(clicked()), SLOT(chooseKey()));
581
connect(pb_keyclear, SIGNAL(clicked()), SLOT(clearKey()));
582
connect(pb_save, SIGNAL(clicked()), SLOT(save()));
584
le_pass->setEnabled(true);
585
le_host->setEnabled(false);
586
le_port->setEnabled(false);
588
gb_pgp->setEnabled(false);
590
connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
591
connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
593
le_name->setText(acc.name);
594
le_jid->setText(acc.jid);
596
ck_ssl->setChecked(acc.opt_ssl);
597
connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
600
le_pass->setText(acc.pass);
602
ck_host->setChecked(acc.opt_host);
603
le_host->setText(acc.host);
604
le_port->setText(QString::number(acc.port));
606
le_resource->setText(acc.resource);
607
le_priority->setText(QString::number(acc.priority));
609
ck_plain->setChecked(acc.opt_plain);
610
ck_auto->setChecked(acc.opt_auto);
611
ck_reconn->setChecked(acc.opt_reconn);
612
ck_log->setChecked(acc.opt_log);
613
ck_keepAlive->setChecked(acc.opt_keepAlive);
614
ck_ignoreSSLWarnings->setChecked(acc.opt_ignoreSSLWarnings);
615
le_dtProxy->setText(acc.dtProxy.full());
617
keyID = acc.pgpSecretKeyID;
619
if(pa->psi()->pgp()) {
620
gb_pgp->setEnabled(true);
623
pc = pa->psi()->proxy()->createProxyChooser(gb_proxy);
624
replaceWidget(lb_proxychooser, pc);
625
pc->setCurrentItem(acc.proxy_index);
627
if(le_name->text().isEmpty())
629
else if(le_jid->text().isEmpty())
634
// QWhatsThis helpers
635
QWhatsThis::add(ck_plain,
636
tr("Normally, Psi logs in using the <i>digest</i> authentication "
637
"method. Check this box to force a plain text login "
638
"to the Jabber server. Use this option only if you have "
639
"problems connecting with the normal login procedure, as it "
640
"makes your connection potentially vulnerable to "
642
QWhatsThis::add(ck_auto,
643
tr("Automatically login to this account on Psi startup. Useful if "
644
"you have Psi automatically launched when an Internet "
645
"connection is detected."));
646
QWhatsThis::add(ck_reconn,
647
tr("Makes Psi try to reconnect if the connection was broken. "
648
"Useful, if you have an unstable connection and have to "
649
"reconnect often."));
650
QWhatsThis::add(ck_log,
651
tr("Keep a log of message history. Disable this "
652
"option if you want to conserve disk space or if you need "
653
"maximum security."));
654
QWhatsThis::add(ck_keepAlive,
655
tr("Sends so called \"Keep-alive\" packets periodically. "
656
"It is useful if your connection is set to be "
657
"automatically disconnected after a certain period of "
658
"inactivity (for example, by your ISP) and you want to keep it "
659
"up all the time."));
660
QWhatsThis::add(ck_ignoreSSLWarnings,
661
tr("Ignores all the SSL warnings, for example, about "
662
"incorrect certificates. Useful if your server doesn't "
663
"use a validated SSL certificate and you are "
664
"annoyed with warnings."));
665
QWhatsThis::add(ck_ssl,
666
tr("Check this option to use an encrypted SSL connection to "
667
"the Jabber server. You may use this option if your "
668
"server supports it and if you have the necessary QSSL "
669
"plugin installed. For more information, check the "
671
QWhatsThis::add(ck_host,
672
tr("Use this option for manual configuration of your Jabber host "
673
"if it is not the same as the host you are connecting to. This option is mostly useful "
674
"if you have some sort of proxy route on your "
675
"local machine (i.e. you connect to localhost), but your "
676
"account is registered on an external server."));
677
QWhatsThis::add(le_resource,
678
tr("You can have multiple clients connected to the Jabber server "
679
"with your single account. Each login is distinguished by a \"resource\" "
680
"name, which you can specify in this field."));
681
QWhatsThis::add(le_priority,
682
tr("<p>You can have multiple clients connected to the Jabber "
683
"server with your single account. In such a situation, "
684
"the client with the highest priority (that is specified in "
685
"this field) will be the one that will receive "
686
"all incoming events.</p>"
687
"<p>For example, if you have a permanent connection "
688
"to the Internet at your work location, and have a dial-up at home, "
689
"you can have your Jabber client permanently running at work "
690
"with a low priority, and you can still use the same account "
691
"from home, using a client with higher priority to "
692
"temporary \"disable\" the lower priority client at work.</p>"));
694
resize(minimumSize());
697
AccountModifyDlg::~AccountModifyDlg()
699
pa->dialogUnregister(this);
702
void AccountModifyDlg::updateUserID()
704
if(keyID.isEmpty()) {
708
QString userID = QString::null;
709
if(pa->psi()->pgp()) {
710
OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
711
for(OpenPGP::KeyList::ConstIterator it = list.begin(); it != list.end(); ++it) {
712
const OpenPGP::Key &k = *it;
713
if(k.keyID() == keyID) {
720
setKeyID(true, tr("Unknown Key: %1").arg(keyID.left(8)));
722
setKeyID(true, userID);
726
void AccountModifyDlg::setKeyID(bool b, const QString &s)
729
lb_keyname->setText(s);
730
lb_keyname->setMinimumWidth(100);
731
lb_keyicon->setEnabled(true);
732
lb_keyname->setEnabled(true);
733
pb_keyclear->setEnabled(true);
736
lb_keyname->setText(tr("No Key Selected"));
737
lb_keyicon->setEnabled(false);
738
lb_keyname->setEnabled(false);
739
pb_keyclear->setEnabled(false);
743
void AccountModifyDlg::pgpToggled(bool b)
746
gb_pgp->setEnabled(true);
749
gb_pgp->setEnabled(false);
754
void AccountModifyDlg::setPassword(const QString &pw)
756
if (!le_pass->text().isEmpty())
757
le_pass->setText(pw);
760
void AccountModifyDlg::sslToggled(bool on)
762
if(on && !QCA::isSupported(QCA::CAP_TLS)) {
763
QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS. Plugin not found."));
764
ck_ssl->setChecked(false);
768
le_port->setText(on ? "5223": "5222");
771
void AccountModifyDlg::hostToggled(bool on)
773
le_host->setEnabled(on);
774
le_port->setEnabled(on);
777
void AccountModifyDlg::chooseKey()
779
OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
780
PGPKeyDlg *w = new PGPKeyDlg(list, keyID, this);
781
w->setCaption(tr("Secret Key"));
784
if(r == QDialog::Accepted)
794
void AccountModifyDlg::clearKey()
800
void AccountModifyDlg::detailsVCard()
805
void AccountModifyDlg::detailsChangePW()
810
void AccountModifyDlg::save()
812
UserAccount acc = pa->userAccount();
814
if(le_name->text().isEmpty()) {
815
QMessageBox::information(this, tr("Error"), tr("You must specify a name for the account before you may save it."));
819
Jid newJid( le_jid->text() );
820
if ( newJid.user().isEmpty() || newJid.host().isEmpty() ) {
821
QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
825
// do not allow duplicate account names
826
QString def = le_name->text();
830
PsiAccountListIt it(pa->psi()->accountList());
831
for(PsiAccount *pa; (pa = it.current()); ++it)
832
if(aname == pa->name())
836
if ( aname == acc.name )
840
aname = def + '_' + QString::number(++n);
841
le_name->setText( aname );
843
acc.name = le_name->text();
844
acc.jid = le_jid->text();
845
acc.pass = le_pass->text();
846
acc.opt_pass = !acc.pass.isEmpty();
848
acc.opt_host = ck_host->isChecked();
849
acc.host = le_host->text();
850
acc.port = le_port->text().toInt();
852
acc.resource = le_resource->text();
853
acc.priority = le_priority->text().toInt();
855
acc.opt_ssl = ck_ssl->isChecked();
856
acc.opt_plain = ck_plain->isChecked();
857
acc.opt_auto = ck_auto->isChecked();
858
acc.opt_reconn = ck_reconn->isChecked();
859
acc.opt_log = ck_log->isChecked();
860
acc.opt_keepAlive = ck_keepAlive->isChecked();
861
acc.opt_ignoreSSLWarnings = ck_ignoreSSLWarnings->isChecked();
862
acc.dtProxy = le_dtProxy->text();
864
acc.pgpSecretKeyID = keyID;
866
acc.proxy_index = pc->currentItem();
869
QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
872
pa->setUserAccount(acc);
878
//----------------------------------------------------------------------------
880
//----------------------------------------------------------------------------
881
AccountRegDlg::AccountRegDlg(ProxyManager *_proxyman, QWidget *parent, const char *name)
882
:AccountRegUI(parent, name, false)
884
setCaption(CAP(caption()));
886
le_host->setEnabled(false);
887
le_port->setEnabled(false);
889
connect(pb_reg, SIGNAL(clicked()), SLOT(reg()));
890
connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
891
connect(ck_host, SIGNAL(toggled(bool)), SLOT(hostToggled(bool)));
893
proxyman = _proxyman;
894
pc = proxyman->createProxyChooser(gb_proxy);
895
replaceWidget(lb_proxychooser, pc);
896
pc->fixTabbing(le_confirm, ck_ssl);
897
pc->setCurrentItem(0);
899
le_port->setText("5222");
902
client = new MiniClient;
903
connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
904
connect(client, SIGNAL(error()), SLOT(client_error()));
907
AccountRegDlg::~AccountRegDlg()
912
/*void AccountRegDlg::closeEvent(QCloseEvent *e)
918
void AccountRegDlg::done(int r)
920
if(busy->isActive()) {
921
int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the registration?"), tr("&Yes"), tr("&No"));
928
void AccountRegDlg::sslToggled(bool on)
930
if(on && !QCA::isSupported(QCA::CAP_TLS)) {
931
QMessageBox::information(this, tr("SSL error"), tr("Cannot enable SSL/TLS. Plugin not found."));
932
ck_ssl->setChecked(false);
936
le_port->setText(on ? "5223": "5222");
939
void AccountRegDlg::hostToggled(bool on)
941
le_host->setEnabled(on);
942
le_port->setEnabled(on);
945
void AccountRegDlg::reg()
948
Jid j(le_jid->text());
949
if ( j.user().isEmpty() || j.host().isEmpty() ) {
950
QMessageBox::information(this, tr("Error"), tr("<i>Jabber ID</i> must be specified in the format <i>user@host</i>."));
954
if(le_pass->text().isEmpty()) {
955
QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can register."));
959
if(le_pass->text() != le_confirm->text()) {
960
QMessageBox::information(this, tr("Error"), tr("Password and confirmation do not match. Please enter them again."));
961
le_pass->setText("");
962
le_confirm->setText("");
971
ssl = ck_ssl->isChecked();
972
pass = le_pass->text();
973
opt_host = ck_host->isChecked();
974
sp_host = le_host->text();
975
sp_port = le_port->text().toInt();
977
client->connectToServer(jid, ssl, opt_host ? sp_host : QString(), sp_port, proxyman, pc->currentItem(), 0);
980
void AccountRegDlg::client_handshaken()
982
// try to register an account
983
JT_Register *reg = new JT_Register(client->client()->rootTask());
984
connect(reg, SIGNAL(finished()), SLOT(reg_finished()));
985
reg->reg(jid.user(), pass);
989
void AccountRegDlg::client_error()
995
void AccountRegDlg::reg_finished()
997
JT_Register *reg = (JT_Register *)sender();
1002
if(reg->success()) {
1003
QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
1004
proxy = pc->currentItem();
1008
else if(reg->statusCode() != Task::ErrDisc) {
1010
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(reg->statusString()));
1014
void AccountRegDlg::block()
1016
gb_account->setEnabled(false);
1017
gb_proxy->setEnabled(false);
1018
gb_advanced->setEnabled(false);
1019
pb_reg->setEnabled(false);
1022
void AccountRegDlg::unblock()
1024
gb_account->setEnabled(true);
1025
gb_proxy->setEnabled(true);
1026
gb_advanced->setEnabled(true);
1027
pb_reg->setEnabled(true);
1032
//----------------------------------------------------------------------------
1034
//----------------------------------------------------------------------------
1035
class AccountRemoveDlg::Private
1042
ProxyManager *proxyman;
1045
AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent, const char *name)
1046
:AccountRemoveUI(parent, name, false)
1050
d->proxyman = proxyman;
1052
setCaption(CAP(caption()));
1054
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
1055
connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
1057
d->bg = new QButtonGroup(0);
1058
d->bg->insert(rb_remove, 0);
1059
d->bg->insert(rb_removeAndUnreg, 1);
1060
connect(d->bg, SIGNAL(clicked(int)), SLOT(bg_clicked(int)));
1061
d->bg->setButton(0);
1064
pb_close->setFocus();
1066
client = new MiniClient;
1067
connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
1068
connect(client, SIGNAL(error()), SLOT(client_error()));
1071
AccountRemoveDlg::~AccountRemoveDlg()
1079
/*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
1085
void AccountRemoveDlg::done(int r)
1087
if(busy->isActive()) {
1088
int n = QMessageBox::information(this, tr("Warning"), tr("Are you sure you want to cancel the unregistration?"), tr("&Yes"), tr("&No"));
1095
void AccountRemoveDlg::bg_clicked(int x)
1098
lb_pass->setEnabled(false);
1099
le_pass->setEnabled(false);
1102
lb_pass->setEnabled(true);
1103
le_pass->setEnabled(true);
1104
le_pass->setFocus();
1108
void AccountRemoveDlg::remove()
1110
bool unreg = rb_removeAndUnreg->isChecked();
1113
if(le_pass->text() != d->acc.pass) {
1114
QMessageBox::information(this, tr("Error"), tr("Password does not match account. Please try again."));
1115
le_pass->setFocus();
1120
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"));
1130
gb_account->setEnabled(false);
1131
pb_remove->setEnabled(false);
1134
j.setResource(d->acc.resource);
1135
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);
1138
void AccountRemoveDlg::client_handshaken()
1140
// try to unregister an account
1141
JT_Register *reg = new JT_Register(client->client()->rootTask());
1142
connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
1147
void AccountRemoveDlg::client_error()
1150
gb_account->setEnabled(true);
1151
pb_remove->setEnabled(true);
1154
void AccountRemoveDlg::unreg_finished()
1156
JT_Register *reg = (JT_Register *)sender();
1161
if(reg->success()) {
1162
QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
1166
else if(reg->statusCode() != Task::ErrDisc) {
1167
gb_account->setEnabled(true);
1168
pb_remove->setEnabled(true);
1169
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error unregistering the account.\nReason: %1")).arg(reg->statusString()));