photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandleraiwshowmap.cpp
changeset 0 4e91876724a2
child 3 9a9c174934f5
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:    Show on map command handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxcommandhandleraiwshowmap.h"
       
    22 
       
    23 #include <e32math.h>
       
    24 #include <glxattributecontext.h>
       
    25 #include <glxcommandhandlers.hrh>
       
    26 #include <glxmedia.h>
       
    27 #include <glxuiutilities.rsg>
       
    28 #include <glxmediageneraldefs.h>
       
    29 #include <glxtracer.h>
       
    30 #include <mglxmedialist.h>
       
    31 
       
    32 
       
    33 // For LocationFW
       
    34 #include <EPos_CPosLandmark.h>
       
    35 #include <epos_poslandmarkserialization.h>
       
    36 #include <lbsposition.h>
       
    37 
       
    38 #include "glxaiwservicehandler.h"
       
    39 
       
    40 const TInt KGlxAiwShowMapCommandSpace = 0x00000400;
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //	
       
    46 EXPORT_C CGlxCommandHandlerAiwShowMap* CGlxCommandHandlerAiwShowMap::NewL(
       
    47     MGlxMediaListProvider* aMediaListProvider, TInt aMenuResource )
       
    48     {
       
    49     TRACER("CGlxCommandHandlerAiwShowMap::NewL");
       
    50     CGlxCommandHandlerAiwShowMap* self = new ( ELeave ) 
       
    51         CGlxCommandHandlerAiwShowMap( aMediaListProvider, aMenuResource );
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL();
       
    54     CleanupStack::Pop( self );
       
    55     return self;
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 CGlxCommandHandlerAiwShowMap::~CGlxCommandHandlerAiwShowMap()
       
    63     {
       
    64     iBufferArray.ResetAndDestroy();
       
    65     }
       
    66     
       
    67 // -----------------------------------------------------------------------------
       
    68 // Constructor
       
    69 // -----------------------------------------------------------------------------
       
    70 //	
       
    71 CGlxCommandHandlerAiwShowMap::CGlxCommandHandlerAiwShowMap(
       
    72     MGlxMediaListProvider* aMediaListProvider, TInt aMenuResource )
       
    73         : CGlxCommandHandlerAiwBase( aMediaListProvider, aMenuResource )
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CGlxCommandHandlerAiwShowMap::DoGetRequiredAttributesL
       
    79 // -----------------------------------------------------------------------------
       
    80 //	
       
    81 void CGlxCommandHandlerAiwShowMap::DoGetRequiredAttributesL
       
    82                     (RArray<TMPXAttribute>& aAttributes, TBool aFilterUsingSelection) const
       
    83     {
       
    84 	if (!aFilterUsingSelection || SelectionLength() <= MaxSelectedItems())
       
    85 		{
       
    86 		aAttributes.AppendL(KGlxMediaGeneralLocation);
       
    87 		}
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // AiwDoDynInitMenuPaneL
       
    92 // -----------------------------------------------------------------------------
       
    93 //	
       
    94 void CGlxCommandHandlerAiwShowMap::AiwDoDynInitMenuPaneL(TInt /*aResourceId*/, 
       
    95         CEikMenuPane* aMenuPane)
       
    96     {
       
    97 	TInt num_items = aMenuPane->NumberOfItemsInPane();
       
    98 	
       
    99 	// Iterate through menu pane
       
   100 	TInt i = 0;
       
   101 	while (i < num_items)
       
   102 		{
       
   103 		CEikMenuPaneItem::SData& item = aMenuPane->ItemDataByIndexL(i);
       
   104         
       
   105         // "Show on map" cannot be dimmed as AIW resets the flags to not dimmed
       
   106         // Have to delete the menu item in this case.
       
   107         if (EGlxCmdAiwShowMap == item.iCommandId)
       
   108             {
       
   109             // Check visibility of the menu item
       
   110             TBool isDisabled = IsItemWithLocationInfoSelected(MediaList());
       
   111             
       
   112             // Should it be disabled
       
   113             if ((isDisabled) || (MediaList().SelectionCount() > 1))
       
   114                 {
       
   115                 // if so delete it. 
       
   116                 aMenuPane->DeleteMenuItem(EGlxCmdAiwShowMap);
       
   117                 }
       
   118             break;
       
   119             }
       
   120         ++i;
       
   121 		}
       
   122     }
       
   123     
       
   124 // -----------------------------------------------------------------------------
       
   125 // CommandId
       
   126 // -----------------------------------------------------------------------------
       
   127 //	
       
   128 TInt CGlxCommandHandlerAiwShowMap::CommandId() const
       
   129     {
       
   130     TRACER("CGlxCommandHandlerAiwShowMap::CommandId");
       
   131     return EGlxCmdAiwShowMap;
       
   132     }
       
   133     
       
   134 // -----------------------------------------------------------------------------
       
   135 // AiwCommandId
       
   136 // -----------------------------------------------------------------------------
       
   137 //	
       
   138 TInt CGlxCommandHandlerAiwShowMap::AiwCommandId() const
       
   139     {
       
   140     TRACER("CGlxCommandHandlerAiwShowMap::AiwCommandId");
       
   141     return KAiwCmdMnShowMap;
       
   142     }
       
   143     
       
   144 // -----------------------------------------------------------------------------
       
   145 // AiwInterestResource
       
   146 // -----------------------------------------------------------------------------
       
   147 //	
       
   148 TInt CGlxCommandHandlerAiwShowMap::AiwInterestResource() const
       
   149     {
       
   150     TRACER("CGlxCommandHandlerAiwShowMap::AiwInterestResource");
       
   151     return R_GLX_AIW_SHOWMAP_INTEREST;
       
   152     }
       
   153         
       
   154 // -----------------------------------------------------------------------------
       
   155 // AppendAiwParameterL
       
   156 // -----------------------------------------------------------------------------
       
   157 //	
       
   158 TBool CGlxCommandHandlerAiwShowMap::AppendAiwParameterL(const TGlxMedia& aItem, 
       
   159                                      CGlxAiwServiceHandler& aAiwServiceHandler)
       
   160     {
       
   161     TRACER("CGlxCommandHandlerAiwShowMap::AppendAiwParameterL");
       
   162     TBool success = EFalse;
       
   163     
       
   164     // Cleanup before execution
       
   165     iBufferArray.ResetAndDestroy();
       
   166     
       
   167     TCoordinate coordinate;
       
   168     if (aItem.GetCoordinate(coordinate))
       
   169         {
       
   170         // Create a landmark from the coordinate
       
   171         CPosLandmark* landmark = CPosLandmark::NewLC();
       
   172         TRealX noNumber;
       
   173         noNumber.SetNaN();   // Not a Number
       
   174 
       
   175         TLocality locality( coordinate, noNumber );
       
   176 
       
   177         // locality must have valid (ie not NaN) values
       
   178         landmark->SetPositionL( locality );
       
   179         
       
   180         // Serialize buffer to landmark and append it to AIW parameter
       
   181         const HBufC8* landmarkBuf = 
       
   182             PosLandmarkSerialization::PackL( *landmark );
       
   183         // we have ownership of landmarkBuf so add to array
       
   184         // for cleanup on our destruction
       
   185         iBufferArray.AppendL( landmarkBuf );
       
   186        
       
   187          // Append location parameter to the AIW param list
       
   188         TAiwVariant landmarkVariant( *landmarkBuf );        
       
   189         TAiwGenericParam landmarkParam( EGenericParamLandmark, landmarkVariant );
       
   190         aAiwServiceHandler.AddParamL(aItem.Id(), landmarkParam );
       
   191 
       
   192         success = ETrue;
       
   193         CleanupStack::PopAndDestroy( landmark );
       
   194         }
       
   195     
       
   196     return success;
       
   197     }
       
   198     
       
   199 // -----------------------------------------------------------------------------
       
   200 // CommandSpace
       
   201 // -----------------------------------------------------------------------------
       
   202 //	
       
   203 TInt CGlxCommandHandlerAiwShowMap::CommandSpace() const
       
   204     {
       
   205     TRACER("CGlxCommandHandlerAiwShowMap::CommandSpace");
       
   206     return KGlxAiwShowMapCommandSpace;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // DoIsDisabled
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 // 
       
   214 TBool CGlxCommandHandlerAiwShowMap::IsItemWithLocationInfoSelected(MGlxMediaList& aList )
       
   215     {
       
   216     TRACER("CGlxCommandHandlerAiwShowMap::DoIsDisabled");
       
   217     // Disable the "Show on map" menu item if the selection (marked list,
       
   218     // or focused item if none marked) does not contain any items 
       
   219     // that have location data
       
   220     TBool isSupported = EFalse;
       
   221     
       
   222     // Check through all, if any, selected items, otherwise the focused item
       
   223     TGlxSelectionIterator iterator;
       
   224     iterator.SetToFirst( &aList );
       
   225     
       
   226     // Loop until a supported item is found or until there are no
       
   227     // more indexes to process
       
   228     TInt index = KErrNotFound;
       
   229     while ( KErrNotFound != (index = iterator++ ) && !isSupported )
       
   230         {
       
   231         // get the media item
       
   232         const TGlxMedia& media = aList.Item( index );
       
   233         
       
   234         // Test to see if the coordinate is present
       
   235         TCoordinate coordinate;
       
   236         isSupported = media.GetCoordinate(coordinate);
       
   237         }
       
   238         
       
   239     // Don't disable the menu item if the property's supported
       
   240     return !isSupported;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // PreDynInitMenuPaneL
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void CGlxCommandHandlerAiwShowMap::PreDynInitMenuPaneL(TInt aResourceId)
       
   248 	{
       
   249 	CGlxCommandHandlerAiwBase::PreDynInitMenuPaneL(aResourceId);
       
   250 	}