~ubuntu-branches/ubuntu/saucy/kopete/saucy-proposed

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
/*
    kopetestatusitems.h - Kopete Status Items

    Copyright (c) 2008      by Roman Jarosz          <kedgedev@centrum.cz>
    Kopete    (c) 2008      by the Kopete developers <kopete-devel@kde.org>

    *************************************************************************
    *                                                                       *
    * This library is free software; you can redistribute it and/or         *
    * modify it under the terms of the GNU Lesser General Public            *
    * License as published by the Free Software Foundation; either          *
    * version 2 of the License, or (at your option) any later version.      *
    *                                                                       *
    *************************************************************************
*/
#ifndef KOPETESTATUSITEMS_H
#define KOPETESTATUSITEMS_H

#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtCore/QString>

#include "kopete_export.h"
#include "kopeteonlinestatusmanager.h"

namespace Kopete {

namespace Status {

class StatusGroup;

/**
 * StatusItem is a base class for all status items. The items store
 * values that are needed to build status menu.
 *
 * The items are stored in StatusManager.
 *
 * IdentityManager is a singleton, you may uses it with @ref IdentityManager::self()
 *
 *@author Roman Jarosz <kedgedev@centrum.cz>
 */
class KOPETE_EXPORT StatusItem : public QObject
{
	Q_OBJECT
public:
	/**
	 * StatusItem constructor
	 **/
	StatusItem();
	StatusItem( const QString& uid );

	/**
	 * Sets category
	 **/
	void setCategory( OnlineStatusManager::Categories category );

	/**
	 * Returns category
	 **/
	OnlineStatusManager::Categories category() const { return mCategory; }

	/**
	 * Sets title
	 **/
	void setTitle( const QString& title );

	/**
	 * Returns title
	 **/
	QString title() const { return mTitle; }

	/**
	 * Returns unique identifier
	 **/
	QString uid() const { return mUid; }

	/**
	 * Returns true if StatusItem is group
	 **/
	virtual bool isGroup() const = 0;
	
	/**
	 * Returns number of childes
	 **/
	virtual int childCount() const = 0;

	/**
	 * Returns a StatusItem at given @p index or 0 if there is no item at given @p index
	 **/
	virtual StatusItem *child( int /*index*/ ) const = 0;

	/**
	 * Returns index of this Item in parent group
	 **/
	int index() const;

	/**
	 * Returns StatusGroup this Item belongs to
	 **/
	StatusGroup *parentGroup() const;

	/**
	 * Creates a copy of StatusItem
	 *
	 * @note this copies also uid so it should only be used when we know
	 * that the original or copy object will be destroyed
	 **/
	virtual StatusItem* copy() const = 0;

Q_SIGNALS:
	/**
	 * This signal is emitted whenever the item's content changes
	 **/
	void changed();

private:
	OnlineStatusManager::Categories mCategory;
	QString mTitle;
	QString mUid;

	StatusGroup *mParentItem;
	Q_DISABLE_COPY(StatusItem)
};

/**
 * StatusGroup represents a group that can contain other StatusItems
 *
 *@author Roman Jarosz <kedgedev@centrum.cz>
 */
class KOPETE_EXPORT StatusGroup : public StatusItem
{
	Q_OBJECT
public:
	/**
	 * StatusGroup constructor
	 **/
	StatusGroup();
	StatusGroup( const QString& uid );

	/**
	 * Returns true if StatusItem is group
	 * @note for StatusGroup it always returns true;
	 **/
	virtual bool isGroup() const { return true; }
	
	/**
	 * Returns number of childes
	 **/
	virtual int childCount() const { return mChildItems.count(); }

	/**
	 * Returns a StatusItem at given @p index or 0 if there is no item at given @p index
	 **/
	virtual StatusItem *child( int index ) const { return mChildItems.value( index, 0 ); }

	/**
	 * Returns list of all childes
	 **/
	QList<StatusItem*> childList() const { return mChildItems; }

	/**
	 * Returns index for given StatusItem
	 **/
	int indexOf( StatusItem *child ) const { return mChildItems.indexOf( child ); }

	/**
	 * Inserts @p child at given @p index
	 **/
	void insertChild( int index, StatusItem *child );

	/**
	 * Inserts @p child at the end
	 **/
	void appendChild( Kopete::Status::StatusItem *child );

	/**
	 * Removes @p child
	 **/
	void removeChild( Kopete::Status::StatusItem *child );

	/**
	 * Creates a copy of this object
	 *
	 * @note this copies also uid so it should only be used when we know
	 * that the original or copy object will be destroyed
	 **/
	virtual StatusItem* copy() const;
Q_SIGNALS:
	/**
	 * This signal is emitted after new child was inserted is inserted at position @p index
	 **/
	void childInserted( int index, Kopete::Status::StatusItem *child );

	/**
	 * This signal is emitted after child was removed
	 **/
	void childRemoved( Kopete::Status::StatusItem *child );

private Q_SLOTS:
	void childDestroyed( QObject *object );
	
private:
	QList<StatusItem*> mChildItems;
};

/**
 * Status represents a status which has title, message and category.
 * Values from this class are used to create status action with which user can change status.
 *
 *@author Roman Jarosz <kedgedev@centrum.cz>
 */
class KOPETE_EXPORT Status : public StatusItem
{
	Q_OBJECT
public:
	/**
	 * Status constructor
	 **/
	Status();
	Status( const QString& uid );

	/**
	 * Returns true if the item is group
	 * @note for Status it always returns false;
	 **/
	virtual bool isGroup() const { return false; }

	/**
	 * Returns number of childes
	 * @note for Status it always returns 0;
	 **/
	virtual int childCount() const { return 0; }

	/**
	 * Returns the item at given @p index or 0 if there is no item at given @p index
	 * @note for Status it always returns 0;
	 **/
	virtual StatusItem *child( int ) const { return 0; }

	/**
	 * Set message
	 **/
	void setMessage( const QString& message );

	/**
	 * Returns message
	 **/
	QString message() const { return mMessage; }

	/**
	 * Creates a copy of this object
	 *
	 * @note this copies also uid so it should only be used when we know
	 * that the original or copy object will be destroyed
	 **/
	virtual StatusItem* copy() const;

private:
	QString mMessage;
};

}

}

#endif