videocollection/tsrc/stubs/src/hbdocumentloader.cpp
branchRCL_3
changeset 56 839377eedc2b
equal deleted inserted replaced
54:315810614048 56:839377eedc2b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "hbdocumentloader.h"
       
    19 #include "hbmainwindow.h"
       
    20 #include "hbmenu.h"
       
    21 #include "hbview.h"
       
    22 #include "hbstackedwidget.h"
       
    23 #include "hblabel.h"
       
    24 #include "hbwidget.h"
       
    25 #include "hbcheckbox.h"
       
    26 #include "hbpushbutton.h"
       
    27 #include "hblabel.h"
       
    28 #include "hbgroupbox.h"
       
    29 #include "videocollectionuiloader.h"
       
    30 #include "videocollectionuiloaderdef.h"
       
    31 #include "videolistwidget.h"
       
    32 #include "videolistview.h"
       
    33 #include "videohintwidget.h"
       
    34 #include "videolistselectiondialog.h"
       
    35 
       
    36 bool HbDocumentLoader::mFindWidgetFails = false;
       
    37 bool HbDocumentLoader::mFindObjectFails = false;
       
    38 bool HbDocumentLoader::mCreateObjectFails = false;
       
    39 bool HbDocumentLoader::mVideoListWidgetFailure = false;
       
    40 bool HbDocumentLoader::mCollectionWidgetFailure = false;
       
    41 bool HbDocumentLoader::mCollectionContentWidgetFailure = false;
       
    42 bool HbDocumentLoader::mLoadFails = false;
       
    43 QObjectList HbDocumentLoader::mLoadReturns;
       
    44 
       
    45 void HbDocumentLoader::cleanup() {
       
    46     mFindWidgetFails = false;
       
    47     mFindObjectFails = false;
       
    48     mCreateObjectFails = false;
       
    49     mVideoListWidgetFailure = false;
       
    50     mCollectionWidgetFailure = false;
       
    51     mCollectionContentWidgetFailure = false;
       
    52     mLoadFails = false;
       
    53     mLoadReturns.clear();
       
    54 }
       
    55 
       
    56 HbDocumentLoader::HbDocumentLoader() : mCreatingObject(false)
       
    57 {
       
    58 
       
    59 }
       
    60 
       
    61 HbDocumentLoader::HbDocumentLoader(const HbMainWindow *window) : mCreatingObject(false)
       
    62 {
       
    63     Q_UNUSED(window);
       
    64     // Not stubbed.
       
    65 }
       
    66 
       
    67 HbDocumentLoader::~HbDocumentLoader()
       
    68 {
       
    69     cleanup();
       
    70     reset();
       
    71 }
       
    72 
       
    73 QObjectList HbDocumentLoader::load( const QString &fileName, const QString &section , bool *ok)
       
    74 {
       
    75     Q_UNUSED(fileName);
       
    76     Q_UNUSED(section);
       
    77 
       
    78     *ok = true;
       
    79     if(mLoadFails)
       
    80     {
       
    81         *ok = false;
       
    82     }
       
    83     
       
    84     return mLoadReturns;
       
    85 }
       
    86 
       
    87 QObjectList HbDocumentLoader::load( const QString &fileName, bool *ok)
       
    88 {
       
    89     Q_UNUSED(fileName);
       
    90     Q_UNUSED(ok);
       
    91 
       
    92     *ok = true;
       
    93     if(mLoadFails)
       
    94     {
       
    95         *ok = false;
       
    96     }
       
    97     
       
    98     return mLoadReturns;
       
    99 }
       
   100     
       
   101 QGraphicsWidget *HbDocumentLoader::findWidget(const QString &name)
       
   102 {   
       
   103     if(mFindWidgetFails)
       
   104     {
       
   105         return 0;
       
   106     }
       
   107     
       
   108     if(mVideoListWidgetFailure && name == DOCML_NAME_VC_VIDEOLISTWIDGET)
       
   109     {
       
   110         return 0;
       
   111     }
       
   112     
       
   113     if(mCollectionWidgetFailure && name == DOCML_NAME_VC_COLLECTIONWIDGET)
       
   114     {
       
   115         return 0;
       
   116     }
       
   117     
       
   118     if(mCollectionContentWidgetFailure && name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET)
       
   119     {
       
   120         return 0;
       
   121     }
       
   122 
       
   123     QObject *obj = 0;
       
   124     
       
   125     for(int i = 0; i < mObjects.count(); i++)
       
   126     {
       
   127         if(mObjects[i]->mName == name)
       
   128         {
       
   129             obj = mObjects[i]->mObject;
       
   130             break;
       
   131         }
       
   132     }
       
   133     
       
   134     if(!obj && !mCreatingObject)
       
   135     {
       
   136         mCreatingObject = true;
       
   137         obj = createObject(QString(), name);
       
   138         if(obj)
       
   139         {   
       
   140             mObjects.append(new ObjectData(obj, name));
       
   141         }
       
   142         mCreatingObject = false;
       
   143     }
       
   144     
       
   145     if(obj)
       
   146     {
       
   147         return qobject_cast<QGraphicsWidget *>(obj);
       
   148     }
       
   149     
       
   150     return 0;
       
   151 }
       
   152 
       
   153 QObject *HbDocumentLoader::findObject(const QString &name)
       
   154 {
       
   155     if(mFindObjectFails)
       
   156     {
       
   157         return 0;
       
   158     }
       
   159     
       
   160     QObject *obj = 0;
       
   161     for(int i = 0; i < mObjects.count(); i++)
       
   162     {
       
   163         if(mObjects[i]->mName == name)
       
   164         {
       
   165             obj = mObjects[i]->mObject;
       
   166             break;
       
   167         }
       
   168     }
       
   169 
       
   170     if(!obj && !mCreatingObject)
       
   171     {
       
   172         mCreatingObject = true;
       
   173         obj = createObject(QString(), name);
       
   174         if(obj)
       
   175         {   
       
   176             mObjects.append(new ObjectData(obj, name));
       
   177         }
       
   178         mCreatingObject = false;
       
   179     }    
       
   180     
       
   181     return obj;
       
   182 }
       
   183 
       
   184 void HbDocumentLoader::reset()
       
   185 {
       
   186     while(!mObjects.isEmpty())
       
   187     {
       
   188         ObjectData *o = mObjects.takeFirst();
       
   189         delete o;
       
   190     }
       
   191     mObjects.clear();
       
   192 }
       
   193 
       
   194 QObject *HbDocumentLoader::createObject(const QString& type, const QString &name)
       
   195 {
       
   196     Q_UNUSED(type);
       
   197     
       
   198     QObject *obj = 0;
       
   199     
       
   200     if(mCreateObjectFails) 
       
   201     {
       
   202         return 0;
       
   203     }
       
   204     
       
   205     obj = doCreateObject(name);
       
   206     return obj;
       
   207 }
       
   208 
       
   209 QObject *HbDocumentLoader::doCreateObject(const QString &name)
       
   210 {
       
   211     QObject *obj = 0;
       
   212     if(name == DOCML_NAME_VIEW)
       
   213     {
       
   214         obj = new VideoListView(0, 0);
       
   215     } 
       
   216     else if(name == DOCML_NAME_VC_HEADINGBANNER)
       
   217     {
       
   218         obj = new HbGroupBox();
       
   219     }
       
   220     else if(name == DOCML_NAME_VC_COLLECTIONWIDGET)
       
   221     {
       
   222         obj = new VideoListWidget(0, 0);
       
   223     }
       
   224     else if(name == DOCML_NAME_VC_COLLECTIONCONTENTWIDGET)
       
   225     {
       
   226         obj = new VideoListWidget(0, 0);
       
   227     }
       
   228     else if(name == DOCML_NAME_VC_VIDEOLISTWIDGET)
       
   229     {
       
   230         obj = new VideoListWidget(0, 0);
       
   231     }
       
   232     else if(name == DOCML_NAME_VC_VIDEOHINTWIDGET)
       
   233     {
       
   234         obj = new VideoHintWidget(0, 0);
       
   235     }
       
   236     else if(name == DOCML_NAME_OPTIONS_MENU)
       
   237     {
       
   238         obj = new HbMenu();
       
   239     }
       
   240     else if(name == DOCML_NAME_SORT_MENU)
       
   241     {
       
   242         obj = new HbMenu();
       
   243     }
       
   244     else if(name == DOCML_NAME_SORT_BY_DATE)
       
   245     {
       
   246         obj = new HbAction();
       
   247     }
       
   248     else if(name == DOCML_NAME_SORT_BY_NAME)
       
   249     {
       
   250         obj = new HbAction();
       
   251     }
       
   252     else if(name == DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS)
       
   253     {
       
   254         obj = new HbAction();
       
   255     }
       
   256     else if(name == DOCML_NAME_SORT_BY_SIZE)
       
   257     {
       
   258         obj = new HbAction();
       
   259     }
       
   260     else if(name == DOCML_NAME_ADD_TO_COLLECTION)
       
   261     {
       
   262         obj = new HbAction();
       
   263     }
       
   264     else if(name == DOCML_NAME_CREATE_COLLECTION)
       
   265     {
       
   266         obj = new HbAction();
       
   267     }
       
   268     else if(name == DOCML_NAME_DELETE_MULTIPLE)
       
   269     {
       
   270         obj = new HbAction();
       
   271     }
       
   272     else if(name == DOCML_NAME_HINT_BUTTON)
       
   273     {
       
   274         obj = new HbPushButton();
       
   275     }
       
   276     else if(name == DOCML_NAME_NO_VIDEOS_LABEL)
       
   277     {
       
   278         obj = new HbLabel();
       
   279     }
       
   280     else if(name == DOCML_VIDEOSELECTIONDIALOG_FILE)
       
   281     {
       
   282         obj = new VideoListSelectionDialog(0, 0);
       
   283     }
       
   284     else if(name == DOCML_NAME_DIALOG)
       
   285     {
       
   286         obj = new VideoListSelectionDialog(0, 0);
       
   287     }
       
   288     else if(name == DOCML_NAME_DLG_HEADINGLBL)
       
   289     {
       
   290         obj = new HbLabel();
       
   291     }
       
   292     else if(name == DOCML_NAME_CHECK_CONTAINER)
       
   293     {
       
   294         obj = new HbWidget();
       
   295     }
       
   296     else if(name == DOCML_NAME_MARKALL)
       
   297     {
       
   298         obj = new HbCheckBox();
       
   299     }
       
   300     else if(name == DOCML_NAME_LBL_SELECTION)
       
   301     {
       
   302         obj = new HbLabel();
       
   303     }
       
   304     else if(name == DOCML_NAME_LIST_CONTAINER)
       
   305     {
       
   306         obj = new HbStackedWidget();
       
   307     }
       
   308     else if(name == DOCML_NAME_LBL_MARKALL)
       
   309     {
       
   310         obj = new HbLabel();
       
   311     }
       
   312     return obj;
       
   313 }