summaryrefslogtreecommitdiffstats
path: root/kopete/protocols/oscar/icq/icqpresence.h
blob: d7ef9ed23ccec050841d6370e39366ea8b370a1d (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
/*
    icqpresence.h  -  ICQ online status and presence management
    
    Copyright (c) 2004      by Richard Smith          <kde@metafoo.co.uk>
    Kopete    (c) 2002-2004 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 ICQCOMMON_H
#define ICQCOMMON_H

#include <kdebug.h>

namespace Kopete { class OnlineStatus; }

namespace ICQ
{

class Presence;

/**
 * @brief This namespace contains status flags used in OSCAR's on-the-wire format.
 * 
 * The IS_XXX values are bits representing actual status flags. However, the flags
 * are just that -- flags.  ICQ statuses are represented by a combination of these
 * flags rather than just one value.  This seems to be for backwards compatibility
 * reasons -- this way you can add a new status and existing clients should still
 * work correctly.
 * 
 * So, when changing status you need to specify not only what status it is, but
 * also all other status flags that are appropriate. The SET_XXX flags do just that;
 * SET_DND for instance sets the DND, Occupied and Away bits.
 */
namespace StatusCode
{
	enum
	{
		OFFLINE    = 0xFFFFFFFF,
		ONLINE     = 0x00000000,
		INVISIBLE  = 0x00000100,
		
		IS_DND     = 0x00000002, ///< Do Not Disturb
		IS_OCC     = 0x00000010, ///< Occupied
		IS_NA      = 0x00000004, ///< Not Available
		IS_AWAY    = 0x00000001, ///< Away
		IS_FFC     = 0x00000020, ///< Free For Chat
		
		SET_DND    = 0x00000013, //== DND + Occupied + Away
		SET_OCC    = 0x00000011, //== Occupied + Away
		SET_NA     = 0x00000005, //== NA + Away
		SET_AWAY   = 0x00000001,
		SET_FFC    = 0x00000020,
		
		WEBAWARE   = 0x00010000,
		SHOWIP     = 0x00020000
	};
} // end namespace StatusCode

/**
 * @brief A manager for ICQ's online statuses
 * 
 * Looks after ICQ's numerous online statuses, and maps between them and Presence objects.
 * A single instance of this class is held by the ICQProtocol object.
 */
class OnlineStatusManager
{
public:
	OnlineStatusManager();
	~OnlineStatusManager();
	ICQ::Presence presenceOf( uint internalStatus );
	Kopete::OnlineStatus onlineStatusOf( const ICQ::Presence &presence );
	Kopete::OnlineStatus connectingStatus();
	Kopete::OnlineStatus unknownStatus();
	Kopete::OnlineStatus waitingForAuth();
	
private:
	class Private;
	Private *d;
};

/**
 * @brief An ICQ online presence object
 */
class Presence
{
public:
	/**
	 * Friendly types this status can be
	 */
	enum Type { Offline, DoNotDisturb, Occupied, NotAvailable, Away, Online, FreeForChat };
	enum { TypeCount = FreeForChat + 1 };
	
	enum Visibility { Invisible, Visible };
	
	Presence( Type type, Visibility vis ) : _type(type), _visibility(vis) {}
	
	Type type() const { return _type; }
	Visibility visibility() const { return _visibility; }
	
	/**
	 * Generate a Presence object from an online status
	 */
	static Presence fromOnlineStatus( const Kopete::OnlineStatus &status );
	
	/**
	 * Convert this Presence object to an online status
	 */
	Kopete::OnlineStatus toOnlineStatus() const;
	
	/**
	 * Get the status code to pass to liboscar to set us to this Status.
	 * @note This is not the opposite of fromOnlineStatus(). The set and get codes don't match.
	 */
	unsigned long toOscarStatus() const;
	
	/**
	 * Get the status a contact is at based on liboscar's view of its status.
	 * @note This is not the opposite of toOnlineStatus().
	 */
	static Presence fromOscarStatus( unsigned long code );
	
	bool operator==( const Presence &other ) const { return other._type == _type && other._visibility == _visibility; }
	bool operator!=( const Presence &other ) const { return !(*this == other); }
	
private:
	unsigned long basicOscarStatus() const;
	static Type typeFromOscarStatus( unsigned long status );
private:
	Type _type;
	Visibility _visibility;
};

}

#if 0
const unsigned int ICQ_PORT  = 5190;


const unsigned short ICQ_SEARCHSTATE_OFFLINE   = 0;
const unsigned short ICQ_SEARCHSTATE_ONLINE    = 1;
const unsigned short ICQ_SEARCHSTATE_DISABLED  = 2;


// Taken from libicq, not sure if we ever support these requests
const unsigned char PHONEBOOK_SIGN[16] =
{
	0x90, 0x7C, 0x21, 0x2C, 0x91, 0x4D, 0xD3, 0x11,
	0xAD, 0xEB, 0x00, 0x04, 0xAC, 0x96, 0xAA, 0xB2
};

const unsigned char PLUGINS_SIGN[16] =
{
	0xF0, 0x02, 0xBF, 0x71, 0x43, 0x71, 0xD3, 0x11,
	0x8D, 0xD2, 0x00, 0x10, 0x4B, 0x06, 0x46, 0x2E
};

/*
const unsigned char SHARED_FILES_SIGN[16] =
{
	0xF0, 0x2D, 0x12, 0xD9, 0x30, 0x91, 0xD3, 0x11,
	0x8D, 0xD7, 0x00, 0x10, 0x4B, 0x06, 0x46, 0x2E
};
*/
#endif

#endif
// vim: set noet ts=4 sts=4 sw=4:
// kate: indent-mode: csands