summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/jabber/jabberbasecontact.h
blob: c3453344692fb8f9c66002370857614a5878564a (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
 /*
  * jabbercontact.h  -  Base class for the Kopete Jabber protocol contact
  *
  * Copyright (c) 2002-2004 by Till Gerken <till@tantalo.net>
  * Copyright (c) 2002 by Daniel Stone <dstone@kde.org>
  *
  * 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 JABBERBASECONTACT_H
#define JABBERBASECONTACT_H

#include "kopetecontact.h"
#include "xmpp.h"
#include "im.h"

class dlgJabberVCard;
class JabberProtocol;
class JabberAccount;
class JabberResource;
class JabberTransport;
namespace Kopete { class MetaContact; }
namespace XMPP { class VCard; }

class JabberBaseContact : public Kopete::Contact
{

Q_OBJECT
  TQ_OBJECT
friend class JabberAccount;	/* Friends can touch each other's private parts. */

public:

	/**
	 * @param legacyId is the contactId of the contact if != Jid
	 */
	JabberBaseContact (const XMPP::RosterItem &rosterItem,
					   Kopete::Account *account, Kopete::MetaContact * mc, 
					   const TQString &legacyId=TQString());

	/********************************************************************
	 *
	 * Kopete::Contact reimplementation start
	 *
	 ********************************************************************/

	/**
	 * Return the protocol instance associated with this contact
	 */
	JabberProtocol *protocol ();

	/**
	 * Return the account instance associated with this contact
	 */
	JabberAccount *account () const { return m_account; };
	
	/**
	 * return the transport if any, or null
	 */
	JabberTransport *transport();
			
	/**
	 * Return if the contact is reachable (this is true if the account
	 * is online)
	 */
	virtual bool isReachable ();

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

	/**
	 * Serialize contact
	 */
	virtual void serialize (TQMap < TQString, TQString > &serializedData, TQMap < TQString, TQString > &addressBookData);

	/**
	 * Update contact if a roster item has been
	 * received for it. (used during login)
	 */
	void updateContact ( const XMPP::RosterItem &item );

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

	/**
	 * Update the resource property of the
	 * contact, listing all available resources.
	 */
	void updateResourceList ();

	/**
	 * Return current full address.
	 * Uses bestResource() if no presubscribed
	 * address exists.
	 */
	TQString fullAddress ();

	/**
	 * Set the dontSync flag for this contact.
	 * If this flag is set, calls to @ref sync will
	 * be ignored. This is required if the contact
	 * has been moved between groups on the server
	 * after we logged in and we try to update our
	 * local contact list. Since libkopete can only
	 * handle one group update at a time, moving
	 * between groups requires to operations which
	 * each in turn would cause a call to sync(),
	 * overwriting the change that is being carried
	 * out. (besides causing unnecessary traffic)
	 * This is avoided by setting the dontSync flag
	 * while synchronizing the local copy.
	 */
	void setDontSync ( bool flag );

	/**
	 * Return the status of the dontSync flag.
	 * See @ref setDontSync for a full description.
	 */
	bool dontSync ();
	
	/**
	 * return the roster item of the contact.
	 * to get the jid, use  rosterItem().jid().full()  don't use contactId as it is not the same with transport
	 */
	XMPP::RosterItem rosterItem() const { return mRosterItem; }
	
	/**
	 * Reads a vCard object and updates the contact's
	 * properties accordingly.
	 */
	void setPropertiesFromVCard ( const XMPP::VCard &vCard );


public slots:

	/**
	 * Retrieve a vCard for the contact
	 */
	virtual void slotUserInfo ();
	
	
	/**
	 * Re-evaluate online status. Gets called
	 * whenever a resource is added, removed, or
	 * changed in the resource pool.
	 */
	void reevaluatetqStatus ();

protected:
	/**
	 * Construct best address out of
	 * eventually preselected resource
	 * (due to subscription) and best
	 * available resource.
	 */
	XMPP::Jid bestAddress ();

	/**
	 * This will simply cache all
	 * relevant data for this contact.
	 */
	XMPP::RosterItem mRosterItem;

private:
	bool mDontSync;
	JabberAccount *m_account;

};

#endif

// vim: set noet ts=4 sts=4 sw=4: