videocollection/videocollectionview/src/videolistselectiondialog.cpp
changeset 52 e3cecb93e76a
parent 46 adbe7d5ba2f5
child 59 a76e86df7ccd
equal deleted inserted replaced
47:45e72b57a2fd 52:e3cecb93e76a
    13 *
    13 *
    14 * Description:   videolist selection dialog implementation
    14 * Description:   videolist selection dialog implementation
    15 * 
    15 * 
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 30 %
    18 // Version : %version: 30.1.2 %
    19 
    19 
    20 // INCLUDE FILES
    20 // INCLUDE FILES
    21 #include <qgraphicsitem.h>
    21 #include <qgraphicsitem.h>
    22 #include <hblabel.h>
    22 #include <hblabel.h>
    23 #include <hbcheckbox.h>
    23 #include <hbcheckbox.h>
    84     , mCheckBoxText( 0 )
    84     , mCheckBoxText( 0 )
    85     , mCheckBox( 0 )
    85     , mCheckBox( 0 )
    86     , mListContainer( 0 )
    86     , mListContainer( 0 )
    87     , mForcedCheck( false )
    87     , mForcedCheck( false )
    88     , mModel( 0 )
    88     , mModel( 0 )
       
    89     , mModelReady( false )
       
    90     , mAlbumListReady( false )
    89     , mListWidget( 0 )
    91     , mListWidget( 0 )
    90     , mPrimaryAction( 0 )
    92     , mPrimaryAction( 0 )
    91     , mSecondaryAction( 0 )
    93     , mSecondaryAction( 0 )
    92 {
    94 {
    93 	FUNC_LOG;
    95 	FUNC_LOG;
   301         default:
   303         default:
   302         break;
   304         break;
   303     }
   305     }
   304 
   306 
   305     mPrimaryAction->setText(primaryTxt);
   307     mPrimaryAction->setText(primaryTxt);
       
   308     
       
   309     mModelReady = false;
       
   310     mAlbumListReady = false;
   306 
   311 
   307     if(mTypeOfSelection == ESelectCollection)
   312     if(mTypeOfSelection == ESelectCollection)
   308     {
   313     {
   309         headingTxt = hbTrId("txt_videos_title_select_collection");
   314         headingTxt = hbTrId("txt_videos_title_select_collection");
   310         mCheckboxContainer->setVisible(false);
   315         mCheckboxContainer->setVisible(false);
   344     mListWidget->clearSelection(); 
   349     mListWidget->clearSelection(); 
   345     
   350     
   346     // scroll list back to top
   351     // scroll list back to top
   347     mListWidget->scrollTo(mModel->index(0, 0));
   352     mListWidget->scrollTo(mModel->index(0, 0));
   348     
   353     
       
   354     connectSignals();
       
   355 
   349     if(mModel->rowCount())
   356     if(mModel->rowCount())
   350     {
   357     {
   351         connectSignals();
       
   352     
       
   353         if(mTypeOfSelection == ECreateCollection)
   358         if(mTypeOfSelection == ECreateCollection)
   354         {
   359         {
   355             // note this does not leak memory as the dialog will destroy itself upon close.
   360             // note this does not leak memory as the dialog will destroy itself upon close.
   356             HbInputDialog *dialog = gCreateNewAlbumNameDialog(LIST_VIEW_OBJECT_NAME_CREATE_COLLECTION);
   361             HbInputDialog *dialog = gCreateNewAlbumNameDialog(LIST_VIEW_OBJECT_NAME_CREATE_COLLECTION);
   357             dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
   362             dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
   360         {
   365         {
   361             // show dialog
   366             // show dialog
   362             HbDialog::open();
   367             HbDialog::open();
   363         }
   368         }
   364     }
   369     }
   365     else
   370     else if((mModelReady && mTypeOfSelection != ESelectCollection) || 
       
   371             (mAlbumListReady && mTypeOfSelection == ESelectCollection))
   366     {
   372     {
   367         INFO("VideoListSelectionDialog::exec(): nothing to show, finishing.")
   373         INFO("VideoListSelectionDialog::exec(): nothing to show, finishing.")
   368         // no items, finish right away
   374         // no items, finish right away
   369         finishedSlot(mPrimaryAction);
   375         finishedSlot(mPrimaryAction);
   370     }
   376     }
   387     if(mTypeOfSelection == ESelectCollection)
   393     if(mTypeOfSelection == ESelectCollection)
   388     {
   394     {
   389         mTypeOfSelection = EAddToCollection;
   395         mTypeOfSelection = EAddToCollection;
   390         if(mSelectedAlbumId == TMPXItemId::InvalidId())
   396         if(mSelectedAlbumId == TMPXItemId::InvalidId())
   391         {
   397         {
       
   398             close(); // closes selection dialog if it's open.
       
   399             
   392             // note this does not leak memory as the dialog will destroy itself upon close.
   400             // note this does not leak memory as the dialog will destroy itself upon close.
   393             HbInputDialog *dialog = gCreateNewAlbumNameDialog(SELECTION_DIALOG_OBJECT_NAME_NEW_COLLECTION);
   401             HbInputDialog *dialog = gCreateNewAlbumNameDialog(SELECTION_DIALOG_OBJECT_NAME_NEW_COLLECTION);
   394             dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
   402             dialog->open(this, SLOT(newAlbumNameDialogFinished(HbAction *)));
   395        }
   403        }
   396        else
   404        else
   418     QVariant variant = dialog->value();
   426     QVariant variant = dialog->value();
   419     
   427     
   420     if(dialog->actions().first() == action && variant.isValid())
   428     if(dialog->actions().first() == action && variant.isValid())
   421     {
   429     {
   422         QString text = mModel->resolveAlbumName(variant.toString());
   430         QString text = mModel->resolveAlbumName(variant.toString());
   423         if(text.length())
   431         if(!text.isEmpty())
   424         {
   432         {
   425             if(mSelectedVideos.count() == 0)
   433             if(mSelectedVideos.count() == 0)
   426             {
   434             {
   427                 mNewAlbumText = text;
   435                 mNewAlbumText = text;
   428                 // show video selection dialog
   436                 // show video selection dialog
   432             {
   440             {
   433                 mSelectedAlbumId = mModel->addNewAlbum(text);
   441                 mSelectedAlbumId = mModel->addNewAlbum(text);
   434                 finalize(text);
   442                 finalize(text);
   435             }
   443             }
   436         }
   444         }
       
   445         else
       
   446         {
       
   447             // new album name empty, effectively cancel, so disconnect signals.
       
   448             disconnectSignals();
       
   449         }
       
   450     }
       
   451     else
       
   452     {
       
   453         // new album dialog cancelled, disconnect signals.
       
   454         disconnectSignals();
   437     }
   455     }
   438 }
   456 }
   439 
   457 
   440 // ---------------------------------------------------------------------------
   458 // ---------------------------------------------------------------------------
   441 // finalize
   459 // finalize
   584 // ---------------------------------------------------------------------------
   602 // ---------------------------------------------------------------------------
   585 //
   603 //
   586 void VideoListSelectionDialog::modelReadySlot()
   604 void VideoListSelectionDialog::modelReadySlot()
   587 {
   605 {
   588 	FUNC_LOG;
   606 	FUNC_LOG;
       
   607     mModelReady = true;
       
   608     
       
   609 	if(mTypeOfSelection != ESelectCollection)
       
   610 	{
       
   611         if(!mModel->rowCount())
       
   612         {
       
   613             // no items, finish right away
       
   614             INFO("VideoListSelectionDialog::modelReadySlot(): nothing to show, finishing.");
       
   615             
       
   616             if(mTypeOfSelection == EAddToCollection ||
       
   617                mTypeOfSelection == ERemoveFromCollection)
       
   618             {
       
   619                 primaryActionTriggeredSlot();
       
   620             }
       
   621             else
       
   622             {
       
   623                 finishedSlot(mPrimaryAction);
       
   624             }
       
   625             
       
   626             return;
       
   627         }
       
   628             
       
   629         // if dialog is not yet visible, bring it visible. 
       
   630         if(!isVisible() && mTypeOfSelection != ECreateCollection)
       
   631         {
       
   632             // scroll list back to top
       
   633             mListWidget->scrollTo(mModel->index(0, 0));
       
   634             
       
   635             HbDialog::open();
       
   636         }
       
   637         
       
   638         updateCounterSlot();
       
   639 	}
       
   640 }
       
   641 
       
   642 // ---------------------------------------------------------------------------
       
   643 // albumListReadySlot
       
   644 // ---------------------------------------------------------------------------
       
   645 //
       
   646 void VideoListSelectionDialog::albumListReadySlot()
       
   647 {
       
   648     mAlbumListReady = true;
       
   649     
   589     if(mTypeOfSelection == ESelectCollection)
   650     if(mTypeOfSelection == ESelectCollection)
   590     {
   651     {
   591         if(!mModel->rowCount())
   652         if(!mModel->rowCount())
   592         {
   653         {
   593             // in case there are no user defined albums, 
   654             finishedSlot(mPrimaryAction);
   594             // start input dialog right away by accepting dialog
       
   595             INFO("VideoListSelectionDialog::selectionChangedSlot(): no albums, starting album creation.")
       
   596             mPrimaryAction->trigger();
       
   597             return;
   655             return;
   598         }
   656         }
   599     }
   657             
   600     updateCounterSlot();
   658         // if dialog is not yet visible, bring it visible. 
       
   659         if(!isVisible())
       
   660         {
       
   661             // scroll list back to top
       
   662             mListWidget->scrollTo(mModel->index(0, 0));
       
   663             
       
   664             HbDialog::open();
       
   665         }
       
   666         
       
   667         updateCounterSlot();
       
   668     }
   601 }
   669 }
   602 
   670 
   603 // ---------------------------------------------------------------------------
   671 // ---------------------------------------------------------------------------
   604 // updateCounterSlot
   672 // updateCounterSlot
   605 // ---------------------------------------------------------------------------
   673 // ---------------------------------------------------------------------------
   637     // reconnect primary action
   705     // reconnect primary action
   638     mPrimaryAction->disconnect(SIGNAL(triggered()));
   706     mPrimaryAction->disconnect(SIGNAL(triggered()));
   639     connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   707     connect(mPrimaryAction, SIGNAL(triggered()), this, SLOT(close()));
   640 
   708 
   641     // update video items selection here before content changes.
   709     // update video items selection here before content changes.
   642     int count = mSelection.indexes().count();
   710     QModelIndexList indexes = mSelection.indexes();
       
   711     int count = indexes.count();
   643     TMPXItemId id = TMPXItemId::InvalidId();
   712     TMPXItemId id = TMPXItemId::InvalidId();
   644     for(int i = 0; i < count; ++i)
   713     for(int i = 0; i < count; ++i)
   645     {
   714     {
   646         id = mModel->getMediaIdAtIndex(mSelection.indexes().at(i));
   715         id = mModel->getMediaIdAtIndex(indexes.at(i));
   647         if(id.iId2 == KVcxMvcMediaTypeVideo)
   716         if(id.iId2 == KVcxMvcMediaTypeVideo)
   648         {
   717         {
   649             mSelectedVideos.insert(id);
   718             mSelectedVideos.insert(id);
   650         }
   719         }
   651     }
   720     }
   683     
   752     
   684     connect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
   753     connect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
   685             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
   754             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
   686 
   755 
   687     // model changes signals
   756     // model changes signals
   688     connect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));    
   757     connect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));
   689     connect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));    
   758     connect(mModel->sourceModel(), SIGNAL(albumListReady()), this, SLOT(albumListReadySlot()));
       
   759     connect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));
   690     
   760     
   691     // mark all state changes
   761     // mark all state changes
   692     connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
   762     connect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
   693 }
   763 }
   694  
   764  
   707     disconnect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
   777     disconnect(mListWidget->selectionModel(), SIGNAL(selectionChanged (const QItemSelection&, const QItemSelection&)),
   708                             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
   778                             this, SLOT(selectionChangedSlot(const QItemSelection&, const QItemSelection &)));
   709 
   779 
   710     // model changes signals
   780     // model changes signals
   711     disconnect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));    
   781     disconnect(mModel->sourceModel(), SIGNAL(modelReady()), this, SLOT(modelReadySlot()));    
       
   782     disconnect(mModel->sourceModel(), SIGNAL(albumListReady()), this, SLOT(albumListReadySlot()));
   712     disconnect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));   
   783     disconnect(mModel->sourceModel(), SIGNAL(modelChanged()), this, SLOT(updateCounterSlot()));   
   713     
   784     
   714     // mark all state changes
   785     // mark all state changes
   715     disconnect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
   786     disconnect(mCheckBox, SIGNAL(stateChanged(int)), this, SLOT(markAllStateChangedSlot(int)));
   716 }
   787 }