videocollection/tsrc/stubs/src/videocollectionuiloader.cpp
author hgs
Tue, 05 Oct 2010 09:26:49 +0300
changeset 66 adb51f74b890
parent 63 4707a0db12f6
child 67 72c709219fcd
permissions -rw-r--r--
201039
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34
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
35
hgs
parents: 34
diff changeset
    18
#include <qdebug.h>
34
hgs
parents:
diff changeset
    19
#include <qset.h>
hgs
parents:
diff changeset
    20
#include <qstring.h>
hgs
parents:
diff changeset
    21
#include <hblistview.h>
35
hgs
parents: 34
diff changeset
    22
#include <hbmenu.h>
34
hgs
parents:
diff changeset
    23
36
hgs
parents: 35
diff changeset
    24
#include "videocollectioncommon.h"
34
hgs
parents:
diff changeset
    25
#include "videocollectionuiloader.h"
36
hgs
parents: 35
diff changeset
    26
#include "videocollectionuiloaderdef.h"
34
hgs
parents:
diff changeset
    27
#include "videolistview.h"
hgs
parents:
diff changeset
    28
#include "videolistwidget.h"
hgs
parents:
diff changeset
    29
#include "videolistselectiondialog.h"
36
hgs
parents: 35
diff changeset
    30
#include "videocollectionwrapper.h"
34
hgs
parents:
diff changeset
    31
hgs
parents:
diff changeset
    32
#include "videocollectionuiloaderdata.h"
hgs
parents:
diff changeset
    33
hgs
parents:
diff changeset
    34
bool VideoCollectionUiLoaderData::mFindFailure = false;
hgs
parents:
diff changeset
    35
bool VideoCollectionUiLoaderData::mFailDialogLoad = false;
hgs
parents:
diff changeset
    36
QStringList VideoCollectionUiLoaderData::mFindFailureNameList;
36
hgs
parents: 35
diff changeset
    37
QMap<VideoCollectionUiLoader::ActionIds, HbAction*> VideoCollectionUiLoaderData::mMenuActions;
hgs
parents: 35
diff changeset
    38
int VideoCollectionUiLoaderData::mLastLoadPhasedData = -1;
63
hgs
parents: 58
diff changeset
    39
int VideoCollectionUiLoaderData::mAddDataCallCount = 0;
34
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
VideoCollectionUiLoader::VideoCollectionUiLoader():
hgs
parents:
diff changeset
    42
    HbDocumentLoader(),
36
hgs
parents: 35
diff changeset
    43
    mTimerId(0),
63
hgs
parents: 58
diff changeset
    44
    mSortGroup(0),
36
hgs
parents: 35
diff changeset
    45
    mIsService(0)
34
hgs
parents:
diff changeset
    46
{
hgs
parents:
diff changeset
    47
    // not stubbed
hgs
parents:
diff changeset
    48
}
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
VideoCollectionUiLoader::~VideoCollectionUiLoader()
hgs
parents:
diff changeset
    51
{
hgs
parents:
diff changeset
    52
    VideoCollectionUiLoaderData::reset();
hgs
parents:
diff changeset
    53
}
hgs
parents:
diff changeset
    54
36
hgs
parents: 35
diff changeset
    55
void VideoCollectionUiLoader::loadPhase(int loadPhase)
hgs
parents: 35
diff changeset
    56
{
hgs
parents: 35
diff changeset
    57
    VideoCollectionUiLoaderData::mLastLoadPhasedData = loadPhase;
hgs
parents: 35
diff changeset
    58
}
hgs
parents: 35
diff changeset
    59
hgs
parents: 35
diff changeset
    60
void VideoCollectionUiLoader::addData(QList<VideoCollectionUiLoaderParam> params,
34
hgs
parents:
diff changeset
    61
    QObject *receiver,
36
hgs
parents: 35
diff changeset
    62
    const char *slot)
34
hgs
parents:
diff changeset
    63
{
63
hgs
parents: 58
diff changeset
    64
    VideoCollectionUiLoaderData::mAddDataCallCount++;
36
hgs
parents: 35
diff changeset
    65
    Q_UNUSED(params);
34
hgs
parents:
diff changeset
    66
    Q_UNUSED(receiver);
36
hgs
parents: 35
diff changeset
    67
    Q_UNUSED(slot);
hgs
parents: 35
diff changeset
    68
}
hgs
parents: 35
diff changeset
    69
