30 #include "videohintwidget.h" |
33 #include "videohintwidget.h" |
31 #include "videocollectionwrapper.h" |
34 #include "videocollectionwrapper.h" |
32 #include "videosortfilterproxymodel.h" |
35 #include "videosortfilterproxymodel.h" |
33 #include "videocollectionviewutils.h" |
36 #include "videocollectionviewutils.h" |
34 #include "videoservices.h" |
37 #include "videoservices.h" |
|
38 #include "videocollectiontrace.h" |
35 |
39 |
36 // --------------------------------------------------------------------------- |
40 // --------------------------------------------------------------------------- |
37 // VideoCollectionUiLoader |
41 // VideoCollectionUiLoader |
38 // --------------------------------------------------------------------------- |
42 // --------------------------------------------------------------------------- |
39 // |
43 // |
40 VideoCollectionUiLoader::VideoCollectionUiLoader(): |
44 VideoCollectionUiLoader::VideoCollectionUiLoader() |
41 HbDocumentLoader(), |
45 : HbDocumentLoader() |
42 mTimerId(0), |
46 , mTimerId( 0 ) |
43 mSortGroup(0), |
47 , mSortGroup( 0 ) |
44 mIsService(false) |
48 , mIsService( false ) |
45 { |
49 { |
|
50 FUNC_LOG; |
46 } |
51 } |
47 |
52 |
48 // --------------------------------------------------------------------------- |
53 // --------------------------------------------------------------------------- |
49 // VideoCollectionUiLoader |
54 // VideoCollectionUiLoader |
50 // --------------------------------------------------------------------------- |
55 // --------------------------------------------------------------------------- |
51 // |
56 // |
52 VideoCollectionUiLoader::~VideoCollectionUiLoader() |
57 VideoCollectionUiLoader::~VideoCollectionUiLoader() |
53 { |
58 { |
|
59 FUNC_LOG; |
|
60 |
|
61 // delete objects without a parent |
|
62 while (!mOrphans.isEmpty()) |
|
63 { |
|
64 delete mOrphans.takeFirst(); |
|
65 } |
|
66 |
|
67 // kill timer if running |
54 if (mTimerId) |
68 if (mTimerId) |
55 { |
69 { |
56 killTimer(mTimerId); |
70 killTimer(mTimerId); |
57 mTimerId = 0; |
71 mTimerId = 0; |
58 } |
72 } |
59 |
73 |
60 // selection dialog needs to be deleted manually |
|
61 QGraphicsWidget *widget = |
|
62 HbDocumentLoader::findWidget(DOCML_NAME_DIALOG); |
|
63 |
|
64 VideoListSelectionDialog *dialog = |
|
65 qobject_cast<VideoListSelectionDialog*>(widget); |
|
66 delete dialog; |
|
67 |
|
68 // clear queue and hash tables |
74 // clear queue and hash tables |
69 mQueue.clear(); |
75 mQueue.clear(); |
70 mDocmls.clear(); |
76 mDocmls.clear(); |
71 mWidgets.clear(); |
77 mSections.clear(); |
72 mObjects.clear(); |
78 mObjects.clear(); |
|
79 mPhases.clear(); |
73 } |
80 } |
74 |
81 |
75 // --------------------------------------------------------------------------- |
82 // --------------------------------------------------------------------------- |
76 // load |
83 // load |
77 // --------------------------------------------------------------------------- |
84 // --------------------------------------------------------------------------- |
78 // |
85 // |
79 QObjectList VideoCollectionUiLoader::load( const QString &fileName, bool *ok ) |
86 void VideoCollectionUiLoader::load(const QString &fileName, bool *ok) |
80 { |
87 { |
81 QObjectList list; |
88 FUNC_LOG; |
82 if (!mDocmls.contains(fileName)) |
89 if (!mDocmls.contains(fileName)) |
83 { |
90 { |
84 mDocmls.append(fileName); |
91 QObjectList list = HbDocumentLoader::load(fileName, ok); |
85 list = HbDocumentLoader::load(fileName, ok); |
92 if (ok && *ok) |
86 //TODO: save returned and delete on destructor |
93 { |
|
94 mDocmls.insert(fileName); |
|
95 } |
|
96 |
|
97 // add objects without a parent to orphan list |
|
98 storeOrphans(list); |
87 } |
99 } |
88 return list; |
100 else |
|
101 { |
|
102 *ok = true; |
|
103 } |
89 } |
104 } |
90 |
105 |
91 // --------------------------------------------------------------------------- |
106 // --------------------------------------------------------------------------- |
92 // load |
107 // load |
93 // --------------------------------------------------------------------------- |
108 // --------------------------------------------------------------------------- |
94 // |
109 // |
95 QObjectList VideoCollectionUiLoader::load( const QString &fileName, const QString §ion , bool *ok ) |
110 void VideoCollectionUiLoader::load(const QString &fileName, |
96 { |
111 const QString §ion, |
97 return HbDocumentLoader::load(fileName, section, ok); |
112 bool *ok) |
98 //TODO: save returned and delete on destructor |
113 { |
99 } |
114 FUNC_LOG; |
100 |
115 if (!mSections.contains(section)) |
101 // --------------------------------------------------------------------------- |
116 { |
102 // startLoading |
117 QObjectList list = HbDocumentLoader::load(fileName, section, ok); |
103 // --------------------------------------------------------------------------- |
118 if (ok && *ok) |
104 // |
119 { |
105 void VideoCollectionUiLoader::startLoading(QSet<QString> uiSections, |
120 mSections.insert(section); |
|
121 } |
|
122 |
|
123 // add objects without a parent to orphan list |
|
124 storeOrphans(list); |
|
125 } |
|
126 else |
|
127 { |
|
128 *ok = true; |
|
129 } |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // addData |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 void VideoCollectionUiLoader::addData( |
|
137 QList<VideoCollectionUiLoaderParam> params, |
106 QObject *receiver, |
138 QObject *receiver, |
107 const char *widgetSlot, |
139 const char *slot) |
108 const char *objectSlot) |
140 { |
109 { |
141 FUNC_LOG; |
110 if (uiSections.contains(DOCML_NAME_VC_HEADINGBANNER)) |
142 // go through all parameters and add then in to the queue |
111 { |
143 foreach (VideoCollectionUiLoaderParam param, params) |
112 VideoCollectionUiLoader::Params params( |
144 { |
113 DOCML_NAME_VC_HEADINGBANNER, |
145 addToQueue(param, receiver, slot); |
114 true, // is widget |
146 } |
115 receiver, |
147 } |
116 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
148 |
117 0, |
149 // --------------------------------------------------------------------------- |
118 widgetSlot); |
150 // loadPhase |
119 addToQueue(params); |
151 // --------------------------------------------------------------------------- |
120 } |
152 // |
121 if (uiSections.contains(DOCML_NAME_VC_VIDEOLISTWIDGET)) |
153 void VideoCollectionUiLoader::loadPhase(int loadPhase) |
122 { |
154 { |
123 VideoCollectionUiLoader::Params params( |
155 FUNC_LOG; |
124 DOCML_NAME_VC_VIDEOLISTWIDGET, |
156 if (!mPhases.contains(loadPhase)) |
125 true, // is widget |
157 { |
126 receiver, |
158 mPhases.insert(loadPhase); |
127 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
159 if (!mTimerId) |
128 0, |
160 { |
129 widgetSlot); |
161 runNext(); |
130 addToQueue(params); |
162 } |
131 } |
163 } |
132 if (uiSections.contains(DOCML_NAME_OPTIONS_MENU)) |
164 } |
133 { |
165 |
134 VideoCollectionUiLoader::Params params( |
166 // --------------------------------------------------------------------------- |
135 DOCML_NAME_OPTIONS_MENU, |
167 // removeOrphanFromList |
136 true, // is widget |
168 // --------------------------------------------------------------------------- |
137 receiver, |
169 // |
138 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
170 void VideoCollectionUiLoader::removeOrphanFromList(QObject *object) |
139 0, |
171 { |
140 widgetSlot); |
172 FUNC_LOG; |
141 addToQueue(params); |
173 // remove from orphan list |
142 } |
174 if (mOrphans.contains(object)) |
143 if (uiSections.contains(DOCML_NAME_ADD_TO_COLLECTION)) |
175 { |
144 { |
176 mOrphans.removeOne(object); |
145 VideoCollectionUiLoader::Params params( |
177 } |
146 DOCML_NAME_ADD_TO_COLLECTION, |
178 |
147 false, // is object |
179 // remove from initialized objects list |
148 receiver, |
180 const QString &name = mObjects.key(object); |
149 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
181 if (!name.isEmpty()) |
150 0, |
182 { |
151 objectSlot); |
183 // found from list, remove |
152 addToQueue(params); |
184 mObjects.remove(name); |
153 } |
|
154 if (uiSections.contains(DOCML_NAME_CREATE_COLLECTION)) |
|
155 { |
|
156 VideoCollectionUiLoader::Params params( |
|
157 DOCML_NAME_CREATE_COLLECTION, |
|
158 false, // is object |
|
159 receiver, |
|
160 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
161 0, |
|
162 objectSlot); |
|
163 addToQueue(params); |
|
164 } |
|
165 if (uiSections.contains(DOCML_NAME_DELETE_MULTIPLE)) |
|
166 { |
|
167 VideoCollectionUiLoader::Params params( |
|
168 DOCML_NAME_DELETE_MULTIPLE, |
|
169 false, // is object |
|
170 receiver, |
|
171 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
172 0, |
|
173 objectSlot); |
|
174 addToQueue(params); |
|
175 } |
|
176 if (uiSections.contains(DOCML_NAME_VC_VIDEOHINTWIDGET)) |
|
177 { |
|
178 VideoCollectionUiLoader::Params params( |
|
179 DOCML_NAME_VC_VIDEOHINTWIDGET, |
|
180 true, // is widget |
|
181 receiver, |
|
182 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
183 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
184 widgetSlot); |
|
185 addToQueue(params); |
|
186 } |
|
187 if (uiSections.contains(DOCML_NAME_HINT_BUTTON)) |
|
188 { |
|
189 VideoCollectionUiLoader::Params params( |
|
190 DOCML_NAME_HINT_BUTTON, |
|
191 true, // is widget |
|
192 receiver, |
|
193 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
194 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
195 widgetSlot); |
|
196 addToQueue(params); |
|
197 } |
|
198 if (uiSections.contains(DOCML_NAME_NO_VIDEOS_LABEL)) |
|
199 { |
|
200 VideoCollectionUiLoader::Params params( |
|
201 DOCML_NAME_NO_VIDEOS_LABEL, |
|
202 true, // is widget |
|
203 receiver, |
|
204 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
205 DOCML_VIDEOCOLLECTIONVIEW_SECTION_HINT, |
|
206 widgetSlot); |
|
207 addToQueue(params); |
|
208 } |
|
209 if (uiSections.contains(DOCML_NAME_SORT_BY_DATE)) |
|
210 { |
|
211 VideoCollectionUiLoader::Params params( |
|
212 DOCML_NAME_SORT_BY_DATE, |
|
213 false, // is object |
|
214 receiver, |
|
215 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
216 0, |
|
217 objectSlot); |
|
218 addToQueue(params); |
|
219 } |
|
220 if (uiSections.contains(DOCML_NAME_SORT_BY_NAME)) |
|
221 { |
|
222 VideoCollectionUiLoader::Params params( |
|
223 DOCML_NAME_SORT_BY_NAME, |
|
224 false, // is object |
|
225 receiver, |
|
226 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
227 0, |
|
228 objectSlot); |
|
229 addToQueue(params); |
|
230 } |
|
231 if (uiSections.contains(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS)) |
|
232 { |
|
233 VideoCollectionUiLoader::Params params( |
|
234 DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS, |
|
235 false, // is object |
|
236 receiver, |
|
237 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
238 0, |
|
239 objectSlot); |
|
240 addToQueue(params); |
|
241 } |
|
242 if (uiSections.contains(DOCML_NAME_SORT_BY_SIZE)) |
|
243 { |
|
244 VideoCollectionUiLoader::Params params( |
|
245 DOCML_NAME_SORT_BY_SIZE, |
|
246 false, // is object |
|
247 receiver, |
|
248 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
249 0, |
|
250 objectSlot); |
|
251 addToQueue(params); |
|
252 } |
|
253 if (uiSections.contains(DOCML_NAME_SORT_MENU)) |
|
254 { |
|
255 VideoCollectionUiLoader::Params params( |
|
256 DOCML_NAME_SORT_MENU, |
|
257 true, // is widget |
|
258 receiver, |
|
259 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
260 0, |
|
261 widgetSlot); |
|
262 addToQueue(params); |
|
263 } |
|
264 if (uiSections.contains(DOCML_NAME_VC_COLLECTIONWIDGET)) |
|
265 { |
|
266 VideoCollectionUiLoader::Params params( |
|
267 DOCML_NAME_VC_COLLECTIONWIDGET, |
|
268 true, // is widget |
|
269 receiver, |
|
270 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
271 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
272 widgetSlot); |
|
273 addToQueue(params); |
|
274 } |
|
275 if (uiSections.contains(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET)) |
|
276 { |
|
277 VideoCollectionUiLoader::Params params( |
|
278 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET, |
|
279 true, // is widget |
|
280 receiver, |
|
281 DOCML_VIDEOCOLLECTIONVIEW_FILE, |
|
282 DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST, |
|
283 widgetSlot); |
|
284 addToQueue(params); |
|
285 } |
|
286 if (uiSections.contains(DOCML_NAME_DIALOG)) |
|
287 { |
|
288 VideoCollectionUiLoader::Params params(DOCML_NAME_DIALOG, |
|
289 true, // is widget |
|
290 receiver, |
|
291 DOCML_VIDEOSELECTIONDIALOG_FILE, |
|
292 0, |
|
293 widgetSlot); |
|
294 addToQueue(params); |
|
295 } |
185 } |
296 } |
186 } |
297 |
187 |
298 // --------------------------------------------------------------------------- |
188 // --------------------------------------------------------------------------- |
299 // setIsService |
189 // setIsService |
300 // --------------------------------------------------------------------------- |
190 // --------------------------------------------------------------------------- |
301 // |
191 // |
302 void VideoCollectionUiLoader::setIsService(bool isService) |
192 void VideoCollectionUiLoader::setIsService(bool isService) |
303 { |
193 { |
|
194 FUNC_LOG; |
304 mIsService = isService; |
195 mIsService = isService; |
305 } |
196 } |
306 |
197 |
307 // --------------------------------------------------------------------------- |
198 // --------------------------------------------------------------------------- |
308 // doFindWidget |
199 // doFindWidget |
309 // --------------------------------------------------------------------------- |
200 // --------------------------------------------------------------------------- |
310 // |
201 // |
311 QGraphicsWidget* VideoCollectionUiLoader::doFindWidget(const QString &name) |
202 QGraphicsWidget* VideoCollectionUiLoader::doFindWidget(const QString &name) |
312 { |
203 { |
|
204 FUNC_LOG; |
313 QGraphicsWidget *widget = 0; |
205 QGraphicsWidget *widget = 0; |
314 |
|
315 // 1. check from hash |
|
316 if (mWidgets.contains(name)) |
|
317 { |
|
318 widget = mWidgets.value(name); |
|
319 } |
|
320 |
|
321 // 2. load from document |
|
322 else |
|
323 { |
|
324 widget = HbDocumentLoader::findWidget(name); |
|
325 if (!widget) |
|
326 { |
|
327 // check if the widget is being loaded and remove it from queue |
|
328 int count = mQueue.count(); |
|
329 for (int i = 0; i < count; i++) |
|
330 { |
|
331 const Params& params = mQueue.at(i); |
|
332 if (params.mName.compare(name) == 0) |
|
333 { |
|
334 bool ok(true); |
|
335 |
|
336 if(!mDocmls.contains(params.mDocml)) |
|
337 { |
|
338 load(params.mDocml, &ok); |
|
339 |
|
340 if (ok) |
|
341 { |
|
342 mDocmls.append(params.mDocml); |
|
343 } |
|
344 } |
|
345 if ((params.mSection != 0) && ok) |
|
346 { |
|
347 load(params.mDocml, params.mSection, &ok); |
|
348 } |
|
349 if(ok) |
|
350 { |
|
351 widget = HbDocumentLoader::findWidget(params.mName); |
|
352 } |
|
353 break; |
|
354 } |
|
355 } |
|
356 } |
|
357 if (widget) |
|
358 { |
|
359 // initialize widget |
|
360 initWidget(widget, name); |
|
361 |
|
362 // add it to the hash |
|
363 mWidgets.insert(name, widget); |
|
364 |
|
365 // check if the widget is being loaded and remove it from queue |
|
366 int count = mQueue.count(); |
|
367 for (int i = 0; i < count; i++) |
|
368 { |
|
369 const Params& params = mQueue.at(i); |
|
370 if (params.mName.compare(name) == 0) |
|
371 { |
|
372 if (connect( |
|
373 this, SIGNAL(widgetReady(QGraphicsWidget*, const QString&)), |
|
374 params.mReceiver, params.mMember)) |
|
375 { |
|
376 emit widgetReady(widget, params.mName); |
|
377 disconnect( |
|
378 this, SIGNAL(widgetReady(QGraphicsWidget*, const QString&)), |
|
379 params.mReceiver, params.mMember); |
|
380 } |
|
381 mQueue.removeAt(i); |
|
382 runNext(); //removes timer if queue is empty |
|
383 break; |
|
384 } |
|
385 } |
|
386 } |
|
387 } |
|
388 |
|
389 return widget; |
|
390 } |
|
391 |
|
392 // --------------------------------------------------------------------------- |
|
393 // doFindObject |
|
394 // --------------------------------------------------------------------------- |
|
395 // |
|
396 QObject* VideoCollectionUiLoader::doFindObject(const QString &name) |
|
397 { |
|
398 QObject *object = 0; |
|
399 |
206 |
400 // 1. check from hash |
207 // 1. check from hash |
401 if (mObjects.contains(name)) |
208 if (mObjects.contains(name)) |
402 { |
209 { |
|
210 widget = qobject_cast<QGraphicsWidget*>(mObjects.value(name)); |
|
211 } |
|
212 |
|
213 // 2. load from document and initialize |
|
214 else |
|
215 { |
|
216 // find object from queue |
|
217 int index = indexInQueue(name); |
|
218 if (index != -1) |
|
219 { |
|
220 // object found from queue, load and initialize object |
|
221 const VideoCollectionUiLoaderParam ¶m = mQueue.at(index); |
|
222 widget = qobject_cast<QGraphicsWidget*>(executeRequest(param)); |
|
223 |
|
224 // object in loading queue, remove it |
|
225 removeFromQueue(name); |
|
226 } |
|
227 else |
|
228 { |
|
229 // assuming that docml and section has already been loaded |
|
230 widget = HbDocumentLoader::findWidget(name); |
|
231 } |
|
232 } |
|
233 |
|
234 return widget; |
|
235 } |
|
236 |
|
237 // --------------------------------------------------------------------------- |
|
238 // doFindObject |
|
239 // --------------------------------------------------------------------------- |
|
240 // |
|
241 QObject* VideoCollectionUiLoader::doFindObject(const QString &name) |
|
242 { |
|
243 FUNC_LOG; |
|
244 QObject *object = 0; |
|
245 |
|
246 // 1. check from hash |
|
247 if (mObjects.contains(name)) |
|
248 { |
403 object = mObjects.value(name); |
249 object = mObjects.value(name); |
404 } |
250 } |
405 |
251 |
406 // 2. load from document and cancel async loading |
252 // 2. load from document and initialize |
407 else |
253 else |
408 { |
254 { |
409 object = HbDocumentLoader::findObject(name); |
255 // find object from queue |
410 if (!object) |
256 int index = indexInQueue(name); |
411 { |
257 if (index != -1) |
412 // check if the object is being loaded and remove it from queue |
258 { |
413 int count = mQueue.count(); |
259 // object found from queue, load and initialize object |
414 for (int i = 0; i < count; i++) |
260 const VideoCollectionUiLoaderParam ¶m = mQueue.at(index); |
415 { |
261 object = executeRequest(param); |
416 const Params& params = mQueue.at(i); |
|
417 if (params.mName.compare(name) == 0) |
|
418 { |
|
419 bool ok(true); |
|
420 |
|
421 if(!mDocmls.contains(params.mDocml)) |
|
422 { |
|
423 load(params.mDocml, &ok); |
|
424 |
|
425 if (ok) |
|
426 { |
|
427 mDocmls.append(params.mDocml); |
|
428 } |
|
429 } |
|
430 if ((params.mSection != 0) && ok) |
|
431 { |
|
432 load(params.mDocml, params.mSection, &ok); |
|
433 } |
|
434 if(ok) |
|
435 { |
|
436 object = HbDocumentLoader::findObject(params.mName); |
|
437 } |
|
438 break; |
|
439 } |
|
440 } |
|
441 } |
|
442 if (object) |
|
443 { |
|
444 // initialize widget |
|
445 initObject(object, name); |
|
446 |
262 |
447 // add it to the hash |
263 // object in loading queue, remove it |
448 mObjects.insert(name, object); |
264 removeFromQueue(name); |
449 |
265 } |
450 // check if the object is being loaded and remove it from queue |
266 else |
451 int count = mQueue.count(); |
267 { |
452 for (int i = 0; i < count; i++) |
268 // assuming that docml and section has already been loaded |
453 { |
269 object = HbDocumentLoader::findObject(name); |
454 const Params& params = mQueue.at(i); |
270 } |
455 if (params.mName.compare(name) == 0) |
271 } |
456 { |
272 |
457 if (connect( |
|
458 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
459 params.mReceiver, params.mMember)) |
|
460 { |
|
461 emit objectReady(object, params.mName); |
|
462 disconnect( |
|
463 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
464 params.mReceiver, params.mMember); |
|
465 } |
|
466 mQueue.removeAt(i); |
|
467 runNext(); //removes timer if queue is empty |
|
468 break; |
|
469 } |
|
470 } |
|
471 } |
|
472 } |
|
473 |
|
474 return object; |
273 return object; |
475 } |
274 } |
476 |
275 |
477 // --------------------------------------------------------------------------- |
276 // --------------------------------------------------------------------------- |
478 // addToQueue |
277 // addToQueue |
479 // --------------------------------------------------------------------------- |
278 // --------------------------------------------------------------------------- |
480 // |
279 // |
481 void VideoCollectionUiLoader::addToQueue(Params ¶ms) |
280 void VideoCollectionUiLoader::addToQueue(VideoCollectionUiLoaderParam ¶m, |
482 { |
281 QObject *receiver, |
483 if (isValid(params)) |
282 const char *slot) |
|
283 { |
|
284 FUNC_LOG; |
|
285 |
|
286 INFOQSTR_1("VideoCollectionUiLoader::addToQueue() name: %S", param.mName); |
|
287 |
|
288 // set receiver if not already set |
|
289 if (!param.mReceiver) |
|
290 { |
|
291 param.mReceiver = receiver; |
|
292 } |
|
293 |
|
294 // set slot if not already set |
|
295 if (!param.mMember) |
|
296 { |
|
297 param.mMember = slot; |
|
298 } |
|
299 |
|
300 // check validity and hit it |
|
301 if (isValid(param)) |
484 { |
302 { |
485 // add the params in async queue |
303 // add the params in async queue |
486 mQueue.append(params); |
304 mQueue.append(param); |
487 runNext(); |
305 } |
488 } |
306 } |
489 } |
307 |
490 |
308 // --------------------------------------------------------------------------- |
491 // --------------------------------------------------------------------------- |
309 // getObject |
492 // initWidget |
310 // --------------------------------------------------------------------------- |
493 // --------------------------------------------------------------------------- |
311 // |
494 // |
312 QObject* VideoCollectionUiLoader::getObject( |
495 void VideoCollectionUiLoader::initWidget(QGraphicsWidget *widget, |
313 const VideoCollectionUiLoaderParam ¶m) |
|
314 { |
|
315 FUNC_LOG; |
|
316 QObject *object = 0; |
|
317 |
|
318 if (param.mIsWidget) |
|
319 { |
|
320 object = HbDocumentLoader::findWidget(param.mName); |
|
321 } |
|
322 else |
|
323 { |
|
324 object = HbDocumentLoader::findObject(param.mName); |
|
325 } |
|
326 |
|
327 return object; |
|
328 } |
|
329 |
|
330 // --------------------------------------------------------------------------- |
|
331 // prepareDocmlAndSection |
|
332 // --------------------------------------------------------------------------- |
|
333 // |
|
334 bool VideoCollectionUiLoader::prepareDocmlAndSection(const char *docml, |
|
335 const char *section) |
|
336 { |
|
337 FUNC_LOG; |
|
338 bool ok = true; |
|
339 |
|
340 // prepare docml |
|
341 if (docml && !mDocmls.contains(docml)) |
|
342 { |
|
343 load(docml, &ok); |
|
344 } |
|
345 |
|
346 // prepare section |
|
347 if (ok && section && !mSections.contains(section)) |
|
348 { |
|
349 load(docml, section, &ok); |
|
350 } |
|
351 |
|
352 return ok; |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // initObject |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void VideoCollectionUiLoader::initObject(QObject *object, |
496 const QString &name) |
360 const QString &name) |
497 { |
361 { |
498 if (widget) |
362 FUNC_LOG; |
499 { |
363 if (object) |
|
364 { |
|
365 INFOQSTR_1("VideoCollectionUiLoader::initObject() name: %S", name); |
500 VideoCollectionWrapper &wrapper = VideoCollectionWrapper::instance(); |
366 VideoCollectionWrapper &wrapper = VideoCollectionWrapper::instance(); |
501 |
|
502 if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0) |
367 if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0) |
503 { |
368 { |
504 VideoListWidget *videoList = qobject_cast<VideoListWidget*>(widget); |
369 VideoListWidget *videoList = qobject_cast<VideoListWidget*>(object); |
505 if (videoList) |
370 if (videoList) |
506 { |
371 { |
507 VideoSortFilterProxyModel *model = |
372 VideoSortFilterProxyModel *model = |
508 wrapper.getModel(VideoCollectionWrapper::EAllVideos); |
373 wrapper.getModel(VideoCollectionCommon::EModelTypeAllVideos); |
509 if(model) |
374 if(model) |
510 { |
375 { |
511 // open and sort model |
376 // open and sort model |
512 model->open(VideoCollectionCommon::ELevelVideos); |
377 model->open(VideoCollectionCommon::ELevelVideos); |
513 VideoCollectionViewUtils::sortModel(model, true); |
378 VideoCollectionViewUtils::sortModel(model, true, VideoCollectionCommon::ELevelVideos); |
514 |
379 |
515 // init widget |
380 // init widget |
516 VideoServices *videoServices = 0; |
381 VideoServices *videoServices = 0; |
517 if (mIsService) |
382 if (mIsService) |
518 { |
383 { |
706 } |
560 } |
707 } |
561 } |
708 } |
562 } |
709 |
563 |
710 // --------------------------------------------------------------------------- |
564 // --------------------------------------------------------------------------- |
|
565 // executeRequest |
|
566 // --------------------------------------------------------------------------- |
|
567 // |
|
568 QObject* VideoCollectionUiLoader::executeRequest( |
|
569 const VideoCollectionUiLoaderParam ¶m) |
|
570 { |
|
571 FUNC_LOG; |
|
572 QObject *object = getObject(param); |
|
573 if (!object) |
|
574 { |
|
575 // object was not found, try preparing docml and section |
|
576 bool ok = prepareDocmlAndSection(param.mDocml, param.mSection); |
|
577 if (ok) |
|
578 { |
|
579 // try to get the object again |
|
580 object = getObject(param); |
|
581 } |
|
582 } |
|
583 |
|
584 // initialize object if it was found from docml |
|
585 if (object) |
|
586 { |
|
587 if (!mObjects.contains(param.mName)) |
|
588 { |
|
589 // initialize object |
|
590 initObject(object, param.mName); |
|
591 |
|
592 // insert object in hash table |
|
593 mObjects.insert(param.mName, object); |
|
594 } |
|
595 |
|
596 bool ok = connect( |
|
597 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
598 param.mReceiver, param.mMember); |
|
599 if (ok) |
|
600 { |
|
601 // signal client and disconnect |
|
602 emit objectReady(object, param.mName); |
|
603 disconnect( |
|
604 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
605 param.mReceiver, param.mMember); |
|
606 } |
|
607 } |
|
608 |
|
609 return object; |
|
610 } |
|
611 |
|
612 // --------------------------------------------------------------------------- |
|
613 // indexInQueue |
|
614 // --------------------------------------------------------------------------- |
|
615 // |
|
616 int VideoCollectionUiLoader::indexInQueue(const QString &name) |
|
617 { |
|
618 FUNC_LOG; |
|
619 int index = -1; |
|
620 |
|
621 int count = mQueue.count(); |
|
622 for (int i = 0; i < count; i++) |
|
623 { |
|
624 const VideoCollectionUiLoaderParam ¶m = mQueue.at(i); |
|
625 if (param.mName == name) |
|
626 { |
|
627 // found from queue |
|
628 index = i; |
|
629 break; |
|
630 } |
|
631 } |
|
632 |
|
633 return index; |
|
634 } |
|
635 |
|
636 // --------------------------------------------------------------------------- |
|
637 // removeFromQueue |
|
638 // --------------------------------------------------------------------------- |
|
639 // |
|
640 void VideoCollectionUiLoader::removeFromQueue(const QString &name) |
|
641 { |
|
642 FUNC_LOG; |
|
643 int count = mQueue.count(); |
|
644 for (int i = 0; i < count; i++) |
|
645 { |
|
646 const VideoCollectionUiLoaderParam ¶m = mQueue.at(i); |
|
647 if (param.mName == name) |
|
648 { |
|
649 mQueue.removeAt(i); |
|
650 break; |
|
651 } |
|
652 } |
|
653 } |
|
654 |
|
655 // --------------------------------------------------------------------------- |
711 // timerEvent |
656 // timerEvent |
712 // --------------------------------------------------------------------------- |
657 // --------------------------------------------------------------------------- |
713 // |
658 // |
714 void VideoCollectionUiLoader::timerEvent(QTimerEvent *event) |
659 void VideoCollectionUiLoader::timerEvent(QTimerEvent *event) |
715 { |
660 { |
|
661 FUNC_LOG; |
716 if (event) |
662 if (event) |
717 { |
663 { |
718 if (event->timerId() == mTimerId) |
664 if (event->timerId() == mTimerId) |
719 { |
665 { |
720 // get current request from queue |
666 // get current request from queue and execute it |
721 const Params ¶ms = mQueue.at(0); |
667 int count = mQueue.count(); |
722 |
668 for (int i = 0; i < count; i++) |
723 // load the widget / object |
669 { |
724 if (params.mIsWidget) |
670 const VideoCollectionUiLoaderParam ¶m = mQueue.at(i); |
725 { |
671 if (mPhases.contains(param.mPhase)) |
726 // correct timer id, emit signal for receiver |
|
727 bool ok = connect( |
|
728 this, SIGNAL(widgetReady(QGraphicsWidget*, const QString&)), |
|
729 params.mReceiver, params.mMember); |
|
730 if (ok) |
|
731 { |
672 { |
732 QGraphicsWidget *widget = |
673 // load and initialize |
733 HbDocumentLoader::findWidget(params.mName); |
674 executeRequest(param); |
734 if (!widget) |
675 |
735 { |
676 // remove the current request from queue and run next |
736 // widget not found, try to load the docml |
677 removeFromQueue(param.mName); |
737 if(!mDocmls.contains(params.mDocml)) |
678 break; |
738 { |
|
739 load(params.mDocml, &ok); |
|
740 |
|
741 if (ok) |
|
742 { |
|
743 mDocmls.append(params.mDocml); |
|
744 } |
|
745 } |
|
746 if ((params.mSection != 0) && ok) |
|
747 { |
|
748 load(params.mDocml, params.mSection, &ok); |
|
749 } |
|
750 if(ok) |
|
751 { |
|
752 widget = HbDocumentLoader::findWidget(params.mName); |
|
753 } |
|
754 } |
|
755 if (widget) |
|
756 { |
|
757 // widget found, add it to the hash |
|
758 if (!mWidgets.contains(params.mName)) |
|
759 { |
|
760 // initialize widget |
|
761 initWidget(widget, params.mName); |
|
762 |
|
763 // insert widget in hash table |
|
764 mWidgets.insert(params.mName, widget); |
|
765 } |
|
766 emit widgetReady(widget, params.mName); |
|
767 } |
|
768 } |
679 } |
769 |
680 } |
770 // disconnect |
681 runNext(); |
771 disconnect( |
682 } |
772 this, SIGNAL(widgetReady(QGraphicsWidget*, const QString&)), |
|
773 params.mReceiver, params.mMember); |
|
774 } |
|
775 else |
|
776 { |
|
777 // correct timer id, emit signal for receiver |
|
778 bool ok = connect( |
|
779 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
780 params.mReceiver, params.mMember); |
|
781 if (ok) |
|
782 { |
|
783 QObject *object = |
|
784 HbDocumentLoader::findObject(params.mName); |
|
785 if (!object) |
|
786 { |
|
787 // widget not found, try to load the docml |
|
788 if(!mDocmls.contains(params.mDocml)) |
|
789 { |
|
790 load(params.mDocml, &ok); |
|
791 |
|
792 if (ok) |
|
793 { |
|
794 mDocmls.append(params.mDocml); |
|
795 } |
|
796 } |
|
797 if ((params.mSection != 0) && ok) |
|
798 { |
|
799 load(params.mDocml, params.mSection, &ok); |
|
800 } |
|
801 if(ok) |
|
802 { |
|
803 object = HbDocumentLoader::findObject(params.mName); |
|
804 } |
|
805 } |
|
806 if (object) |
|
807 { |
|
808 // object found, add it to the hash |
|
809 if (!mObjects.contains(params.mName)) |
|
810 { |
|
811 // initialize object |
|
812 initObject(object, params.mName); |
|
813 |
|
814 // add object in hash table |
|
815 mObjects.insert(params.mName, object); |
|
816 } |
|
817 emit objectReady(object, params.mName); |
|
818 } |
|
819 } |
|
820 |
|
821 // disconnect |
|
822 disconnect( |
|
823 this, SIGNAL(objectReady(QObject*, const QString&)), |
|
824 params.mReceiver, params.mMember); |
|
825 } |
|
826 } |
|
827 |
|
828 // remove the request from the queue and run next request if any |
|
829 mQueue.removeAt(0); |
|
830 runNext(); |
|
831 } |
683 } |
832 } |
684 } |
833 |
685 |
834 // --------------------------------------------------------------------------- |
686 // --------------------------------------------------------------------------- |
835 // createObject |
687 // createObject |
836 // --------------------------------------------------------------------------- |
688 // --------------------------------------------------------------------------- |
837 // |
689 // |
838 QObject* VideoCollectionUiLoader::createObject( const QString& type, const QString &name ) |
690 QObject* VideoCollectionUiLoader::createObject( const QString& type, const QString &name ) |
839 { |
691 { |
|
692 FUNC_LOG; |
840 QObject* object = 0; |
693 QObject* object = 0; |
841 |
694 |
842 if ( type == VideoListView::staticMetaObject.className() ) |
695 if ( type == VideoListView::staticMetaObject.className() ) |
843 { |
696 { |
844 object = new VideoListView(this); |
697 object = new VideoListView(this); |