photosgallery/viewframework/views/viewbase/src/glxmskcontroller.cpp
changeset 0 4e91876724a2
child 35 420f6808bf21
equal deleted inserted replaced
-1:000000000000 0:4e91876724a2
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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:    Media item list observer interface 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxmskcontroller.h"
       
    22 #include <glxtracer.h>                         // For Logs
       
    23 #include <mglxmedialist.h>
       
    24 #include <glxlistviewplugin.rsg>
       
    25 #include "glxcommandhandlers.hrh"
       
    26 #include <avkon.rsg>
       
    27 #include <glxviewbase.rsg>
       
    28 #include <StringLoader.h>
       
    29 
       
    30 
       
    31 //----------------------------------------------------------------------------------
       
    32 // NewL
       
    33 //----------------------------------------------------------------------------------
       
    34 //
       
    35 CGlxMSKController* CGlxMSKController::NewL()
       
    36     {
       
    37     TRACER("CGlxToolbarController::NewL");
       
    38     
       
    39     CGlxMSKController *self = new( ELeave ) CGlxMSKController ();
       
    40     return self;
       
    41     }
       
    42 
       
    43 //----------------------------------------------------------------------------------
       
    44 // Default Constructor
       
    45 //----------------------------------------------------------------------------------
       
    46 //
       
    47 CGlxMSKController::CGlxMSKController()
       
    48                     
       
    49     {
       
    50     TRACER("CGlxMSKController::CGlxMSKController");
       
    51     iUiUtility = CGlxUiUtility::UtilityL();
       
    52     }
       
    53     
       
    54 //----------------------------------------------------------------------------------
       
    55 // AddToObserver
       
    56 //----------------------------------------------------------------------------------
       
    57 //
       
    58 void CGlxMSKController::AddToObserverL (MGlxMediaList& aList, CEikButtonGroupContainer* aCba)
       
    59     {
       
    60     TRACER("CGlxMSKController::AddToObserverL");
       
    61 
       
    62     iCba = aCba;
       
    63     iAttributeAvailable = EFalse;
       
    64     aList.AddMediaListObserverL ( this );
       
    65     }
       
    66 
       
    67 //----------------------------------------------------------------------------------
       
    68 // RemoveFromObserver 
       
    69 //----------------------------------------------------------------------------------
       
    70 //
       
    71 void CGlxMSKController::RemoveFromObserver (MGlxMediaList& aList)
       
    72     {
       
    73     TRACER("CGlxMSKController::RemoveFromObserver");
       
    74 
       
    75     aList.RemoveMediaListObserver ( this );
       
    76     }
       
    77 
       
    78 //----------------------------------------------------------------------------
       
    79 // HandleItemAddedL
       
    80 //----------------------------------------------------------------------------
       
    81 //
       
    82 void CGlxMSKController::HandleItemAddedL(TInt /*aStartIndex*/, TInt /*aEndIndex*/, 
       
    83         MGlxMediaList* /*aList*/)
       
    84     {
       
    85     TRACER("CGlxMSKController::HandleItemAddedL");
       
    86     // no implementation
       
    87     }
       
    88 
       
    89 //----------------------------------------------------------------------------
       
    90 // HandleMediaL
       
    91 //----------------------------------------------------------------------------
       
    92 //
       
    93 void CGlxMSKController::HandleMediaL(TInt /*aListIndex*/, MGlxMediaList* /*aList*/)
       
    94     {
       
    95     TRACER("CGlxMSKController::HandleMediaL");
       
    96     // no implementation
       
    97     }
       
    98 
       
    99 //----------------------------------------------------------------------------
       
   100 // HandleItemRemovedL
       
   101 //----------------------------------------------------------------------------
       
   102 //
       
   103 void CGlxMSKController::HandleItemRemovedL(TInt /*aStartIndex*/, 
       
   104         TInt /*aEndIndex*/, MGlxMediaList* aList)
       
   105     {
       
   106     TRACER("CGlxMSKController::HandleItemRemovedL");
       
   107     
       
   108     if( aList->Count() <= 0 )
       
   109         {
       
   110         iCba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
       
   111         iCba->DrawNow();
       
   112         }
       
   113     }
       
   114 
       
   115 //----------------------------------------------------------------------------
       
   116 // HandleItemModifiedL
       
   117 //----------------------------------------------------------------------------
       
   118 //
       
   119 void CGlxMSKController::HandleItemModifiedL(const RArray<TInt>& /*aItemIndexes*/, 
       
   120         MGlxMediaList* /*aList*/)
       
   121     {
       
   122     TRACER("CGlxMSKController::HandleItemModifiedL");
       
   123     // no implementation
       
   124     }
       
   125 
       
   126 //----------------------------------------------------------------------------
       
   127 // HandleAttributesAvailableL
       
   128 //----------------------------------------------------------------------------
       
   129 //
       
   130 void CGlxMSKController::HandleAttributesAvailableL(TInt aItemIndex, 
       
   131         const RArray<TMPXAttribute>& /*aAttributes*/, 
       
   132         MGlxMediaList* aList)
       
   133     {
       
   134     TRACER("CGlxMSKController::HandleAttributesAvailableL");
       
   135      
       
   136     if( aItemIndex == aList->FocusIndex() )
       
   137         {        
       
   138         iAttributeAvailable = ETrue;
       
   139         SetStatusL(aList);
       
   140         }
       
   141     const TGlxMedia& mediaItem = aList->Item(aList->FocusIndex());      
       
   142 
       
   143     if( mediaItem.IsStatic() && aList->SelectionCount() <= 0 )
       
   144         {
       
   145         HBufC* openbuf =  StringLoader::LoadLC(R_GLX_MSK_OPEN);
       
   146         TPtr textopenptr = openbuf->Des();
       
   147                
       
   148         iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   149                 EAknCmdOpen, textopenptr );
       
   150         iCba->DrawNow();
       
   151         CleanupStack::PopAndDestroy(openbuf);
       
   152         }
       
   153     }
       
   154 
       
   155 //----------------------------------------------------------------------------
       
   156 // HandleFocusChangedL
       
   157 //----------------------------------------------------------------------------
       
   158 //
       
   159 void CGlxMSKController::HandleFocusChangedL(NGlxListDefs::TFocusChangeType /*aType*/, 
       
   160         TInt aNewIndex, TInt /*aOldIndex*/, 
       
   161         MGlxMediaList* aList)
       
   162     {  
       
   163     TRACER("CGlxMSKController::HandleFocusChangedL");
       
   164 
       
   165     // If new index is not equal to -1 (i.e., if there are items present), 
       
   166     // then check the media item
       
   167 
       
   168     if( (KErrNotFound != aNewIndex) && (aNewIndex == aList->FocusIndex()) )
       
   169         {
       
   170         SetStatusL(aList);
       
   171         }
       
   172     }
       
   173 
       
   174 //----------------------------------------------------------------------------
       
   175 // HandleItemSelectedL
       
   176 //----------------------------------------------------------------------------
       
   177 //
       
   178 void CGlxMSKController::HandleItemSelectedL(TInt /*aIndex*/, TBool aSelected, 
       
   179         MGlxMediaList* aList)
       
   180     {
       
   181     TRACER("CGlxMSKController::HandleItemSelectedL");
       
   182     
       
   183     if( !aSelected )
       
   184         {
       
   185         SetStatusL(aList);
       
   186         }
       
   187     }
       
   188 
       
   189 //----------------------------------------------------------------------------
       
   190 // HandleMessageL
       
   191 //----------------------------------------------------------------------------
       
   192 //
       
   193 void CGlxMSKController::HandleMessageL(const CMPXMessage& /*aMessage*/, 
       
   194         MGlxMediaList* /*aList*/)
       
   195     {
       
   196     TRACER("CGlxMSKController::HandleMessageL");
       
   197     // no implementation
       
   198     }
       
   199 
       
   200 //----------------------------------------------------------------------------
       
   201 // Destructor
       
   202 //----------------------------------------------------------------------------
       
   203 //
       
   204 CGlxMSKController::~CGlxMSKController()
       
   205     {
       
   206     TRACER("CGlxMSKController::~CGlxMSKController");
       
   207     if ( iUiUtility )
       
   208         {
       
   209         iUiUtility->Close();
       
   210         iUiUtility = NULL;
       
   211         }
       
   212     }
       
   213 
       
   214 //----------------------------------------------------------------------------
       
   215 // SetStatusOnViewActivationL
       
   216 //----------------------------------------------------------------------------
       
   217 //
       
   218 void CGlxMSKController::SetStatusOnViewActivationL( MGlxMediaList* aList )
       
   219     {
       
   220     TRACER("CGlxMSKController::SetStatusOnViewActivationL");
       
   221 
       
   222     // When going back from fullscreen to grid, when the attributes are already 
       
   223     // available in the cache, there is no HandleAttributeAvailable callback. Hence,
       
   224     // checking for medialist count.
       
   225     if( !iAttributeAvailable && (aList->Count(NGlxListDefs::ECountNonStatic) > 0))
       
   226         {
       
   227         SetStatusL(aList);
       
   228         }
       
   229     if( aList->Count() == 0 )
       
   230         {
       
   231         iCba->SetCommandSetL(R_AVKON_SOFTKEYS_OPTIONS_BACK);
       
   232         iCba->DrawNow();
       
   233         }
       
   234     }
       
   235 
       
   236 //----------------------------------------------------------------------------
       
   237 //SetStatusL
       
   238 //----------------------------------------------------------------------------
       
   239 //
       
   240 void CGlxMSKController::SetStatusL(MGlxMediaList* aList)
       
   241     {
       
   242     TRACER("CGlxMSKController::SetStatusL");
       
   243    
       
   244     if( !aList->SelectionCount() > 0 )
       
   245         {
       
   246         //Get the current media item from medialist
       
   247         const TGlxMedia& mediaItem = aList->Item(aList->FocusIndex());      
       
   248         TBool isSystemItem = EFalse;    
       
   249         mediaItem.GetSystemItem(isSystemItem);
       
   250 
       
   251         HBufC* openbuf =  StringLoader::LoadLC(R_GLX_MSK_OPEN);
       
   252         TPtr textopen = openbuf->Des();
       
   253 
       
   254         HBufC* playbuf =  StringLoader::LoadLC(R_GLX_MSK_PLAY);
       
   255         TPtr textplay = playbuf->Des();
       
   256         
       
   257         // Check whether media item is a system item, for example Favourites album 
       
   258         // or a static item
       
   259         if( isSystemItem || mediaItem.IsStatic() )
       
   260             {
       
   261             iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   262                     EAknCmdOpen, textopen );
       
   263             iCba->DrawNow();
       
   264             }
       
   265 
       
   266         else
       
   267             {
       
   268             switch (mediaItem.Category())
       
   269                 {
       
   270                 case EMPXImage:
       
   271                     {
       
   272                      if (!iUiUtility->IsExitingState())
       
   273 			            {
       
   274 			             // When Marking is done and Exit key is pressed, we do not need to set
       
   275 			             // MSK, as the application is exiting.
       
   276 		                iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   277 			                            EAknCmdOpen, textopen );
       
   278 			            iCba->DrawNow();
       
   279 			            }
       
   280                     break;
       
   281                     }
       
   282                 case EMPXVideo:
       
   283                     {
       
   284                      // When Marking is done and Exit key is pressed, we do not need to set
       
   285 			         // MSK, as the application is exiting.
       
   286                      if (!iUiUtility->IsExitingState())
       
   287 			            {
       
   288 					    iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   289 			                            EAknCmdOpen, textplay );
       
   290 			            iCba->DrawNow();
       
   291 			            }
       
   292 	                break;
       
   293                     }
       
   294                 case EMPXMonth:
       
   295                     {
       
   296                     iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   297                             EAknCmdOpen, textopen );
       
   298                     iCba->DrawNow();
       
   299                     break;
       
   300                     }
       
   301                 case EMPXAlbum:
       
   302                     {
       
   303                     iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   304                             EAknCmdOpen, textopen );
       
   305                     iCba->DrawNow();
       
   306                     break;
       
   307                     }
       
   308                 case EMPXTag:
       
   309                     {
       
   310                     iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   311                             EAknCmdOpen, textopen );
       
   312                     iCba->DrawNow();
       
   313                     break;
       
   314                     }
       
   315                 default:
       
   316                     {
       
   317                     iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   318                             EAknCmdOpen, textopen );
       
   319                     iCba->DrawNow();
       
   320                     break;
       
   321                     }                   
       
   322                 }
       
   323             }
       
   324         CleanupStack::PopAndDestroy(playbuf);
       
   325         CleanupStack::PopAndDestroy(openbuf);
       
   326         }
       
   327     }
       
   328 
       
   329 //----------------------------------------------------------------------------
       
   330 //SetMainStatusL
       
   331 //----------------------------------------------------------------------------
       
   332 //
       
   333 void CGlxMSKController::SetMainStatusL()
       
   334     {
       
   335     HBufC* openbuf =  StringLoader::LoadLC(R_GLX_MSK_OPEN);
       
   336     TPtr textopen = openbuf->Des();
       
   337         
       
   338     iCba->SetCommandL(CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   339             EAknCmdOpen, textopen );
       
   340     iCba->DrawNow();
       
   341     CleanupStack::PopAndDestroy(openbuf);
       
   342     }
       
   343