~ubuntu-branches/ubuntu/quantal/psi/quantal

« back to all changes in this revision

Viewing changes to src/psievent.cpp

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

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * psievent.h - 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 "psievent.h"
 
22
 
 
23
#include <qdom.h>
 
24
 
 
25
#include "psicon.h"
 
26
#include "psiaccount.h"
 
27
#include "xmpp_xmlcommon.h"
 
28
#include "filetransfer.h"
 
29
 
 
30
using namespace XMLHelper;
 
31
 
 
32
static PsiEvent *copyPsiEvent(PsiEvent *fe)
 
33
{
 
34
        PsiEvent *e = 0;
 
35
        if ( fe->inherits("MessageEvent") )
 
36
                e = new MessageEvent( *((MessageEvent *)fe) );
 
37
        else if ( fe->inherits("AuthEvent") )
 
38
                e = new AuthEvent( *((AuthEvent *)fe) );
 
39
        else if ( fe->inherits("PGPEvent") )
 
40
                e = new PGPEvent( *((PGPEvent *)fe) );
 
41
        else
 
42
                qWarning("copyPsiEvent(): Failed: unknown event type: %s", fe->className());
 
43
 
 
44
        return 0;
 
45
}
 
46
 
 
47
//----------------------------------------------------------------------------
 
48
// DummyStream
 
49
//----------------------------------------------------------------------------
 
50
class DummyStream : public Stream
 
51
{
 
52
public:
 
53
        QDomDocument & doc() const { return v_doc; }
 
54
        QString baseNS() const { return QString::null; }
 
55
        bool old() const { return false; }
 
56
 
 
57
        void close() { }
 
58
        bool stanzaAvailable() const { return false; }
 
59
        Stanza read() { return Stanza(); }
 
60
        void write(const Stanza &) { }
 
61
 
 
62
        int errorCondition() const { return 0; }
 
63
        QString errorText() const { return QString::null; }
 
64
        QDomElement errorAppSpec() const { return v_doc.documentElement(); }
 
65
 
 
66
private:
 
67
        static QDomDocument v_doc;
 
68
};
 
69
 
 
70
QDomDocument DummyStream::v_doc;
 
71
 
 
72
//----------------------------------------------------------------------------
 
73
// PsiEvent
 
74
//----------------------------------------------------------------------------
 
75
PsiEvent::PsiEvent(PsiAccount *acc)
 
76
{
 
77
        v_originLocal = false;
 
78
        v_late = false;
 
79
        v_account = acc;
 
80
}
 
81
 
 
82
PsiEvent::PsiEvent(const PsiEvent &from)
 
83
: QObject()
 
84
{
 
85
        v_originLocal = from.v_originLocal;
 
86
        v_late = from.v_late;
 
87
        v_ts = from.v_ts;
 
88
        v_jid = from.v_jid;
 
89
        v_account = from.v_account;
 
90
}
 
91
 
 
92
PsiEvent::~PsiEvent()
 
93
{
 
94
}
 
95
 
 
96
XMPP::Jid PsiEvent::jid() const
 
97
{
 
98
        return v_jid;
 
99
}
 
100
 
 
101
void PsiEvent::setJid(const XMPP::Jid &j)
 
102
{
 
103
        v_jid = j;
 
104
}
 
105
 
 
106
PsiAccount *PsiEvent::account() const
 
107
{
 
108
        return v_account;
 
109
}
 
110
 
 
111
bool PsiEvent::originLocal() const
 
112
{
 
113
        return v_originLocal;
 
114
}
 
115
 
 
116
bool PsiEvent::late() const
 
117
{
 
118
        return v_late;
 
119
}
 
120
 
 
121
QDateTime PsiEvent::timeStamp() const
 
122
{
 
123
        return v_ts;
 
124
}
 
125
 
 
126
void PsiEvent::setOriginLocal(bool b)
 
127
{
 
128
        v_originLocal = b;
 
129
}
 
130
 
 
131
void PsiEvent::setLate(bool b)
 
132
{
 
133
        v_late = b;
 
134
}
 
135
 
 
136
void PsiEvent::setTimeStamp(const QDateTime &t)
 
137
{
 
138
        v_ts = t;
 
139
}
 
140
 
 
141
QDomElement *PsiEvent::toXml(QDomDocument *doc) const
 