hgs
parents: 35
diff changeset
    70
void VideoCollectionUiLoader::removeOrphanFromList(QObject *object)
hgs
parents: 35
diff changeset
    71
{
hgs
parents: 35
diff changeset
    72
    if (mOrphans.contains(object))
hgs
parents: 35
diff changeset
    73
    {
hgs
parents: 35
diff changeset
    74
        mOrphans.removeOne(object);
hgs
parents: 35
diff changeset
    75
    }
hgs
parents: 35
diff changeset
    76
hgs
parents: 35
diff changeset
    77
    const QString &name = mObjects.key(object);
hgs
parents: 35
diff changeset
    78
    if (!name.isEmpty())
hgs
parents: 35
diff changeset
    79
    {
hgs
parents: 35
diff changeset
    80
        // found from list, remove
hgs
parents: 35
diff changeset
    81
        mObjects.remove(name);
hgs
parents: 35
diff changeset
    82
    }
34
hgs
parents:
diff changeset
    83
}
hgs
parents:
diff changeset
    84
hgs
parents:
diff changeset
    85
void VideoCollectionUiLoader::setIsService(bool isService)
hgs
parents:
diff changeset
    86
{
36
hgs
parents: 35
diff changeset
    87
    mIsService = isService;
hgs
parents: 35
diff changeset
    88
}
hgs
parents: 35
diff changeset
    89
hgs
parents: 35
diff changeset
    90
void VideoCollectionUiLoader::load(const QString &fileName, bool *ok)
hgs
parents: 35
diff changeset
    91
{
hgs
parents: 35
diff changeset
    92
    QObjectList list = HbDocumentLoader::load(fileName, ok);
hgs
parents: 35
diff changeset
    93
    storeOrphans(list);
hgs
parents: 35
diff changeset
    94
}
hgs
parents: 35
diff changeset
    95
hgs
parents: 35
diff changeset
    96
void VideoCollectionUiLoader::load(const QString &fileName, const QString &section , bool *ok)
hgs
parents: 35
diff changeset
    97
{
hgs
parents: 35
diff changeset
    98
    QObjectList list = HbDocumentLoader::load(fileName, section, ok);
hgs
parents: 35
diff changeset
    99
    storeOrphans(list);
34
hgs
parents:
diff changeset
   100
}
hgs
parents:
diff changeset
   101
38
hgs
parents: 36
diff changeset
   102
QGraphicsWidget* VideoCollectionUiLoader::doFindWidget(const QString &name, bool loadIfNotFound)
34
hgs
parents:
diff changeset
   103
{
38
hgs
parents: 36
diff changeset
   104
    Q_UNUSED(loadIfNotFound);
34
hgs
parents:
diff changeset
   105
    QGraphicsWidget *widget = 0;
35
hgs
parents: 34
diff changeset
   106
    if(VideoCollectionUiLoaderData::mFindFailure)
hgs
parents: 34
diff changeset
   107
    {
hgs
parents: 34
diff changeset
   108
        return 0; 
hgs
parents: 34
diff changeset
   109
    }
hgs
parents: 34
diff changeset
   110
    if(!VideoCollectionUiLoaderData::mFindFailureNameList.contains(name))
hgs
parents: 34
diff changeset
   111
    {
hgs
parents: 34
diff changeset
   112
        widget = HbDocumentLoader::findWidget(name);
hgs
parents: 34
diff changeset
   113
    }
34
hgs
parents:
diff changeset
   114
    return widget;
hgs
parents:
diff changeset
   115
}
hgs
parents:
diff changeset
   116
38
hgs
parents: 36
diff changeset
   117
QObject* VideoCollectionUiLoader::doFindObject(const QString &name, bool loadIfNotFound)
34
hgs
parents:
diff changeset
   118
{
38
hgs
parents: 36
diff changeset
   119
    Q_UNUSED(loadIfNotFound);
34
hgs
parents:
diff changeset
   120
    QObject *object = 0;
35
hgs
parents: 34
diff changeset
   121
    if(VideoCollectionUiLoaderData::mFindFailure)
hgs
parents: 34
diff changeset
   122
    {
hgs
parents: 34
diff changeset
   123
        return 0; 
hgs
parents: 34
diff changeset
   124
    }
hgs
parents: 34
diff changeset
   125
    if(!VideoCollectionUiLoaderData::mFindFailureNameList.contains(name))
hgs
parents: 34
diff changeset
   126
    {
hgs
parents: 34
diff changeset
   127
        object = HbDocumentLoader::findObject(name);
hgs
parents: 34
diff changeset
   128
    }
34
hgs
parents:
diff changeset
   129
    return object;
hgs
parents:
diff changeset
   130
}
hgs
parents:
diff changeset
   131
