|
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: VideoThumbnailDataPrivate class definition |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifndef __VIDEOTHUMBNAILDATAPRIVATE_H__ |
|
19 #define __VIDEOTHUMBNAILDATAPRIVATE_H__ |
|
20 |
|
21 // INCLUDES |
|
22 #include <QObject> |
|
23 #include <QPointer> |
|
24 #include <QCache> |
|
25 #include <QIcon> |
|
26 #include <QSet> |
|
27 #include <QList> |
|
28 #include <e32const.h> |
|
29 #include <mpxitemid.h> |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class VideoCollectionWrapper; |
|
33 class VideoSortFilterProxyModel; |
|
34 class QModelIndex; |
|
35 class QTimer; |
|
36 class VideoThumbnailFetcher; |
|
37 class HbIcon; |
|
38 |
|
39 class VideoThumbnailDataPrivate : public QObject |
|
40 { |
|
41 /** |
|
42 * defined to be able to use signals and slots |
|
43 */ |
|
44 Q_OBJECT |
|
45 |
|
46 public: |
|
47 |
|
48 /** |
|
49 * Default constructor |
|
50 */ |
|
51 VideoThumbnailDataPrivate(); |
|
52 |
|
53 /** |
|
54 * Destructor |
|
55 */ |
|
56 virtual ~VideoThumbnailDataPrivate(); |
|
57 |
|
58 /** |
|
59 * Method returns a pointer to video's thumbnail. |
|
60 * |
|
61 * If thumbnail fetching is ongoing or not yet started, pointer to default thumbnail |
|
62 * is returned. |
|
63 * |
|
64 * @param mediaId media id for which to get thumbnail |
|
65 * @param tnData reference to thumbnail data where data is ocpied |
|
66 * |
|
67 * @return QIcon* thumbnail pointer |
|
68 * |
|
69 */ |
|
70 const QIcon* getThumbnail(TMPXItemId mediaId); |
|
71 |
|
72 /** |
|
73 * Method removes thumbnail data from the icon cache. |
|
74 * |
|
75 * @param mediaId id for media whose thumbnail is to be removed |
|
76 * |
|
77 * @return bool: true if item removed correctly, false if not. |
|
78 * |
|
79 */ |
|
80 bool removeThumbnail(TMPXItemId mediaId); |
|
81 |
|
82 /** |
|
83 * Starts background thumbnail fetching from the given fetch index. |
|
84 * |
|
85 * @param model model of the items for the fetching. |
|
86 * @param fetchIndex index where to start the background thumbnail fetching. |
|
87 */ |
|
88 void startBackgroundFetching(VideoSortFilterProxyModel *model, int fetchIndex); |
|
89 |
|
90 /** |
|
91 * Enables or disables thumbnail background fetching. |
|
92 * |
|
93 * @param enable true enables and false disables thumbnail background fetching. |
|
94 */ |
|
95 void enableBackgroundFetching(bool enable); |
|
96 |
|
97 /** |
|
98 * Enables or disables thumbnail creation. Default is enabled. Thumbnails |
|
99 * that have been already generated are fetched still. |
|
100 * |
|
101 * @param enable true enables and false disables thumbnail creation. |
|
102 */ |
|
103 void enableThumbnailCreation(bool enable); |
|
104 |
|
105 /** |
|
106 * Frees allocated data for thumbnails and cancels ongoing fetches. |
|
107 */ |
|
108 void freeThumbnailData(); |
|
109 |
|
110 protected: |
|
111 |
|
112 /** |
|
113 * Method creates member objects and connects signals. |
|
114 * |
|
115 * @return int 0 initialization ok, -1 initialization failed |
|
116 * |
|
117 */ |
|
118 int initialize(); |
|
119 |
|
120 /** |
|
121 * Cleanup internal data. This must be called before UI environment is destroyed. |
|
122 */ |
|
123 void cleanup(); |
|
124 |
|
125 /** |
|
126 * Connects the signals. |
|
127 * |
|
128 * @return int 0 connecting ok, -1 connecting failed. |
|
129 */ |
|
130 int connectSignals(); |
|
131 |
|
132 /** |
|
133 * Disconnects the signals. |
|
134 * |
|
135 */ |
|
136 void disconnectSignals(); |
|
137 |
|
138 /** |
|
139 * Starts fetching thumbnails for medias in the model defined by the indexes |
|
140 * parameter. Priority for the thumbnails is ascending starting from the |
|
141 * defined priority. |
|
142 * |
|
143 * param @indexes indexes of the medias in the model |
|
144 * param @priority starting priority for the thumbnails |
|
145 * |
|
146 * @return int count of fetches started or -1 in case of error. |
|
147 */ |
|
148 int startFetchingThumbnails(const QList<QModelIndex> &indexes, int priority); |
|
149 |
|
150 /** |
|
151 * Method starts fetching thumbnail for the video specified by given mediaId |
|
152 * Media IDs are used as a key identification in the thumbnail map where data is |
|
153 * collected. |
|
154 * |
|
155 * @param mediaId media id for which to start fetching thumbnail |
|
156 * @param priority priority for the fetch |
|
157 * |
|
158 * @return int: thumbnail id or -1 if fetch starting fails. |
|
159 * |
|
160 */ |
|
161 int startFetchingThumbnail(TMPXItemId mediaId, int priority); |
|
162 |
|
163 /** |
|
164 * Appends indexes in the source model to the list between start and end. |
|
165 * |
|
166 * @param indexes list of indexes |
|
167 * @param startIndex start index |
|
168 * @param endIndex end index |
|
169 */ |
|
170 void getModelIndexes(QList<QModelIndex> &indexes, int startIndex, int endIndex); |
|
171 |
|
172 /** |
|
173 * Method returns default thumbnail data. |
|
174 * |
|
175 * @param mediaId media id for which to get thumbnail |
|
176 * |
|
177 * @return QIcon: reference to default thumbnail data |
|
178 * |
|
179 */ |
|
180 const QIcon* defaultThumbnail(TMPXItemId mediaId); |
|
181 |
|
182 /** |
|
183 * Starts timer that continues the background thumbnail fetching at timeout. |
|
184 */ |
|
185 void continueBackgroundFetch(); |
|
186 |
|
187 signals: |
|
188 |
|
189 /** |
|
190 * This signal is emitted from thumbnailReadySlot, when |
|
191 * |
|
192 * @param mediaIds: media ids of the videos whose thumbnail is ready. |
|
193 * |
|
194 */ |
|
195 void thumbnailsFetched(QList<TMPXItemId> mediaIds); |
|
196 |
|
197 private slots: |
|
198 |
|
199 /** |
|
200 * Thumbnail fetcher signals this slot when thumbnail is ready |
|
201 * for some item. Thumbnail data is saved to icon cache. |
|
202 * |
|
203 * @param tnData: thumbnail |
|
204 * @param internal: internal data contains pointer to the media id used in emitted signal |
|
205 * @param error: possible error code from thumbnail manager ( 0 == ok ) |
|
206 * |
|
207 */ |
|
208 void thumbnailReadySlot(QPixmap tnData, void *internal, int error); |
|
209 |
|
210 /** |
|
211 * VideoListDataModel signals this slot when the model has been changed. |
|
212 * |
|
213 */ |
|
214 void modelChangedSlot(); |
|
215 |
|
216 /** |
|
217 * Fetches thumbnails around of mCurrentFetchIndex in batches of THUMBNAIL_BACKGROUND_FETCH_AMOUNT. |
|
218 * The fetch index is set by startFetchingThumbnails which also resets |
|
219 * mCurrentBackgroundFetchCount. Maximum of THUMBNAIL_MAX_BACKGROUND_FETCH thumbnails are |
|
220 * fetched between the count resets. |
|
221 * |
|
222 */ |
|
223 void doBackgroundFetching(); |
|
224 |
|
225 /** |
|
226 * Signaled when UI environment is about to be destroyed. Thumbnails must be cleaned before that. |
|
227 * |
|
228 */ |
|
229 void aboutToQuitSlot(); |
|
230 |
|
231 /** |
|
232 * Emits thumbnailReady signals for list of thumbnails. |
|
233 * |
|
234 */ |
|
235 void reportThumbnailsReadySlot(); |
|
236 |
|
237 /** |
|
238 * Thumbnail fetcher signals this when all thumbnails have been fetched. |
|
239 */ |
|
240 void allThumbnailsFetchedSlot(); |
|
241 |
|
242 private: // Data |
|
243 |
|
244 VideoThumbnailFetcher *mThumbnailFetcher; |
|
245 |
|
246 /** |
|
247 * Local cache for thumbnail data: |
|
248 * - key is the video's media id |
|
249 * - data is the actual thumbnail data. |
|
250 * If thumbnail data is not yet fetched, QIcon is default thumbnail. |
|
251 */ |
|
252 QCache<TMPXItemId, QIcon> mThumbnailData; |
|
253 |
|
254 /** |
|
255 * Local hash for default thumbnails. |
|
256 * - key is mpx item id defining default tn type |
|
257 * - data is the actual thumbnail data. |
|
258 */ |
|
259 QHash<TMPXItemId, HbIcon> mDefaultThumbnails; |
|
260 |
|
261 /** |
|
262 * Default thumbnail for a category. |
|
263 */ |
|
264 QIcon *mDefaultTnCategory; |
|
265 |
|
266 /** |
|
267 * Current model, set at call to startBackgroundFetching. |
|
268 */ |
|
269 QPointer<VideoSortFilterProxyModel> mCurrentModel; |
|
270 |
|
271 /** |
|
272 * Current index for background thumbnail fetching. |
|
273 */ |
|
274 int mCurrentFetchIndex; |
|
275 |
|
276 /** |
|
277 * Current count of background thumbnails fetched around the fetch index. |
|
278 */ |
|
279 int mCurrentBackgroundFetchCount; |
|
280 |
|
281 /** |
|
282 * Timer for background fetching. |
|
283 */ |
|
284 QTimer *mBgFetchTimer; |
|
285 |
|
286 /** |
|
287 * Timer for thumbnail ready signaling. |
|
288 */ |
|
289 QTimer *mTbnReportTimer; |
|
290 |
|
291 /** |
|
292 * List of media ids for thumbnails that are ready. |
|
293 */ |
|
294 QList<TMPXItemId> mReadyThumbnailMediaIds; |
|
295 |
|
296 /** |
|
297 * Flag for signal connections. |
|
298 */ |
|
299 bool mSignalsConnected; |
|
300 |
|
301 /** |
|
302 * Indicates if background thumbnail fetching is enabled. |
|
303 */ |
|
304 bool mBackgroundFetchingEnabled; |
|
305 }; |
|
306 |
|
307 #endif // __VIDEOTHUMBNAILDATAPRIVATE_H__ |
|
308 |
|
309 // End of file |