|
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: Sensor Settings model. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "gssensorpluginmodel.h" |
|
21 #include "gssensorplugin.hrh" |
|
22 #include "gssensorplugin_debug.h" |
|
23 |
|
24 #include <sensorplugindomaincrkeys.h> |
|
25 |
|
26 // ========================= MEMBER FUNCTIONS ================================= |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CGSSensorPluginModel::NewL |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 CGSSensorPluginModel* CGSSensorPluginModel::NewL() |
|
33 { |
|
34 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::NewL()" ); |
|
35 CGSSensorPluginModel* self = new( ELeave ) CGSSensorPluginModel; |
|
36 CleanupStack::PushL( self ); |
|
37 self->ConstructL(); |
|
38 CleanupStack::Pop( self ); |
|
39 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::NewL() - return" ); |
|
40 return self; |
|
41 } |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // CGSSensorPluginModel::CGSSensorPluginModel |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CGSSensorPluginModel::CGSSensorPluginModel() |
|
48 { |
|
49 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::CGSSensorPluginModel()" ); |
|
50 iChangesMade = EFalse; |
|
51 } |
|
52 |
|
53 // ---------------------------------------------------------------------------- |
|
54 // CGSSensorPluginModel::ConstructL |
|
55 // ---------------------------------------------------------------------------- |
|
56 // |
|
57 void CGSSensorPluginModel::ConstructL() |
|
58 { |
|
59 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::ConstructL()" ); |
|
60 // Connect to Sensor Settings repository |
|
61 iSensorRepository = CRepository::NewL( KCRUidSensorSettings ); |
|
62 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::ConstructL() - return" ); |
|
63 } |
|
64 |
|
65 // ---------------------------------------------------------------------------- |
|
66 // CGSSensorPluginModel::~CGSSensorPluginModel |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CGSSensorPluginModel::~CGSSensorPluginModel() |
|
70 { |
|
71 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::~CGSSensorPluginModel()" ); |
|
72 if ( iSensorRepository ) |
|
73 { |
|
74 delete iSensorRepository; |
|
75 } |
|
76 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::~CGSSensorPluginModel() - return" ); |
|
77 } |
|
78 |
|
79 // ---------------------------------------------------------------------------- |
|
80 // CGSSensorPluginModel::SensorActiveStatusL |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CGSSensorPluginModel::SensorActiveStatusL() |
|
84 { |
|
85 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SensorActiveStatusL()" ); |
|
86 TInt mode( 0 ); |
|
87 // Get the sensors active status value from CenRep. |
|
88 User::LeaveIfError( iSensorRepository->Get( KSenSettingsSensorsOn, mode ) ); |
|
89 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::SensorActiveStatusL() - return: %i", mode ); |
|
90 return mode; |
|
91 } |
|
92 |
|
93 // ---------------------------------------------------------------------------- |
|
94 // CGSSensorPluginModel::SetSensorActiveStatusL |
|
95 // ---------------------------------------------------------------------------- |
|
96 // |
|
97 void CGSSensorPluginModel::SetSensorActiveStatusL( TInt aStatus ) |
|
98 { |
|
99 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::SetSensorActiveStatusL() - %i", aStatus ); |
|
100 // Update the sensors active status value to CenRep. |
|
101 User::LeaveIfError( iSensorRepository->Set( KSenSettingsSensorsOn, aStatus ) ); |
|
102 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SetSensorActiveStatusL() - return"); |
|
103 } |
|
104 |
|
105 // ---------------------------------------------------------------------------- |
|
106 // CGSSensorPluginModel::SelectionListL |
|
107 // ---------------------------------------------------------------------------- |
|
108 // |
|
109 TUint32 CGSSensorPluginModel::SelectionListL( TInt aInteraction ) |
|
110 { |
|
111 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::SelectionListL() - Interaction: %i", |
|
112 aInteraction ); |
|
113 |
|
114 TUint32 keyId( 0 ); // key to central repository |
|
115 TInt selections( 0 ); |
|
116 |
|
117 // Resolve interaction |
|
118 switch ( aInteraction ) |
|
119 { |
|
120 case EGSSenTapping: |
|
121 { |
|
122 keyId = KSenSettingsTapCtrl; |
|
123 break; |
|
124 } |
|
125 case EGSSenTurning: |
|
126 { |
|
127 keyId = KSenSettingsTurnCtrl; |
|
128 break; |
|
129 } |
|
130 case EGSSenOrientation: |
|
131 { |
|
132 keyId = KSenSettingsOrientation; |
|
133 break; |
|
134 } |
|
135 default: |
|
136 { |
|
137 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SelectionListL() - Unknown interaction" ); |
|
138 User::Leave( KErrUnknown ); |
|
139 } |
|
140 } |
|
141 |
|
142 // Get interactions selection list from CenRep |
|
143 User::LeaveIfError( iSensorRepository->Get( keyId, selections ) ); |
|
144 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::SelectionListL() - return: %b", selections ); |
|
145 return selections; |
|
146 } |
|
147 |
|
148 // ---------------------------------------------------------------------------- |
|
149 // CGSSensorPluginModel::SelectionListL |
|
150 // ---------------------------------------------------------------------------- |
|
151 // |
|
152 TUint32 CGSSensorPluginModel::VariationListL( const TInt aInteraction ) |
|
153 { |
|
154 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::VariationListL() - Interaction: %i", |
|
155 aInteraction ); |
|
156 |
|
157 TUint32 keyId( 0 ); // key to central repository |
|
158 TInt selections( 0 ); |
|
159 |
|
160 // Resolve interaction |
|
161 switch ( aInteraction ) |
|
162 { |
|
163 case EGSSenTapping: |
|
164 { |
|
165 keyId = KSenSetVariationTapCtrl; |
|
166 break; |
|
167 } |
|
168 case EGSSenTurning: |
|
169 { |
|
170 keyId = KSenSetVariationTurnCtrl; |
|
171 break; |
|
172 } |
|
173 case EGSSenOrientation: |
|
174 default: |
|
175 { |
|
176 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::VariationListL() - Unknown interaction" ); |
|
177 User::Leave( KErrUnknown ); |
|
178 } |
|
179 } |
|
180 |
|
181 // Get interactions variation list from CenRep |
|
182 User::LeaveIfError( iSensorRepository->Get( keyId, selections ) ); |
|
183 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::VariationListL() - return: %b", selections ); |
|
184 return selections; |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // CGSSensorPluginModel::SetSelectionListL |
|
189 // ---------------------------------------------------------------------------- |
|
190 // |
|
191 void CGSSensorPluginModel::SetSelectionListL( TInt aInteraction, TInt aList ) |
|
192 { |
|
193 TRACE_2( "[GSSensorPlugin] CGSSensorPluginModel::SetSelectionListL() - Interaction: %i Selections: %b", |
|
194 aInteraction, aList ); |
|
195 TUint32 keyId( 0 ); // key to central repository |
|
196 |
|
197 // Resolve interaction |
|
198 switch ( aInteraction ) |
|
199 { |
|
200 case EGSSenTapping: |
|
201 { |
|
202 keyId = KSenSettingsTapCtrl; |
|
203 break; |
|
204 } |
|
205 case EGSSenTurning: |
|
206 { |
|
207 keyId = KSenSettingsTurnCtrl; |
|
208 break; |
|
209 } |
|
210 case EGSSenOrientation: |
|
211 { |
|
212 keyId = KSenSettingsOrientation; |
|
213 break; |
|
214 } |
|
215 default: |
|
216 { |
|
217 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SetSelectionListL() - Unknown interaction" ); |
|
218 User::Leave( KErrUnknown ); |
|
219 } |
|
220 } |
|
221 |
|
222 // Set interactions selection list to CenRep |
|
223 User::LeaveIfError( iSensorRepository->Set( keyId, aList ) ); |
|
224 |
|
225 // Set flag on that changes has been made |
|
226 iChangesMade = ETrue; |
|
227 |
|
228 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SetSelectionListL() - return" ); |
|
229 } |
|
230 |
|
231 // ---------------------------------------------------------------------------- |
|
232 // CGSSensorPluginModel::ChangesMade |
|
233 // ---------------------------------------------------------------------------- |
|
234 // |
|
235 TBool CGSSensorPluginModel::ChangesMade() |
|
236 { |
|
237 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::ChangesMade() - return %i", iChangesMade ); |
|
238 TBool retVal( iChangesMade ); |
|
239 iChangesMade = EFalse; |
|
240 return retVal; |
|
241 } |
|
242 |
|
243 // ---------------------------------------------------------------------------- |
|
244 // CGSSensorPluginModel::SettingsExists |
|
245 // ---------------------------------------------------------------------------- |
|
246 // |
|
247 TBool CGSSensorPluginModel::SettingsExistsL() |
|
248 { |
|
249 TRACE_( "[GSSensorPlugin] CGSSensorPluginModel::SettingsExists()" ); |
|
250 TUint32 settingsMask = 0; |
|
251 // Get all settings and add them to one bitmask. If even one exists, this function returns ETrue |
|
252 settingsMask = SelectionListL( EGSSenTapping ); |
|
253 settingsMask = settingsMask | SelectionListL( EGSSenTurning ); |
|
254 settingsMask = settingsMask | SelectionListL( EGSSenOrientation ); |
|
255 |
|
256 TRACE_1( "[GSSensorPlugin] CGSSensorPluginModel::SettingsExists() - return: %i", settingsMask ); |
|
257 return settingsMask; |
|
258 } |