hgs
parents:
diff changeset
   132
void VideoCollectionUiLoader::initObject(QObject *object,
hgs
parents:
diff changeset
   133
    const QString &name)
hgs
parents:
diff changeset
   134
{
36
hgs
parents: 35
diff changeset
   135
    VideoCollectionWrapper &wrapper = VideoCollectionWrapper::instance();
hgs
parents: 35
diff changeset
   136
    
hgs
parents: 35
diff changeset
   137
    if (name == DOCML_NAME_VC_VIDEOLISTWIDGET ||
hgs
parents: 35
diff changeset
   138
        name == DOCML_NAME_VC_COLLECTIONWIDGET ||
hgs
parents: 35
diff changeset
   139
        name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET)
hgs
parents: 35
diff changeset
   140
    {
58
hgs
parents: 41
diff changeset
   141
        VideoProxyModelGeneric *model(0);
hgs
parents: 41
diff changeset
   142
        
36
hgs
parents: 35
diff changeset
   143
        if(name == DOCML_NAME_VC_COLLECTIONWIDGET) {
58
hgs
parents: 41
diff changeset
   144
            model = wrapper.getCollectionsModel();
36
hgs
parents: 35
diff changeset
   145
        } else if (name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) {
58
hgs
parents: 41
diff changeset
   146
            model = wrapper.getCollectionContentModel();
hgs
parents: 41
diff changeset
   147
        } else
hgs
parents: 41
diff changeset
   148
        {
hgs
parents: 41
diff changeset
   149
            model = wrapper.getAllVideosModel();
36
hgs
parents: 35
diff changeset
   150
        }
hgs
parents: 35
diff changeset
   151
        VideoListWidget *videoList = qobject_cast<VideoListWidget*>(object);
41
hgs
parents: 38
diff changeset
   152
        
hgs
parents: 38
diff changeset
   153
        VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelInvalid;
hgs
parents: 38
diff changeset
   154
        if(name == DOCML_NAME_VC_VIDEOLISTWIDGET )
hgs
parents: 38
diff changeset
   155
        {
hgs
parents: 38
diff changeset
   156
            level = VideoCollectionCommon::ELevelVideos;
hgs
parents: 38
diff changeset
   157
        }
hgs
parents: 38
diff changeset
   158
        else if(name == DOCML_NAME_VC_COLLECTIONWIDGET)
hgs
parents: 38
diff changeset
   159
        {
hgs
parents: 38
diff changeset
   160
            level = VideoCollectionCommon::ELevelCategory;
hgs
parents: 38
diff changeset
   161
        }
hgs
parents: 38
diff changeset
   162
        videoList->initialize(*model, 0, level);
36
hgs
parents: 35
diff changeset
   163
    }
hgs
parents: 35
diff changeset
   164
    else if (name == DOCML_NAME_DIALOG)
hgs
parents: 35
diff changeset
   165
    {
hgs
parents: 35
diff changeset
   166
hgs
parents: 35
diff changeset
   167
    }
hgs
parents: 35
diff changeset
   168
    else if (name == DOCML_NAME_OPTIONS_MENU)
hgs
parents: 35
diff changeset
   169
    {
hgs
parents: 35
diff changeset
   170
hgs
parents: 35
diff changeset
   171
    }
hgs
parents: 35
diff changeset
   172
    else if (name == DOCML_NAME_SORT_MENU)
hgs
parents: 35
diff changeset
   173
    {
hgs
parents: 35
diff changeset
   174
        VideoCollectionUiLoaderData::mMenuActions[EActionSortBy] = qobject_cast<HbAction*>(object);
hgs
parents: 35
diff changeset
   175
    }
hgs
parents: 35
diff changeset
   176
    else if(name == DOCML_NAME_ADD_TO_COLLECTION)
hgs
parents: 35
diff changeset
   177
    {
hgs
parents: 35
diff changeset
   178
        VideoCollectionUiLoaderData::mMenuActions[EActionAddToCollection] = qobject_cast<HbAction*>(object);
hgs
parents: 35
diff changeset
   179
    }
hgs
parents: 35
diff changeset
   180
    else if(name == DOCML_NAME_CREATE_COLLECTION)
hgs
parents: 35
diff changeset
   181
    {
hgs
parents: 35
diff changeset
   182
        VideoCollectionUiLoaderData::mMenuActions[EActionNewCollection] = qobject_cast<HbAction*>(object);
hgs
parents: 35
diff changeset
   183
    }
hgs
parents: 35
diff changeset
   184
    else if(name == DOCML_NAME_DELETE_MULTIPLE)
hgs
parents: 35
diff changeset
   185
    {
hgs
parents: 35
diff changeset
   186
        VideoCollectionUiLoaderData::mMenuActions[EActionDelete] = qobject_cast<HbAction*>(object);
hgs
parents: 35
diff changeset
   187
    }
hgs
parents: 35
diff changeset
   188
    else if(name == DOCML_NAME_SORT_BY_DATE)
hgs
parents: 35
diff changeset
   189
    {
hgs
parents: 35
diff changeset
   190
        VideoCollectionUiLoaderData::mMenuActions[EActionSortByDate] = qobject_cast<HbAction*>(object);
63
hgs
parents: 58
diff changeset
   191
        VideoCollectionUiLoaderData::mMenuActions[EActionSortByDate]->setCheckable(true);
36
hgs
parents: 35
diff changeset
   192
    }
hgs
parents: 35
diff changeset
   193
    else if(name == DOCML_NAME_SORT_BY_NAME)
hgs
parents: 35
diff changeset
   194
    {
hgs
parents: 35
diff changeset
   195
        VideoCollectionUiLoaderData::mMenuActions[EActionSortByName] = qobject_cast<HbAction*>(object);
63
hgs
parents: 58
diff changeset
   196
        VideoCollectionUiLoaderData::mMenuActions[EActionSortByName]->setCheckable(true);
36
hgs
parents: 35
diff changeset
   197
    }
hgs
parents: 35
diff changeset
   198
    else if(name == DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS)
hgs
parents: 35
diff changeset
   199
    {
hgs
parents: 35
diff changeset
   200
        VideoCollectionUiLoaderData::mMenuActions[EACtionSortByItemCount] = qobject_cast<HbAction*>(object);
63
hgs
parents: 58
diff changeset
   201
        VideoCollectionUiLoaderData::mMenuActions[EACtionSortByItemCount]->setCheckable(true);
36
hgs
parents: 35
diff changeset
   202
    }
hgs
parents: 35
diff changeset
   203
    else if(name == DOCML_NAME_SORT_BY_SIZE)
hgs
parents: 35
diff changeset
   204
    {
hgs
parents: 35
diff changeset
   205
        VideoCollectionUiLoaderData::mMenuActions[EActionSortBySize] = qobject_cast<HbAction*>(object);
63
hgs
parents: 58
diff changeset
   206
        VideoCollectionUiLoaderData::mMenuActions[EActionSortBySize]->setCheckable(true);
36
hgs
parents: 35
diff changeset
   207
    }
34
hgs
parents:
diff changeset
   208
}
hgs
parents:
diff changeset
   209
