videocollection/videocollectionview/src/videolistselectiondialog.cpp
branchRCL_3
changeset 56 839377eedc2b
equal deleted inserted replaced
54:315810614048 56:839377eedc2b
       
     1 /*
       
     2 * Copyright (c) 2008 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 selection dialog implementation
       
    15 * 
       
    16 */
       
    17 
       
    18 // Version : %version: 30.1.3 %
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <qgraphicsitem.h>
       
    22 #include <hblabel.h>
       
    23 #include <hbcheckbox.h>
       
    24 #include <hbaction.h>
       
    25 #include <hbstackedwidget.h>
       
    26 #include <hbabstractitemview.h>
       
    27 #include <hbinputdialog.h>
       
    28 #include <vcxmyvideosdefs.h>
       
    29 #include <hbstyleloader.h>
       
    30 
       
    31 #include "videocollectionuiloader.h"
       
    32 #include "videolistwidget.h"
       
    33 #include "videosortfilterproxymodel.h"
       
    34 #include "videolistselectiondialog.h"
       
    35 #include "videocollectionwrapper.h"
       
    36 #include "videocollectionviewutils.h"
       
    37 #include "videocollectionclient.h"
       
    38 #include "videocollectiontrace.h"
       
    39 
       
    40 // Object names.
       
    41 const char* const SELECTION_DIALOG_OBJECT_NAME_LIST_WIDGET    = "vc:SelectionDialogListWidget";
       
    42 const char* const SELECTION_DIALOG_OBJECT_NAME_NEW_COLLECTION = "vc:SelectionDialogNewCollection";
       
    43 const char* const LIST_VIEW_OBJECT_NAME_CREATE_COLLECTION     = "vc::ListViewInputDialogCreateCollection";
       
    44 const char* const SELECTION_DIALOG_OBJECT_NAME_BUTTON_OK      = "vc:SelectionDialogButtonOk";
       
    45 const char* const SELECTION_DIALOG_OBJECT_NAME_BUTTON_CANCEL  = "vc:SelectionDialogButtonCancel";
       
    46 
       
    47 /**
       
    48  * global qHash function required fo creating hash values for TMPXItemId -keys
       
    49  */
       
    50 inline uint qHash(TMPXItemId key) 
       
    51 { 
       
    52     QPair<uint, uint> keyPair(key.iId1, key.iId2); 
       
    53 
       
    54     return qHash(keyPair);
       
    55 }
       
    56 
       
    57 /**
       
    58  * Helper function for creating a new album name query dialog 
       
    59  */
       
    60 HbInputDialog* gCreateNewAlbumNameDialog(const char* objectName)
       
    61 {
       
    62     QString label(hbTrId("txt_videos_title_enter_name"));
       
    63     QString text(hbTrId("txt_videos_dialog_entry_new_collection"));
       
    64     HbInputDialog *dialog = new HbInputDialog();
       
    65     dialog->setAttribute(Qt::WA_DeleteOnClose);
       
    66     dialog->setObjectName(objectName);
       
    67     dialog->setPromptText(label);
       
    68     dialog->setValue(text);
       
    69     return dialog;
       
    70 }
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // VideoListSelectionDialog
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 VideoListSelectionDialog::VideoListSelectionDialog( VideoCollectionUiLoader *uiLoader,
       
    77                                                     QGraphicsItem *parent)  
       
    78     : HbDialog( parent )
       
    79     , mUiLoader( uiLoader )
       
    80     , mTypeOfSelection( -1 )
       
    81     , mHeading( 0 )
       
    82     , mCheckboxContainer( 0 )
       
    83     , mItemCount( 0 )
       
    84     , mCheckBoxText( 0 )
       
    85     , mCheckBox( 0 )
       
    86     , mListContainer( 0 )
       
    87     , mForcedCheck( false )
       
    88     , mModel( 0 )
       
    89     , mModelReady( false )
       
    90     , mAlbumListReady( false )
       
    91     , mListWidget( 0 )
       
    92     , mPrimaryAction( 0 )
       
    93     , mSecondaryAction( 0 )
       
    94 {
       
    95 	FUNC_LOG;
       
    96     
       
    97 	HbStyleLoader::registerFilePath( ":/style/hbdialog.css" );
       
    98 
       
    99     setDismissPolicy(HbDialog::NoDismiss);
       
   100     setTimeout(HbDialog::NoTimeout);    
       
   101 
       
   102     // create model for list widget
       
   103     mModel =
       
   104         VideoCollectionWrapper::instance().getModel(
       
   105         		VideoCollectionCommon::EModelTypeGeneric);
       
   106     if (mModel)
       
   107     {
       
   108         // create list widget
       
   109         mListWidget = new VideoListWidget(mUiLoader);
       
   110         if(mListWidget->initialize(*mModel) < 0)
       
   111         {
       
   112             ERROR(-1, "VideoListSelectionDialog::VideoListSelectionDialog() failed to init list widget");
       
   113             delete mListWidget;
       
   114             mListWidget = 0;
       
   115         }
       
   116         // disable list related animations to make dialog faster 
       
   117         mListWidget->setEnabledAnimations(HbAbstractItemView::None);
       
   118         mListWidget->setObjectName(SELECTION_DIALOG_OBJECT_NAME_LIST_WIDGET);
       
   119     }
       
   120 }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // ~VideoListSelectionDialog
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 VideoListSelectionDialog::~VideoListSelectionDialog() 
       
   127 {
       
   128 	FUNC_LOG;
       
   129 	HbStyleLoader::unregisterFilePath( ":/style/hbdialog.css" );
       
   130     delete mListWidget;
       
   131     mListWidget = 0;
       
   132 }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // setupContent
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 void VideoListSelectionDialog::setupContent(int type, TMPXItemId activeItem)
       
   139 {
       
   140 	FUNC_LOG;
       
   141 	INFO_1("VideoListSelectionDialog::setupContent() type: %d", type);
       
   142     if(type < EDeleteVideos || type > ESelectCollection)
       
   143     {
       
   144         return;
       
   145     }
       
   146    
       
   147     mTypeOfSelection = type; 
       
   148     if(!initDialog())
       
   149     {
       
   150         ERROR(-1, "VideoListSelectionDialog::setupContent() dialog init failed.");
       
   151         return;
       
   152     }
       
   153     mSelection.clear();
       
   154     mSelectedVideos.clear();
       
   155     mSelectedAlbumId = TMPXItemId::InvalidId();
       
   156     mNewAlbumText = QString();
       
   157     
       
   158     // if provided "owner" is album or category    
       
   159     if(activeItem != TMPXItemId::InvalidId())
       
   160     {
       
   161         // if album, set as "selected"
       
   162         if(activeItem.iId2 == KVcxMvcMediaTypeAlbum)
       
   163         {
       
   164             mSelectedAlbumId = activeItem;
       
   165         }
       
   166         else if(activeItem.iId2 == KVcxMvcMediaTypeVideo)
       
   167         {
       
   168             mSelectedVideos.insert(activeItem);
       
   169         }
       
   170     }
       
   171     // set (or reset) generic id filter
       
   172     bool filterValue = true;
       
   173     if(mTypeOfSelection == EAddToCollection || 
       
   174        mTypeOfSelection == ESelectCollection ||
       
   175        mTypeOfSelection == ECreateCollection)
       
   176     {
       
   177         filterValue = false;
       
   178     }
       
   179     mModel->setGenericIdFilter(activeItem, filterValue);    
       
   180     activateSelection();
       
   181 }
       
   182 
       
   183 // ---------------------------------------------------------------------------
       
   184 // initDialog
       
   185 // ---------------------------------------------------------------------------
       
   186 //
       
   187 bool VideoListSelectionDialog::initDialog()
       
   188 {
       
   189 	FUNC_LOG;
       
   190     if(!mModel)
       
   191     {
       
   192         mModel = VideoCollectionWrapper::instance().getModel(VideoCollectionCommon::EModelTypeGeneric);
       
   193         if (!mModel)
       
   194         {
       
   195            return false;
       
   196         }
       
   197     }  
       
   198     if (!mListContainer)
       
   199     {
       
   200         mListContainer =
       
   201                    mUiLoader->findWidget<HbStackedWidget>(DOCML_NAME_LIST_CONTAINER);
       
   202     
       
   203         if(!mListWidget)
       
   204         {
       
   205             mListWidget = new VideoListWidget(mUiLoader);
       
   206             mListWidget->setObjectName(SELECTION_DIALOG_OBJECT_NAME_LIST_WIDGET);
       
   207             if(mListWidget->initialize(*mModel) < 0)
       
   208             {
       
   209                 ERROR(-1, "VideoListSelectionDialog::initDialog() failed to setup VideoListWidget.");
       
   210                 delete mListWidget;
       
   211                 mListWidget = 0;
       
   212                 mListContainer = 0;
       
   213                 return false;
       
   214             }
       
   215         }
       
   216         if(mListContainer)
       
   217         {
       
   218             mListContainer->addWidget(mListWidget);
       
   219         }
       
   220     }
       
   221 
       
   222     if(!mHeading)
       
   223     {
       
   224         mHeading = mUiLoader->findWidget<HbLabel>(DOCML_NAME_DLG_HEADINGLBL);
       
   225     }
       
   226     if(!mCheckboxContainer)
       
   227     {
       
   228         mCheckboxContainer = mUiLoader->findWidget<HbWidget>(DOCML_NAME_CHECK_CONTAINER);
       
   229     }
       
   230     if(!mItemCount)
       
   231     {
       
   232         mItemCount = mUiLoader->findWidget<HbLabel>(DOCML_NAME_LBL_SELECTION);
       
   233         mItemCount->setAlignment(Qt::AlignRight);
       
   234     }        
       
   235     if(!mCheckBox)
       
   236     {
       
   237         mCheckBox = mUiLoader->findWidget<HbCheckBox >(DOCML_NAME_MARKALL);
       
   238     }
       
   239 
       
   240     if(!mCheckBoxText)
       
   241     {
       
   242         mCheckBoxText = mUiLoader->findWidget<HbLabel >(DOCML_NAME_LBL_MARKALL);
       
   243     }
       
   244 
       
   245     // HbDialog connects actions to finished signal by default. 
       
   246     if(!mPrimaryAction)
       
   247     {
       
   248         mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
       
   249         mPrimaryAction->setObjectName(SELECTION_DIALOG_OBJECT_NAME_BUTTON_OK);
       
   250         addAction(mPrimaryAction);
       
   251     }
       
   252     if(!mSecondaryAction)
       
   253     {
       
   254         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
       
   255         mSecondaryAction->setObjectName(SELECTION_DIALOG_OBJECT_NAME_BUTTON_CANCEL);
       
   256         addAction(mSecondaryAction);
       
   257     }
       
   258     
       
   259     if(!mListContainer || !mHeading || !mCheckBox || !mCheckBoxText)
       
   260     {
       
   261         ERROR(-1, "VideoListSelectionDialog::initDialog() !mListContainer || !mHeading || !mCheckBox || !mCheckBoxText");
       
   262         return false;
       
   263     }
       
   264     return true;  
       
   265 }
       
   266 
       
   267 // ---------------------------------------------------------------------------
       
   268 // activateSelection
       
   269 // ---------------------------------------------------------------------------
       
   270 //
       
   271 void VideoListSelectionDialog::activateSelection()
       
   272 {
       
   273 	FUNC_LOG;
       
   274     // "add to collection", "remove from collection" and "create collection" -selections
       
   275 	// needs additional functionality for primary key
       
   276     if(mTypeOfSelection == EAddToCollection ||
       
   277        mTypeOfSelection == ERemoveFromCollection ||
       
   278        mTypeOfSelection == ECreateCollection)
       
   279     {
       
   280         mPrimaryAction->disconnect(SIGNAL(triggered()));
       
   281         connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(primaryActionTriggeredSlot()));
       
   282     }
       
   283     QString headingTxt("");
       
   284     QString primaryTxt("");
       
   285     // create texts
       
   286     switch(mTypeOfSelection)
       
   287     {
       
   288         case EDeleteVideos:
       
   289             primaryTxt = hbTrId("txt_common_button_delete");
       
   290         break;
       
   291         case EAddToCollection:
       
   292             primaryTxt = hbTrId("txt_common_button_add");
       
   293         break;
       
   294         case ECreateCollection:
       
   295             primaryTxt = hbTrId("txt_common_button_ok");
       
   296         break;
       
   297         case ERemoveFromCollection:
       
   298             primaryTxt = hbTrId("txt_common_button_remove");
       
   299         break;
       
   300         case ESelectCollection:
       
   301             primaryTxt = hbTrId("txt_videos_button_new");
       
   302         break;
       
   303         default:
       
   304         break;
       
   305     }
       
   306 
       
   307     mPrimaryAction->setText(primaryTxt);
       
   308     
       
   309     mModelReady = false;
       
   310     mAlbumListReady = false;
       
   311 
       
   312     if(mTypeOfSelection == ESelectCollection)
       
   313     {
       
   314         headingTxt = hbTrId("txt_videos_title_select_collection");
       
   315         mCheckboxContainer->setVisible(false);
       
   316         mListWidget->setSelectionMode(-1);   
       
   317         mListWidget->activate(VideoCollectionCommon::ELevelCategory);
       
   318         // New collection button is always enabled for collection selection.
       
   319         mPrimaryAction->setDisabled(false);
       
   320     }
       
   321     else
       
   322     {
       
   323         headingTxt = hbTrId("txt_videos_title_select_videos");
       
   324         mListWidget->setSelectionMode(HbAbstractItemView::MultiSelection);
       
   325         mListWidget->activate(VideoCollectionCommon::ELevelVideos);
       
   326         mCheckboxContainer->setVisible(true);
       
   327         mItemCount->setPlainText(tr("0/%1").arg(mModel->rowCount())); 
       
   328         mCheckBox->setChecked(false);
       
   329         
       
   330         // Add button will be enabled when videos are selected from the list.
       
   331         mPrimaryAction->setDisabled(mTypeOfSelection != ECreateCollection);
       
   332     }
       
   333     mHeading->setPlainText(headingTxt);         
       
   334     // sort to make sure dialog has correctly filtered content
       
   335     // at the same order as in view
       
   336     VideoCollectionViewUtils::sortModel(mModel, false, mListWidget->getLevel());        
       
   337 }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // exec
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void VideoListSelectionDialog::exec()
       
   344 {
       
   345 	FUNC_LOG;
       
   346     // clear checkbox
       
   347     mCheckBox->setChecked(false);
       
   348     
       
   349     mListWidget->clearSelection(); 
       
   350     
       
   351     // scroll list back to top
       
   352     mListWidget->scrollTo(mModel->index(0, 0));
       
   353     
       
   354     connectSignals();
       
   355 
       
   356     if(mTypeOfSelection == ECreateCollection)
       
   357     {
       
   358         // note this does not leak memory as the dialog will destroy itself upon close.
       
   359         HbInputDialog *dialog = gCreateNewAlbumNameDialog(LIST_VIEW_OBJECT_NAME_CREATE_COLLECTION);
       
   360         dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
       
   361     }
       
   362     else if(mModel->rowCount())
       
   363     {
       
   364         // show dialog
       
   365         HbDialog::open();
       
   366     }
       
   367     else if((mModelReady && mTypeOfSelection != ESelectCollection) || 
       
   368             (mAlbumListReady && mTypeOfSelection == ESelectCollection))
       
   369     {
       
   370         INFO("VideoListSelectionDialog::exec(): nothing to show, finishing.")
       
   371         // no items, finish right away
       
   372         finishedSlot(mPrimaryAction);
       
   373     }
       
   374 }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // finishedSlot
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void VideoListSelectionDialog::finishedSlot(HbAction *action)
       
   381 {
       
   382 	FUNC_LOG;
       
   383     disconnectSignals();
       
   384     if(action == mSecondaryAction)
       
   385     {
       
   386         INFO("VideoListSelectionDialog::exec(): secondary action triggered.")
       
   387         return;
       
   388     }
       
   389     
       
   390     if(mTypeOfSelection == ESelectCollection)
       
   391     {
       
   392         mTypeOfSelection = EAddToCollection;
       
   393         if(mSelectedAlbumId == TMPXItemId::InvalidId())
       
   394         {
       
   395             close(); // closes selection dialog if it's open.
       
   396             
       
   397             // note this does not leak memory as the dialog will destroy itself upon close.
       
   398             HbInputDialog *dialog = gCreateNewAlbumNameDialog(SELECTION_DIALOG_OBJECT_NAME_NEW_COLLECTION);
       
   399             dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
       
   400        }
       
   401        else
       
   402        {
       
   403            finalize();
       
   404        }
       
   405     }
       
   406     else
       
   407     {
       
   408         finalize();
       
   409     }
       
   410 }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // newAlbumNameDialogFinished
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 void VideoListSelectionDialog::newAlbumNameDialogFinished(HbAction *action)
       
   417 {
       
   418     FUNC_LOG;
       
   419     Q_UNUSED(action);
       
   420     
       
   421     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   422     
       
   423     QVariant variant = dialog->value();
       
   424     
       
   425     if(dialog->actions().first() == action && variant.isValid())
       
   426     {
       
   427         QString text = mModel->resolveAlbumName(variant.toString());
       
   428         if(!text.isEmpty())
       
   429         {
       
   430             if(mSelectedVideos.count() == 0 && mModel->rowCount())
       
   431             {
       
   432                 mNewAlbumText = text;
       
   433                 // show video selection dialog
       
   434                 HbDialog::open();
       
   435             }
       
   436             else
       
   437             {
       
   438                 mSelectedAlbumId = mModel->addNewAlbum(text);
       
   439                 finalize(text);
       
   440             }
       
   441         }
       
   442         else
       
   443         {
       
   444             // new album name empty, effectively cancel, so disconnect signals.
       
   445             disconnectSignals();
       
   446         }
       
   447     }
       
   448     else
       
   449     {
       
   450         // new album dialog cancelled, disconnect signals.
       
   451         disconnectSignals();
       
   452     }
       
   453 }
       
   454 
       
   455 // ---------------------------------------------------------------------------
       
   456 // finalize
       
   457 // ---------------------------------------------------------------------------
       
   458 //
       
   459 void VideoListSelectionDialog::finalize(QString albumName)
       
   460 {
       
   461     // Must be checked again if type was ESelectCollection
       
   462     if(mTypeOfSelection == EAddToCollection ||
       
   463        mTypeOfSelection == ECreateCollection)
       
   464     {
       
   465         if(mTypeOfSelection == ECreateCollection)
       
   466         {
       
   467             mSelectedAlbumId = mModel->addNewAlbum(mNewAlbumText);
       
   468             albumName = mNewAlbumText;
       
   469         }
       
   470         
       
   471         if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count())
       
   472         {
       
   473             if(mModel->addItemsInAlbum(mSelectedAlbumId, mSelectedVideos.toList()) == 0)
       
   474             {
       
   475                 if(!albumName.length())
       
   476                 {
       
   477                     albumName = getSelectedName();
       
   478                 }
       
   479                 QList<QVariant> dataList;
       
   480                 dataList.append(QVariant(mSelectedVideos.count()));
       
   481                 dataList.append(QVariant(albumName));
       
   482                 QVariant data = dataList;
       
   483                 VideoCollectionViewUtils::instance().showStatusMsgSlot(
       
   484                         VideoCollectionCommon::statusVideosAddedToCollection,
       
   485                         data);
       
   486             }
       
   487         }
       
   488     }
       
   489     else if(mTypeOfSelection == ERemoveFromCollection)
       
   490     {
       
   491         if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count())
       
   492         {
       
   493             if(mModel->removeItemsFromAlbum(mSelectedAlbumId, mSelectedVideos.toList()) == 0)
       
   494             {
       
   495                 QVariant data = getSelectedName();
       
   496                 VideoCollectionViewUtils::instance().showStatusMsgSlot(
       
   497                         VideoCollectionCommon::statusVideosRemovedFromCollection,
       
   498                         data);
       
   499             }
       
   500         }
       
   501     }
       
   502     // user is deleting videos
       
   503     else if(mTypeOfSelection == EDeleteVideos)
       
   504     {
       
   505         QVariant data = mSelection.indexes().count();
       
   506         VideoCollectionViewUtils::instance().showStatusMsgSlot(
       
   507                 VideoCollectionCommon::statusDeleteInProgress,
       
   508                 data);
       
   509         // delete items            
       
   510         mModel->deleteItems(mSelection.indexes());
       
   511     } 
       
   512 }
       
   513 
       
   514 // ---------------------------------------------------------------------------
       
   515 // markAllStateChanged
       
   516 // ---------------------------------------------------------------------------
       
   517 //
       
   518 void VideoListSelectionDialog::markAllStateChangedSlot(int state)
       
   519 { 
       
   520 	FUNC_LOG;
       
   521     if(mForcedCheck)
       
   522     {
       
   523         return;
       
   524     }
       
   525     if(state == Qt::Checked)
       
   526     {
       
   527         mListWidget->selectAll();
       
   528     }
       
   529     else
       
   530     {
       
   531         mListWidget->clearSelection();
       
   532     }   
       
   533 }
       
   534 
       
   535 // ---------------------------------------------------------------------------
       
   536 // selectionChangedSlot
       
   537 // ---------------------------------------------------------------------------
       
   538 //
       
   539 void VideoListSelectionDialog::selectionChangedSlot(const QItemSelection &selected, const QItemSelection &deselected)
       
   540 {  
       
   541 	FUNC_LOG;
       
   542     if(!mPrimaryAction || mTypeOfSelection == ESelectCollection)
       
   543     {
       
   544         INFO("VideoListSelectionDialog::selectionChangedSlot(): no primary action or we are selecting collection.")
       
   545         return;
       
   546     }
       
   547    
       
   548     if(selected.indexes().count() > 0)
       
   549     {
       
   550         mSelection.merge(selected, QItemSelectionModel::Select);
       
   551     }
       
   552     
       
   553     if(deselected.indexes().count() >  0)
       
   554     {
       
   555         mSelection.merge(deselected, QItemSelectionModel::Deselect);
       
   556     }
       
   557     
       
   558     if(mSelection.indexes().count() > 0)
       
   559     {
       
   560         mPrimaryAction->setDisabled(false);
       
   561         
       
   562         if(mTypeOfSelection == ECreateCollection)
       
   563         {
       
   564             mPrimaryAction->setText(hbTrId("txt_common_button_add"));
       
   565         }
       
   566     }
       
   567     else
       
   568     {
       
   569         mPrimaryAction->setDisabled(mTypeOfSelection != ECreateCollection);
       
   570         
       
   571         if(mTypeOfSelection == ECreateCollection)
       
   572         {
       
   573             mPrimaryAction->setText(hbTrId("txt_common_button_ok"));
       
   574         }
       
   575     }    
       
   576 
       
   577     updateCounterSlot();
       
   578 }
       
   579 
       
   580 // ---------------------------------------------------------------------------
       
   581 // singleItemSelectedSlot
       
   582 // ---------------------------------------------------------------------------
       
   583 //
       
   584 void VideoListSelectionDialog::singleItemSelectedSlot(const QModelIndex &index)
       
   585 {
       
   586 	FUNC_LOG;
       
   587     if(mTypeOfSelection == ESelectCollection)
       
   588     {
       
   589        if(index.isValid())
       
   590        {
       
   591            mSelectedAlbumId = mModel->getMediaIdAtIndex(index);            
       
   592            mPrimaryAction->trigger();
       
   593        }
       
   594     }
       
   595 }
       
   596 
       
   597 // ---------------------------------------------------------------------------
       
   598 // modelReadySlot
       
   599 // ---------------------------------------------------------------------------
       
   600 //
       
   601 void VideoListSelectionDialog::modelReadySlot()
       
   602 {
       
   603 	FUNC_LOG;
       
   604     mModelReady = true;
       
   605     
       
   606 	if(mTypeOfSelection != ESelectCollection)
       
   607 	{
       
   608         if(!mModel->rowCount())
       
   609         {
       
   610             // no items, finish right away
       
   611             INFO("VideoListSelectionDialog::modelReadySlot(): nothing to show, finishing.");
       
   612             
       
   613             if(mTypeOfSelection == EAddToCollection ||
       
   614                mTypeOfSelection == ERemoveFromCollection)
       
   615             {
       
   616                 primaryActionTriggeredSlot();
       
   617             }
       
   618             else
       
   619             {
       
   620                 finishedSlot(mPrimaryAction);
       
   621             }
       
   622             
       
   623             return;
       
   624         }
       
   625             
       
   626         // if dialog is not yet visible, bring it visible. 
       
   627         if(!isVisible() && mTypeOfSelection != ECreateCollection)
       
   628         {
       
   629             // scroll list back to top
       
   630             mListWidget->scrollTo(mModel->index(0, 0));
       
   631             
       
   632             HbDialog::open();
       
   633         }
       
   634         
       
   635         updateCounterSlot();
       
   636 	}
       
   637 }
       
   638 
       
   639 // ---------------------------------------------------------------------------
       
   640 // albumListReadySlot
       
   641 // ---------------------------------------------------------------------------
       
   642 //
       
   643 void VideoListSelectionDialog::albumListReadySlot()
       
   644 {
       
   645     mAlbumListReady = true;
       
   646     
       
   647     if(mTypeOfSelection == ESelectCollection)
       
   648     {
       
   649         if(!mModel->rowCount())
       
   650         {
       
   651             finishedSlot(mPrimaryAction);
       
   652             return;
       
   653         }
       
   654             
       
   655         // if dialog is not yet visible, bring it visible. 
       
   656         if(!isVisible())
       
   657         {
       
   658             // scroll list back to top
       
   659             mListWidget->scrollTo(mModel->index(0, 0));
       
   660             
       
   661             HbDialog::open();
       
   662         }
       
   663         
       
   664         updateCounterSlot();
       
   665     }
       
   666 }
       
   667 
       
   668 // ---------------------------------------------------------------------------
       
   669 // updateCounterSlot
       
   670 // ---------------------------------------------------------------------------
       
   671 //
       
   672 void VideoListSelectionDialog::updateCounterSlot()
       
   673 {
       
   674 	FUNC_LOG;
       
   675     if(!mItemCount)
       
   676     {
       
   677         return;
       
   678     }
       
   679 
       
   680     int rowCount = mModel->rowCount();       
       
   681     int selectionCount = mSelection.indexes().count();
       
   682     mItemCount->setPlainText(tr("%1/%2").arg(selectionCount).arg(rowCount));  
       
   683     mForcedCheck = true;
       
   684     if(selectionCount == rowCount && rowCount > 0)
       
   685     {     
       
   686         mCheckBox->setChecked(true);
       
   687     }
       
   688     else
       
   689     {
       
   690         mCheckBox->setChecked(false);
       
   691     }
       
   692     mForcedCheck = false;
       
   693 }
       
   694 
       
   695 // ---------------------------------------------------------------------------
       
   696 // primaryActionTriggeredSlot
       
   697 // ---------------------------------------------------------------------------
       
   698 //
       
   699 void VideoListSelectionDialog::primaryActionTriggeredSlot()
       
   700 {
       
   701 	FUNC_LOG;
       
   702     // reconnect primary action
       
   703     mPrimaryAction->disconnect(SIGNAL(triggered()));
       
   704     connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
       
   705 
       
   706     // update video items selection here before content changes.
       
   707     QModelIndexList indexes = mSelection.indexes();
       
   708     int count = indexes.count();
       
   709     TMPXItemId id = TMPXItemId::InvalidId();
       
   710     for(int i = 0; i < count; ++i)
       
   711     {
       
   712         id = mModel->getMediaIdAtIndex(indexes.at(i));
       
   713         if(id.iId2 == KVcxMvcMediaTypeVideo)
       
   714         {
       
   715             mSelectedVideos.insert(id);
       
   716         }
       
   717     }
       
   718     
       
   719     if(mSelectedAlbumId != TMPXItemId::InvalidId() ||
       
   720        mTypeOfSelection == ECreateCollection)
       
   721     {
       
   722         INFO("VideoListSelectionDialog::primaryActionTriggeredSlot(): closing dialog.")
       
   723         mPrimaryAction->trigger();
       
   724         return;
       
   725     }
       
   726     else if(mTypeOfSelection == EAddToCollection)
       
   727     {
       
   728         INFO("VideoListSelectionDialog::primaryActionTriggeredSlot(): activating collection selection.")
       
   729         // videos for collection selected, but collection 
       
   730         // not yet selected, activate selection for it
       
   731         mTypeOfSelection = ESelectCollection;
       
   732         activateSelection();
       
   733    }   
       
   734 }
       
   735 
       
   736 // ---------------------------------------------------------------------------
       
   737 // connectSignals
       
   738 // ---------------------------------------------------------------------------
       
   739 //
       
   740 void VideoListSelectionDialog::connectSignals()
       
   741 {   
       
   742 	FUNC_LOG;
       
   743     // dialog finished
       
   744     connect(this, SIGNAL(finished(HbAction*)), this, SLOT(finishedSlot(HbAction*)));
       
   745     
       
   746     // selection changes
       
   747     connect(mListWidget, SIGNAL(activated(const QModelIndex&)),
       
   748             this, SLOT(singleItemSelectedSlot(const QModelIndex&)));
       
   749     
       
   750     connect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
       
   751             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
       
   752 
       
   753     // model changes signals
       
   754     connect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));
       
   755     connect(mModel->sourceModel(), SIGNAL(albumListReady()), this, SLOT(albumListReadySlot()));
       
   756     connect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));
       
   757     
       
   758     // mark all state changes
       
   759     connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
       
   760 }
       
   761  
       
   762 // ---------------------------------------------------------------------------
       
   763 // disconnectSignals
       
   764 // ---------------------------------------------------------------------------
       
   765 //
       
   766 void VideoListSelectionDialog::disconnectSignals()
       
   767 {   
       
   768 	FUNC_LOG;
       
   769     disconnect(this, SIGNAL(finished(HbAction*)), this, SLOT(finishedSlot(HbAction*)));
       
   770     
       
   771     disconnect(mListWidget, SIGNAL(activated(const QModelIndex&)),
       
   772                 this, SLOT(singleItemSelectedSlot(const QModelIndex&)));
       
   773     
       
   774     disconnect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
       
   775                             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
       
   776 
       
   777     // model changes signals
       
   778     disconnect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));    
       
   779     disconnect(mModel->sourceModel(), SIGNAL(albumListReady()), this, SLOT(albumListReadySlot()));
       
   780     disconnect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));   
       
   781     
       
   782     // mark all state changes
       
   783     disconnect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
       
   784 }
       
   785 
       
   786 // ---------------------------------------------------------------------------
       
   787 // getSelectedName
       
   788 // ---------------------------------------------------------------------------
       
   789 //
       
   790 QString VideoListSelectionDialog::getSelectedName()
       
   791 {
       
   792 	FUNC_LOG;
       
   793     QString name;
       
   794     if(mSelectedAlbumId.iId2 > KVcxMvcMediaTypeVideo)
       
   795     {
       
   796         VideoSortFilterProxyModel *model = 
       
   797                 VideoCollectionWrapper::instance().getModel(
       
   798                 		VideoCollectionCommon::EModelTypeCollections);
       
   799         if(!model)
       
   800         {
       
   801             return name;
       
   802         }
       
   803         QModelIndex index = model->indexOfId(mSelectedAlbumId);
       
   804         if(index.isValid())
       
   805         {
       
   806             name = model->data(index, VideoCollectionCommon::KeyTitle).toString();
       
   807         }
       
   808     }
       
   809     return name;
       
   810 }
       
   811 
       
   812 // End of file