videocollection/videocollectionview/src/videolisttoolbar.cpp
changeset 65 a9d57bd8d7b7
child 66 adb51f74b890
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:   VideoListToolbar class source code
       
    15 *
       
    16 */
       
    17 
       
    18 // Version : %version: 1.1.2 %
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <qactiongroup.h>
       
    22 #include <hbaction.h>
       
    23 #include <hbtoolbarextension.h>
       
    24 #include <vcxmyvideosdefs.h>
       
    25 
       
    26 #include "videolisttoolbar.h"
       
    27 #include "videoservices.h"
       
    28 #include "videooperatorservice.h"
       
    29 #include "videocollectioncenrepdefs.h"
       
    30 #include "videocollectiontrace.h"
       
    31 #include "videolistview.h"
       
    32 #include "videocollectionuiloader.h"
       
    33 #include "videolistwidget.h"
       
    34 #include "videoproxymodelgeneric.h"
       
    35 #include "videolistselectiondialog.h"
       
    36 
       
    37 // Object names.
       
    38 const char* const LIST_VIEW_OBJECT_NAME_TOOLBAR_EXTENSION = "vc::ListViewToolbarExtension";
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // Constructor
       
    42 // ---------------------------------------------------------------------------
       
    43 //
       
    44 VideoListToolbar::VideoListToolbar(VideoCollectionUiLoader* uiLoader, VideoListView* parent)
       
    45     : QObject(parent)
       
    46     , mCurrentLevel(VideoCollectionCommon::ELevelInvalid)
       
    47     , mUiUtils(VideoCollectionViewUtils::instance())
       
    48     , mUiLoader(uiLoader)
       
    49     , mListView(parent)
       
    50     , mVideoServices(0)
       
    51     , mToolbarViewsActionGroup(0)
       
    52     , mToolbarCollectionActionGroup(0)
       
    53     , mToolbarServiceExtension(0)
       
    54 {
       
    55 	FUNC_LOG;
       
    56 }
       
    57 
       
    58 // ---------------------------------------------------------------------------
       
    59 // Destructor
       
    60 // ---------------------------------------------------------------------------
       
    61 //
       
    62 VideoListToolbar::~VideoListToolbar()
       
    63 {
       
    64 	FUNC_LOG;
       
    65     
       
    66 	emit actionsChanged(mViewStateActions[VideoCollectionCommon::ELevelInvalid]);
       
    67 	
       
    68     mToolbarActions.clear();
       
    69 
       
    70     delete mToolbarServiceExtension;
       
    71     mToolbarServiceExtension = 0;
       
    72     
       
    73     if(mVideoServices)
       
    74     {
       
    75     	mVideoServices->decreaseReferenceCount();
       
    76     	mVideoServices = 0;
       
    77     }
       
    78     
       
    79     QList<VideoOperatorService *>::const_iterator iter = mVideoOperatorServices.constBegin();
       
    80     while(iter != mVideoOperatorServices.constEnd())
       
    81     {
       
    82         delete *iter;
       
    83         iter++;
       
    84     }
       
    85     mVideoOperatorServices.clear();
       
    86 }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // initialize()
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 void VideoListToolbar::initialize()
       
    93 {
       
    94     if (mUiUtils.isService())
       
    95     {
       
    96         INFO("VideoListToolbar::initialize() initializing service.");
       
    97         if (!mVideoServices)
       
    98         {
       
    99             mVideoServices = VideoServices::instance();
       
   100         }
       
   101          
       
   102     }
       
   103     else if(mVideoServices)
       
   104     {
       
   105         mVideoServices->decreaseReferenceCount();
       
   106         mVideoServices = 0;
       
   107     }
       
   108     
       
   109     createToolbarActions();
       
   110 }
       
   111 
       
   112 // ---------------------------------------------------------------------------
       
   113 // viewStateChanged()
       
   114 // ---------------------------------------------------------------------------
       
   115 //
       
   116 void VideoListToolbar::viewStateChanged(
       
   117     VideoCollectionCommon::TCollectionLevels currentLevel, 
       
   118     bool noVideos, bool modelReady)
       
   119 {
       
   120     if(!mToolbarViewsActionGroup || !mToolbarCollectionActionGroup)
       
   121     {
       
   122         // not initialized yet.
       
   123         return;
       
   124     }
       
   125     
       
   126     if(currentLevel != mCurrentLevel)
       
   127     {
       
   128         QList<QAction*> newActions = mViewStateActions[currentLevel];
       
   129         QList<QAction*> oldActions = mViewStateActions[mCurrentLevel];
       
   130         
       
   131         mCurrentLevel = currentLevel;
       
   132         
       
   133         if(newActions != oldActions)
       
   134         {
       
   135             emit actionsChanged(newActions);
       
   136             
       
   137             if(mToolbarServiceExtension &&
       
   138                 (mCurrentLevel == VideoCollectionCommon::ELevelCategory ||
       
   139                  mCurrentLevel == VideoCollectionCommon::ELevelVideos))
       
   140             {
       
   141                 emit toolbarExtensionChanged(mToolbarServiceExtension);
       
   142             }
       
   143             // note don't need to clear the toolbar extension actions, as the 
       
   144             // actionsChanged signal should clear all previous actions.
       
   145         }
       
   146         
       
   147         if(mCurrentLevel == VideoCollectionCommon::ELevelVideos &&
       
   148            !mToolbarActions[ETBActionAllVideos]->isChecked())
       
   149         {
       
   150             mToolbarActions[ETBActionAllVideos]->setChecked(true);
       
   151         }
       
   152         else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory &&
       
   153            !mToolbarActions[ETBActionCollections]->isChecked())
       
   154         {
       
   155             mToolbarActions[ETBActionCollections]->setChecked(true);
       
   156         }
       
   157     }
       
   158     if(!mVideoServices)
       
   159     {
       
   160         if(modelReady)
       
   161         {
       
   162         
       
   163             mToolbarActions[ETBActionAddVideos]->setVisible(true);
       
   164             mToolbarActions[ETBActionRemoveVideos]->setVisible(!noVideos);
       
   165 
       
   166         }
       
   167         else
       
   168         {
       
   169             mToolbarActions[ETBActionAddVideos]->setVisible(false);
       
   170             mToolbarActions[ETBActionRemoveVideos]->setVisible(false);
       
   171         }
       
   172     }
       
   173 }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // createToolbarActions()
       
   177 // Creates toolbar actions and toolbar icons
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 void VideoListToolbar::createToolbarActions()
       
   181 {
       
   182 	FUNC_LOG;
       
   183     
       
   184 	// Create actiongroup and add all actions to it. This ensures that only one is
       
   185     // active at certain moment.
       
   186     if(!mToolbarViewsActionGroup && !mToolbarCollectionActionGroup)
       
   187     {
       
   188     	mToolbarViewsActionGroup = new QActionGroup(this);
       
   189         mToolbarCollectionActionGroup = new QActionGroup(this);
       
   190 
       
   191         // create toolbar item actions
       
   192 
       
   193         // All Videos tab
       
   194         mToolbarActions[ETBActionAllVideos] = createAction("qtg_mono_video",
       
   195                 mToolbarViewsActionGroup, SIGNAL(allVideosActionTriggered()));
       
   196 
       
   197         // Collections tab
       
   198         mToolbarActions[ETBActionCollections] = createAction("qtg_mono_video_collection",
       
   199                 mToolbarViewsActionGroup, SIGNAL(collectionViewActionTriggered()));
       
   200 
       
   201         if (!mVideoServices)
       
   202         {
       
   203 			// Create services button or toolbar extension depending how many operator 
       
   204             // services are configured.
       
   205             createOperatorServicesToolbarActions();
       
   206 			
       
   207 			// Add Videos tab
       
   208 			mToolbarActions[ETBActionAddVideos] = 
       
   209 			        createAction("qtg_mono_add_to_video_collection",
       
   210 					mToolbarCollectionActionGroup, SLOT(addVideosToCollectionSlot()));
       
   211 
       
   212 			// Remove Videos tab
       
   213 			mToolbarActions[ETBActionRemoveVideos] = 
       
   214 			        createAction("qtg_mono_remove_from_video_collection",
       
   215 					mToolbarCollectionActionGroup, SLOT(removeVideosFromCollectionSlot()));
       
   216         }
       
   217 
       
   218         // Collection view actions are not checkable
       
   219         mToolbarActions[ETBActionAllVideos]->setCheckable(true);
       
   220         mToolbarActions[ETBActionCollections]->setCheckable(true);
       
   221 
       
   222         if(!mVideoServices && mToolbarActions[ETBActionServices])
       
   223         {
       
   224         	mToolbarActions[ETBActionServices]->setCheckable(false);
       
   225         }
       
   226         
       
   227         mViewStateActions[VideoCollectionCommon::ELevelCategory] = mToolbarViewsActionGroup->actions();
       
   228         mViewStateActions[VideoCollectionCommon::ELevelVideos] = mToolbarViewsActionGroup->actions();
       
   229         if(!mVideoServices)
       
   230         {
       
   231             mViewStateActions[VideoCollectionCommon::ELevelAlbum] = mToolbarCollectionActionGroup->actions();
       
   232         }
       
   233     }
       
   234 }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // createOperatorServicesToolbar()
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void VideoListToolbar::createOperatorServicesToolbarActions()
       
   241 {
       
   242     FUNC_LOG;
       
   243     if(mVideoOperatorServices.count() > 0)
       
   244     {
       
   245         return;
       
   246     }
       
   247     
       
   248     // Load services.
       
   249     
       
   250     loadOperatorService(KVideoCollectionViewCenrepServiceItem1Title, KVideoCollectionViewCenrepServiceItem1ToolbarIconPath, 
       
   251             KVideoCollectionViewCenrepServiceItem1Url, KVideoCollectionViewCenrepServiceItem1Uid);
       
   252     
       
   253     loadOperatorService(KVideoCollectionViewCenrepServiceItem2Title, KVideoCollectionViewCenrepServiceItem2ToolbarIconPath, 
       
   254             KVideoCollectionViewCenrepServiceItem2Url, KVideoCollectionViewCenrepServiceItem2Uid);
       
   255 
       
   256     loadOperatorService(KVideoCollectionViewCenrepServiceItem3Title, KVideoCollectionViewCenrepServiceItem3ToolbarIconPath, 
       
   257             KVideoCollectionViewCenrepServiceItem3Url, KVideoCollectionViewCenrepServiceItem3Uid);
       
   258 
       
   259     loadOperatorService(KVideoCollectionViewCenrepServiceItem4Title, KVideoCollectionViewCenrepServiceItem4ToolbarIconPath, 
       
   260             KVideoCollectionViewCenrepServiceItem4Url, KVideoCollectionViewCenrepServiceItem4Uid);
       
   261 
       
   262     loadOperatorService(KVideoCollectionViewCenrepServiceItem5Title, KVideoCollectionViewCenrepServiceItem5ToolbarIconPath, 
       
   263             KVideoCollectionViewCenrepServiceItem5Url, KVideoCollectionViewCenrepServiceItem5Uid);
       
   264 
       
   265     loadOperatorService(KVideoCollectionViewCenrepServiceItem6Title, KVideoCollectionViewCenrepServiceItem6ToolbarIconPath, 
       
   266             KVideoCollectionViewCenrepServiceItem6Url, KVideoCollectionViewCenrepServiceItem6Uid);
       
   267     
       
   268     // Create toolbar extension when there's multiple services.
       
   269     if(mVideoOperatorServices.count() > 1 && !mToolbarServiceExtension)
       
   270     {
       
   271         mToolbarServiceExtension = new HbToolBarExtension();
       
   272         mToolbarServiceExtension->setObjectName(LIST_VIEW_OBJECT_NAME_TOOLBAR_EXTENSION);
       
   273         
       
   274         QList<VideoOperatorService *>::const_iterator iter = mVideoOperatorServices.constBegin();
       
   275         while(iter != mVideoOperatorServices.constEnd())
       
   276         {
       
   277             HbIcon icon((*iter)->iconResource());
       
   278             HbAction *action = mToolbarServiceExtension->addAction(icon, (*iter)->title(), 
       
   279                     (*iter), SLOT(launchService()));
       
   280             action->setObjectName((*iter)->title());
       
   281             iter++;
       
   282         }
       
   283     }
       
   284     
       
   285     // Add toolbar button when there's only one service.
       
   286     if(mVideoOperatorServices.count() == 1)
       
   287     {
       
   288         VideoOperatorService *service = mVideoOperatorServices[0];
       
   289         mToolbarActions[ETBActionServices] = createAction(service->iconResource(),
       
   290                 mToolbarViewsActionGroup, 0 /*do not connect to any slot*/);
       
   291         connect(mToolbarActions[ETBActionServices], SIGNAL(triggered()), service, SLOT(launchService()));
       
   292     }
       
   293 }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // loadOperatorService()
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void VideoListToolbar::loadOperatorService(int titleKey, int iconKey, int uriKey, int uidKey)
       
   300 {
       
   301     FUNC_LOG;
       
   302     VideoOperatorService *service = new VideoOperatorService();
       
   303     if(service->load(titleKey, iconKey, uriKey, uidKey))
       
   304     {
       
   305         mVideoOperatorServices.append(service);
       
   306     }
       
   307     else
       
   308     {
       
   309         // Load failed, delete service data.
       
   310         delete service;
       
   311     }
       
   312 }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // openOperatorServiceSlot()
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void VideoListToolbar::openOperatorServiceSlot()
       
   319 {
       
   320     FUNC_LOG;
       
   321     
       
   322     if(mVideoOperatorServices.count() > 0)
       
   323     {
       
   324         mVideoOperatorServices[0]->launchService();
       
   325     }
       
   326 }
       
   327 
       
   328 // -------------------------------------------------------------------------------------------------
       
   329 // addVideosToCollectionSlot()
       
   330 // -------------------------------------------------------------------------------------------------
       
   331 //
       
   332 void VideoListToolbar::addVideosToCollectionSlot()
       
   333 {
       
   334     FUNC_LOG;
       
   335     
       
   336     VideoListWidget* currentList = mListView->getCurrentList();
       
   337     
       
   338     if(!currentList || !currentList->getModel())
       
   339     {
       
   340         return;
       
   341     }
       
   342 
       
   343     VideoListSelectionDialog *dialog =
       
   344         mUiLoader->findWidget<VideoListSelectionDialog>(
       
   345             DOCML_NAME_DIALOG);
       
   346     if (!dialog)
       
   347     {
       
   348         // fatal: no selection dialog
       
   349         return;
       
   350     }
       
   351     
       
   352     // do not proceed in case it already have same amount
       
   353     // of videos than all videos view.
       
   354     VideoListWidget *allVideos = mUiLoader->findWidget<VideoListWidget>(
       
   355                 DOCML_NAME_VC_VIDEOLISTWIDGET);
       
   356     if(allVideos && allVideos->getModel())
       
   357     {
       
   358         int count = allVideos->getModel()->rowCount();
       
   359         if(count == currentList->getModel()->rowCount())
       
   360         {
       
   361             if(count)
       
   362             {
       
   363                 QVariant emptyAdditional;
       
   364                 mUiUtils.showStatusMsgSlot(
       
   365                         VideoCollectionCommon::statusAllVideosAlreadyInCollection,
       
   366                         emptyAdditional);
       
   367             }
       
   368             return;
       
   369         }  
       
   370     }
       
   371     
       
   372     TMPXItemId collectionId = currentList->getModel()->getOpenItem();
       
   373     dialog->setupContent(VideoListSelectionDialog::EAddToCollection, collectionId);
       
   374     dialog->exec();
       
   375 }
       
   376 
       
   377 // -------------------------------------------------------------------------------------------------
       
   378 // removeVideosFromCollectionSlot()
       
   379 // -------------------------------------------------------------------------------------------------
       
   380 //
       
   381 void VideoListToolbar::removeVideosFromCollectionSlot()
       
   382 {
       
   383     FUNC_LOG;
       
   384 
       
   385     VideoListWidget* currentList = mListView->getCurrentList();
       
   386     
       
   387     if(!currentList || !currentList->getModel())
       
   388     {
       
   389         return;
       
   390     }
       
   391     
       
   392     // not allowed if for some reason current widget 
       
   393     // is all videos or collection or there are no items
       
   394     if(currentList->getLevel() != VideoCollectionCommon::ELevelAlbum ||
       
   395        !currentList->getModel()->rowCount())
       
   396     {
       
   397         return;
       
   398     }
       
   399 
       
   400     VideoListSelectionDialog *dialog =
       
   401             mUiLoader->findWidget<VideoListSelectionDialog>(
       
   402                         DOCML_NAME_DIALOG);
       
   403     if (!dialog)
       
   404     {
       
   405         ERROR(-1, "VideoListView::removeVideosFromCollectionSlot() failed to load selection dialog.");
       
   406         return;
       
   407     }
       
   408     
       
   409     TMPXItemId collectionId = currentList->getModel()->getOpenItem();
       
   410     if(collectionId != TMPXItemId::InvalidId() && collectionId.iId2 == KVcxMvcMediaTypeAlbum)
       
   411     {
       
   412         dialog->setupContent(VideoListSelectionDialog::ERemoveFromCollection, collectionId);
       
   413         dialog->exec();
       
   414     }
       
   415 }
       
   416 
       
   417 // ---------------------------------------------------------------------------
       
   418 // createAction()
       
   419 // ---------------------------------------------------------------------------
       
   420 //
       
   421 HbAction* VideoListToolbar::createAction(QString icon,
       
   422         QActionGroup* actionGroup, const char *slot)
       
   423 {
       
   424 	FUNC_LOG;
       
   425     HbAction* action = new HbAction(actionGroup);
       
   426 
       
   427     HbIcon hbIcon(icon);
       
   428     action->setIcon(hbIcon);
       
   429 
       
   430     if(slot)
       
   431     {
       
   432         if(!connect(action, SIGNAL(triggered()), this, slot)) {
       
   433             // actiongroup deletion deletes this also.
       
   434             // return 0 tells that there was a problem in creation to caller.
       
   435             delete action;
       
   436             return 0;
       
   437         }
       
   438     }
       
   439     
       
   440     return action;
       
   441 }
       
   442 
       
   443 // End of file