Show invite menu in wlm chat window immediately
[kdenetwork.git] / kopete / libkopete / kopeteonlinestatus.h
blob4ede1c837cdd285110c761f325ac286dad6185b0
1 /*
2 kopeteonlinestatus.h - Kopete Online Status
4 Copyright (c) 2003 by Martijn Klingens <klingens@kde.org>
5 Copyright (c) 2003 by Duncan Mac-Vicar Prett <duncan@kde.org>
6 Copyright (c) 2003 by Will Stephenson <wstephenson@kde.org>
7 Copyright (c) 2004 by Olivier Goffart <ogoffart@kde.org>
9 Kopete (c) 2002-2004 by the Kopete developers <kopete-devel@kde.org>
11 *************************************************************************
12 * *
13 * This library is free software; you can redistribute it and/or *
14 * modify it under the terms of the GNU Lesser General Public *
15 * License as published by the Free Software Foundation; either *
16 * version 2 of the License, or (at your option) any later version. *
17 * *
18 *************************************************************************
21 #ifndef kopeteonlinestatus_h
22 #define kopeteonlinestatus_h
24 #include "kopete_export.h"
26 #include <kdemacros.h>
27 #include <ksharedptr.h>
29 #include <QtCore/QObject>
30 #include <QtCore/QFlags>
31 #include <QtGui/QIcon>
33 #include "kopeteonlinestatusmanager.h"
35 class QString;
36 class QPixmap;
37 class QColor;
39 namespace Kopete
41 class OnlineStatusManager;
43 class Identity;
44 class Protocol;
45 class Account;
46 class Contact;
48 /**
49 * @author Martijn Klingens <klingens@kde.org>
50 * @author Will Stephenson (icon generating code)
52 * OnlineStatus is a class that encapsulates all information about the
53 * various online states that a protocol can be in in a single class. The
54 * online status consists of both a 'global' status as it's known to libkopete
55 * and used for going online or away, which non-protocol plugins can use,
56 * and the 'private' status, which is simply an unsigned int and is only
57 * useful for the actual protocol plugin that uses the status.
59 * This class is passed around by value, but is refcounted to cut down on the
60 * amount of overhead. All in all it should be more than fast enough for
61 * general use.
63 * Note that ONLY the constructor can set the data, the object is considered
64 * to be const after creation as there really shouldn't be a need to change
65 * a status' characteristics during runtime!
67 class KOPETE_EXPORT OnlineStatus
69 public:
70 /**
71 * The available global states. It is possible that multiple internal
72 * states map to the same global states. For example ICQ's 'Do not disturb'
73 * is handled just like 'Away' by libkopete. Only ICQ itself makes (and
74 * should make) a distinction.
75 * The order is important and is used in the < or > operator
77 enum StatusType
79 /**
80 * Refers to protocols where state cannot be determined. This
81 * applies to SMS contacts (text messages via mobile phones),
82 * since there's no presence information over SMS, but also
83 * to e.g. MSN contacts that are not on your contact list,
84 * since MSN only allows a user to query online state for
85 * users that are formally on the contact list. Lastly, libkopete
86 * itself uses the Unknown state in @ref MetaContact for
87 * meta contacts that have no child contacts at all.
89 Unknown=0,
90 /**
91 * State where you really cannot be contacted. Although
92 * Kopete doesn't oppose any technical limitations it really
93 * doesn't make sense to have more than one status per protocol
94 * that maps to 'Offline', since you're supposed to be
95 * disconnected from the network in this state.
97 Offline=10,
98 /**
99 * State where the user is not available on the network yet
100 * but trying to get onto. Most useful to yourself contact, because
101 * this state means not visible but with network access
103 Connecting=20,
105 * State where you are online but none of your contacts can
106 * see that you're online. Useful for all the protocols that support
107 * being invisible.
109 Invisible=30,
111 * Refers to a state where you can be technically reached, but
112 * for one reason or another it is often not useful to do so.
113 * This can be because you really aren't behind the computer
114 * ('Away' or 'Idle') or because you have other things to do
115 * and don't want to get involved in messaging ('Busy' or 'Do
116 * not Disturb' for example).
118 Away=40,
120 * Refers to a true online state, i.e. you can be contacted by
121 * others both technically and practically. This also applies
122 * to e.g. ICQ's 'Free for Chat' status.
124 Online=50
126 // note than Unknown is first, because the metacontact algorithm to detect
127 // the metacontact status from the contact status starts from Unknown, and
128 // takes a contact only if its status is greater
131 * Reserved internal status values
133 * Any internal status value > 0x80000000 is reserved for internal
134 * libkopete use. This enumeration lists the currently known values.
136 enum ReservedInternalStatus
139 * The account this contact belongs to is offline. Used with
140 * the Unknown StatusType.
142 AccountOffline = 0x80000001
147 * Constructor.
149 * Creates an empty OnlineStatus object. Since you cannot change
150 * OnlineStatus objects that are already created other than by their
151 * assignment operator, this constructor is only a convenience method
152 * for use in e.g. class members and local variables.
154 OnlineStatus();
158 * Constructor.
160 * Creates a new OnlineStatus object. All fields are mandatory; there
161 * are no default values. Also, you cannot change the object after creation.
163 * @param status is the global online status as used by libkopete
164 * @param weight is the 'weight' of this status. The contact list is
165 * sorted by status, and by weight within a status. It's not possible to
166 * 'promote' an Away item to a level above Online, since the status field
167 * always takes precedence. Weight is used when the same status is used
168 * more than once. Weight is also used for picking the most important
169 * 'Away' status for a protocol when going Away.
170 * @param protocol is a pointer to the protocol used. This is used when
171 * comparing two online status objects.
172 * @param internalStatus is the status as used internally by the protocol.
173 * This status is usually a lot more fine-grained than the status as used
174 * by libkopete and should be unique per protocol.
175 * @param overlayIcons is a list of QStrings which are the name of status
176 * icons to be used by the KDE icon loader. (Statuses which don't have icons
177 * to overlay like Online and Offline should use QString() as icon
178 * name ). NOTE if the string is a movie ( *.mng ) it must be the first string in the list.
179 * TODO: KDE4 sort out movies and overlay icons.
180 * @param description is a description in e.g. tooltips.
182 OnlineStatus( StatusType status, unsigned weight, Protocol *protocol,
183 unsigned internalStatus, const QStringList &overlayIcons, const QString &description );
186 * Constructor.
188 * @p Creates a new OnlineStatus object and registers it with the @ref Kopete::OnlineStatusManager.
189 * Registration allows you to generate a KActionMenu filled with KActions for changing to this OnlineStatus,
190 * using Kopete::Account::accountMenu().
192 * @p Note that weight has an additional significance for registered protocols when used for menu generation.
194 * All fields are mandatory; there
195 * are no default values. Also, you cannot change the object after creation.
197 * @param status is the global online status as used by libkopete
198 * @param weight is the 'weight' of this status. The contact list is
199 * sorted by status, and by weight within a status. It's not possible to
200 * 'promote' an Away item to a level above Online, since the status field
201 * always takes precedence. Weight is used when the same status is used
202 * more than once. Weight is also used for picking the most important
203 * 'Away' status for a protocol when going Away. Additionally, Weight determinesis also
204 * @param protocol is a pointer to the protocol used. This is used when
205 * comparing two online status objects.
206 * @param internalStatus is the status as used internally by the protocol.
207 * This status is usually a lot more fine-grained than the status as used
208 * by libkopete and should be unique per protocol.
209 * @param overlayIcon is a string returning the name of the status icon to be
210 * used by the KDE icon loader. (Status whiwh doesn't have icon to overlay like
211 * Online and Offline should use QString() as icon string)
212 * @param description is a description in e.g. tooltips.
213 * @param caption is the text of the action in the menu
214 * @param categories the categories this online status is in
215 * @param options the options of this online status
216 * @see Kopete::OnlineStatusManager for more info about the categories and options parameters
218 * You can set the status to be in the predefined categories.
219 * Ideally, each category should own one status.
220 * A status may be in several categories, or in none.
221 * There shouldn't be more than one status per protocol per categories.
223 OnlineStatus( StatusType status, unsigned weight, Protocol *protocol, unsigned internalStatus, const QStringList &overlayIcon,
224 const QString &description, const QString& caption, OnlineStatusManager::Categories categories = 0x0 , OnlineStatusManager::Options options = 0x0 );
228 * Constructor.
230 * Creates a libkopete builtin status object. Weight, protocol and internal
231 * status are set to zero, the strings and icons are set to the meta contact
232 * strings.
234 OnlineStatus( StatusType status ); /* implicit */
237 * Copy constructor.
239 * Just adds a reference to the refcount. Used to copy around the status
240 * objects with very little overhead.
242 OnlineStatus( const OnlineStatus &other );
245 * Destructor.
247 ~OnlineStatus();
250 * \brief Return the status
252 StatusType status() const;
255 * \brief Return the internal status
257 unsigned internalStatus() const;
260 * \brief Return the weight
262 unsigned weight() const;
265 * \brief Return the list of overlay icons
267 QStringList overlayIcons() const;
270 * \brief Return the description
272 QString description() const;
275 * \brief Return the protocol this applies to
277 Protocol* protocol() const;
280 * \brief Return the text for the action in the menu
282 QString caption() const;
285 * \brief Return the categories this online status is in
287 * @see Kopete::OnlineStatusManager for more info about the categories
289 OnlineStatusManager::Categories categories() const;
292 * \brief Return the options of this online status
294 * @see Kopete::OnlineStatusManager for more info about the options parameters
296 OnlineStatusManager::Options options() const;
299 * @return @c true if this a contact with this status is definitely online,
300 * @c false if the contact is Offline, Connecting or Unknown.
302 bool isDefinitelyOnline() const;
308 * \brief Return a status icon generated for the given Contact
310 * This will draw an overlay representing the online status
311 * of the contact the OnlineStatus applies to
312 * over the base icon.
313 * A cache is employed to reduce CPU and memory usage.
314 * @param contact is the contact the icon should apply to.
316 QIcon iconFor( const Contact *contact ) const;
319 * \brief Return a status icon generated for the given Contact
320 * \overload
321 * \deprecated Use the one that return a QIcon
322 * @param contact is the contact the icon should apply to.
323 * @param size is the size we the icon should be scaled to
325 KDE_DEPRECATED QPixmap iconFor( const Contact *contact, int size ) const
326 { return iconFor(contact).pixmap(size); }
329 * \brief Return the mime source for a status icon generated for the given Contact
331 * This behaves essentially like the method above, except for that
332 * it returns a mime source string that can be used to render the
333 * image in richtext components and the like. The returned key
334 * is only valid until the cache is cleared for the next time,
335 * so no assumptions should be made about long-time availability
336 * of the referenced data.
337 * @param contact is the contact the icon should apply to.
338 * @param size is the size we the icon should be scaled to - 16 is default and so costs nothing
340 QString mimeSourceFor( const Contact *contact, int size = 16 ) const;
343 * \brief Return a status icon generated for the given Account
345 * This will draw an overlay representing the online status
346 * of the account the OnlineStatus applies to
347 * over the base icon.
348 * A cache is employed to reduce CPU and memory usage.
349 * @param account is the account the icon should apply to.
350 * The account's color causes tinting, if it's plain QColor(), no tinting takes place.
351 * @param size is the size we the icon should be scaled to - 16 is default and so costs nothing
353 QIcon iconFor( const Account *account ) const;
356 * \brief Return a status icon generated for the given Account
357 * \overload
358 * \deprecated Use the varient which return a QIcon
360 * @param account is the account the icon should apply to.
361 * The account's color causes tinting, if it's plain QColor(), no tinting takes place.
362 * @param size is the size we the icon should be scaled to - 16 is default and so costs nothing
364 KDE_DEPRECATED QPixmap iconFor( const Account *account, int size ) const
365 { return iconFor(account).pixmap(size); }
368 * \brief Return the mime source for a status icon generated for the given Account
370 * This behaves essentially like the method above, except for that
371 * it returns a mime source string that can be used to render the
372 * image in richtext components and the like. The returned key
373 * is only valid until the cache is cleared for the next time,
374 * so no assumptions should be made about long-time availability
375 * of the referenced data.
376 * @param account is the account the icon should apply to.
377 * The account's color causes tinting, if it's plain QColor(), no tinting takes place.
378 * @param size is the size we the icon should be scaled to - 16 is default and so costs nothing
380 QString mimeSourceFor( const Account *account, int size = 16 ) const;
383 * \brief Return a previously rendered status icon for a mime source key
385 * You can access icons with this method that have previously been rendered
386 * using mimeSourceFor(). Note that only a cache lookup will be done, so
387 * if the cache has been invalidated due to a change of icon sets between
388 * requesting the key (thus rendering the icon) and trying to access the
389 * icon by key, an invalid pixmap will be returned.
391 QPixmap iconFor( const QString &mimeSource ) const;
394 * \brief Returns the status icon for the protocol.
396 * A cache is employed to reduce CPU and memory usage.
398 QPixmap protocolIcon() const;
401 * Assignment operator
403 OnlineStatus & operator=( const OnlineStatus &other );
406 * Comparison operator
408 * Returns true if both the protocol and the internal status are
409 * identical.
411 bool operator==( const OnlineStatus &other ) const;
414 * Comparison operator
416 * This operator works exactly opposite of @ref operator==()
418 bool operator!=( const OnlineStatus &other ) const;
421 * Comparison operator
423 * Returns true if the status() of this contact is of higher value than the other
424 * contact or if both statuses are equal and weight() is higher for this contact.
426 bool operator>( const OnlineStatus &other ) const;
429 * Comparison operator
431 * This operator works exactly opposite of @ref operator>()
433 bool operator<( const OnlineStatus &other ) const;
436 * \brief returns a QString from a StatusType
438 * Static method to convert a Kopete::OnlineStatus::StatusType to a string to avoid
439 * many issues when saving StatusType to disk
441 static QString statusTypeToString(OnlineStatus::StatusType status);
444 * \brief returns a StatusType from a QString
446 * Static method to convert a QString representing a StatusType to a StatusType to avoid
447 * many issues when saving StatusType to disk
449 static OnlineStatus::StatusType statusStringToType(const QString& string);
453 private:
455 class Private;
456 KSharedPtr<Private> d;
458 QString mimeSource( const QString& icon, int size, QColor color, bool idle) const;
463 } //END namespace Kopete
465 #endif