videocollection/videocollectionview/src/videolistview.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
    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: 97 %
    18 // Version : %version: 101 %
    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>
    56     , mUiUtils( VideoCollectionViewUtils::instance() )
    56     , mUiUtils( VideoCollectionViewUtils::instance() )
    57     , mWrapper( VideoCollectionWrapper::instance() )
    57     , mWrapper( VideoCollectionWrapper::instance() )
    58     , mUiLoader( uiLoader )
    58     , mUiLoader( uiLoader )
    59     , mIsService( false )
    59     , mIsService( false )
    60     , mModelReady( false )
    60     , mModelReady( false )
    61     , mTransitionOngoing( false )
       
    62     , mHintLevel( VideoHintWidget::AllVideos )
    61     , mHintLevel( VideoHintWidget::AllVideos )
    63     , mVideoServices( 0 )
    62     , mVideoServices( 0 )
    64     , mCurrentList( 0 )
    63     , mCurrentList( 0 )
    65     , mToolbarViewsActionGroup( 0 )
    64     , mToolbarViewsActionGroup( 0 )
    66     , mToolbarCollectionActionGroup( 0 )
    65     , mToolbarCollectionActionGroup( 0 )
   298 // ---------------------------------------------------------------------------
   297 // ---------------------------------------------------------------------------
   299 //
   298 //
   300 void VideoListView::modelReadySlot()
   299 void VideoListView::modelReadySlot()
   301 {
   300 {
   302 	FUNC_LOG;
   301 	FUNC_LOG;
       
   302 	
       
   303 	// if mModelReady is false, then it means that this is the first time modelReady
       
   304 	// signal fires. Signaling that view is ready.
       
   305 	if(!mModelReady)
       
   306 	{
       
   307 	    emit viewReady();
       
   308 	}
       
   309 	
   303     mModelReady = true;
   310     mModelReady = true;
   304     
   311     
   305     // since the reset signal arrives after
   312     // since the reset signal arrives after
   306     // layout changed, need to make sure that
   313     // layout changed, need to make sure that
   307     // view is updated in case needed
   314     // view is updated in case needed
   537 
   544 
   538     if (mToolbarViewsActionGroup && mToolbarCollectionActionGroup && !mIsService)
   545     if (mToolbarViewsActionGroup && mToolbarCollectionActionGroup && !mIsService)
   539     {
   546     {
   540         if (show)
   547         if (show)
   541         {
   548         {
   542             mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
   549         	mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
   543 
   550         }
   544             if(mCurrentList->getLevel() == VideoCollectionCommon::ELevelDefaultColl) 
   551         else if(mToolbarActions[ETBActionRemoveVideos]->isVisible() == false)
   545             {
   552 		{
   546                 mToolbarActions[ETBActionAddVideos]->setVisible(false);
   553         	mToolbarActions[ETBActionRemoveVideos]->setVisible(true);
   547             } 
   554 		}
   548         }
       
   549         else
       
   550         {
       
   551             if(mToolbarActions[ETBActionRemoveVideos]->isVisible() == false)
       
   552             {
       
   553                 mToolbarActions[ETBActionRemoveVideos]->setVisible(true);
       
   554             }
       
   555             if(mToolbarActions[ETBActionAddVideos]->isVisible() == false) 
       
   556             {
       
   557                 mToolbarActions[ETBActionAddVideos]->setVisible(true);
       
   558             }
       
   559         }
       
   560     }
   555     }
   561 
   556 
   562     // prepare sublabel
   557     // prepare sublabel
   563     HbGroupBox *subLabel =
   558     HbGroupBox *subLabel =
   564         mUiLoader->findWidget<HbGroupBox>(
   559         mUiLoader->findWidget<HbGroupBox>(
   725                         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
   720                         DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
   726                 if (collectionContentWidget)
   721                 if (collectionContentWidget)
   727                 {
   722                 {
   728                     // no need to deactivate since there cannot be previous widget
   723                     // no need to deactivate since there cannot be previous widget
   729                     mCurrentList = collectionContentWidget;
   724                     mCurrentList = collectionContentWidget;
   730                     
       
   731                     // hide toolbar
       
   732                     HbToolBar *toolBar = this->toolBar();
       
   733                     if (toolBar)
       
   734                     {
       
   735                         toolBar->hide();
       
   736                     }
       
   737                     
   725                     
   738                     // resolve collection name
   726                     // resolve collection name
   739                     if (itemId.iId1 == KVcxMvcCategoryIdDownloads)
   727                     if (itemId.iId1 == KVcxMvcCategoryIdDownloads)
   740                     {
   728                     {
   741                         mCollectionName = hbTrId("txt_videos_dblist_downloaded");
   729                         mCollectionName = hbTrId("txt_videos_dblist_downloaded");
   751                     // open the model
   739                     // open the model
   752                     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   740                     VideoSortFilterProxyModel &model = mCurrentList->getModel();
   753                     model.openItem(itemId);
   741                     model.openItem(itemId);
   754                     
   742                     
   755                     // sort model
   743                     // sort model
   756                     model.doSorting(VideoCollectionCommon::KeyDateTime, Qt::AscendingOrder);
   744                     int sortRole = VideoCollectionCommon::KeyDateTime;
       
   745                     if (mIsService &&
       
   746                         mVideoServices)
       
   747                     {
       
   748                         // TODO: sorting roles needs to be defined somewhere
       
   749                         sortRole = mVideoServices->sortRole();
       
   750                         switch (sortRole)
       
   751                         {
       
   752                             // sort by name
       
   753                             case 2:
       
   754                             {
       
   755                                 sortRole = VideoCollectionCommon::KeyTitle;
       
   756                                 break;
       
   757                             }
       
   758                             // sort by size
       
   759                             case 3:
       
   760                             {
       
   761                                 sortRole = VideoCollectionCommon::KeySizeValue;
       
   762                                 break;
       
   763                             }
       
   764                             // date & time
       
   765                             case 1:
       
   766                                 // fall through
       
   767                             default:
       
   768                             {
       
   769                                 sortRole = VideoCollectionCommon::KeyDateTime;
       
   770                                 break;
       
   771                             }
       
   772                         }
       
   773                     }
       
   774                     model.doSorting(sortRole, Qt::AscendingOrder);
   757                     
   775                     
   758                     // set hint level to collections
   776                     // set hint level to collections
   759                     setHintLevel(VideoHintWidget::Collection);
   777                     setHintLevel(VideoHintWidget::Collection);
   760                 }
   778                 }
   761                 else
   779                 else
   928 	if (mCurrentList == mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET))
   946 	if (mCurrentList == mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET))
   929 	{
   947 	{
   930 		mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET)->getModel().doSorting(role, order);	
   948 		mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET)->getModel().doSorting(role, order);	
   931 	}
   949 	}
   932 
   950 
   933 	// save sorting values
   951     // save sorting values only if the application is not started as a service
   934 	mUiUtils.saveSortingValues(role, order, mCurrentList->getLevel());
   952 	if (!mIsService)
       
   953 	{
       
   954 	    // save sorting values
       
   955 	    mUiUtils.saveSortingValues(role, order, mCurrentList->getLevel());
       
   956 	}
   935 }
   957 }
   936 
   958 
   937 // -------------------------------------------------------------------------------------------------
   959 // -------------------------------------------------------------------------------------------------
   938 // aboutToChangeOrientationSlot()
   960 // aboutToChangeOrientationSlot()
   939 // hide all items in the window during orientation change
   961 // hide all items in the window during orientation change
   993     if(!mCurrentList)
  1015     if(!mCurrentList)
   994     {
  1016     {
   995         return;
  1017         return;
   996     }
  1018     }
   997     
  1019     
   998     VideoSortFilterProxyModel &model = mCurrentList->getModel();
       
   999     
       
  1000     bool ok = false;
       
  1001     // query a name for the collection
  1020     // query a name for the collection
  1002     QString label(hbTrId("txt_videos_title_enter_name"));
  1021     QString label(hbTrId("txt_videos_title_enter_name"));
  1003     QString text(hbTrId("txt_videos_dialog_entry_new_collection"));
  1022     QString text(hbTrId("txt_videos_dialog_entry_new_collection"));
  1004     text = HbInputDialog::getText(label, text, &ok);
  1023     
  1005     if (ok && text.length())
  1024     HbInputDialog *dialog = new HbInputDialog();
  1006     {
  1025     dialog->setAttribute(Qt::WA_DeleteOnClose);
       
  1026     dialog->getText(label, this, SLOT(createCollectionDialogFinished(HbAction *)), text);
       
  1027 }
       
  1028 
       
  1029 // -------------------------------------------------------------------------------------------------
       
  1030 // createCollectionDialogFinished
       
  1031 // -------------------------------------------------------------------------------------------------
       
  1032 //
       
  1033 void VideoListView::createCollectionDialogFinished(HbAction *action)
       
  1034 {
       
  1035     FUNC_LOG;
       
  1036     Q_UNUSED(action);
       
  1037     
       
  1038     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
  1039     
       
  1040     QVariant variant = dialog->value();
       
  1041     
       
  1042     if(dialog->actions().first() == action && variant.isValid())
       
  1043     {
       
  1044         VideoSortFilterProxyModel &model = mCurrentList->getModel();
       
  1045 
  1007         // resolve collection true name and add new album
  1046         // resolve collection true name and add new album
  1008         text = model.resolveAlbumName(text);
  1047         QString text = model.resolveAlbumName(variant.toString());
  1009         
  1048         
  1010         // when collection reports about new collection, we open it right away,
  1049         if(text.length())
  1011         // for that, connect to rowsInserted so that the new album can be opened
  1050         {
  1012         if(!connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
  1051             // when collection reports about new collection, we open it right away,
  1013                     this, SLOT(openNewAlbumSlot(const QModelIndex&, int, int))))
  1052             // for that, connect to rowsInserted so that the new album can be opened
  1014         {
  1053             if(!connect(&model, SIGNAL(rowsInserted(const QModelIndex&, int, int)),
  1015             return;
  1054                         this, SLOT(openNewAlbumSlot(const QModelIndex&, int, int))))
  1016         }
  1055             {
  1017         
  1056                 return;
  1018         model.addNewAlbum(text);
  1057             }
       
  1058             
       
  1059             model.addNewAlbum(text);
       
  1060         }
  1019     }
  1061     }
  1020 }
  1062 }
  1021 
  1063 
  1022 // -------------------------------------------------------------------------------------------------
  1064 // -------------------------------------------------------------------------------------------------
  1023 // addVideosToCollectionSlot
  1065 // addVideosToCollectionSlot
  1268 void VideoListView::collectionOpenedSlot(bool collectionOpened,
  1310 void VideoListView::collectionOpenedSlot(bool collectionOpened,
  1269     const QString& collection,
  1311     const QString& collection,
  1270     const QModelIndex &index)
  1312     const QModelIndex &index)
  1271 {
  1313 {
  1272 	FUNC_LOG;
  1314 	FUNC_LOG;
  1273 	if(mTransitionOngoing)
  1315 
  1274 	{
  1316     // clear toolbar actions.
  1275 		return;
  1317     toolBar()->clearActions();
  1276 	}
  1318 
  1277 	else
  1319     VideoListWidget *collectionContentWidget =
  1278 	{
  1320                 mUiLoader->findWidget<VideoListWidget>(
  1279 	    // clear toolbar actions.
  1321                     DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
  1280 	    toolBar()->clearActions();
  1322     
  1281 	}
  1323     if(!collectionContentWidget)
  1282 
  1324     {
       
  1325         return;
       
  1326     }
       
  1327     // update collection specific information
       
  1328 	mCollectionName = collection;
       
  1329 	
       
  1330 	// disable collection content animations during widget change        
       
  1331 	HbAbstractItemView::ItemAnimations animationState = collectionContentWidget->enabledAnimations();
       
  1332 	collectionContentWidget->setEnabledAnimations(HbAbstractItemView::None);
       
  1333 	
  1283 	if(collectionOpened)
  1334 	if(collectionOpened)
  1284     {
  1335     {
  1285         if(!index.isValid())
  1336         // open album view        
  1286         {   
  1337         if (!index.isValid() || !mCurrentList || mCurrentList == collectionContentWidget)
       
  1338         {
       
  1339             // no currentlist or currentlist is already collection content -list 
       
  1340             collectionContentWidget->setEnabledAnimations(animationState);
  1287             return;
  1341             return;
  1288         }
  1342         }
  1289         
  1343         
  1290         // open album view
  1344         // get item id before deactivating
  1291         VideoListWidget *collectionContentWidget =
  1345         TMPXItemId itemId = mCurrentList->getModel().getMediaIdAtIndex(index);
  1292             mUiLoader->findWidget<VideoListWidget>(
       
  1293                 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
  1294         
  1346         
  1295         if (!mCurrentList || mCurrentList == collectionContentWidget)
  1347         // get level from the item to be opened only default 
  1296         {
  1348         // or user defined collections can be activated here
  1297             // no currentlist or currentlist is already list 
  1349         VideoCollectionCommon::TCollectionLevels level = VideoCollectionCommon::ELevelInvalid;
  1298             // we're about to transit
  1350         if(itemId.iId2 == KVcxMvcMediaTypeCategory)
       
  1351         {
       
  1352             level = VideoCollectionCommon::ELevelDefaultColl; 
       
  1353         }
       
  1354         else if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
       
  1355         {
       
  1356             level = VideoCollectionCommon::ELevelAlbum; 
       
  1357         }
       
  1358         else 
       
  1359         {
       
  1360             collectionContentWidget->setEnabledAnimations(animationState);
  1299             return;
  1361             return;
  1300         }
  1362         }
  1301 
       
  1302         // get item id before deactivating
       
  1303         TMPXItemId itemId = TMPXItemId::InvalidId();
       
  1304         itemId = mCurrentList->getModel().getMediaIdAtIndex(index);
       
  1305         
  1363         
  1306         // only category or album can be activated here
  1364         // Start fetching content before changing.
  1307         if(itemId == TMPXItemId::InvalidId() ||
       
  1308            (itemId.iId2 != KVcxMvcMediaTypeCategory && 
       
  1309             itemId.iId2 != KVcxMvcMediaTypeAlbum))
       
  1310         {
       
  1311             return;
       
  1312         }
       
  1313         
       
  1314         // Send level that is opened with the effect.
       
  1315         QVariant nextLevel;
       
  1316         if(itemId.iId2 ==  KVcxMvcMediaTypeCategory)
       
  1317         {
       
  1318             nextLevel = QVariant(VideoCollectionCommon::ELevelDefaultColl);
       
  1319         }
       
  1320         else if(itemId.iId2 == KVcxMvcMediaTypeAlbum)
       
  1321         {
       
  1322             nextLevel = QVariant(VideoCollectionCommon::ELevelAlbum);
       
  1323         }            
       
  1324         
       
  1325         // Start fetching content.
       
  1326         collectionContentWidget->getModel().openItem(itemId);
  1365         collectionContentWidget->getModel().openItem(itemId);
  1327         
  1366         
  1328         HbEffect::start(collectionContentWidget,
  1367         // deactivat current widget.
  1329                         EFFECT_SLIDE_IN_TO_LEFT,
  1368         mCurrentList->deactivate();
  1330                         this,
       
  1331                         "finishCollectionOpenedSlot",
       
  1332                         nextLevel);
       
  1333         
  1369         
  1334         mTransitionOngoing = true;
  1370         // activate video collection content widget and set it as current list.
       
  1371         mCurrentList = collectionContentWidget;
       
  1372         mCurrentList->activate(level);
       
  1373 
       
  1374         updateSubLabel();
       
  1375 
       
  1376         // setup correct sorting, collection content contains always a list of videos so we use 
       
  1377         // ELevelVideos as target for sorting
       
  1378         VideoCollectionViewUtils::sortModel(&mCurrentList->getModel(), false, VideoCollectionCommon::ELevelVideos);
       
  1379         mCurrentList->getModel().invalidate();
       
  1380         
       
  1381         // update hint widget for correct content
       
  1382         setHintLevel(VideoHintWidget::Collection);
       
  1383         showHint();
       
  1384 
       
  1385         // update toolbar for albums, default categories don't have one.
       
  1386         if(level == VideoCollectionCommon::ELevelAlbum && 
       
  1387            mToolbarCollectionActionGroup && mToolbarActions.contains(ETBActionCollections))
       
  1388         {
       
  1389             mToolbarActions[ETBActionCollections]->setChecked(false);
       
  1390             toolBar()->addActions(mToolbarCollectionActionGroup->actions());
       
  1391         }
  1335     }
  1392     }
  1336     else
  1393     else
  1337     {
  1394     {
  1338         // open categories view.
  1395         // open collection view
  1339         VideoListWidget *collectionContentWidget =
  1396         openCollectionViewSlot();
  1340             mUiLoader->findWidget<VideoListWidget>(
       
  1341                 DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
  1342         
  1397         
  1343         HbEffect::start(collectionContentWidget,
  1398         // update toolbar
  1344                         EFFECT_SLIDE_OUT_TO_LEFT,
  1399         if(mToolbarViewsActionGroup && mToolbarActions.contains(ETBActionCollections))
  1345                         this,
  1400         {
  1346                         "finishCollectionClosedSlot");
  1401             toolBar()->addActions(mToolbarViewsActionGroup->actions());
  1347         
  1402             mToolbarActions[ETBActionCollections]->setChecked(true);
  1348         mTransitionOngoing = true;
  1403         }
  1349     }
  1404     }
  1350 	// update collection specific information
  1405 	// restore animations for collection content widget
  1351 	mCollectionName = collection;
  1406 	collectionContentWidget->setEnabledAnimations(animationState);
  1352 }
  1407 	
  1353 
       
  1354 // -------------------------------------------------------------------------------------------------
       
  1355 // finishCollectionOpenedSlot
       
  1356 // -------------------------------------------------------------------------------------------------
       
  1357 //
       
  1358 void VideoListView::finishCollectionOpenedSlot(const HbEffect::EffectStatus &status)
       
  1359 {
       
  1360 	FUNC_LOG;
       
  1361     Q_UNUSED(status);
       
  1362     
       
  1363     mTransitionOngoing = false;
       
  1364     
       
  1365     // deactivat current widget.
       
  1366     mCurrentList->deactivate();
       
  1367     
       
  1368     // activate video collection content widget.
       
  1369     mCurrentList = mUiLoader->findWidget<VideoListWidget>(
       
  1370                     DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
  1371 
       
  1372     if(!mCurrentList || !status.userData.isValid())
       
  1373     {
       
  1374         return;
       
  1375     }
       
  1376     
       
  1377     updateSubLabel();
       
  1378 
       
  1379     VideoCollectionCommon::TCollectionLevels level =
       
  1380             static_cast<VideoCollectionCommon::TCollectionLevels>(status.userData.toInt());
       
  1381 	mCurrentList->activate(level);
       
  1382 
       
  1383     VideoCollectionViewUtils::sortModel(&mCurrentList->getModel(), false, VideoCollectionCommon::ELevelVideos);
       
  1384     mCurrentList->getModel().invalidate();
       
  1385 
       
  1386     // update hint widget
       
  1387     setHintLevel(VideoHintWidget::Collection);
       
  1388     showHint();
       
  1389 
       
  1390     // update toolbar for albums, default categories don't have one.
       
  1391     if(level == VideoCollectionCommon::ELevelAlbum && 
       
  1392        mToolbarCollectionActionGroup && mToolbarActions.contains(ETBActionCollections))
       
  1393     {
       
  1394         mToolbarActions[ETBActionCollections]->setChecked(false);
       
  1395         toolBar()->addActions(mToolbarCollectionActionGroup->actions());
       
  1396     }
       
  1397 }
       
  1398 
       
  1399 // -------------------------------------------------------------------------------------------------
       
  1400 // finishCollectionClosedSlot
       
  1401 // -------------------------------------------------------------------------------------------------
       
  1402 //
       
  1403 void VideoListView::finishCollectionClosedSlot(const HbEffect::EffectStatus &status)
       
  1404 {
       
  1405 	FUNC_LOG;
       
  1406     Q_UNUSED(status);
       
  1407     
       
  1408     mTransitionOngoing = false;
       
  1409     
       
  1410     // open collection view
       
  1411     openCollectionViewSlot();
       
  1412     
       
  1413     // update toolbar
       
  1414     if(mToolbarViewsActionGroup && mToolbarActions.contains(ETBActionCollections))
       
  1415     {
       
  1416         toolBar()->addActions(mToolbarViewsActionGroup->actions());
       
  1417         mToolbarActions[ETBActionCollections]->setChecked(true);
       
  1418     }
       
  1419 }
  1408 }
  1420 
  1409 
  1421 // -------------------------------------------------------------------------------------------------
  1410 // -------------------------------------------------------------------------------------------------
  1422 // objectReadySlot
  1411 // objectReadySlot
  1423 // -------------------------------------------------------------------------------------------------
  1412 // -------------------------------------------------------------------------------------------------