summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jabbercontact.h
blob: 4dcb6f8b40e54e140f1d869dda06379d8d42d8c4 (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
 /*
  * jabbercontact.cpp  -  Regular Kopete Jabber protocol contact
  *
  * Copyright (c) 2002-2004 by Till Gerken <till@tantalo.net>
  *
  * Kopete    (c) by the Kopete developers  <kopete-devel@kde.org>
  *
  * *************************************************************************
  * *                                                                       *
  * * This program is free software; you can redistribute it and/or modify  *
  * * it under the terms of the GNU General Public License as published by  *
  * * the Free Software Foundation; either version 2 of the License, or     *
  * * (at your option) any later version.                                   *
  * *                                                                       *
  * *************************************************************************
  */

#ifndef JABBERCONTACT_H
#define JABBERCONTACT_H

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "jabberbasecontact.h"
#include "xmpp_vcard.h"

#include "kopetechatsession.h" // needed for silly Kopete::ContactPtrList

class JabberChatSession;
class TQTimer;

class JabberContact : public JabberBaseContact
{

Q_OBJECT
  

public:

	JabberContact (const XMPP::RosterItem &rosterItem,
				   Kopete::Account *account, Kopete::MetaContact * mc, const TQString &legacyId = TQString());
	
	~JabberContact();

	/**
	 * Create custom context menu items for the contact
	 * FIXME: implement manager version here?
	 */
	TQPtrList<KAction> *customContextMenuActions ();

	/**
	 * Start a rename request.
	 */
	void rename ( const TQString &newName );

	/**
	 * Deal with an incoming message for this contact.
	 */
	void handleIncomingMessage ( const XMPP::Message &message );

	/**
	 * Create a message manager for this contact.
	 * This variant is a pure single-contact version and
	 * not suitable for groupchat, as it only looks for
	 * managers with ourselves in the contact list.
	 */
	Kopete::ChatSession *manager ( Kopete::Contact::CanCreateFlags );
	

	bool isContactRequestingEvent( XMPP::MsgEvent event );

	TQString lastReceivedMessageId () const;

public slots:

	/**
	 * Remove this contact from the roster
	 */
	void deleteContact ();

	/**
	 * Sync Groups with server
	 * 
	 * operations are alctually performed in sloDelayedSync()
	 */
	void sync(unsigned int);

	/**
	 * This is the JabberContact level slot for sending files.
	 *
	 * @param sourceURL The actual KURL of the file you are sending
	 * @param fileName (Optional) An alternate name for the file - what the
	 *                 receiver will see
	 * @param fileSize (Optional) Size of the file being sent. Used when sending
	 *                 a nondeterminate file size (such as over a socket)
	 */
	virtual void sendFile( const KURL &sourceURL = KURL(),
		const TQString &fileName = TQString(), uint fileSize = 0L );

	/**
	 * Update the vCard on the server.
	 * @todo is that still used ?
	 */ 
	void slotSendVCard();

	/**
	 * Set contact photo.
	 * @param path Path to the photo.
	 */
	void setPhoto(const TQString &photoPath);
	
	/**
	 * this will start a voice call to the contact
	 */
	void voiceCall();

private slots:

	/**
	 * Send type="subscribed" to contact
	 */
	void slotSendAuth ();

	/**
	 * Send type="subscribe" to contact
	 */
	void slotRequestAuth ();

	/**
	 * Send type="unsubscribed" to contact
	 */
	void slotRemoveAuth ();

	/**
	 * Change this contact's status
	 */
	void slotStatusOnline ();
	void slotStatusChatty ();
	void slotStatusAway ();
	void slotStatusXA ();
	void slotStatusDND ();
	void slotStatusInvisible ();

	/**
	* Select a new resource for the contact
	*/
	void slotSelectResource ();

	void slotChatSessionDeleted ( TQObject *sender );
	
	/**
	 * Check if cached vCard is recent.
	 * Triggered as soon as Kopete changes its online state.
	 */
	void slotCheckVCard ();

	/**
	 * Triggered from a timer, requests the vCard.
	 * Timer is initiated by @ref slotCheckVCard.
	 */
	void slotGetTimedVCard ();
	
	/**
	 * Passes vCard on to parsing function.
	 */
	void slotGotVCard ();

	/**
	 * Get information about last activity of the contact.
	 * Triggered as soon as Kopete goes online or the contact goes offline.
	 */
	void slotCheckLastActivity ( Kopete::Contact *, const Kopete::OnlineStatus &, const Kopete::OnlineStatus & );

	/**
	 * Triggered from a timer, requests last activity information.
	 * Timer is initiated by @ref slotCheckLastActivity.
	 */
	void slotGetTimedLastActivity ();

	/**
	 * Updates activity information.
	 */
	void slotGotLastActivity ();

	/**
	 * Display a error message if the vCard sent was unsuccesful.
	 */
	void slotSentVCard();
	
	/**
	 * The service discovery on that contact is finished
	 */
	void slotDiscoFinished();
	
	/**
	 * actually perform operations of sync() with a delay.
	 * slot received by the syncTimer.
	 */
	void slotDelayedSync();
private:

	/**
	 * Create a message manager for this contact.
	 * This variant is a pure single-contact version and
	 * not suitable for groupchat, as it only looks for
	 * managers with ourselves in the contact list.
	 * Additionally to the version above, this one adds
	 * a resource constraint that has to be matched by
	 * the manager. If a new manager is created, the given
	 * resource is preselected.
	 */
	JabberChatSession *manager ( const TQString &resource, Kopete::Contact::CanCreateFlags );

	/**
	 * Create a message manager for this contact.
	 * This version is suitable for group chat as it
	 * looks for a message manager with a given
	 * list of contacts as members.
	 */
	JabberChatSession *manager ( Kopete::ContactPtrList chatMembers, Kopete::Contact::CanCreateFlags );

	/**
	 * Sends subscription messages.
	 */
	void sendSubscription (const TQString& subType);

	/**
	 * Sends a presence packet to this contact
	 */
	void sendPresence ( const XMPP::Status status );

	/**
	 * This variable keeps a list of message managers.
	 * It is required to locate message managers by
	 * resource name, if one account is interacting
	 * with several resources of the same contact
	 * at the same time. Note that this does *not*
	 * apply to group chats, so this variable
	 * only contains classes of type JabberChatSession.
	 * The casts in manager() and slotChatSessionDeleted()
	 * are thus legal.
	 */
	TQPtrList<JabberChatSession> mManagers;

	/**
	 * Indicates whether the vCard is currently
	 * being updated or not.
	 */
	bool mVCardUpdateInProgress :1;

	bool mRequestComposingEvent :1;
	bool mRequestOfflineEvent :1;
	bool mRequestDisplayedEvent :1;
	bool mRequestDeliveredEvent :1;
	bool mRequestGoneEvent :1;
	/**
	 * tell if the disco#info has been done for this contact.
	 */
	bool mDiscoDone :1;

	TQString mLastReceivedMessageId;
	TQTimer *m_syncTimer;

};

#endif