27
26
#include<qcheckbox.h>
29
28
#include<qlayout.h>
32
static AccountManageDlg *accountmanage_ptr = 0;
34
AccountManageDlg::AccountManageDlg(JabSessionManager *_jsm, QWidget *parent, const char *name)
35
:AccountManageUI(parent, name, FALSE, WDestructiveClose)
37
setCaption(CAP(tr("Jabber Accounts")));
39
accountmanage_ptr = this;
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)
325
if(s || !pa->isActive() && !pa->eventQueue()->count()){
326
if(pa->enabled()!=s) pa->setEnabled(s);
330
QMessageBox::information(listView(), AccountManageDlg::tr("Error"), AccountManageDlg::tr("Unable to disable the account, as it is currently active."));
332
QMessageBox::information(listView(), AccountManageDlg::tr("Error"), AccountManageDlg::tr("Unable to disable the account, as it has pending events."));
344
AccountManageDlg::AccountManageDlg(PsiCon *_psi, const char *name)
345
:AccountManageUI(0, name, false, WDestructiveClose)
348
psi->dialogRegister(this);
350
setCaption(CAP(caption()));
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()));
45
358
connect(lv_accs, SIGNAL(doubleClicked(QListViewItem *)), SLOT(modify(QListViewItem *)));
47
connect(jsm, SIGNAL(sessionUpdate(JabSession *)), SLOT(sessionUpdate(JabSession *)));
49
lv_accs->setAllColumnsShowFocus(TRUE);
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);
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 *)));
364
lv_accs->setAllColumnsShowFocus(true);
365
lv_accs->setResizeMode(QListView::LastColumn);
367
PsiAccountListIt it(psi->accountList());
368
for(PsiAccount *pa; (pa = it.current()); ++it) {
369
new AccountManageItem(lv_accs, pa);
59
372
if(lv_accs->childCount() > 0)
60
lv_accs->setSelected(lv_accs->firstChild(), TRUE);
373
lv_accs->setSelected(lv_accs->firstChild(), true);
375
qlv_selectionChanged(0);
63
378
AccountManageDlg::~AccountManageDlg()
65
accountmanage_ptr = 0;
68
/* static */ AccountManageDlg *AccountManageDlg::find()
70
return accountmanage_ptr;
380
psi->dialogUnregister(this);
383
void AccountManageDlg::qlv_selectionChanged(QListViewItem *lvi)
385
AccountManageItem *i = (AccountManageItem *)lvi;
386
bool ok = i ? true: false;
388
pb_modify->setEnabled(ok);
389
pb_remove->setEnabled(ok);
392
void AccountManageDlg::add()
394
AccountAddDlg *w = new AccountAddDlg(psi, 0);
73
398
void AccountManageDlg::modify()
75
QListViewItem *lvi = lv_accs->currentItem();
400
modify(lv_accs->currentItem());
82
403
void AccountManageDlg::modify(QListViewItem *lvi)
84
signalModify(lvi->text(0));
87
void AccountManageDlg::updateEntry(JabSession *s)
405
AccountManageItem *i = (AccountManageItem *)lvi;
409
psi->modifyAccount(i->pa);
412
void AccountManageDlg::remove()
414
AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
418
if(i->pa->isActive()) {
419
QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
423
AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
425
if(n != QDialog::Accepted) {
430
psi->removeAccount(i->pa);
433
void AccountManageDlg::accountAdded(PsiAccount *pa)
435
new AccountManageItem(lv_accs, pa);
438
void AccountManageDlg::accountUpdated(PsiAccount *pa)
440
AccountManageItem *i;
90
441
QListViewItemIterator it(lv_accs);
91
for(; (i = (AccountViewItem *)it.current()) ; ++it) {
442
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
101
void AccountManageDlg::sessionUpdate(JabSession *s)
107
AccountViewItem::AccountViewItem(QListView *par, JabSession *_s)
115
void AccountViewItem::updateInfo()
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");
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)
127
setCaption(tr("Account Properties"));
128
setIcon(*pix_account);
130
resize(width(), sizeHint().height());
134
UserAccount &acc = *s->acc();
452
void AccountManageDlg::accountRemoved(PsiAccount *pa)
454
AccountManageItem *i;
455
QListViewItemIterator it(lv_accs);
456
for(; (i = (AccountManageItem *)it.current()) ; ++it) {
465
qlv_selectionChanged(lv_accs->currentItem());
469
//----------------------------------------------------------------------------
471
//----------------------------------------------------------------------------
472
AccountAddDlg::AccountAddDlg(PsiCon *_psi, QWidget *parent, const char *name)
473
:AccountAddUI(parent, name, false, WDestructiveClose)
476
psi->dialogRegister(this);
478
setCaption(CAP(caption()));
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 &)));
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."));
489
QString def = tr("Default");
494
PsiAccountListIt it(psi->accountList());
495
for(PsiAccount *pa; (pa = it.current()); ++it) {
496
if(aname == pa->name()) {
504
aname = def + '_' + QString::number(++n);
507
le_name->setText(aname);
511
AccountAddDlg::~AccountAddDlg()
513
psi->dialogUnregister(this);
516
void AccountAddDlg::add()
518
QString def = le_name->text();
523
PsiAccountListIt it(psi->accountList());
524
for(PsiAccount *pa; (pa = it.current()); ++it) {
525
if(aname == pa->name()) {
533
aname = def + '_' + QString::number(++n);
535
le_name->setText( aname );
537
if(ck_reg->isChecked()) {
538
AccountRegDlg *w = new AccountRegDlg(psi->proxy(), this);
540
if(n != QDialog::Accepted) {
546
QString pass = w->pass;
547
bool opt_host = w->opt_host;
548
QString host = w->sp_host;
549
int port = w->sp_port;
551
int proxy = w->proxy;
555
psi->createAccount(le_name->text(), jid, pass, opt_host, host, port, ssl, proxy);
558
psi->createAccount(le_name->text());
564
void AccountAddDlg::setAddButton(const QString &s)
566
pb_add->setEnabled(!s.isEmpty());
570
//----------------------------------------------------------------------------
572
//----------------------------------------------------------------------------
573
AccountModifyDlg::AccountModifyDlg(PsiAccount *_pa, QWidget *parent, const char *name)
574
:AccountModifyUI(parent, name, false, WDestructiveClose)
577
connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
578
pa->dialogRegister(this);
580
setCaption(CAP(caption()));
581
setIcon(IconsetFactory::icon("psi/account"));
583
const UserAccount &acc = pa->userAccount();
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()));
141
le_pass->setEnabled(FALSE);
143
pb_unreg->setEnabled(FALSE);
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)));
153
le_user->setText(acc.user);
155
ck_pass->setChecked(TRUE);
156
le_pass->setText(acc.pass);
592
le_pass->setEnabled(false);
593
le_host->setEnabled(false);
594
le_port->setEnabled(false);
596
gb_pgp->setEnabled(false);
597
connect(ck_pp, SIGNAL(toggled(bool)), SLOT(optpp_toggled(bool)));
598
le_pp->setEnabled(false);
600
connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
601
connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
603
le_name->setText(acc.name);
604
le_jid->setText(acc.jid);
606
ck_ssl->setChecked(acc.opt_ssl);
607
connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
610
ck_pass->setChecked(true);
611
le_pass->setText(acc.pass);
614
ck_host->setChecked(acc.opt_host);
615
le_host->setText(acc.host);
616
le_port->setText(QString::number(acc.port));
618
le_resource->setText(acc.resource);
619
le_priority->setText(QString::number(acc.priority));
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());
629
keyID = acc.pgpSecretKeyID;
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);
158
le_resource->setText(acc.resource);
159
le_priority->setText(QString::number(acc.priority));
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);
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);
644
if(le_name->text().isEmpty())
646
else if(le_jid->text().isEmpty())
166
649
pb_save->setFocus();
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 "
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 "
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>"));
717
resize(minimumSize());
172
720
AccountModifyDlg::~AccountModifyDlg()
176
/*static*/ AccountModifyDlg * AccountModifyDlg::find(const QString &accname)
178
return (AccountModifyDlg *)UniqueWindowBank::find("AccountModifyDlg", accname.lower());
722
pa->dialogUnregister(this);
725
void AccountModifyDlg::updateUserID()
727
if(keyID.isEmpty()) {
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) {
743
setKeyID(true, tr("Unknown Key: %1").arg(keyID.left(8)));
745
setKeyID(true, userID);
749
void AccountModifyDlg::setKeyID(bool b, const QString &s)
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);
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);
769
void AccountModifyDlg::pgpToggled(bool b)
772
gb_pgp->setEnabled(true);
775
gb_pgp->setEnabled(false);
776
ck_pp->setChecked(false);
781
void AccountModifyDlg::optpp_toggled(bool b)
784
le_pp->setEnabled(true);
786
le_pp->setEnabled(false);
791
void AccountModifyDlg::setPassword(const QString &pw)
793
le_pass->setText(pw);
181
796
void AccountModifyDlg::sslToggled(bool on)
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);
189
804
le_port->setText(on ? "5223": "5222");
807
void AccountModifyDlg::hostToggled(bool on)
809
le_host->setEnabled(on);
810
le_port->setEnabled(on);
813
void AccountModifyDlg::chooseKey()
815
OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
816
PGPKeyDlg *w = new PGPKeyDlg(list, keyID, this);
817
w->setCaption(tr("Secret Key"));
820
if(r == QDialog::Accepted)
827
ck_pp->setChecked(false);
831
void AccountModifyDlg::clearKey()
837
void AccountModifyDlg::detailsVCard()
842
void AccountModifyDlg::detailsChangePW()
192
847
void AccountModifyDlg::save()
194
if(s->serv()->isActive()) {
195
QMessageBox::information(this, tr("Error"), tr("Please disconnect from this account before trying to modify it."));
199
UserAccount &acc = *s->acc();
201
QString before = acc.name.lower();
202
QString after = le_name->text().lower();
203
if(after.length() == 0) {
849
UserAccount acc = pa->userAccount();
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."));
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."));
215
bool newUser = FALSE;
216
if(acc.user != le_user->text() || acc.host != le_host->text() || acc.port != le_port->text().toInt()) {
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>."));
862
// do not allow duplicate account names
863
QString def = le_name->text();
867
PsiAccountListIt it(pa->psi()->accountList());
868
for(PsiAccount *pa; (pa = it.current()); ++it)
869
if(aname == pa->name())
873
if ( aname == acc.name )
877
aname = def + '_' + QString::number(++n);
878
le_name->setText( aname );
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();
227
884
acc.pass = le_pass->text();
888
acc.opt_host = ck_host->isChecked();
889
acc.host = le_host->text();
890
acc.port = le_port->text().toInt();
230
892
acc.resource = le_resource->text();
231
893
acc.priority = le_priority->text().toInt();
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();
901
acc.opt_ignoreSSLWarnings = ck_ignoreSSLWarnings->isChecked();
902
acc.dtProxy = le_dtProxy->text();
904
acc.pgpSecretKeyID = keyID;
905
acc.opt_passphrase = ck_pp->isChecked();
906
if(acc.opt_passphrase)
907
acc.pgpPassphrase = le_pp->text();
909
acc.pgpPassphrase = "";
911
acc.proxy_index = pc->currentItem();
914
QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
917
pa->setUserAccount(acc);
243
void AccountModifyDlg::doRegister()
923
//----------------------------------------------------------------------------
925
//----------------------------------------------------------------------------
926
AccountRegDlg::AccountRegDlg(ProxyManager *_proxyman, QWidget *parent, const char *name)
927
:AccountRegUI(parent, name, false)
929
setCaption(CAP(caption()));
931
le_host->setEnabled(false);
932
le_port->setEnabled(false);
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)));
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);
944
le_port->setText("5222");
947
client = new MiniClient;
948
connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
949
connect(client, SIGNAL(error()), SLOT(client_error()));
952
AccountRegDlg::~AccountRegDlg()
957
/*void AccountRegDlg::closeEvent(QCloseEvent *e)
963
void AccountRegDlg::done(int r)
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"));
973
void AccountRegDlg::sslToggled(bool on)
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);
981
le_port->setText(on ? "5223": "5222");
984
void AccountRegDlg::hostToggled(bool on)
986
le_host->setEnabled(on);
987
le_port->setEnabled(on);
990
void AccountRegDlg::reg()
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>."));
245
999
if(le_pass->text().isEmpty()) {
246
QMessageBox::warning(this, tr("Error"), tr("You must specify a password for the new account."));
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"
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"
260
"Click on \"Yes\" to attempt to register an account.\n"),
261
tr("&Yes"), tr("&No"));
1000
QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can register."));
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();
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();
1022
client->connectToServer(jid, ssl, opt_host ? sp_host : QString(), sp_port, proxyman, pc->currentItem(), 0);
1025
void AccountRegDlg::client_handshaken()
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);
1034
void AccountRegDlg::client_error()
1040
void AccountRegDlg::reg_finished()
1042
JT_Register *reg = (JT_Register *)sender();
1047
if(reg->success()) {
1048
QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
1049
proxy = pc->currentItem();
1053
else if(reg->statusCode() != Task::ErrDisc) {
1055
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(reg->statusString()));
1059
void AccountRegDlg::block()
1061
gb_account->setEnabled(false);
1062
gb_proxy->setEnabled(false);
1063
gb_advanced->setEnabled(false);
1064
pb_reg->setEnabled(false);
1067
void AccountRegDlg::unblock()
1069
gb_account->setEnabled(true);
1070
gb_proxy->setEnabled(true);
1071
gb_advanced->setEnabled(true);
1072
pb_reg->setEnabled(true);
1077
//----------------------------------------------------------------------------
1079
//----------------------------------------------------------------------------
1080
class AccountRemoveDlg::Private
1087
ProxyManager *proxyman;
1090
AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent, const char *name)
1091
:AccountRemoveUI(parent, name, false)
1095
d->proxyman = proxyman;
1097
setCaption(CAP(caption()));
1099
connect(pb_close, SIGNAL(clicked()), SLOT(close()));
1100
connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
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);
1109
pb_close->setFocus();
1111
client = new MiniClient;
1112
connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
1113
connect(client, SIGNAL(error()), SLOT(client_error()));
1116
AccountRemoveDlg::~AccountRemoveDlg()
1124
/*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
1130
void AccountRemoveDlg::done(int r)
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"));
1140
void AccountRemoveDlg::bg_clicked(int x)
1143
lb_pass->setEnabled(false);
1144
le_pass->setEnabled(false);
1147
lb_pass->setEnabled(true);
1148
le_pass->setEnabled(true);
1149
le_pass->setFocus();
1153
void AccountRemoveDlg::remove()
1155
bool unreg = rb_removeAndUnreg->isChecked();
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();
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"));
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();
273
// we should probably verify they are ok
275
// perform a registration
276
AccountRegisterDlg::reg(this, host, port, opt_ssl, user, pass);
280
AccountRegisterDlg::AccountRegisterDlg(QWidget *par, const char *name)
281
:QDialog(par, name, TRUE)
283
setCaption(tr("Account Registration"));
285
QVBoxLayout *vb = new QVBoxLayout(this, 4);
286
QHBoxLayout *hb = new QHBoxLayout(vb);
287
QLabel *l = new QLabel(tr("Registering account..."), this);
289
busy = new BusyWidget(this);
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();
297
connect(jab, SIGNAL(accRegisterFinished(bool, const QString &)), SLOT(accRegisterFinished(bool, const QString &)));
298
connect(jab, SIGNAL(error(JabError *)), SLOT(jab_error(JabError *)));
301
AccountRegisterDlg::~AccountRegisterDlg()
306
void AccountRegisterDlg::closeEvent(QCloseEvent *e)
310
QDialog::closeEvent(e);
313
void AccountRegisterDlg::start(const QString &host, int port, bool opt_ssl, const QString &user, const QString &pass)
317
jab->setSSLEnabled(opt_ssl);
318
jab->setHost(host, port);
319
jab->setAccount(user, pass, "");
323
void AccountRegisterDlg::stop()
328
void AccountRegisterDlg::cancel()
334
bool AccountRegisterDlg::reg(QWidget *par, const QString &host, int port, bool opt_ssl, const QString &user, const QString &pass)
336
AccountRegisterDlg *w = new AccountRegisterDlg(par);
337
w->start(host, port, opt_ssl, user, pass);
344
void AccountRegisterDlg::accRegisterFinished(bool ok, const QString &errMsg)
350
QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
352
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(errMsg));
357
void AccountRegisterDlg::jab_error(JabError *err)
362
QMessageBox::critical(this, tr("Error"), QString(tr("There was an error communicating with the Jabber server.\nReason: %1")).arg(err->msg));
1175
gb_account->setEnabled(false);
1176
pb_remove->setEnabled(false);
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);
1183
void AccountRemoveDlg::client_handshaken()
1185
// try to unregister an account
1186
JT_Register *reg = new JT_Register(client->client()->rootTask());
1187
connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
1192
void AccountRemoveDlg::client_error()
1195
gb_account->setEnabled(true);
1196
pb_remove->setEnabled(true);
1199
void AccountRemoveDlg::unreg_finished()
1201
JT_Register *reg = (JT_Register *)sender();
1206
if(reg->success()) {
1207
QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
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()));