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