videocollection/videocollectionview/src/videolistview.cpp
changeset 28 c48470be1ba7
parent 24 7d93ee07fb27
child 46 adbe7d5ba2f5
--- a/videocollection/videocollectionview/src/videolistview.cpp	Thu May 27 12:53:14 2010 +0300
+++ b/videocollection/videocollectionview/src/videolistview.cpp	Fri Jun 11 13:39:54 2010 +0300
@@ -15,7 +15,7 @@
 *
 */
 
-// Version : %version: 106 %
+// Version : %version: 108 %
 
 // INCLUDE FILES
 #include <xqserviceutil.h>
@@ -123,14 +123,30 @@
         	connect(mVideoServices, SIGNAL(titleReady(const QString&)), this, SLOT(titleReadySlot(const QString&)));
         }
 	}
+    QList<VideoCollectionUiLoaderParam> params;
+    int videoListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
+    int collectionListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
     
+    if(VideoCollectionViewUtils::loadWidgetLevel() == VideoCollectionCommon::ELevelCategory)
+    {
+        videoListPhase = VideoCollectionUiLoaderParam::LoadPhaseSecondary;
+        collectionListPhase = VideoCollectionUiLoaderParam::LoadPhasePrimary;
+       
+       
+    }
     // start loading objects and widgets
-    QList<VideoCollectionUiLoaderParam> params;
     params.append(VideoCollectionUiLoaderParam(
-        DOCML_NAME_VC_VIDEOLISTWIDGET,
-        DOCML_VIDEOCOLLECTIONVIEW_FILE,
-        true,
-        VideoCollectionUiLoaderParam::LoadPhasePrimary));
+                   DOCML_NAME_VC_VIDEOLISTWIDGET,
+                   DOCML_VIDEOCOLLECTIONVIEW_FILE,
+                   true,
+                   videoListPhase));
+    params.append(VideoCollectionUiLoaderParam(
+                   DOCML_NAME_VC_COLLECTIONWIDGET,
+                   DOCML_VIDEOCOLLECTIONVIEW_FILE,
+                   DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
+                   true,
+                   collectionListPhase));
+        
     params.append(VideoCollectionUiLoaderParam(
         DOCML_NAME_OPTIONS_MENU,
         DOCML_VIDEOCOLLECTIONVIEW_FILE,
@@ -180,13 +196,7 @@
         DOCML_NAME_SORT_BY_SIZE,
         DOCML_VIDEOCOLLECTIONVIEW_FILE,
         false,
-        VideoCollectionUiLoaderParam::LoadPhaseSecondary));
-    params.append(VideoCollectionUiLoaderParam(
-        DOCML_NAME_VC_COLLECTIONWIDGET,
-        DOCML_VIDEOCOLLECTIONVIEW_FILE,
-        DOCML_VIDEOCOLLECTIONVIEW_SECTION_LIST,
-        true,
-        VideoCollectionUiLoaderParam::LoadPhaseSecondary));
+        VideoCollectionUiLoaderParam::LoadPhaseSecondary));   
     params.append(VideoCollectionUiLoaderParam(
         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET,
         DOCML_VIDEOCOLLECTIONVIEW_FILE,
@@ -222,6 +232,17 @@
     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhasePrimary);
     params.clear();
     
+    if(videoListPhase == VideoCollectionUiLoaderParam::LoadPhasePrimary)
+    {
+        mCurrentList = mUiLoader->findWidget<VideoListWidget>(
+                                DOCML_NAME_VC_VIDEOLISTWIDGET);
+    }
+    else
+    {
+        mCurrentList = mUiLoader->findWidget<VideoListWidget>(
+                                    DOCML_NAME_VC_COLLECTIONWIDGET);
+    }
+    
     return 0;
 }
 
@@ -294,7 +315,10 @@
 {
 	FUNC_LOG;
     mUiLoader->loadPhase(VideoCollectionUiLoaderParam::LoadPhaseSecondary);
-	emit doDelayeds();
+	if(mCurrentList)
+	{
+	    mCurrentList->doDelayedsSlot();
+	}
 }
 
 // ---------------------------------------------------------------------------
@@ -375,6 +399,8 @@
     
     if(mCurrentList)
     {
+        VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel();
+        VideoCollectionViewUtils::saveWidgetLevel(level);
         mCurrentList->deactivate();
     }
 }
