locationsystemui/locationsysui/locnotprefplugin/src/locnotprefsomadapter.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 Systen of Measurement adapter
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // System Include
       
    20 #include <centralrepository.h>
       
    21 
       
    22 // User Include
       
    23 #include "locnotprefsomadapter.h"
       
    24 #include "locnotprefadapterobserver.h"
       
    25 
       
    26 
       
    27 // ========================= MEMBER FUNCTIONS ================================
       
    28 
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // CLocNotPrefSystemofMeasAdapter::CLocNotPrefSystemofMeasAdapter
       
    32 // Overloaded Constructor
       
    33 //
       
    34 // ---------------------------------------------------------------------------
       
    35 //  
       
    36 CLocNotPrefSystemofMeasAdapter::CLocNotPrefSystemofMeasAdapter(  
       
    37                                 MLocNotPrefAdapterObserver& aAdapterObsrv )
       
    38     :CActive(EPriorityStandard),
       
    39     iObserver(aAdapterObsrv)
       
    40     {
       
    41     }
       
    42 
       
    43 // ---------------------------------------------------------------------------
       
    44 // CLocNotPrefSystemofMeasAdapter::~CLocNotPrefSystemofMeasAdapter
       
    45 // Destructor
       
    46 //
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CLocNotPrefSystemofMeasAdapter::~CLocNotPrefSystemofMeasAdapter()
       
    50     {
       
    51     Cancel();
       
    52     
       
    53     delete iRepository; 
       
    54     }
       
    55     
       
    56 // ---------------------------------------------------------------------------
       
    57 // CLocNotPrefSystemofMeasAdapter* CLocNotPrefSystemofMeasAdapter::NewL
       
    58 // Creates new Systen of Measurement adapter
       
    59 //
       
    60 // @param  aAdapterObsrv                        Observer to the Settings adapter
       
    61 // @return CLocNotPrefSystemofMeasAdapter&  Reference to the application view
       
    62 // ---------------------------------------------------------------------------
       
    63 //    
       
    64 CLocNotPrefSystemofMeasAdapter* CLocNotPrefSystemofMeasAdapter::NewL( 
       
    65                             MLocNotPrefAdapterObserver& aAdapterObsrv )
       
    66     {   
       
    67     CLocNotPrefSystemofMeasAdapter* self = 
       
    68                         CLocNotPrefSystemofMeasAdapter::NewLC( aAdapterObsrv );
       
    69     CleanupStack::Pop(self);
       
    70     return self;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CLocNotPrefSystemofMeasAdapter* CLocNotPrefSystemofMeasAdapter::NewLC
       
    75 // Creates new Systen of Measurement adapter. Leaves the object on the clean-up
       
    76 // stack
       
    77 //
       
    78 // @param  aAdapterObsrv                        Observer to the Settings adapter
       
    79 // @return CLocNotPrefSystemofMeasAdapter&  Reference to the application view
       
    80 // ---------------------------------------------------------------------------
       
    81 // 
       
    82 CLocNotPrefSystemofMeasAdapter* CLocNotPrefSystemofMeasAdapter::NewLC( 
       
    83                             MLocNotPrefAdapterObserver& aAdapterObsrv )
       
    84     {   
       
    85     CLocNotPrefSystemofMeasAdapter* self = 
       
    86                         new(ELeave) CLocNotPrefSystemofMeasAdapter( aAdapterObsrv );
       
    87     CleanupStack::PushL(self);
       
    88     self->ConstructL();
       
    89     return self;
       
    90     }
       
    91     
       
    92 // ---------------------------------------------------------------------------
       
    93 // void CLocNotPrefSystemofMeasAdapter::ConstructL
       
    94 // Second Phase Constructor
       
    95 //
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CLocNotPrefSystemofMeasAdapter::ConstructL()
       
    99     {
       
   100     CActiveScheduler::Add( this );
       
   101     
       
   102     // Create the Central repository object for manipulating Avkon Central
       
   103     // repository for System of measurements settings
       
   104     iRepository = CRepository::NewL(TUid::Uid( KCRUidLocNotationPref ));
       
   105     
       
   106     StartNotification();    
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // TLocSystemofMeasurementValues CLocNotPrefSystemofMeasAdapter::GetCurrentSysofMeasL
       
   111 // Returns the current value of the System of measurements settings
       
   112 //
       
   113 // @return TLocSystemofMeasurementValues  Current value of the System of 
       
   114 //                                        measurements settings
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 TLocSystemofMeasurementValues CLocNotPrefSystemofMeasAdapter::GetCurrentSysofMeasL()
       
   118     {
       
   119     
       
   120     TInt settingsValue = 0;
       
   121     User::LeaveIfError( iRepository->Get( KLocSystemofMeasurements,
       
   122                                           settingsValue ));  
       
   123     return ( static_cast<TLocSystemofMeasurementValues>( settingsValue ));
       
   124     }
       
   125 
       
   126 // --------------------------------------------------------------------------
       
   127 // void CLocNotPrefSystemofMeasAdapter::SetCurrentSysofMeasL
       
   128 // Sets the value of the System of measurements settings
       
   129 //
       
   130 // @param aSettingsValue  New value of the System of measurements settings
       
   131 // ---------------------------------------------------------------------------
       
   132 //
       
   133 void CLocNotPrefSystemofMeasAdapter::SetCurrentSysofMeasL( 
       
   134                             TLocSystemofMeasurementValues aSettingsValue )
       
   135     {
       
   136     User::LeaveIfError( iRepository->Set( KLocSystemofMeasurements,
       
   137                                           aSettingsValue ));
       
   138     }
       
   139  
       
   140 // --------------------------------------------------------------------------
       
   141 // void CLocNotPrefSystemofMeasAdapter::ToggleSysofMeasSettingsL
       
   142 // Toggles the settings value
       
   143 // 
       
   144 // ---------------------------------------------------------------------------
       
   145 //
       
   146 void CLocNotPrefSystemofMeasAdapter::ToggleSysofMeasSettingsL()
       
   147     {
       
   148     TInt currentSettings = 0;
       
   149     TLocSystemofMeasurementValues newSettings = ELocMetric;
       
   150     
       
   151     // Obtain the current settings value and if its ELocMetric
       
   152     // then set ELocImperial else set ELocMetric
       
   153     User::LeaveIfError( iRepository->Get( KLocSystemofMeasurements,
       
   154                                           currentSettings ));
       
   155     
       
   156     if( ELocMetric == currentSettings )
       
   157         {
       
   158         newSettings = ELocImperial;
       
   159         }
       
   160     User::LeaveIfError( iRepository->Set( KLocSystemofMeasurements,
       
   161                                           newSettings ));
       
   162     }
       
   163             
       
   164 // --------------------------------------------------------------------------
       
   165 // void CLocNotPrefSystemofMeasAdapter::RunL
       
   166 // Inherited from CActive
       
   167 //
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 void CLocNotPrefSystemofMeasAdapter::RunL()
       
   171     {
       
   172     // Issue Notification
       
   173     iObserver.HandleSettingsChangeL();
       
   174     
       
   175     // Schedule for listening to change events again
       
   176     StartNotification();
       
   177     }
       
   178 
       
   179 // --------------------------------------------------------------------------
       
   180 // void CLocNotPrefSystemofMeasAdapter::DoCancel
       
   181 // Inherited from CActive
       
   182 //
       
   183 // ---------------------------------------------------------------------------
       
   184 //
       
   185 void CLocNotPrefSystemofMeasAdapter::DoCancel()
       
   186     {
       
   187     // Cancel the outstanding CR notification request
       
   188     if( iRepository )
       
   189         {
       
   190         iRepository->NotifyCancel( KLocSystemofMeasurements );        
       
   191         }
       
   192     }
       
   193     
       
   194 // --------------------------------------------------------------------------
       
   195 // void CLocNotPrefSystemofMeasAdapter::StartNotification
       
   196 // Start notification from the Central repository server for any changes in the
       
   197 // System of measurements key value
       
   198 //
       
   199 // ---------------------------------------------------------------------------
       
   200 //
       
   201 void CLocNotPrefSystemofMeasAdapter::StartNotification()
       
   202     {
       
   203     if( !IsActive())
       
   204         {
       
   205         iStatus = KRequestPending;
       
   206         // Request for notification
       
   207         iRepository->NotifyRequest( KLocSystemofMeasurements, iStatus);
       
   208         SetActive();          
       
   209         }  
       
   210     }