source: psi/trunk/src/psievent.h@ 37

Last change on this file since 37 was 2, checked in by dmik, 19 years ago

Imported original Psi 0.10 sources from Affinix

File size: 4.8 KB
Line 
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#ifndef PSIEVENT_H
22#define PSIEVENT_H
23
24#include <qdatetime.h>
25#include <qobject.h>
26#include <qptrlist.h>
27#include <qdom.h>
28#include <qguardedptr.h>
29
30#include"im.h"
31
32namespace XMPP
33{
34 class FileTransfer;
35};
36
37using namespace XMPP;
38
39class PsiCon;
40class PsiAccount;
41
42
43class PsiEvent : public QObject
44{
45 Q_OBJECT
46public:
47 PsiEvent(PsiAccount *);
48 PsiEvent(const PsiEvent &);
49 virtual ~PsiEvent() = 0;
50
51 enum {
52 Message,
53 Auth,
54 PGP,
55 File
56 };
57 virtual int type() const = 0;
58
59 virtual Jid from() const = 0;
60 virtual void setFrom(const Jid &j) = 0;
61
62 Jid jid() const;
63 void setJid(const Jid &);
64
65 bool originLocal() const;
66 bool late() const;
67 QDateTime timeStamp() const;
68
69 void setOriginLocal(bool b);
70 void setLate(bool b);
71 void setTimeStamp(const QDateTime &t);
72
73 PsiAccount *account() const;
74
75 virtual QDomElement toXml(QDomDocument *) const;
76 virtual bool fromXml(PsiCon *, PsiAccount *, const QDomElement *);
77
78 virtual int priority() const;
79
80 virtual PsiEvent *copy() const;
81
82private:
83 bool v_originLocal, v_late;
84 QDateTime v_ts;
85 Jid v_jid;
86 PsiAccount *v_account;
87};
88
89// normal, chat, error, headline, etc
90class MessageEvent : public PsiEvent
91{
92 Q_OBJECT
93public:
94 MessageEvent(PsiAccount *acc);
95 MessageEvent(const MessageEvent &from);
96 MessageEvent(const XMPP::Message &, PsiAccount *acc);
97 ~MessageEvent();
98
99 int type() const;
100 Jid from() const;
101 void setFrom(const Jid &j);
102
103 bool sentToChatWindow() const;
104 const XMPP::Message & message() const;
105
106 void setSentToChatWindow(bool b);
107 void setMessage(const XMPP::Message &m);
108
109 QDomElement toXml(QDomDocument *) const;
110 bool fromXml(PsiCon *, PsiAccount *, const QDomElement *);
111
112 virtual int priority() const;
113
114 virtual PsiEvent *copy() const;
115
116private:
117 XMPP::Message v_m;
118 bool v_sentToChatWindow;
119};
120
121// subscribe, subscribed, unsubscribe, unsubscribed
122class AuthEvent : public PsiEvent
123{
124 Q_OBJECT
125public:
126 AuthEvent(const Jid &j, const QString &authType, PsiAccount *acc);
127 AuthEvent(const AuthEvent &from);
128 ~AuthEvent();
129
130 int type() const;
131 Jid from() const;
132 void setFrom(const Jid &j);
133
134 QString authType() const;
135
136 QDomElement toXml(QDomDocument *) const;
137 bool fromXml(PsiCon *, PsiAccount *, const QDomElement *);
138
139 virtual int priority() const;
140
141 virtual PsiEvent *copy() const;
142
143private:
144 Jid v_from;
145 QString v_at;
146};
147
148// request pgp passphrase
149class PGPEvent : public PsiEvent
150{
151 Q_OBJECT
152public:
153 PGPEvent(PsiAccount *acc) : PsiEvent(acc) {}
154 PGPEvent(const PGPEvent &from)
155 : PsiEvent(from) {}
156 ~PGPEvent() {}
157 int type() const { return PGP; }
158 Jid from() const { return QString(); }
159 void setFrom(const Jid &) {}
160};
161
162// incoming file transfer
163class FileEvent : public PsiEvent
164{
165 Q_OBJECT
166public:
167 FileEvent(const Jid &j, FileTransfer *ft, PsiAccount *acc);
168 ~FileEvent();
169
170 int type() const { return File; }
171 Jid from() const;
172 void setFrom(const Jid &);
173 FileTransfer *takeFileTransfer();
174
175 virtual int priority() const;
176
177private:
178 Jid v_from;
179 QGuardedPtr<FileTransfer> ft;
180};
181
182// event queue
183class EventQueue : public QObject
184{
185 Q_OBJECT
186public:
187 EventQueue(PsiAccount *);
188 EventQueue(const EventQueue &);
189 ~EventQueue();
190
191 EventQueue &operator= (const EventQueue &);
192
193 int nextId() const;
194 int count() const;
195 int count(const Jid &, bool compareRes=true) const;
196 void enqueue(PsiEvent *);
197 void dequeue(PsiEvent *);
198 PsiEvent *dequeue(const Jid &, bool compareRes=true);
199 PsiEvent *peek(const Jid &, bool compareRes=true) const;
200 PsiEvent *dequeueNext();
201 PsiEvent *peekNext() const;
202 bool hasChats(const Jid &, bool compareRes=true) const;
203 PsiEvent *peekFirstChat(const Jid &, bool compareRes=true) const;
204 void extractChats(QPtrList<PsiEvent> *list, const Jid &, bool compareRes=true);
205 void printContent() const;
206 void clear();
207 void clear(const Jid &, bool compareRes=true);
208
209 QDomElement toXml(QDomDocument *) const; // these work with pointers, to save inclusion of qdom.h, which is pretty large
210 bool fromXml(const QDomElement *);
211
212 bool toFile(const QString &fname);
213 bool fromFile(const QString &fname);
214
215signals:
216 void handleEvent(PsiEvent *);
217 void queueChanged();
218
219private:
220 class Private;
221 Private *d;
222};
223
224
225
226#endif
Note: See TracBrowser for help on using the repository browser.