mpviewplugins/mpcollectionviewplugin/src/mpcollectionview.cpp
changeset 43 0f32e550d9d8
parent 38 b93f525c9244
child 51 560ce2306a17
equal deleted inserted replaced
38:b93f525c9244 43:0f32e550d9d8
    27 #include <hbmenu.h>
    27 #include <hbmenu.h>
    28 #include <hbmessagebox.h>
    28 #include <hbmessagebox.h>
    29 #include <hblabel.h>
    29 #include <hblabel.h>
    30 #include <hblistview.h>
    30 #include <hblistview.h>
    31 #include <hbscrollbar.h>
    31 #include <hbscrollbar.h>
       
    32 #include <hbstyleloader.h>
    32 
    33 
    33 #include "mpcollectionview.h"
    34 #include "mpcollectionview.h"
    34 #include "mpcollectiondocumentloader.h"
    35 #include "mpcollectiondocumentloader.h"
    35 #include "mpcollectioncontainerfactory.h"
    36 #include "mpcollectioncontainerfactory.h"
    36 #include "mpcollectioncontainer.h"
    37 #include "mpcollectioncontainer.h"
   154 
   155 
   155     mWindow = mainWindow();
   156     mWindow = mainWindow();
   156 
   157 
   157     // Create softkey actions
   158     // Create softkey actions
   158     mSoftKeyQuit = new HbAction( Hb::QuitNaviAction, this );
   159     mSoftKeyQuit = new HbAction( Hb::QuitNaviAction, this );
   159     connect( mSoftKeyQuit, SIGNAL( triggered() ), this, SLOT( back() ) );
   160     connect( mSoftKeyQuit, SIGNAL( triggered() ), 
       
   161 	         this, SLOT( back() ) );
   160 
   162 
   161     mSoftKeyBack = new HbAction( Hb::BackNaviAction, this );
   163     mSoftKeyBack = new HbAction( Hb::BackNaviAction, this );
   162     connect( mSoftKeyBack, SIGNAL( triggered() ), this, SLOT( back() ) );
   164     connect( mSoftKeyBack, SIGNAL( triggered() ), 
       
   165 	         this, SLOT( back() ) );
   163 
   166 
   164     mMpEngine = MpEngineFactory::sharedEngine();
   167     mMpEngine = MpEngineFactory::sharedEngine();
   165 
   168 
   166     connect( mMpEngine, SIGNAL( collectionPlaylistOpened() ),
   169     connect( mMpEngine, SIGNAL( collectionPlaylistOpened() ),
   167             this, SLOT( startPlaybackView() ) );
   170             this, SLOT( startPlaybackView() ) );
   175             this, SLOT( handleIsolatedCollectionOpened( MpMpxCollectionData* ) ) );
   178             this, SLOT( handleIsolatedCollectionOpened( MpMpxCollectionData* ) ) );
   176 
   179 
   177     mCollectionData = mMpEngine->collectionData();
   180     mCollectionData = mMpEngine->collectionData();
   178     qRegisterMetaType<TCollectionContext>("TCollectionContext");
   181     qRegisterMetaType<TCollectionContext>("TCollectionContext");
   179     connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), 
   182     connect( mCollectionData, SIGNAL( contextChanged( TCollectionContext ) ), 
   180              this, SLOT( setContext( TCollectionContext ) ), Qt::QueuedConnection );
   183              this, SLOT( setContext( TCollectionContext ) ), 
       
   184 			 Qt::QueuedConnection );
   181     mCollectionDataModel = new MpCollectionDataModel( mCollectionData );
   185     mCollectionDataModel = new MpCollectionDataModel( mCollectionData );
       
   186     
       
   187     connect( mCollectionDataModel, SIGNAL( dataReloaded() ),
       
   188              this, SLOT( containerDataChanged() ) );
   182 
   189 
   183     mDocumentLoader = new MpCollectionDocumentLoader();
   190     mDocumentLoader = new MpCollectionDocumentLoader();
   184     bool ok = false;
   191     bool ok = false;
   185     mDocumentLoader->load( MUSIC_COLLECTION_DOCML, &ok );
   192     mDocumentLoader->load( MUSIC_COLLECTION_DOCML, &ok );
   186     if ( ok ) {
   193     if ( ok ) {
   194             // from playback preview. Disable the banner from updating.
   201             // from playback preview. Disable the banner from updating.
   195             mNowPlayingBanner->setEnabled( false );
   202             mNowPlayingBanner->setEnabled( false );
   196             attachNowPlayingBanner( false );
   203             attachNowPlayingBanner( false );
   197         }
   204         }
   198         else {
   205         else {
   199             connect( mNowPlayingBanner, SIGNAL( clicked() ), this, SLOT( startPlaybackView() ) );
   206             connect( mNowPlayingBanner, SIGNAL( clicked() ), 
       
   207 				     this, SLOT( startPlaybackView() ) );
   200             connect( mNowPlayingBanner, SIGNAL( playbackAttachmentChanged( bool ) ),
   208             connect( mNowPlayingBanner, SIGNAL( playbackAttachmentChanged( bool ) ),
   201                      this, SLOT( attachNowPlayingBanner( bool ) ) );
   209                      this, SLOT( attachNowPlayingBanner( bool ) ) );
   202             attachNowPlayingBanner( mNowPlayingBanner->isBannerAttached() );
   210             attachNowPlayingBanner( mNowPlayingBanner->isBannerAttached() );
   203         }
   211         }
   204 
   212 
   217     else {
   225     else {
   218         TX_LOG_ARGS( "Error: invalid xml file." );
   226         TX_LOG_ARGS( "Error: invalid xml file." );
   219         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   227         Q_ASSERT_X( ok, "MpCollectionView::initializeView", "invalid xml file" );
   220     }
   228     }
   221 
   229 
       
   230     // Load custom tbone css here so we do it only once.
       
   231     HbStyleLoader::registerFilePath(":/css/tbonemediawall.css");
       
   232     HbStyleLoader::registerFilePath(":/css/tbonemediawall_color.css");
       
   233     HbStyleLoader::registerFilePath(":/css/tbonemediawall.hgmediawall.widgetml");
       
   234         
   222     mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader );
   235     mContainerFactory = new MpCollectionContainerFactory( this, mDocumentLoader );
   223     
   236     
   224     mMpPopupHandler = new MpCollectionPopupHandler( this );
   237     mMpPopupHandler = new MpCollectionPopupHandler( this );
   225 
   238 
   226     connect( mMpEngine, SIGNAL( usbBlocked(bool) ),
   239     connect( mMpEngine, SIGNAL( usbBlocked(bool) ),
   310 {
   323 {
   311     TX_ENTRY_ARGS( "index = " << index );
   324     TX_ENTRY_ARGS( "index = " << index );
   312     QModelIndex modelIndex;
   325     QModelIndex modelIndex;
   313     modelIndex = mCollectionDataModel->index( index );
   326     modelIndex = mCollectionDataModel->index( index );
   314     qobject_cast<MpCollectionListContainer*>(mCollectionContainer)->itemActivated( modelIndex );
   327     qobject_cast<MpCollectionListContainer*>(mCollectionContainer)->itemActivated( modelIndex );
       
   328     TX_EXIT
       
   329 }
       
   330 
       
   331 /*!
       
   332  Shows the detailed metadata information for the song with \a index.
       
   333  It activates details view.
       
   334  */
       
   335 void MpCollectionView::showItemDetails( int index )
       
   336 {
       
   337     TX_ENTRY_ARGS( "index = " << index );
       
   338     mMpEngine->retrieveSongDetails( index );
       
   339     emit command( MpCommon::ActivateDetailsView );
   315     TX_EXIT
   340     TX_EXIT
   316 }
   341 }
   317 
   342 
   318 /*!
   343 /*!
   319  Slot to be called when collection context is changed as a result of Open
   344  Slot to be called when collection context is changed as a result of Open
   792     }
   817     }
   793     TX_EXIT
   818     TX_EXIT
   794 }
   819 }
   795 
   820 
   796 /*!
   821 /*!
       
   822  Slot to be called when a container data is changed/updated.
       
   823  */
       
   824 void MpCollectionView::containerDataChanged()
       
   825 {
       
   826     TX_ENTRY
       
   827     if ( mCollectionContext == ECollectionContextPlaylistSongs ) {
       
   828          updateToolBar();
       
   829     }
       
   830     TX_EXIT
       
   831 }
       
   832 
       
   833 /*!
   797  \internal
   834  \internal
   798  Sets the main ( default ) toolbar for the view.
   835  Sets the main ( default ) toolbar for the view.
   799  */
   836  */
   800 void MpCollectionView::setMainToolBar()
   837 void MpCollectionView::setMainToolBar()
   801 {
   838 {
   958                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
   995                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
   959                 }
   996                 }
   960                 else {
   997                 else {
   961                     menuAction->setDisabled( true );
   998                     menuAction->setDisabled( true );
   962                 }
   999                 }
   963                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) );
  1000                 addDefaultMenuOptions( myMenu, true, true );
   964                 if ( !mUsbBlocked ) {
       
   965                     connect( menuAction, SIGNAL( triggered() ), mMpEngine, SLOT( refreshLibrary() ) );
       
   966                 }
       
   967                 else {
       
   968                     menuAction->setDisabled( true );
       
   969                 }
       
   970                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
       
   971                 break;
  1001                 break;
   972             case ECollectionContextArtists:
  1002             case ECollectionContextArtists:
       
  1003             case ECollectionContextArtistAlbums:
   973             case ECollectionContextAlbums:
  1004             case ECollectionContextAlbums:
   974                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) );
  1005                 addDefaultMenuOptions( myMenu, true, true );
   975                 if ( !mUsbBlocked ) {
       
   976                     connect( menuAction, SIGNAL( triggered() ), mMpEngine, SLOT( refreshLibrary() ) );                
       
   977                 }
       
   978                 else {
       
   979                     menuAction->setDisabled( true );
       
   980                 }
       
   981                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
       
   982                 break;
  1006                 break;
   983             case ECollectionContextArtistAlbumsTBone:
  1007             case ECollectionContextArtistAlbumsTBone:
   984             case ECollectionContextAlbumsTBone:
  1008             case ECollectionContextAlbumsTBone:
   985                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
  1009                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
   986                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
  1010                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
   992                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
  1016                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
   993                 }
  1017                 }
   994                 else {
  1018                 else {
   995                     menuAction->setDisabled( true );
  1019                     menuAction->setDisabled( true );
   996                 }
  1020                 }
       
  1021                 addDefaultMenuOptions( myMenu, true, true );
   997                 break;
  1022                 break;
   998             case ECollectionContextArtistAllSongs:
  1023             case ECollectionContextArtistAllSongs:
   999                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
  1024                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
  1000                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
  1025                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
  1001                 if ( count <= 1 ) {
  1026                 if ( count <= 1 ) {
  1006                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
  1031                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( addToPlaylist() ) );
  1007                 }
  1032                 }
  1008                 else {
  1033                 else {
  1009                     menuAction->setDisabled( true );
  1034                     menuAction->setDisabled( true );
  1010                 }
  1035                 }
       
  1036                 addDefaultMenuOptions( myMenu, true, true );
  1011                 break;
  1037                 break;
  1012             case ECollectionContextPlaylists:
  1038             case ECollectionContextPlaylists:
  1013                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_new_playlist" ) );
  1039                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_new_playlist" ) );
  1014                 if ( !mUsbBlocked ) {
  1040                 if ( !mUsbBlocked ) {
  1015                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( prepareToAddToPlaylist() ) );
  1041                     connect( menuAction, SIGNAL( triggered() ), this, SLOT( prepareToAddToPlaylist() ) );
  1016                 }
  1042                 }
  1017                 else {
  1043                 else {
  1018                     menuAction->setDisabled( true );
  1044                     menuAction->setDisabled( true );
  1019                 }
  1045                 }
  1020                 connect( myMenu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL(triggered()), this, SLOT(exit()) );
  1046                 addDefaultMenuOptions( myMenu, true, true );
  1021                 break;
  1047                 break;
  1022             case ECollectionContextPlaylistSongs:
  1048             case ECollectionContextPlaylistSongs:
  1023                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
  1049                 mShuffleAction = myMenu->addAction( hbTrId( "txt_mus_opt_shuffle" ) );
  1024                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
  1050                 connect( mShuffleAction, SIGNAL( triggered() ), this, SLOT( shufflePlayAll() ) );
  1025                 if ( count <= 1 ) {
  1051                 if ( count <= 1 ) {
  1032                     }
  1058                     }
  1033                     else {
  1059                     else {
  1034                         menuAction->setDisabled( true );
  1060                         menuAction->setDisabled( true );
  1035                     }
  1061                     }
  1036                 }
  1062                 }
       
  1063                 addDefaultMenuOptions( myMenu, true, true );
  1037                 break;
  1064                 break;
  1038             default:
  1065             default:
  1039                 break;
  1066                 break;
  1040         }
  1067         }
  1041     }
  1068     }
  1042     else if ( mViewMode == MpCommon::FetchView ) {
  1069     else if ( mViewMode == MpCommon::FetchView ) {
  1043         switch ( mCollectionContext ) {
  1070         switch ( mCollectionContext ) {
  1044             case ECollectionContextAllSongs:
  1071             case ECollectionContextAllSongs:
  1045             case ECollectionContextArtists:
  1072             case ECollectionContextArtists:
  1046             case ECollectionContextAlbums:
  1073             case ECollectionContextAlbums:
  1047                 menuAction = myMenu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) );
  1074                 addDefaultMenuOptions( myMenu, true, false );
  1048                 if ( !mUsbBlocked ) {
       
  1049                     connect( menuAction, SIGNAL( triggered() ), mMpEngine, SLOT( refreshLibrary() ) );
       
  1050                 }
       
  1051                 else {
       
  1052                     menuAction->setDisabled( true );
       
  1053                 }
       
  1054                 break;
  1075                 break;
  1055             default:
  1076             default:
  1056                 break;
  1077                 break;
  1057         }
  1078         }
  1058     }
  1079     }
  1059 
  1080 
  1060     setMenu( myMenu );
  1081     setMenu( myMenu );
       
  1082     TX_EXIT
       
  1083 }
       
  1084 
       
  1085 /*!
       
  1086  \internal
       
  1087  Add default options to a specific menu.
       
  1088  */
       
  1089 void MpCollectionView::addDefaultMenuOptions( HbMenu *menu, bool optRefresh, bool optExit )
       
  1090 {
       
  1091     TX_ENTRY
       
  1092     if ( menu ) {
       
  1093         HbAction *menuAction;
       
  1094         if( optRefresh ) {
       
  1095             menuAction = menu->addAction( hbTrId( "txt_mus_opt_refresh_library" ) );
       
  1096             if ( !mUsbBlocked ) {
       
  1097                 connect( menuAction, SIGNAL( triggered() ), mMpEngine, SLOT( refreshLibrary() ) );
       
  1098             }
       
  1099             else {
       
  1100                 menuAction->setDisabled( true );
       
  1101                 }
       
  1102         }
       
  1103         if ( optExit ) {
       
  1104             connect( menu->addAction(hbTrId("txt_common_opt_exit")), SIGNAL( triggered() ), this, SLOT( exit() ) );
       
  1105         }
       
  1106     }
  1061     TX_EXIT
  1107     TX_EXIT
  1062 }
  1108 }
  1063 
  1109 
  1064 /*!
  1110 /*!
  1065  \internal
  1111  \internal