mpxplugins/viewplugins/views/collectionview/src/mpxcollectionviewcontainer.cpp
changeset 0 ff3acec5bc43
child 21 a1247965635c
equal deleted inserted replaced
-1:000000000000 0:ff3acec5bc43
       
     1 /*
       
     2 * Copyright (c) 2006 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:  Implementation of Collection view container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <hlplch.h>
       
    21 #include <aknappui.h>
       
    22 #include <akncontext.h>
       
    23 #include <AknsUtils.h>  // AknsUtils
       
    24 #include <AknUtils.h>
       
    25 #include <data_caging_path_literals.hrh>
       
    26 #include <eikspane.h>
       
    27 #include <eiktxlbx.h>
       
    28 #include <mpxcollectionview.mbg>
       
    29 #include <mpxplaybackframeworkdefs.h>
       
    30 #include <mpxmediageneraldefs.h>
       
    31 #include <mpxmedia.h>
       
    32 #include <mpxconstants.h>
       
    33 #include <mpxlog.h>
       
    34 #include <eikon.hrh>
       
    35 #include <mpxuser.h>
       
    36 
       
    37 #include "mpxcollectionview.hrh"
       
    38 #include "mpxcollectionviewlistboxarray.h"
       
    39 #include "mpxcollectionview.hlp.hrh"
       
    40 #include "mpxcollectionviewcontainer.h"
       
    41 
       
    42 // CONSTANTS
       
    43 _LIT( KMPXCollectionViewIconFile, "mpxcollectionview.mbm" );
       
    44 
       
    45 // ======== MEMBER FUNCTIONS ========
       
    46 
       
    47 // ---------------------------------------------------------------------------
       
    48 // Two-phased constructor.
       
    49 // ---------------------------------------------------------------------------
       
    50 //
       
    51 CMPXCollectionViewContainer* CMPXCollectionViewContainer::NewL(
       
    52     MEikCommandObserver* aView,
       
    53     MEikListBoxObserver* aObserver,
       
    54     TBool aIsEmbedded)
       
    55     {
       
    56     MPX_FUNC( "CMPXCollectionViewContainer::NewL" );
       
    57     CMPXCollectionViewContainer* self =
       
    58         new ( ELeave ) CMPXCollectionViewContainer(aView, aObserver, aIsEmbedded);
       
    59     CleanupStack::PushL( self );
       
    60     self->ConstructL();
       
    61     CleanupStack::Pop( self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // C++ constructor can NOT contain any code that might leave.
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CMPXCollectionViewContainer::CMPXCollectionViewContainer(
       
    70     MEikCommandObserver* aView,
       
    71     MEikListBoxObserver* aObserver,
       
    72     TBool aIsEmbedded) 
       
    73     : iView( aView )
       
    74     , iListBoxObserver( aObserver )
       
    75     , iReady( EFalse )
       
    76     , iIsEmbedded(aIsEmbedded)    
       
    77     {
       
    78     }
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // Destructor
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 CMPXCollectionViewContainer::~CMPXCollectionViewContainer()
       
    85     {
       
    86     MPX_FUNC( "CMPXCollectionViewContainer::~CMPXCollectionViewContainer" );
       
    87     delete iCommonContainer;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // Symbian 2nd phase constructor can leave.
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 void CMPXCollectionViewContainer::ConstructL()
       
    95     {
       
    96     MPX_FUNC( "CMPXCollectionViewContainer::ConstructL" );
       
    97     iCommonContainer = CMPXCommonContainerFactory::NewL();
       
    98     iCommonContainer->SetViewContainer( this );
       
    99     iCommonContainer->SetCommandObserver( iView );
       
   100     iCommonContainer->SetListBoxObserver( iListBoxObserver );
       
   101     iCommonContainer->ConstructContainerL( MMPXCommonContainer::EMPXCommonContainerMusic );
       
   102     iLbxArray = static_cast<CMPXCollectionViewListBoxArray*>(
       
   103         CreateListBoxArrayL() );
       
   104     iCommonContainer->SetListBoxArrayL( iLbxArray );
       
   105     iCommonContainer->HandleListBoxArrayEventL(
       
   106         MMPXCommonListBoxArrayObserver::EMPXCommonListBoxArrayEventIconArrayChange );
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // Sets playback status
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CMPXCollectionViewContainer::SetPlaybackStatusByIdL(
       
   114     TMPXItemId aId, TMPXPlaybackState aStatus, TInt aIndex)
       
   115     {
       
   116     MPX_FUNC( "CMPXCollectionViewContainer::SetPlaybackStatusByIdL" );
       
   117     if ( iLbxArray && iCommonContainer )
       
   118         {
       
   119         TInt index( iLbxArray->SetPlaybackStatusByIdL( aId, aStatus, aIndex ) );
       
   120         if ( index != KErrNotFound )
       
   121             {
       
   122             // Update the previous item as not playing anymore
       
   123             iCommonContainer->DrawLbxItem( index );
       
   124             }
       
   125         index = iLbxArray->GetPlaybackIndex();
       
   126         if ( index != KErrNotFound )
       
   127             {
       
   128             // Update new item as playing
       
   129             iCommonContainer->DrawLbxItem( index );
       
   130             }
       
   131         }
       
   132     }
       
   133 
       
   134 // ---------------------------------------------------------------------------
       
   135 // Get playback index
       
   136 // ---------------------------------------------------------------------------
       
   137 //
       
   138 TInt CMPXCollectionViewContainer::PlaybackIndex()
       
   139     {
       
   140     MPX_FUNC( "CMPXCollectionViewContainer::PlaybackIndex" );
       
   141     return ( iLbxArray ? iLbxArray->GetPlaybackIndex() : KErrNotFound );
       
   142     }
       
   143 
       
   144 // ---------------------------------------------------------------------------
       
   145 // Activate reorder mode
       
   146 // ---------------------------------------------------------------------------
       
   147 //
       
   148 void CMPXCollectionViewContainer::ActivateReorderMode( TBool aEnable )
       
   149     {
       
   150     MPX_FUNC( "CMPXCollectionViewContainer::ActivateReorderMode" );
       
   151     if ( iLbxArray )
       
   152         {
       
   153         iReorder = aEnable;
       
   154         iLbxArray->ActivateReorderMode( iReorder );
       
   155         }
       
   156     }
       
   157 
       
   158 // ---------------------------------------------------------------------------
       
   159 // Set reorder mode
       
   160 // ---------------------------------------------------------------------------
       
   161 //
       
   162 void CMPXCollectionViewContainer::SetReorderGrabbedMode(
       
   163     TBool aEnable, TInt aIndex )
       
   164     {
       
   165     MPX_FUNC( "CMPXCollectionViewContainer::SetReorderGrabbedMode" );
       
   166     if ( iLbxArray )
       
   167         {
       
   168         iLbxArray->SetReorderGrabbedMode( aEnable, aIndex );
       
   169         }
       
   170     }
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // Determines if it's currently in reorder mode
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 TBool CMPXCollectionViewContainer::IsInReorderMode()
       
   177     {
       
   178     MPX_FUNC( "CMPXCollectionViewContainer::IsInReorderMode" );
       
   179     return iReorder;
       
   180     }
       
   181 
       
   182 // ---------------------------------------------------------------------------
       
   183 // Move current reorder index
       
   184 // ---------------------------------------------------------------------------
       
   185 //
       
   186 void CMPXCollectionViewContainer::MoveReorderIndex( TInt aDirection )
       
   187     {
       
   188     MPX_FUNC( "CMPXCollectionViewContainer::MoveReorderIndex" );
       
   189     if ( iLbxArray )
       
   190         {
       
   191         iLbxArray->MoveReorderIndex( aDirection );
       
   192         }
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // set current reorder index
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 void CMPXCollectionViewContainer::SetReorderIndex( TInt aIndex )
       
   200     {
       
   201     MPX_FUNC( "CMPXCollectionViewContainer::SetReorderIndex" );
       
   202     if ( iLbxArray )
       
   203         {
       
   204         iLbxArray->SetReorderIndex( aIndex );
       
   205         }
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // Confirm reorder
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CMPXCollectionViewContainer::ConfirmReorderL()
       
   213     {
       
   214     MPX_FUNC( "CMPXCollectionViewContainer::ConfirmReorderL" );
       
   215     if ( iLbxArray )
       
   216         {
       
   217         iLbxArray->ConfirmReorderL();
       
   218         }
       
   219     }
       
   220 
       
   221 // ---------------------------------------------------------------------------
       
   222 // Cancel reorder
       
   223 // ---------------------------------------------------------------------------
       
   224 //
       
   225 void CMPXCollectionViewContainer::CancelReorder()
       
   226     {
       
   227     MPX_FUNC( "CMPXCollectionViewContainer::CancelReorder" );
       
   228     TInt originalIndex( GetOriginalIndex() );
       
   229     if ( iLbxArray )
       
   230         {
       
   231         iLbxArray->CancelReorder();
       
   232         }
       
   233     iCommonContainer->SetLbxCurrentItemIndexAndDraw( originalIndex );
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // Gets original index of currently selected item
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 TInt CMPXCollectionViewContainer::GetOriginalIndex()
       
   241     {
       
   242     MPX_FUNC( "CMPXCollectionViewContainer::GetOriginalIndex" );
       
   243     TInt index( KErrNotFound );
       
   244     if ( iLbxArray )
       
   245         {
       
   246         index = iLbxArray->GetOriginalIndex();
       
   247         }
       
   248     return index;
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // Update Titlepane icon to reorder image
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 void CMPXCollectionViewContainer::UpdateReorderTitleIconL()
       
   256     {
       
   257     MPX_FUNC( "CMPXCollectionViewContainer::UpdateReorderTitleIconL" );
       
   258     // For status changes
       
   259     CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   260     TParse parse;
       
   261     parse.Set( KMPXCollectionViewIconFile, &KDC_APP_RESOURCE_DIR, NULL );
       
   262     TFileName iconFile( parse.FullName() );
       
   263     User::LeaveIfError( MPXUser::CompleteWithDllPath( iconFile ) );
       
   264 
       
   265     MAknsSkinInstance* skin( AknsUtils::SkinInstance() );
       
   266 
       
   267     CFbsBitmap* bitmap( NULL );
       
   268     CFbsBitmap* mask( NULL );
       
   269 
       
   270     AknsUtils::CreateIconLC(
       
   271         skin,
       
   272         KAknsIIDNone,
       
   273         bitmap,
       
   274         mask,
       
   275         iconFile,
       
   276         EMbmMpxcollectionviewQgn_graf_mup_ctx_reordersong,
       
   277         EMbmMpxcollectionviewQgn_graf_mup_ctx_reordersong_mask );
       
   278 
       
   279     CEikImage* newIcon = new ( ELeave ) CEikImage();
       
   280     CleanupStack::PushL( newIcon );
       
   281     newIcon->SetPicture( bitmap, mask );
       
   282     newIcon->SetPictureOwnedExternally( EFalse );
       
   283     iContextPane = static_cast<CAknContextPane*>
       
   284         ( sp->ControlL( TUid::Uid( EEikStatusPaneUidContext ) ) );
       
   285     iOrigIcon = iContextPane->SwapPicture( newIcon );
       
   286     CleanupStack::Pop( 3 ); // bitmap, mask, newIcon
       
   287     }
       
   288 
       
   289 // -----------------------------------------------------------------------------
       
   290 // Update Titlepane icon to use original image
       
   291 // -----------------------------------------------------------------------------
       
   292 //
       
   293 void CMPXCollectionViewContainer::RestoreOriginalTitleIconL()
       
   294     {
       
   295     MPX_FUNC( "CMPXCollectionViewContainer::RestoreOriginalTitleIconL" );
       
   296     if ( iOrigIcon )
       
   297         {
       
   298         CEikImage* newIcon = iContextPane->SwapPicture( iOrigIcon );
       
   299         delete newIcon;
       
   300         }
       
   301     }
       
   302 
       
   303 // -----------------------------------------------------------------------------
       
   304 // Creates listbox array
       
   305 // -----------------------------------------------------------------------------
       
   306 //
       
   307 CMPXCommonListBoxArrayBase* CMPXCollectionViewContainer::CreateListBoxArrayL()
       
   308     {
       
   309     MPX_FUNC( "CMPXCollectionViewContainer::CreateListBoxArrayL" );
       
   310     CMPXCollectionViewListBoxArray* array = CMPXCollectionViewListBoxArray::NewL();
       
   311     array->ConstructListBoxArrayL();
       
   312     array->SetObserver( this );
       
   313     return array;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // Returns common container
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 MMPXCommonContainer* CMPXCollectionViewContainer::Common()
       
   321     {
       
   322     ASSERT( iCommonContainer );
       
   323     return iCommonContainer;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // From MMPXViewContainer
       
   328 // Handles key events.
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 TKeyResponse CMPXCollectionViewContainer::HandleKeyEventL(
       
   332     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   333     {
       
   334     ASSERT( iCommonContainer );
       
   335     MPX_DEBUG4( "CMPXCollectionViewContainer::HandleKeyEventL(iCode=%d, iScanCode=%d, aType=%d)",
       
   336         aKeyEvent.iCode, aKeyEvent.iScanCode, aType );
       
   337 
       
   338     if ( aKeyEvent.iCode == EKeyUpArrow ||
       
   339         aKeyEvent.iCode == EKeyPrevious )
       
   340         {
       
   341         iView->ProcessCommandL( EMPXCmdUpArrow );
       
   342         }
       
   343     else if ( aKeyEvent.iCode == EKeyDownArrow ||
       
   344             aKeyEvent.iCode == EKeyNext )
       
   345         {
       
   346         iView->ProcessCommandL( EMPXCmdDownArrow );
       
   347         }
       
   348     TKeyResponse response = EKeyWasNotConsumed;
       
   349 
       
   350     if( iReady )
       
   351         {
       
   352         const CMPXMedia& containerMedia(
       
   353             iCommonContainer->ListBoxArray()->ContainerMedia() );
       
   354         TMPXGeneralType containerType(
       
   355             containerMedia.ValueTObjectL<TMPXGeneralType>(
       
   356                 KMPXMediaGeneralType ) );
       
   357         TMPXGeneralCategory containerCategory(
       
   358             containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
   359                 KMPXMediaGeneralCategory ) );
       
   360 
       
   361         // Hashkey mark/unmark works in all song's view and other tracks view,
       
   362         // not on other category views
       
   363         if( containerCategory == EMPXSong ||
       
   364             (( containerCategory == EMPXPlaylist ||
       
   365             containerCategory == EMPXAlbum  ||
       
   366             containerCategory == EMPXGenre ||
       
   367             containerCategory == EMPXComposer ) &&
       
   368             containerType == EMPXItem ) ||
       
   369             aKeyEvent.iScanCode != EStdKeyHash )
       
   370             {
       
   371             response = iCommonContainer->HandleKeyEventL( aKeyEvent, aType );
       
   372             }
       
   373         }
       
   374     else
       
   375         {
       
   376         response = iCommonContainer->HandleKeyEventL( aKeyEvent, aType );
       
   377         MPX_DEBUG2( "CMPXCollectionViewContainer::OfferKeyEventL commoncontainer offerkey res = %d", response);
       
   378         }
       
   379 
       
   380     if ( aKeyEvent.iCode == EKeyUpArrow ||
       
   381         aKeyEvent.iCode == EKeyPrevious )
       
   382         {
       
   383         iView->ProcessCommandL( EMPXCmdUpArrowAfterListboxHandled );
       
   384         }
       
   385     else if ( aKeyEvent.iCode == EKeyDownArrow ||
       
   386             aKeyEvent.iCode == EKeyNext )
       
   387         {
       
   388         iView->ProcessCommandL( EMPXCmdDownArrowAfterListboxHandled );
       
   389         }
       
   390     return response;
       
   391     }
       
   392 
       
   393 // ---------------------------------------------------------------------------
       
   394 // From MMPXViewContainer
       
   395 // Handle the retrieval of the view container's help context.
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 void CMPXCollectionViewContainer::HandleHelpContext(
       
   399     TCoeHelpContext& aContext ) const
       
   400     {
       
   401     ASSERT( iCommonContainer );
       
   402     MPX_FUNC( "CMPXCollectionViewContainer::HandleHelpContext" );
       
   403     aContext.iMajor = KAppUidMusicPlayerX;
       
   404 
       
   405     const CMPXMedia& containerMedia(
       
   406         iCommonContainer->ListBoxArray()->ContainerMedia() );
       
   407     TMPXGeneralType containerType(
       
   408         containerMedia.ValueTObjectL<TMPXGeneralType>(
       
   409             KMPXMediaGeneralType ) );
       
   410     TMPXGeneralCategory containerCategory(
       
   411         containerMedia.ValueTObjectL<TMPXGeneralCategory>(
       
   412             KMPXMediaGeneralCategory ) );
       
   413     MPX_DEBUG3( "CMPXCollectionViewContainer::HandleHelpContext containertype = %d, containercategory = %d", containerType, containerCategory );
       
   414 
       
   415     switch ( containerCategory )
       
   416         {
       
   417         case EMPXCollection:
       
   418             {
       
   419             // music menu view
       
   420             aContext.iContext = KMusHlpLibMainView;
       
   421             break;
       
   422             }
       
   423         case EMPXPlaylist:
       
   424             {
       
   425             if (iIsEmbedded)
       
   426                 {
       
   427                 aContext.iContext = KMusHlpEmbeddedPlaylistTracksView;
       
   428                 }
       
   429             else
       
   430                 {            	
       
   431                 if ( containerType == EMPXGroup )
       
   432                     {
       
   433                     // playlist view
       
   434                     aContext.iContext = KMusHlpPlaylistView;
       
   435                     }
       
   436                 else if ( containerType == EMPXItem )
       
   437                     {
       
   438                     // playlist tracks view
       
   439                     aContext.iContext = KMusHlpPlaylistTracksView;
       
   440                     }
       
   441                 else
       
   442                     {
       
   443                     // default to music main view help context
       
   444                     aContext.iContext = KMusHlpLibMainView;
       
   445                     }
       
   446                 }
       
   447             break;
       
   448             }
       
   449         case EMPXAlbum:
       
   450         case EMPXGenre:
       
   451         case EMPXComposer:
       
   452             {
       
   453             if ( containerType == EMPXGroup )
       
   454                 {
       
   455                 // album, genre, composer view
       
   456                 aContext.iContext = KMusHlpCategoryView;
       
   457                 }
       
   458             else if ( containerType == EMPXItem )
       
   459                 {
       
   460                 // album, genre, composer tracks view
       
   461                 aContext.iContext = KMusHlpTracksView;
       
   462                 }
       
   463             else
       
   464                 {
       
   465                 // default to music main view help context
       
   466                 aContext.iContext = KMusHlpLibMainView;
       
   467                 }
       
   468             break;
       
   469             }
       
   470         case EMPXArtist:
       
   471             {
       
   472             // artist view
       
   473             // artist/album view
       
   474             aContext.iContext = KMusHlpCategoryView;
       
   475             break;
       
   476             }
       
   477         case EMPXSong:
       
   478             {
       
   479             // all songs view
       
   480             aContext.iContext = KMusHlpTracksView;
       
   481             break;
       
   482             }
       
   483         default:
       
   484             {
       
   485             // default to music main view help context
       
   486             aContext.iContext = KMusHlpLibMainView;
       
   487             break;
       
   488             }
       
   489         }
       
   490     }
       
   491 
       
   492 // ---------------------------------------------------------------------------
       
   493 // From MMPXViewContainer
       
   494 // Returns the indicators for the specified item within the view container
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 RArray<TInt> CMPXCollectionViewContainer::IndicatorsL( TInt aIndex )
       
   498     {
       
   499     return iLbxArray->IndicatorIconIndicesL( aIndex );
       
   500     }
       
   501 
       
   502 // ---------------------------------------------------------------------------
       
   503 // From MMPXCommonListBoxArrayObserver
       
   504 // Handle listbox array events.
       
   505 // ---------------------------------------------------------------------------
       
   506 //
       
   507 void CMPXCollectionViewContainer::HandleListBoxArrayEventL(
       
   508     TMPXCommonListBoxArrayEvents aEvent )
       
   509     {
       
   510     MPX_FUNC( "CMPXCollectionViewContainer::HandleListBoxArrayEventL" );
       
   511     ASSERT( iCommonContainer );
       
   512     iCommonContainer->HandleListBoxArrayEventL( aEvent );
       
   513     }
       
   514 
       
   515 // ---------------------------------------------------------------------------
       
   516 // Content is ready.
       
   517 // ---------------------------------------------------------------------------
       
   518 //
       
   519 void CMPXCollectionViewContainer::ContentIsReady( TBool aReady )
       
   520     {
       
   521     iReady = aReady;
       
   522     }
       
   523 
       
   524 //  End of File