videocollection/videocollectionview/src/videolistwidget.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
   379 
   379 
   380     if (variant.isValid())
   380     if (variant.isValid())
   381     {
   381     {
   382         QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
   382         QString text = hbTrId("txt_videos_info_do_you_want_to_delete_1").arg(
   383                 variant.toString());
   383                 variant.toString());
   384         if(HbMessageBox::question(text))
   384         
       
   385         HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
       
   386         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   387         messageBox->open(this, SLOT(deleteItemDialogFinished(HbAction *)));
       
   388     }
       
   389 }
       
   390 
       
   391 // ---------------------------------------------------------------------------
       
   392 // deleteItemDialogFinished
       
   393 // ---------------------------------------------------------------------------
       
   394 //
       
   395 void VideoListWidget::deleteItemDialogFinished(HbAction *action)
       
   396 {
       
   397     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
       
   398     if(action == dlg->actions().at(0)) 
       
   399     {
       
   400         QModelIndex index = currentIndex();
       
   401         if(index.isValid())
   385         {
   402         {
   386             QModelIndexList list;
   403             QModelIndexList list;
   387             list.append(index);
   404             list.append(index);
   388             mModel->deleteItems(list);
   405             mModel->deleteItems(list);
   389         }
   406         }
   414             service = mVideoServices->currentService();
   431             service = mVideoServices->currentService();
   415         }
   432         }
   416         
   433         
   417         if (service == VideoServices::EUriFetcher)
   434         if (service == VideoServices::EUriFetcher)
   418         {
   435         {
       
   436             mContextMenuActions[EActionAttach]    = 
       
   437                     mContextMenu->addAction(hbTrId("txt_videos_menu_attach"), this, SLOT(openItemSlot())); 
   419             mContextMenuActions[EActionPlay]    = 
   438             mContextMenuActions[EActionPlay]    = 
   420                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(openItemSlot())); 
   439                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(playItemSlot())); 
   421             mContextMenuActions[EActionDetails] = 
   440             mContextMenuActions[EActionDetails] = 
   422                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   441                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   423         }
   442         }
   424         else if (service == VideoServices::EBrowse)
   443         else if (service == VideoServices::EBrowse)
   425         {
   444         {
   426             mContextMenuActions[EActionPlay]    = 
   445             mContextMenuActions[EActionPlay]    = 
   427                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(openItemSlot())); 
   446                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(playItemSlot())); 
   428             mContextMenuActions[EActionDelete]           = 
   447             mContextMenuActions[EActionDelete]           = 
   429                     mContextMenu->addAction(hbTrId("txt_common_menu_delete"), this, SLOT(deleteItemSlot()));
   448                     mContextMenu->addAction(hbTrId("txt_common_menu_delete"), this, SLOT(deleteItemSlot()));
   430             mContextMenuActions[EActionDetails] = 
   449             mContextMenuActions[EActionDetails] = 
   431                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   450                     mContextMenu->addAction(hbTrId("txt_common_menu_details"), this, SLOT(openDetailsSlot()));
   432         }
   451         }
   433         else
   452         else
   434         {
   453         {
   435             mContextMenuActions[EActionPlay]    = 
   454             mContextMenuActions[EActionPlay]    = 
   436                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(openItemSlot())); 
   455                     mContextMenu->addAction(hbTrId("txt_videos_menu_play"), this, SLOT(playItemSlot())); 
   437             mContextMenuActions[EActionOpen]    = 
   456             mContextMenuActions[EActionOpen]    = 
   438                                 mContextMenu->addAction(hbTrId("txt_common_menu_open"), this, SLOT(openItemSlot()));  
   457                                 mContextMenu->addAction(hbTrId("txt_common_menu_open"), this, SLOT(openItemSlot()));  
   439             mContextMenuActions[EActionAddToCollection] = 
   458             mContextMenuActions[EActionAddToCollection] = 
   440                     mContextMenu->addAction(hbTrId("txt_videos_menu_add_to_collection"), this, SLOT(addToCollectionSlot()));
   459                     mContextMenu->addAction(hbTrId("txt_videos_menu_add_to_collection"), this, SLOT(addToCollectionSlot()));
   441             mContextMenuActions[EActionRemove]           = 
   460             mContextMenuActions[EActionRemove]           = 
   501     {        
   520     {        
   502     	if (!mIsService)
   521     	if (!mIsService)
   503     	{
   522     	{
   504 			mContextMenuActions[EActionAddToCollection]->setVisible(true);
   523 			mContextMenuActions[EActionAddToCollection]->setVisible(true);
   505     		mContextMenuActions[EActionDelete]->setVisible(true);
   524     		mContextMenuActions[EActionDelete]->setVisible(true);
       
   525     	} else {
       
   526             mContextMenuActions[EActionAttach]->setVisible(true);
   506     	}
   527     	}
   507     	mContextMenuActions[EActionPlay]->setVisible(true);
   528     	mContextMenuActions[EActionPlay]->setVisible(true);
   508 		mContextMenuActions[EActionDetails]->setVisible(true);
   529 		mContextMenuActions[EActionDetails]->setVisible(true);
   509     }
   530     }
   510     else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory) 
   531     else if(mCurrentLevel == VideoCollectionCommon::ELevelCategory) 
   521     {
   542     {
   522     	if (!mIsService)
   543     	if (!mIsService)
   523     	{
   544     	{
   524 			mContextMenuActions[EActionRemove]->setVisible(true);
   545 			mContextMenuActions[EActionRemove]->setVisible(true);
   525             mContextMenuActions[EActionDelete]->setVisible(true);
   546             mContextMenuActions[EActionDelete]->setVisible(true);
   526     	}
   547         } else {
       
   548             mContextMenuActions[EActionAttach]->setVisible(true);
       
   549         }
   527     	mContextMenuActions[EActionPlay]->setVisible(true);
   550     	mContextMenuActions[EActionPlay]->setVisible(true);
   528 		mContextMenuActions[EActionDetails]->setVisible(true);
   551 		mContextMenuActions[EActionDetails]->setVisible(true);
   529     }
   552     }
   530 }
   553 }
   531 
   554 
   573     {
   596     {
   574         // no custom functionality defined
   597         // no custom functionality defined
   575         emit activated(modelIndex);
   598         emit activated(modelIndex);
   576         return;
   599         return;
   577     }
   600     }
       
   601     doEmitActivated(modelIndex);
       
   602 }
       
   603 
       
   604 // ---------------------------------------------------------------------------
       
   605 // doEmitActivated
       
   606 // ---------------------------------------------------------------------------
       
   607 //
       
   608 void VideoListWidget::doEmitActivated (const QModelIndex &index)
       
   609 {
   578     if(mIsService &&
   610     if(mIsService &&
   579        mVideoServices &&
   611        mVideoServices &&
   580        mVideoServices->currentService() == VideoServices::EUriFetcher &&
   612        mVideoServices->currentService() == VideoServices::EUriFetcher &&
   581        mCurrentLevel != VideoCollectionCommon::ELevelCategory)
   613        mCurrentLevel != VideoCollectionCommon::ELevelCategory)
   582     {
   614     {
   583         QVariant variant = mModel->data(modelIndex, VideoCollectionCommon::KeyFilePath);
   615         QVariant variant = mModel->data(index, VideoCollectionCommon::KeyFilePath);
   584         if ( variant.isValid()  )
   616         if ( variant.isValid()  )
   585         {
   617         {
   586             QString itemPath = variant.value<QString>();
   618             QString itemPath = variant.value<QString>();
   587             emit(fileUri(itemPath));
   619             emit(fileUri(itemPath));
   588         }
   620         }
   589     }
   621     }
   590     else
   622     else
   591     {
   623     {
   592         doActivateItem(modelIndex);
   624         doActivateItem(index);
   593     }
   625     }
   594 }
   626 }
   595 
   627 
   596 // ---------------------------------------------------------------------------
   628 // ---------------------------------------------------------------------------
   597 // doActivateItem
   629 // doActivateItem
   630 //
   662 //
   631 void VideoListWidget::setSelectionMode(int mode)
   663 void VideoListWidget::setSelectionMode(int mode)
   632 {
   664 {
   633 	FUNC_LOG_ADDR(this);
   665 	FUNC_LOG_ADDR(this);
   634     HbAbstractItemView::SelectionMode selMode = HbAbstractItemView::NoSelection;
   666     HbAbstractItemView::SelectionMode selMode = HbAbstractItemView::NoSelection;
   635     if(mode >= HbAbstractItemView::NoSelection && mode <= HbAbstractItemView::ContiguousSelection)
   667     if(mode >= HbAbstractItemView::NoSelection && mode <= HbAbstractItemView::MultiSelection)
   636     {
   668     {
   637         selMode = HbAbstractItemView::SelectionMode(mode);
   669         selMode = HbAbstractItemView::SelectionMode(mode);
   638     }
   670     }
   639 
   671 
   640     HbListView::setSelectionMode(selMode);
   672     HbListView::setSelectionMode(selMode);
   704 		createContextMenu();
   736 		createContextMenu();
   705 	}
   737 	}
   706 }
   738 }
   707 
   739 
   708 // ---------------------------------------------------------------------------
   740 // ---------------------------------------------------------------------------
       
   741 // openItemSlot
       
   742 // ---------------------------------------------------------------------------
       
   743 //
       
   744 void VideoListWidget::openItemSlot()
       
   745 {
       
   746     FUNC_LOG_ADDR(this);
       
   747     doEmitActivated(currentIndex());
       
   748 }
       
   749 
       
   750 // ---------------------------------------------------------------------------
   709 // playItemSlot
   751 // playItemSlot
   710 // ---------------------------------------------------------------------------
   752 // ---------------------------------------------------------------------------
   711 //
   753 //
   712 void VideoListWidget::openItemSlot()
   754 void VideoListWidget::playItemSlot()
   713 {
   755 {
   714     FUNC_LOG_ADDR(this);
   756     FUNC_LOG_ADDR(this);
   715     doActivateItem(currentIndex());
   757     doActivateItem(currentIndex());
   716 }
   758 }
   717 
   759 
   744     QVariant variant = mModel->data(index, VideoCollectionCommon::KeyTitle);
   786     QVariant variant = mModel->data(index, VideoCollectionCommon::KeyTitle);
   745     TMPXItemId itemId = mModel->getMediaIdAtIndex(index);
   787     TMPXItemId itemId = mModel->getMediaIdAtIndex(index);
   746 
   788 
   747     if(variant.isValid() && itemId.iId2 == KVcxMvcMediaTypeAlbum)
   789     if(variant.isValid() && itemId.iId2 == KVcxMvcMediaTypeAlbum)
   748     {
   790     {
   749         bool ok = false;
       
   750         QString label(hbTrId("txt_videos_title_enter_name"));
   791         QString label(hbTrId("txt_videos_title_enter_name"));
   751         QString albumName = variant.toString();
   792         QString albumName = variant.toString();
   752         QString newAlbumName;
   793         
   753 
   794         HbInputDialog *dialog = new HbInputDialog();
   754         // Query a name for the collection
   795         dialog->setAttribute(Qt::WA_DeleteOnClose);
   755         newAlbumName = HbInputDialog::getText(label, albumName, &ok);
   796         dialog->getText(label, this, SLOT(renameDialogFinished(HbAction *)), albumName);
   756         // Rename only when name has changed. 
   797     }
   757         if(ok && newAlbumName.length() && newAlbumName.trimmed() != albumName)
   798 }
       
   799 
       
   800 // -------------------------------------------------------------------------------------------------
       
   801 // renameDialogFinished
       
   802 // -------------------------------------------------------------------------------------------------
       
   803 //
       
   804 void VideoListWidget::renameDialogFinished(HbAction *action)
       
   805 {
       
   806     Q_UNUSED(action);
       
   807 
       
   808     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   809     
       
   810     QModelIndex index = currentIndex();
       
   811     TMPXItemId itemId = mModel->getMediaIdAtIndex(index);
       
   812     QVariant newNameVariant = dialog->value();
       
   813     QVariant oldNameVariant = mModel->data(index, VideoCollectionCommon::KeyTitle);
       
   814     
       
   815     if(dialog->actions().first() == action &&
       
   816        oldNameVariant.isValid() && newNameVariant.isValid() && itemId.iId2 == KVcxMvcMediaTypeAlbum)
       
   817     {
       
   818         QString newAlbumName = newNameVariant.toString();
       
   819         QString oldAlbumName = oldNameVariant.toString();
       
   820         
       
   821         if(newAlbumName.length() && newAlbumName.trimmed() != oldAlbumName)
   758         {
   822         {
   759             // Resolve collection true name and rename the album
   823             // Resolve collection true name and rename the album
   760             newAlbumName = mModel->resolveAlbumName(newAlbumName);
   824             newAlbumName = mModel->resolveAlbumName(newAlbumName);
   761             mModel->renameAlbum(itemId, newAlbumName);
   825             mModel->renameAlbum(itemId, newAlbumName);
   762         }
   826         }
   763     }
   827     }
   764 }
   828 }
   765 
       
   766 // ---------------------------------------------------------------------------
   829 // ---------------------------------------------------------------------------
   767 // addToCollectionSlot
   830 // addToCollectionSlot
   768 // ---------------------------------------------------------------------------
   831 // ---------------------------------------------------------------------------
   769 //
   832 //
   770 void VideoListWidget::addToCollectionSlot()
   833 void VideoListWidget::addToCollectionSlot()
   826 
   889 
   827     if (variant.isValid())
   890     if (variant.isValid())
   828     {
   891     {
   829         QString text = hbTrId("txt_videos_info_do_you_want_to_remove_collection").arg(
   892         QString text = hbTrId("txt_videos_info_do_you_want_to_remove_collection").arg(
   830                 variant.toString());
   893                 variant.toString());
   831         if(HbMessageBox::question(text))
   894         HbMessageBox *messageBox = new HbMessageBox(text, HbMessageBox::MessageTypeQuestion);
       
   895         messageBox->setAttribute(Qt::WA_DeleteOnClose);
       
   896         messageBox->open(this, SLOT(removeCollectionDialogFinished(HbAction *)));
       
   897     }
       
   898 }
       
   899 
       
   900 // ---------------------------------------------------------------------------
       
   901 // removeCollectionDialogFinished
       
   902 // ---------------------------------------------------------------------------
       
   903 //
       
   904 void VideoListWidget::removeCollectionDialogFinished(HbAction *action)
       
   905 {
       
   906     HbMessageBox *dlg = static_cast<HbMessageBox*>(sender());
       
   907     if(action == dlg->actions().at(0)) 
       
   908     {
       
   909         QModelIndex index = currentIndex();
       
   910         if(index.isValid())
   832         {
   911         {
   833             QModelIndexList list;
   912             QModelIndexList list;
   834             list.append(index);
   913             list.append(index);
   835         	mModel->removeAlbums(list);
   914             mModel->removeAlbums(list);
   836         }
   915         }
   837     }
   916     }
   838 }
   917 }
   839 
   918 
   840 // ---------------------------------------------------------------------------
   919 // ---------------------------------------------------------------------------