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