videocollection/videocollectionview/src/videolistselectiondialog.cpp
changeset 37 4eb2df7f7cbe
parent 36 8aed59de29f9
child 38 ff53afa8ad05
equal deleted inserted replaced
36:8aed59de29f9 37:4eb2df7f7cbe
    13 *
    13 *
    14 * Description:   videolist selection dialog implementation
    14 * Description:   videolist selection dialog implementation
    15 * 
    15 * 
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 22 %
    18 // Version : %version: 25 %
    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>
    24 #include <hbaction.h>
    24 #include <hbaction.h>
    25 #include <hbstackedwidget.h>
    25 #include <hbstackedwidget.h>
    26 #include <hbabstractitemview.h>
    26 #include <hbabstractitemview.h>
    27 #include <hbinputdialog.h>
    27 #include <hbinputdialog.h>
    28 #include <vcxmyvideosdefs.h>
    28 #include <vcxmyvideosdefs.h>
       
    29 #include <hbstyleloader.h>
    29 
    30 
    30 #include "videocollectionuiloader.h"
    31 #include "videocollectionuiloader.h"
    31 #include "videolistwidget.h"
    32 #include "videolistwidget.h"
    32 #include "videosortfilterproxymodel.h"
    33 #include "videosortfilterproxymodel.h"
    33 #include "videolistselectiondialog.h"
    34 #include "videolistselectiondialog.h"
    56     , mUiLoader( uiLoader )
    57     , mUiLoader( uiLoader )
    57     , mTypeOfSelection( -1 )
    58     , mTypeOfSelection( -1 )
    58     , mHeading( 0 )
    59     , mHeading( 0 )
    59     , mCheckboxContainer( 0 )
    60     , mCheckboxContainer( 0 )
    60     , mItemCount( 0 )
    61     , mItemCount( 0 )
       
    62     , mCheckBoxText( 0 )
    61     , mCheckBox( 0 )
    63     , mCheckBox( 0 )
    62     , mListContainer( 0 )
    64     , mListContainer( 0 )
    63     , mForcedCheck( false )
    65     , mForcedCheck( false )
    64     , mModel( 0 )
    66     , mModel( 0 )
    65     , mListWidget( 0 )
    67     , mListWidget( 0 )
    66     , mPrimaryAction( 0 )
    68     , mPrimaryAction( 0 )
    67     , mSecondaryAction( 0 )
    69     , mSecondaryAction( 0 )
    68 {
    70 {
    69 	FUNC_LOG;
    71 	FUNC_LOG;
       
    72     
       
    73 	HbStyleLoader::registerFilePath( ":/style/hbdialog.css" );
       
    74 
    70     setDismissPolicy(HbDialog::NoDismiss);
    75     setDismissPolicy(HbDialog::NoDismiss);
    71     setTimeout(HbDialog::NoTimeout);    
    76     setTimeout(HbDialog::NoTimeout);    
    72 
    77 
    73     // create model for list widget
    78     // create model for list widget
    74     mModel =
    79     mModel =
    82         {
    87         {
    83             ERROR(-1, "VideoListSelectionDialog::VideoListSelectionDialog() failed to init list widget");
    88             ERROR(-1, "VideoListSelectionDialog::VideoListSelectionDialog() failed to init list widget");
    84             delete mListWidget;
    89             delete mListWidget;
    85             mListWidget = 0;
    90             mListWidget = 0;
    86         }
    91         }
       
    92         // disable list related animations to make dialog faster 
       
    93         mListWidget->setEnabledAnimations(HbAbstractItemView::None);
    87     }
    94     }
    88 }
    95 }
    89 
    96 
    90 // ---------------------------------------------------------------------------
    97 // ---------------------------------------------------------------------------
    91 // ~VideoListSelectionDialog
    98 // ~VideoListSelectionDialog
    92 // ---------------------------------------------------------------------------
    99 // ---------------------------------------------------------------------------
    93 //
   100 //
    94 VideoListSelectionDialog::~VideoListSelectionDialog() 
   101 VideoListSelectionDialog::~VideoListSelectionDialog() 
    95 {
   102 {
    96 	FUNC_LOG;
   103 	FUNC_LOG;
       
   104 	HbStyleLoader::unregisterFilePath( ":/style/hbdialog.css" );
    97     delete mListWidget;
   105     delete mListWidget;
       
   106     mListWidget = 0;
    98 }
   107 }
    99 
   108 
   100 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
   101 // setupContent
   110 // setupContent
   102 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   196     }        
   205     }        
   197     if(!mCheckBox)
   206     if(!mCheckBox)
   198     {
   207     {
   199         mCheckBox = mUiLoader->findWidget<HbCheckBox >(DOCML_NAME_MARKALL);
   208         mCheckBox = mUiLoader->findWidget<HbCheckBox >(DOCML_NAME_MARKALL);
   200     }
   209     }
       
   210 
       
   211     if(!mCheckBoxText)
       
   212     {
       
   213         mCheckBoxText = mUiLoader->findWidget<HbLabel >(DOCML_NAME_LBL_MARKALL);
       
   214     }
       
   215 
   201     // HbDialog connects actions to finished signal by default. 
   216     // HbDialog connects actions to finished signal by default. 
   202     if(!mPrimaryAction)
   217     if(!mPrimaryAction)
   203     {
   218     {
   204         mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
   219         mPrimaryAction = new HbAction(hbTrId("txt_common_button_ok"));
   205         addAction(mPrimaryAction);
   220         addAction(mPrimaryAction);
   207     if(!mSecondaryAction)
   222     if(!mSecondaryAction)
   208     {
   223     {
   209         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   224         mSecondaryAction = new HbAction(hbTrId("txt_common_button_cancel"));
   210         addAction(mSecondaryAction);
   225         addAction(mSecondaryAction);
   211     }
   226     }
   212     if(!mListContainer || !mHeading || !mCheckBox)
   227     
   213     {
   228     if(!mListContainer || !mHeading || !mCheckBox || !mCheckBoxText)
   214         ERROR(-1, "VideoListSelectionDialog::initDialog() !mListContainer || !mHeading || !mCheckBox");
   229     {
       
   230         ERROR(-1, "VideoListSelectionDialog::initDialog() !mListContainer || !mHeading || !mCheckBox || !mCheckBoxText");
   215         return false;
   231         return false;
   216     }
   232     }
   217     return true;  
   233     return true;  
   218 }
   234 }
   219 
   235 
   329         return;
   345         return;
   330     }
   346     }
   331     QString albumName("");
   347     QString albumName("");
   332     if( mTypeOfSelection == ESelectCollection )
   348     if( mTypeOfSelection == ESelectCollection )
   333     {
   349     {
       
   350         mTypeOfSelection = EAddToCollection;
   334         if( mSelectedAlbumId == TMPXItemId::InvalidId())
   351         if( mSelectedAlbumId == TMPXItemId::InvalidId())
   335         {
   352         {
   336             albumName = queryNewAlbumSelected();
   353             QString label(hbTrId("txt_videos_title_enter_name"));
   337             if(mSelectedAlbumId == TMPXItemId::InvalidId())
   354             HbInputDialog *dialog = new HbInputDialog();
   338             {
   355             dialog->setAttribute(Qt::WA_DeleteOnClose);
   339                 // user canceled new album creation
   356             dialog->getText(label, this, SLOT(newAlbumNameDialogFinished(HbAction *)), 
   340                 return;
   357                     hbTrId("txt_videos_dialog_entry_new_collection"));
   341             }           
       
   342        }
   358        }
   343        mTypeOfSelection = EAddToCollection;
   359        else
   344     }
   360        {
   345     
   361            finalize();
       
   362        }
       
   363     }
       
   364     else
       
   365     {
       
   366         finalize();
       
   367     }
       
   368 }
       
   369 
       
   370 // ---------------------------------------------------------------------------
       
   371 // newAlbumNameDialogFinished
       
   372 // ---------------------------------------------------------------------------
       
   373 //
       
   374 void VideoListSelectionDialog::newAlbumNameDialogFinished(HbAction *action)
       
   375 {
       
   376     FUNC_LOG;
       
   377     Q_UNUSED(action);
       
   378     
       
   379     HbInputDialog *dialog = static_cast<HbInputDialog*>(sender());
       
   380     
       
   381     QVariant variant = dialog->value();
       
   382     
       
   383     if(dialog->actions().first() == action && variant.isValid())
       
   384     {
       
   385         QString text = mModel->resolveAlbumName(variant.toString());
       
   386         if(text.length())
       
   387         {
       
   388             mSelectedAlbumId = mModel->addNewAlbum(text);
       
   389             finalize(text);
       
   390         }
       
   391     }
       
   392 }
       
   393 
       
   394 // ---------------------------------------------------------------------------
       
   395 // finalize
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void VideoListSelectionDialog::finalize(QString albumName)
       
   399 {
   346     // Must be checked again if type was ESelectCollection
   400     // Must be checked again if type was ESelectCollection
   347     if(mTypeOfSelection == EAddToCollection)
   401     if(mTypeOfSelection == EAddToCollection)
   348     {  
   402     {  
   349         if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count())
   403         if(mSelectedAlbumId != TMPXItemId::InvalidId() && mSelectedVideos.count())
   350         {
   404         {
   624     }
   678     }
   625     
   679     
   626     return name;
   680     return name;
   627 }
   681 }
   628 
   682 
   629 // ---------------------------------------------------------------------------
       
   630 // queryNewAlbumSelected
       
   631 // ---------------------------------------------------------------------------
       
   632 //
       
   633 QString VideoListSelectionDialog::queryNewAlbumSelected()
       
   634 {
       
   635 	FUNC_LOG;
       
   636     mSelectedAlbumId = TMPXItemId::InvalidId();
       
   637     bool ok = false;
       
   638     QString label(hbTrId("txt_videos_title_enter_name"));
       
   639     QString text("");
       
   640     text = HbInputDialog::getText(label, hbTrId("txt_videos_dialog_entry_new_collection"), &ok);
       
   641     if (ok && text.length())
       
   642     {
       
   643        // check for duplicate album name and add new album
       
   644         text = mModel->resolveAlbumName(text);
       
   645         mSelectedAlbumId = mModel->addNewAlbum(text);
       
   646     }
       
   647     return text;
       
   648 }
       
   649