1 /* |
|
2 * Copyright (c) 2008 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: An observer for change in System of Measurement |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Include |
|
20 #include <centralrepository.h> |
|
21 |
|
22 // User Include |
|
23 #include "evtmgmtuisysofmeasurement.h" |
|
24 |
|
25 |
|
26 // ========================= MEMBER FUNCTIONS ================================ |
|
27 |
|
28 |
|
29 // --------------------------------------------------------------------------- |
|
30 // CEvtMgmtUiSysOfMeasurement::CEvtMgmtUiSysOfMeasurement |
|
31 // Overloaded Constructor |
|
32 // |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 CEvtMgmtUiSysOfMeasurement::CEvtMgmtUiSysOfMeasurement( |
|
36 MEvtMgmtUiSOMObserver& aAdapterObsrv ) |
|
37 :CActive(EPriorityStandard), |
|
38 iObserver(aAdapterObsrv) |
|
39 { |
|
40 } |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CEvtMgmtUiSysOfMeasurement::~CEvtMgmtUiSysOfMeasurement |
|
44 // Destructor |
|
45 // |
|
46 // --------------------------------------------------------------------------- |
|
47 // |
|
48 CEvtMgmtUiSysOfMeasurement::~CEvtMgmtUiSysOfMeasurement() |
|
49 { |
|
50 Cancel(); |
|
51 |
|
52 delete iRepository; |
|
53 } |
|
54 |
|
55 // --------------------------------------------------------------------------- |
|
56 // CEvtMgmtUiSysOfMeasurement* CEvtMgmtUiSysOfMeasurement::NewL |
|
57 // Creates new Systen of Measurement adapter |
|
58 // |
|
59 // @param aAdapterObsrv Observer to the Settings adapter |
|
60 // @return CEvtMgmtUiSysOfMeasurement& Reference to the application view |
|
61 // --------------------------------------------------------------------------- |
|
62 // |
|
63 CEvtMgmtUiSysOfMeasurement* CEvtMgmtUiSysOfMeasurement::NewL( |
|
64 MEvtMgmtUiSOMObserver& aAdapterObsrv ) |
|
65 { |
|
66 CEvtMgmtUiSysOfMeasurement* self = |
|
67 CEvtMgmtUiSysOfMeasurement::NewLC( aAdapterObsrv ); |
|
68 CleanupStack::Pop(self); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 // CEvtMgmtUiSysOfMeasurement* CEvtMgmtUiSysOfMeasurement::NewLC |
|
74 // Creates new Systen of Measurement adapter. Leaves the object on the clean-up |
|
75 // stack |
|
76 // |
|
77 // @param aAdapterObsrv Observer to the Settings adapter |
|
78 // @return CEvtMgmtUiSysOfMeasurement& Reference to the application view |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 CEvtMgmtUiSysOfMeasurement* CEvtMgmtUiSysOfMeasurement::NewLC( |
|
82 MEvtMgmtUiSOMObserver& aAdapterObsrv ) |
|
83 { |
|
84 CEvtMgmtUiSysOfMeasurement* self = |
|
85 new(ELeave) CEvtMgmtUiSysOfMeasurement( aAdapterObsrv ); |
|
86 CleanupStack::PushL(self); |
|
87 self->ConstructL(); |
|
88 return self; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // void CEvtMgmtUiSysOfMeasurement::ConstructL |
|
93 // Second Phase Constructor |
|
94 // |
|
95 // --------------------------------------------------------------------------- |
|
96 // |
|
97 void CEvtMgmtUiSysOfMeasurement::ConstructL() |
|
98 { |
|
99 CActiveScheduler::Add( this ); |
|
100 |
|
101 // Create the Central repository object for manipulating Avkon Central |
|
102 // repository for System of measurements settings |
|
103 iRepository = CRepository::NewL(TUid::Uid( KCRUidLocNotationPref )); |
|
104 |
|
105 StartNotification(); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // TLocSystemofMeasurementValues CEvtMgmtUiSysOfMeasurement::GetCurrentSysofMeasL |
|
110 // Returns the current value of the System of measurements settings |
|
111 // |
|
112 // @return TLocSystemofMeasurementValues Current value of the System of |
|
113 // measurements settings |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 TLocSystemofMeasurementValues CEvtMgmtUiSysOfMeasurement::GetCurrentSysofMeasL() |
|
117 { |
|
118 |
|
119 TInt settingsValue = 0; |
|
120 User::LeaveIfError( iRepository->Get( KLocSystemofMeasurements, |
|
121 settingsValue )); |
|
122 return ( static_cast<TLocSystemofMeasurementValues>( settingsValue )); |
|
123 } |
|
124 |
|
125 // -------------------------------------------------------------------------- |
|
126 // void CEvtMgmtUiSysOfMeasurement::RunL |
|
127 // Inherited from CActive |
|
128 // |
|
129 // --------------------------------------------------------------------------- |
|
130 // |
|
131 void CEvtMgmtUiSysOfMeasurement::RunL() |
|
132 { |
|
133 // Issue Notification |
|
134 iObserver.NotifySOMChangeL(); |
|
135 |
|
136 // Schedule for listening to change events again |
|
137 StartNotification(); |
|
138 } |
|
139 |
|
140 // -------------------------------------------------------------------------- |
|
141 // void CEvtMgmtUiSysOfMeasurement::DoCancel |
|
142 // Inherited from CActive |
|
143 // |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CEvtMgmtUiSysOfMeasurement::DoCancel() |
|
147 { |
|
148 // Cancel the outstanding CR notification request |
|
149 if( iRepository ) |
|
150 { |
|
151 iRepository->NotifyCancel( KLocSystemofMeasurements ); |
|
152 } |
|
153 } |
|
154 |
|
155 // -------------------------------------------------------------------------- |
|
156 // void CEvtMgmtUiSysOfMeasurement::StartNotification |
|
157 // Start notification from the Central repository server for any changes in the |
|
158 // System of measurements key value |
|
159 // |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CEvtMgmtUiSysOfMeasurement::StartNotification() |
|
163 { |
|
164 if( !IsActive()) |
|
165 { |
|
166 iStatus = KRequestPending; |
|
167 // Request for notification |
|
168 iRepository->NotifyRequest( KLocSystemofMeasurements, iStatus); |
|
169 SetActive(); |
|
170 } |
|
171 } |
|