|
1 /* |
|
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: List of media items |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __C_GLXSTATICITEMLIST_H__ |
|
22 #define __C_GLXSTATICITEMLIST_H__ |
|
23 |
|
24 #include <e32base.h> |
|
25 |
|
26 #include "mglxitemlistobserver.h" |
|
27 #include "glxlistdefs.h" |
|
28 #include "glxmediaid.h" |
|
29 |
|
30 class CGlxItemList; |
|
31 class CGlxMedia; |
|
32 class CMPXCollectionPath; |
|
33 class MGlxMediaPool; |
|
34 class MGlxMediaUser; |
|
35 class TGlxMedia; |
|
36 |
|
37 /** |
|
38 * CGlxItemList |
|
39 * |
|
40 * List that has |
|
41 * - non-static items |
|
42 * - static items |
|
43 * |
|
44 * @author Aki Vanhatalo |
|
45 * |
|
46 * @internal reviewed 17/07/2007 by Kimmo Hoikka |
|
47 * |
|
48 * @ingroup mlm_media_list_manager_design |
|
49 */ |
|
50 NONSHARABLE_CLASS( CGlxStaticItemList ) : public CBase, public MGlxItemListObserver |
|
51 { |
|
52 public: // Interface for external use |
|
53 /** |
|
54 * Two-phase constructor |
|
55 * @param aIdSpaceId id of the "space" in which all item ids are unique |
|
56 * @param aObserver Observer to be notified |
|
57 * @param aMediaUser User of media objects - media objects that |
|
58 * this list links to will be linked to the user, so that |
|
59 * cache manager is able to quickly access the media lists |
|
60 * that use particular media objects |
|
61 */ |
|
62 static CGlxStaticItemList* NewL( const TGlxIdSpaceId& aIdSpaceId, |
|
63 MGlxItemListObserver& aObserver, MGlxMediaUser& aMediaUser ); |
|
64 |
|
65 /** |
|
66 * Destructor |
|
67 */ |
|
68 ~CGlxStaticItemList(); |
|
69 |
|
70 /** |
|
71 * @return id space id |
|
72 */ |
|
73 const TGlxIdSpaceId& IdSpaceId() const; |
|
74 |
|
75 /** |
|
76 * Synchronises the list with new path |
|
77 * Sends added/removed notifications as necessary |
|
78 * Note: Does not copy the selected items or focus |
|
79 * |
|
80 * @param aSource path with item ids |
|
81 * @param aMediaPool interface from which to ask for media items |
|
82 */ |
|
83 void SetContentsL( const CMPXCollectionPath& aSource, const MGlxMediaPool& aMediaPool ); |
|
84 |
|
85 /** |
|
86 * Remove an item form the list |
|
87 * Sends removed notification |
|
88 * |
|
89 * @param aIdSpaceId Id space of the item. Use KGlxStaticItemIdSpaceId |
|
90 * if you want to permanently remove a static item. |
|
91 * @param aItemId Id of item to remove |
|
92 */ |
|
93 void Remove( const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aItemId ); |
|
94 |
|
95 /** |
|
96 * Remove any pointers to the media object at the specified index |
|
97 * @param aIndex index of media object from which to remove a reference |
|
98 */ |
|
99 void RemoveReference( TInt aIndex ); |
|
100 |
|
101 /** |
|
102 * @param aType type of count (all, static items, etc) |
|
103 * Default value of "all" to make it easier ro create test template |
|
104 * @return count of items, as specified in aType |
|
105 */ |
|
106 TInt Count( NGlxListDefs::TCountType aType = NGlxListDefs::ECountAll ) const; |
|
107 |
|
108 /** |
|
109 * @return item at index |
|
110 */ |
|
111 TGlxMedia& Item( TInt aIndex ); |
|
112 |
|
113 /** |
|
114 * @param aId Id of item for which index is needed |
|
115 * @return item with id aId or KErrNotFound |
|
116 */ |
|
117 TInt Index(const TGlxIdSpaceId& aIdSpaceId, const TGlxMediaId& aId ) const; |
|
118 |
|
119 /** |
|
120 * Adds a static item and takes ownership |
|
121 * If an item with the same id already exists (in the same position), |
|
122 * deletes the old item. |
|
123 * Note: In case of a leave, aStaticItem may have been modified. |
|
124 * It is assumed that since ownership of the static item is passed, |
|
125 * the object is free to be modifies. |
|
126 * @param aStaticItem Static item to be added |
|
127 * @param aTargetPosition Whether to be added at beginning or end |
|
128 */ |
|
129 void AddStaticItemL( CGlxMedia* aStaticItem, |
|
130 NGlxListDefs::TInsertionPosition aTargetPosition ); |
|
131 |
|
132 /** |
|
133 * Enables or disables static items |
|
134 * @param aEnabled true if static items should be enabled |
|
135 * false if static items should be disabled |
|
136 */ |
|
137 void SetStaticItemsEnabled( TBool aEnabled ); |
|
138 |
|
139 /** |
|
140 * @return ETrue if static items are enabled |
|
141 */ |
|
142 TBool IsStaticItemsEnabled() const; |
|
143 |
|
144 public: // From MGlxItemListObserver |
|
145 void HandleItemsAdded( TInt aFirstInsertedIndex, TInt aCount ); |
|
146 void HandleItemsRemoved( TInt aRemovedFromIndex, TInt aCount ); |
|
147 |
|
148 private: |
|
149 /** Array that owns static media items */ |
|
150 class RStaticMediaArray : public RArray< TGlxMedia > |
|
151 { |
|
152 public: |
|
153 /** Destructor */ |
|
154 ~RStaticMediaArray(); |
|
155 /** |
|
156 * Deletes an item at aIndex |
|
157 * Does not remove the position in the array at index |
|
158 * @param aIndex index at which to delete the item |
|
159 */ |
|
160 void Delete( TInt aIndex ); |
|
161 }; |
|
162 |
|
163 private: |
|
164 /** |
|
165 * Constructor |
|
166 * @param aObserver Observer to be notified |
|
167 */ |
|
168 CGlxStaticItemList( MGlxItemListObserver& aObserver ); |
|
169 |
|
170 /** |
|
171 * Second-phase constructor |
|
172 * @param aMediaUser User of media objects |
|
173 * @param aIdSpaceId id of the "space" in which all item ids are unique |
|
174 */ |
|
175 void ConstructL( const TGlxIdSpaceId& aIdSpaceId, |
|
176 MGlxMediaUser& aMediaUser ); |
|
177 |
|
178 /** @return Number of items in list */ |
|
179 TInt CountAll() const; |
|
180 |
|
181 /** @return Number of static items in list */ |
|
182 TInt CountStatic() const; |
|
183 |
|
184 /** @return Number of non static items */ |
|
185 TInt CountNonStatic() const; |
|
186 |
|
187 /** @return Index of the first post static item */ |
|
188 TInt FirstPostStaticIndex() const; |
|
189 |
|
190 /** |
|
191 * Make static item ready to be added to the list |
|
192 * @param aStaticItem Static item to be modified |
|
193 */ |
|
194 void SetupStaticItemL( CGlxMedia& aStaticItem ); |
|
195 |
|
196 /** |
|
197 * Delete a static item |
|
198 * @param aId Id of the static item to be deleted |
|
199 */ |
|
200 void DeleteStaticItem( const TGlxMediaId& aId ); |
|
201 |
|
202 /** |
|
203 * Try to replace the static item. Replaces the static item |
|
204 * only if it is found on the same position as to which the |
|
205 * replacement is intended for |
|
206 * @param aStaticItem Static item to replace with |
|
207 * @param aTargetPosition Position into which to add the item |
|
208 * @return ETrue if item was replaced, EFalse if not |
|
209 */ |
|
210 TBool TryReplaceStaticItem( CGlxMedia& aStaticItem, |
|
211 NGlxListDefs::TInsertionPosition aTargetPosition ); |
|
212 |
|
213 /** |
|
214 * Try to find the static item in the provided array, and if found, replace |
|
215 * the item with the supplied one |
|
216 * @param aStaticItem Static item to replace with |
|
217 * @param aInArray Array in which to try to find the item |
|
218 * @return ETrue if item was replaced, EFalse if not |
|
219 */ |
|
220 TBool TryReplaceStaticItem( CGlxMedia& aStaticItem, |
|
221 RStaticMediaArray& aInArray ); |
|
222 |
|
223 /** |
|
224 * Deletes a static item and notifies observer |
|
225 * @param aId Id of the static item to delete |
|
226 * @param aFromArray Array from which to try to find the static item |
|
227 * @param aArrayOffset Index in the full list of the first |
|
228 * item in aFromArray |
|
229 * @param aCountCurrentStatic Reference to the member variable |
|
230 * that stores the current count of the |
|
231 * aFromArray |
|
232 */ |
|
233 void DeleteStaticItem( const TGlxMediaId& aId, |
|
234 RStaticMediaArray& aFromArray, TInt aArrayOffset, |
|
235 TInt& aCountCurrentStatic ); |
|
236 |
|
237 /** |
|
238 * Add a static item. Assumes reservation has been made on both front and |
|
239 * rear static item array, and hence will never leave |
|
240 * @param aStaticItem Static item to be added |
|
241 * @param aTargetPosition Whether to be added at beginning or end |
|
242 */ |
|
243 void AddStaticItem( CGlxMedia& aStaticItem, |
|
244 NGlxListDefs::TInsertionPosition aTargetPosition ); |
|
245 |
|
246 /** |
|
247 * Add static item to the beginning of the list. Assumes reservation has |
|
248 * been made on the front static item array, and hence will never leave |
|
249 * @param aStaticItem Static item to add. |
|
250 * Takes ownership |
|
251 */ |
|
252 void AddFrontStaticItem( CGlxMedia& aStaticItem ); |
|
253 |
|
254 /** |
|
255 * Add static item to the end of the list. Assumes reservation has been |
|
256 * made on the rear static item array, and hence will never leave. |
|
257 * @param aStaticItem Static item to add. |
|
258 * Takes ownership |
|
259 */ |
|
260 void AddRearStaticItem( CGlxMedia& aStaticItem ); |
|
261 |
|
262 /** Enable front static items and notify observer of additions */ |
|
263 void EnableFrontStaticItems(); |
|
264 /** Enable rear static items and notify observer of additions */ |
|
265 void EnableRearStaticItems(); |
|
266 |
|
267 /** Disable front static items and notify observer of removals */ |
|
268 void DisableFrontStaticItems(); |
|
269 /** Disable rear static items and notify observer of removals */ |
|
270 void DisableRearStaticItems(); |
|
271 |
|
272 /** |
|
273 * @param aId Id of an item to find |
|
274 * @param aInArray Array in which to find the item |
|
275 * @return index of item with aId in aInArray or KErrNotFound |
|
276 */ |
|
277 TInt Index( const TGlxMediaId& aId, |
|
278 const RStaticMediaArray& aInArray ) const; |
|
279 |
|
280 private: |
|
281 /// Data model is organised as follows |
|
282 /// (Static items are items that client, not server, supplied) |
|
283 /// |
|
284 /// Example: In a list of 2 front static items, 5 non-static items, 3 rear |
|
285 /// static items |
|
286 /// |
|
287 /// Legend: |
|
288 /// "S" static item |
|
289 /// "i" non-static item |
|
290 /// "|" Link (Pointer) |
|
291 /// "O" (Static) media object (CGlxMedia) |
|
292 /// "^" Position of index in relation to list |
|
293 /// |
|
294 /// Case: Static items enabled: # # |
|
295 /// iItems: id + pointer to media object # SSiiiiiSSS # |
|
296 /// # || ||| # (linked via pointer) |
|
297 /// iFrontStaticItems: static media objects # OO ||| # |
|
298 /// iRearStaticItems: static media objects # OOO # |
|
299 /// # # |
|
300 /// iFirstNonStaticIndex, static items enabled # ^ # (2) |
|
301 /// iFirstRearStaticIndex, static items enabled # ^ # (7) |
|
302 /// |
|
303 /// Case: Static items disabled: # # |
|
304 /// iItems: id + pointer to media object # iiiii # |
|
305 /// # # |
|
306 /// iFrontStaticItems: static media objects # OO # (not linked to iItems) |
|
307 /// iRearStaticItems: static media objects # OOO # (not linked to iItems) |
|
308 /// # # |
|
309 /// iFirstNonStaticIndex # ^ # (0) |
|
310 /// iFirstRearStaticIndex # ^ # (5) |
|
311 |
|
312 /// List of media items |
|
313 CGlxItemList* iItemList; // own |
|
314 |
|
315 /// Array of command items before the server-originated media items |
|
316 RStaticMediaArray iFrontStaticItems; // own |
|
317 |
|
318 /// Array of command items after the server-originated media items |
|
319 RStaticMediaArray iRearStaticItems; // own |
|
320 |
|
321 /// Current count of front static items. Zero if static items |
|
322 /// are disabled (or no front static items). |
|
323 TInt iCountCurrentFrontStatic; |
|
324 |
|
325 /// Current count of front static items. Zero if static items |
|
326 /// are disabled (or no front static items). |
|
327 TInt iCountCurrentRearStatic; |
|
328 |
|
329 /// Info of whether static items are visible or hidden (outside this object) |
|
330 TBool iStaticItemsEnabled; |
|
331 |
|
332 /// Observer for changes |
|
333 MGlxItemListObserver& iObserver; |
|
334 |
|
335 __DECLARE_TEST; |
|
336 }; |
|
337 |
|
338 #endif // __C_GLXSTATICITEMLIST_H__ |