locationsystemui/locationsysui/locnotprefplugin/src/locnotprefpluginengine.cpp
branchRCL_3
changeset 44 2b4ea9893b66
parent 42 02ba3f1733c6
child 45 6b6920c56e2f
equal deleted inserted replaced
42:02ba3f1733c6 44:2b4ea9893b66
     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:  Location Notation Preferences Plugin Engine
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Include
       
    20 #include <e32keys.h>        // Tab Keys
       
    21 #include <StringLoader.h>   // String Loader
       
    22 #include <locnotprefpluginview.rsg>
       
    23 #include <aknradiobuttonsettingpage.h>
       
    24 
       
    25 // User Include
       
    26 #include "locnotprefpluginengine.h"
       
    27 #include "locnotprefengobserver.h"
       
    28 #include "locnotprefcorddisadapter.h"
       
    29 #include "locnotprefsomadapter.h"
       
    30 
       
    31 // Constant Defintions
       
    32 const TInt KNumberofSettingsItems = 2;
       
    33 const TInt KMaxConversionBufferLength = 0x200;
       
    34 const TInt KNoofSysofMeas = 2;
       
    35 const TInt KNoofCordDisplayFormats = 3;
       
    36 
       
    37 // ========================= MEMBER FUNCTIONS ================================
       
    38 
       
    39 
       
    40 // ---------------------------------------------------------------------------
       
    41 // CLocNotPrefPluginEngine::CLocNotPrefPluginEngine
       
    42 // Overloaded Constructor
       
    43 //
       
    44 // ---------------------------------------------------------------------------
       
    45 //  
       
    46 CLocNotPrefPluginEngine::CLocNotPrefPluginEngine(  
       
    47                                 MLocNotPrefEngObserver& aEngineObserver )
       
    48     :iObserver(aEngineObserver),
       
    49     iSettingsDialogOutstanding( EFalse )
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CLocNotPrefPluginEngine::~CLocNotPrefPluginEngine
       
    55 // Destructor
       
    56 //
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CLocNotPrefPluginEngine::~CLocNotPrefPluginEngine()
       
    60     {
       
    61     // Delete the list box strings
       
    62     delete iSysofMeasTitle;
       
    63     
       
    64     delete iCoordDispTitle;
       
    65     
       
    66     delete iImperialSettings;
       
    67     
       
    68     delete iMetricSettings;
       
    69     
       
    70     delete iDegreesSettings;
       
    71     
       
    72     delete iMinutesSettings;
       
    73     
       
    74     delete iSecondsSettings;
       
    75     
       
    76     delete iConversionBuffer;
       
    77         
       
    78     // Delete the Co-ordinate display settings handle
       
    79     delete iCordDisplaySettings;
       
    80 
       
    81     // Delete the System of Measurements settings handle    
       
    82     delete iSysofMeasSettings;
       
    83     }
       
    84     
       
    85 // ---------------------------------------------------------------------------
       
    86 // CLocNotPrefPluginEngine* CLocNotPrefPluginEngine::NewL
       
    87 // Creates new Location Notation Preferences plug-in engine instance.
       
    88 //
       
    89 // @param  aEngineObserver           Observer to the Notation preferences engine
       
    90 // @return CLocNotPrefPluginEngine* Reference to the application view
       
    91 // ---------------------------------------------------------------------------
       
    92 //    
       
    93 CLocNotPrefPluginEngine* CLocNotPrefPluginEngine::NewL( 
       
    94                             MLocNotPrefEngObserver& aEngineObserver )
       
    95     {   
       
    96     CLocNotPrefPluginEngine* self = 
       
    97                         CLocNotPrefPluginEngine::NewLC( aEngineObserver );
       
    98     CleanupStack::Pop(self);
       
    99     return self;
       
   100     }
       
   101 
       
   102 // ---------------------------------------------------------------------------
       
   103 // CLocNotPrefPluginEngine* CLocNotPrefPluginEngine::NewLC
       
   104 // Creates new Location Notation Preferences plug-in engine instance. Leaves
       
   105 // the object on the Cleanup stack
       
   106 //
       
   107 // @param  aEngineObserver           Observer to the Notation preferences engine
       
   108 // @return CLocNotPrefPluginEngine* Reference to the application view
       
   109 // ---------------------------------------------------------------------------
       
   110 // 
       
   111 CLocNotPrefPluginEngine* CLocNotPrefPluginEngine::NewLC( 
       
   112                             MLocNotPrefEngObserver& aEngineObserver )
       
   113     {   
       
   114     CLocNotPrefPluginEngine* self = 
       
   115                         new(ELeave) CLocNotPrefPluginEngine( aEngineObserver );
       
   116     CleanupStack::PushL(self);
       
   117     self->ConstructL();
       
   118     return self;
       
   119     }
       
   120     
       
   121 // ---------------------------------------------------------------------------
       
   122 // void CLocNotPrefPluginEngine::ConstructL
       
   123 // Second Phase Constructor
       
   124 //
       
   125 // ---------------------------------------------------------------------------
       
   126 //
       
   127 void CLocNotPrefPluginEngine::ConstructL()
       
   128     {
       
   129     // Create Co-ordinate display settings handle
       
   130     iCordDisplaySettings = CLocNotPrefCoordinateDisplayAdapter::NewL( *this );
       
   131     
       
   132     iSysofMeasSettings = CLocNotPrefSystemofMeasAdapter::NewL( *this );
       
   133     
       
   134     // Load the list box strings
       
   135     // Allocate and set the System of measurement heading
       
   136     iSysofMeasTitle = StringLoader::LoadL( R_LOC_NOTATION_MEASURES );
       
   137     
       
   138     // Allocate and set the server ip address title field
       
   139     iCoordDispTitle = StringLoader::LoadL( R_LOC_NOTATION_COORDINATE_FORMAT );
       
   140 
       
   141     // Allocate and set the Imperial settings text
       
   142     iImperialSettings = StringLoader::LoadL( R_LOC_IMPERIAL_SYSTEM );
       
   143     
       
   144     // Allocate and set the Metric settings text
       
   145     iMetricSettings = StringLoader::LoadL( R_LOC_METRIC_SYSTEM );
       
   146     
       
   147     // Allocate and set the Degrees resolution settings text
       
   148     iDegreesSettings = StringLoader::LoadL( R_LOC_FORMAT_DECIMAL_DEGREES );
       
   149     
       
   150     // Allocate and set the Minutes resolution settings text
       
   151     iMinutesSettings = StringLoader::LoadL( R_LOC_FORMAT_DECIMAL_MINUTES );
       
   152     
       
   153     // Allocate and set the Seconds resolution settings text
       
   154     iSecondsSettings = StringLoader::LoadL( R_LOC_FORMAT_DECIMAL_SECONDS );
       
   155     
       
   156     // Allocate the Conversion Buffer
       
   157     iConversionBuffer = HBufC16::NewL( KMaxConversionBufferLength );        
       
   158     }
       
   159     
       
   160 // ---------------------------------------------------------------------------
       
   161 // TInt CLocNotPrefPluginEngine::MdcaCount
       
   162 // Inherited from MDesCArray
       
   163 //
       
   164 // ---------------------------------------------------------------------------
       
   165 //
       
   166 TInt CLocNotPrefPluginEngine::MdcaCount() const
       
   167     {
       
   168     return KNumberofSettingsItems;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // TInt CLocNotPrefPluginEngine::MdcaPoint
       
   173 // Inherited from MDesCArray
       
   174 //
       
   175 // ---------------------------------------------------------------------------
       
   176 //
       
   177 TPtrC16 CLocNotPrefPluginEngine::MdcaPoint( TInt aIndex ) const
       
   178     {
       
   179     // Zero the internal buffer
       
   180     TPtr16 ptr( iConversionBuffer->Des());
       
   181     ptr.Zero();
       
   182     
       
   183     // Format "\t%S\t\t%S"
       
   184     
       
   185     // Append the first tab
       
   186     ptr.Append( EKeyTab );
       
   187             
       
   188     switch( aIndex )
       
   189         {
       
   190         case ESystemofMeasurement:
       
   191             {
       
   192             // Append the Title text
       
   193             ptr.Append( iSysofMeasTitle->Des());
       
   194             
       
   195             // Append the second tab
       
   196             ptr.Append( EKeyTab ); 
       
   197                             
       
   198             // Append the third tab
       
   199             ptr.Append( EKeyTab );
       
   200             
       
   201             // Obtain the current value of system of measurement and append
       
   202             // to the buffer
       
   203             TLocSystemofMeasurementValues currentSettings = ELocMetric;
       
   204             TRAPD( error, currentSettings = iSysofMeasSettings->GetCurrentSysofMeasL());
       
   205             if( KErrNone == error )
       
   206                 {
       
   207                 if( ELocMetric == currentSettings )
       
   208                     {
       
   209                     ptr.Append( iMetricSettings->Des());
       
   210                     }
       
   211                 else if ( ELocImperial == currentSettings )
       
   212                     {
       
   213                     ptr.Append( iImperialSettings->Des());
       
   214                     }
       
   215                 }
       
   216             
       
   217             break;    
       
   218             }
       
   219         case ECoordinateDisplayFormat:
       
   220             {
       
   221             // Append the Title text
       
   222             ptr.Append( iCoordDispTitle->Des());
       
   223             
       
   224             // Append the second tab
       
   225             ptr.Append( EKeyTab ); 
       
   226             
       
   227             // Append the third tab
       
   228             ptr.Append( EKeyTab );
       
   229             
       
   230             // Obtain the current value of co-ordinate display format and append
       
   231             // to the buffer
       
   232             CLocNotPrefCoordinateDisplayAdapter::TCordDisSetListPosition currentSettings = 
       
   233                     CLocNotPrefCoordinateDisplayAdapter::EPosDMSS;
       
   234             TRAPD( error, currentSettings = iCordDisplaySettings->GetCurrentDisplayFormatL());
       
   235             if( KErrNone == error )
       
   236                 {
       
   237                 if( CLocNotPrefCoordinateDisplayAdapter::EPosDD == currentSettings )
       
   238                     {
       
   239                     ptr.Append( iDegreesSettings->Des());
       
   240                     }
       
   241                 else if ( CLocNotPrefCoordinateDisplayAdapter::EPosDMM == currentSettings )
       
   242                     {
       
   243                     ptr.Append( iMinutesSettings->Des());
       
   244                     }
       
   245                 else if ( CLocNotPrefCoordinateDisplayAdapter::EPosDMSS == currentSettings )
       
   246                     {
       
   247                     ptr.Append( iSecondsSettings->Des());
       
   248                     }
       
   249                 }           
       
   250             break;    
       
   251             }
       
   252         default:
       
   253             {
       
   254             // Append the second tab
       
   255             ptr.Append( EKeyTab );          
       
   256             // Append the third tab
       
   257             ptr.Append( EKeyTab );
       
   258             break;    
       
   259             }
       
   260         }  
       
   261     return iConversionBuffer->Des();
       
   262     }
       
   263  
       
   264 // ---------------------------------------------------------------------------
       
   265 // void CLocNotPrefPluginEngine::HandleSettingsChangeL
       
   266 // Inherited from MLocNotPrefAdapterObserver
       
   267 //
       
   268 // ---------------------------------------------------------------------------
       
   269 //   
       
   270 void CLocNotPrefPluginEngine::HandleSettingsChangeL()
       
   271     {
       
   272     iObserver.HandleSettingsChangeEventL();
       
   273     }
       
   274  
       
   275 // ---------------------------------------------------------------------------
       
   276 // void CLocNotPrefPluginEngine::Close
       
   277 // Closes the running Settings UI prematurely. This would result in dismissing
       
   278 // any active dialogs currently running
       
   279 //
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 void CLocNotPrefPluginEngine::Close()
       
   283     {
       
   284     // If any of the dialogs are active then issue a cancel event on the 
       
   285     // dialogs
       
   286     if( iSettingsDialogOutstanding )
       
   287         {
       
   288         TKeyEvent   keyEvent;
       
   289         keyEvent.iCode          = EKeyCBA2;
       
   290         keyEvent.iScanCode      = EStdKeyDevice1;         
       
   291         keyEvent.iModifiers     = EAllModifiers;
       
   292         keyEvent.iRepeats       = 0;
       
   293         CCoeEnv* cCoeEnv = CCoeEnv::Static();
       
   294         
       
   295         // Simulate a Cancel event on the running dialogs. The Simulated event
       
   296         // is for the Left Soft Key.
       
   297         // Ignore the error incase of a leave
       
   298         
       
   299         TRAP_IGNORE( cCoeEnv->SimulateKeyEventL( keyEvent, EEventKey ));
       
   300         }
       
   301     iSettingsDialogOutstanding = EFalse;                
       
   302     }
       
   303             
       
   304 // ---------------------------------------------------------------------------
       
   305 // void CLocNotPrefPluginEngine::ChangeSysofMeasSettingsL
       
   306 // Change System of Measurement settings
       
   307 // 
       
   308 // ---------------------------------------------------------------------------
       
   309 // 
       
   310 void CLocNotPrefPluginEngine::ChangeSysofMeasSettingsL()
       
   311     {
       
   312     if( iSettingsDialogOutstanding )
       
   313         {
       
   314         User::Leave( KErrInUse );
       
   315         }
       
   316     // Allocate the descriptor array for Text settings for System
       
   317     // of measurement
       
   318     CDesCArrayFlat* items = new( ELeave ) CDesCArrayFlat( KNoofSysofMeas );
       
   319     CleanupStack::PushL( items );
       
   320 
       
   321     // Append the radio-button list items
       
   322     items->AppendL( iMetricSettings->Des());
       
   323     items->AppendL( iImperialSettings->Des());
       
   324      
       
   325     // Obtain the current value for current system of measurement
       
   326     // This would be used for setting the default value for 
       
   327     // the text settings page               
       
   328 
       
   329     // The settings value start from 1 whereas the list box items
       
   330     // start from 0. Hence, subtract 1 from the current settings
       
   331     // value
       
   332     TInt currentSettings = iSysofMeasSettings->GetCurrentSysofMeasL() - 1;
       
   333         
       
   334     CAknRadioButtonSettingPage* dlg = 
       
   335                         new ( ELeave )CAknRadioButtonSettingPage( R_LOC_SYSOFMEAS_SETTINGS,
       
   336                                                                   currentSettings, 
       
   337                                                                   items );
       
   338     // Settings Outstanding flag is marked True to enable dismissal incase
       
   339     // of a Cancel event                                                                  
       
   340     iSettingsDialogOutstanding = ETrue;                                                                  
       
   341     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenChanged ))
       
   342         {
       
   343         // The settings value start from 1 whereas the list box items
       
   344         // start from 0. Hence, add 1 from the current settings
       
   345         // value
       
   346         TLocSystemofMeasurementValues newValue = 
       
   347                     static_cast<TLocSystemofMeasurementValues>( currentSettings + 1 );
       
   348         iSysofMeasSettings->SetCurrentSysofMeasL( newValue );
       
   349         } 
       
   350     iSettingsDialogOutstanding = EFalse;           
       
   351     // Free the items resource
       
   352     CleanupStack::PopAndDestroy( items );
       
   353      
       
   354     }
       
   355 
       
   356 // ---------------------------------------------------------------------------
       
   357 // void CLocNotPrefPluginEngine::ToggleSysofMeasSettingsL
       
   358 // Toggle System of Measurement settings
       
   359 // 
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CLocNotPrefPluginEngine::ToggleSysofMeasSettingsL()
       
   363     {      
       
   364     if( iSettingsDialogOutstanding )
       
   365         {
       
   366         User::Leave( KErrInUse );
       
   367         }    
       
   368     iSysofMeasSettings->ToggleSysofMeasSettingsL();
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // void CLocNotPrefPluginEngine::ToggleSysofMeasSettingsL
       
   373 // Change Co-ordinate display format settings
       
   374 // 
       
   375 // ---------------------------------------------------------------------------
       
   376 //
       
   377 void CLocNotPrefPluginEngine::ChangeCoordinateDisplaySettingsL()
       
   378     {
       
   379     if( iSettingsDialogOutstanding )
       
   380         {
       
   381         User::Leave( KErrInUse );
       
   382         }
       
   383             
       
   384     // Allocate the descriptor array for Text settings for Co-ordinate display
       
   385     // formats
       
   386     CDesCArrayFlat* items = new( ELeave ) CDesCArrayFlat( KNoofCordDisplayFormats );
       
   387     CleanupStack::PushL( items );
       
   388 
       
   389     // Append the radio-button list items
       
   390     items->AppendL( iSecondsSettings->Des());    
       
   391     items->AppendL( iMinutesSettings->Des());
       
   392     items->AppendL( iDegreesSettings->Des());
       
   393      
       
   394     // Obtain the current value for current system of measurement
       
   395     // This would be used for setting the default value for 
       
   396     // the text settings page               
       
   397 
       
   398     TInt currentSettings = iCordDisplaySettings->GetCurrentDisplayFormatL();
       
   399         
       
   400     CAknRadioButtonSettingPage* dlg = 
       
   401                         new ( ELeave )CAknRadioButtonSettingPage( R_LOC_COORDDISPLAY_SETTINGS,
       
   402                                                                   currentSettings, 
       
   403                                                                   items );
       
   404                                                                            
       
   405     // Settings Outstanding flag is marked True to enable dismissal incase
       
   406     // of a Cancel event                                                                  
       
   407     iSettingsDialogOutstanding = ETrue;
       
   408 
       
   409     if ( dlg->ExecuteLD( CAknSettingPage::EUpdateWhenAccepted ))
       
   410         {
       
   411         // The settings value start from 1 whereas the list box items
       
   412         // start from 0. Hence, add 1 from the current settings
       
   413         // value
       
   414         CLocNotPrefCoordinateDisplayAdapter::
       
   415             TCordDisSetListPosition newValue = static_cast<
       
   416                 CLocNotPrefCoordinateDisplayAdapter::TCordDisSetListPosition>( 
       
   417                                                                     currentSettings );
       
   418                                                                     
       
   419         iCordDisplaySettings->SetCurrentDisplayFormatL( newValue );
       
   420         }
       
   421 
       
   422     iSettingsDialogOutstanding = EFalse;
       
   423               
       
   424     // Free the items resource
       
   425     CleanupStack::PopAndDestroy( items );    
       
   426     }