30
|
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:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
41
|
18 |
// Version : %version: 24 %
|
36
|
19 |
|
|
20 |
// INCLUDE FILES
|
34
|
21 |
#include <qgraphicswidget.h>
|
|
22 |
#include <qaction.h>
|
|
23 |
#include <qactiongroup.h>
|
|
24 |
#include <hbmenu.h>
|
|
25 |
#include <hbaction.h>
|
|
26 |
#include <hbgroupbox.h>
|
|
27 |
#include <hbpushbutton.h>
|
|
28 |
|
30
|
29 |
#include "videocollectionuiloader.h"
|
|
30 |
#include "videolistview.h"
|
|
31 |
#include "videolistselectiondialog.h"
|
|
32 |
#include "videolistwidget.h"
|
|
33 |
#include "videohintwidget.h"
|
34
|
34 |
#include "videocollectionwrapper.h"
|
|
35 |
#include "videosortfilterproxymodel.h"
|
|
36 |
#include "videocollectionviewutils.h"
|
36
|
37 |
#include "videocollectiontrace.h"
|
34
|
38 |
|
|
39 |
// ---------------------------------------------------------------------------
|
|
40 |
// VideoCollectionUiLoader
|
|
41 |
// ---------------------------------------------------------------------------
|
|
42 |
//
|
36
|
43 |
VideoCollectionUiLoader::VideoCollectionUiLoader()
|
|
44 |
: HbDocumentLoader()
|
|
45 |
, mTimerId( 0 )
|
|
46 |
, mSortGroup( 0 )
|
|
47 |
, mIsService( false )
|
34
|
48 |
{
|
36
|
49 |
FUNC_LOG;
|
34
|
50 |
}
|
30
|
51 |
|
|
52 |
// ---------------------------------------------------------------------------
|
|
53 |
// VideoCollectionUiLoader
|
|
54 |
// ---------------------------------------------------------------------------
|
|
55 |
//
|
34
|
56 |
VideoCollectionUiLoader::~VideoCollectionUiLoader()
|
|
57 |
{
|
36
|
58 |
FUNC_LOG;
|
|
59 |
|
|
60 |
// delete objects without a parent
|
|
61 |
while (!mOrphans.isEmpty())
|
|
62 |
{
|
|
63 |
delete mOrphans.takeFirst();
|
|
64 |
}
|
|
65 |
|
|
66 |
// kill timer if running
|
35
|
67 |
if (mTimerId)
|
|
68 |
{
|
|
69 |
killTimer(mTimerId);
|
|
70 |
mTimerId = 0;
|
|
71 |
}
|
|
72 |
|
34
|
73 |
// clear queue and hash tables
|
|
74 |
mQueue.clear();
|
35
|
75 |
mDocmls.clear();
|
36
|
76 |
mSections.clear();
|
34
|
77 |
mObjects.clear();
|
36
|
78 |
mPhases.clear();
|
34
|
79 |
}
|
|
80 |
|
|
81 |
// ---------------------------------------------------------------------------
|
35
|
82 |
// load
|
|
83 |
// ---------------------------------------------------------------------------
|
|
84 |
//
|
36
|
85 |
void VideoCollectionUiLoader::load(const QString &fileName, bool *ok)
|
35
|
86 |
{
|
36
|
87 |
FUNC_LOG;
|
35
|
88 |
if (!mDocmls.contains(fileName))
|
|
89 |
{
|
36
|
90 |
QObjectList list = HbDocumentLoader::load(fileName, ok);
|
|
91 |
if (ok && *ok)
|
|
92 |
{
|
|
93 |
mDocmls.insert(fileName);
|
|
94 |
}
|
|
95 |
|
|
96 |
// add objects without a parent to orphan list
|
|
97 |
storeOrphans(list);
|
35
|
98 |
}
|
36
|
99 |
else
|
|
100 |
{
|
|
101 |
*ok = true;
|
|
102 |
}
|
35
|
103 |
}
|
|
104 |
|
|
105 |
// ---------------------------------------------------------------------------
|
|
106 |
// load
|
|
107 |
// ---------------------------------------------------------------------------
|
|
108 |
//
|
36
|
109 |
void VideoCollectionUiLoader::load(const QString &fileName,
|
|
110 |
const QString §ion,
|
|
111 |
bool *ok)
|
35
|
112 |
{
|
36
|
113 |
FUNC_LOG;
|
|
114 |
if (!mSections.contains(section))
|
|
115 |
{
|
|
116 |
QObjectList list = HbDocumentLoader::load(fileName, section, ok);
|
|
117 |
if (ok && *ok)
|
|
118 |
{
|
|
119 |
mSections.insert(section);
|
|
120 |
}
|
|
121 |
|
|
122 |
// add objects without a parent to orphan list
|
|
123 |
storeOrphans(list);
|
|
124 |
}
|
|
125 |
else
|
|
126 |
{
|
|
127 |
*ok = true;
|
|
128 |
}
|
35
|
129 |
}
|
|
130 |
|
|
131 |
// ---------------------------------------------------------------------------
|
36
|
132 |
// addData
|
|
133 |
// ---------------------------------------------------------------------------
|
|
134 |
//
|
|
135 |
void VideoCollectionUiLoader::addData(
|
|
136 |
QList<VideoCollectionUiLoaderParam> params,
|
|
137 |
QObject *receiver,
|
|
138 |
const char *slot)
|
|
139 |
{
|
|
140 |
FUNC_LOG;
|
|
141 |
// go through all parameters and add then in to the queue
|
|
142 |
foreach (VideoCollectionUiLoaderParam param, params)
|
|
143 |
{
|
|
144 |
addToQueue(param, receiver, slot);
|
|
145 |
}
|
|
146 |
}
|
|
147 |
|
|
148 |
// ---------------------------------------------------------------------------
|
|
149 |
// loadPhase
|
34
|
150 |
// ---------------------------------------------------------------------------
|
|
151 |
//
|
36
|
152 |
void VideoCollectionUiLoader::loadPhase(int loadPhase)
|
30
|
153 |
{
|
36
|
154 |
FUNC_LOG;
|
|
155 |
if (!mPhases.contains(loadPhase))
|
34
|
156 |
{
|
36
|
157 |
mPhases.insert(loadPhase);
|
|
158 |
if (!mTimerId)
|
|
159 |
{
|
|
160 |
runNext();
|
|
161 |
}
|
34
|
162 |
}
|
36
|
163 |
}
|
|
164 |
|
|
165 |
// ---------------------------------------------------------------------------
|
|
166 |
// removeOrphanFromList
|
|
167 |
// ---------------------------------------------------------------------------
|
|
168 |
//
|
|
169 |
void VideoCollectionUiLoader::removeOrphanFromList(QObject *object)
|
|
170 |
{
|
|
171 |
FUNC_LOG;
|
|
172 |
// remove from orphan list
|
|
173 |
if (mOrphans.contains(object))
|
34
|
174 |
{
|
36
|
175 |
mOrphans.removeOne(object);
|
34
|
176 |
}
|
36
|
177 |
|
|
178 |
// remove from initialized objects list
|
|
179 |
const QString &name = mObjects.key(object);
|
|
180 |
if (!name.isEmpty())
|
34
|
181 |
{
|
36
|
182 |
// found from list, remove
|
|
183 |
mObjects.remove(name);
|
34
|
184 |
}
|
|
185 |
}
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
// setIsService
|
|
189 |
// ---------------------------------------------------------------------------
|
|
190 |
//
|
|
191 |
void VideoCollectionUiLoader::setIsService(bool isService)
|
|
192 |
{
|
36
|
193 |
FUNC_LOG;
|
34
|
194 |
mIsService = isService;
|
|
195 |
}
|
|
196 |
|
|
197 |
// ---------------------------------------------------------------------------
|
|
198 |
// doFindWidget
|
|
199 |
// ---------------------------------------------------------------------------
|
|
200 |
//
|
38
|
201 |
QGraphicsWidget* VideoCollectionUiLoader::doFindWidget(const QString &name, bool loadIfNotFound)
|
34
|
202 |
{
|
36
|
203 |
FUNC_LOG;
|
34
|
204 |
QGraphicsWidget *widget = 0;
|
|
205 |
|
|
206 |
// 1. check from hash
|
36
|
207 |
if (mObjects.contains(name))
|
34
|
208 |
{
|
36
|
209 |
widget = qobject_cast<QGraphicsWidget*>(mObjects.value(name));
|
34
|
210 |
}
|
36
|
211 |
|
|
212 |
// 2. load from document and initialize
|
38
|
213 |
else if (loadIfNotFound)
|
34
|
214 |
{
|
36
|
215 |
// find object from queue
|
|
216 |
int index = indexInQueue(name);
|
|
217 |
if (index != -1)
|
35
|
218 |
{
|
36
|
219 |
// object found from queue, load and initialize object
|
|
220 |
const VideoCollectionUiLoaderParam ¶m = mQueue.at(index);
|
|
221 |
widget = qobject_cast<QGraphicsWidget*>(executeRequest(param));
|
|
222 |
|
|
223 |
// object in loading queue, remove it
|
|
224 |
removeFromQueue(name);
|
35
|
225 |
}
|
36
|
226 |
else
|
34
|
227 |
{
|
36
|
228 |
// assuming that docml and section has already been loaded
|
|
229 |
widget = HbDocumentLoader::findWidget(name);
|
34
|
230 |
}
|
|
231 |
}
|
36
|
232 |
|
34
|
233 |
return widget;
|
|
234 |
}
|
|
235 |
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
// doFindObject
|
|
238 |
// ---------------------------------------------------------------------------
|
|
239 |
//
|
38
|
240 |
QObject* VideoCollectionUiLoader::doFindObject(const QString &name, bool loadIfNotFound)
|
34
|
241 |
{
|
36
|
242 |
FUNC_LOG;
|
34
|
243 |
QObject *object = 0;
|
|
244 |
|
|
245 |
// 1. check from hash
|
|
246 |
if (mObjects.contains(name))
|
|
247 |
{
|
|
248 |
object = mObjects.value(name);
|
|
249 |
}
|
36
|
250 |
|
|
251 |
// 2. load from document and initialize
|
38
|
252 |
else if (loadIfNotFound)
|
34
|
253 |
{
|
36
|
254 |
// find object from queue
|
|
255 |
int index = indexInQueue(name);
|
|
256 |
if (index != -1)
|
35
|
257 |
{
|
36
|
258 |
// object found from queue, load and initialize object
|
|
259 |
const VideoCollectionUiLoaderParam ¶m = mQueue.at(index);
|
|
260 |
object = executeRequest(param);
|
|
261 |
|
|
262 |
// object in loading queue, remove it
|
|
263 |
removeFromQueue(name);
|
35
|
264 |
}
|
36
|
265 |
else
|
34
|
266 |
{
|
36
|
267 |
// assuming that docml and section has already been loaded
|
|
268 |
object = HbDocumentLoader::findObject(name);
|
34
|
269 |
}
|
|
270 |
}
|
36
|
271 |
|
34
|
272 |
return object;
|
30
|
273 |
}
|
|
274 |
|
|
275 |
// ---------------------------------------------------------------------------
|
34
|
276 |
// addToQueue
|
|
277 |
// ---------------------------------------------------------------------------
|
|
278 |
//
|
36
|
279 |
void VideoCollectionUiLoader::addToQueue(VideoCollectionUiLoaderParam ¶m,
|
|
280 |
QObject *receiver,
|
|
281 |
const char *slot)
|
34
|
282 |
{
|
36
|
283 |
FUNC_LOG;
|
|
284 |
|
|
285 |
INFOQSTR_1("VideoCollectionUiLoader::addToQueue() name: %S", param.mName);
|
|
286 |
|
|
287 |
// set receiver if not already set
|
|
288 |
if (!param.mReceiver)
|
|
289 |
{
|
|
290 |
param.mReceiver = receiver;
|
|
291 |
}
|
|
292 |
|
|
293 |
// set slot if not already set
|
|
294 |
if (!param.mMember)
|
|
295 |
{
|
|
296 |
param.mMember = slot;
|
|
297 |
}
|
|
298 |
|
|
299 |
// check validity and hit it
|
|
300 |
if (isValid(param))
|
34
|
301 |
{
|
|
302 |
// add the params in async queue
|
36
|
303 |
mQueue.append(param);
|
34
|
304 |
}
|
|
305 |
}
|
|
306 |
|
|
307 |
// ---------------------------------------------------------------------------
|
36
|
308 |
// getObject
|
|
309 |
// ---------------------------------------------------------------------------
|
|
310 |
//
|
|
311 |
QObject* VideoCollectionUiLoader::getObject(
|
|
312 |
const VideoCollectionUiLoaderParam ¶m)
|
|
313 |
{
|
|
314 |
FUNC_LOG;
|
|
315 |
QObject *object = 0;
|
|
316 |
|
|
317 |
if (param.mIsWidget)
|
|
318 |
{
|
|
319 |
object = HbDocumentLoader::findWidget(param.mName);
|
|
320 |
}
|
|
321 |
else
|
|
322 |
{
|
|
323 |
object = HbDocumentLoader::findObject(param.mName);
|
|
324 |
}
|
|
325 |
|
|
326 |
return object;
|
|
327 |
}
|
|
328 |
|
|
329 |
// ---------------------------------------------------------------------------
|
|
330 |
// prepareDocmlAndSection
|
34
|
331 |
// ---------------------------------------------------------------------------
|
|
332 |
//
|
36
|
333 |
bool VideoCollectionUiLoader::prepareDocmlAndSection(const char *docml,
|
|
334 |
const char *section)
|
|
335 |
{
|
|
336 |
FUNC_LOG;
|
|
337 |
bool ok = true;
|
|
338 |
|
|
339 |
// prepare docml
|
|
340 |
if (docml && !mDocmls.contains(docml))
|
|
341 |
{
|
|
342 |
load(docml, &ok);
|
|
343 |
}
|
|
344 |
|
|
345 |
// prepare section
|
|
346 |
if (ok && section && !mSections.contains(section))
|
|
347 |
{
|
|
348 |
load(docml, section, &ok);
|
|
349 |
}
|
|
350 |
|
|
351 |
return ok;
|
|
352 |
}
|
|
353 |
|
|
354 |
// ---------------------------------------------------------------------------
|
|
355 |
// initObject
|
|
356 |
// ---------------------------------------------------------------------------
|
|
357 |
//
|
|
358 |
void VideoCollectionUiLoader::initObject(QObject *object,
|
34
|
359 |
const QString &name)
|
|
360 |
{
|
36
|
361 |
FUNC_LOG;
|
|
362 |
if (object)
|
34
|
363 |
{
|
36
|
364 |
INFOQSTR_1("VideoCollectionUiLoader::initObject() name: %S", name);
|
34
|
365 |
VideoCollectionWrapper &wrapper = VideoCollectionWrapper::instance();
|
|
366 |
if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0)
|
|
367 |
{
|
36
|
368 |
VideoListWidget *videoList = qobject_cast<VideoListWidget*>(object);
|
34
|
369 |
if (videoList)
|
|
370 |
{
|
|
371 |
VideoSortFilterProxyModel *model =
|
36
|
372 |
wrapper.getModel(VideoCollectionCommon::EModelTypeAllVideos);
|
34
|
373 |
if(model)
|
|
374 |
{
|
38
|
375 |
VideoCollectionViewUtils::sortModel(model, true, VideoCollectionCommon::ELevelVideos);
|
|
376 |
|
34
|
377 |
// init widget
|
41
|
378 |
videoList->initialize(*model, mIsService, VideoCollectionCommon::ELevelVideos);
|
34
|
379 |
}
|
|
380 |
}
|
|
381 |
}
|
|
382 |
else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
|
|
383 |
{
|
|
384 |
VideoSortFilterProxyModel *model = wrapper.getModel(
|
36
|
385 |
VideoCollectionCommon::EModelTypeCollections);
|
34
|
386 |
if (model)
|
|
387 |
{
|
36
|
388 |
VideoCollectionViewUtils::sortModel(model, true, VideoCollectionCommon::ELevelCategory);
|
38
|
389 |
|
34
|
390 |
// initialize video collection widget
|
|
391 |
VideoListWidget *videoList =
|
36
|
392 |
qobject_cast<VideoListWidget*>(object);
|
34
|
393 |
if (videoList)
|
|
394 |
{
|
|
395 |
// init widget
|
41
|
396 |
videoList->initialize(*model, mIsService, VideoCollectionCommon::ELevelCategory);
|
34
|
397 |
}
|
|
398 |
}
|
|
399 |
}
|
|
400 |
else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
|
|
401 |
{
|
|
402 |
VideoSortFilterProxyModel *model = wrapper.getModel(
|
36
|
403 |
VideoCollectionCommon::EModelTypeCollectionContent);
|
34
|
404 |
if (model)
|
|
405 |
{
|
38
|
406 |
// collection content contains always a list of videos so we use
|
|
407 |
// ELevelVideos as target for sorting
|
|
408 |
VideoCollectionViewUtils::sortModel(model, false, VideoCollectionCommon::ELevelVideos);
|
|
409 |
|
36
|
410 |
VideoListWidget *videoList = qobject_cast<VideoListWidget*>(object);
|
34
|
411 |
if (videoList)
|
|
412 |
{
|
|
413 |
// init widget
|
39
|
414 |
// cannot set level at this point yet: it can be either default or user defined collection
|
41
|
415 |
videoList->initialize(*model, mIsService);
|
34
|
416 |
}
|
|
417 |
}
|
|
418 |
}
|
|
419 |
else if (name.compare(DOCML_NAME_DIALOG) == 0)
|
|
420 |
{
|
|
421 |
// by default, initialize the selection dialog to delete mode
|
|
422 |
VideoListSelectionDialog *dialog =
|
36
|
423 |
qobject_cast<VideoListSelectionDialog*>(object);
|
34
|
424 |
if (dialog)
|
|
425 |
{
|
|
426 |
dialog->setupContent(VideoListSelectionDialog::EDeleteVideos,
|
|
427 |
TMPXItemId::InvalidId());
|
|
428 |
}
|
|
429 |
}
|
|
430 |
else if (name.compare(DOCML_NAME_SORT_MENU) == 0)
|
|
431 |
{
|
36
|
432 |
HbMenu *menu = qobject_cast<HbMenu*>(object);
|
34
|
433 |
if (menu)
|
|
434 |
{
|
|
435 |
// create sort by menu action
|
|
436 |
mMenuActions[EActionSortBy] = menu->menuAction();
|
|
437 |
|
|
438 |
// ensure that all the actions related to sort menu are loaded
|
|
439 |
// when sort menu is loaded
|
|
440 |
findObject<HbAction>(DOCML_NAME_SORT_BY_DATE);
|
|
441 |
findObject<HbAction>(DOCML_NAME_SORT_BY_NAME);
|
|
442 |
findObject<HbAction>(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
|
|
443 |
findObject<HbAction>(DOCML_NAME_SORT_BY_SIZE);
|
|
444 |
|
|
445 |
// add sub menu actions
|
|
446 |
if (!mSortGroup)
|
|
447 |
{
|
|
448 |
mSortGroup = new QActionGroup(menu);
|
|
449 |
mSortGroup->addAction(mMenuActions[EActionSortByDate]);
|
|
450 |
mSortGroup->addAction(mMenuActions[EActionSortByName]);
|
|
451 |
mSortGroup->addAction(mMenuActions[EACtionSortByItemCount]);
|
|
452 |
mSortGroup->addAction(mMenuActions[EActionSortBySize]);
|
|
453 |
|
|
454 |
// set all sub menu items checkable
|
|
455 |
foreach (QAction *action, menu->actions())
|
|
456 |
{
|
|
457 |
action->setCheckable(true);
|
|
458 |
}
|
|
459 |
}
|
|
460 |
}
|
|
461 |
}
|
|
462 |
else if (name.compare(DOCML_NAME_VC_VIDEOHINTWIDGET) == 0)
|
|
463 |
{
|
36
|
464 |
VideoHintWidget *hintWidget = qobject_cast<VideoHintWidget*>(object);
|
34
|
465 |
if (hintWidget)
|
|
466 |
{
|
|
467 |
hintWidget->initialize();
|
|
468 |
}
|
|
469 |
}
|
|
470 |
else if (name.compare(DOCML_NAME_OPTIONS_MENU) == 0)
|
|
471 |
{
|
|
472 |
// ensure that all the actions related to options menu are loaded
|
|
473 |
// when options menu is loaded
|
36
|
474 |
// when applicaton has been launched as a service,
|
|
475 |
// do not load components which are not required
|
|
476 |
if(!mIsService)
|
|
477 |
{
|
|
478 |
findObject<HbAction>(DOCML_NAME_ADD_TO_COLLECTION);
|
|
479 |
findObject<HbAction>(DOCML_NAME_CREATE_COLLECTION);
|
|
480 |
findObject<HbAction>(DOCML_NAME_DELETE_MULTIPLE);
|
|
481 |
}
|
34
|
482 |
}
|
36
|
483 |
else if (name.compare(DOCML_NAME_ADD_TO_COLLECTION) == 0)
|
34
|
484 |
{
|
|
485 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
486 |
if (action)
|
|
487 |
{
|
|
488 |
mMenuActions[EActionAddToCollection] = action;
|
|
489 |
}
|
|
490 |
}
|
|
491 |
else if (name.compare(DOCML_NAME_CREATE_COLLECTION) == 0)
|
|
492 |
{
|
|
493 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
494 |
if (action)
|
|
495 |
{
|
|
496 |
mMenuActions[EActionNewCollection] = action;
|
|
497 |
}
|
|
498 |
}
|
|
499 |
else if (name.compare(DOCML_NAME_DELETE_MULTIPLE) == 0)
|
|
500 |
{
|
|
501 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
502 |
if (action)
|
|
503 |
{
|
|
504 |
mMenuActions[EActionDelete] = action;
|
|
505 |
}
|
|
506 |
}
|
|
507 |
else if (name.compare(DOCML_NAME_SORT_BY_DATE) == 0)
|
|
508 |
{
|
|
509 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
510 |
if (action)
|
|
511 |
{
|
|
512 |
mMenuActions[EActionSortByDate] = action;
|
|
513 |
}
|
|
514 |
}
|
|
515 |
else if (name.compare(DOCML_NAME_SORT_BY_NAME) == 0)
|
|
516 |
{
|
|
517 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
518 |
if (action)
|
|
519 |
{
|
|
520 |
mMenuActions[EActionSortByName] = action;
|
|
521 |
}
|
|
522 |
}
|
|
523 |
else if (name.compare(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS) == 0)
|
|
524 |
{
|
|
525 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
526 |
if (action)
|
|
527 |
{
|
|
528 |
mMenuActions[EACtionSortByItemCount] = action;
|
|
529 |
}
|
|
530 |
}
|
|
531 |
else if (name.compare(DOCML_NAME_SORT_BY_SIZE) == 0)
|
|
532 |
{
|
|
533 |
HbAction *action = qobject_cast<HbAction*>(object);
|
|
534 |
if (action)
|
|
535 |
{
|
|
536 |
mMenuActions[EActionSortBySize] = action;
|
|
537 |
}
|
|
538 |
}
|
|
539 |
}
|
|
540 |
}
|
|
541 |
|
|
542 |
// ---------------------------------------------------------------------------
|
36
|
543 |
// executeRequest
|
|
544 |
// ---------------------------------------------------------------------------
|
|
545 |
//
|
|
546 |
QObject* VideoCollectionUiLoader::executeRequest(
|
|
547 |
const VideoCollectionUiLoaderParam ¶m)
|
|
548 |
{
|
|
549 |
FUNC_LOG;
|
|
550 |
QObject *object = getObject(param);
|
|
551 |
if (!object)
|
|
552 |
{
|
|
553 |
// object was not found, try preparing docml and section
|
|
554 |
bool ok = prepareDocmlAndSection(param.mDocml, param.mSection);
|
|
555 |
if (ok)
|
|
556 |
{
|
|
557 |
// try to get the object again
|
|
558 |
object = getObject(param);
|
|
559 |
}
|
|
560 |
}
|
|
561 |
|
|
562 |
// initialize object if it was found from docml
|
|
563 |
if (object)
|
|
564 |
{
|
|
565 |
if (!mObjects.contains(param.mName))
|
|
566 |
{
|
|
567 |
// initialize object
|
|
568 |
initObject(object, param.mName);
|
|
569 |
|
|
570 |
// insert object in hash table
|
|
571 |
mObjects.insert(param.mName, object);
|
|
572 |
}
|
|
573 |
|
|
574 |
bool ok = connect(
|
|
575 |
this, SIGNAL(objectReady(QObject*, const QString&)),
|
|
576 |
param.mReceiver, param.mMember);
|
|
577 |
if (ok)
|
|
578 |
{
|
|
579 |
// signal client and disconnect
|
|
580 |
emit objectReady(object, param.mName);
|
|
581 |
disconnect(
|
|
582 |
this, SIGNAL(objectReady(QObject*, const QString&)),
|
|
583 |
param.mReceiver, param.mMember);
|
|
584 |
}
|
|
585 |
}
|
|
586 |
|
|
587 |
return object;
|
|
588 |
}
|
|
589 |
|
|
590 |
// ---------------------------------------------------------------------------
|
|
591 |
// indexInQueue
|
|
592 |
// ---------------------------------------------------------------------------
|
|
593 |
//
|
|
594 |
int VideoCollectionUiLoader::indexInQueue(const QString &name)
|
|
595 |
{
|
|
596 |
FUNC_LOG;
|
|
597 |
int index = -1;
|
|
598 |
|
|
599 |
int count = mQueue.count();
|
|
600 |
for (int i = 0; i < count; i++)
|
|
601 |
{
|
|
602 |
const VideoCollectionUiLoaderParam ¶m = mQueue.at(i);
|
|
603 |
if (param.mName == name)
|
|
604 |
{
|
|
605 |
// found from queue
|
|
606 |
index = i;
|
|
607 |
break;
|
|
608 |
}
|
|
609 |
}
|
|
610 |
|
|
611 |
return index;
|
|
612 |
}
|
|
613 |
|
|
614 |
// ---------------------------------------------------------------------------
|
|
615 |
// removeFromQueue
|
|
616 |
// ---------------------------------------------------------------------------
|
|
617 |
//
|
|
618 |
void VideoCollectionUiLoader::removeFromQueue(const QString &name)
|
|
619 |
{
|
|
620 |
FUNC_LOG;
|
|
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 |
mQueue.removeAt(i);
|
|
628 |
break;
|
|
629 |
}
|
|
630 |
}
|
|
631 |
}
|
|
632 |
|
|
633 |
// ---------------------------------------------------------------------------
|
34
|
634 |
// timerEvent
|
|
635 |
// ---------------------------------------------------------------------------
|
|
636 |
//
|
|
637 |
void VideoCollectionUiLoader::timerEvent(QTimerEvent *event)
|
30
|
638 |
{
|
36
|
639 |
FUNC_LOG;
|
34
|
640 |
if (event)
|
|
641 |
{
|
|
642 |
if (event->timerId() == mTimerId)
|
|
643 |
{
|
36
|
644 |
// get current request from queue and execute it
|
|
645 |
int count = mQueue.count();
|
|
646 |
for (int i = 0; i < count; i++)
|
34
|
647 |
{
|
36
|
648 |
const VideoCollectionUiLoaderParam ¶m = mQueue.at(i);
|
|
649 |
if (mPhases.contains(param.mPhase))
|
34
|
650 |
{
|
36
|
651 |
// load and initialize
|
|
652 |
executeRequest(param);
|
|
653 |
|
|
654 |
// remove the current request from queue and run next
|
|
655 |
removeFromQueue(param.mName);
|
|
656 |
break;
|
34
|
657 |
}
|
|
658 |
}
|
36
|
659 |
runNext();
|
34
|
660 |
}
|
|
661 |
}
|
30
|
662 |
}
|
|
663 |
|
|
664 |
// ---------------------------------------------------------------------------
|
|
665 |
// createObject
|
|
666 |
// ---------------------------------------------------------------------------
|
|
667 |
//
|
|
668 |
QObject* VideoCollectionUiLoader::createObject( const QString& type, const QString &name )
|
|
669 |
{
|
36
|
670 |
FUNC_LOG;
|
30
|
671 |
QObject* object = 0;
|
|
672 |
|
|
673 |
if ( type == VideoListView::staticMetaObject.className() )
|
|
674 |
{
|
|
675 |
object = new VideoListView(this);
|
|
676 |
}
|
|
677 |
else if ( type == VideoListSelectionDialog::staticMetaObject.className() )
|
|
678 |
{
|
|
679 |
object = new VideoListSelectionDialog(this);
|
|
680 |
}
|
|
681 |
else if ( type == VideoListWidget::staticMetaObject.className() )
|
|
682 |
{
|
34
|
683 |
object = new VideoListWidget(this);
|
30
|
684 |
}
|
|
685 |
else if ( type == VideoHintWidget::staticMetaObject.className() )
|
|
686 |
{
|
|
687 |
object = new VideoHintWidget(this);
|
|
688 |
}
|
|
689 |
if ( object )
|
|
690 |
{
|
|
691 |
object->setObjectName( name );
|
|
692 |
return object;
|
|
693 |
}
|
|
694 |
|
|
695 |
return HbDocumentLoader::createObject( type, name );
|
|
696 |
}
|
34
|
697 |
|
|
698 |
// ---------------------------------------------------------------------------
|
|
699 |
// runNext
|
|
700 |
// ---------------------------------------------------------------------------
|
|
701 |
//
|
|
702 |
void VideoCollectionUiLoader::runNext()
|
|
703 |
{
|
36
|
704 |
FUNC_LOG;
|
|
705 |
bool runNext = false;
|
|
706 |
int count = mQueue.count();
|
|
707 |
for (int i = 0; i < count; i++)
|
|
708 |
{
|
|
709 |
const VideoCollectionUiLoaderParam ¶m = mQueue.at(i);
|
|
710 |
if (mPhases.contains(param.mPhase))
|
|
711 |
{
|
|
712 |
runNext = true;
|
|
713 |
break;
|
|
714 |
}
|
|
715 |
}
|
|
716 |
|
|
717 |
if (runNext)
|
34
|
718 |
{
|
|
719 |
if (!mTimerId)
|
|
720 |
{
|
|
721 |
// timer not running, start it
|
|
722 |
mTimerId = startTimer(ASYNC_FIND_TIMEOUT);
|
|
723 |
}
|
|
724 |
}
|
|
725 |
else
|
|
726 |
{
|
|
727 |
// no new requests, kill timer
|
|
728 |
if (mTimerId)
|
|
729 |
{
|
|
730 |
killTimer(mTimerId);
|
|
731 |
mTimerId = 0;
|
|
732 |
}
|
|
733 |
}
|
|
734 |
}
|
|
735 |
|
|
736 |
// ---------------------------------------------------------------------------
|
|
737 |
// isValid
|
|
738 |
// ---------------------------------------------------------------------------
|
|
739 |
//
|
36
|
740 |
bool VideoCollectionUiLoader::isValid(const VideoCollectionUiLoaderParam ¶m)
|
34
|
741 |
{
|
|
742 |
bool valid = true;
|
|
743 |
|
36
|
744 |
if (param.mName.length() &&
|
|
745 |
param.mDocml &&
|
|
746 |
param.mMember &&
|
|
747 |
param.mReceiver)
|
34
|
748 |
{
|
|
749 |
// check if the param is already in the queue
|
|
750 |
int count = mQueue.count();
|
|
751 |
for (int i = 0; i < count; i++)
|
|
752 |
{
|
36
|
753 |
if (mQueue.at(i) == param)
|
34
|
754 |
{
|
36
|
755 |
INFO("VideoCollectionUiLoader::isValid() already in queue.");
|
34
|
756 |
valid = false;
|
|
757 |
break;
|
|
758 |
}
|
|
759 |
}
|
|
760 |
|
|
761 |
// check that the item has not already been loaded
|
|
762 |
if (valid)
|
|
763 |
{
|
36
|
764 |
valid = !mObjects.contains(param.mName);
|
34
|
765 |
}
|
|
766 |
}
|
|
767 |
else
|
|
768 |
{
|
36
|
769 |
INFO("VideoCollectionUiLoader::isValid() params missing.");
|
34
|
770 |
valid = false;
|
|
771 |
}
|
|
772 |
|
|
773 |
return valid;
|
|
774 |
}
|
36
|
775 |
|
|
776 |
// ---------------------------------------------------------------------------
|
|
777 |
// storeOrphans
|
|
778 |
// ---------------------------------------------------------------------------
|
|
779 |
//
|
|
780 |
void VideoCollectionUiLoader::storeOrphans(const QObjectList &list)
|
|
781 |
{
|
|
782 |
FUNC_LOG;
|
|
783 |
foreach (QObject *object, list)
|
|
784 |
{
|
|
785 |
if (!mOrphans.contains(object))
|
|
786 |
{
|
|
787 |
// add to list
|
|
788 |
mOrphans.append(object);
|
|
789 |
|
|
790 |
// connect to "destroyed" signal
|
|
791 |
connect(
|
|
792 |
object, SIGNAL(destroyed(QObject*)),
|
|
793 |
this, SLOT(removeOrphanFromList(QObject*)));
|
|
794 |
}
|
|
795 |
}
|
|
796 |
}
|
|
797 |
|
|
798 |
// end of file
|
|
799 |
|