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