1 | /*
|
---|
2 | * eventdlg.cpp - dialog for sending / receiving messages and events
|
---|
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"eventdlg.h"
|
---|
22 |
|
---|
23 | #include<qlabel.h>
|
---|
24 | #include<qcombobox.h>
|
---|
25 | #include<qlayout.h>
|
---|
26 | #include<qpushbutton.h>
|
---|
27 | #include<qdragobject.h>
|
---|
28 | #include<qdropsite.h>
|
---|
29 | #include<qmessagebox.h>
|
---|
30 | #include<qstringlist.h>
|
---|
31 | #include<qtimer.h>
|
---|
32 | #include<qcursor.h>
|
---|
33 | #include<qpopupmenu.h>
|
---|
34 | #include<qiconset.h>
|
---|
35 | #include<qdatetime.h>
|
---|
36 | #include<qtooltip.h>
|
---|
37 | #include<qheader.h>
|
---|
38 | #include<qapplication.h>
|
---|
39 | #include<qclipboard.h>
|
---|
40 | #include<qlcdnumber.h>
|
---|
41 | #include"psievent.h"
|
---|
42 | #include"psicon.h"
|
---|
43 | #include"psiaccount.h"
|
---|
44 | #include"msgmle.h"
|
---|
45 | #include"common.h"
|
---|
46 | #include"userlist.h"
|
---|
47 | #include"iconwidget.h"
|
---|
48 | #include"fancylabel.h"
|
---|
49 | #include"iconselect.h"
|
---|
50 | #include"iconwidget.h"
|
---|
51 |
|
---|
52 | static QString findJid(const QString &s, int x, int *p1, int *p2)
|
---|
53 | {
|
---|
54 | // scan backward for the beginning of a Jid
|
---|
55 | int n1 = x;
|
---|
56 | if(n1 >= (int)s.length())
|
---|
57 | n1 = s.length()-1;
|
---|
58 | for(; n1 >= 0; --n1) {
|
---|
59 | if(s.at(n1) == ',') {
|
---|
60 | ++n1;
|
---|
61 | break;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | if(n1 < 0)
|
---|
65 | n1 = 0;
|
---|
66 | // go forward, skipping whitespace
|
---|
67 | for(; n1 < (int)s.length(); ++n1) {
|
---|
68 | if(!s.at(n1).isSpace())
|
---|
69 | break;
|
---|
70 | }
|
---|
71 |
|
---|
72 | // now find the end of the Jid
|
---|
73 | int n2 = n1;
|
---|
74 | for(; n2 < (int)s.length(); ++n2) {
|
---|
75 | if(s.at(n2) == ',')
|
---|
76 | break;
|
---|
77 | }
|
---|
78 | --n2;
|
---|
79 | // scan backwards from the end, skipping whitespace
|
---|
80 | for(; n2 > n1; --n2) {
|
---|
81 | if(!s.at(n2).isSpace())
|
---|
82 | break;
|
---|
83 | }
|
---|
84 | ++n2;
|
---|
85 |
|
---|
86 | *p1 = n1;
|
---|
87 | *p2 = n2;
|
---|
88 |
|
---|
89 | return s.mid(n1, n2-n1);
|
---|
90 | }
|
---|
91 |
|
---|
92 | //----------------------------------------------------------------------------
|
---|
93 | // ELineEdit - a line edit that handles advanced Jid entry
|
---|
94 | //----------------------------------------------------------------------------
|
---|
95 | // hack hack hack hack
|
---|
96 | struct QLineEditPrivate
|
---|
97 | {
|
---|
98 | // qt 3.3.1
|
---|
99 | /*QLineEdit *q;
|
---|
100 | QString text;
|
---|
101 | int cursor;
|
---|
102 | int cursorTimer;
|
---|
103 | QPoint tripleClick;
|
---|
104 | int tripleClickTimer;
|
---|
105 | uint frame : 1;
|
---|
106 | uint cursorVisible : 1;
|
---|
107 | uint separator : 1;
|
---|
108 | uint readOnly : 1;
|
---|
109 | uint modified : 1;
|
---|
110 | uint direction : 5;
|
---|
111 | uint dragEnabled : 1;
|
---|
112 | uint alignment : 3;
|
---|
113 | uint echoMode : 2;
|
---|
114 | uint textDirty : 1;
|
---|
115 | uint selDirty : 1;
|
---|
116 | uint validInput : 1;
|
---|
117 | int ascent;
|
---|
118 | int maxLength;
|
---|
119 | int menuId;
|
---|
120 | int hscroll;*/
|
---|
121 |
|
---|
122 | char pad[sizeof(QLineEdit *) + sizeof(QString) + (sizeof(int)*2) + sizeof(QPoint) + sizeof(int) + 3 + (sizeof(int)*3)];
|
---|
123 | int hscroll;
|
---|
124 | };
|
---|
125 |
|
---|
126 | ELineEdit::ELineEdit(EventDlg *parent, const char *name)
|
---|
127 | :QLineEdit(parent, name)
|
---|
128 | {
|
---|
129 | setAcceptDrops(TRUE);
|
---|
130 | }
|
---|
131 |
|
---|
132 | void ELineEdit::dragEnterEvent(QDragEnterEvent *e)
|
---|
133 | {
|
---|
134 | e->accept(QTextDrag::canDecode(e));
|
---|
135 | }
|
---|
136 |
|
---|
137 | void ELineEdit::dropEvent(QDropEvent *e)
|
---|
138 | {
|
---|
139 | QString str;
|
---|
140 |
|
---|
141 | if(QTextDrag::decode(e, str)) {
|
---|
142 | Jid jid(str);
|
---|
143 | if(!jid.isValid())
|
---|
144 | setText(str);
|
---|
145 | else {
|
---|
146 | EventDlg *e = (EventDlg *)parent();
|
---|
147 | QString name = e->jidToString(jid);
|
---|
148 |
|
---|
149 | bool hasComma = false, hasText = false;
|
---|
150 | int len = text().length();
|
---|
151 | while ( --len >= 0 ) {
|
---|
152 | QChar c = text().at( len );
|
---|
153 | if ( c == ',' ) {
|
---|
154 | hasComma = true;
|
---|
155 | break;
|
---|
156 | }
|
---|
157 | else if ( !c.isSpace() ) {
|
---|
158 | hasText = true;
|
---|
159 | break;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | if ( hasComma || !hasText )
|
---|
164 | setText(text() + ' ' + name);
|
---|
165 | else
|
---|
166 | setText(text() + ", " + name);
|
---|
167 | }
|
---|
168 | setCursorPosition(text().length());
|
---|
169 |
|
---|
170 | repaint();
|
---|
171 | }
|
---|
172 | }
|
---|
173 |
|
---|
174 | void ELineEdit::keyPressEvent(QKeyEvent *e)
|
---|
175 | {
|
---|
176 | QLineEdit::keyPressEvent(e);
|
---|
177 | if(e->ascii() >= 32 && e->ascii() < 127)
|
---|
178 | tryComplete();
|
---|
179 | }
|
---|
180 |
|
---|
181 | QPopupMenu *ELineEdit::createPopupMenu()
|
---|
182 | {
|
---|
183 | EventDlg *e = (EventDlg *)parent();
|
---|
184 | int xoff = mapFromGlobal(QCursor::pos()).x();
|
---|
185 | int x = characterAt(d->hscroll + xoff, 0);
|
---|
186 | QString str = text();
|
---|
187 | int p1, p2;
|
---|
188 | QString j = findJid(str, x, &p1, &p2);
|
---|
189 | if(j.isEmpty())
|
---|
190 | return QLineEdit::createPopupMenu();
|
---|
191 |
|
---|
192 | UserResourceList list = e->getResources(j);
|
---|
193 |
|
---|
194 | setCursorPosition(p1);
|
---|
195 | setSelection(p1, p2-p1);
|
---|
196 |
|
---|
197 | url = list;
|
---|
198 | url.sort();
|
---|
199 |
|
---|
200 | int n = 100;
|
---|
201 | QPopupMenu *rm = new QPopupMenu(this); //= new QPopupMenu(pm);
|
---|
202 | connect(rm, SIGNAL(activated(int)), SLOT(resourceMenuActivated(int)));
|
---|
203 |
|
---|
204 | rm->insertItem(tr("Recipient Default"), n++);
|
---|
205 |
|
---|
206 | if(!list.isEmpty()) {
|
---|
207 | rm->insertSeparator();
|
---|
208 |
|
---|
209 | for(UserResourceList::ConstIterator it = url.begin(); it != url.end(); ++it) {
|
---|
210 | const UserResource &r = *it;
|
---|
211 | QString name;
|
---|
212 | if(r.name().isEmpty())
|
---|
213 | name = QObject::tr("[blank]");
|
---|
214 | else
|
---|
215 | name = r.name();
|
---|
216 |
|
---|
217 | rm->insertItem(is->status(r.status()), name, n++);
|
---|
218 | }
|
---|
219 | }
|
---|
220 |
|
---|
221 | //pm->insertItem("Change Resource", rm, -1, 0);
|
---|
222 | //pm->insertSeparator(1);
|
---|
223 |
|
---|
224 | return rm;
|
---|
225 | }
|
---|
226 |
|
---|
227 | void ELineEdit::resourceMenuActivated(int x)
|
---|
228 | {
|
---|
229 | if(x < 100)
|
---|
230 | return;
|
---|
231 |
|
---|
232 | QString name;
|
---|
233 | if(x == 100)
|
---|
234 | name = "";
|
---|
235 | else {
|
---|
236 | int n = 101;
|
---|
237 | for(UserResourceList::ConstIterator it = url.begin(); it != url.end(); ++it) {
|
---|
238 | if(n == x) {
|
---|
239 | name = (*it).name();
|
---|
240 | break;
|
---|
241 | }
|
---|
242 | ++n;
|
---|
243 | }
|
---|
244 | }
|
---|
245 | url.clear();
|
---|
246 |
|
---|
247 | changeResource(name);
|
---|
248 | }
|
---|
249 |
|
---|
250 |
|
---|
251 | //----------------------------------------------------------------------------
|
---|
252 | // AttachView
|
---|
253 | //----------------------------------------------------------------------------
|
---|
254 | class AttachViewItem : public QListViewItem
|
---|
255 | {
|
---|
256 | public:
|
---|
257 | AttachViewItem(const QString &_url, const QString &_desc, AttachView *par)
|
---|
258 | :QListViewItem(par)
|
---|
259 | {
|
---|
260 | type = 0;
|
---|
261 | url = _url;
|
---|
262 | desc = _desc;
|
---|
263 |
|
---|
264 | setPixmap(0, IconsetFactory::icon("psi/www"));
|
---|
265 | setText(0, url + " (" + desc + ')');
|
---|
266 | setMultiLinesEnabled(true);
|
---|
267 | }
|
---|
268 |
|
---|
269 | AttachViewItem(const QString &_gc, AttachView *par)
|
---|
270 | :QListViewItem(par)
|
---|
271 | {
|
---|
272 | type = 1;
|
---|
273 | gc = _gc;
|
---|
274 |
|
---|
275 | setPixmap(0, IconsetFactory::icon("psi/groupChat"));
|
---|
276 | setText(0, gc);
|
---|
277 | setMultiLinesEnabled(true);
|
---|
278 | }
|
---|
279 |
|
---|
280 | int rtti() const
|
---|
281 | {
|
---|
282 | return 9100;
|
---|
283 | }
|
---|
284 |
|
---|
285 | QString url, desc;
|
---|
286 | QString gc;
|
---|
287 | int type;
|
---|
288 | };
|
---|
289 |
|
---|
290 | AttachView::AttachView(QWidget *parent, const char *name)
|
---|
291 | :QListView(parent, name)
|
---|
292 | {
|
---|
293 | v_readOnly = false;
|
---|
294 | addColumn(tr("Attachments"));
|
---|
295 | setResizeMode(QListView::AllColumns);
|
---|
296 |
|
---|
297 | connect(this, SIGNAL(contextMenuRequested(QListViewItem *, const QPoint &, int)), SLOT(qlv_context(QListViewItem *, const QPoint &, int)));
|
---|
298 | connect(this, SIGNAL(doubleClicked(QListViewItem *)), SLOT(qlv_doubleClicked(QListViewItem *)));
|
---|
299 | };
|
---|
300 |
|
---|
301 | AttachView::~AttachView()
|
---|
302 | {
|
---|
303 | }
|
---|
304 |
|
---|
305 | void AttachView::setReadOnly(bool b)
|
---|
306 | {
|
---|
307 | v_readOnly = b;
|
---|
308 | }
|
---|
309 |
|
---|
310 | void AttachView::urlAdd(const QString &url, const QString &desc)
|
---|
311 | {
|
---|
312 | new AttachViewItem(url, desc, this);
|
---|
313 | childCountChanged();
|
---|
314 | }
|
---|
315 |
|
---|
316 | void AttachView::gcAdd(const QString &gc)
|
---|
317 | {
|
---|
318 | new AttachViewItem(gc, this);
|
---|
319 | childCountChanged();
|
---|
320 | }
|
---|
321 |
|
---|
322 | void AttachView::qlv_context(QListViewItem *lvi, const QPoint &pos, int)
|
---|
323 | {
|
---|
324 | AttachViewItem *i = (AttachViewItem *)lvi;
|
---|
325 | if(!i)
|
---|
326 | return;
|
---|
327 |
|
---|
328 | QPopupMenu pm(this);
|
---|
329 | if(i->type == 0) {
|
---|
330 | pm.insertItem(tr("Go to &URL..."), 0);
|
---|
331 | pm.insertItem(tr("Copy location"), 1);
|
---|
332 | }
|
---|
333 | else
|
---|
334 | pm.insertItem(tr("Join &Groupchat..."), 0);
|
---|
335 | pm.insertSeparator();
|
---|
336 | pm.insertItem(tr("Remove"), 2);
|
---|
337 |
|
---|
338 | if(v_readOnly)
|
---|
339 | pm.setItemEnabled(2, false);
|
---|
340 |
|
---|
341 | int n = pm.exec(pos);
|
---|
342 | if(n == -1)
|
---|
343 | return;
|
---|
344 |
|
---|
345 | if(n == 0) {
|
---|
346 | if(i->type == 0)
|
---|
347 | goURL(i->url);
|
---|
348 | else
|
---|
349 | actionGCJoin(i->gc);
|
---|
350 | }
|
---|
351 | else if(n == 1) {
|
---|
352 | QApplication::clipboard()->setText(i->url, QClipboard::Clipboard);
|
---|
353 | if(QApplication::clipboard()->supportsSelection())
|
---|
354 | QApplication::clipboard()->setText(i->url, QClipboard::Selection);
|
---|
355 | }
|
---|
356 | else if(n == 2) {
|
---|
357 | delete i;
|
---|
358 | childCountChanged();
|
---|
359 | }
|
---|
360 | }
|
---|
361 |
|
---|
362 | void AttachView::qlv_doubleClicked(QListViewItem *lvi)
|
---|
363 | {
|
---|
364 | AttachViewItem *i = (AttachViewItem *)lvi;
|
---|
365 | if(!i)
|
---|
366 | return;
|
---|
367 |
|
---|
368 | if(i->type == 0)
|
---|
369 | goURL(i->url);
|
---|
370 | else
|
---|
371 | actionGCJoin(i->gc);
|
---|
372 | }
|
---|
373 |
|
---|
374 | void AttachView::goURL(const QString &_url)
|
---|
375 | {
|
---|
376 | if(_url.isEmpty())
|
---|
377 | return;
|
---|
378 |
|
---|
379 | QString url = _url;
|
---|
380 | if(url.find("://") == -1)
|
---|
381 | url.insert(0, "http://");
|
---|
382 |
|
---|
383 | openURL(url);
|
---|
384 | }
|
---|
385 |
|
---|
386 | UrlList AttachView::urlList() const
|
---|
387 | {
|
---|
388 | UrlList list;
|
---|
389 |
|
---|
390 | for(AttachViewItem *i = (AttachViewItem *)firstChild(); i; i = (AttachViewItem *)i->nextSibling())
|
---|
391 | list += Url(i->url, i->desc);
|
---|
392 |
|
---|
393 | return list;
|
---|
394 | }
|
---|
395 |
|
---|
396 | void AttachView::addUrlList(const UrlList &list)
|
---|
397 | {
|
---|
398 | for(QValueList<Url>::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
---|
399 | const Url &u = *it;
|
---|
400 | urlAdd(u.url(), u.desc());
|
---|
401 | }
|
---|
402 | }
|
---|
403 |
|
---|
404 |
|
---|
405 | //----------------------------------------------------------------------------
|
---|
406 | // AddUrlDlg
|
---|
407 | //----------------------------------------------------------------------------
|
---|
408 | AddUrlDlg::AddUrlDlg(QWidget *parent, const char *name)
|
---|
409 | :AddUrlUI(parent, name, true)
|
---|
410 | {
|
---|
411 | #ifndef Q_WS_MAC
|
---|
412 | setIcon(IconsetFactory::icon("psi/www"));
|
---|
413 | #endif
|
---|
414 |
|
---|
415 | connect(pb_close, SIGNAL(clicked()), SLOT(reject()));
|
---|
416 | connect(pb_ok, SIGNAL(clicked()), SLOT(accept()));
|
---|
417 | }
|
---|
418 |
|
---|
419 | AddUrlDlg::~AddUrlDlg()
|
---|
420 | {
|
---|
421 | }
|
---|
422 |
|
---|
423 |
|
---|
424 | //----------------------------------------------------------------------------
|
---|
425 | // EventDlg - a window to read and write events
|
---|
426 | //----------------------------------------------------------------------------
|
---|
427 | class EventDlg::Private : public QObject
|
---|
428 | {
|
---|
429 | Q_OBJECT
|
---|
430 | public:
|
---|
431 | Private(EventDlg *d) {
|
---|
432 | dlg = d;
|
---|
433 | }
|
---|
434 |
|
---|
435 | EventDlg *dlg;
|
---|
436 | PsiCon *psi;
|
---|
437 | PsiAccount *pa;
|
---|
438 |
|
---|
439 | bool composing;
|
---|
440 |
|
---|
441 | AccountsComboBox *cb_ident;
|
---|
442 | QComboBox *cb_type;
|
---|
443 | QLabel *lb_ident, *lb_time;
|
---|
444 | IconLabel *lb_status;
|
---|
445 | ELineEdit *le_to;
|
---|
446 | QLineEdit *le_from, *le_subj;
|
---|
447 | QLCDNumber *lcd_count;
|
---|
448 | IconToolButton *tb_url, *tb_info, *tb_history, *tb_pgp, *tb_icon;
|
---|
449 | IconLabel *lb_pgp;
|
---|
450 | bool enc;
|
---|
451 | int transid;
|
---|
452 | IconButton *pb_next;
|
---|
453 | IconButton *pb_close, *pb_quote, *pb_deny, *pb_send, *pb_reply, *pb_chat, *pb_auth;
|
---|
454 | ChatView *mle;
|
---|
455 | AttachView *attachView;
|
---|
456 | QTimer *whois;
|
---|
457 | QString lastWhois;
|
---|
458 | Jid jid, realJid;
|
---|
459 | QString thread;
|
---|
460 | QStringList completionList;
|
---|
461 | Icon *anim, *nextAnim;
|
---|
462 | int nextAmount;
|
---|
463 |
|
---|
464 | bool urlOnShow;
|
---|
465 |
|
---|
466 | Message m;
|
---|
467 | QStringList sendLeft;
|
---|
468 |
|
---|
469 | public slots:
|
---|
470 | void addEmoticon(const Icon *icon) {
|
---|
471 | if ( !dlg->isActiveWindow() )
|
---|
472 | return;
|
---|
473 |
|
---|
474 | QString text;
|
---|
475 |
|
---|
476 | QDict<QString> itext = icon->text();
|
---|
477 | QDictIterator<QString> it ( itext );
|
---|
478 | for ( ; it.current(); ++it) {
|
---|
479 | if ( it.current() && !it.current()->isEmpty() ) {
|
---|
480 | text = *(it.current()) + " ";
|
---|
481 | break;
|
---|
482 | }
|
---|
483 | }
|
---|
484 |
|
---|
485 | if ( !text.isEmpty() )
|
---|
486 | mle->insert( text );
|
---|
487 | }
|
---|
488 |
|
---|
489 | void addEmoticon(QString text) {
|
---|
490 | if ( !dlg->isActiveWindow() )
|
---|
491 | return;
|
---|
492 |
|
---|
493 | mle->insert( text + " " );
|
---|
494 | }
|
---|
495 |
|
---|
496 | void updateCounter() {
|
---|
497 | lcd_count->display((int)mle->text().length());
|
---|
498 | }
|
---|
499 | };
|
---|
500 |
|
---|
501 | EventDlg::EventDlg(const QString &to, PsiCon *psi, PsiAccount *pa)
|
---|
502 | :AdvancedWidget<QWidget>(0, 0, WDestructiveClose | WGroupLeader)
|
---|
503 | {
|
---|
504 | d = new Private(this);
|
---|
505 | d->composing = true;
|
---|
506 | d->psi = psi;
|
---|
507 | d->pa = 0;
|
---|
508 | d->psi->dialogRegister(this);
|
---|
509 |
|
---|
510 | d->anim = 0;
|
---|
511 | d->nextAnim = 0;
|
---|
512 | d->nextAmount = 0;
|
---|
513 | d->urlOnShow = false;
|
---|
514 |
|
---|
515 | setAccount(pa);
|
---|
516 |
|
---|
517 | d->whois = new QTimer;
|
---|
518 | connect(d->whois, SIGNAL(timeout()), SLOT(doWhois()));
|
---|
519 |
|
---|
520 | init();
|
---|
521 |
|
---|
522 | d->cb_ident->setAccount(pa);
|
---|
523 |
|
---|
524 | d->pb_send->show();
|
---|
525 | d->le_to->setText(expandAddresses(to, false));
|
---|
526 | d->le_to->setCursorPosition(0);
|
---|
527 |
|
---|
528 | if(option.grabUrls) {
|
---|
529 | // url in clipboard?
|
---|
530 | QClipboard *cb = QApplication::clipboard();
|
---|
531 | QCString subtype("plain");
|
---|
532 | bool oldmode = cb->selectionModeEnabled();
|
---|
533 | cb->setSelectionMode(false);
|
---|
534 | QString text = cb->text(subtype);
|
---|
535 | if(!text && cb->supportsSelection()) {
|
---|
536 | cb->setSelectionMode(true);
|
---|
537 | text = cb->text(subtype);
|
---|
538 | }
|
---|
539 | if(text) {
|
---|
540 | if(text.left(7) == "http://") {
|
---|
541 | d->attachView->urlAdd(text, "");
|
---|
542 | cb->setSelectionMode(false);
|
---|
543 | cb->clear();
|
---|
544 | cb->setSelectionMode(true);
|
---|
545 | cb->clear();
|
---|
546 | }
|
---|
547 | }
|
---|
548 | cb->setSelectionMode(oldmode);
|
---|
549 | }
|
---|
550 |
|
---|
551 | updateIdentity(pa);
|
---|
552 |
|
---|
553 | X11WM_CLASS("event");
|
---|
554 |
|
---|
555 | if(d->le_to->text().isEmpty())
|
---|
556 | d->le_to->setFocus();
|
---|
557 | else
|
---|
558 | d->mle->setFocus();
|
---|
559 |
|
---|
560 | if(d->tb_pgp) {
|
---|
561 | UserListItem *u = d->pa->findFirstRelavent(d->jid);
|
---|
562 | if(u && u->isSecure(d->jid.resource()))
|
---|
563 | d->tb_pgp->setOn(true);
|
---|
564 | }
|
---|
565 | }
|
---|
566 |
|
---|
567 | EventDlg::EventDlg(const Jid &j, PsiAccount *pa, bool unique)
|
---|
568 | :AdvancedWidget<QWidget>(0, 0, WDestructiveClose | WGroupLeader)
|
---|
569 | {
|
---|
570 | d = new Private(this);
|
---|
571 | d->composing = false;
|
---|
572 | d->psi = pa->psi();
|
---|
573 | d->pa = pa;
|
---|
574 | d->jid = j;
|
---|
575 | d->realJid = j;
|
---|
576 |
|
---|
577 | if(unique)
|
---|
578 | d->pa->dialogRegister(this, j);
|
---|
579 | else
|
---|
580 | d->pa->dialogRegister(this);
|
---|
581 |
|
---|
582 | d->anim = 0;
|
---|
583 | d->nextAnim = 0;
|
---|
584 | d->nextAmount = 0;
|
---|
585 | d->urlOnShow = false;
|
---|
586 |
|
---|
587 | init();
|
---|
588 |
|
---|
589 | d->le_from->setText(expandAddresses(d->jid.full(), false));
|
---|
590 | d->le_from->setCursorPosition(0);
|
---|
591 |
|
---|
592 | doWhois();
|
---|
593 |
|
---|
594 | d->pb_next->show();
|
---|
595 |
|
---|
596 | d->pb_close->setFocus();
|
---|
597 |
|
---|
598 | X11WM_CLASS("event");
|
---|
599 |
|
---|
600 | setTime(QDateTime::currentDateTime(), true);
|
---|
601 | }
|
---|
602 |
|
---|
603 | EventDlg::~EventDlg()
|
---|
604 | {
|
---|
605 | if(d->composing) {
|
---|
606 | delete d->whois;
|
---|
607 | d->psi->dialogUnregister(this);
|
---|
608 | }
|
---|
609 | else {
|
---|
610 | d->pa->dialogUnregister(this);
|
---|
611 | }
|
---|
612 | delete d;
|
---|
613 | }
|
---|
614 |
|
---|
615 | void EventDlg::init()
|
---|
616 | {
|
---|
617 | QVBoxLayout *vb1 = new QVBoxLayout(this, 4);
|
---|
618 | QLabel *l;
|
---|
619 |
|
---|
620 | // first row
|
---|
621 | QHBoxLayout *hb1 = new QHBoxLayout(vb1);
|
---|
622 | l = new QLabel(tr("Identity:"), this);
|
---|
623 | hb1->addWidget(l);
|
---|
624 |
|
---|
625 | d->enc = false;
|
---|
626 | d->transid = -1;
|
---|
627 |
|
---|
628 | if(d->composing) {
|
---|
629 | d->cb_ident = d->psi->accountsComboBox(this);
|
---|
630 | connect(d->cb_ident, SIGNAL(activated(PsiAccount *)), SLOT(updateIdentity(PsiAccount *)));
|
---|
631 | hb1->addWidget(d->cb_ident);
|
---|
632 | }
|
---|
633 | else {
|
---|
634 | d->lb_ident = d->pa->accountLabel(this);
|
---|
635 | d->lb_ident->setSizePolicy(QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ));
|
---|
636 | hb1->addWidget(d->lb_ident);
|
---|
637 | }
|
---|
638 |
|
---|
639 | if(d->composing) {
|
---|
640 | l = new QLabel(tr("Type:"), this);
|
---|
641 | hb1->addWidget(l);
|
---|
642 | d->cb_type = new QComboBox(this);
|
---|
643 | d->cb_type->insertItem(tr("Normal"));
|
---|
644 | d->cb_type->insertItem(tr("Chat"));
|
---|
645 | hb1->addWidget(d->cb_type);
|
---|
646 | }
|
---|
647 | else {
|
---|
648 | l = new QLabel(tr("Time:"), this);
|
---|
649 | hb1->addWidget(l);
|
---|
650 | d->lb_time = new QLabel(this);
|
---|
651 | d->lb_time->setFrameStyle( QFrame::Panel | QFrame::Sunken );
|
---|
652 | hb1->addWidget(d->lb_time);
|
---|
653 | }
|
---|
654 |
|
---|
655 | // second row
|
---|
656 | QHBoxLayout *hb2 = new QHBoxLayout(vb1);
|
---|
657 |
|
---|
658 | d->lb_status = new IconLabel(this);
|
---|
659 | d->lb_status->setIcon(IconsetFactory::iconPtr("status/noauth"));
|
---|
660 |
|
---|
661 | if(d->composing) {
|
---|
662 | l = new QLabel(tr("To:"), this);
|
---|
663 | hb2->addWidget(l);
|
---|
664 | hb2->addWidget(d->lb_status);
|
---|
665 | d->le_to = new ELineEdit(this);
|
---|
666 | connect(d->le_to, SIGNAL(textChanged(const QString &)), SLOT(to_textChanged(const QString &)));
|
---|
667 | connect(d->le_to, SIGNAL(changeResource(const QString &)), SLOT(to_changeResource(const QString &)));
|
---|
668 | connect(d->le_to, SIGNAL(tryComplete()), SLOT(to_tryComplete()));
|
---|
669 | hb2->addWidget(d->le_to);
|
---|
670 | }
|
---|
671 | else {
|
---|
672 | l = new QLabel(tr("From:"), this);
|
---|
673 | hb2->addWidget(l);
|
---|
674 | hb2->addWidget(d->lb_status);
|
---|
675 | d->le_from = new QLineEdit(this);
|
---|
676 | d->le_from->setReadOnly(true);
|
---|
677 | hb2->addWidget(d->le_from);
|
---|
678 | }
|
---|
679 |
|
---|
680 | // icon select
|
---|
681 | //connect(d->psi->iconSelectPopup(), SIGNAL(iconSelected(const Icon *)), d, SLOT(addEmoticon(const Icon *)));
|
---|
682 | connect(d->psi->iconSelectPopup(), SIGNAL(textSelected(QString)), d, SLOT(addEmoticon(QString)));
|
---|
683 |
|
---|
684 | d->tb_icon = new IconToolButton(this);
|
---|
685 | d->tb_icon->setIcon(IconsetFactory::iconPtr("psi/smile"));
|
---|
686 | d->tb_icon->setPopup(d->psi->iconSelectPopup());
|
---|
687 | d->tb_icon->setPopupDelay (1);
|
---|
688 | QToolTip::add(d->tb_icon, tr("Select icon"));
|
---|
689 | if ( !d->composing )
|
---|
690 | d->tb_icon->setEnabled(false);
|
---|
691 |
|
---|
692 | // message length counter
|
---|
693 | d->le_subj = new QLineEdit(this);
|
---|
694 | d->lcd_count = new QLCDNumber(this);
|
---|
695 | QToolTip::add(d->lcd_count, tr("Message length"));
|
---|
696 | d->lcd_count->setFixedWidth(50);
|
---|
697 |
|
---|
698 | if(d->composing) {
|
---|
699 | d->tb_pgp = new IconToolButton(this);
|
---|
700 | d->tb_pgp->setToggleButton(true);
|
---|
701 | QToolTip::add(d->tb_pgp, tr("Toggle encryption"));
|
---|
702 | d->lb_pgp = 0;
|
---|
703 | }
|
---|
704 | else {
|
---|
705 | d->lb_pgp = new IconLabel(this);
|
---|
706 | d->lb_pgp->setIcon(IconsetFactory::iconPtr("psi/cryptoNo"));
|
---|
707 | d->tb_pgp = 0;
|
---|
708 | }
|
---|
709 |
|
---|
710 | d->tb_url = new IconToolButton(this);
|
---|
711 | connect(d->tb_url, SIGNAL(clicked()), SLOT(addUrl()));
|
---|
712 | QToolTip::add(d->tb_url, tr("Add URL"));
|
---|
713 | d->tb_info = new IconToolButton(this);
|
---|
714 | connect(d->tb_info, SIGNAL(clicked()), SLOT(doInfo()));
|
---|
715 | QToolTip::add(d->tb_info, tr("User info"));
|
---|
716 | d->tb_history = new IconToolButton(this);
|
---|
717 | connect(d->tb_history, SIGNAL(clicked()), SLOT(doHistory()));
|
---|
718 | QToolTip::add(d->tb_history, tr("Message history"));
|
---|
719 |
|
---|
720 | QHBoxLayout *hb3 = new QHBoxLayout(vb1);
|
---|
721 |
|
---|
722 | // if(d->composing /* && config->showsubject */) {
|
---|
723 | if(option.showSubjects) {
|
---|
724 | // third row
|
---|
725 | l = new QLabel(tr("Subject:"), this);
|
---|
726 | hb3->addWidget(l);
|
---|
727 | hb3->addWidget(d->le_subj);
|
---|
728 | hb3->addWidget(d->lcd_count);
|
---|
729 | hb3->addWidget(d->tb_icon);
|
---|
730 | hb3->addWidget(d->tb_url);
|
---|
731 | hb3->addWidget(d->tb_info);
|
---|
732 | hb3->addWidget(d->tb_history);
|
---|
733 |
|
---|
734 | if(!d->composing) {
|
---|
735 | d->le_subj->setReadOnly(true);
|
---|
736 | d->tb_url->setEnabled(false);
|
---|
737 | hb3->addWidget(d->lb_pgp);
|
---|
738 | } else
|
---|
739 | hb3->addWidget(d->tb_pgp);
|
---|
740 |
|
---|
741 | } else {
|
---|
742 | d->le_subj->hide();
|
---|
743 | hb2->addWidget(d->lcd_count);
|
---|
744 | hb2->addWidget(d->tb_icon);
|
---|
745 | hb2->addWidget(d->tb_url);
|
---|
746 | hb2->addWidget(d->tb_info);
|
---|
747 | hb2->addWidget(d->tb_history);
|
---|
748 | if(d->composing)
|
---|
749 | hb2->addWidget(d->tb_pgp);
|
---|
750 | else
|
---|
751 | hb2->addWidget(d->lb_pgp);
|
---|
752 | }
|
---|
753 |
|
---|
754 | // text area
|
---|
755 | d->mle = new ChatView(this);
|
---|
756 | d->mle->setReadOnly(false);
|
---|
757 | d->mle->setUndoRedoEnabled(true);
|
---|
758 | d->mle->setTextFormat(PlainText);
|
---|
759 | d->mle->setMinimumHeight(50);
|
---|
760 | vb1->addWidget(d->mle);
|
---|
761 |
|
---|
762 | connect(d->mle, SIGNAL(textChanged()), d, SLOT(updateCounter()));
|
---|
763 |
|
---|
764 | d->mle->setTextFormat(QTextEdit::PlainText);
|
---|
765 | if(!d->composing) {
|
---|
766 | d->mle->setReadOnly(true);
|
---|
767 | d->mle->setUndoRedoEnabled(false);
|
---|
768 | }
|
---|
769 |
|
---|
770 | // attachment view
|
---|
771 | d->attachView = new AttachView(this);
|
---|
772 | d->attachView->setFixedHeight(80);
|
---|
773 | d->attachView->hide();
|
---|
774 | connect(d->attachView, SIGNAL(childCountChanged()), SLOT(showHideAttachView()));
|
---|
775 | connect(d->attachView, SIGNAL(actionGCJoin(const QString &)), SLOT(actionGCJoin(const QString &)));
|
---|
776 | vb1->addWidget(d->attachView);
|
---|
777 |
|
---|
778 | if(!d->composing)
|
---|
779 | d->attachView->setReadOnly(true);
|
---|
780 |
|
---|
781 | // bottom row
|
---|
782 | QHBoxLayout *hb4 = new QHBoxLayout(vb1);
|
---|
783 | d->pb_close = new IconButton(this);
|
---|
784 | d->pb_close->setText(tr("&Close"));
|
---|
785 | connect(d->pb_close, SIGNAL(clicked()), SLOT(close()));
|
---|
786 | d->pb_close->setMinimumWidth(80);
|
---|
787 | hb4->addWidget(d->pb_close);
|
---|
788 | hb4->addStretch(1);
|
---|
789 | d->pb_next = new IconButton(this);
|
---|
790 | connect(d->pb_next, SIGNAL(clicked()), SLOT(doReadNext()));
|
---|
791 | d->pb_next->setText(tr("&Next"));
|
---|
792 | d->pb_next->hide();
|
---|
793 | d->pb_next->setMinimumWidth(96);
|
---|
794 | d->pb_next->setEnabled(false);
|
---|
795 | hb4->addWidget(d->pb_next);
|
---|
796 | d->pb_quote = new IconButton(this);
|
---|
797 | d->pb_quote->setText(tr("&Quote"));
|
---|
798 | connect(d->pb_quote, SIGNAL(clicked()), SLOT(doQuote()));
|
---|
799 | d->pb_quote->hide();
|
---|
800 | d->pb_quote->setMinimumWidth(96);
|
---|
801 | hb4->addWidget(d->pb_quote);
|
---|
802 | d->pb_deny = new IconButton(this);
|
---|
803 | d->pb_deny->setText(tr("&Deny"));
|
---|
804 | connect(d->pb_deny, SIGNAL(clicked()), SLOT(doDeny()));
|
---|
805 | d->pb_deny->hide();
|
---|
806 | d->pb_deny->setMinimumWidth(96);
|
---|
807 | hb4->addWidget(d->pb_deny);
|
---|
808 | d->pb_auth = new IconButton(this);
|
---|
809 | d->pb_auth->setText(tr("&Add/Auth"));
|
---|
810 | connect(d->pb_auth, SIGNAL(clicked()), SLOT(doAuth()));
|
---|
811 | d->pb_auth->setIcon(IconsetFactory::iconPtr("psi/addContact"));
|
---|
812 | d->pb_auth->hide();
|
---|
813 | d->pb_auth->setMinimumWidth(96);
|
---|
814 | hb4->addWidget(d->pb_auth);
|
---|
815 | d->pb_send = new IconButton(this);
|
---|
816 | d->pb_send->setText(tr("&Send"));
|
---|
817 | connect(d->pb_send, SIGNAL(clicked()), SLOT(doSend()));
|
---|
818 | d->pb_send->hide();
|
---|
819 | d->pb_send->setMinimumWidth(96);
|
---|
820 | hb4->addWidget(d->pb_send);
|
---|
821 | d->pb_chat = new IconButton(this);
|
---|
822 | d->pb_chat->setText(tr("&Chat"));
|
---|
823 | connect(d->pb_chat, SIGNAL(clicked()), SLOT(doChat()));
|
---|
824 | d->pb_chat->hide();
|
---|
825 | d->pb_chat->setMinimumWidth(96);
|
---|
826 | hb4->addWidget(d->pb_chat);
|
---|
827 | d->pb_reply = new IconButton(this);
|
---|
828 | d->pb_reply->setText(tr("&Reply"));
|
---|
829 | connect(d->pb_reply, SIGNAL(clicked()), SLOT(doReply()));
|
---|
830 | d->pb_reply->hide();
|
---|
831 | d->pb_reply->setMinimumWidth(96);
|
---|
832 | hb4->addWidget(d->pb_reply);
|
---|
833 |
|
---|
834 | setTabOrder(d->mle, d->pb_send);
|
---|
835 |
|
---|
836 | updatePGP();
|
---|
837 | connect(d->pa, SIGNAL(pgpKeyChanged()), SLOT(updatePGP()));
|
---|
838 | connect(d->pa, SIGNAL(encryptedMessageSent(int, bool)), SLOT(encryptedMessageSent(int, bool)));
|
---|
839 |
|
---|
840 | resize(option.sizeEventDlg);
|
---|
841 | optionsUpdate();
|
---|
842 | }
|
---|
843 |
|
---|
844 | void EventDlg::setAccount(PsiAccount *pa)
|
---|
845 | {
|
---|
846 | if(d->pa)
|
---|
847 | disconnect(d->pa, SIGNAL(updatedActivity()), this, SLOT(accountUpdatedActivity()));
|
---|
848 |
|
---|
849 | d->pa = pa;
|
---|
850 | connect(d->pa, SIGNAL(updatedActivity()), this, SLOT(accountUpdatedActivity()));
|
---|
851 | }
|
---|
852 |
|
---|
853 | void EventDlg::updateIdentity(PsiAccount *pa)
|
---|
854 | {
|
---|
855 | if(!pa) {
|
---|
856 | close();
|
---|
857 | return;
|
---|
858 | }
|
---|
859 |
|
---|
860 | setAccount(pa);
|
---|
861 |
|
---|
862 | buildCompletionList();
|
---|
863 | doWhois(true);
|
---|
864 | }
|
---|
865 |
|
---|
866 | void EventDlg::accountUpdatedActivity()
|
---|
867 | {
|
---|
868 | // TODO: act on account activity change
|
---|
869 | }
|
---|
870 |
|
---|
871 | QString EventDlg::text() const
|
---|
872 | {
|
---|
873 | return d->mle->text();
|
---|
874 | }
|
---|
875 |
|
---|
876 | void EventDlg::setText(const QString &s)
|
---|
877 | {
|
---|
878 | d->mle->setText(s);
|
---|
879 | d->mle->moveCursor(QTextEdit::MoveEnd, false);
|
---|
880 | }
|
---|
881 |
|
---|
882 | void EventDlg::setSubject(const QString &s)
|
---|
883 | {
|
---|
884 | d->le_subj->setText(s);
|
---|
885 | }
|
---|
886 |
|
---|
887 | void EventDlg::setThread(const QString &t)
|
---|
888 | {
|
---|
889 | d->thread = t;
|
---|
890 | }
|
---|
891 |
|
---|
892 | void EventDlg::setUrlOnShow()
|
---|
893 | {
|
---|
894 | d->urlOnShow = true;
|
---|
895 | }
|
---|
896 |
|
---|
897 | PsiAccount *EventDlg::psiAccount()
|
---|
898 | {
|
---|
899 | return d->pa;
|
---|
900 | }
|
---|
901 |
|
---|
902 | QStringList EventDlg::stringToList(const QString &s, bool enc) const
|
---|
903 | {
|
---|
904 | QStringList list;
|
---|
905 |
|
---|
906 | int x1, x2;
|
---|
907 | x1 = 0;
|
---|
908 | x2 = 0;
|
---|
909 | while(1) {
|
---|
910 | // scan along for a comma
|
---|
911 | bool found = false;
|
---|
912 | for(int n = x1; n < (int)s.length(); ++n) {
|
---|
913 | if(s.at(n) == ',') {
|
---|
914 | found = true;
|
---|
915 | x2 = n;
|
---|
916 | break;
|
---|
917 | }
|
---|
918 | }
|
---|
919 | if(!found)
|
---|
920 | x2 = s.length();
|
---|
921 |
|
---|
922 | QString c = s.mid(x1, (x2-x1));
|
---|
923 | QString j;
|
---|
924 | if(enc)
|
---|
925 | j = findJidInString(c);
|
---|
926 | else
|
---|
927 | j = c;
|
---|
928 | if(j.isEmpty())
|
---|
929 | j = c;
|
---|
930 |
|
---|
931 | j = j.stripWhiteSpace();
|
---|
932 | //printf("j=[%s]\n", j.latin1());
|
---|
933 | if(!j.isEmpty())
|
---|
934 | list += j;
|
---|
935 |
|
---|
936 | if(!found)
|
---|
937 | break;
|
---|
938 | x1 = x2+1;
|
---|
939 | }
|
---|
940 |
|
---|
941 | return list;
|
---|
942 | }
|
---|
943 |
|
---|
944 | QString EventDlg::findJidInString(const QString &s) const
|
---|
945 | {
|
---|
946 | int a = s.find('<');
|
---|
947 | if(a != -1) {
|
---|
948 | ++a;
|
---|
949 | int b = s.find('>', a);
|
---|
950 | if(b != -1)
|
---|
951 | return dec822jid(s.mid(a, b-a));
|
---|
952 | }
|
---|
953 | return "";
|
---|
954 | }
|
---|
955 |
|
---|
956 | QString EventDlg::expandAddresses(const QString &in, bool enc) const
|
---|
957 | {
|
---|
958 | //printf("in: [%s]\n", in.latin1());
|
---|
959 | QString str;
|
---|
960 | QStringList list = stringToList(in, enc);
|
---|
961 | bool first = true;
|
---|
962 | for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
---|
963 | if(!first)
|
---|
964 | str += ", ";
|
---|
965 | first = false;
|
---|
966 |
|
---|
967 | Jid j(*it);
|
---|
968 | QPtrList<UserListItem> ul = d->pa->findRelavent(j);
|
---|
969 | if(ul.isEmpty()) {
|
---|
970 | str += j.full();
|
---|
971 | continue;
|
---|
972 | }
|
---|
973 | UserListItem *u = ul.first();
|
---|
974 |
|
---|
975 | Jid jid;
|
---|
976 | if(j.resource().isEmpty())
|
---|
977 | jid = u->jid().full();
|
---|
978 | else
|
---|
979 | jid = u->jid().userHost() + '/' + j.resource();
|
---|
980 |
|
---|
981 | QString name;
|
---|
982 | if(!u->name().isEmpty())
|
---|
983 | name += u->name() + QString(" <%1>").arg(enc822jid(jid.full()));
|
---|
984 | else
|
---|
985 | name = enc822jid(jid.full());
|
---|
986 | str += name;
|
---|
987 | }
|
---|
988 |
|
---|
989 | //printf("expanding: [%s]\n", str.latin1());
|
---|
990 | return str;
|
---|
991 | }
|
---|
992 |
|
---|
993 | void EventDlg::to_textChanged(const QString &)
|
---|
994 | {
|
---|
995 | d->whois->start(250);
|
---|
996 | }
|
---|
997 |
|
---|
998 | void EventDlg::to_changeResource(const QString &r)
|
---|
999 | {
|
---|
1000 | QString str = d->le_to->text();
|
---|
1001 | int start, len;
|
---|
1002 | if(!d->le_to->getSelection(&start, &len)) {
|
---|
1003 | //printf("bad selection\n");
|
---|
1004 | return;
|
---|
1005 | }
|
---|
1006 | //printf("selection: [%d,%d]\n", start, len);
|
---|
1007 |
|
---|
1008 | int p1, p2;
|
---|
1009 | QString s = findJid(str, start, &p1, &p2);
|
---|
1010 | QString j = findJidInString(s);
|
---|
1011 | if(j.isEmpty())
|
---|
1012 | j = s;
|
---|
1013 | Jid jid(j);
|
---|
1014 | if(!jid.isValid()) {
|
---|
1015 | //printf("invalid jid\n");
|
---|
1016 | return;
|
---|
1017 | }
|
---|
1018 | //printf("s=[%s], j=[%s], p: [%d,%d]\n", s.latin1(), j.latin1(), p1, p2);
|
---|
1019 |
|
---|
1020 | QString js = jidToString(jid, r);
|
---|
1021 | //printf("js=[%s]\n", js.latin1());
|
---|
1022 | /*str.remove(start, len);
|
---|
1023 | str.insert(start, js);
|
---|
1024 | d->le_to->deselect();
|
---|
1025 | d->le_to->setCursorPosition(0);
|
---|
1026 | d->le_to->setText(str);
|
---|
1027 | //d->le_to->setCursorPosition(start + js.length());*/
|
---|
1028 | d->le_to->insert(js);
|
---|
1029 | }
|
---|
1030 |
|
---|
1031 | void EventDlg::to_tryComplete()
|
---|
1032 | {
|
---|
1033 | if(!option.jidComplete)
|
---|
1034 | return;
|
---|
1035 |
|
---|
1036 | QString str = d->le_to->text();
|
---|
1037 | int x = d->le_to->cursorPosition();
|
---|
1038 |
|
---|
1039 | int p1, p2;
|
---|
1040 | QString s = findJid(str, x, &p1, &p2);
|
---|
1041 | if(s.length() < 1 || x != p2)
|
---|
1042 | return;
|
---|
1043 |
|
---|
1044 | for(QStringList::ConstIterator it = d->completionList.begin(); it != d->completionList.end(); ++it) {
|
---|
1045 | QString name = *it;
|
---|
1046 | if(s.length() > name.length())
|
---|
1047 | continue;
|
---|
1048 |
|
---|
1049 | bool ok = true;
|
---|
1050 | int n;
|
---|
1051 | for(n = 0; n < (int)s.length(); ++n) {
|
---|
1052 | if(s.at(n).lower() != name.at(n).lower()) {
|
---|
1053 | ok = false;
|
---|
1054 | break;
|
---|
1055 | }
|
---|
1056 | }
|
---|
1057 | name = name.mid(n);
|
---|
1058 | if(ok) {
|
---|
1059 | d->le_to->insert(name);
|
---|
1060 | d->le_to->setCursorPosition(x);
|
---|
1061 | d->le_to->setSelection(x, name.length());
|
---|
1062 | break;
|
---|
1063 | }
|
---|
1064 | }
|
---|
1065 | }
|
---|
1066 |
|
---|
1067 | void EventDlg::buildCompletionList()
|
---|
1068 | {
|
---|
1069 | d->completionList.clear();
|
---|
1070 |
|
---|
1071 | d->completionList += d->pa->jid().full();
|
---|
1072 |
|
---|
1073 | UserListIt it(*d->pa->userList());
|
---|
1074 | for(UserListItem *u; (u = it.current()); ++it) {
|
---|
1075 | QString j = u->jid().full();
|
---|
1076 | if(!u->name().isEmpty())
|
---|
1077 | d->completionList += u->name() + " <"+j+'>';
|
---|
1078 | d->completionList += j;
|
---|
1079 | }
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | QString EventDlg::jidToString(const Jid &jid, const QString &r) const
|
---|
1083 | {
|
---|
1084 | QString name;
|
---|
1085 |
|
---|
1086 | QPtrList<UserListItem> ul = d->pa->findRelavent(jid);
|
---|
1087 | if(!ul.isEmpty()) {
|
---|
1088 | UserListItem *u = ul.first();
|
---|
1089 |
|
---|
1090 | QString j;
|
---|
1091 | if(r.isEmpty())
|
---|
1092 | j = u->jid().full();
|
---|
1093 | else
|
---|
1094 | j = u->jid().userHost() + '/' + r;
|
---|
1095 |
|
---|
1096 | if(!u->name().isEmpty())
|
---|
1097 | name = u->name() + QString(" <%1>").arg(enc822jid(j));
|
---|
1098 | else
|
---|
1099 | name = enc822jid(j);
|
---|
1100 | }
|
---|
1101 | else
|
---|
1102 | name = enc822jid(jid.full());
|
---|
1103 |
|
---|
1104 | return name;
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | void EventDlg::doWhois(bool force)
|
---|
1108 | {
|
---|
1109 | QString str;
|
---|
1110 | if(d->composing) {
|
---|
1111 | str = d->le_to->text();
|
---|
1112 | if(str == d->lastWhois && !force)
|
---|
1113 | return;
|
---|
1114 | }
|
---|
1115 | else {
|
---|
1116 | str = d->le_from->text();
|
---|
1117 | }
|
---|
1118 |
|
---|
1119 | //printf("whois: [%s]\n", str.latin1());
|
---|
1120 | d->lastWhois = str;
|
---|
1121 | QStringList list = stringToList(str);
|
---|
1122 | bool found = false;
|
---|
1123 | if(list.count() == 1) {
|
---|
1124 | Jid j(list[0]);
|
---|
1125 | d->jid = j;
|
---|
1126 | QPtrList<UserListItem> ul = d->pa->findRelavent(j);
|
---|
1127 | if(!ul.isEmpty()) {
|
---|
1128 | d->tb_info->setEnabled(true);
|
---|
1129 | d->tb_history->setEnabled(true);
|
---|
1130 | found = true;
|
---|
1131 | }
|
---|
1132 | updateContact(d->jid);
|
---|
1133 | }
|
---|
1134 | if(!found) {
|
---|
1135 | d->jid = "";
|
---|
1136 |
|
---|
1137 | d->lb_status->setIcon(IconsetFactory::iconPtr("status/noauth"));
|
---|
1138 | d->tb_info->setEnabled(false);
|
---|
1139 | d->tb_history->setEnabled(false);
|
---|
1140 | setCaption(tr("Send Message"));
|
---|
1141 | QToolTip::remove(d->lb_status);
|
---|
1142 | }
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | UserResourceList EventDlg::getResources(const QString &s) const
|
---|
1146 | {
|
---|
1147 | UserResourceList list;
|
---|
1148 |
|
---|
1149 | QString j = findJidInString(s);
|
---|
1150 | if(j.isEmpty())
|
---|
1151 | j = s;
|
---|
1152 | Jid jid(j);
|
---|
1153 | if(!jid.isValid())
|
---|
1154 | return list;
|
---|
1155 |
|
---|
1156 | QPtrList<UserListItem> ul = d->pa->findRelavent(jid);
|
---|
1157 | if(!ul.isEmpty()) {
|
---|
1158 | UserListItem *u = ul.first();
|
---|
1159 | if(u->isAvailable())
|
---|
1160 | return u->userResourceList();
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | return list;
|
---|
1164 | }
|
---|
1165 |
|
---|
1166 | void EventDlg::optionsUpdate()
|
---|
1167 | {
|
---|
1168 | // update the font
|
---|
1169 | QFont f;
|
---|
1170 | f.fromString(option.font[fMessage]);
|
---|
1171 | d->mle->setFont(f);
|
---|
1172 |
|
---|
1173 | // update status icon
|
---|
1174 | doWhois(true);
|
---|
1175 |
|
---|
1176 | if ( option.showCounter && d->composing )
|
---|
1177 | d->lcd_count->show();
|
---|
1178 | else
|
---|
1179 | d->lcd_count->hide();
|
---|
1180 |
|
---|
1181 | if ( option.useEmoticons )
|
---|
1182 | d->tb_icon->show();
|
---|
1183 | else
|
---|
1184 | d->tb_icon->hide();
|
---|
1185 |
|
---|
1186 | // tool buttons: not required
|
---|
1187 | d->tb_url->setIcon(IconsetFactory::iconPtr("psi/www"));
|
---|
1188 | d->tb_info->setIcon(IconsetFactory::iconPtr("psi/vCard"));
|
---|
1189 | d->tb_history->setIcon(IconsetFactory::iconPtr("psi/history"));
|
---|
1190 | if(d->tb_pgp) {
|
---|
1191 | QIconSet i;
|
---|
1192 | i.setPixmap(IconsetFactory::icon("psi/cryptoNo"), QIconSet::Automatic, QIconSet::Normal, QIconSet::Off);
|
---|
1193 | i.setPixmap(IconsetFactory::icon("psi/cryptoYes"), QIconSet::Automatic, QIconSet::Normal, QIconSet::On);
|
---|
1194 | d->tb_pgp->setIconSet(i);
|
---|
1195 | }
|
---|
1196 | if(d->lb_pgp)
|
---|
1197 | d->lb_pgp->setIcon(IconsetFactory::iconPtr(d->enc ? "psi/cryptoYes" : "psi/cryptoNo"));
|
---|
1198 |
|
---|
1199 | // update the readnext icon
|
---|
1200 | if(d->nextAmount > 0)
|
---|
1201 | d->pb_next->forceSetIcon(d->nextAnim);
|
---|
1202 |
|
---|
1203 | // update the widget icon
|
---|
1204 | #ifndef Q_WS_MAC
|
---|
1205 | if(d->composing) {
|
---|
1206 | setIcon(IconsetFactory::icon("psi/sendMessage"));
|
---|
1207 | }
|
---|
1208 | else {
|
---|
1209 | if(d->anim)
|
---|
1210 | setIcon(d->anim->impix());
|
---|
1211 | }
|
---|
1212 | #endif
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | QSize EventDlg::defaultSize()
|
---|
1216 | {
|
---|
1217 | return QSize(420, 280);
|
---|
1218 | }
|
---|
1219 |
|
---|
1220 | void EventDlg::showEvent(QShowEvent *e)
|
---|
1221 | {
|
---|
1222 | QWidget::showEvent(e);
|
---|
1223 |
|
---|
1224 | if(d->urlOnShow) {
|
---|
1225 | d->urlOnShow = false;
|
---|
1226 | QTimer::singleShot(1, this, SLOT(addUrl()));
|
---|
1227 | }
|
---|
1228 | }
|
---|
1229 |
|
---|
1230 | void EventDlg::resizeEvent(QResizeEvent *e)
|
---|
1231 | {
|
---|
1232 | if(option.keepSizes)
|
---|
1233 | option.sizeEventDlg = e->size();
|
---|
1234 | }
|
---|
1235 |
|
---|
1236 | void EventDlg::keyPressEvent(QKeyEvent *e)
|
---|
1237 | {
|
---|
1238 | if(e->key() == Key_Escape)
|
---|
1239 | close();
|
---|
1240 | #ifdef Q_WS_MAC
|
---|
1241 | else if(e->key() == Key_W && e->state() & ControlButton)
|
---|
1242 | close();
|
---|
1243 | #endif
|
---|
1244 | else if(d->composing && e->key() == Key_Return && ((e->state() & ControlButton) || (e->state() & AltButton)) )
|
---|
1245 | doSend();
|
---|
1246 | else if(e->key() == Key_H && (e->state() & ControlButton))
|
---|
1247 | doHistory();
|
---|
1248 | else if(e->key() == Key_I && (e->state() & ControlButton))
|
---|
1249 | doInfo();
|
---|
1250 | else
|
---|
1251 | e->ignore();
|
---|
1252 | }
|
---|
1253 |
|
---|
1254 | void EventDlg::closeEvent(QCloseEvent *e)
|
---|
1255 | {
|
---|
1256 | // really lame way of checking if we are encrypting
|
---|
1257 | if(!d->mle->isEnabled())
|
---|
1258 | return;
|
---|
1259 |
|
---|
1260 | e->accept();
|
---|
1261 | }
|
---|
1262 |
|
---|
1263 | void EventDlg::doSend()
|
---|
1264 | {
|
---|
1265 | if(!d->composing)
|
---|
1266 | return;
|
---|
1267 |
|
---|
1268 | if(!d->pb_send->isEnabled())
|
---|
1269 | return;
|
---|
1270 |
|
---|
1271 | if(!d->pa->checkConnected(this))
|
---|
1272 | return;
|
---|
1273 |
|
---|
1274 | if(d->mle->text().isEmpty() && d->attachView->childCount() == 0) {
|
---|
1275 | QMessageBox::information(this, tr("Warning"), tr("Please type in a message first."));
|
---|
1276 | return;
|
---|
1277 | }
|
---|
1278 |
|
---|
1279 | QStringList list = stringToList(d->le_to->text());
|
---|
1280 | if(list.isEmpty()) {
|
---|
1281 | QMessageBox::warning(this, tr("Warning"), tr("No recipients have been specified!"));
|
---|
1282 | return;
|
---|
1283 | }
|
---|
1284 |
|
---|
1285 | Message m;
|
---|
1286 | if(d->cb_type->currentItem() == 0)
|
---|
1287 | m.setType("");
|
---|
1288 | else
|
---|
1289 | m.setType("chat");
|
---|
1290 |
|
---|
1291 | m.setBody(d->mle->text());
|
---|
1292 | m.setSubject(d->le_subj->text());
|
---|
1293 | m.setUrlList(d->attachView->urlList());
|
---|
1294 | m.setTimeStamp(QDateTime::currentDateTime());
|
---|
1295 | m.setThread(d->thread);
|
---|
1296 | if(d->tb_pgp->isOn())
|
---|
1297 | m.setWasEncrypted(true);
|
---|
1298 | d->m = m;
|
---|
1299 |
|
---|
1300 | d->enc = false;
|
---|
1301 | if(d->tb_pgp->isOn()) {
|
---|
1302 | d->le_to->setEnabled(false);
|
---|
1303 | d->mle->setEnabled(false);
|
---|
1304 | d->enc = true;
|
---|
1305 | d->sendLeft = list;
|
---|
1306 |
|
---|
1307 | trySendEncryptedNext();
|
---|
1308 | }
|
---|
1309 | else {
|
---|
1310 | for(QStringList::ConstIterator it = list.begin(); it != list.end(); ++it) {
|
---|
1311 | m.setTo(Jid(*it));
|
---|
1312 | d->pa->dj_sendMessage(m);
|
---|
1313 | }
|
---|
1314 | doneSend();
|
---|
1315 | }
|
---|
1316 | }
|
---|
1317 |
|
---|
1318 | void EventDlg::doneSend()
|
---|
1319 | {
|
---|
1320 | close();
|
---|
1321 | }
|
---|
1322 |
|
---|
1323 | void EventDlg::doReadNext()
|
---|
1324 | {
|
---|
1325 | aReadNext(d->realJid);
|
---|
1326 | }
|
---|
1327 |
|
---|
1328 | void EventDlg::doChat()
|
---|
1329 | {
|
---|
1330 | QStringList list = stringToList(d->le_from->text());
|
---|
1331 | if(list.isEmpty())
|
---|
1332 | return;
|
---|
1333 |
|
---|
1334 | // FIXME: Maybe it's better without bare(), but then PsiAccount::actionChat
|
---|
1335 | // doesn't find the UserListItem to chat with :-(
|
---|
1336 | Jid jf(list[0]);
|
---|
1337 | Jid j(jf.bare());
|
---|
1338 | aChat(j);
|
---|
1339 | }
|
---|
1340 |
|
---|
1341 | void EventDlg::doReply()
|
---|
1342 | {
|
---|
1343 | QStringList list = stringToList(d->le_from->text());
|
---|
1344 | if(list.isEmpty())
|
---|
1345 | return;
|
---|
1346 | Jid j(list[0]);
|
---|
1347 | aReply(j, "", d->le_subj->text(), d->thread);
|
---|
1348 | }
|
---|
1349 |
|
---|
1350 | void EventDlg::doQuote()
|
---|
1351 | {
|
---|
1352 | QStringList list = stringToList(d->le_from->text());
|
---|
1353 | if(list.isEmpty())
|
---|
1354 | return;
|
---|
1355 | Jid j(list[0]);
|
---|
1356 |
|
---|
1357 | QString body;
|
---|
1358 | if(d->mle->hasSelectedText())
|
---|
1359 | body = rich2plain(d->mle->selectedText());
|
---|
1360 | else
|
---|
1361 | body = rich2plain(d->mle->text());
|
---|
1362 |
|
---|
1363 | aReply(j, body, d->le_subj->text(), d->thread);
|
---|
1364 | }
|
---|
1365 |
|
---|
1366 | void EventDlg::doDeny()
|
---|
1367 | {
|
---|
1368 | if(!d->pa->checkConnected(this))
|
---|
1369 | return;
|
---|
1370 |
|
---|
1371 | QStringList list = stringToList(d->le_from->text());
|
---|
1372 | if(list.isEmpty())
|
---|
1373 | return;
|
---|
1374 | Jid j(list[0]);
|
---|
1375 | aDeny(j);
|
---|
1376 | close();
|
---|
1377 | }
|
---|
1378 |
|
---|
1379 | void EventDlg::doAuth()
|
---|
1380 | {
|
---|
1381 | if(!d->pa->checkConnected(this))
|
---|
1382 | return;
|
---|
1383 |
|
---|
1384 | QStringList list = stringToList(d->le_from->text());
|
---|
1385 | if(list.isEmpty())
|
---|
1386 | return;
|
---|
1387 | Jid j(list[0]);
|
---|
1388 | aAuth(j);
|
---|
1389 | d->pb_auth->setEnabled(false);
|
---|
1390 | closeAfterReply();
|
---|
1391 | }
|
---|
1392 |
|
---|
1393 | void EventDlg::doHistory()
|
---|
1394 | {
|
---|
1395 | d->pa->actionHistory(d->jid.withResource(""));
|
---|
1396 | }
|
---|
1397 |
|
---|
1398 | void EventDlg::doInfo()
|
---|
1399 | {
|
---|
1400 | d->pa->actionInfo(d->jid);
|
---|
1401 | }
|
---|
1402 |
|
---|
1403 | void EventDlg::closeAfterReply()
|
---|
1404 | {
|
---|
1405 | if(d->nextAmount == 0)
|
---|
1406 | close();
|
---|
1407 | }
|
---|
1408 |
|
---|
1409 | void EventDlg::addUrl()
|
---|
1410 | {
|
---|
1411 | AddUrlDlg *w = new AddUrlDlg(this);
|
---|
1412 | int n = w->exec();
|
---|
1413 | if(n != QDialog::Accepted) {
|
---|
1414 | delete w;
|
---|
1415 | return;
|
---|
1416 | }
|
---|
1417 |
|
---|
1418 | QString url = w->le_url->text();
|
---|
1419 | QString desc = w->le_desc->text();
|
---|
1420 | delete w;
|
---|
1421 |
|
---|
1422 | d->attachView->urlAdd(url, desc);
|
---|
1423 | }
|
---|
1424 |
|
---|
1425 | void EventDlg::showHideAttachView()
|
---|
1426 | {
|
---|
1427 | if(d->attachView->childCount() > 0) {
|
---|
1428 | if(d->attachView->isHidden())
|
---|
1429 | d->attachView->show();
|
---|
1430 | }
|
---|
1431 | else {
|
---|
1432 | if(!d->attachView->isHidden())
|
---|
1433 | d->attachView->hide();
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 |
|
---|
1437 | void EventDlg::updateContact(const Jid &jid)
|
---|
1438 | {
|
---|
1439 | if(d->jid.compare(jid, false)) {
|
---|
1440 | QString rname = d->jid.resource();
|
---|
1441 | QPtrList<UserListItem> ul = d->pa->findRelavent(d->jid);
|
---|
1442 | UserListItem *u = 0;
|
---|
1443 | int status = -1;
|
---|
1444 | if(!ul.isEmpty()) {
|
---|
1445 | u = ul.first();
|
---|
1446 | if(rname.isEmpty()) {
|
---|
1447 | // use priority
|
---|
1448 | if(!u->isAvailable())
|
---|
1449 | status = STATUS_OFFLINE;
|
---|
1450 | else
|
---|
1451 | status = makeSTATUS((*u->userResourceList().priority()).status());
|
---|
1452 | }
|
---|
1453 | else {
|
---|
1454 | // use specific
|
---|
1455 | UserResourceList::ConstIterator rit = u->userResourceList().find(rname);
|
---|
1456 | if(rit != u->userResourceList().end())
|
---|
1457 | status = makeSTATUS((*rit).status());
|
---|
1458 | else
|
---|
1459 | status = STATUS_OFFLINE;
|
---|
1460 | }
|
---|
1461 | }
|
---|
1462 |
|
---|
1463 | if(status == -1 || !u)
|
---|
1464 | d->lb_status->setIcon(IconsetFactory::iconPtr("status/noauth"));
|
---|
1465 | else
|
---|
1466 | d->lb_status->setIcon(is->statusPtr(jid, status));
|
---|
1467 |
|
---|
1468 | if(u)
|
---|
1469 | QToolTip::add(d->lb_status, u->makeTip(true, false));
|
---|
1470 | else
|
---|
1471 | QToolTip::remove(d->lb_status);
|
---|
1472 |
|
---|
1473 | if(u)
|
---|
1474 | setCaption(jidnick(u->jid().full(), u->name()));
|
---|
1475 | }
|
---|
1476 | }
|
---|
1477 |
|
---|
1478 | void EventDlg::setTime(const QDateTime &t, bool late)
|
---|
1479 | {
|
---|
1480 | QString str;
|
---|
1481 | //str.sprintf("<nobr>%02d/%02d %02d:%02d:%02d</nobr>", t.date().month(), t.date().day(), t.time().hour(), t.time().minute(), t.time().second());
|
---|
1482 | str = QString("<nobr>") + t.toString(LocalDate) + "</nobr>";
|
---|
1483 | if(late)
|
---|
1484 | str = QString("<font color=\"red\">") + str + "</font>";
|
---|
1485 |
|
---|
1486 | d->lb_time->setText(str);
|
---|
1487 | }
|
---|
1488 |
|
---|
1489 | void EventDlg::updateEvent(PsiEvent *e)
|
---|
1490 | {
|
---|
1491 | Icon *oldanim = d->anim;
|
---|
1492 | d->anim = is->event2icon(e);
|
---|
1493 |
|
---|
1494 | if(d->anim != oldanim)
|
---|
1495 | setIcon(d->anim->impix());
|
---|
1496 |
|
---|
1497 | d->le_from->setText(expandAddresses(e->from().full(), false));
|
---|
1498 | d->le_from->setCursorPosition(0);
|
---|
1499 | QToolTip::add(d->le_from, e->from().full());
|
---|
1500 | setTime(e->timeStamp(), e->late());
|
---|
1501 |
|
---|
1502 | d->enc = false;
|
---|
1503 |
|
---|
1504 | if(e->type() == PsiEvent::Message) {
|
---|
1505 | MessageEvent *me = (MessageEvent *)e;
|
---|
1506 | const Message &m = me->message();
|
---|
1507 |
|
---|
1508 | d->enc = m.wasEncrypted();
|
---|
1509 |
|
---|
1510 | d->pb_auth->hide();
|
---|
1511 | d->pb_deny->hide();
|
---|
1512 |
|
---|
1513 | d->pb_chat->show();
|
---|
1514 | d->pb_reply->show();
|
---|
1515 | d->pb_quote->show();
|
---|
1516 |
|
---|
1517 | QString txt = plain2rich(m.body());
|
---|
1518 |
|
---|
1519 | // show subject line if the incoming message has one
|
---|
1520 | if(m.subject() != "" && !option.showSubjects)
|
---|
1521 | txt = "<p><font color=\"red\"><b>" + tr("Subject:") + " " + m.subject() + "</b></font></p>" + txt;
|
---|
1522 |
|
---|
1523 | d->mle->moveCursor(QTextEdit::MoveHome, false);
|
---|
1524 | d->mle->setTextFormat(RichText);
|
---|
1525 |
|
---|
1526 | if(option.useEmoticons)
|
---|
1527 | txt = emoticonify(txt);
|
---|
1528 |
|
---|
1529 | d->mle->setText("<qt>" + linkify(txt) + "</qt>");
|
---|
1530 |
|
---|
1531 | d->le_subj->setText(m.subject());
|
---|
1532 | d->le_subj->setCursorPosition(0);
|
---|
1533 |
|
---|
1534 | d->thread = m.thread();
|
---|
1535 |
|
---|
1536 | d->attachView->clear();
|
---|
1537 | d->attachView->addUrlList(m.urlList());
|
---|
1538 |
|
---|
1539 | if(!m.invite().isEmpty())
|
---|
1540 | d->attachView->gcAdd(m.invite());
|
---|
1541 | showHideAttachView();
|
---|
1542 | }
|
---|
1543 | else if(e->type() == PsiEvent::Auth) {
|
---|
1544 | AuthEvent *ae = (AuthEvent *)e;
|
---|
1545 | QString type = ae->authType();
|
---|
1546 |
|
---|
1547 | d->le_subj->setText("");
|
---|
1548 | if(type == "subscribe") {
|
---|
1549 | QString body(tr("<big>[System Message]</big><br>This user wants to subscribe to your presence. Click the button labelled \"Add/Auth\" to authorize the subscription. This will also add the person to your contact list if it is not already there."));
|
---|
1550 | d->mle->moveCursor(QTextEdit::MoveHome, false);
|
---|
1551 | d->mle->setTextFormat(RichText);
|
---|
1552 | d->mle->setText("<qt>" + body + "</qt>");
|
---|
1553 |
|
---|
1554 | d->pb_chat->show();
|
---|
1555 | d->pb_reply->hide();
|
---|
1556 | d->pb_quote->hide();
|
---|
1557 |
|
---|
1558 | d->pb_auth->setEnabled(true);
|
---|
1559 | d->pb_auth->show();
|
---|
1560 | d->pb_deny->show();
|
---|
1561 | }
|
---|
1562 | else if(type == "subscribed") {
|
---|
1563 | QString body(tr("<big>[System Message]</big><br>You are now authorized."));
|
---|
1564 | d->mle->moveCursor(QTextEdit::MoveHome, false);
|
---|
1565 | d->mle->setTextFormat(RichText);
|
---|
1566 | d->mle->setText("<qt>" + body + "</qt>");
|
---|
1567 |
|
---|
1568 | d->pb_auth->hide();
|
---|
1569 | d->pb_deny->hide();
|
---|
1570 | d->pb_chat->show();
|
---|
1571 | d->pb_reply->show();
|
---|
1572 | d->pb_quote->show();
|
---|
1573 | }
|
---|
1574 | else if(type == "unsubscribed") {
|
---|
1575 | QString body(tr("<big>[System Message]</big><br>Your authorization has been removed!"));
|
---|
1576 | d->mle->moveCursor(QTextEdit::MoveHome, false);
|
---|
1577 | d->mle->setTextFormat(RichText);
|
---|
1578 | d->mle->setText("<qt>" + body + "</qt>");
|
---|
1579 |
|
---|
1580 | d->pb_auth->hide();
|
---|
1581 | d->pb_deny->hide();
|
---|
1582 | d->pb_chat->show();
|
---|
1583 | d->pb_reply->show();
|
---|
1584 | d->pb_quote->show();
|
---|
1585 | }
|
---|
1586 | }
|
---|
1587 |
|
---|
1588 | if(d->lb_pgp)
|
---|
1589 | d->lb_pgp->setIcon( IconsetFactory::iconPtr(d->enc ? "psi/cryptoYes" : "psi/cryptoNo") );
|
---|
1590 |
|
---|
1591 | if(!d->le_subj->text().isEmpty())
|
---|
1592 | QToolTip::add(d->le_subj, d->le_subj->text());
|
---|
1593 | else
|
---|
1594 | QToolTip::remove(d->le_subj);
|
---|
1595 |
|
---|
1596 | doWhois();
|
---|
1597 | }
|
---|
1598 |
|
---|
1599 | void EventDlg::updateReadNext(Icon *nextAnim, int nextAmount)
|
---|
1600 | {
|
---|
1601 | int oldAmount = d->nextAmount;
|
---|
1602 |
|
---|
1603 | d->nextAnim = nextAnim;
|
---|
1604 | d->nextAmount = nextAmount;
|
---|
1605 |
|
---|
1606 | if(nextAmount == 0) {
|
---|
1607 | d->nextAnim = 0;
|
---|
1608 | d->pb_next->forceSetIcon(0);
|
---|
1609 | d->pb_next->setEnabled(false);
|
---|
1610 | d->pb_next->setText(tr("&Next"));
|
---|
1611 |
|
---|
1612 | if(d->pb_reply->isEnabled())
|
---|
1613 | d->pb_reply->setFocus();
|
---|
1614 | else if(d->pb_auth->isVisible())
|
---|
1615 | d->pb_auth->setFocus();
|
---|
1616 | }
|
---|
1617 | else {
|
---|
1618 | d->pb_next->setEnabled(true);
|
---|
1619 | QString str(tr("&Next"));
|
---|
1620 | str += QString(" - %1").arg(nextAmount);
|
---|
1621 | d->pb_next->setText(str);
|
---|
1622 |
|
---|
1623 | d->pb_next->forceSetIcon(d->nextAnim);
|
---|
1624 |
|
---|
1625 | if(d->nextAmount > oldAmount)
|
---|
1626 | d->pb_next->setFocus();
|
---|
1627 | }
|
---|
1628 | }
|
---|
1629 |
|
---|
1630 | void EventDlg::actionGCJoin(const QString &gc)
|
---|
1631 | {
|
---|
1632 | Jid j(gc);
|
---|
1633 | d->pa->actionJoin(j.withResource(""));
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | void EventDlg::updatePGP()
|
---|
1637 | {
|
---|
1638 | if(d->tb_pgp) {
|
---|
1639 | if(!d->pa->pgpKey().isEmpty()) {
|
---|
1640 | d->tb_pgp->setEnabled(true);
|
---|
1641 | }
|
---|
1642 | else {
|
---|
1643 | d->tb_pgp->setOn(false);
|
---|
1644 | d->tb_pgp->setEnabled(false);
|
---|
1645 | }
|
---|
1646 | }
|
---|
1647 | }
|
---|
1648 |
|
---|
1649 | void EventDlg::trySendEncryptedNext()
|
---|
1650 | {
|
---|
1651 | if(d->sendLeft.isEmpty())
|
---|
1652 | return;
|
---|
1653 | Message m = d->m;
|
---|
1654 | m.setTo(Jid(d->sendLeft.first()));
|
---|
1655 | d->transid = d->pa->sendMessageEncrypted(m);
|
---|
1656 | if(d->transid == -1) {
|
---|
1657 | d->le_to->setEnabled(true);
|
---|
1658 | d->mle->setEnabled(true);
|
---|
1659 | d->mle->setFocus();
|
---|
1660 | return;
|
---|
1661 | }
|
---|
1662 | }
|
---|
1663 |
|
---|
1664 | void EventDlg::encryptedMessageSent(int x, bool b)
|
---|
1665 | {
|
---|
1666 | if(d->transid == -1)
|
---|
1667 | return;
|
---|
1668 | if(d->transid != x)
|
---|
1669 | return;
|
---|
1670 | d->transid = -1;
|
---|
1671 | if(b) {
|
---|
1672 | // remove the item
|
---|
1673 | QStringList::Iterator it = d->sendLeft.begin();
|
---|
1674 | Jid j(*it);
|
---|
1675 | d->sendLeft.remove(it);
|
---|
1676 |
|
---|
1677 | //d->pa->toggleSecurity(j, d->enc);
|
---|
1678 |
|
---|
1679 | if(d->sendLeft.isEmpty()) {
|
---|
1680 | d->le_to->setEnabled(true);
|
---|
1681 | d->mle->setEnabled(true);
|
---|
1682 | doneSend();
|
---|
1683 | }
|
---|
1684 | else {
|
---|
1685 | trySendEncryptedNext();
|
---|
1686 | return;
|
---|
1687 | }
|
---|
1688 | }
|
---|
1689 | else
|
---|
1690 | QMessageBox::information(this, tr("Error"), tr("There was an error trying to send the message encrypted.\nCheck your OpenPGP application/settings."));
|
---|
1691 |
|
---|
1692 | d->le_to->setEnabled(true);
|
---|
1693 | d->mle->setEnabled(true);
|
---|
1694 | d->mle->setFocus();
|
---|
1695 | }
|
---|
1696 |
|
---|
1697 | #include "eventdlg.moc"
|
---|