~ubuntu-branches/ubuntu/dapper/psi/dapper

« back to all changes in this revision

Viewing changes to src/psievent.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2004-06-15 00:10:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040615001041-enywb6pcpe4sjsw6
Tags: 0.9.2-1
* New upstream release
* Set KDEDIR for ./configure so kde specific files get installed
* Don't install libpsiwidgets.so. It got installed in /usr/share
  where it doesn't belong. May be included (at a better location)
  later.

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
#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
 
 
32
namespace XMPP
 
33
{
 
34
        class FileTransfer;
 
35
};
 
36
 
 
37
using namespace XMPP;
 
38
 
 
39
class PsiCon;
 
40
class PsiAccount;
 
41
 
 
42
 
 
43
class PsiEvent : public QObject
 
44
{
 
45
        Q_OBJECT
 
46
public:
 
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 *, const QDomElement *);
 
77
 
 
78
        virtual int priority() const;
 
79
 
 
80
private:
 
81
        bool v_originLocal, v_late;
 
82
        QDateTime v_ts;
 
83
        Jid v_jid;
 
84
        PsiAccount *v_account;
 
85
};
 
86
 
 
87
// normal, chat, error, headline, etc
 
88
class MessageEvent : public PsiEvent
 
89
{
 
90
        Q_OBJECT
 
91
public:
 
92
        MessageEvent(PsiAccount *acc);
 
93
        MessageEvent(const MessageEvent &from);
 
94
        MessageEvent(const XMPP::Message &, PsiAccount *acc);
 
95
        ~MessageEvent();
 
96
 
 
97
        int type() const;
 
98
        Jid from() const;
 
99
        void setFrom(const Jid &j);
 
100
 
 
101
        bool sentToChatWindow() const;
 
102
        const XMPP::Message & message() const;
 
103
 
 
104
        void setSentToChatWindow(bool b);
 
105
        void setMessage(const XMPP::Message &m);
 
106
 
 
107
        QDomElement *toXml(QDomDocument *) const;
 
108
        bool fromXml(PsiCon *, const QDomElement *);
 
109
 
 
110
        virtual int priority() const;
 
111
 
 
112
private:
 
113
        XMPP::Message v_m;
 
114
        bool v_sentToChatWindow;
 
115
};
 
116
 
 
117
// subscribe, subscribed, unsubscribe, unsubscribed
 
118
class AuthEvent : public PsiEvent
 
119
{
 
120
        Q_OBJECT
 
121
public:
 
122
        AuthEvent(const Jid &j, const QString &authType, PsiAccount *acc);
 
123
        AuthEvent(const AuthEvent &from);
 
124
        ~AuthEvent();
 
125
 
 
126
        int type() const;
 
127
        Jid from() const;
 
128
        void setFrom(const Jid &j);
 
129
 
 
130
        QString authType() const;
 
131
 
 
132
        QDomElement *toXml(QDomDocument *) const;
 
133
        bool fromXml(PsiCon *, const QDomElement *);
 
134
 
 
135
        virtual int priority() const;
 
136
 
 
137
private:
 
138
        Jid v_from;
 
139
        QString v_at;
 
140
};
 
141
 
 
142
// request pgp passphrase
 
143
class PGPEvent : public PsiEvent
 
144
{
 
145
        Q_OBJECT
 
146
public:
 
147
        PGPEvent(PsiAccount *acc) : PsiEvent(acc) {}
 
148
        PGPEvent(const PGPEvent &from)
 
149
        : PsiEvent(from) {}
 
150
        ~PGPEvent() {}
 
151
        int type() const { return PGP; }
 
152
        Jid from() const { return QString(); }
 
153
        void setFrom(const Jid &) {}
 
154
};
 
155
 
 
156
// incoming file transfer
 
157
class FileEvent : public PsiEvent
 
158
{
 
159
        Q_OBJECT
 
160
public:
 
161
        FileEvent(const Jid &j, FileTransfer *ft, PsiAccount *acc);
 
162
        ~FileEvent();
 
163
 
 
164
        int type() const { return File; }
 
165
        Jid from() const;
 
166
        void setFrom(const Jid &);
 
167
        FileTransfer *takeFileTransfer();
 
168
 
 
169
        virtual int priority() const;
 
170
 
 
171
private:
 
172
        Jid v_from;
 
173
        QGuardedPtr<FileTransfer> ft;
 
174
};
 
175
 
 
176
// event queue
 
177
class EventQueue : public QObject
 
178
{
 
179
        Q_OBJECT
 
180
public:
 
181
        EventQueue(PsiCon *);
 
182
        EventQueue(const EventQueue &);
 
183
        ~EventQueue();
 
184
 
 
185
        EventQueue &operator= (const EventQueue &);
 
186
 
 
187
        int nextId() const;
 
188
        int count() const;
 
189
        int count(const Jid &, bool compareRes=true) const;
 
190
        void enqueue(PsiEvent *);
 
191
        void dequeue(PsiEvent *);
 
192
        PsiEvent *dequeue(const Jid &, bool compareRes=true);
 
193
        PsiEvent *peek(const Jid &, bool compareRes=true) const;
 
194
        PsiEvent *dequeueNext();
 
195
        PsiEvent *peekNext() const;
 
196
        bool hasChats(const Jid &, bool compareRes=true) const;
 
197
        PsiEvent *peekFirstChat(const Jid &, bool compareRes=true) const;
 
198
        void extractChats(QPtrList<PsiEvent> *list, const Jid &, bool compareRes=true);
 
199
        void printContent() const;
 
200
        void clear();
 
201
        void clear(const Jid &, bool compareRes=true);
 
202
 
 
203
        QDomElement *toXml(QDomDocument *) const; // these work with pointers, to save inclusion of qdom.h, which is pretty large
 
204
        bool fromXml(const QDomElement *);
 
205
 
 
206
        bool toFile(const QString &fname);
 
207
        bool fromFile(const QString &fname);
 
208
 
 
209
signals:
 
210
        void handleEvent(PsiEvent *);
 
211
        void queueChanged();
 
212
 
 
213
private:
 
214
        class Private;
 
215
        Private *d;
 
216
};
 
217
 
 
218
 
 
219
 
 
220
#endif