142
{
 
143
        QDomElement e = doc->createElement("event");
 
144
        e.setAttribute("type", className());
 
145
 
 
146
        e.appendChild( textTag(*doc, "originLocal",     v_originLocal) );
 
147
        e.appendChild( textTag(*doc, "late",            v_late) );
 
148
        e.appendChild( textTag(*doc, "ts",              v_ts.toString( ISODate )) );
 
149
        if ( !v_jid.full().isEmpty() )
 
150
                e.appendChild( textTag(*doc, "jid",             v_jid.full()) );
 
151
 
 
152
        if ( v_account )
 
153
                e.appendChild( textTag(*doc, "account", v_account->name()) );
 
154
 
 
155
        QDomElement *ret = new QDomElement(e);
 
156
        return ret;
 
157
}
 
158
 
 
159
bool PsiEvent::fromXml(PsiCon *psi, const QDomElement *e)
 
160
{
 
161
        if ( e->tagName() != "event" )
 
162
                return false;
 
163
        if ( e->attribute("type") != className() )
 
164
                return false;
 
165
 
 
166
        readBoolEntry(*e, "originLocal", &v_originLocal);
 
167
        readBoolEntry(*e, "late", &v_late);
 
168
        v_ts  = QDateTime::fromString(subTagText(*e, "ts"), ISODate);
 
169
        v_jid = Jid( subTagText(*e, "jid") );
 
170
 
 
171
        if ( hasSubTag(*e, "account") ) {
 
172
                PsiAccountList list = psi->accountList();
 
173
                PsiAccountListIt it(list);
 
174
                QString accName = subTagText(*e, "account");
 
175
                for ( ; it.current(); ++it) {
 
176
                        if ( it.current()->name() == accName ) {
 
177
                                v_account = it.current();
 
178
                                break;
 
179
                        }
 
180
                }
 
181
        }
 
182
 
 
183
        return true;
 
184
}
 
185
 
 
186
int PsiEvent::priority() const
 
187
{
 
188
        return Options::EventPriorityDontCare;
 
189
}
 
190
 
 
191
//----------------------------------------------------------------------------
 
192
// MessageEvent
 
193
//----------------------------------------------------------------------------
 
194
 
 
195
MessageEvent::MessageEvent(PsiAccount *acc)
 
196
: PsiEvent(acc)
 
197
{
 
198
        v_sentToChatWindow = false;
 
199
}
 
200
 
 
201
MessageEvent::MessageEvent(const XMPP::Message &m, PsiAccount *acc)
 
202
: PsiEvent(acc)
 
203
{
 
204
        v_sentToChatWindow = false;
 
205
        setMessage(m);
 
206
}
 
207
 
 
208
MessageEvent::MessageEvent(const MessageEvent &from)
 
209
: PsiEvent(from), v_m(from.v_m), v_sentToChatWindow(from.v_sentToChatWindow)
 
210
{
 
211
}
 
212
 
 
213
MessageEvent::~MessageEvent()
 
214
{
 
215
}
 
216
 
 
217
int MessageEvent::type() const
 
218
{
 
219
        return Message;
 
220
}
 
221
 
 
222
Jid MessageEvent::from() const
 
223
{
 
224
        return v_m.from();
 
225
}
 
226
 
 
227
void MessageEvent::setFrom(const Jid &j)
 
228
{
 
229
        v_m.setFrom(j);
 
230
}
 
231
 
 
232
bool MessageEvent::sentToChatWindow() const
 
233
{
 
234
        return v_sentToChatWindow;
 
235
}
 
236
 
 
237
const XMPP::Message & MessageEvent::message() const
 
238
{
 
239
        return v_m;
 
240
}
 
241
 
 
242
void MessageEvent::setSentToChatWindow(bool b)
 
243
{
 
244
        v_sentToChatWindow = b;
 
245
}
 
246
 
 
247
void MessageEvent::setMessage(const XMPP::Message &m)
 
248
{
 
249
        v_m = m;
 
250
        setTimeStamp ( v_m.timeStamp() );
 
251
        setLate ( v_m.spooled() );
 
252
}
 
253
 
 
254
QDomElement *MessageEvent::toXml(QDomDocument *doc) const
 
255
{
 
256
        QDomElement *e = PsiEvent::toXml(doc);
 
257
        if ( !e )
 
258
                return 0;
 
259
 
 
260
        DummyStream stream;
 
261
        Stanza s = v_m.toStanza(&stream);
 
262
        e->appendChild( s.element() );
 
263
 
 
264
        return e;
 
265
}
 
