|
1 /* |
|
2 * Copyright (c) 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: VideoListDataModel class definition* |
|
15 */ |
|
16 |
|
17 #ifndef __VIDEOLISTDATAMODEL_H__ |
|
18 #define __VIDEOLISTDATAMODEL_H__ |
|
19 |
|
20 |
|
21 // INCLUDES |
|
22 #include <QObject> |
|
23 #include <qabstractitemmodel.h> |
|
24 #include <e32const.h> |
|
25 #include <mpxitemid.h> |
|
26 |
|
27 |
|
28 // FORWARD DECLARATIONS |
|
29 class VideoListDataModelPrivate; |
|
30 class VideoThumbnailData; |
|
31 class VideoCollectionClient; |
|
32 class VideoDeleteWorker; |
|
33 |
|
34 |
|
35 class VideoListDataModel : public QAbstractItemModel |
|
36 { |
|
37 /** |
|
38 * define to be able to use signals and slots |
|
39 */ |
|
40 Q_OBJECT |
|
41 |
|
42 /** |
|
43 * disable copy-constructor and assignment operator |
|
44 */ |
|
45 Q_DISABLE_COPY(VideoListDataModel) |
|
46 |
|
47 /** |
|
48 * private class declaration macro |
|
49 */ |
|
50 Q_DECLARE_PRIVATE_D( d_ptr, VideoListDataModel ) |
|
51 |
|
52 public: |
|
53 |
|
54 /** |
|
55 * Default constructor |
|
56 */ |
|
57 VideoListDataModel(QObject *parent = 0); |
|
58 |
|
59 /** |
|
60 * Destructor |
|
61 */ |
|
62 ~VideoListDataModel(); |
|
63 |
|
64 /** |
|
65 * Initializes model. Sets model cache proxy and cache's plugin to |
|
66 * to be this object. Creates videolist and puts it to observe |
|
67 * collection client. Calls connectSignals to connect signals into |
|
68 * appropriate slots |
|
69 * |
|
70 * |
|
71 * @return int: 0 if everything ok |
|
72 */ |
|
73 int initialize( ); |
|
74 |
|
75 /** |
|
76 * returns collectionclient object |
|
77 * |
|
78 * @return VideoCollectionClient* |
|
79 */ |
|
80 VideoCollectionClient* getCollectionClient(); |
|
81 |
|
82 /** |
|
83 * Method calls video list data to check if there are valid media object |
|
84 * at the given index. If there is, item id is returned. |
|
85 * |
|
86 * @param index index of the item to be opened |
|
87 * @return TMPXItemId item id or TMPXItemId::Invalid() if no valid item. |
|
88 */ |
|
89 const TMPXItemId& mediaIdAtIndex(const int &index) const; |
|
90 |
|
91 /** |
|
92 * returns model index of id provided |
|
93 * |
|
94 * @param id of the item |
|
95 * @return modelIndex |
|
96 */ |
|
97 QModelIndex indexOfId(const TMPXItemId &id); |
|
98 |
|
99 /** |
|
100 * Method calls video list data to check if there are valid media object |
|
101 * for the given media id. If there is, file path for is returned. |
|
102 * |
|
103 * @param mediaId id of the item to be opened |
|
104 * @return QString file path of the media at index, empty string if not valid item. |
|
105 */ |
|
106 QString mediaFilePathForId(const TMPXItemId &mediaId) const; |
|
107 |
|
108 /** |
|
109 * Called by the client when removal of videos are requested. |
|
110 * Sets video status to be removed to videolistdata and |
|
111 * eventually calls collection to handle the actual removing. |
|
112 * |
|
113 * @param indexlist list of indeces of items requested for deletion |
|
114 * |
|
115 * @return bool true if removal startup succeeds |
|
116 */ |
|
117 bool removeRows(const QModelIndexList &indexList); |
|
118 |
|
119 /** |
|
120 * Checks if the specified item belongs to currently open album. |
|
121 * |
|
122 * @param albumId, Album to be checked. If zero, using the currently open album. |
|
123 * @param itemId, Item to be checked. |
|
124 * @return true if item belongs to the album. |
|
125 */ |
|
126 bool belongsToAlbum(const TMPXItemId &itemId, TMPXItemId albumId = TMPXItemId::InvalidId()) const; |
|
127 |
|
128 /** |
|
129 * Set album in use. |
|
130 * |
|
131 * @param albumId, Album to set in use. |
|
132 * @return None. |
|
133 */ |
|
134 void setAlbumInUse(const TMPXItemId &albumId); |
|
135 |
|
136 /** |
|
137 * returns album id currently in use |
|
138 * |
|
139 * @return TMPXItemId |
|
140 */ |
|
141 const TMPXItemId& albumInUse() const; |
|
142 |
|
143 /** |
|
144 * removes provided items from provided album id and calls |
|
145 * collectionclient to update mds as well. |
|
146 * |
|
147 * @param albumId album from where to remove |
|
148 * @param items items to remove |
|
149 * |
|
150 * @return count of items removed or -1 if failed |
|
151 */ |
|
152 int removeItemsFromAlbum(const TMPXItemId &albumId, const QList<TMPXItemId> &items); |
|
153 |
|
154 public: // from QAbstractItemModel |
|
155 |
|
156 /** |
|
157 * Returns video item count to the proxy cache |
|
158 * |
|
159 * @param parent, parent's index, not used |
|
160 * |
|
161 * @return int count of items |
|
162 */ |
|
163 int rowCount(const QModelIndex &parent = QModelIndex()) const; |
|
164 |
|
165 /** |
|
166 * Returns video item data from index pointed by |
|
167 * given QModelIndex's row index: |
|
168 * - video name |
|
169 * - video detail row |
|
170 * - video thumbnail |
|
171 * |
|
172 * If fetch more is setted for given index tries to append |
|
173 * additional details into map as well. |
|
174 * |
|
175 * @param index, index of the item data is requested |
|
176 * |
|
177 * @return QMap<int, QVariant> item data |
|
178 */ |
|
179 QMap<int, QVariant> itemData(const QModelIndex &index) const; |
|
180 |
|
181 /** |
|
182 * data |
|
183 */ |
|
184 QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const; |
|
185 |
|
186 /** |
|
187 * columnCount |
|
188 */ |
|
189 int columnCount(const QModelIndex & parent = QModelIndex()) const; |
|
190 |
|
191 /** |
|
192 * index |
|
193 */ |
|
194 QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex()) const; |
|
195 |
|
196 /** |
|
197 * Parent |
|
198 */ |
|
199 QModelIndex parent(const QModelIndex & index) const; |
|
200 |
|
201 signals: |
|
202 |
|
203 /** |
|
204 * This signal is connected to video list's details ready |
|
205 * -signal indicating that video details data is fetched |
|
206 * and provides a QMap of the details'. |
|
207 */ |
|
208 void fullVideoDetailsReady(QVariant &); |
|
209 |
|
210 /** |
|
211 * This signal is connected to proxy models short details ready |
|
212 * -signal indicating that video details data fetching started ok |
|
213 * |
|
214 * @param id of the video item |
|
215 */ |
|
216 void shortDetailsReady(TMPXItemId id); |
|
217 |
|
218 /** |
|
219 * Signals that the model is ready, ie. loaded all data from |
|
220 * myvideocollection. |
|
221 */ |
|
222 void modelReady(); |
|
223 |
|
224 /** |
|
225 * Signals that all albums have been loaded from myvideoscollection. |
|
226 */ |
|
227 void albumListReady(); |
|
228 |
|
229 /** |
|
230 * Signal to be emitted when something has happened in the |
|
231 * model's data container |
|
232 */ |
|
233 void modelChanged(); |
|
234 |
|
235 /** |
|
236 * Signals that album content has been updated. |
|
237 */ |
|
238 void albumChanged(); |
|
239 |
|
240 private slots: |
|
241 |
|
242 /** |
|
243 * signaled by the deleteworker in case some delete startup fails |
|
244 * |
|
245 * @param ids list of ids whose deletion fails |
|
246 */ |
|
247 void deleteStartingFailsSlot(QList<TMPXItemId>& ids); |
|
248 |
|
249 private: |
|
250 |
|
251 /** |
|
252 * Method connects signals used for delete worker |
|
253 */ |
|
254 void connectSignals(); |
|
255 |
|
256 /** |
|
257 * method disconnects signals |
|
258 */ |
|
259 void disconnectSignals(); |
|
260 |
|
261 /** |
|
262 * Generates a detail row string for the video item |
|
263 * at the given index. |
|
264 * |
|
265 * In case item is not found in the provided index, empty |
|
266 * string is returned. |
|
267 * |
|
268 * @param index, index of the item data is requested |
|
269 * |
|
270 * @return QString detail string |
|
271 */ |
|
272 QString prepareDetailRow(int &index) const; |
|
273 |
|
274 /** |
|
275 * Formats a detail row string for the video item |
|
276 * at the given index. |
|
277 * |
|
278 * In case item is not found in the provided index, empty |
|
279 * string is returned. |
|
280 * |
|
281 * @param index, index of the item data is requested |
|
282 * @param duration, duration of the video |
|
283 * |
|
284 * @return QString detail string |
|
285 */ |
|
286 QString doDetailRow(int &index) const; |
|
287 |
|
288 /** |
|
289 * Generates a video count string for category or album at given index. |
|
290 * |
|
291 * In case item is not found in the provided index, empty |
|
292 * string is returned. |
|
293 * |
|
294 * @param index, index of the item data is requested |
|
295 * @param index, item id of the item data is requested |
|
296 * |
|
297 * @return QString video count string |
|
298 */ |
|
299 QString prepareVideoCountString(int &index) const; |
|
300 |
|
301 /** |
|
302 * Generates a video size string from video item at given index |
|
303 * |
|
304 * In case item is not found in the provided index, empty |
|
305 * string is returned. |
|
306 * |
|
307 * @param index, index of the item data is requested |
|
308 * |
|
309 * @return QString size string |
|
310 */ |
|
311 QString prepareSizeString(int &index) const; |
|
312 |
|
313 /** |
|
314 * Called when there are status changes in some async operation |
|
315 * |
|
316 * @param statusCode status of operation |
|
317 * @data data from operation |
|
318 */ |
|
319 void reportAsyncStatus(int statusCode, QVariant &additional); |
|
320 |
|
321 private: |
|
322 |
|
323 /** |
|
324 * Private implementation Contains the actual video data and |
|
325 * video array. Own. |
|
326 */ |
|
327 VideoListDataModelPrivate* const d_ptr; |
|
328 |
|
329 /** |
|
330 * Pointer to collection client. Used to send commands to collection. |
|
331 * Owned. |
|
332 */ |
|
333 VideoCollectionClient *mCollectionClient; |
|
334 |
|
335 /** |
|
336 * object for handling item deletion conveniently in small blocks. |
|
337 * Own |
|
338 */ |
|
339 VideoDeleteWorker *mDeleteWorker; |
|
340 |
|
341 /** |
|
342 * initialized flag |
|
343 */ |
|
344 bool mInitialized; |
|
345 |
|
346 }; |
|
347 #endif // __VIDEOLISTDATAMODEL_H__ |
|
348 |
|
349 // End of file |
|
350 |