ipsservices/ipssossettings/src/ipssetuictrlsoftkey.cpp
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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: This file implements class CIpsSetUiCtrlSoftkey.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "emailtrace.h"
       
    20 #include <StringLoader.h>           // StringLoader
       
    21 #include <eikbtgpc.h>           // CEikButtonGroupContainer
       
    22 
       
    23 #include "ipssetutilsexception.h"
       
    24 
       
    25 #include "ipssetuictrlsoftkey.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // ----------------------------------------------------------------------------
       
    30 // CIpsSetUiCtrlSoftkey::CIpsSetUiCtrlSoftkey()
       
    31 // ----------------------------------------------------------------------------
       
    32 //
       
    33 CIpsSetUiCtrlSoftkey::CIpsSetUiCtrlSoftkey(
       
    34      CEikButtonGroupContainer& aSoftkeys )
       
    35      :
       
    36      iSoftkeys( aSoftkeys ),
       
    37      iFlags( 0 )
       
    38     {
       
    39     FUNC_LOG;
       
    40     }
       
    41 
       
    42 // ----------------------------------------------------------------------------
       
    43 // CIpsSetUiCtrlSoftkey::~CIpsSetUiCtrlSoftkey()
       
    44 // ----------------------------------------------------------------------------
       
    45 //
       
    46 CIpsSetUiCtrlSoftkey::~CIpsSetUiCtrlSoftkey()
       
    47     {
       
    48     FUNC_LOG;
       
    49     }
       
    50 
       
    51 // ----------------------------------------------------------------------------
       
    52 // CIpsSetUiCtrlSoftkey::ConstructL()
       
    53 // ----------------------------------------------------------------------------
       
    54 //
       
    55 void CIpsSetUiCtrlSoftkey::ConstructL()
       
    56     {
       
    57     FUNC_LOG;
       
    58     }
       
    59 
       
    60 // ----------------------------------------------------------------------------
       
    61 // CIpsSetUiCtrlSoftkey::NewL()
       
    62 // ----------------------------------------------------------------------------
       
    63 //
       
    64 CIpsSetUiCtrlSoftkey* CIpsSetUiCtrlSoftkey::NewL(
       
    65      CEikButtonGroupContainer& aSoftkeys )
       
    66     {
       
    67     FUNC_LOG;
       
    68     CIpsSetUiCtrlSoftkey* self = NewLC( aSoftkeys );
       
    69     CleanupStack::Pop( self );
       
    70 
       
    71     return self;
       
    72     }
       
    73 
       
    74 // ----------------------------------------------------------------------------
       
    75 // CIpsSetUiCtrlSoftkey::NewLC()
       
    76 // ----------------------------------------------------------------------------
       
    77 //
       
    78 CIpsSetUiCtrlSoftkey* CIpsSetUiCtrlSoftkey::NewLC(
       
    79      CEikButtonGroupContainer& aSoftkeys )
       
    80     {
       
    81     FUNC_LOG;
       
    82     CIpsSetUiCtrlSoftkey* self = new ( ELeave ) CIpsSetUiCtrlSoftkey( aSoftkeys );
       
    83     CleanupStack::PushL( self );
       
    84     self->ConstructL();
       
    85 
       
    86     return self;
       
    87     }
       
    88    
       
    89 
       
    90 // ----------------------------------------------------------------------------
       
    91 // CIpsSetUiCtrlSoftkey::ChangeObserver()
       
    92 // ----------------------------------------------------------------------------
       
    93 //
       
    94 TInt CIpsSetUiCtrlSoftkey::ChangeObserver( 
       
    95     const TBool aOn,
       
    96     const TIpsSetUiObservedKeys aSoftkey,
       
    97     MEikCommandObserver& aCommandObserver )
       
    98     {
       
    99     FUNC_LOG;
       
   100     TInt error = KErrNone;
       
   101     
       
   102     if ( aOn )
       
   103         {
       
   104         error = SetObserver( aSoftkey, aCommandObserver );
       
   105         }
       
   106     else
       
   107         {
       
   108         RemoveObserver( aSoftkey );
       
   109         }
       
   110         
       
   111     return error;        
       
   112     }
       
   113 
       
   114 // ----------------------------------------------------------------------------
       
   115 // CIpsSetUiCtrlSoftkey::SetObserver()
       
   116 // ----------------------------------------------------------------------------
       
   117 //
       
   118 TInt CIpsSetUiCtrlSoftkey::SetObserver(
       
   119     const TIpsSetUiObservedKeys aSoftkey,
       
   120     MEikCommandObserver& aCommandObserver )
       
   121     {
       
   122     FUNC_LOG;
       
   123     TRAPD( error, 
       
   124         iSoftkeys.UpdateCommandObserverL( aSoftkey, aCommandObserver ) );
       
   125 
       
   126     iFlags |= aSoftkey;
       
   127     
       
   128     return error;
       
   129     }
       
   130         
       
   131 // ----------------------------------------------------------------------------
       
   132 // CIpsSetUiCtrlSoftkey::SetObserver()
       
   133 // ----------------------------------------------------------------------------
       
   134 //
       
   135 TInt CIpsSetUiCtrlSoftkey::SetObserver( 
       
   136     const TBool aLeftSoftkey,
       
   137     const TBool aRightSoftkey,
       
   138     const TBool aMiddleSoftkey,
       
   139     MEikCommandObserver& aCommandObserver )
       
   140     {
       
   141     FUNC_LOG;
       
   142     // Set observer for the left softkey
       
   143     TInt error = ChangeObserver( 
       
   144         aLeftSoftkey, ELeftSoftkey, aCommandObserver );    
       
   145     IPS_ASSERT_DEBUG( error == KErrNone, ESoftkeyLeft, ESoftkeys ); 
       
   146 
       
   147     // Set observer for the right softkey        
       
   148     if ( error == KErrNone )    
       
   149         {        
       
   150         error = ChangeObserver( 
       
   151             aRightSoftkey, ERightSoftkey, aCommandObserver );
       
   152             
       
   153         IPS_ASSERT_DEBUG( error == KErrNone, ESoftkeyRight, ESoftkeys ); 
       
   154         }
       
   155 
       
   156     // Set observer for the middle softkey
       
   157     if ( error == KErrNone )    
       
   158         {                
       
   159         error = ChangeObserver( 
       
   160             aMiddleSoftkey, EMiddleSoftkey, aCommandObserver );        
       
   161         IPS_ASSERT_DEBUG( error == KErrNone, ESoftkeyMiddle, ESoftkeys ); 
       
   162         }
       
   163 
       
   164     return error;
       
   165     }
       
   166 
       
   167 // ----------------------------------------------------------------------------
       
   168 // CIpsSetUiCtrlSoftkey::RemoveObserver()
       
   169 // ----------------------------------------------------------------------------
       
   170 //
       
   171 void CIpsSetUiCtrlSoftkey::RemoveObserver( 
       
   172     const TIpsSetUiObservedKeys aSoftkey )
       
   173     {
       
   174     FUNC_LOG;
       
   175     iSoftkeys.RemoveCommandObserver( aSoftkey );
       
   176 
       
   177     iFlags &= ~aSoftkey;
       
   178     }
       
   179     
       
   180 // ----------------------------------------------------------------------------
       
   181 // CIpsSetUiCtrlSoftkey::operator()()
       
   182 // ----------------------------------------------------------------------------
       
   183 //
       
   184 CEikButtonGroupContainer& CIpsSetUiCtrlSoftkey::operator()()
       
   185     {
       
   186     FUNC_LOG;
       
   187     return iSoftkeys;
       
   188     }
       
   189 
       
   190 // ----------------------------------------------------------------------------
       
   191 // CIpsSetUiCtrlSoftkey::DefineCustomSoftkeyL()
       
   192 // ----------------------------------------------------------------------------
       
   193 //
       
   194 void CIpsSetUiCtrlSoftkey::DefineCustomSoftkeyL(
       
   195     const TInt aLabelResource,
       
   196     const TIpsSetUiObservedKeys aSoftkeyPos,
       
   197     const TInt aSoftkeyCmd,
       
   198     MEikCommandObserver* aCommandObserver )
       
   199     {
       
   200     FUNC_LOG;
       
   201     HBufC* options = NULL; // <cmail>
       
   202     
       
   203     if( aLabelResource == KErrNotFound )
       
   204         {
       
   205         options = NULL;
       
   206         DefineCustomSoftkeyL(
       
   207             *options, aSoftkeyPos, aSoftkeyCmd, aCommandObserver );
       
   208         }
       
   209     else
       
   210         {
       
   211         // Define buttons 'Options' and 'Start'
       
   212         options = StringLoader::LoadL( aLabelResource );
       
   213         CleanupStack::PushL( options );
       
   214         DefineCustomSoftkeyL(
       
   215             *options, aSoftkeyPos, aSoftkeyCmd, aCommandObserver );
       
   216         CleanupStack::PopAndDestroy( options );
       
   217         options = NULL;
       
   218         }
       
   219     }
       
   220 
       
   221 
       
   222 // ----------------------------------------------------------------------------
       
   223 // CIpsSetUiCtrlSoftkey::DefineCustomSoftkeyL()
       
   224 // ----------------------------------------------------------------------------
       
   225 //
       
   226 void CIpsSetUiCtrlSoftkey::DefineCustomSoftkeyL(
       
   227     const TDesC& aSoftkeyLabel,
       
   228     const TIpsSetUiObservedKeys aSoftkeyPos,
       
   229     const TInt aSoftkeyCmd,
       
   230     MEikCommandObserver* aCommandObserver )
       
   231     {
       
   232     FUNC_LOG;
       
   233     // Make sure there is matching command for the position
       
   234     if ( iSoftkeys.PositionById( aSoftkeyCmd ) > KErrNotFound )
       
   235         {        
       
   236         // First, remove the observer for the key
       
   237         if ( iFlags & aSoftkeyPos )
       
   238             {
       
   239             RemoveObserver( aSoftkeyPos );
       
   240             }
       
   241                 
       
   242         // Remove the key information and then add new command            
       
   243         iSoftkeys.RemoveCommandFromStack( aSoftkeyPos, aSoftkeyCmd );
       
   244         iSoftkeys.AddCommandToStackL( aSoftkeyPos, aSoftkeyCmd, aSoftkeyLabel );
       
   245             
       
   246         if ( aCommandObserver )
       
   247             {
       
   248             // Set as observer and set the flags
       
   249             SetObserver( aSoftkeyPos, *aCommandObserver );
       
   250             }
       
   251         }
       
   252     }
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CIpsSetUiCtrlSoftkey::MSKLabelling()
       
   256 // ----------------------------------------------------------------------------
       
   257 //
       
   258 TBool CIpsSetUiCtrlSoftkey::MSKLabelling()
       
   259     {
       
   260     FUNC_LOG;
       
   261     return ( ( iFlags & EAllowMiddleSoftkeyLabelChange ) > 0 );
       
   262     }
       
   263 
       
   264 // ----------------------------------------------------------------------------
       
   265 // CIpsSetUiCtrlSoftkey::SetMSKLabelling()
       
   266 // ----------------------------------------------------------------------------
       
   267 //
       
   268 void CIpsSetUiCtrlSoftkey::SetMSKLabelling( const TBool aNewState )
       
   269     {
       
   270     FUNC_LOG;
       
   271     if ( aNewState )
       
   272         {
       
   273         iFlags |= EAllowMiddleSoftkeyLabelChange;
       
   274         }
       
   275     else 
       
   276         {
       
   277         iFlags &= EAllowMiddleSoftkeyLabelChange;
       
   278         }
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CIpsSetUiCtrlSoftkey::UpdateMiddleSoftkeyLabelL()
       
   283 // ----------------------------------------------------------------------------
       
   284 //
       
   285 void CIpsSetUiCtrlSoftkey::UpdateMiddleSoftkeyLabelL( 
       
   286     const TInt aLabelResource, 
       
   287     const TInt aCommandId,
       
   288     MEikCommandObserver* aCommandObserver )
       
   289     {
       
   290     FUNC_LOG;
       
   291     // If labelling allowed, change the label for the middle soft key
       
   292     if ( MSKLabelling() && iPreviousMskLabelResource != aLabelResource )
       
   293         {
       
   294         iPreviousMskLabelResource = aLabelResource;
       
   295         DefineCustomSoftkeyL(
       
   296             aLabelResource, 
       
   297             EMiddleSoftkey,
       
   298             aCommandId,
       
   299             aCommandObserver );
       
   300         }
       
   301     }
       
   302 
       
   303 // ---------------------------------------------------------------------------
       
   304 // CIpsSetUiCtrlSoftkey::SetAbsorb()
       
   305 // ---------------------------------------------------------------------------
       
   306 //
       
   307 void CIpsSetUiCtrlSoftkey::SetAbsorb( const TBool aAbsorb )
       
   308     {
       
   309     FUNC_LOG;
       
   310     // Absorbing keys, keep the order, so the flags are not messed up.
       
   311     if ( aAbsorb )
       
   312         {
       
   313         iFlags |= EAbsorbing;
       
   314         SetObserver( ETrue, ETrue, ETrue, *this );
       
   315         }
       
   316     else
       
   317         {
       
   318         SetObserver( EFalse, EFalse, EFalse, *this );
       
   319         iFlags &= ~EAbsorbing;
       
   320         }                    
       
   321     }
       
   322 
       
   323 // ---------------------------------------------------------------------------
       
   324 // From class MEikCommandObserver.
       
   325 // CIpsSetUiCtrlSoftkey::ProcessCommandL()
       
   326 // ---------------------------------------------------------------------------
       
   327 //
       
   328 void CIpsSetUiCtrlSoftkey::ProcessCommandL( TInt /* aCommandId */ )
       
   329     {
       
   330     FUNC_LOG;
       
   331     
       
   332     }
       
   333 
       
   334 // End of File
       
   335