266
 
 
267
bool MessageEvent::fromXml(PsiCon *psi, const QDomElement *e)
 
268
{
 
269
        if ( !PsiEvent::fromXml(psi, e) )
 
270
                return false;
 
271
 
 
272
        bool found = false;
 
273
        QDomElement msg = findSubTag(*e, "message", &found);
 
274
        if ( found ) {
 
275
                DummyStream stream;
 
276
                Stanza s = stream.createStanza(msg);
 
277
                v_m.fromStanza(s, 0); // FIXME: fix tzoffset?
 
278
                return true;
 
279
        }
 
280
 
 
281
        return false;
 
282
}
 
283
 
 
284
int MessageEvent::priority() const
 
285
{
 
286
        if ( v_m.type() == "headline" )
 
287
                return option.eventPriorityHeadline;
 
288
        else if ( v_m.type() == "chat" )
 
289
                return option.eventPriorityChat;
 
290
 
 
291
        return option.eventPriorityMessage;
 
292
}
 
293
 
 
294
//----------------------------------------------------------------------------
 
295
// AuthEvent
 
296
//----------------------------------------------------------------------------
 
297
 
 
298
AuthEvent::AuthEvent(const Jid &j, const QString &authType, PsiAccount *acc)
 
299
: PsiEvent(acc)
 
300
{
 
301
        v_from = j;
 
302
        v_at = authType;
 
303
}
 
304
 
 
305
AuthEvent::AuthEvent(const AuthEvent &from)
 
306
: PsiEvent(from), v_from(from.v_from), v_at(from.v_at)
 
307
{
 
308
}
 
309
 
 
310
AuthEvent::~AuthEvent()
 
311
{
 
312
}
 
313
 
 
314
int AuthEvent::type() const
 
315
{
 
316
        return Auth;
 
317
}
 
318
 
 
319
Jid AuthEvent::from() const
 
320
{
 
321
        return v_from;
 
322
}
 
323
 
 
324
void AuthEvent::setFrom(const Jid &j)
 
325
{
 
326
        v_from = j;
 
327
}
 
328
 
 
329
QString AuthEvent::authType() const
 
330
{
 
331
        return v_at;
 
332
}
 
333
 
 
334
QDomElement *AuthEvent::toXml(QDomDocument *doc) const
 
335
{
 
336
        QDomElement *e = PsiEvent::toXml(doc);
 
337
        if ( !e )
 
338
                return 0;
 
339
 
 
340
        e->appendChild( textTag(*doc, "from",    v_from.full()) );
 
341
        e->appendChild( textTag(*doc, "authType", v_at) );
 
342
 
 
343
        return 0;
 
344
}
 
345
 
 
346
bool AuthEvent::fromXml(PsiCon *psi, const QDomElement *e)
 
347
{
 
348
        if ( !PsiEvent::fromXml(psi, e) )
 
349
                return false;
 
350
 
 
351
        v_from = Jid( subTagText(*e, "from") );
 
352
        v_at   = subTagText(*e, "authType");
 
353
 
 
354
        return false;
 
355
}
 
356
 
 
357
int AuthEvent::priority() const
 
358
{
 
359
        return option.eventPriorityAuth;
 
360
}
 
361
 
 
362
//----------------------------------------------------------------------------
 
363
// FileEvent
 
364
//----------------------------------------------------------------------------
 
365
FileEvent::FileEvent(const Jid &j, FileTransfer *_ft, PsiAccount *acc)
 
366
:PsiEvent(acc)
 
367
{
 
368
        v_from = j;
 
369
        ft = _ft;
 
370
}
 
371
 
 
372
FileEvent::~FileEvent()
 
373
{
 
374
        delete ft;
 
375
}
 
376
 
 
377
int FileEvent::priority() const
 
378
{
 
379
        return option.eventPriorityFile;
 
380
}
 
381
 
 
382
Jid FileEvent::from() const
 
383
{
 
384
        return v_from;
 
385
}
 
386
 
 
387
void FileEvent::setFrom(const Jid &j)
 
388
{
 
389
        v_from = j;
 
390
}
 
391
 
 
392
FileTransfer *FileEvent::takeFileTransfer()
 
393
{
 
394
        FileTransfer *_ft = ft;
 
395
        ft = 0;
 
396
        return _ft;
 
397
}
 