hgs
parents:
diff changeset
   210
void VideoCollectionUiLoader::timerEvent(QTimerEvent *event)
hgs
parents:
diff changeset
   211
{
hgs
parents:
diff changeset
   212
    Q_UNUSED(event);
hgs
parents:
diff changeset
   213
    // not stubbed
hgs
parents:
diff changeset
   214
}
hgs
parents:
diff changeset
   215
hgs
parents:
diff changeset
   216
QObject* VideoCollectionUiLoader::createObject(const QString& type,
hgs
parents:
diff changeset
   217
    const QString &name)
hgs
parents:
diff changeset
   218
{
38
hgs
parents: 36
diff changeset
   219
    QObject* object = doFindObject(name, true);
34
hgs
parents:
diff changeset
   220
    if (!object)
hgs
parents:
diff changeset
   221
    {
35
hgs
parents: 34
diff changeset
   222
        if (name == DOCML_NAME_VIEW)
34
hgs
parents:
diff changeset
   223
        {
hgs
parents:
diff changeset
   224
            object = new VideoListView(this);
hgs
parents:
diff changeset
   225
        }
35
hgs
parents: 34
diff changeset
   226
        else if (name == DOCML_NAME_VC_COLLECTIONWIDGET ||
hgs
parents: 34
diff changeset
   227
                 name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET ||
hgs
parents: 34
diff changeset
   228
                 name == DOCML_NAME_VC_VIDEOLISTWIDGET)
34
hgs
parents:
diff changeset
   229
        {
hgs
parents:
diff changeset
   230
            object = new VideoListWidget(this);
36
hgs
parents: 35
diff changeset
   231
            initObject(qobject_cast<QGraphicsWidget*>(object), name);
34
hgs
parents:
diff changeset
   232
        }
35
hgs
parents: 34
diff changeset
   233
        else if (name == DOCML_NAME_DIALOG)
34
hgs
parents:
diff changeset
   234
        {
hgs
parents:
diff changeset
   235
            if(!VideoCollectionUiLoaderData::mFailDialogLoad)
hgs
parents:
diff changeset
   236
            {
hgs
parents:
diff changeset
   237
                object = new VideoListSelectionDialog(this);
hgs
parents:
diff changeset
   238
            }
hgs
parents:
diff changeset
   239
            else
hgs
parents:
diff changeset
   240
            {
hgs
parents:
diff changeset
   241
                return 0;
hgs
parents:
diff changeset
   242
            }
hgs
parents:
diff changeset
   243
        }
hgs
parents:
diff changeset
   244
        if (object)
hgs
parents:
diff changeset
   245
        {
hgs
parents:
diff changeset
   246
            object->setObjectName(name);
hgs
parents:
diff changeset
   247
            return object;
hgs
parents:
diff changeset
   248
        }
hgs
parents:
diff changeset
   249
        object = HbDocumentLoader::createObject(type, name);
36
hgs
parents: 35
diff changeset
   250
        initObject(object, name);
34
hgs
parents:
diff changeset
   251
    }
hgs
parents:
diff changeset
   252
    
hgs
parents:
diff changeset
   253
    return object;
hgs
parents:
diff changeset
   254
}
hgs
parents:
diff changeset
   255
