1 /*
2     oscarpresence.h  -  Oscar presence class
3 
4     Copyright (c) 2004      by Richard Smith          <kde@metafoo.co.uk>
5     Copyright (c) 2006,2007 by Roman Jarosz           <kedgedev@centrum.cz>
6     Kopete    (c) 2002-2007 by the Kopete developers  <kopete-devel@kde.org>
7 
8     *************************************************************************
9     *                                                                       *
10     * This program is free software; you can redistribute it and/or modify  *
11     * it under the terms of the GNU General Public License as published by  *
12     * the Free Software Foundation; either version 2 of the License, or     *
13     * (at your option) any later version.                                   *
14     *                                                                       *
15     *************************************************************************
16 */
17 
18 #ifndef OSCARPRESENCE_H
19 #define OSCARPRESENCE_H
20 
21 #include <QFlags>
22 #include <QString>
23 
24 #include "oscar_export.h"
25 
26 class OscarStatusManager;
27 
28 namespace Oscar
29 {
30 
31 /**
32  * @brief An Oscar presence object
33  */
34 class OSCAR_EXPORT Presence
35 {
36 public:
37 	/**
38 	 * Friendly types this status can be
39 	 */
40 	enum Type {
41 		Offline       = 0x00000000,
42 		DoNotDisturb  = 0x00000001,
43 		Occupied      = 0x00000002,
44 		NotAvailable  = 0x00000003,
45 		Away          = 0x00000004,
46 		FreeForChat   = 0x00000005,
47 		Online        = 0x00000006,
48 
49 		TypeMask      = 0x0000000F
50 	};
51 	enum { TypeCount = Online + 1 };
52 
53 	enum Flag {
54 		None          = 0x00000000,
55 		AIM           = 0x00000010,
56 		ICQ           = 0x00000020,
57 		Wireless      = 0x00000100,
58 		Invisible     = 0x00000200,
59 		XStatus       = 0x00001000,
60 		ExtStatus     = 0x00002000,
61 		ExtStatus2    = 0x00004000,
62 
63 		FlagsMask     = 0x0000FFF0,
64 		StatusTypeMask= 0x0000F000
65 	};
66 	Q_DECLARE_FLAGS(Flags, Flag)
67 
68 	enum {
69 		XtrazMask     = 0xFF000000
70 	};
71 
72 	explicit Presence( Type type, Flags flags = None );
73 
74 	void setType( Type type );
type()75 	Type type() const { return (Type)(mInternalStatus & TypeMask); }
76 
77 	void setFlags( Flags flags );
flags()78 	Flags flags() const { return (Flags)(mInternalStatus & FlagsMask); }
79 
80 	/**
81 	 * Returns internal status
82 	 * @note Internal status is 32-bit int with a following structure XX00FFFT where
83 	 * T is status type, FFF are Presence::Flags, XX is Xtraz status,
84 	 * 0 are always null
85 	 */
internalStatus()86 	uint internalStatus() const { return mInternalStatus; }
87 
88 	bool operator==( const Presence &other ) const { return other.mInternalStatus == mInternalStatus; }
89 	bool operator!=( const Presence &other ) const { return !(*this == other); }
90 
91 	/**
92 	 * Sets Xtraz status
93 	 */
94 	void setXtrazStatus( int xtraz );
95 
96 	/**
97 	 * Returns Xtraz status
98 	 * @note If Presence::XStatus or Presence::ExtStatus2 flags are not set function returns -1.
99 	 */
100 	int xtrazStatus() const;
101 
102 	/**
103 	 * Sets mood (ExtStatus2 status icon)
104 	 */
105 	void setMood( int mood );
106 
107 	/**
108 	 * Returns mood
109 	 * @note If Presence::XStatus or Presence::ExtStatus2 flags are not set function returns -1.
110 	 */
111 	int mood() const;
112 
113 private:
114 	friend class ::OscarStatusManager;
115 	Presence( uint internalStatus );
116 
117 	uint mInternalStatus;
118 	static const int moodToXtraz[];
119 };
120 Q_DECLARE_OPERATORS_FOR_FLAGS(Presence::Flags)
121 
122 }
123 
124 #endif
125