398
 
 
399
//----------------------------------------------------------------------------
 
400
// EventQueue
 
401
//----------------------------------------------------------------------------
 
402
 
 
403
class EventItem
 
404
{
 
405
public:
 
406
        EventItem(PsiEvent *_e, int i)
 
407
        {
 
408
                e = _e;
 
409
                v_id = i;
 
410
        }
 
411
 
 
412
        EventItem(const EventItem &from)
 
413
        {
 
414
                e = copyPsiEvent(from.e);
 
415
                v_id = from.v_id;
 
416
        }
 
417
 
 
418
        ~EventItem()
 
419
        {
 
420
        }
 
421
 
 
422
        int id() const
 
423
        {
 
424
                return v_id;
 
425
        }
 
426
 
 
427
        PsiEvent *event() const
 
428
        {
 
429
                return e;
 
430
        }
 
431
 
 
432
private:
 
433
        PsiEvent *e;
 
434
        int v_id;
 
435
};
 
436
 
 
437
class EventQueue::Private
 
438
{
 
439
public:
 
440
        Private() {
 
441
                list.setAutoDelete(true);
 
442
        }
 
443
 
 
444
        QPtrList<EventItem> list;
 
445
        PsiCon *psi;
 
446
};
 
447
 
 
448
EventQueue::EventQueue(PsiCon *psi)
 
449
{
 
450
        d = new Private();
 
451
 
 
452
        d->psi = psi;
 
453
}
 
454
 
 
455
EventQueue::EventQueue(const EventQueue &from)
 
456
        : QObject()
 
457
{
 
458
        d = new Private();
 
459
 
 
460
        *this = from;
 
461
}
 
462
 
 
463
EventQueue::~EventQueue()
 
464
{
 
465
        delete d;
 
466
}
 
467
 
 
468
int EventQueue::nextId() const
 
469
{
 
470
        QPtrListIterator<EventItem> it(d->list);
 
471
        EventItem *i = it.current();
 
472
        if(!i)
 
473
                return -1;
 
474
        return i->id();
 
475
}
 
476
 
 
477
int EventQueue::count() const
 
478
{
 
479
        return d->list.count();
 
480
}
 
481
 
 
482
int EventQueue::count(const Jid &j, bool compareRes) const
 
483
{
 
484
        int total = 0;
 
485
 
 
486
        QPtrListIterator<EventItem> it(d->list);
 
487
        for(EventItem *i; (i = it.current()); ++it) {
 
488
                Jid j2(i->event()->jid());
 
489
                if(j.compare(j2, compareRes))
 
490
                        ++total;
 
491
        }
 
492
 
 
493
        return total;
 
494
}
 
495
 
 
496
void EventQueue::enqueue(PsiEvent *e)
 
497
{
 
498
        EventItem *i = new EventItem(e, d->psi->getId());
 
499
 
 
500
        int prior  = e->priority();
 
501
        bool found = false;
 
502
 
 
503
        // skip all with higher or equal priority
 
504
        for ( EventItem *ei = d->list.first(); ei; ei = d->list.next() ) {
 
505
                if ( ei && ei->event()->priority() < prior ) {
 
506
                        d->list.insert(d->list.find(ei), i);
 
507
                        found = true;
 
508
                        break;
 
509
                }
 
510
        }
 
511
 
 
512
        // everything else
 
513
        if ( !found )
 
514
                d->list.append(i);
 
515
 
 
516
        emit queueChanged();
 
517
}
 
518
 
 
519
void EventQueue::dequeue(PsiEvent *e)
 
520
{
 
521
        if ( !e )
 
522
                return;
 
523
 
 
524
        QPtrListIterator<EventItem> it(d->list);
 
525
        for(EventItem *i; (i = it.current()); ++it) {
 
526
                if ( e == i->event() ) {
 
527
                        d->list.remove(i);
 
528
                        return;
 
529
                }
 
530
        }
 
531
 
 
532
        emit queueChanged();
 
533
}
 
534
 
 
535
PsiEvent *EventQueue::dequeue(const Jid &j, bool compareRes)
 
536
{
 
537
        QPtrListIterator<EventItem> it(d->list);
 
538
        for(EventItem *i; (i = it.current()); ++it) {
 
539
                PsiEvent *e = i->event();
 
540
                Jid j2(e->jid());
 
541
                if(j.compare(j2, compareRes)) {
 
542
                        d->list.removeRef(i);
 
543
                        emit queueChanged();
 
544
                        return e;
 
545
                }
 
546
        }
 
547
 
 
548
        return 0;
 
549
}
 
