photosgallery/viewframework/commandhandlers/commoncommandhandlers/src/glxcommandhandlersortorder.cpp
changeset 0 4e91876724a2
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:    SortOrder command handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include "glxcommandhandlersortorder.h"
       
    22 
       
    23 #include <data_caging_path_literals.hrh>
       
    24 #include <glxcommandhandlers.hrh>
       
    25 #include <glxpanic.h>
       
    26 #include <glxtracer.h>
       
    27 #include <glxlog.h>
       
    28 #include <centralrepository.h>		// For CRepository
       
    29 #include <mglxmedialist.h>			// For MGlxMediaList
       
    30 #include <glxsettingsmodel.h>		// For cenrep setting 
       
    31 	
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // Two-phased constructor.
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CGlxCommandHandlerSortOrder* CGlxCommandHandlerSortOrder::NewL(
       
    38         					MGlxMediaListProvider* aMediaListProvider,
       
    39 							const TUint32 aCRKey)
       
    40     {
       
    41     CGlxCommandHandlerSortOrder* self = new ( ELeave )
       
    42     	CGlxCommandHandlerSortOrder(aMediaListProvider, aCRKey);
       
    43     CleanupStack::PushL( self );
       
    44     self->ConstructL();
       
    45     CleanupStack::Pop( self );
       
    46     return self;
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // C++ default constructor can NOT contain any code, that
       
    51 // might leave.
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CGlxCommandHandlerSortOrder::CGlxCommandHandlerSortOrder(
       
    55 							MGlxMediaListProvider* aMediaListProvider,
       
    56 							const TUint32 aCRKey)
       
    57     : CGlxMediaListCommandHandler(aMediaListProvider), iKey(aCRKey)
       
    58     {
       
    59     // Do nothing
       
    60     }
       
    61  
       
    62 // ---------------------------------------------------------------------------
       
    63 // Symbian 2nd phase constructor can leave.
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 void CGlxCommandHandlerSortOrder::ConstructL()
       
    67     {
       
    68     TRACER("CGlxCommandHandlerSortOrder::ConstructL");
       
    69     
       
    70     // Add supported commands
       
    71     GLX_LOG_INFO("CGlxCommandHandlerSortOrder::ConstructL::Add alphabetical sort order command handler");
       
    72    	TCommandInfo info( EGlxCmdSortByAlphabetical );
       
    73     info.iMinSelectionLength = 1;
       
    74     info.iMaxSelectionLength = KMaxTInt;
       
    75    	AddCommandL(info);
       
    76    	
       
    77    	GLX_LOG_INFO("CGlxCommandHandlerSortOrder::ConstructL::Add frequency sort order command handler");
       
    78    	TCommandInfo info2( EGlxCmdSortByCount );
       
    79     info2.iMinSelectionLength = 1;
       
    80     info2.iMaxSelectionLength = KMaxTInt;
       
    81    	AddCommandL(info2);
       
    82 	}
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // Destructor
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 EXPORT_C CGlxCommandHandlerSortOrder::~CGlxCommandHandlerSortOrder()
       
    89     {
       
    90     // Do nothing
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // DoExecute - the relevant action for the command id
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 TBool CGlxCommandHandlerSortOrder::DoExecuteL(TInt aCommandId,
       
    98 													MGlxMediaList& aList)
       
    99 	{
       
   100     TRACER("CGlxCommandHandlerSortOrder::DoExecuteL");
       
   101     
       
   102     __ASSERT_DEBUG( NULL != &aList, Panic(EGlxPanicIllegalArgument) );
       
   103 	
       
   104 	GLX_LOG_INFO1("CGlxCommandHandlerSortOrder::DoExecuteL::Command Id (%d)",aCommandId);
       
   105 	TGlxFilterSortOrder newSortOrder = EGlxFilterSortOrderNotUsed;
       
   106 	TGlxFilterSortDirection newSortDirection = EGlxFilterSortDirectionNotUsed;
       
   107     TBool handledCommand = EFalse;
       
   108 
       
   109 	switch (aCommandId)
       
   110 		{
       
   111         case EGlxCmdSortByAlphabetical:
       
   112             {
       
   113   			GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoExecuteL::Sort Alphabetically");
       
   114 
       
   115        		newSortOrder = EGlxFilterSortOrderAlphabetical;
       
   116        		newSortDirection = EGlxFilterSortDirectionAscending;
       
   117        		handledCommand = ETrue;
       
   118             break;
       
   119             }
       
   120         case EGlxCmdSortByCount:
       
   121             {
       
   122   			GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoExecuteL::Sort by count");
       
   123   			
       
   124        		newSortOrder = EGlxFilterSortOrderItemCount;
       
   125        		newSortDirection = EGlxFilterSortDirectionDescending;	        		
       
   126        		handledCommand = ETrue;
       
   127             break;
       
   128             }            
       
   129         default:
       
   130         	{
       
   131         	break;
       
   132         	}
       
   133 		}
       
   134 		
       
   135 	// Check if the existing and the new sort order are different, the change the filter in MediaList
       
   136 	if( newSortOrder != EGlxFilterSortOrderNotUsed )
       
   137 		{
       
   138 		GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoExecuteL::Create a new sort order");
       
   139 
       
   140 		TGlxFilterProperties filterProperties;
       
   141     	filterProperties.iSortOrder = newSortOrder;
       
   142     	filterProperties.iSortDirection = newSortDirection;
       
   143     	
       
   144     	CMPXFilter* newFilter = TGlxFilterFactory::CreateCombinedFilterL(filterProperties, 
       
   145     	                                                                    aList.Filter());
       
   146     	CleanupStack::PushL(newFilter);
       
   147 
       
   148     	aList.SetFilterL(newFilter);
       
   149     	// Update central repository with new sort order
       
   150     	CGlxSettingsModel::SetValueL(iKey,newSortOrder);
       
   151     	CleanupStack::PopAndDestroy(newFilter);
       
   152 		}
       
   153 	
       
   154 	return handledCommand;
       
   155 	}
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // DoIsDisabled
       
   159 // -----------------------------------------------------------------------------
       
   160 //	
       
   161 TBool CGlxCommandHandlerSortOrder::DoIsDisabled(TInt aCommandId, 
       
   162 													MGlxMediaList& aList) const
       
   163 	{
       
   164     TRACER("CGlxCommandHandlerSortOrder::DoIsDisabled");
       
   165 	
       
   166     __ASSERT_DEBUG( NULL != &aList, Panic(EGlxPanicIllegalArgument) );
       
   167     
       
   168 	// Get the existing filter & try to find out what is the current sort order
       
   169 	GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoIsDisabled::Get the existing filter");
       
   170     TGlxFilterSortOrder currentSortOrder = CurrentSortOrder(aList);		
       
   171 	
       
   172 	GLX_LOG_INFO1("CGlxCommandHandlerSortOrder::DoIsDisabled::Command Id (%d)",aCommandId);
       
   173 	TBool disabled = EFalse;
       
   174 	
       
   175 	TInt count(aList.Count());
       
   176     switch( aCommandId)
       
   177     	{
       
   178         case EGlxCmdSortByAlphabetical:
       
   179             {
       
   180             GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoIsDisabled::Sort Alphabetically");
       
   181             
       
   182             // If the filter is already Alphabetical sort then hide the menu
       
   183             if( count )
       
   184             	{
       
   185             	disabled = ( currentSortOrder == EGlxFilterSortOrderAlphabetical);
       
   186             	}
       
   187             else
       
   188             	{
       
   189             	disabled = ETrue; // Menu options should appear only if the list count is non-zero
       
   190             	}
       
   191         	
       
   192             break;
       
   193             }
       
   194         case EGlxCmdSortByCount:
       
   195             {
       
   196     		GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoIsDisabled::Sort by count");
       
   197     		
       
   198     		// If the filter is already Frequency sort then hide the menu
       
   199             if( count )
       
   200             	{
       
   201             	disabled = ( currentSortOrder == EGlxFilterSortOrderItemCount);
       
   202             	}
       
   203             else
       
   204             	{
       
   205             	disabled = ETrue; // Menu options should appear only if the list count is non-zero            	
       
   206             	}
       
   207             break;
       
   208             }            
       
   209         default:
       
   210         	{
       
   211         	break;
       
   212         	}
       
   213 		}
       
   214 	
       
   215 	return disabled;
       
   216 	}
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // GetSortOrder
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 TGlxFilterSortOrder	CGlxCommandHandlerSortOrder::CurrentSortOrder(MGlxMediaList& aList) const
       
   223     {
       
   224     TRACER("CGlxCommandHandlerSortOrder::CurrentSortOrder");
       
   225     
       
   226     __ASSERT_DEBUG( NULL != &aList, Panic(EGlxPanicIllegalArgument) );
       
   227     
       
   228     TGlxFilterSortOrder currentSortOrder = EGlxFilterSortOrderNotUsed;
       
   229 	
       
   230 	CMPXFilter* filter = aList.Filter();
       
   231 	if ( filter )
       
   232 		{
       
   233 		GLX_LOG_INFO("CGlxCommandHandlerSortOrder::DoIsDisabled::Find the existing sort order");
       
   234         currentSortOrder = filter->ValueTObjectL<TGlxFilterSortOrder>(KGlxFilterGeneralSortType);
       
   235 		}
       
   236 		
       
   237 	return currentSortOrder;
       
   238     }
       
   239 	
       
   240 //End of file