videocollection/videocollectionview/src/videolistwidget.cpp
changeset 35 3738fe97f027
parent 34 bbb98528c666
child 36 8aed59de29f9
equal deleted inserted replaced
34:bbb98528c666 35:3738fe97f027
    25 #include <hbaction.h>
    25 #include <hbaction.h>
    26 #include <hbinstance.h>
    26 #include <hbinstance.h>
    27 #include <hbmainwindow.h>
    27 #include <hbmainwindow.h>
    28 #include <hblistviewitem.h>
    28 #include <hblistviewitem.h>
    29 #include <hbmessagebox.h>
    29 #include <hbmessagebox.h>
    30 #include <hbstyleloader.h>
       
    31 #include <vcxmyvideosdefs.h>
    30 #include <vcxmyvideosdefs.h>
    32 #include "videocollectionuiloader.h"
       
    33 
    31 
    34 #include "videocollectionviewutils.h"
    32 #include "videocollectionviewutils.h"
    35 #include "videocollectionuiloader.h"
    33 #include "videocollectionuiloader.h"
    36 #include "videolistselectiondialog.h"
    34 #include "videolistselectiondialog.h"
    37 #include "videoservices.h"
    35 #include "videoservices.h"
    51 HbListView(parent),
    49 HbListView(parent),
    52 mModel(0),
    50 mModel(0),
    53 mVideoServices(0),
    51 mVideoServices(0),
    54 mCurrentLevel(VideoCollectionCommon::ELevelInvalid),
    52 mCurrentLevel(VideoCollectionCommon::ELevelInvalid),
    55 mSignalsConnected(false),
    53 mSignalsConnected(false),
    56 mDetailsReady(false),
       
    57 mIsService(false),
    54 mIsService(false),
    58 mNavKeyBackAction(0),
    55 mNavKeyBackAction(0),
    59 mNavKeyQuitAction(0),
    56 mNavKeyQuitAction(0),
    60 mContextMenu(0),
    57 mContextMenu(0),
    61 mSelectionMode(HbAbstractItemView::NoSelection),
    58 mSelectionMode(HbAbstractItemView::NoSelection),
    69 // Destructor
    66 // Destructor
    70 // ---------------------------------------------------------------------------
    67 // ---------------------------------------------------------------------------
    71 //
    68 //
    72 VideoListWidget::~VideoListWidget()
    69 VideoListWidget::~VideoListWidget()
    73 {
    70 {
    74     HbStyleLoader::unregisterFilePath( ":/style/hblistviewitem.css" );
       
    75     delete mScrollPositionTimer;
    71     delete mScrollPositionTimer;
    76     mScrollPositionTimer = 0;
    72     mScrollPositionTimer = 0;
    77 	mContextMenuActions.clear();
    73 	mContextMenuActions.clear();
    78 	disconnect();
    74 	disconnect();
    79     delete mContextMenu;
    75     delete mContextMenu;
   105     // Navigation keys.
   101     // Navigation keys.
   106     mNavKeyBackAction = new HbAction(Hb::BackNaviAction);
   102     mNavKeyBackAction = new HbAction(Hb::BackNaviAction);
   107 	
   103 	
   108     mNavKeyQuitAction = new HbAction(Hb::QuitNaviAction);
   104     mNavKeyQuitAction = new HbAction(Hb::QuitNaviAction);
   109 
   105 
   110     // initial setup for widget is hidden
       
   111 	setVisible(false);
       
   112 
       
   113 	mScrollPositionTimer = new QTimer();
   106 	mScrollPositionTimer = new QTimer();
   114 	mScrollPositionTimer->setSingleShot(true);
   107 	mScrollPositionTimer->setSingleShot(true);
   115 
   108 
   116 	if (mIsService)
   109 	if (mIsService)
   117 	{
   110 	{
   118 		connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
   111 		connect(this, SIGNAL(fileUri(const QString&)), mVideoServices, SLOT(itemSelected(const QString&)));
   119 	}
   112 	}
   120 
   113 
   121     bool ret = HbStyleLoader::registerFilePath( ":/style/hblistviewitem.css" );
   114 	setModel(mModel);
   122 
   115 	
   123     if(!ret)
   116     return 0;
       
   117 }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // activate
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 int VideoListWidget::activate()
       
   124 {
       
   125     return activate(mCurrentLevel);
       
   126 }
       
   127 
       
   128 // ---------------------------------------------------------------------------
       
   129 // activate
       
   130 // ---------------------------------------------------------------------------
       
   131 //
       
   132 int VideoListWidget::activate(VideoCollectionCommon::TCollectionLevels level)
       
   133 {
       
   134     if(!mModel)
   124     {
   135     {
   125         return -1;
   136         return -1;
   126     }
   137     }
   127 	
   138     
   128 	setModel(mModel);
       
   129 
       
   130     return 0;
       
   131 }
       
   132 
       
   133 // ---------------------------------------------------------------------------
       
   134 // activate
       
   135 // ---------------------------------------------------------------------------
       
   136 //
       
   137 int VideoListWidget::activate()
       
   138 {
       
   139     return activate(mCurrentLevel);
       
   140 }
       
   141 
       
   142 // ---------------------------------------------------------------------------
       
   143 // activate
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 int VideoListWidget::activate(VideoCollectionCommon::TCollectionLevels level)
       
   147 {
       
   148     if(!mModel)
       
   149     {
       
   150         return -1;
       
   151     }
       
   152 	mCurrentLevel = level;
   139 	mCurrentLevel = level;
   153 	setVisible(true);
   140     setVisible(true);
   154 
   141 
   155     if ( connectSignals() < 0)
   142     if ( connectSignals() < 0)
   156     {
   143     {
   157         return -1;
   144         return -1;
   158     }
   145     }
   198 {
   185 {
   199     if(mContextMenu) 
   186     if(mContextMenu) 
   200     {
   187     {
   201         mContextMenu->hide();
   188         mContextMenu->hide();
   202     }
   189     }
   203     setVisible(false);  
   190 
       
   191     setVisible(false);
   204     disConnectSignals();
   192     disConnectSignals();
   205     
   193     
   206     // Free allocated memory for list thumbnails and disable background fetching.
   194     // Free allocated memory for list thumbnails and disable background fetching.
   207     VideoThumbnailData &thumbnailData = VideoThumbnailData::instance();
   195     VideoThumbnailData &thumbnailData = VideoThumbnailData::instance();
   208     thumbnailData.enableBackgroundFetching(false);
   196     thumbnailData.enableBackgroundFetching(false);
   231            !connect(this, SIGNAL(scrollPositionChanged(const QPointF &)), 
   219            !connect(this, SIGNAL(scrollPositionChanged(const QPointF &)), 
   232                    this, SLOT(scrollPositionChangedSlot(const QPointF &))) ||
   220                    this, SLOT(scrollPositionChangedSlot(const QPointF &))) ||
   233            !connect(mScrollPositionTimer, SIGNAL(timeout()), this, SLOT(scrollPositionTimerSlot())) || 
   221            !connect(mScrollPositionTimer, SIGNAL(timeout()), this, SLOT(scrollPositionTimerSlot())) || 
   234            !connect(mNavKeyBackAction, SIGNAL(triggered()), this, SLOT(back())) ||
   222            !connect(mNavKeyBackAction, SIGNAL(triggered()), this, SLOT(back())) ||
   235            !connect(mNavKeyQuitAction, SIGNAL(triggered()), qApp, SLOT(quit()))) 
   223            !connect(mNavKeyQuitAction, SIGNAL(triggered()), qApp, SLOT(quit()))) 
   236            
       
   237         {
   224         {
   238             return -1;
   225             return -1;
   239         }
   226         }
   240         mSignalsConnected = true;
   227         mSignalsConnected = true;
   241     }
   228     }
   258 
   245 
   259 	mSignalsConnected = false;
   246 	mSignalsConnected = false;
   260 }
   247 }
   261 
   248 
   262 // ---------------------------------------------------------------------------
   249 // ---------------------------------------------------------------------------
   263 // shareItemSlot
       
   264 // ---------------------------------------------------------------------------
       
   265 //
       
   266 void VideoListWidget::shareItemSlot()
       
   267 {
       
   268     debugNotImplementedYet();
       
   269 }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // deleteItemSlot
   250 // deleteItemSlot
   273 // ---------------------------------------------------------------------------
   251 // ---------------------------------------------------------------------------
   274 //
   252 //
   275 void VideoListWidget::deleteItemSlot()
   253 void VideoListWidget::deleteItemSlot()
   276 {
   254 {
   283     QModelIndex index = currentIndex();
   261     QModelIndex index = currentIndex();
   284     variant = mModel->data(index, Qt::DisplayRole);
   262     variant = mModel->data(index, Qt::DisplayRole);
   285 
   263 
   286     if (variant.isValid())
   264     if (variant.isValid())
   287     {
   265     {
   288         QString text = tr("Do you want to delete \"%1\"?").arg( //TODO: localisation
   266         QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
   289                 variant.toStringList().first());
   267                 variant.toStringList().first());
   290         if(HbMessageBox::question(text))
   268         if(HbMessageBox::question(text))
   291         {
   269         {
   292             QModelIndexList list;
   270             QModelIndexList list;
   293             list.append(index);
   271             list.append(index);
   304 {
   282 {
   305     if(mContextMenu)
   283     if(mContextMenu)
   306     {
   284     {
   307         return;
   285         return;
   308     }
   286     }
       
   287     
   309     mContextMenu = new HbMenu();
   288     mContextMenu = new HbMenu();
   310 
   289     if (mContextMenu)
   311     if (mIsService)
   290     {
   312     {
   291         mContextMenu->setDismissPolicy(HbPopup::TapAnywhere);
   313 		mContextMenuActions[EActionPlay]    = mContextMenu->addAction(hbTrId("txt_videos_menu_play"),    this, SLOT(playItemSlot())); //TODO: localisation
   292         if (mIsService)
   314 		mContextMenuActions[EActionDetails] = mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   293         {
   315     }
   294             mContextMenuActions[EActionPlay]    = 
   316     else
   295                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(playItemSlot())); 
   317     {
   296             mContextMenuActions[EActionDetails] = 
   318         mContextMenuActions[EACtionAddToCollection]      = mContextMenu->addAction(hbTrId("txt_videos_menu_add_to_collection"), this, SLOT(addToCollectionSlot()));
   297                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   319         mContextMenuActions[EACtionRemoveFromCollection] = mContextMenu->addAction(hbTrId("txt_videos_menu_remove_collection"), this, SLOT(debugNotImplementedYet()));
   298         }
   320         mContextMenuActions[EActionShare]                = mContextMenu->addAction(hbTrId("txt_videos_menu_share"), this, SLOT(shareItemSlot()));
   299         else
   321         mContextMenuActions[EActionRename]               = mContextMenu->addAction(hbTrId("txt_common_menu_rename_item"), this, SLOT(renameSlot()));
   300         {
   322         mContextMenuActions[EACtionRemoveCollection]     = mContextMenu->addAction(hbTrId("txt_videos_menu_remove_collection"), this, SLOT(removeCollectionSlot()));   
   301             mContextMenuActions[EActionAddToCollection] = 
   323         mContextMenuActions[EActionDelete]               = mContextMenu->addAction(hbTrId("txt_common_menu_delete"), this, SLOT(deleteItemSlot()));
   302                     mContextMenu->addAction(hbTrId("txt_videos_menu_add_to_collection"), this, SLOT(addToCollectionSlot()));
   324         mContextMenuActions[EActionDetails]              = mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   303             mContextMenuActions[EActionRemove]           = 
       
   304                     mContextMenu->addAction(hbTrId("txt_videos_menu_remove_from_collection"), this, SLOT(removeFromCollectionSlot()));
       
   305             mContextMenuActions[EActionRename]           = 
       
   306                     mContextMenu->addAction(hbTrId("txt_common_menu_rename_item"), this, SLOT(renameSlot()));
       
   307             mContextMenuActions[EActionRemoveCollection] = 
       
   308                     mContextMenu->addAction(hbTrId("txt_videos_menu_remove_collection"), this, SLOT(removeCollectionSlot()));   
       
   309             mContextMenuActions[EActionDelete]           = 
       
   310                     mContextMenu->addAction(hbTrId("txt_common_menu_delete"), this, SLOT(deleteItemSlot()));
       
   311             mContextMenuActions[EActionDetails]          = 
       
   312                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
       
   313         }
   325     }
   314     }
   326 }
   315 }
   327 
   316 
   328 // -------------------------------------------------------------------------------------------------
   317 // -------------------------------------------------------------------------------------------------
   329 // setContextMenu
   318 // setContextMenu
   333 {
   322 {
   334     if(!mContextMenu)
   323     if(!mContextMenu)
   335     {
   324     {
   336         createContextMenu();
   325         createContextMenu();
   337     }
   326     }
       
   327     
       
   328     if (!mContextMenu)
       
   329     {
       
   330         // failed to create context menu, return
       
   331         return;
       
   332     }
       
   333     
   338 	int menuActionCount = 0;
   334 	int menuActionCount = 0;
   339     HbAction *action = 0;
   335     HbAction *action = 0;
   340     foreach(action, mContextMenuActions.values())
   336     foreach(action, mContextMenuActions.values())
   341     {
   337     {
   342         if(action)
   338         if(action)
   359     if(mCurrentLevel == VideoCollectionCommon::ELevelVideos ||
   355     if(mCurrentLevel == VideoCollectionCommon::ELevelVideos ||
   360        mCurrentLevel == VideoCollectionCommon::ELevelDefaultColl)
   356        mCurrentLevel == VideoCollectionCommon::ELevelDefaultColl)
   361     {
   357     {
   362     	if (!mIsService)
   358     	if (!mIsService)
   363     	{
   359     	{
   364 			mContextMenuActions[EACtionAddToCollection]->setVisible(true);
   360 			mContextMenuActions[EActionAddToCollection]->setVisible(true);
   365     		mContextMenuActions[EActionShare]->setVisible(true);
       
   366     		mContextMenuActions[EActionDelete]->setVisible(true);
   361     		mContextMenuActions[EActionDelete]->setVisible(true);
   367     	}
   362     	}
   368     	else
   363     	else
   369     	{
   364     	{
   370     		mContextMenuActions[EActionPlay]->setVisible(true);
   365     		mContextMenuActions[EActionPlay]->setVisible(true);
   374     else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory) 
   369     else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory) 
   375     {
   370     {
   376 		if(!mIsService)
   371 		if(!mIsService)
   377 		{
   372 		{
   378             mContextMenuActions[EActionRename]->setVisible(true);
   373             mContextMenuActions[EActionRename]->setVisible(true);
   379             mContextMenuActions[EACtionRemoveCollection]->setVisible(true);
   374             mContextMenuActions[EActionRemoveCollection]->setVisible(true);
   380 		}
   375 		}
   381     }
   376     }
   382     else if(mCurrentLevel == VideoCollectionCommon::ELevelAlbum)
   377     else if(mCurrentLevel == VideoCollectionCommon::ELevelAlbum)
   383     {
   378     {
   384     	if (!mIsService)
   379     	if (!mIsService)
   385     	{
   380     	{
   386 			mContextMenuActions[EACtionRemoveFromCollection]->setVisible(true);
   381 			mContextMenuActions[EActionRemove]->setVisible(true);
   387             mContextMenuActions[EActionShare]->setVisible(true);
       
   388             mContextMenuActions[EActionDelete]->setVisible(true);
   382             mContextMenuActions[EActionDelete]->setVisible(true);
   389     	}
   383     	}
   390     	else
   384     	else
   391     	{
   385     	{
   392     		mContextMenuActions[EActionPlay]->setVisible(true);
   386     		mContextMenuActions[EActionPlay]->setVisible(true);
   410 // This slot is called by the fw when viewitem is activated
   404 // This slot is called by the fw when viewitem is activated
   411 // ---------------------------------------------------------------------------
   405 // ---------------------------------------------------------------------------
   412 //
   406 //
   413 void VideoListWidget::emitActivated (const QModelIndex &modelIndex)
   407 void VideoListWidget::emitActivated (const QModelIndex &modelIndex)
   414 {
   408 {
       
   409     // surprisingly interenting feature: after long press also single press
       
   410     // is executed. as a workaround the following hack check is needed.
       
   411     // otherwise after the context menu is shown also single press action
       
   412     // is executed.
       
   413     if (mContextMenu &&
       
   414         mContextMenu->isVisible())
       
   415     {
       
   416         // do not activate context menu if it is already visible
       
   417         return;
       
   418     }
       
   419     
   415     if(mSelectionMode != HbAbstractItemView::NoSelection)
   420     if(mSelectionMode != HbAbstractItemView::NoSelection)
   416     {
   421     {
   417         // no custom functionality defined
   422         // no custom functionality defined
   418         emit activated(modelIndex);
   423         emit activated(modelIndex);
   419         return;
   424         return;
   430         if (variant.isValid())
   435         if (variant.isValid())
   431         {
   436         {
   432             // signal view that item has been activated
   437             // signal view that item has been activated
   433             emit(collectionOpened(true,
   438             emit(collectionOpened(true,
   434                 variant.toStringList().first(),
   439                 variant.toStringList().first(),
   435                 modelIndex));
   440                 modelIndex));                       
   436             
   441         }
   437             return;
   442         return;
   438         }
       
   439     }
   443     }
   440     if(mIsService && (mCurrentLevel != VideoCollectionCommon::ELevelCategory))
   444     if(mIsService && (mCurrentLevel != VideoCollectionCommon::ELevelCategory))
   441     {
   445     {
   442     	QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
   446     	QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
   443 		if ( variant.isValid()  )
   447 		if ( variant.isValid()  )
   476 // ---------------------------------------------------------------------------
   480 // ---------------------------------------------------------------------------
   477 //
   481 //
   478 //
   482 //
   479 void VideoListWidget::longPressGesture (const QPointF &point)
   483 void VideoListWidget::longPressGesture (const QPointF &point)
   480 {
   484 {
   481     if (!mDetailsReady)
       
   482     {
       
   483         emit command(MpxHbVideoCommon::LoadVideoDetailsView);
       
   484         mDetailsReady = true;
       
   485     }
       
   486     if(mSelectionMode != HbAbstractItemView::NoSelection)
   485     if(mSelectionMode != HbAbstractItemView::NoSelection)
   487     {
   486     {
   488         // do not activate context menu during selection mode
   487         // do not activate context menu during selection mode
   489         return;
   488         return;
   490     }
   489     }
   491 
   490 
   492 	QModelIndex index = currentIndex();
   491     HbAbstractViewItem *viewItem = itemAtPosition(point);
   493     if(mModel && index.isValid())
   492     if (viewItem)
   494     {   
   493     {
   495     	TMPXItemId mpxId = mModel->getMediaIdAtIndex(index);
   494         QModelIndex index = viewItem->modelIndex();
   496     	// Only videos and user created albums have context menu.
   495         if(mModel && index.isValid())
   497     	if((mpxId.iId2 == KVcxMvcMediaTypeVideo) ||
   496         {   
   498     	   (!mIsService && mpxId.iId2 == KVcxMvcMediaTypeAlbum ))
   497             TMPXItemId mpxId = mModel->getMediaIdAtIndex(index);
   499     	{
   498             // Only videos and user created albums have context menu.
   500             setContextMenu();
   499             if((mpxId.iId2 == KVcxMvcMediaTypeVideo) ||
   501             // if menu not yet exists, it has been created
   500                (!mIsService && mpxId.iId2 == KVcxMvcMediaTypeAlbum ))
   502             // setup might fail causing menu to be removed
       
   503             if(mContextMenu)
       
   504             {
   501             {
   505                 mContextMenu->exec(point);
   502                 setContextMenu();
       
   503                 // if menu not yet exists, it has been created
       
   504                 // setup might fail causing menu to be removed
       
   505                 if(mContextMenu)
       
   506                 {
       
   507                     mContextMenu->setPreferredPos(point);
       
   508                     mContextMenu->show();
       
   509                 }
   506             }
   510             }
   507     	}
   511         }
   508     }
   512     }
   509 	HbListView::longPressGesture(point);
   513 	HbListView::longPressGesture(point);
       
   514 }
       
   515 
       
   516 // ---------------------------------------------------------------------------
       
   517 // doDelayedsSlot
       
   518 // ---------------------------------------------------------------------------
       
   519 //
       
   520 void VideoListWidget::doDelayedsSlot()
       
   521 {
       
   522 	if (!mContextMenu)
       
   523 	{
       
   524 		createContextMenu();
       
   525 	}
   510 }
   526 }
   511 
   527 
   512 // ---------------------------------------------------------------------------
   528 // ---------------------------------------------------------------------------
   513 // playItemSlot
   529 // playItemSlot
   514 // ---------------------------------------------------------------------------
   530 // ---------------------------------------------------------------------------
   559         dialog->exec();
   575         dialog->exec();
   560     }
   576     }
   561 }
   577 }
   562 
   578 
   563 // ---------------------------------------------------------------------------
   579 // ---------------------------------------------------------------------------
       
   580 // removeFromCollectionSlot
       
   581 // ---------------------------------------------------------------------------
       
   582 //
       
   583 void VideoListWidget::removeFromCollectionSlot()
       
   584 {
       
   585     if(!mModel)
       
   586     {
       
   587         return;
       
   588     }
       
   589     TMPXItemId collectionId = mModel->getOpenItem();
       
   590     TMPXItemId itemId = mModel->getMediaIdAtIndex(currentIndex());
       
   591     if(collectionId != TMPXItemId::InvalidId() && 
       
   592        itemId != TMPXItemId::InvalidId())
       
   593     {
       
   594         QList<TMPXItemId> ids;
       
   595         ids.append(itemId);
       
   596         mModel->removeItemsFromAlbum(collectionId, ids);
       
   597     }
       
   598 }
       
   599 
       
   600 // ---------------------------------------------------------------------------
   564 // removeCollectionSlot
   601 // removeCollectionSlot
   565 // ---------------------------------------------------------------------------
   602 // ---------------------------------------------------------------------------
   566 //
   603 //
   567 void VideoListWidget::removeCollectionSlot()
   604 void VideoListWidget::removeCollectionSlot()
   568 {
   605 {
   601 // back
   638 // back
   602 // ---------------------------------------------------------------------------
   639 // ---------------------------------------------------------------------------
   603 //
   640 //
   604 void VideoListWidget::back()
   641 void VideoListWidget::back()
   605 {
   642 {
       
   643 	// Empty the proxy model causing the items to be removed from list widget.
       
   644     mModel->setAlbumInUse(TMPXItemId::InvalidId());
   606     if(mModel)
   645     if(mModel)
   607     {
   646     {
   608     	emit collectionOpened(false, QString(), QModelIndex());
   647         emit collectionOpened(false, QString(), QModelIndex());
   609     }
   648     }
   610 }
   649 }
   611 
   650 
   612 // ---------------------------------------------------------------------------
   651 // ---------------------------------------------------------------------------
   613 // scrollingStartedSlot
   652 // scrollingStartedSlot