550
 
 
551
PsiEvent *EventQueue::peek(const Jid &j, bool compareRes) const
 
552
{
 
553
        QPtrListIterator<EventItem> it(d->list);
 
554
        for(EventItem *i; (i = it.current()); ++it) {
 
555
                PsiEvent *e = i->event();
 
556
                Jid j2(e->jid());
 
557
                if(j.compare(j2, compareRes)) {
 
558
                        return e;
 
559
                }
 
560
        }
 
561
 
 
562
        return 0;
 
563
}
 
564
 
 
565
PsiEvent *EventQueue::dequeueNext()
 
566
{
 
567
        QPtrListIterator<EventItem> it(d->list);
 
568
        EventItem *i = it.current();
 
569
        if(!i)
 
570
                return 0;
 
571
        PsiEvent *e = i->event();
 
572
        d->list.remove(it);
 
573
        emit queueChanged();
 
574
        return e;
 
575
}
 
576
 
 
577
PsiEvent *EventQueue::peekNext() const
 
578
{
 
579
        QPtrListIterator<EventItem> it(d->list);
 
580
        EventItem *i = it.current();
 
581
        if(!i)
 
582
                return 0;
 
583
        return i->event();
 
584
}
 
585
 
 
586
PsiEvent *EventQueue::peekFirstChat(const Jid &j, bool compareRes) const
 
587
{
 
588
        QPtrListIterator<EventItem> it(d->list);
 
589
        for(EventItem *i; (i = it.current()); ++it) {
 
590
                PsiEvent *e = i->event();
 
591
                if(e->type() == PsiEvent::Message) {
 
592
                        MessageEvent *me = (MessageEvent *)e;
 
593
                        if(j.compare(me->from(), compareRes) && me->message().type() == "chat")
 
594
                                return e;
 
595
                }
 
596
        }
 
597
 
 
598
        return 0;
 
599
}
 
600
 
 
601
bool EventQueue::hasChats(const Jid &j, bool compareRes) const
 
602
{
 
603
        return (peekFirstChat(j, compareRes) ? true: false);
 
604
}
 
605
 
 
606
// this function extracts all chats from the queue, and returns a list of queue positions
 
607
void EventQueue::extractChats(QPtrList<PsiEvent> *el, const Jid &j, bool compareRes)
 
608
{
 
609
        bool changed = false;
 
610
 
 
611
        QPtrListIterator<EventItem> it(d->list);
 
612
        for(EventItem *i; (i = it.current());) {
 
613
                PsiEvent *e = i->event();
 
614
                if(e->type() == PsiEvent::Message) {
 
615
                        MessageEvent *me = (MessageEvent *)e;
 
616
                        if(j.compare(me->from(), compareRes) && me->message().type() == "chat") {
 
617
                                el->append(me);
 
618
                                d->list.remove(it);
 
619
                                changed = true;
 
620
                                continue;
 
621
                        }
 
622
                }
 
623
                ++it;
 
624
        }
 
625
 
 
626
        if ( changed )
 
627
                emit queueChanged();
 
628
}
 
629
 
 
630
void EventQueue::printContent() const
 
631
{
 
632
        QPtrListIterator<EventItem> it(d->list);
 
633
        for(EventItem *i; (i = it.current()); ++it) {
 
634
                PsiEvent *e = i->event();
 
635
                printf("  %d: (%d) from=[%s] jid=[%s]\n", i->id(), e->type(), e->from().full().latin1(), e->jid().full().latin1());
 
636
        }
 
637
}
 
638
 
 
639
void EventQueue::clear()
 
640
{
 
641
        d->list.clear();
 
642
 
 
643
        emit queueChanged();
 
644
}
 
645
 
 
646
// this function removes all events associated with the input jid
 
647
void EventQueue::clear(const Jid &j, bool compareRes)
 
648
{
 
649
        bool changed = false;
 
650
 
 
651
        QPtrListIterator<EventItem> it(d->list);
 
652
        for(EventItem *i; (i = it.current());) {
 
653
                PsiEvent *e = i->event();
 
654
                Jid j2(e->jid());
 
655
                if(j.compare(j2, compareRes)) {
 
656
                        d->list.removeRef(i);
 
657
                        changed = true;
 
658
                }
 
659
                else
 
660
                        ++it;
 
661
        }
 
662
 
 
663
        if ( changed )
 
664
                emit queueChanged();
 
665
}
 
