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 |
|
---|
21 | #include"accountdlg.h"
|
---|
22 |
|
---|
23 | #include<qpushbutton.h>
|
---|
24 | #include<qlistview.h>
|
---|
25 | #include<qlineedit.h>
|
---|
26 | #include<qcheckbox.h>
|
---|
27 | #include<qlabel.h>
|
---|
28 | #include<qlayout.h>
|
---|
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 (pa->enabled()!=s)
|
---|
325 | pa->setEnabled(s);
|
---|
326 | updateInfo();
|
---|
327 | }
|
---|
328 |
|
---|
329 | int rtti() const
|
---|
330 | {
|
---|
331 | return 8109;
|
---|
332 | }
|
---|
333 |
|
---|
334 | PsiAccount *pa;
|
---|
335 | };
|
---|
336 |
|
---|
337 | AccountManageDlg::AccountManageDlg(PsiCon *_psi, const char *name)
|
---|
338 | :AccountManageUI(0, name, false, WDestructiveClose)
|
---|
339 | {
|
---|
340 | psi = _psi;
|
---|
341 | psi->dialogRegister(this);
|
---|
342 |
|
---|
343 | setCaption(CAP(caption()));
|
---|
344 |
|
---|
345 | // setup signals
|
---|
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()));
|
---|
350 |
|
---|
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 *)));
|
---|
356 |
|
---|
357 | lv_accs->setAllColumnsShowFocus(true);
|
---|
358 | lv_accs->setResizeMode(QListView::LastColumn);
|
---|
359 |
|
---|
360 | PsiAccountListIt it(psi->accountList());
|
---|
361 | for(PsiAccount *pa; (pa = it.current()); ++it) {
|
---|
362 | new AccountManageItem(lv_accs, pa);
|
---|
363 | }
|
---|
364 |
|
---|
365 | if(lv_accs->childCount() > 0)
|
---|
366 | lv_accs->setSelected(lv_accs->firstChild(), true);
|
---|
367 | else
|
---|
368 | qlv_selectionChanged(0);
|
---|
369 | }
|
---|
370 |
|
---|
371 | AccountManageDlg::~AccountManageDlg()
|
---|
372 | {
|
---|
373 | psi->dialogUnregister(this);
|
---|
374 | }
|
---|
375 |
|
---|
376 | void AccountManageDlg::qlv_selectionChanged(QListViewItem *lvi)
|
---|
377 | {
|
---|
378 | AccountManageItem *i = (AccountManageItem *)lvi;
|
---|
379 | bool ok = i ? true: false;
|
---|
380 |
|
---|
381 | pb_modify->setEnabled(ok);
|
---|
382 | pb_remove->setEnabled(ok);
|
---|
383 | }
|
---|
384 |
|
---|
385 | void AccountManageDlg::add()
|
---|
386 | {
|
---|
387 | AccountAddDlg *w = new AccountAddDlg(psi, 0);
|
---|
388 | w->show();
|
---|
389 | }
|
---|
390 |
|
---|
391 | void AccountManageDlg::modify()
|
---|
392 | {
|
---|
393 | modify(lv_accs->currentItem());
|
---|
394 | }
|
---|
395 |
|
---|
396 | void AccountManageDlg::modify(QListViewItem *lvi)
|
---|
397 | {
|
---|
398 | AccountManageItem *i = (AccountManageItem *)lvi;
|
---|
399 | if(!i)
|
---|
400 | return;
|
---|
401 |
|
---|
402 | psi->modifyAccount(i->pa);
|
---|
403 | }
|
---|
404 |
|
---|
405 | void AccountManageDlg::remove()
|
---|
406 | {
|
---|
407 | AccountManageItem *i = (AccountManageItem *)lv_accs->currentItem();
|
---|
408 | if(!i)
|
---|
409 | return;
|
---|
410 |
|
---|
411 | if(i->pa->isActive()) {
|
---|
412 | QMessageBox::information(this, tr("Error"), tr("Unable to remove the account, as it is currently active."));
|
---|
413 | return;
|
---|
414 | }
|
---|
415 |
|
---|
416 | AccountRemoveDlg *w = new AccountRemoveDlg(psi->proxy(), i->pa->userAccount());
|
---|
417 | int n = w->exec();
|
---|
418 | if(n != QDialog::Accepted) {
|
---|
419 | delete w;
|
---|
420 | return;
|
---|
421 | }
|
---|
422 | delete w;
|
---|
423 | psi->removeAccount(i->pa);
|
---|
424 | }
|
---|
425 |
|
---|
426 | void AccountManageDlg::accountAdded(PsiAccount *pa)
|
---|
427 | {
|
---|
428 | new AccountManageItem(lv_accs, pa);
|
---|
429 | }
|
---|
430 |
|
---|
431 | void AccountManageDlg::accountUpdated(PsiAccount *pa)
|
---|
432 | {
|
---|
433 | AccountManageItem *i;
|
---|
434 | QListViewItemIterator it(lv_accs);
|
---|
435 | for(; (i = (AccountManageItem *)it.current()) ; ++it) {
|
---|
436 | if(i->pa == pa)
|
---|
437 | break;
|
---|
438 | }
|
---|
439 | if(!i)
|
---|
440 | return;
|
---|
441 |
|
---|
442 | i->updateInfo();
|
---|
443 | }
|
---|
444 |
|
---|
445 | void AccountManageDlg::accountRemoved(PsiAccount *pa)
|
---|
446 | {
|
---|
447 | AccountManageItem *i;
|
---|
448 | QListViewItemIterator it(lv_accs);
|
---|
449 | for(; (i = (AccountManageItem *)it.current()) ; ++it) {
|
---|
450 | if(i->pa == pa)
|
---|
451 | break;
|
---|
452 | }
|
---|
453 | if(!i)
|
---|
454 | return;
|
---|
455 |
|
---|
456 | delete i;
|
---|
457 |
|
---|
458 | qlv_selectionChanged(lv_accs->currentItem());
|
---|
459 | }
|
---|
460 |
|
---|
461 |
|
---|
462 | //----------------------------------------------------------------------------
|
---|
463 | // AccountAddDlg
|
---|
464 | //----------------------------------------------------------------------------
|
---|
465 | AccountAddDlg::AccountAddDlg(PsiCon *_psi, QWidget *parent, const char *name)
|
---|
466 | :AccountAddUI(parent, name, false, WDestructiveClose)
|
---|
467 | {
|
---|
468 | psi = _psi;
|
---|
469 | psi->dialogRegister(this);
|
---|
470 |
|
---|
471 | setCaption(CAP(caption()));
|
---|
472 |
|
---|
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 &)));
|
---|
476 |
|
---|
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."));
|
---|
481 |
|
---|
482 | QString def = tr("Default");
|
---|
483 | QString aname = def;
|
---|
484 | int n = 0;
|
---|
485 | while(1) {
|
---|
486 | bool taken = false;
|
---|
487 | PsiAccountListIt it(psi->accountList());
|
---|
488 | for(PsiAccount *pa; (pa = it.current()); ++it) {
|
---|
489 | if(aname == pa->name()) {
|
---|
490 | taken = true;
|
---|
491 | break;
|
---|
492 | }
|
---|
493 | }
|
---|
494 |
|
---|
495 | if(!taken)
|
---|
496 | break;
|
---|
497 | aname = def + '_' + QString::number(++n);
|
---|
498 | }
|
---|
499 |
|
---|
500 | le_name->setText(aname);
|
---|
501 | le_name->setFocus();
|
---|
502 | }
|
---|
503 |
|
---|
504 | AccountAddDlg::~AccountAddDlg()
|
---|
505 | {
|
---|
506 | psi->dialogUnregister(this);
|
---|
507 | }
|
---|
508 |
|
---|
509 | void AccountAddDlg::add()
|
---|
510 | {
|
---|
511 | QString def = le_name->text();
|
---|
512 | QString aname = def;
|
---|
513 | int n = 0;
|
---|
514 | while(1) {
|
---|
515 | bool taken = false;
|
---|
516 | PsiAccountListIt it(psi->accountList());
|
---|
517 | for(PsiAccount *pa; (pa = it.current()); ++it) {
|
---|
518 | if(aname == pa->name()) {
|
---|
519 | taken = true;
|
---|
520 | break;
|
---|
521 | }
|
---|
522 | }
|
---|
523 |
|
---|
524 | if(!taken)
|
---|
525 | break;
|
---|
526 | aname = def + '_' + QString::number(++n);
|
---|
527 | }
|
---|
528 | le_name->setText( aname );
|
---|
529 |
|
---|
530 | if(ck_reg->isChecked()) {
|
---|
531 | AccountRegDlg *w = new AccountRegDlg(psi->proxy(), this);
|
---|
532 | int n = w->exec();
|
---|
533 | if(n != QDialog::Accepted) {
|
---|
534 | delete w;
|
---|
535 | return;
|
---|
536 | }
|
---|
537 |
|
---|
538 | Jid jid = w->jid;
|
---|
539 | QString pass = w->pass;
|
---|
540 | bool opt_host = w->opt_host;
|
---|
541 | QString host = w->sp_host;
|
---|
542 | int port = w->sp_port;
|
---|
543 | bool ssl = w->ssl;
|
---|
544 | int proxy = w->proxy;
|
---|
545 |
|
---|
546 | delete w;
|
---|
547 |
|
---|
548 | psi->createAccount(le_name->text(), jid, pass, opt_host, host, port, ssl, proxy);
|
---|
549 | }
|
---|
550 | else {
|
---|
551 | psi->createAccount(le_name->text());
|
---|
552 | }
|
---|
553 |
|
---|
554 | close();
|
---|
555 | }
|
---|
556 |
|
---|
557 | void AccountAddDlg::setAddButton(const QString &s)
|
---|
558 | {
|
---|
559 | pb_add->setEnabled(!s.isEmpty());
|
---|
560 | }
|
---|
561 |
|
---|
562 |
|
---|
563 | //----------------------------------------------------------------------------
|
---|
564 | // AccountModifyDlg
|
---|
565 | //----------------------------------------------------------------------------
|
---|
566 | AccountModifyDlg::AccountModifyDlg(PsiAccount *_pa, QWidget *parent, const char *name)
|
---|
567 | :AccountModifyUI(parent, name, false, WDestructiveClose)
|
---|
568 | {
|
---|
569 | pa = _pa;
|
---|
570 | connect(pa->psi(), SIGNAL(pgpToggled(bool)), SLOT(pgpToggled(bool)));
|
---|
571 | pa->dialogRegister(this);
|
---|
572 |
|
---|
573 | setCaption(CAP(caption()));
|
---|
574 | setIcon(IconsetFactory::icon("psi/account"));
|
---|
575 |
|
---|
576 | const UserAccount &acc = pa->userAccount();
|
---|
577 |
|
---|
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()));
|
---|
583 |
|
---|
584 | le_pass->setEnabled(true);
|
---|
585 | le_host->setEnabled(false);
|
---|
586 | le_port->setEnabled(false);
|
---|
587 |
|
---|
588 | gb_pgp->setEnabled(false);
|
---|
589 |
|
---|
590 | connect(pb_vcard, SIGNAL(clicked()), SLOT(detailsVCard()));
|
---|
591 | connect(pb_changepw, SIGNAL(clicked()), SLOT(detailsChangePW()));
|
---|
592 |
|
---|
593 | le_name->setText(acc.name);
|
---|
594 | le_jid->setText(acc.jid);
|
---|
595 |
|
---|
596 | ck_ssl->setChecked(acc.opt_ssl);
|
---|
597 | connect(ck_ssl, SIGNAL(toggled(bool)), SLOT(sslToggled(bool)));
|
---|
598 |
|
---|
599 | if (acc.opt_pass)
|
---|
600 | le_pass->setText(acc.pass);
|
---|
601 |
|
---|
602 | ck_host->setChecked(acc.opt_host);
|
---|
603 | le_host->setText(acc.host);
|
---|
604 | le_port->setText(QString::number(acc.port));
|
---|
605 |
|
---|
606 | le_resource->setText(acc.resource);
|
---|
607 | le_priority->setText(QString::number(acc.priority));
|
---|
608 |
|
---|
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());
|
---|
616 |
|
---|
617 | keyID = acc.pgpSecretKeyID;
|
---|
618 | updateUserID();
|
---|
619 | if(pa->psi()->pgp()) {
|
---|
620 | gb_pgp->setEnabled(true);
|
---|
621 | }
|
---|
622 |
|
---|
623 | pc = pa->psi()->proxy()->createProxyChooser(gb_proxy);
|
---|
624 | replaceWidget(lb_proxychooser, pc);
|
---|
625 | pc->setCurrentItem(acc.proxy_index);
|
---|
626 |
|
---|
627 | if(le_name->text().isEmpty())
|
---|
628 | le_name->setFocus();
|
---|
629 | else if(le_jid->text().isEmpty())
|
---|
630 | le_jid->setFocus();
|
---|
631 | else
|
---|
632 | pb_save->setFocus();
|
---|
633 |
|
---|
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 "
|
---|
641 | "attacks."));
|
---|
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 "
|
---|
670 | "Psi homepage."));
|
---|
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>"));
|
---|
693 |
|
---|
694 | resize(minimumSize());
|
---|
695 | }
|
---|
696 |
|
---|
697 | AccountModifyDlg::~AccountModifyDlg()
|
---|
698 | {
|
---|
699 | pa->dialogUnregister(this);
|
---|
700 | }
|
---|
701 |
|
---|
702 | void AccountModifyDlg::updateUserID()
|
---|
703 | {
|
---|
704 | if(keyID.isEmpty()) {
|
---|
705 | setKeyID(false);
|
---|
706 | }
|
---|
707 | else {
|
---|
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) {
|
---|
714 | userID = k.userID();
|
---|
715 | break;
|
---|
716 | }
|
---|
717 | }
|
---|
718 | }
|
---|
719 | if(userID.isNull())
|
---|
720 | setKeyID(true, tr("Unknown Key: %1").arg(keyID.left(8)));
|
---|
721 | else
|
---|
722 | setKeyID(true, userID);
|
---|
723 | }
|
---|
724 | }
|
---|
725 |
|
---|
726 | void AccountModifyDlg::setKeyID(bool b, const QString &s)
|
---|
727 | {
|
---|
728 | if(b) {
|
---|
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);
|
---|
734 | }
|
---|
735 | else {
|
---|
736 | lb_keyname->setText(tr("No Key Selected"));
|
---|
737 | lb_keyicon->setEnabled(false);
|
---|
738 | lb_keyname->setEnabled(false);
|
---|
739 | pb_keyclear->setEnabled(false);
|
---|
740 | }
|
---|
741 | }
|
---|
742 |
|
---|
743 | void AccountModifyDlg::pgpToggled(bool b)
|
---|
744 | {
|
---|
745 | if(b) {
|
---|
746 | gb_pgp->setEnabled(true);
|
---|
747 | }
|
---|
748 | else {
|
---|
749 | gb_pgp->setEnabled(false);
|
---|
750 | }
|
---|
751 | updateUserID();
|
---|
752 | }
|
---|
753 |
|
---|
754 | void AccountModifyDlg::setPassword(const QString &pw)
|
---|
755 | {
|
---|
756 | if (!le_pass->text().isEmpty())
|
---|
757 | le_pass->setText(pw);
|
---|
758 | }
|
---|
759 |
|
---|
760 | void AccountModifyDlg::sslToggled(bool on)
|
---|
761 | {
|
---|
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);
|
---|
765 | return;
|
---|
766 | }
|
---|
767 |
|
---|
768 | le_port->setText(on ? "5223": "5222");
|
---|
769 | }
|
---|
770 |
|
---|
771 | void AccountModifyDlg::hostToggled(bool on)
|
---|
772 | {
|
---|
773 | le_host->setEnabled(on);
|
---|
774 | le_port->setEnabled(on);
|
---|
775 | }
|
---|
776 |
|
---|
777 | void AccountModifyDlg::chooseKey()
|
---|
778 | {
|
---|
779 | OpenPGP::KeyList list = pa->psi()->pgp()->secretKeys();
|
---|
780 | PGPKeyDlg *w = new PGPKeyDlg(list, keyID, this);
|
---|
781 | w->setCaption(tr("Secret Key"));
|
---|
782 | int r = w->exec();
|
---|
783 | QString key;
|
---|
784 | if(r == QDialog::Accepted)
|
---|
785 | key = w->keyID();
|
---|
786 | delete w;
|
---|
787 |
|
---|
788 | if(!key.isEmpty()) {
|
---|
789 | keyID = key;
|
---|
790 | updateUserID();
|
---|
791 | }
|
---|
792 | }
|
---|
793 |
|
---|
794 | void AccountModifyDlg::clearKey()
|
---|
795 | {
|
---|
796 | setKeyID(false);
|
---|
797 | keyID = "";
|
---|
798 | }
|
---|
799 |
|
---|
800 | void AccountModifyDlg::detailsVCard()
|
---|
801 | {
|
---|
802 | pa->changeVCard();
|
---|
803 | }
|
---|
804 |
|
---|
805 | void AccountModifyDlg::detailsChangePW()
|
---|
806 | {
|
---|
807 | pa->changePW();
|
---|
808 | }
|
---|
809 |
|
---|
810 | void AccountModifyDlg::save()
|
---|
811 | {
|
---|
812 | UserAccount acc = pa->userAccount();
|
---|
813 |
|
---|
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."));
|
---|
816 | return;
|
---|
817 | }
|
---|
818 |
|
---|
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>."));
|
---|
822 | return;
|
---|
823 | }
|
---|
824 |
|
---|
825 | // do not allow duplicate account names
|
---|
826 | QString def = le_name->text();
|
---|
827 | QString aname = def;
|
---|
828 | int n = 0;
|
---|
829 | {
|
---|
830 | PsiAccountListIt it(pa->psi()->accountList());
|
---|
831 | for(PsiAccount *pa; (pa = it.current()); ++it)
|
---|
832 | if(aname == pa->name())
|
---|
833 | n++;
|
---|
834 | }
|
---|
835 |
|
---|
836 | if ( aname == acc.name )
|
---|
837 | n--;
|
---|
838 |
|
---|
839 | if ( n )
|
---|
840 | aname = def + '_' + QString::number(++n);
|
---|
841 | le_name->setText( aname );
|
---|
842 |
|
---|
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();
|
---|
847 |
|
---|
848 | acc.opt_host = ck_host->isChecked();
|
---|
849 | acc.host = le_host->text();
|
---|
850 | acc.port = le_port->text().toInt();
|
---|
851 |
|
---|
852 | acc.resource = le_resource->text();
|
---|
853 | acc.priority = le_priority->text().toInt();
|
---|
854 |
|
---|
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();
|
---|
863 |
|
---|
864 | acc.pgpSecretKeyID = keyID;
|
---|
865 |
|
---|
866 | acc.proxy_index = pc->currentItem();
|
---|
867 |
|
---|
868 | if(pa->isActive()) {
|
---|
869 | QMessageBox::information(this, tr("Warning"), tr("This account is currently active, so certain changes may not take effect until the next login."));
|
---|
870 | }
|
---|
871 |
|
---|
872 | pa->setUserAccount(acc);
|
---|
873 |
|
---|
874 | accept();
|
---|
875 | }
|
---|
876 |
|
---|
877 |
|
---|
878 | //----------------------------------------------------------------------------
|
---|
879 | // AccountRegDlg
|
---|
880 | //----------------------------------------------------------------------------
|
---|
881 | AccountRegDlg::AccountRegDlg(ProxyManager *_proxyman, QWidget *parent, const char *name)
|
---|
882 | :AccountRegUI(parent, name, false)
|
---|
883 | {
|
---|
884 | setCaption(CAP(caption()));
|
---|
885 |
|
---|
886 | le_host->setEnabled(false);
|
---|
887 | le_port->setEnabled(false);
|
---|
888 |
|
---|
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)));
|
---|
892 |
|
---|
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);
|
---|
898 |
|
---|
899 | le_port->setText("5222");
|
---|
900 | le_host->setFocus();
|
---|
901 |
|
---|
902 | client = new MiniClient;
|
---|
903 | connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
|
---|
904 | connect(client, SIGNAL(error()), SLOT(client_error()));
|
---|
905 | }
|
---|
906 |
|
---|
907 | AccountRegDlg::~AccountRegDlg()
|
---|
908 | {
|
---|
909 | delete client;
|
---|
910 | }
|
---|
911 |
|
---|
912 | /*void AccountRegDlg::closeEvent(QCloseEvent *e)
|
---|
913 | {
|
---|
914 | e->ignore();
|
---|
915 | reject();
|
---|
916 | }*/
|
---|
917 |
|
---|
918 | void AccountRegDlg::done(int r)
|
---|
919 | {
|
---|
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"));
|
---|
922 | if(n != 0)
|
---|
923 | return;
|
---|
924 | }
|
---|
925 | QDialog::done(r);
|
---|
926 | }
|
---|
927 |
|
---|
928 | void AccountRegDlg::sslToggled(bool on)
|
---|
929 | {
|
---|
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);
|
---|
933 | return;
|
---|
934 | }
|
---|
935 |
|
---|
936 | le_port->setText(on ? "5223": "5222");
|
---|
937 | }
|
---|
938 |
|
---|
939 | void AccountRegDlg::hostToggled(bool on)
|
---|
940 | {
|
---|
941 | le_host->setEnabled(on);
|
---|
942 | le_port->setEnabled(on);
|
---|
943 | }
|
---|
944 |
|
---|
945 | void AccountRegDlg::reg()
|
---|
946 | {
|
---|
947 | // sanity check
|
---|
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>."));
|
---|
951 | return;
|
---|
952 | }
|
---|
953 |
|
---|
954 | if(le_pass->text().isEmpty()) {
|
---|
955 | QMessageBox::information(this, tr("Error"), tr("You must fill out the fields properly before you can register."));
|
---|
956 | return;
|
---|
957 | }
|
---|
958 |
|
---|
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("");
|
---|
963 | le_pass->setFocus();
|
---|
964 | return;
|
---|
965 | }
|
---|
966 |
|
---|
967 | busy->start();
|
---|
968 | block();
|
---|
969 |
|
---|
970 | jid = j;
|
---|
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();
|
---|
976 |
|
---|
977 | client->connectToServer(jid, ssl, opt_host ? sp_host : QString(), sp_port, proxyman, pc->currentItem(), 0);
|
---|
978 | }
|
---|
979 |
|
---|
980 | void AccountRegDlg::client_handshaken()
|
---|
981 | {
|
---|
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);
|
---|
986 | reg->go(true);
|
---|
987 | }
|
---|
988 |
|
---|
989 | void AccountRegDlg::client_error()
|
---|
990 | {
|
---|
991 | busy->stop();
|
---|
992 | unblock();
|
---|
993 | }
|
---|
994 |
|
---|
995 | void AccountRegDlg::reg_finished()
|
---|
996 | {
|
---|
997 | JT_Register *reg = (JT_Register *)sender();
|
---|
998 |
|
---|
999 | client->close();
|
---|
1000 | busy->stop();
|
---|
1001 |
|
---|
1002 | if(reg->success()) {
|
---|
1003 | QMessageBox::information(this, tr("Success"), tr("The account was registered successfully."));
|
---|
1004 | proxy = pc->currentItem();
|
---|
1005 | accept();
|
---|
1006 | return;
|
---|
1007 | }
|
---|
1008 | else if(reg->statusCode() != Task::ErrDisc) {
|
---|
1009 | unblock();
|
---|
1010 | QMessageBox::critical(this, tr("Error"), QString(tr("There was an error registering the account.\nReason: %1")).arg(reg->statusString()));
|
---|
1011 | }
|
---|
1012 | }
|
---|
1013 |
|
---|
1014 | void AccountRegDlg::block()
|
---|
1015 | {
|
---|
1016 | gb_account->setEnabled(false);
|
---|
1017 | gb_proxy->setEnabled(false);
|
---|
1018 | gb_advanced->setEnabled(false);
|
---|
1019 | pb_reg->setEnabled(false);
|
---|
1020 | }
|
---|
1021 |
|
---|
1022 | void AccountRegDlg::unblock()
|
---|
1023 | {
|
---|
1024 | gb_account->setEnabled(true);
|
---|
1025 | gb_proxy->setEnabled(true);
|
---|
1026 | gb_advanced->setEnabled(true);
|
---|
1027 | pb_reg->setEnabled(true);
|
---|
1028 | le_jid->setFocus();
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 |
|
---|
1032 | //----------------------------------------------------------------------------
|
---|
1033 | // AccountRemoveDlg
|
---|
1034 | //----------------------------------------------------------------------------
|
---|
1035 | class AccountRemoveDlg::Private
|
---|
1036 | {
|
---|
1037 | public:
|
---|
1038 | Private() {}
|
---|
1039 |
|
---|
1040 | UserAccount acc;
|
---|
1041 | QButtonGroup *bg;
|
---|
1042 | ProxyManager *proxyman;
|
---|
1043 | };
|
---|
1044 |
|
---|
1045 | AccountRemoveDlg::AccountRemoveDlg(ProxyManager *proxyman, const UserAccount &acc, QWidget *parent, const char *name)
|
---|
1046 | :AccountRemoveUI(parent, name, false)
|
---|
1047 | {
|
---|
1048 | d = new Private;
|
---|
1049 | d->acc = acc;
|
---|
1050 | d->proxyman = proxyman;
|
---|
1051 |
|
---|
1052 | setCaption(CAP(caption()));
|
---|
1053 |
|
---|
1054 | connect(pb_close, SIGNAL(clicked()), SLOT(close()));
|
---|
1055 | connect(pb_remove, SIGNAL(clicked()), SLOT(remove()));
|
---|
1056 |
|
---|
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);
|
---|
1062 | bg_clicked(0);
|
---|
1063 |
|
---|
1064 | pb_close->setFocus();
|
---|
1065 |
|
---|
1066 | client = new MiniClient;
|
---|
1067 | connect(client, SIGNAL(handshaken()), SLOT(client_handshaken()));
|
---|
1068 | connect(client, SIGNAL(error()), SLOT(client_error()));
|
---|
1069 | }
|
---|
1070 |
|
---|
1071 | AccountRemoveDlg::~AccountRemoveDlg()
|
---|
1072 | {
|
---|
1073 | delete client;
|
---|
1074 |
|
---|
1075 | delete d->bg;
|
---|
1076 | delete d;
|
---|
1077 | }
|
---|
1078 |
|
---|
1079 | /*void AccountRemoveDlg::closeEvent(QCloseEvent *e)
|
---|
1080 | {
|
---|
1081 | e->ignore();
|
---|
1082 | reject();
|
---|
1083 | }*/
|
---|
1084 |
|
---|
1085 | void AccountRemoveDlg::done(int r)
|
---|
1086 | {
|
---|
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"));
|
---|
1089 | if(n != 0)
|
---|
1090 | return;
|
---|
1091 | }
|
---|
1092 | QDialog::done(r);
|
---|
1093 | }
|
---|
1094 |
|
---|
1095 | void AccountRemoveDlg::bg_clicked(int x)
|
---|
1096 | {
|
---|
1097 | if(x == 0) {
|
---|
1098 | lb_pass->setEnabled(false);
|
---|
1099 | le_pass->setEnabled(false);
|
---|
1100 | }
|
---|
1101 | else if(x == 1) {
|
---|
1102 | lb_pass->setEnabled(true);
|
---|
1103 | le_pass->setEnabled(true);
|
---|
1104 | le_pass->setFocus();
|
---|
1105 | }
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | void AccountRemoveDlg::remove()
|
---|
1109 | {
|
---|
1110 | bool unreg = rb_removeAndUnreg->isChecked();
|
---|
1111 |
|
---|
1112 | if(unreg) {
|
---|
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();
|
---|
1116 | return;
|
---|
1117 | }
|
---|
1118 | }
|
---|
1119 |
|
---|
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"));
|
---|
1121 | if(n != 0)
|
---|
1122 | return;
|
---|
1123 |
|
---|
1124 | if(!unreg) {
|
---|
1125 | accept();
|
---|
1126 | return;
|
---|
1127 | }
|
---|
1128 |
|
---|
1129 | busy->start();
|
---|
1130 | gb_account->setEnabled(false);
|
---|
1131 | pb_remove->setEnabled(false);
|
---|
1132 |
|
---|
1133 | Jid j = d->acc.jid;
|
---|
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);
|
---|
1136 | }
|
---|
1137 |
|
---|
1138 | void AccountRemoveDlg::client_handshaken()
|
---|
1139 | {
|
---|
1140 | // try to unregister an account
|
---|
1141 | JT_Register *reg = new JT_Register(client->client()->rootTask());
|
---|
1142 | connect(reg, SIGNAL(finished()), SLOT(unreg_finished()));
|
---|
1143 | reg->unreg();
|
---|
1144 | reg->go(true);
|
---|
1145 | }
|
---|
1146 |
|
---|
1147 | void AccountRemoveDlg::client_error()
|
---|
1148 | {
|
---|
1149 | busy->stop();
|
---|
1150 | gb_account->setEnabled(true);
|
---|
1151 | pb_remove->setEnabled(true);
|
---|
1152 | }
|
---|
1153 |
|
---|
1154 | void AccountRemoveDlg::unreg_finished()
|
---|
1155 | {
|
---|
1156 | JT_Register *reg = (JT_Register *)sender();
|
---|
1157 |
|
---|
1158 | client->close();
|
---|
1159 | busy->stop();
|
---|
1160 |
|
---|
1161 | if(reg->success()) {
|
---|
1162 | QMessageBox::information(this, tr("Success"), tr("The account was unregistered successfully."));
|
---|
1163 | accept();
|
---|
1164 | return;
|
---|
1165 | }
|
---|
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()));
|
---|
1170 | }
|
---|
1171 | }
|
---|