videocollection/videocollectionview/src/videolistmenu.cpp
changeset 65 a9d57bd8d7b7
child 67 72c709219fcd
equal deleted inserted replaced
62:0e1e938beb1a 65:a9d57bd8d7b7
       
     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:   Videolist view class source code
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 1 %
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include <hbmenu.h>
       
    23 
       
    24 #include "videolistmenu.h"
       
    25 #include "videolistselectiondialog.h"
       
    26 #include "videocollectionviewutils.h"
       
    27 #include "videolistwidget.h"
       
    28 #include "videolistview.h"
       
    29 #include "videocollectioncommon.h"
       
    30 #include "videoproxymodelgeneric.h"
       
    31 #include "videocollectionuiloader.h"
       
    32 #include "videocollectiontrace.h"
       
    33 
       
    34 // ---------------------------------------------------------------------------
       
    35 // Constructor
       
    36 // ---------------------------------------------------------------------------
       
    37 //
       
    38 VideoListMenu::VideoListMenu(VideoCollectionUiLoader *uiLoader, VideoListView* parent) 
       
    39     : QObject(parent)
       
    40     , mUiUtils(VideoCollectionViewUtils::instance())
       
    41     , mUiLoader(uiLoader)
       
    42     , mListView(parent)
       
    43     , mVideoServices(0)
       
    44 {
       
    45 	FUNC_LOG;
       
    46 }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Destructor
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 VideoListMenu::~VideoListMenu()
       
    53 {
       
    54 	FUNC_LOG;
       
    55     
       
    56     mSortingRoles.clear();
       
    57     
       
    58     if(mVideoServices)
       
    59     {
       
    60         mVideoServices->decreaseReferenceCount();
       
    61         mVideoServices = 0;
       
    62     }
       
    63 }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // initializeView()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 int VideoListMenu::initializeMenu()
       
    70 {
       
    71 	FUNC_LOG;
       
    72 	if(!mUiLoader)
       
    73 	{
       
    74 		return -1;
       
    75 	}
       
    76 	
       
    77     if (mUiUtils.isService())
       
    78     {
       
    79         INFO("VideoListMenu::initializeMenu() initializing service.");
       
    80         if (!mVideoServices)
       
    81         {
       
    82             mVideoServices = VideoServices::instance();
       
    83         }
       
    84          
       
    85     }
       
    86 	
       
    87     // start loading objects and widgets
       
    88     QList<VideoCollectionUiLoaderParam> params;
       
    89     
       
    90     params.append(VideoCollectionUiLoaderParam(
       
    91         DOCML_NAME_OPTIONS_MENU,
       
    92         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
    93         true,
       
    94         VideoCollectionUiLoaderParam::LoadPhasePrimary));
       
    95     params.append(VideoCollectionUiLoaderParam(
       
    96         DOCML_NAME_ADD_TO_COLLECTION,
       
    97         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
    98         false,
       
    99         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   100     params.append(VideoCollectionUiLoaderParam(
       
   101         DOCML_NAME_CREATE_COLLECTION,
       
   102         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   103         false,
       
   104         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   105     params.append(VideoCollectionUiLoaderParam(
       
   106         DOCML_NAME_DELETE_MULTIPLE,
       
   107         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   108         false,
       
   109         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   110     params.append(VideoCollectionUiLoaderParam(
       
   111         DOCML_NAME_SORT_MENU,
       
   112         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   113         true,
       
   114         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   115     params.append(VideoCollectionUiLoaderParam(
       
   116         DOCML_NAME_SORT_BY_DATE,
       
   117         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   118         false,
       
   119         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   120     params.append(VideoCollectionUiLoaderParam(
       
   121         DOCML_NAME_SORT_BY_NAME,
       
   122         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   123         false,
       
   124         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   125     params.append(VideoCollectionUiLoaderParam(
       
   126         DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS,
       
   127         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   128         false,
       
   129         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   130     params.append(VideoCollectionUiLoaderParam(
       
   131         DOCML_NAME_SORT_BY_SIZE,
       
   132         DOCML_VIDEOCOLLECTIONVIEW_FILE,
       
   133         false,
       
   134         VideoCollectionUiLoaderParam::LoadPhaseSecondary));
       
   135     
       
   136     mUiLoader->addData(params,
       
   137         this,
       
   138         SLOT(objectReadySlot(QObject*, const QString&)));
       
   139     
       
   140     params.clear();
       
   141     
       
   142     return 0;
       
   143 }
       
   144 
       
   145 // ---------------------------------------------------------------------------
       
   146 // showAction()
       
   147 // ---------------------------------------------------------------------------
       
   148 //
       
   149 void VideoListMenu::showAction(bool show, const QString &name)
       
   150 {
       
   151 	FUNC_LOG;
       
   152     HbAction *action = mUiLoader->findObject<HbAction>(name);
       
   153     if (!action)
       
   154     {
       
   155         // must be menu widget
       
   156         HbMenu *menu = mUiLoader->findWidget<HbMenu>(name);
       
   157         if (menu)
       
   158         {
       
   159             action = menu->menuAction();
       
   160         }
       
   161     }
       
   162 
       
   163     // hide or show action
       
   164     if (action)
       
   165     {
       
   166         action->setVisible(show);
       
   167     }
       
   168 }
       
   169 
       
   170 // ---------------------------------------------------------------------------
       
   171 // startSorting()
       
   172 // ---------------------------------------------------------------------------
       
   173 //
       
   174 void VideoListMenu::startSorting()
       
   175 {
       
   176 	FUNC_LOG;
       
   177 	
       
   178     HbMenu *optionsMenu =
       
   179         mUiLoader->findWidget<HbMenu>(
       
   180             DOCML_NAME_OPTIONS_MENU);
       
   181     
       
   182     VideoListWidget* currentList = mListView->getCurrentList();
       
   183     
       
   184     if (optionsMenu && currentList)
       
   185     {
       
   186         // get sorting role from active action
       
   187         HbAction* action = optionsMenu->activeAction();
       
   188         HbMenu* sortMenu = mUiLoader->findWidget<HbMenu>(DOCML_NAME_SORT_MENU);
       
   189         if(action == sortMenu->menuAction()) // make sure that active action is the sort menu. 
       
   190         {
       
   191             HbAction* action = sortMenu->activeAction();
       
   192             if(action)
       
   193             {
       
   194                 doSorting(mSortingRoles[action]);
       
   195             }
       
   196         }
       
   197     }
       
   198 }
       
   199 
       
   200 // ---------------------------------------------------------------------------
       
   201 // doSorting()
       
   202 // ---------------------------------------------------------------------------
       
   203 //
       
   204 void VideoListMenu::doSorting(int role)
       
   205 {
       
   206 	FUNC_LOG;
       
   207 	
       
   208     VideoListWidget* currentList = mListView->getCurrentList();
       
   209     
       
   210 	if(!currentList || !currentList->getModel())
       
   211 	{
       
   212 	    // no list or model, cannot sort
       
   213 	    return;
       
   214 	}
       
   215 	// sort model
       
   216 	Qt::SortOrder order(Qt::AscendingOrder);
       
   217 	VideoProxyModelGeneric *model = currentList->getModel();
       
   218 	if(model->sortRole() == role && model->sortOrder() == Qt::AscendingOrder)
       
   219 	{
       
   220 		order = Qt::DescendingOrder;
       
   221 	}
       
   222 	model->doSorting(role, order);
       
   223 	
       
   224 	// for video related sorting, all videos list and collection content
       
   225 	// list, sorting orders are same all the time
       
   226 	VideoListWidget *anotherVideosList = 0;
       
   227 	VideoCollectionCommon::TCollectionLevels level = currentList->getLevel();
       
   228 	if (level == VideoCollectionCommon::ELevelDefaultColl ||
       
   229 	    level == VideoCollectionCommon::ELevelAlbum)
       
   230 	{
       
   231 	    anotherVideosList = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_VIDEOLISTWIDGET);
       
   232 	}
       
   233 	else if(level == VideoCollectionCommon::ELevelVideos)
       
   234 	{
       
   235 	    anotherVideosList = mUiLoader->findWidget<VideoListWidget>(DOCML_NAME_VC_COLLECTIONCONTENTWIDGET);
       
   236 	}
       
   237     if(anotherVideosList && anotherVideosList->getModel())
       
   238     {
       
   239         anotherVideosList->getModel()->doSorting(role, order);
       
   240     }
       
   241 
       
   242     // save sorting values only if the application is not started as a service
       
   243 	if (!mVideoServices)
       
   244 	{
       
   245 	    // save sorting values
       
   246 	    mUiUtils.saveSortingValues(role, order, currentList->getLevel());
       
   247 	}
       
   248 }
       
   249 
       
   250 // -------------------------------------------------------------------------------------------------
       
   251 // deleteItemsSlot
       
   252 // -------------------------------------------------------------------------------------------------
       
   253 //
       
   254 void VideoListMenu::deleteItemsSlot()
       
   255 {
       
   256 	FUNC_LOG;
       
   257 
       
   258     VideoListSelectionDialog *dialog =
       
   259         mUiLoader->findWidget<VideoListSelectionDialog>(
       
   260             DOCML_NAME_DIALOG);
       
   261     
       
   262     if (dialog)
       
   263     {
       
   264         TMPXItemId collectionId = mListView->getCurrentList()->getModel()->getOpenItem();
       
   265         dialog->setupContent(VideoListSelectionDialog::EDeleteVideos, collectionId); 
       
   266         dialog->exec();
       
   267     }
       
   268 }
       
   269 
       
   270 // -------------------------------------------------------------------------------------------------
       
   271 // createCollectionSlot
       
   272 // -------------------------------------------------------------------------------------------------
       
   273 //
       
   274 void VideoListMenu::createCollectionSlot()
       
   275 {
       
   276 	FUNC_LOG;
       
   277      
       
   278     VideoListSelectionDialog *dialog =
       
   279         mUiLoader->findWidget<VideoListSelectionDialog>(
       
   280             DOCML_NAME_DIALOG);
       
   281     
       
   282     if (!dialog)
       
   283     {
       
   284         // fatal: no selection dialog
       
   285         return;
       
   286     }
       
   287     
       
   288     dialog->setupContent(VideoListSelectionDialog::ECreateCollection, TMPXItemId::InvalidId());
       
   289     dialog->exec();
       
   290 }
       
   291 
       
   292 // -------------------------------------------------------------------------------------------------
       
   293 // addVideosToCollectionSlot
       
   294 // -------------------------------------------------------------------------------------------------
       
   295 //
       
   296 void VideoListMenu::addVideosToCollectionSlot()
       
   297 {
       
   298 	FUNC_LOG;
       
   299 	
       
   300     VideoListWidget* currentList = mListView->getCurrentList();
       
   301     
       
   302     if(!currentList || !currentList->getModel())
       
   303     {
       
   304         return;
       
   305     }
       
   306 
       
   307     VideoListSelectionDialog *dialog =
       
   308         mUiLoader->findWidget<VideoListSelectionDialog>(
       
   309             DOCML_NAME_DIALOG);
       
   310     
       
   311     if (!dialog)
       
   312     {
       
   313         // fatal: no selection dialog
       
   314         return;
       
   315     }
       
   316 
       
   317     TMPXItemId collectionId = currentList->getModel()->getOpenItem();
       
   318     dialog->setupContent(VideoListSelectionDialog::EAddToCollection, collectionId);
       
   319     dialog->exec();
       
   320 }
       
   321 
       
   322 // -------------------------------------------------------------------------------------------------
       
   323 // aboutToShowMainMenuSlot
       
   324 // -------------------------------------------------------------------------------------------------
       
   325 //
       
   326 void VideoListMenu::aboutToShowMainMenuSlot()
       
   327 {
       
   328     if (mVideoServices &&
       
   329         mVideoServices->currentService() == VideoServices::EBrowse)
       
   330     {
       
   331         prepareBrowseServiceMenu();
       
   332         return;
       
   333     }
       
   334     
       
   335     VideoListWidget* currentList = mListView->getCurrentList();
       
   336     
       
   337 	if (!currentList)
       
   338 	{
       
   339 		return;
       
   340 	}
       
   341 	
       
   342 	// hide all actions by default
       
   343     showAction(false, DOCML_NAME_ADD_TO_COLLECTION);
       
   344     showAction(false, DOCML_NAME_CREATE_COLLECTION);
       
   345     showAction(false, DOCML_NAME_DELETE_MULTIPLE);
       
   346     showAction(false, DOCML_NAME_SORT_BY_DATE);
       
   347     showAction(false, DOCML_NAME_SORT_BY_NAME);
       
   348     showAction(false, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
       
   349     showAction(false, DOCML_NAME_SORT_BY_SIZE);
       
   350     showAction(false, DOCML_NAME_SORT_MENU);
       
   351 
       
   352     // Create collection action is shown even when there's no videos. 
       
   353     if(currentList->getLevel() == VideoCollectionCommon::ELevelCategory && !mVideoServices)
       
   354     {
       
   355         showAction(true, DOCML_NAME_CREATE_COLLECTION);
       
   356     }
       
   357     
       
   358     //  No other actions shown if there's no videos.
       
   359     VideoProxyModelGeneric *model = currentList->getModel();
       
   360     if (!model || !model->rowCount())
       
   361     {
       
   362         return;
       
   363     }
       
   364     
       
   365     // get current sorting values
       
   366     int role;
       
   367     Qt::SortOrder order;
       
   368     model->getSorting(role, order);
       
   369 
       
   370     if(currentList->getLevel() == VideoCollectionCommon::ELevelVideos)
       
   371     {
       
   372         showAction(true, DOCML_NAME_SORT_MENU);
       
   373         showAction(true, DOCML_NAME_SORT_BY_DATE);
       
   374         showAction(true, DOCML_NAME_SORT_BY_NAME);
       
   375         showAction(true, DOCML_NAME_SORT_BY_SIZE);
       
   376 
       
   377         HbAction* action = mSortingRoles.key(role);
       
   378 		if (action)
       
   379 		{
       
   380 			action->setChecked(true);
       
   381 		}
       
   382 
       
   383         if (!mVideoServices)
       
   384         {
       
   385             showAction(true, DOCML_NAME_ADD_TO_COLLECTION);
       
   386             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
       
   387         }
       
   388     }
       
   389     else if(currentList->getLevel() == VideoCollectionCommon::ELevelCategory)
       
   390     {
       
   391         showAction(true, DOCML_NAME_SORT_MENU);
       
   392         showAction(true, DOCML_NAME_SORT_BY_NAME);
       
   393         showAction(true, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
       
   394     	
       
   395 		HbAction* action = mSortingRoles.key(role);
       
   396 		if (action)
       
   397 		{
       
   398 			action->setChecked(true);
       
   399 		}
       
   400     }
       
   401     else if(currentList->getLevel() == VideoCollectionCommon::ELevelDefaultColl ||
       
   402             currentList->getLevel() == VideoCollectionCommon::ELevelAlbum)
       
   403     {
       
   404         showAction(true, DOCML_NAME_SORT_MENU);
       
   405         showAction(true, DOCML_NAME_SORT_BY_DATE);
       
   406         showAction(true, DOCML_NAME_SORT_BY_NAME);
       
   407         showAction(true, DOCML_NAME_SORT_BY_SIZE);
       
   408 
       
   409         HbAction* action = mSortingRoles.key(role);
       
   410 		if (action)
       
   411 		{
       
   412 			action->setChecked(true);
       
   413 		}
       
   414 
       
   415         if (!mVideoServices)
       
   416         {
       
   417             showAction(true, DOCML_NAME_DELETE_MULTIPLE);
       
   418         }
       
   419     }
       
   420 }
       
   421 
       
   422 // -------------------------------------------------------------------------------------------------
       
   423 // prepareBrowseServiceMenu
       
   424 // -------------------------------------------------------------------------------------------------
       
   425 //
       
   426 void VideoListMenu::prepareBrowseServiceMenu()
       
   427 {
       
   428     VideoListWidget* currentList = mListView->getCurrentList();
       
   429     
       
   430     if (!currentList)
       
   431     {
       
   432         return;
       
   433     }
       
   434     
       
   435     // hide all actions by default
       
   436     showAction(false, DOCML_NAME_ADD_TO_COLLECTION);
       
   437     showAction(false, DOCML_NAME_CREATE_COLLECTION);
       
   438     showAction(false, DOCML_NAME_DELETE_MULTIPLE);
       
   439     showAction(false, DOCML_NAME_SORT_BY_DATE);
       
   440     showAction(false, DOCML_NAME_SORT_BY_NAME);
       
   441     showAction(false, DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS);
       
   442     showAction(false, DOCML_NAME_SORT_BY_SIZE);
       
   443     showAction(false, DOCML_NAME_SORT_MENU);
       
   444     
       
   445     VideoProxyModelGeneric *model = currentList->getModel();
       
   446     if (!model || !model->rowCount())
       
   447     {
       
   448         return;
       
   449     }
       
   450     
       
   451     // show delete action
       
   452     showAction(true, DOCML_NAME_DELETE_MULTIPLE);
       
   453     
       
   454     // show sort actions
       
   455     showAction(true, DOCML_NAME_SORT_MENU);
       
   456     showAction(true, DOCML_NAME_SORT_BY_DATE);
       
   457     showAction(true, DOCML_NAME_SORT_BY_NAME);
       
   458     showAction(true, DOCML_NAME_SORT_BY_SIZE);
       
   459     
       
   460     // set current sort action selected
       
   461     int role;
       
   462     Qt::SortOrder order;
       
   463     model->getSorting(role, order);
       
   464     HbAction* action = mSortingRoles.key(role);
       
   465     if (action)
       
   466     {
       
   467         action->setChecked(true);
       
   468     }
       
   469 }
       
   470 
       
   471 // -------------------------------------------------------------------------------------------------
       
   472 // objectReadySlot
       
   473 // -------------------------------------------------------------------------------------------------
       
   474 //
       
   475 void VideoListMenu::objectReadySlot(QObject *object, const QString &name)
       
   476 {
       
   477 	FUNC_LOG;
       
   478     
       
   479 	if (name.compare(DOCML_NAME_OPTIONS_MENU) == 0)
       
   480     {
       
   481         connect(
       
   482             object, SIGNAL(aboutToShow()), this, SLOT(aboutToShowMainMenuSlot()));
       
   483     }
       
   484     else if (name.compare(DOCML_NAME_SORT_BY_DATE) == 0)
       
   485     {
       
   486         HbAction *action = qobject_cast<HbAction*>(object);
       
   487         if (action)
       
   488         {
       
   489         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
       
   490             mSortingRoles[action] = VideoCollectionCommon::KeyDateTime;
       
   491         }
       
   492     }
       
   493     else if (name.compare(DOCML_NAME_SORT_BY_NAME) == 0)
       
   494     {
       
   495         HbAction *action = qobject_cast<HbAction*>(object);
       
   496         if (action)
       
   497         {
       
   498         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
       
   499             mSortingRoles[action] = VideoCollectionCommon::KeyTitle;
       
   500         }
       
   501     }
       
   502     else if (name.compare(DOCML_NAME_SORT_BY_NUMBER_OF_ITEMS) == 0)
       
   503     {
       
   504         HbAction *action = qobject_cast<HbAction*>(object);
       
   505         if (action)
       
   506         {
       
   507             connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
       
   508             mSortingRoles[action] = VideoCollectionCommon::KeyNumberOfItems;
       
   509         }
       
   510     }
       
   511     else if (name.compare(DOCML_NAME_SORT_BY_SIZE) == 0)
       
   512     {
       
   513         HbAction *action = qobject_cast<HbAction*>(object);
       
   514         if (action)
       
   515         {
       
   516         	connect(action, SIGNAL(triggered()), this, SLOT(startSorting()));
       
   517             mSortingRoles[action] = VideoCollectionCommon::KeySizeValue;
       
   518         }
       
   519     }
       
   520     else if (name.compare(DOCML_NAME_ADD_TO_COLLECTION) == 0)
       
   521     {
       
   522         HbAction *action = qobject_cast<HbAction*>(object);
       
   523         if (action)
       
   524         {
       
   525             connect(action, SIGNAL(triggered()), this, SLOT(addVideosToCollectionSlot()));
       
   526         }
       
   527     }
       
   528     else if (name.compare(DOCML_NAME_CREATE_COLLECTION) == 0)
       
   529     {
       
   530         HbAction *action = qobject_cast<HbAction*>(object);
       
   531         if (action)
       
   532         {
       
   533             connect(action, SIGNAL(triggered()), this, SLOT(createCollectionSlot()));
       
   534         }
       
   535     }
       
   536     else if (name.compare(DOCML_NAME_DELETE_MULTIPLE) == 0)
       
   537     {
       
   538         HbAction *action = qobject_cast<HbAction*>(object);
       
   539         if (action)
       
   540         {
       
   541             connect(action, SIGNAL(triggered()), this, SLOT(deleteItemsSlot()));
       
   542         }
       
   543     }
       
   544 }
       
   545 
       
   546 // End of file