summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/groupwise/libgroupwise/client.h
blob: 542d32eb672fa3998f2e509c011c5d0de463ecc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/*
    Kopete Groupwise Protocol
    client.h - The main interface for the Groupwise protocol

    Copyright (c) 2004      SUSE Linux AG	 	 http://www.suse.com
    
    Based on Iris, Copyright (C) 2003  Justin Karneges

    Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
 
    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/

#ifndef LIBGW_CLIENT_H
#define LIBGW_CLIENT_H

#include <tqstring.h>

#include "gwclientstream.h"
#include "gwerror.h"
#include "rtf2html.h"
#include "transfer.h"

class ChatroomManager;
class PrivacyManager;
class RequestFactory;
class UserDetailsManager;
class Task;

using namespace GroupWise;

class Client : public TQObject
{
Q_OBJECT
  TQ_OBJECT

	public:
	
		/*************
		  EXTERNAL API 
		 *************/
		  
		Client( TQObject *parent = 0, uint protocolVersion = 2 );
		~Client();
		void setOSName( const TQString &name );
		void setClientName( const TQString &s );
		void setClientVersion( const TQString &s );
		void setUserDN( const TQString & userDN );
		/**
		 * Start a connection to the server using the supplied @ref ClientStream.
		 * This is only a transport layer connection.
		 * Needed for protocol action P1.
		 * @param s initialised client stream to use for the connection.
		 * @param server the server to connect to - but this is also set on the connector used to construct the clientstream??
		 * @param auth needed for jabber protocol layer only?
		 */
		void connectToServer( ClientStream *s, const NovellDN &server, bool auth=true );
		
		/**
		 * Login to the GroupWise server using the supplied credentials
		 * Protocol action P1, needed for all
		 * @param host - probably could obtain this back from the connector - used for outgoing tasks to determine destination
		 * @param user The user name to log in as.
fd		 * @param password 
		 */ 
		void start( const TQString &host, const uint port, const TQString &userId, const TQString &pass );
		
		/**
		 * Logout and disconnect
		 * Protocol action P4		void distribute(const TQDomElement &);

		 */
		void close();

		/**
		 * Accessors needed for login
		 */
		TQString host();
		int port();
		
		/** 
		 * Set the user's presence on the server
		 * Protocol action P2
		 * @param status status enum
		 * @param reason custom status name for away statuses
		 * @param autoReply auto reply message for use in this status
		 */
		void setStatus( GroupWise::Status status, const TQString & reason, const TQString & autoReply );

		/**
		 * Send a message 
		 * Protocol action P10
		 * @param message contains the text and the recipient.
		 */
		void sendMessage( const TQStringList & addresseeDNs, const OutgoingMessage & message );
		  
		/**
		 * Send a typing notification
		 * Protocol action P11
		 * @param conference The conference where the typing took place.
		 * @param typing True if the user is now typing, false otherwise.
		 */
		void sendTyping( const ConferenceGuid & conferenceGuid, bool typing );
		
		/** 
		 * Request details for one or more users, for example, if we receive a message from someone who isn't on our contact list
		 * @param userDNs A list of one or more user's DNs to fetch details for
		 */
		void requestDetails( const TQStringList & userDNs );
		 
		/**
		 * Request the status of a single user, for example, if they have messaged us and are not on our contact list
		 */
		void requestStatus( const TQString & userDN );
		
		/**
		 * Add a contact to the contact list
		 * Protocol action P12
		 */

		/**
		 * Remove a contact from the contact list
		 * Protocol action P13
		 */
		
		/**
		 * Instantiate a conference on the server
		 * Protocol action P5
		 */
		void createConference( const int clientId );
		/**
		 * Overloaded version of the above to create a conference with a supplied list of invitees
		 */
		void createConference( const int clientId, const TQStringList & participants );
		
		/**
		 * Join a conference, accepting an invitation 
		 * Protocol action P7
		 */
		void joinConference( const ConferenceGuid & guid );

		/**
		 * Reject a conference invitation
		 * Protocol action P8
		 */
		void rejectInvitation( const ConferenceGuid & guid );
		
		/**
		 * Leave a conference, notifying 
		 * Protocol action P6
		 */
		void leaveConference( const ConferenceGuid & guid ); 
		
		/**
		 * Send an invitation to join a conference
		 * Protocol action P9
		 */
		void sendInvitation( const ConferenceGuid & guid, const TQString & dn, const GroupWise::OutgoingMessage & message );
		/*************
		  INTERNAL (FOR USE BY TASKS) METHODS 
		 *************/
		/**
		 * Send an outgoing request to the server
		 */
		void send( Request *request );
		/**
		 * Print a debug statement
		 */
		void debug( const TQString &str );

		/**
		 * The protocol version of the Client
		 */
		uint protocolVersion() const;
		/**
		 * Generate a unique ID for Tasks.
		 */
		TQString genUniqueId();
		
		/**
		 * The current user's user ID
		 */
		TQString userId();
		
		/**
		 * The current user's DN
		 */
		TQString userDN();
		/**
		 * The current user's password
		 */
		TQString password();
		
		/**
		 * User agent details for this host
		 */
		TQString userAgent();
		
		/**
		 * Host's IP address
		 */
		TQCString ipAddress();

		/**
		 * Obtain the list of custom statuses stored on the server 
		 */
		TQValueList<GroupWise::CustomStatus> customStatuses();

		/**
		 * Get a reference to the RequestFactory for this Client. 
		 * Used by Tasks to generate Requests with an ascending sequence of transaction IDs 
		 * for this connection
		 */
		RequestFactory * requestFactory();

		/**
		 * Get a reference to the ChatroomManager for this Client.
		 * This is constructed the first time this function is called.  Used to manipulate chat rooms on the server.
		 */
		ChatroomManager * chatroomManager();

		/**
		 * Get a reference to the UserDetailsManager for this Client.
		 * Used to track known user details and issue new details requests
		 */
		UserDetailsManager * userDetailsManager();
		/**
		 * Get a reference to the PrivacyManager for this Client.
		 * Used to track and manipulate server side privacy settings
		 */
		PrivacyManager * privacyManager();
		/**
		 * Access the root Task for this client, so tasks may be added to it.
		 */
		Task* rootTask();

	signals:
		/** CONNECTION EVENTS */
		/**
		 * Notifies that the login process has succeeded.
		 */
		void loggedIn();
		void loginFailed();
		/**
		 * Notifies tasks and account so they can react properly
		 */
		void disconnected();
		/**
		 * We were disconnected because we connected elsewhere
		 */
		void connectedElsewhere();
		
		/** STATUS AND METADATA EVENTS */
		/**
		 * We've just got the user's own details from the server.
		 */
		void accountDetailsReceived( const GroupWise::ContactDetails & );
		/** 
		 * We've just found out about a folder from the server.
		 */
		void folderReceived( const FolderItem & );
		/** 
		 * We've just found out about a folder from the server.
		 */
		void contactReceived( const ContactItem & );
		/** 
		 * We've just received a contact's metadata from the server.
		 */
		void contactUserDetailsReceived( const GroupWise::ContactDetails & );
		/** 
		 * A remote contact changed status
		 */
		void statusReceived( const TQString & contactId, TQ_UINT16 status, const TQString & statusText );
		/** 
		 * Our status changed on the server
		 */
		void ourStatusChanged( GroupWise::Status status, const TQString & statusText, const TQString & autoReply );
		
		/** CONFERENCE (MANAGEMENT) EVENTS */
		/** 
		 * Notify that we've just received a message.  Sender may not be on our contact list
		 */
		void messageReceived( const ConferenceEvent & );
		/**
		 * Notify that we've received an auto reply.  This Event does not contain any rtf, unlike a normal message.
		 */
		void autoReplyReceived( const ConferenceEvent & );
		/** 
		 * A conference was successfully created on the server
		 */
		void conferenceCreated( const int clientId, const GroupWise::ConferenceGuid & guid );
		/**
		 * A third party was invited to join a chat.  They may not be on our contact list.
		 */
		void inviteNotifyReceived( const ConferenceEvent & );
		/**
		 * We were invited to join a chat.  The inviter may not be on our contact list
		 */
		void invitationReceived( const ConferenceEvent & );
		/**
		 * Someone joined a chat.  They may not be on our contact list if it is a group chat
		 * and they were invited to join the chat prior to our being invited to join and joining
		 */
		void conferenceJoinNotifyReceived( const ConferenceEvent & );
		/**
		 * Someone left a conference. This may close a conference, see @ref conferenceClosed.
		 */
		void conferenceLeft( const ConferenceEvent & );
		/**
		 * Someone declined an invitation to join a conference. This may close a conference, see @ref conferenceClosed.
		 */
		void invitationDeclined( const ConferenceEvent & );
		/**
		 * A conference was closed by the server. This occurs if we are the only participant and there
		 * are no outstanding invitations.
		 */
		void conferenceClosed( const ConferenceEvent & );
		/**
		 * We joined a conference.
		 */
		void conferenceJoined( const GroupWise::ConferenceGuid &, const TQStringList &, const TQStringList & );
		/**
		 * We received an "is typing" event in a conference
		 */
		void contactTyping( const ConferenceEvent & );
		/**
		 * We received an "is not typing event" in a conference
		 */
		void contactNotTyping( const ConferenceEvent & );
		/**
		 * An attempt to create a conference failed.
		 */
		void conferenceCreationFailed( const int clientId, const int error );
		/**
		 * We received a temporary contact related to a conference 
		 */
		void tempContactReceived( const GroupWise::ContactDetails & );
		/**
		 * We received a broadcast message
		 */
		void broadcastReceived( const ConferenceEvent & );
		/**
		 * We received a system broadcast
		 */
		void systemBroadcastReceived ( const ConferenceEvent & );
		/** CONTACT LIST MANAGEMENT EVENTS */
		/** TBD! */
        void messageSendingFailed();
	protected:
		/**
		 * Instantiate all the event handling tasks
		 */
		void initialiseEventTasks();
	protected slots:
		// INTERNAL, FOR USE BY TASKS' finished() SIGNALS //
		void lt_loginFinished();
		void sst_statusChanged();
		void cct_conferenceCreated();
		/**
		 * Transforms an RTF message into an HTML message and emits messageReceived()
		 */ 
		void ct_messageReceived( const ConferenceEvent & );
		void jct_joinConfCompleted();
		/**
		 * Receive a custom status during login and record it
		 */
		void lt_gotCustomStatus( const GroupWise::CustomStatus & );
		/**
		 * Notify us of the keepalive period contained in the login response
		 */
		void lt_gotKeepalivePeriod( int );

		/**
		 * Used by the client stream to notify errors to upper layers.
		 */
		void streamError( int error );
		
		/**
		 * The client stream has data ready to read.
		 */
		void streamReadyRead();
		
		/**
		 * sendout a 'ping' keepalive message so that the server does not disconnect us
		 */
		void sendKeepAlive();
        void smt_messageSent();
    
	private:
		void distribute( Transfer *transfer );
		class ClientPrivate;
		ClientPrivate* d;
};

#endif