hgs
parents:
diff changeset
   256
void VideoCollectionUiLoader::runNext()
hgs
parents:
diff changeset
   257
{
hgs
parents:
diff changeset
   258
    // not stubbed
hgs
parents:
diff changeset
   259
}
hgs
parents:
diff changeset
   260
36
hgs
parents: 35
diff changeset
   261
bool VideoCollectionUiLoader::isValid(const VideoCollectionUiLoaderParam &param)
34
hgs
parents:
diff changeset
   262
{
36
hgs
parents: 35
diff changeset
   263
    Q_UNUSED(param);
34
hgs
parents:
diff changeset
   264
    // not stubbed
hgs
parents:
diff changeset
   265
    return true;
hgs
parents:
diff changeset
   266
}
36
hgs
parents: 35
diff changeset
   267
hgs
parents: 35
diff changeset
   268
// ---------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   269
// storeOrphans
hgs
parents: 35
diff changeset
   270
// ---------------------------------------------------------------------------
hgs
parents: 35
diff changeset
   271
//
hgs
parents: 35
diff changeset
   272
void VideoCollectionUiLoader::storeOrphans(const QObjectList &list)
hgs
parents: 35
diff changeset
   273
{
hgs
parents: 35
diff changeset
   274
    foreach (QObject *object, list)
hgs
parents: 35
diff changeset
   275
    {
hgs
parents: 35
diff changeset
   276
        if (!mOrphans.contains(object))
hgs
parents: 35
diff changeset
   277
        {
hgs
parents: 35
diff changeset
   278
            // add to list
hgs
parents: 35
diff changeset
   279
            mOrphans.append(object);
hgs
parents: 35
diff changeset
   280
            
hgs
parents: 35
diff changeset
   281
            // connect to "destroyed" signal
hgs
parents: 35
diff changeset
   282
            connect(
hgs
parents: 35
diff changeset
   283
                object, SIGNAL(destroyed(QObject*)),
hgs
parents: 35
diff changeset
   284
                this, SLOT(removeOrphanFromList(QObject*)));
hgs
parents: 35
diff changeset
   285
        }
hgs
parents: 35
diff changeset
   286
    }
hgs
parents: 35
diff changeset
   287
}
hgs
parents: 35
diff changeset
   288
hgs
parents: 35
diff changeset
   289
// end of file