videocollection/videocollectionview/src/videolistview.cpp
changeset 41 229f037ce963
parent 40 13331705e488
child 44 518105d52e45
equal deleted inserted replaced
40:13331705e488 41:229f037ce963
    13 *
    13 *
    14 * Description:   Videolist view class source code
    14 * Description:   Videolist view class source code
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 110 %
    18 // Version : %version: 113 %
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <xqserviceutil.h>
    21 #include <xqserviceutil.h>
    22 #include <qactiongroup.h>
    22 #include <qactiongroup.h>
    23 #include <hbinstance.h>
    23 #include <hbinstance.h>
    57 VideoListView::VideoListView( VideoCollectionUiLoader *uiLoader, QGraphicsItem *parent ) 
    57 VideoListView::VideoListView( VideoCollectionUiLoader *uiLoader, QGraphicsItem *parent ) 
    58     : HbView( parent )
    58     : HbView( parent )
    59     , mUiUtils( VideoCollectionViewUtils::instance() )
    59     , mUiUtils( VideoCollectionViewUtils::instance() )
    60     , mWrapper( VideoCollectionWrapper::instance() )
    60     , mWrapper( VideoCollectionWrapper::instance() )
    61     , mUiLoader( uiLoader )
    61     , mUiLoader( uiLoader )
    62     , mIsService( false )
       
    63     , mModelReady( false )
    62     , mModelReady( false )
    64     , mViewReady( false )
    63     , mViewReady( false )
    65     , mHintLevel( VideoHintWidget::AllVideos )
    64     , mHintLevel( VideoHintWidget::AllVideos )
    66     , mVideoServices( 0 )
    65     , mVideoServices( 0 )
    67     , mCurrentList( 0 )
    66     , mCurrentList( 0 )
   101 	if(!mUiLoader)
   100 	if(!mUiLoader)
   102 	{
   101 	{
   103         cleanup();
   102         cleanup();
   104 		return -1;
   103 		return -1;
   105 	}
   104 	}
   106 
   105 	int videoListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
   107     if (XQServiceUtil::isService() && !mVideoServices)
   106 	int collectionListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
   108     {
   107 	int collectionContentListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
   109         INFO("VideoListView::initializeView() service flag set to true.");
   108 	VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
   110         mIsService = true;
   109     if (XQServiceUtil::isService())
   111 
   110     {
   112     	mVideoServices = VideoServices::instance();
   111         INFO("VideoListView::initializeView() initializing service.");
   113 
       
   114     	if (!mVideoServices)
   112     	if (!mVideoServices)
   115         {
   113         {
   116     	    ERROR(-1, "VideoListView::initializeView() getting services instance failed.");
   114     	    mVideoServices = VideoServices::instance();
   117             cleanup();
   115     	    connect(mVideoServices, SIGNAL(titleReady(const QString&)), 
   118         	return -1;
   116     	            this, SLOT(titleReadySlot(const QString&)));
   119 		}
   117 		}
   120         else
   118     	 
   121         {
       
   122         	connect(mVideoServices, SIGNAL(titleReady(const QString&)), this, SLOT(titleReadySlot(const QString&)));
       
   123         }
       
   124 	}
   119 	}
       
   120     else
       
   121     {
       
   122         if(mVideoServices)
       
   123         {
       
   124             disconnect(mVideoServices, SIGNAL(titleReady(const QString&)), 
       
   125                     this, SLOT(titleReadySlot(const QString&)));
       
   126             mVideoServices->decreaseReferenceCount();
       
   127             mVideoServices = 0;
       
   128         }
       
   129         VideoCollectionViewUtils::getActivityWidgetLevel(level);
       
   130         if(level == VideoCollectionCommon::ELevelCategory)
       
   131         {
       
   132             videoListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
       
   133             collectionListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
       
   134             collectionContentListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
       
   135         }
       
   136         else if(level == VideoCollectionCommon::ELevelDefaultColl ||
       
   137                 level == VideoCollectionCommon::ELevelAlbum)
       
   138         {
       
   139             videoListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
       
   140             collectionListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
       
   141             collectionContentListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
       
   142         }   
       
   143     }
       
   144     // start loading objects and widgets
   125     QList<VideoCollectionUiLoaderParam> params;
   145     QList<VideoCollectionUiLoaderParam> params;
   126     int videoListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
   146     
   127     int collectionListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
   147     params.append(VideoCollectionUiLoaderParam(
   128     
   148         DOCML_NAME_VC_VIDEOLISTWIDGET,
   129     if(VideoCollectionViewUtils::loadWidgetLevel() == VideoCollectionCommon::ELevelCategory)
   149         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   130     {
   150         true,
   131         videoListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
   151         videoListPhase));
   132         collectionListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
   152     
   133        
   153     params.append(VideoCollectionUiLoaderParam(
   134        
   154         DOCML_NAME_VC_COLLECTIONWIDGET,
   135     }
   155         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   136     // start loading objects and widgets
   156         DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
   137     params.append(VideoCollectionUiLoaderParam(
   157         true,
   138                    DOCML_NAME_VC_VIDEOLISTWIDGET,
   158         collectionListPhase));
   139                    DOCML_VIDEOCOLLECTIONVIEW_FILE,
   159     
   140                    true,
   160     params.append(VideoCollectionUiLoaderParam(
   141                    videoListPhase));
   161         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET,
   142     params.append(VideoCollectionUiLoaderParam(
   162         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   143                    DOCML_NAME_VC_COLLECTIONWIDGET,
   163         DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
   144                    DOCML_VIDEOCOLLECTIONVIEW_FILE,
   164         true,
   145                    DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
   165         collectionContentListPhase)); 
   146                    true,
   166     
   147                    collectionListPhase));
       
   148         
       
   149     params.append(VideoCollectionUiLoaderParam(
   167     params.append(VideoCollectionUiLoaderParam(
   150         DOCML_NAME_OPTIONS_MENU,
   168         DOCML_NAME_OPTIONS_MENU,
   151         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   169         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   152         true,
   170         true,
   153         VideoCollectionUiLoaderParam::LoadPhasePrimary));
   171         VideoCollectionUiLoaderParam::LoadPhasePrimary));
   193         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
   211         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
   194     params.append(VideoCollectionUiLoaderParam(
   212     params.append(VideoCollectionUiLoaderParam(
   195         DOCML_NAME_SORT_BY_SIZE,
   213         DOCML_NAME_SORT_BY_SIZE,
   196         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   214         DOCML_VIDEOCOLLECTIONVIEW_FILE,
   197         false,
   215         false,
   198         VideoCollectionUiLoaderParam::LoadPhaseSecondary));   
   216         VideoCollectionUiLoaderParam::LoadPhaseSecondary));       
   199     params.append(VideoCollectionUiLoaderParam(
       
   200         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET,
       
   201         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   202         DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
       
   203         true,
       
   204         VideoCollectionUiLoaderParam::LoadPhaseSecondary)); // widget
       
   205     params.append(VideoCollectionUiLoaderParam(
   217     params.append(VideoCollectionUiLoaderParam(
   206         DOCML_NAME_DIALOG,
   218         DOCML_NAME_DIALOG,
   207         DOCML_VIDEOSELECTIONDIALOG_FILE,
   219         DOCML_VIDEOSELECTIONDIALOG_FILE,
   208         true,
   220         true,
   209         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
   221         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
   229         this,
   241         this,
   230         SLOT(objectReadySlot(QObject*, const QString&)));
   242         SLOT(objectReadySlot(QObject*, const QString&)));
   231     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary);
   243     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary);
   232     params.clear();
   244     params.clear();
   233     
   245     
       
   246     // fetch current list right away for main views
       
   247     // for default and user defined collections, currentList 
       
   248     // will be setted during activation
   234     if(videoListPhase == VideoCollectionUiLoaderParam::LoadPhasePrimary)
   249     if(videoListPhase == VideoCollectionUiLoaderParam::LoadPhasePrimary)
   235     {
   250     {
   236         mCurrentList = mUiLoader->findWidget<VideoListWidget>(
   251         mCurrentList = mUiLoader->findWidget<VideoListWidget>(
   237                                 DOCML_NAME_VC_VIDEOLISTWIDGET);
   252                 DOCML_NAME_VC_VIDEOLISTWIDGET );
   238     }
   253     }
   239     else
   254     else 
   240     {
   255     {
   241         mCurrentList = mUiLoader->findWidget<VideoListWidget>(
   256         mCurrentList = mUiLoader->findWidget<VideoListWidget>(
   242                                     DOCML_NAME_VC_COLLECTIONWIDGET);
   257                 DOCML_NAME_VC_COLLECTIONWIDGET );
   243     }
   258     }
       
   259 
       
   260 
   244     
   261     
   245     return 0;
   262     return 0;
   246 }
   263 }
   247 
   264 
   248 // ---------------------------------------------------------------------------
   265 // ---------------------------------------------------------------------------
   257 
   274 
   258 // ---------------------------------------------------------------------------
   275 // ---------------------------------------------------------------------------
   259 // activateView()
   276 // activateView()
   260 // ---------------------------------------------------------------------------
   277 // ---------------------------------------------------------------------------
   261 //
   278 //
   262 int VideoListView::activateView(const TMPXItemId &itemId)
   279 int VideoListView::activateView( TMPXItemId &itemId)
   263 {
   280 {
   264 	FUNC_LOG;
   281 	FUNC_LOG;
   265 
   282 
   266     int err = 0;
   283     int err = -1;
   267     
   284            
   268     // activate collection to correct view
   285     // activate collection to correct view
   269     if (itemId == TMPXItemId::InvalidId())
   286     if (itemId == TMPXItemId::InvalidId())
   270     {
   287     {  
   271         err = activateVideosView();
   288         
   272     }
   289         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
   273     else
   290         if(!mVideoServices)
       
   291         {
       
   292             VideoCollectionViewUtils::getActivityWidgetLevel(level);
       
   293         }
       
   294         if(level == VideoCollectionCommon::ELevelCategory ||
       
   295            level == VideoCollectionCommon::ELevelVideos)
       
   296         {
       
   297             err = activateMainView();
       
   298         }
       
   299         else if(level == VideoCollectionCommon::ELevelDefaultColl ||
       
   300                 level == VideoCollectionCommon::ELevelAlbum)
       
   301         {
       
   302             // level is default or user defined collection
       
   303             // see if we have item id 
       
   304             VideoCollectionViewUtils::getCollectionActivityData(itemId, mCollectionName);     
       
   305         }
       
   306     }
       
   307     if(itemId != TMPXItemId::InvalidId())
   274     {
   308     {
   275         err = activateCollectionContentView(itemId);
   309         err = activateCollectionContentView(itemId);
   276     }
   310     }
   277     
   311     
       
   312     if(!err)
       
   313     {
       
   314        
       
   315        err = createToolbar();
       
   316     }
       
   317     
   278     // connect signals if everything went ok
   318     // connect signals if everything went ok
   279     if (err == 0)
   319     if (!err)
   280     {
   320     {
   281         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   321         HbMainWindow *mainWnd = hbInstance->allMainWindows().value(0);
   282         mainWnd->setOrientation(Qt::Vertical, false);
   322         mainWnd->setOrientation(Qt::Vertical, false);
   283         if (!connect(
   323         if (!connect(
   284                 mainWnd, SIGNAL(aboutToChangeOrientation()),
   324                 mainWnd, SIGNAL(aboutToChangeOrientation()),
   300             // deactivate view so we get rid of dangling connections.
   340             // deactivate view so we get rid of dangling connections.
   301             deactivateView();
   341             deactivateView();
   302             err = -1;
   342             err = -1;
   303         }
   343         }
   304     }
   344     }
       
   345     else
       
   346     {
       
   347         deactivateView();
       
   348     }
   305     
   349     
   306     return err;
   350     return err;
   307 }
   351 }
   308 
   352 
   309 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   392         disconnect(mCurrentList->getModel()->sourceModel(),
   436         disconnect(mCurrentList->getModel()->sourceModel(),
   393                 SIGNAL(modelReady()),
   437                 SIGNAL(modelReady()),
   394                 this, SLOT(modelReadySlot()));
   438                 this, SLOT(modelReadySlot()));
   395 
   439 
   396         showHint(false);
   440         showHint(false);
   397     }
   441         if(!mVideoServices)
   398     
   442         {
   399     if(mCurrentList)
   443             VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel();
   400     {
   444             VideoCollectionViewUtils::setWidgetActivityLevel(level);
   401         VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel();
   445         }
   402         VideoCollectionViewUtils::saveWidgetLevel(level);
       
   403         mCurrentList->deactivate();
   446         mCurrentList->deactivate();
   404     }
   447     }
   405 }
   448 }
   406 
   449 
   407 // ---------------------------------------------------------------------------
   450 // ---------------------------------------------------------------------------
   453 
   496 
   454         // Collections tab
   497         // Collections tab
   455         mToolbarActions[ETBActionCollections] = createAction("qtg_mono_video_collection",
   498         mToolbarActions[ETBActionCollections] = createAction("qtg_mono_video_collection",
   456                 mToolbarViewsActionGroup, SLOT(openCollectionViewSlot()));
   499                 mToolbarViewsActionGroup, SLOT(openCollectionViewSlot()));
   457 
   500 
   458         if (!mIsService)
   501         if (!mVideoServices)
   459         {
   502         {
   460 			// Services tab
   503 			// Services tab
   461 			mToolbarActions[ETBActionServices] = createAction("qtg_mono_ovistore",
   504 			mToolbarActions[ETBActionServices] = createAction("qtg_mono_ovistore",
   462 					mToolbarViewsActionGroup, SLOT(openServicesViewSlot()));
   505 					mToolbarViewsActionGroup, SLOT(openServicesViewSlot()));
   463 			// Add Videos tab
   506 			// Add Videos tab
   474         HbToolBar *bar = toolBar(); // First call to toolBar() creates the object, so on failure it could return 0.
   517         HbToolBar *bar = toolBar(); // First call to toolBar() creates the object, so on failure it could return 0.
   475 
   518 
   476         if(   !bar
   519         if(   !bar
   477 		   || !mToolbarActions[ETBActionAllVideos]
   520 		   || !mToolbarActions[ETBActionAllVideos]
   478            || !mToolbarActions[ETBActionCollections]
   521            || !mToolbarActions[ETBActionCollections]
   479            || ( !mIsService && (!mToolbarActions[ETBActionServices] 
   522            || ( !mVideoServices && (!mToolbarActions[ETBActionServices] 
   480               || !mToolbarActions[ETBActionAddVideos]
   523               || !mToolbarActions[ETBActionAddVideos]
   481               || !mToolbarActions[ETBActionRemoveVideos])))
   524               || !mToolbarActions[ETBActionRemoveVideos])))
   482         {
   525         {
   483             ERROR(-1, "VideoListView::createToolbar() failed to create all actions or the toolbar.");
   526             ERROR(-1, "VideoListView::createToolbar() failed to create all actions or the toolbar.");
   484         	delete mToolbarActions[ETBActionAllVideos];
   527         	delete mToolbarActions[ETBActionAllVideos];
   491 
   534 
   492         // Collection view actions are not checkable
   535         // Collection view actions are not checkable
   493         mToolbarActions[ETBActionAllVideos]->setCheckable(true);
   536         mToolbarActions[ETBActionAllVideos]->setCheckable(true);
   494         mToolbarActions[ETBActionCollections]->setCheckable(true);
   537         mToolbarActions[ETBActionCollections]->setCheckable(true);
   495 
   538 
   496         if (!mIsService)
   539         if (!mVideoServices)
   497         {
   540         {
   498         	mToolbarActions[ETBActionServices]->setCheckable(false);
   541         	mToolbarActions[ETBActionServices]->setCheckable(false);
   499         }
   542         }
   500 
   543         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
   501         if(mCurrentList->getLevel() == VideoCollectionCommon::ELevelCategory)
   544         if(mCurrentList)
       
   545         {
       
   546             level = mCurrentList->getLevel();
       
   547         }
       
   548         if(level == VideoCollectionCommon::ELevelCategory)
   502         {
   549         {
   503             mToolbarActions[ETBActionCollections]->setChecked(true);
   550             mToolbarActions[ETBActionCollections]->setChecked(true);
   504         }
   551             bar->addActions(mToolbarViewsActionGroup->actions());
   505         else
   552         }
       
   553         else if(level == VideoCollectionCommon::ELevelVideos )
   506         {
   554         {
   507             mToolbarActions[ETBActionAllVideos]->setChecked(true);
   555             mToolbarActions[ETBActionAllVideos]->setChecked(true);
   508         }
   556             bar->addActions(mToolbarViewsActionGroup->actions());
   509 
   557         }
   510         bar->addActions(mToolbarViewsActionGroup->actions());
   558         else if(level == VideoCollectionCommon::ELevelAlbum) 
       
   559         {
       
   560             bar->addActions(mToolbarCollectionActionGroup->actions());
       
   561         }
       
   562         
   511     }
   563     }
   512 
   564 
   513     return 0;
   565     return 0;
   514 }
   566 }
   515 
   567 
   580             hintWidget->deactivate();
   632             hintWidget->deactivate();
   581             hintWidget->setButtonShown(true);
   633             hintWidget->setButtonShown(true);
   582         }
   634         }
   583     }
   635     }
   584 
   636 
   585     if (mToolbarViewsActionGroup && mToolbarCollectionActionGroup && !mIsService)
   637     if (mToolbarViewsActionGroup && mToolbarCollectionActionGroup && !mVideoServices)
   586     {
   638     {
   587         if (show)
   639         if (show)
   588         {
   640         {
   589         	mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
   641         	mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
   590         }
   642         }
   690         action->setVisible(show);
   742         action->setVisible(show);
   691     }
   743     }
   692 }
   744 }
   693 
   745 
   694 // ---------------------------------------------------------------------------
   746 // ---------------------------------------------------------------------------
   695 // activateVideosView()
   747 // activateMainView()
   696 // ---------------------------------------------------------------------------
   748 // ---------------------------------------------------------------------------
   697 //
   749 //
   698 int VideoListView::activateVideosView()
   750 int VideoListView::activateMainView()
   699 {
   751 {
   700     FUNC_LOG;
   752     FUNC_LOG;
   701 
   753 
   702     if(!mCurrentList)
   754     if(!mCurrentList)
   703     {
   755     {
   704         return -1;
   756         return -1;
   705     }
   757     }
   706     VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel(); 
   758 
   707 
   759     int result = mCurrentList->activate();
   708     int result = mCurrentList->activate(level);
       
   709     if(result < 0)
   760     if(result < 0)
   710     {
   761     {
   711         ERROR(result, "VideoListView::activateVideosView() failed to activate.");
   762         ERROR(result, "VideoListView::activateVideosView() failed to activate.");
   712         // activate failed, deactivate view so we get rid of dangling connections.
       
   713         deactivateView();
       
   714         return -1;
   763         return -1;
   715     }
   764     }
   716     
   765 
   717     if (createToolbar() != 0)
   766     return 0;
   718     {
   767 }
   719         ERROR(result, "VideoListView::activateVideosView() failed to create toolbar.");
   768 
   720         deactivateView();
   769 // ---------------------------------------------------------------------------
       
   770 // activateCollectionContentView()
       
   771 // ---------------------------------------------------------------------------
       
   772 //
       
   773 int VideoListView::activateCollectionContentView(const TMPXItemId &itemId)
       
   774 {
       
   775     FUNC_LOG;
       
   776 
       
   777     // resolve collection name if possible
       
   778     if(itemId.iId2  == KVcxMvcMediaTypeCategory && mCollectionName.isEmpty())
       
   779     {
       
   780         if (itemId.iId1 == KVcxMvcCategoryIdDownloads)
       
   781         {
       
   782             mCollectionName = hbTrId("txt_videos_dblist_downloaded");
       
   783         }
       
   784         else if(itemId.iId1 == KVcxMvcCategoryIdCaptured) 
       
   785         {
       
   786             mCollectionName = hbTrId("txt_videos_dblist_captured");
       
   787         }
       
   788         else
       
   789         {
       
   790             // only downloads and captured are supported in default collections
       
   791             ERROR(-1, "VideoListView::activateVideosView() invalid defauld collection.");
       
   792             return -1;
       
   793         }
       
   794     }
       
   795     // at this point activation will fail if there's no collection name available
       
   796     if(mCollectionName.isEmpty())
       
   797     {
       
   798         ERROR(-1, "VideoListView::activateVideosView() no collection name, cannot proceed.");
   721         return -1;
   799         return -1;
   722     }
   800     }
   723     
   801     
       
   802     // if current list at this point is already collection content, 
       
   803     // no need to init again, just activate
       
   804     if(mCurrentList && 
       
   805        (mCurrentList->getLevel() == VideoCollectionCommon::ELevelDefaultColl ||
       
   806         mCurrentList->getLevel() == VideoCollectionCommon::ELevelAlbum))
       
   807     {
       
   808         
       
   809         return mCurrentList->activate();
       
   810     }
       
   811     // no currentlist, or currentlist differs, create and initialize all over
       
   812     collectionOpenedSlot(true, mCollectionName, itemId);
       
   813     
       
   814     if((!mCurrentList || !mCurrentList->getModel()) ||
       
   815        (mCurrentList->getLevel() != VideoCollectionCommon::ELevelDefaultColl && 
       
   816         mCurrentList->getLevel() != VideoCollectionCommon::ELevelAlbum ))
       
   817     {
       
   818         ERROR(-1, "VideoListView::activateVideosView() failed to init and activate collection.");
       
   819         return -1;
       
   820     }
       
   821 
       
   822     // if we're servicing, need to fetch sorting role from client
       
   823     // in normal use, sorting has set already at uiloader
       
   824    
       
   825     if (mVideoServices)
       
   826     {       
       
   827         // TODO: service sorting roles needs to be defined somewhere
       
   828         int sortRole = mVideoServices->sortRole();
       
   829         if(sortRole == 2)
       
   830         {
       
   831             sortRole = VideoCollectionCommon::KeyTitle;
       
   832         }
       
   833         else if(sortRole == 3)
       
   834         {
       
   835             sortRole = VideoCollectionCommon::KeySizeValue;
       
   836         } 
       
   837         else
       
   838         {
       
   839             // default 
       
   840             sortRole = VideoCollectionCommon::KeyDateTime;
       
   841         }
       
   842         mCurrentList->getModel()->doSorting(sortRole, Qt::AscendingOrder);
       
   843     }
       
   844     
   724     return 0;
   845     return 0;
   725 }
       
   726 
       
   727 // ---------------------------------------------------------------------------
       
   728 // activateCollectionContentView()
       
   729 // ---------------------------------------------------------------------------
       
   730 //
       
   731 int VideoListView::activateCollectionContentView(const TMPXItemId &itemId)
       
   732 {
       
   733     FUNC_LOG;
       
   734     int err = 0;
       
   735     
       
   736     if (itemId.iId2 == KVcxMvcMediaTypeCategory ||
       
   737         itemId.iId2 == KVcxMvcMediaTypeAlbum)
       
   738     {
       
   739         // currently only captured and downloaded categories are supported
       
   740         switch (itemId.iId1)
       
   741         {
       
   742             case KVcxMvcCategoryIdDownloads:
       
   743             case KVcxMvcCategoryIdCaptured:
       
   744             {
       
   745                 VideoListWidget *collectionContentWidget =
       
   746                     mUiLoader->findWidget<VideoListWidget>(
       
   747                         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   748                 if (collectionContentWidget && collectionContentWidget->getModel())
       
   749                 {
       
   750                     // no need to deactivate since there cannot be previous widget
       
   751                     mCurrentList = collectionContentWidget;
       
   752                     
       
   753                     // resolve collection name
       
   754                     if (itemId.iId1 == KVcxMvcCategoryIdDownloads)
       
   755                     {
       
   756                         mCollectionName = hbTrId("txt_videos_dblist_downloaded");
       
   757                     }
       
   758                     else if (itemId.iId1 == KVcxMvcCategoryIdCaptured)
       
   759                     {
       
   760                         mCollectionName = hbTrId("txt_videos_dblist_captured");
       
   761                     }
       
   762                     
       
   763                     // activate collection content widget
       
   764                     mCurrentList->activate(VideoCollectionCommon::ELevelDefaultColl);
       
   765                     
       
   766                     // open the model
       
   767                     VideoSortFilterProxyModel *model = mCurrentList->getModel();
       
   768                     model->openItem(itemId);
       
   769                     
       
   770                     // sort model
       
   771                     int sortRole = VideoCollectionCommon::KeyDateTime;
       
   772                     if (mIsService &&
       
   773                         mVideoServices)
       
   774                     {
       
   775                         // TODO: sorting roles needs to be defined somewhere
       
   776                         sortRole = mVideoServices->sortRole();
       
   777                         switch (sortRole)
       
   778                         {
       
   779                             // sort by name
       
   780                             case 2:
       
   781                             {
       
   782                                 sortRole = VideoCollectionCommon::KeyTitle;
       
   783                                 break;
       
   784                             }
       
   785                             // sort by size
       
   786                             case 3:
       
   787                             {
       
   788                                 sortRole = VideoCollectionCommon::KeySizeValue;
       
   789                                 break;
       
   790                             }
       
   791                             // date & time
       
   792                             case 1:
       
   793                                 // fall through
       
   794                             default:
       
   795                             {
       
   796                                 sortRole = VideoCollectionCommon::KeyDateTime;
       
   797                                 break;
       
   798                             }
       
   799                         }
       
   800                     }
       
   801                     model->doSorting(sortRole, Qt::AscendingOrder);
       
   802                     
       
   803                     // set hint level to collections
       
   804                     setHintLevel(VideoHintWidget::Collection);
       
   805                 }
       
   806                 else
       
   807                 {
       
   808                     ERROR(-1, "VideoListView::activateVideosView() failed to get collection content widget.");
       
   809                     err = -1;
       
   810                 }
       
   811                 break;
       
   812             }
       
   813             default:
       
   814             {
       
   815                 // by default open videos view
       
   816                 err = activateVideosView();
       
   817                 break;
       
   818             }
       
   819         }
       
   820         
       
   821     }
       
   822     else
       
   823     {
       
   824         // open videos view
       
   825         err = activateVideosView();
       
   826     }
       
   827 
       
   828     return err;
       
   829 }
   846 }
   830 
   847 
   831 // ---------------------------------------------------------------------------
   848 // ---------------------------------------------------------------------------
   832 // openAllVideosViewSlot()
   849 // openAllVideosViewSlot()
   833 // ---------------------------------------------------------------------------
   850 // ---------------------------------------------------------------------------
   941 	{
   958 	{
   942 		order = Qt::DescendingOrder;
   959 		order = Qt::DescendingOrder;
   943 	}
   960 	}
   944 	model->doSorting(role, order);
   961 	model->doSorting(role, order);
   945 	
   962 	
   946 	if (mCurrentList == mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET))
   963 	// for video related sorting, all videos list and collection content
       
   964 	// list, sorting orders are same all the time
       
   965 	VideoListWidget *anotherVideosList = 0;
       
   966 	VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel();
       
   967 	if (level == VideoCollectionCommon::ELevelDefaultColl ||
       
   968 	    level == VideoCollectionCommon::ELevelAlbum)
   947 	{
   969 	{
   948 	    VideoListWidget *allVideosList = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET);
   970 	    anotherVideosList = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET);
   949 	    if(allVideosList && allVideosList->getModel())
       
   950 	    {
       
   951 	        allVideosList->getModel()->doSorting(role, order);
       
   952 	    }
       
   953 	}
   971 	}
       
   972 	else if(level == VideoCollectionCommon::ELevelVideos)
       
   973 	{
       
   974 	    anotherVideosList = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   975 	}
       
   976     if(anotherVideosList && anotherVideosList->getModel())
       
   977     {
       
   978         anotherVideosList->getModel()->doSorting(role, order);
       
   979     }
   954 
   980 
   955     // save sorting values only if the application is not started as a service
   981     // save sorting values only if the application is not started as a service
   956 	if (!mIsService)
   982 	if (!mVideoServices)
   957 	{
   983 	{
   958 	    // save sorting values
   984 	    // save sorting values
   959 	    mUiUtils.saveSortingValues(role, order, mCurrentList->getLevel());
   985 	    mUiUtils.saveSortingValues(role, order, mCurrentList->getLevel());
   960 	}
   986 	}
   961 }
   987 }
  1112 // aboutToShowMainMenuSlot
  1138 // aboutToShowMainMenuSlot
  1113 // -------------------------------------------------------------------------------------------------
  1139 // -------------------------------------------------------------------------------------------------
  1114 //
  1140 //
  1115 void VideoListView::aboutToShowMainMenuSlot()
  1141 void VideoListView::aboutToShowMainMenuSlot()
  1116 {
  1142 {
  1117     if (mIsService &&
  1143     if (mVideoServices &&
  1118         mVideoServices &&
       
  1119         mVideoServices->currentService() == VideoServices::EBrowse)
  1144         mVideoServices->currentService() == VideoServices::EBrowse)
  1120     {
  1145     {
  1121         prepareBrowseServiceMenu();
  1146         prepareBrowseServiceMenu();
  1122         return;
  1147         return;
  1123     }
  1148     }
  1165 		if (action)
  1190 		if (action)
  1166 		{
  1191 		{
  1167 			action->setChecked(true);
  1192 			action->setChecked(true);
  1168 		}
  1193 		}
  1169 
  1194 
  1170         if (!mIsService)
  1195         if (!mVideoServices)
  1171         {
  1196         {
  1172             showAction(true, DOCML_NAME_ADD_TO_COLLECTION);
  1197             showAction(true, DOCML_NAME_ADD_TO_COLLECTION);
  1173             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1198             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1174         }
  1199         }
  1175     }
  1200     }
  1176     else if(mToolbarViewsActionGroup->checkedAction() == mToolbarActions[ETBActionCollections] &&
  1201     else if(mToolbarViewsActionGroup->checkedAction() == mToolbarActions[ETBActionCollections] &&
  1177     		firstAction == mToolbarActions[ETBActionAllVideos] )
  1202     		firstAction == mToolbarActions[ETBActionAllVideos] )
  1178     {
  1203     {
  1179         if (!mIsService)
  1204         if (!mVideoServices)
  1180         {
  1205         {
  1181             showAction(true, DOCML_NAME_CREATE_COLLECTION);
  1206             showAction(true, DOCML_NAME_CREATE_COLLECTION);
  1182         }
  1207         }
  1183         showAction(true, DOCML_NAME_SORT_MENU);
  1208         showAction(true, DOCML_NAME_SORT_MENU);
  1184         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1209         showAction(true, DOCML_NAME_SORT_BY_NAME);
  1201 		if (action)
  1226 		if (action)
  1202 		{
  1227 		{
  1203 			action->setChecked(true);
  1228 			action->setChecked(true);
  1204 		}
  1229 		}
  1205 
  1230 
  1206         if (!mIsService)
  1231         if (!mVideoServices)
  1207         {
  1232         {
  1208             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1233             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
  1209         }
  1234         }
  1210     }
  1235     }
  1211 }
  1236 }
  1270 
  1295 
  1271 // -------------------------------------------------------------------------------------------------
  1296 // -------------------------------------------------------------------------------------------------
  1272 // collectionOpenedSlot
  1297 // collectionOpenedSlot
  1273 // -------------------------------------------------------------------------------------------------
  1298 // -------------------------------------------------------------------------------------------------
  1274 //
  1299 //
  1275 void VideoListView::collectionOpenedSlot(bool collectionOpened,
  1300 void VideoListView::collectionOpenedSlot(bool openingCollection,
  1276     const QString& collection,
  1301     const QString& collection,
  1277     const QModelIndex &index)
  1302     const TMPXItemId &collectionId)
  1278 {
  1303 {
  1279 	FUNC_LOG;
  1304 	FUNC_LOG;
  1280 
  1305 
  1281 	if(!mCurrentList || !mCurrentList->getModel())
       
  1282 	{
       
  1283 	    return;
       
  1284 	}
       
  1285     // clear toolbar actions.
  1306     // clear toolbar actions.
  1286     toolBar()->clearActions();
  1307     toolBar()->clearActions();
  1287 
  1308 
  1288     VideoListWidget *collectionContentWidget =
  1309     VideoListWidget *collectionContentWidget =
  1289                 mUiLoader->findWidget<VideoListWidget>(
  1310                 mUiLoader->findWidget<VideoListWidget>(
  1298 	
  1319 	
  1299 	// disable collection content animations during widget change        
  1320 	// disable collection content animations during widget change        
  1300 	HbAbstractItemView::ItemAnimations animationState = collectionContentWidget->enabledAnimations();
  1321 	HbAbstractItemView::ItemAnimations animationState = collectionContentWidget->enabledAnimations();
  1301 	collectionContentWidget->setEnabledAnimations(HbAbstractItemView::None);
  1322 	collectionContentWidget->setEnabledAnimations(HbAbstractItemView::None);
  1302 	
  1323 	
  1303 	if(collectionOpened)
  1324 	if(openingCollection)
  1304     {
  1325     {
  1305         // open album view        
  1326         // open album view        
  1306         if (!index.isValid() || !mCurrentList || mCurrentList == collectionContentWidget)
  1327         if (collectionId == TMPXItemId::InvalidId() || mCurrentList == collectionContentWidget)
  1307         {
  1328         {
  1308             // no currentlist or currentlist is already collection content -list 
  1329             // no currentlist or currentlist is already collection content -list 
  1309             collectionContentWidget->setEnabledAnimations(animationState);
  1330             collectionContentWidget->setEnabledAnimations(animationState);
  1310             return;
  1331             return;
  1311         }
  1332         }
  1312         
  1333                 
  1313         // get item id before deactivating
       
  1314         TMPXItemId itemId = mCurrentList->getModel()->getMediaIdAtIndex(index);
       
  1315         
       
  1316         // get level from the item to be opened only default 
  1334         // get level from the item to be opened only default 
  1317         // or user defined collections can be activated here
  1335         // or user defined collections can be activated here
  1318         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelInvalid;
  1336         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelInvalid;
  1319         if(itemId.iId2 == KVcxMvcMediaTypeCategory)
  1337         if(collectionId.iId2 == KVcxMvcMediaTypeCategory)
  1320         {
  1338         {
  1321             level = VideoCollectionCommon::ELevelDefaultColl; 
  1339             level = VideoCollectionCommon::ELevelDefaultColl; 
  1322         }
  1340         }
  1323         else if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
  1341         else if(collectionId.iId2 == KVcxMvcMediaTypeAlbum)
  1324         {
  1342         {
  1325             level = VideoCollectionCommon::ELevelAlbum; 
  1343             level = VideoCollectionCommon::ELevelAlbum; 
  1326         }
  1344         }
  1327         else 
  1345         else 
  1328         {
  1346         {
  1333         // Start fetching content before changing.
  1351         // Start fetching content before changing.
  1334         VideoSortFilterProxyModel *model = collectionContentWidget->getModel();
  1352         VideoSortFilterProxyModel *model = collectionContentWidget->getModel();
  1335         if(!model)
  1353         if(!model)
  1336         {
  1354         {
  1337             // no model for content widget, cannot activate
  1355             // no model for content widget, cannot activate
       
  1356             collectionContentWidget->setEnabledAnimations(animationState);
  1338             return;
  1357             return;
  1339         }
  1358         }
  1340         model->openItem(itemId);
  1359         model->openItem(collectionId);
  1341         
  1360         
  1342         // deactivat current widget.
  1361         // deactivat current widget.
  1343         mCurrentList->deactivate();
  1362         if(mCurrentList)
       
  1363         {
       
  1364             mCurrentList->deactivate();
       
  1365         }
  1344         
  1366         
  1345         // activate video collection content widget and set it as current list.
  1367         // activate video collection content widget and set it as current list.
  1346         mCurrentList = collectionContentWidget;
  1368         mCurrentList = collectionContentWidget;
  1347         mCurrentList->activate(level);
  1369         mCurrentList->activate(level);
  1348 
  1370 
  1374             mToolbarActions[ETBActionCollections]->setChecked(true);
  1396             mToolbarActions[ETBActionCollections]->setChecked(true);
  1375         }
  1397         }
  1376     }
  1398     }
  1377 	// restore animations for collection content widget
  1399 	// restore animations for collection content widget
  1378 	collectionContentWidget->setEnabledAnimations(animationState);
  1400 	collectionContentWidget->setEnabledAnimations(animationState);
       
  1401 	if(!mVideoServices)
       
  1402 	{
       
  1403 	    // save / clear collection related activity data
       
  1404 	    VideoCollectionViewUtils::setCollectionActivityData(collectionId, collection);
       
  1405 	}
  1379 }
  1406 }
  1380 
  1407 
  1381 // -------------------------------------------------------------------------------------------------
  1408 // -------------------------------------------------------------------------------------------------
  1382 // objectReadySlot
  1409 // objectReadySlot
  1383 // -------------------------------------------------------------------------------------------------
  1410 // -------------------------------------------------------------------------------------------------
  1396         }
  1423         }
  1397     }
  1424     }
  1398     else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
  1425     else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
  1399     {
  1426     {
  1400         connect(
  1427         connect(
  1401             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1428             object, SIGNAL(collectionOpened(bool, const QString&, const TMPXItemId&)),
  1402             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1429             this, SLOT(collectionOpenedSlot(bool, const QString&, const TMPXItemId&)));
  1403         if(mCurrentList != object)
  1430         if(mCurrentList != object)
  1404         {
  1431         {
  1405             // this widget not yet activated so it's has been created on the second phase
  1432             // this widget not yet activated so it's has been created on the second phase
  1406             // safe to call doDelayed right away
  1433             // safe to call doDelayed right away
  1407             qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
  1434             qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
  1409     }
  1436     }
  1410     else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
  1437     else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
  1411     {
  1438     {
  1412         connect(object, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1439         connect(object, SIGNAL(command(int)), this, SIGNAL(command(int)));
  1413         connect(
  1440         connect(
  1414             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
  1441             object, SIGNAL(collectionOpened(bool, const QString&, const TMPXItemId&)),
  1415             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
  1442             this, SLOT(collectionOpenedSlot(bool, const QString&, const TMPXItemId&)));
  1416         if(mCurrentList != object)
  1443         if(mCurrentList != object)
  1417         {
  1444         {
  1418             // this widget not yet activated so it's has been created on the second phase
  1445             // this widget not yet activated so it's has been created on the second phase
  1419             // safe to call doDelayed right away
  1446             // safe to call doDelayed right away
  1420             qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
  1447             qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();