666
 
 
667
EventQueue &EventQueue::operator= (const EventQueue &from)
 
668
{
 
669
        d->list.clear();
 
670
        d->psi = from.d->psi;
 
671
 
 
672
        QPtrListIterator<EventItem> it(d->list);
 
673
        for(EventItem *i; (i = it.current()); ++i) {
 
674
                PsiEvent *e = i->event();
 
675
 
 
676
                enqueue( copyPsiEvent(e) );
 
677
        }
 
678
 
 
679
        return *this;
 
680
}
 
681
 
 
682
QDomElement *EventQueue::toXml(QDomDocument *doc) const
 
683
{
 
684
        QDomElement e = doc->createElement("eventQueue");
 
685
        e.setAttribute("version", "1.0");
 
686
        e.appendChild(textTag(doc, "progver", PROG_VERSION));
 
687
 
 
688
        QPtrListIterator<EventItem> it(d->list);
 
689
        for(EventItem *i; (i = it.current()); ++it) {
 
690
                QDomElement *event = (*it)->event()->toXml(doc);
 
691
 
 
692
                if ( event ) {
 
693
                        e.appendChild( *event );
 
694
                        delete event;
 
695
                }
 
696
        }
 
697
 
 
698
        QDomElement *ret = new QDomElement(e);
 
699
        return ret;
 
700
}
 
701
 
 
702
bool EventQueue::fromXml(const QDomElement *q)
 
703
{
 
704
        if ( !q )
 
705
                return false;
 
706
 
 
707
        if ( q->tagName() != "eventQueue" )
 
708
                return false;
 
709
 
 
710
        if ( q->attribute("version") != "1.0" )
 
711
                return false;
 
712
 
 
713
        QString progver = subTagText(*q, "progver");
 
714
 
 
715
        for(QDomNode n = q->firstChild(); !n.isNull(); n = n.nextSibling()) {
 
716
                QDomElement e = n.toElement();
 
717
                if( e.isNull() )
 
718
                        continue;
 
719
 
 
720
                if ( e.tagName() != "event" )
 
721
                        continue;
 
722
 
 
723
                PsiEvent *event = 0;
 
724
                QString eventType = e.attribute("type");
 
725
                if ( eventType == "MessageEvent" ) {
 
726
                        event = new MessageEvent(0);
 
727
                        if ( !event->fromXml(d->psi, &e) ) {
 
728
                                delete event;
 
729
                                event = 0;
 
730
                        }
 
731
                }
 
732
                else if ( eventType == "AuthEvent" ) {
 
733
                        event = new AuthEvent("", "", 0);
 
734
                        if ( !event->fromXml(d->psi, &e) ) {
 
735
                                delete event;
 
736
                                event = 0;
 
737
                        }
 
738
                }
 
739
 
 
740
                if ( event )
 
741
                        emit handleEvent( event );
 
742
        }
 
743
 
 
744
        return true;
 
745
}
 
746
 
 
747
bool EventQueue::toFile(const QString &fname)
 
748
{
 
749
        QDomDocument doc;
 
750
 
 
751
        QDomElement *element = toXml(&doc);
 
752
        if ( !element )
 
753
                return FALSE;
 
754
        doc.appendChild(*element);
 
755
 
 
756
        QFile f( fname );
 
757
        if( !f.open(IO_WriteOnly) )
 
758
                return FALSE;
 
759
        QTextStream t;
 
760
        t.setDevice( &f );
 
761
        t.setEncoding( QTextStream::UnicodeUTF8 );
 
762
        t << doc.toString(4);
 
763
        t.unsetDevice();
 
764
        f.close();
 
765
 
 
766
        return TRUE;
 
767
}
 
768
 
 
769
bool EventQueue::fromFile(const QString &fname)
 
770
{
 
771
        QString confver;
 
772
        QDomDocument doc;
 
773
 
 
774
        QFile f(fname);
 
775
        if(!f.open(IO_ReadOnly))
 
776
                return FALSE;
 
777
        if(!doc.setContent(&f, true))
 
778
                return FALSE;
 
779
        f.close();
 
780
 
 
781
        QDomElement base = doc.documentElement();
 
782
        return fromXml(&base);
 
783
}