@@ -473,8 +499,14 @@
         	mToolbarActions[ETBActionServices]->setCheckable(false);
         }
 
-        // Allvideos is checked at creation phase
-        mToolbarActions[ETBActionAllVideos]->setChecked(true);
+        if(mCurrentList->getLevel() == VideoCollectionCommon::ELevelCategory)
+        {
+            mToolbarActions[ETBActionCollections]->setChecked(true);
+        }
+        else
+        {
+            mToolbarActions[ETBActionAllVideos]->setChecked(true);
+        }
 
         bar->addActions(mToolbarViewsActionGroup->actions());
     }
@@ -667,39 +699,26 @@
 int VideoListView::activateVideosView()
 {
     FUNC_LOG;
-    VideoListWidget *videoList =
-        mUiLoader->findWidget<VideoListWidget>(
-            DOCML_NAME_VC_VIDEOLISTWIDGET);
-    if (videoList)
+
+    if(!mCurrentList)
+    {
+        return -1;
+    }
+    VideoCollectionCommon::TCollectionLevels level = mCurrentList->getLevel(); 
+
+    int result = mCurrentList->activate(level);
+    if(result < 0)
     {
-        VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelVideos;
-        if (mCurrentList)
-        {
-            level = mCurrentList->getLevel();
-        }
-        else
-        {
-            mCurrentList = videoList;
-        }
-        
-        int result = mCurrentList->activate(level);
-        if(result < 0)
-        {
-            ERROR(result, "VideoListView::activateVideosView() failed to activate.");
-            // activate failed, deactivate view so we get rid of dangling connections.
-            deactivateView();
-            return -1;
-        }
-        
-        if (createToolbar() != 0)
-        {
-            ERROR(result, "VideoListView::activateVideosView() failed to create toolbar.");
-            deactivateView();
-            return -1;
-        }
+        ERROR(result, "VideoListView::activateVideosView() failed to activate.");
+        // activate failed, deactivate view so we get rid of dangling connections.
+        deactivateView();
+        return -1;
     }
-    else
+    
+    if (createToolbar() != 0)
     {
+        ERROR(result, "VideoListView::activateVideosView() failed to create toolbar.");
+        deactivateView();
         return -1;
     }
     
@@ -858,9 +877,7 @@
         
         // activate video collection widget
         mCurrentList = collectionWidget;
-        mCurrentList->activate(VideoCollectionCommon::ELevelCategory);
-        
-        VideoSortFilterProxyModel &model = mCurrentList->getModel(); 
+        mCurrentList->activate(VideoCollectionCommon::ELevelCategory);        
 
         // the collection view is not empty, so we should hide the hint in advance.
         showHint(false);
@@ -1425,15 +1442,24 @@
     if (name.compare(DOCML_NAME_VC_VIDEOLISTWIDGET) == 0)
     {
         connect(object, SIGNAL(command(int)), this, SIGNAL(command(int)));
-        connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
+        if(mCurrentList != object)
+        {
+            // this widget not yet activated so it's has been created on the second phase
+            // safe to call doDelayed right away
+            qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
+        }
     }
     else if (name.compare(DOCML_NAME_VC_COLLECTIONWIDGET) == 0)
     {
         connect(
             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
-            connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
-            emit(doDelayeds());
+        if(mCurrentList != object)
+        {
+            // this widget not yet activated so it's has been created on the second phase
+            // safe to call doDelayed right away
+            qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
+        }
     }
     else if (name.compare(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET) == 0)
     {
@@ -1441,8 +1467,12 @@
         connect(
             object, SIGNAL(collectionOpened(bool, const QString&, const QModelIndex&)),
             this, SLOT(collectionOpenedSlot(bool, const QString&, const QModelIndex&)));
-            connect(this, SIGNAL(doDelayeds()), object, SLOT(doDelayedsSlot()));
-            emit(doDelayeds());
+        if(mCurrentList != object)
+        {
+            // this widget not yet activated so it's has been created on the second phase
+            // safe to call doDelayed right away
+            qobject_cast<VideoListWidget*>(object)->doDelayedsSlot();
+        }        
     }
     else if (name.compare(DOCML_NAME_OPTIONS_MENU) == 0)
     {