2
meanwhilesession.h - interface to the 'C' meanwhile session
4
Copyright (c) 2005 by Jeremy Kerr <jk@ozlabs.org>
6
*************************************************************************
8
* This program is free software; you can redistribute it and/or modify *
9
* it under the terms of the GNU General Public License as published by *
10
* the Free Software Foundation; either version 2 of the License, or *
11
* (at your option) any later version. *
13
*************************************************************************
15
#ifndef MEANWHILESESSION_H
16
#define MEANWHILESESSION_H
18
#include "meanwhileaccount.h"
19
#include "meanwhilecontact.h"
21
#include <meanwhile/mw_session.h>
22
#include <meanwhile/mw_service.h>
23
#include <meanwhile/mw_srvc_aware.h>
24
#include <meanwhile/mw_srvc_im.h>
25
#include <meanwhile/mw_srvc_resolve.h>
27
#include <Q3ValueList>
31
struct MeanwhileClientID {
38
* A class to handle libmeanwhile session management.
40
class MeanwhileSession : public QObject
46
* Create a session. By default, the session is not connected - you will
47
* need to call login() to initiate the connection process.
48
* @param account The account that the connection is for
50
MeanwhileSession(MeanwhileAccount *account);
58
* Connect to the server. This will open a socket and start login. Note that
59
* the connection process is ascychronous - a loginDone() signal will be
60
* emitted when successfully logged in.
62
void connect(QString password);
65
* Disconnect from the server.
70
* Set our (the local contact's) online status. The internalStatus of the
71
* state argument will be used to define the state message we send - it
72
* should be one of the Status enum fields (and not Offline)
73
* @param state the new state of the local user
74
* @param msg a custom message to use, if required
76
void setStatus(Kopete::OnlineStatus status,
77
const Kopete::StatusMessage &msg = Kopete::StatusMessage());
80
* Add a single contact to be registered for status updates
81
* @param contact The contact to register
83
void addContact(const Kopete::Contact *contact);
86
* Add a list of contacts to be registered for status updates
87
* @param contact The list of contacts to register
89
void addContacts(const QHash<QString, Kopete::Contact *> &contacts);
92
* Send a message (with recipient specified).
93
* @param message The message to send
94
* @return non-zero if the message could be sent
96
int sendMessage(Kopete::Message &message);
99
* Send a typing notification to a contact
100
* @param contact The contact to notify
101
* @param isTyping If true, the typing notification is set
103
void sendTyping(MeanwhileContact *contact, bool isTyping);
106
* Determine if the session is connected to the server
107
* @return true if the session is connected
112
* Determine if the session is in the process of connecting to the server
113
* @return true if the session is connecting
118
* Returns an array of well-known meanwhile client IDs
120
static const struct MeanwhileClientID *getClientIDs();
123
* Get the default client ID parameters for kopete
125
static void getDefaultClientIDParams(int *clientID,
126
int *verMajor, int *verMinor);
130
* Emitted when the status of the connection changes
131
* @param status The new status of the session
133
void sessionStateChange(Kopete::OnlineStatus status);
136
* Emitted when a notification is received from the server, or other
137
* out-of-band data (eg, the password is incorrect).
138
* @param mesgString A description of the notification
140
void serverNotification(const QString &mesgString);
143
/** Main libmeanwhile session object */
144
struct mwSession *session;
146
/** Session handler */
147
struct mwSessionHandler sessionHandler;
150
struct mwServiceAware *awareService;
153
struct mwAwareHandler awareHandler;
155
/** Aware List Handler */
156
struct mwAwareListHandler awareListHandler;
158
/** The aware list */
159
struct mwAwareList *awareList;
162
struct mwServiceIm *imService;
165
struct mwImHandler imHandler;
167
/** Resolve service */
168
struct mwServiceResolve *resolveService;
170
/** Storage service, for contact list */
171
struct mwServiceStorage *storageService;
173
/** Last recorded meanwhile state */
174
enum mwSessionState state;
176
/** The kopete account that this library is for */
177
MeanwhileAccount *account;
179
/** socket to the server */
182
/* These structures are stored in the libmeanwhile 'ClientData' fields */
184
/** Stored in the mwConversation struct */
185
struct ConversationData {
186
MeanwhileContact *contact;
187
Kopete::ChatSession *chat;
188
Q3ValueList<Kopete::Message> *queue;
191
/** (To be) stored in the mwConference struct */
192
struct ConferenceData {
193
Kopete::ChatSession *chatsession;
197
* Initialise the conversation data struct for a conversation, and store it
198
* in the meanwhile conversation object
199
* @param conv the meanwhile conversation object
200
* @param contact the contact that the conversation is with
201
* @param createQueue whether a message queue is required for this
203
* @return The created conversation data struct
205
struct ConversationData *createConversationData(
206
struct mwConversation *conv, MeanwhileContact *contact,
207
bool createQueue = false);
210
* Get the contact for a conversation
211
* @param conv the meanwhile conversation
212
* @return the contact that this conversation is held with
214
MeanwhileContact *conversationContact(struct mwConversation *conv);
217
* Convert a libmeanwhile-type status into one of the MeanwhileProtocol
219
* @param mstatus The internal status to convert
220
* @return The Meanwhile status
222
Kopete::OnlineStatus convertStatus(int mstatus);
225
* Parse the nickname of a libmeanwhile contact. From what I've seen,
226
* usernames are in the format:
227
* <userid> - <name>/<domain>/<domain>
228
* @param name the extened username to parse
229
* @return just the name part of the username info
231
QString getNickName(QString name);
234
* Convenience method to call the above from a mwLoginInfo struct. All is
236
* @param logininfo the login info for a contact
237
* @return just the name part of the login info data
239
QString getNickName(struct mwLoginInfo *logininfo);
242
* Resolve a contact to find (and set) the display name. This requires the
243
* session to be connected to use the meanwhile resolve service.
244
* @param contact The contact to resolve
246
void resolveContactNickname(MeanwhileContact *contact);
249
void syncContactsToServer();
250
void syncContactsFromServer();
254
/** Notify the library that data is available on the socket */
255
void slotSocketDataAvailable();
258
* Notify the library that the socket is about to be closed
260
void slotSocketAboutToClose();
263
/* ugly callbacks for libmeanwhile interface. These declare a static method
264
* to proxy the callback from libmeanwhile to a call to the MeanwhileSession
267
#define declare_session_handler_type(type, func, args, ...) \
268
static type _handleSession ## func ( \
269
struct mwSession *mwsession, __VA_ARGS__) { \
270
MeanwhileSession *session = \
271
(MeanwhileSession *)mwSession_getClientData(mwsession); \
272
return session->handleSession ## func args; \
274
type handleSession ## func(__VA_ARGS__)
275
#define declare_session_handler(func, args, ...) \
276
static void _handleSession ## func ( \
277
struct mwSession *mwsession, ## __VA_ARGS__) { \
278
MeanwhileSession *session = \
279
(MeanwhileSession *)mwSession_getClientData(mwsession); \
280
session->handleSession ## func args; \
282
void handleSession ## func(__VA_ARGS__)
284
declare_session_handler_type(int, IOWrite, (buf, len),
285
const guchar *buf, gsize len);
286
declare_session_handler(IOClose,());
287
declare_session_handler(Clear,());
288
declare_session_handler(StateChange, (state, info),
289
enum mwSessionState state, gpointer info);
290
declare_session_handler(SetPrivacyInfo,());
291
declare_session_handler(SetUserStatus,());
292
declare_session_handler(Admin, (text), const char *text);
293
declare_session_handler(Announce, (from, may_reply, text),
294
struct mwLoginInfo *from, gboolean may_reply, const char *text);
296
#define declare_aware_handler(func, args, ...) \
297
static void _handleAware ## func ( \
298
struct mwServiceAware *srvc, ## __VA_ARGS__) { \
299
MeanwhileSession *session = (MeanwhileSession *) \
300
mwService_getClientData((struct mwService *)srvc); \
301
return session->handleAware ## func args; \
303
void handleAware ## func(__VA_ARGS__)
305
declare_aware_handler(Attrib, (attrib), struct mwAwareAttribute *attrib);
306
declare_aware_handler(Clear,());
308
#define declare_aware_list_handler(func, args, ...) \
309
static void _handleAwareList ## func ( \
310
struct mwAwareList *list, ## __VA_ARGS__){ \
311
MeanwhileSession *session = (MeanwhileSession *) \
312
mwAwareList_getClientData(list); \
313
return session->handleAwareList ## func args; \
315
void handleAwareList ## func(__VA_ARGS__)
317
declare_aware_list_handler(Aware, (snapshot),
318
struct mwAwareSnapshot *snapshot);
319
declare_aware_list_handler(Attrib, (id, attrib),
320
struct mwAwareIdBlock *id, struct mwAwareAttribute *attrib);
321
declare_aware_list_handler(Clear,());
323
#define declare_im_handler(func, args, ...) \
324
static void _handleIm ## func ( \
325
struct mwConversation *conv, ## __VA_ARGS__) { \
326
MeanwhileSession *session = (MeanwhileSession *) \
327
mwService_getClientData( \
328
(struct mwService *)mwConversation_getService(conv)); \
329
return session->handleIm ## func args; \
331
void handleIm ## func (struct mwConversation *conv, ## __VA_ARGS__)
333
declare_im_handler(ConvOpened, (conv));
334
declare_im_handler(ConvClosed, (conv, err), guint32 err);
335
declare_im_handler(ConvReceived, (conv, type, msg),
336
enum mwImSendType type, gconstpointer msg);
338
/* resolve service */
339
static void _handleResolveLookupResults(struct mwServiceResolve *srvc,
340
guint32 id, guint32 code, GList *results, gpointer data) {
341
MeanwhileSession *session = (MeanwhileSession *)
342
mwService_getClientData(MW_SERVICE(srvc));
343
session->handleResolveLookupResults(srvc, id, code, results, data);
345
void handleResolveLookupResults(struct mwServiceResolve *srvc, guint32 id,
346
guint32 code, GList *results, gpointer data);
348
/* storage service */
349
static void _handleStorageLoad(struct mwServiceStorage *srvc,
350
guint32 result, struct mwStorageUnit *item, gpointer data) {
351
MeanwhileSession *session = (MeanwhileSession *)
352
mwService_getClientData(MW_SERVICE(srvc));
353
session->handleStorageLoad(srvc, result, item, data);
355
void handleStorageLoad(struct mwServiceStorage *srvc,
356
guint32 result, struct mwStorageUnit *item, gpointer data);
358
void handleRedirect(const char *host);