1 /* |
|
2 * Copyright (c) 2002 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: Implementes settings extension API |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // System Include |
|
20 #include <lbs/epos_cposmodules.h> |
|
21 #include <lbs/epos_cposmoduleidlist.h> |
|
22 #include <lbs/epos_cposmoduleupdate.h> // CPosModuleUpdate |
|
23 #include <lbs/epos_mposmodulesobserver.h> |
|
24 |
|
25 // User Include |
|
26 #include "locpsysettings.h" |
|
27 #include "locpsyengdebug.h" |
|
28 #include "locpsyengobserver.h" |
|
29 #include "locpsyinfo.h" |
|
30 #include "locpsysettingsengconsts.h" |
|
31 #include "locpsyconfigclientimpl.h" |
|
32 #include "locpsyconfigclientwrapper.h" |
|
33 |
|
34 // ============================ MEMBER FUNCTIONS =============================== |
|
35 |
|
36 // Factory function |
|
37 CLocPsySettings* CLocPsySettings::NewL() |
|
38 { |
|
39 CLocPsySettings* self = new( ELeave ) CLocPsySettings(); |
|
40 CleanupStack::PushL( self ); |
|
41 self->ConstructL(); |
|
42 CleanupStack::Pop(self); |
|
43 return self; |
|
44 } |
|
45 |
|
46 // ----------------------------------------------------------------------------- |
|
47 // CLocPsySettings::CLocPsySettings |
|
48 // C++ default constructor can NOT contain any code, that |
|
49 // might leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 CLocPsySettings::CLocPsySettings() |
|
53 { |
|
54 } |
|
55 |
|
56 // ----------------------------------------------------------------------------- |
|
57 // CLocPsySettings::ConstructL |
|
58 // Symbian 2nd phase constructor can leave. |
|
59 // ----------------------------------------------------------------------------- |
|
60 // |
|
61 void CLocPsySettings::ConstructL() |
|
62 { |
|
63 iModuleDb = CPosModules::OpenL(); |
|
64 iPsyList = iModuleDb->ModuleIdListL(); |
|
65 iPsy = new (ELeave) CLocPsyInfo(); |
|
66 |
|
67 iModuleDb->SetObserverL( *this ); |
|
68 } |
|
69 |
|
70 // Destructor |
|
71 |
|
72 CLocPsySettings::~CLocPsySettings() |
|
73 { |
|
74 if ( iModuleDb ) |
|
75 { |
|
76 iModuleDb->RemoveObserver(); |
|
77 delete iModuleDb; |
|
78 } |
|
79 |
|
80 delete iPsyList; |
|
81 delete iPsy; |
|
82 delete iServClient; |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CLocPsySettings::GetPsyL |
|
87 // ----------------------------------------------------------------------------- |
|
88 // |
|
89 CLocPsyInfo* CLocPsySettings::GetPsyL( TInt aIndex ) |
|
90 { |
|
91 TPositionModuleInfo moduleInfo; |
|
92 // Sanity check of input parameter |
|
93 if ( aIndex < 0 || aIndex >= iPsyList->Count()) |
|
94 { |
|
95 // Invalid index values so Leave indicating bad argument |
|
96 User::Leave(KErrArgument); |
|
97 } |
|
98 TPositionModuleId moduleId = iPsyList->At( aIndex ); |
|
99 iModuleDb->GetModuleInfoL( moduleId, moduleInfo); |
|
100 iPsy->SetPsyId( moduleId ); |
|
101 TBuf<KLocPsyMaxLen>* buf=new (ELeave) TBuf<KLocPsyMaxLen>; |
|
102 moduleInfo.GetModuleName( *buf ); |
|
103 CleanupStack::PushL( buf ); |
|
104 iPsy->SetPsyNameL( *buf ); |
|
105 CleanupStack::PopAndDestroy(buf); |
|
106 return iPsy; |
|
107 } |
|
108 |
|
109 // ----------------------------------------------------------------------------- |
|
110 // CLocPsySettings::HandleSettingsChangeL |
|
111 // ----------------------------------------------------------------------------- |
|
112 // |
|
113 void CLocPsySettings::HandleSettingsChangeL(TPosModulesEvent aEvent) |
|
114 { |
|
115 LOCENGDEBUG("CLocPsySettings::HandleSettingsChangeL called"); |
|
116 CPosModuleIdList* temp = iModuleDb->ModuleIdListL(); |
|
117 delete iPsyList; |
|
118 |
|
119 iPsyList = temp; |
|
120 LOCENGDEBUG3("CLocPsySettings::HandleSettingsChangeL event=%d psy=%d no of PSYs=%d", |
|
121 aEvent.iType, aEvent.iModuleId, iPsyList->Count()); |
|
122 |
|
123 if( aEvent.iType == EPosModulesEventModuleRemoved && iServClient && |
|
124 aEvent.iModuleId == TUid::Uid(iServClient->PsyId()) ) |
|
125 { |
|
126 LOCENGDEBUG("Observer: PSY that is being configured is uninstalled"); |
|
127 iServClient->CloseServer(KErrAbort); |
|
128 } |
|
129 if(iObserver) |
|
130 { |
|
131 iObserver->NotifyL(); |
|
132 } |
|
133 } |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CLocPsySettings::EnablePsyL |
|
137 // ----------------------------------------------------------------------------- |
|
138 // |
|
139 void CLocPsySettings::EnablePsyL( TInt aIndex ) |
|
140 { |
|
141 CLocPsyInfo* psyInfo = GetPsyL(aIndex); |
|
142 CPosModuleUpdate* posModuleUpdate = CPosModuleUpdate::NewLC(); |
|
143 posModuleUpdate->SetUpdateAvailability( ETrue ); |
|
144 iModuleDb->UpdateModuleL( psyInfo->PsyId(), *posModuleUpdate ); |
|
145 LOCENGDEBUG2("CLocPsySettings::EnablePsyL: PSY %d index %d", |
|
146 psyInfo->PsyId(), aIndex); |
|
147 CleanupStack::PopAndDestroy(posModuleUpdate); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CLocPsySettings::DisablePsyL |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CLocPsySettings::DisablePsyL( TInt aIndex ) |
|
155 { |
|
156 CLocPsyInfo* psyInfo = GetPsyL(aIndex); |
|
157 CPosModuleUpdate* posModuleUpdate = CPosModuleUpdate::NewLC(); |
|
158 posModuleUpdate->SetUpdateAvailability( EFalse ); |
|
159 iModuleDb->UpdateModuleL( psyInfo->PsyId(), *posModuleUpdate ); |
|
160 LOCENGDEBUG2("CLocPsySettings::DisablePsyL: PSY %d index %d", |
|
161 psyInfo->PsyId(), aIndex); |
|
162 CleanupStack::PopAndDestroy(posModuleUpdate); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CLocPsySettings::ConfigurePsyL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CLocPsySettings::ConfigurePsyL(TInt aIndex, |
|
170 MAknServerAppExitObserver& aObserver) |
|
171 { |
|
172 CLocPsyConfigUiReg* reg = NULL; |
|
173 TRAPD(error, GetPsyL( aIndex ); |
|
174 reg = CLocPsyConfigUiServiceClientImpl::DiscoverLC( |
|
175 iPsy->PsyId().iUid); |
|
176 CleanupStack::Pop(reg);); |
|
177 // If GetModuleInfoL is not supported it returns KErrNotSupported |
|
178 // If DiscoverLC fails it returns KErrNotFound or KErrNoMemory |
|
179 if ( error == KErrNone && reg ) |
|
180 { |
|
181 CleanupStack::PushL( reg ); |
|
182 LOCENGDEBUG2("CLocPsySettings::ConfigurePsyL: PSY %d index %d", |
|
183 iPsy->PsyId(), aIndex); |
|
184 iServClient = static_cast<CLocPsyConfigUiServiceClientImpl*> |
|
185 (CLocPsyConfigUiServiceClientImpl::NewLC(*reg, aObserver)); |
|
186 CleanupStack::Pop(iServClient); |
|
187 iServClient->StartServerL(); |
|
188 CleanupStack::PopAndDestroy( reg ); |
|
189 } |
|
190 } |
|
191 |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CLocPsySettings::ClosePsyConfigurationApp |
|
194 // ----------------------------------------------------------------------------- |
|
195 // |
|
196 void CLocPsySettings::ClosePsyConfigurationApp() |
|
197 { |
|
198 delete iServClient; |
|
199 iServClient = NULL; |
|
200 } |
|
201 |
|
202 // ----------------------------------------------------------------------------- |
|
203 // CLocSettings::IsPsyEnabled |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 TBool CLocPsySettings::IsPsyEnabled( TInt aIndex ) |
|
207 { |
|
208 TPositionModuleInfo moduleInfo; |
|
209 // Sanity check of input parameter |
|
210 if (aIndex < 0 || aIndex >= iPsyList->Count() ) |
|
211 { |
|
212 // Invalid index values so just return False |
|
213 return EFalse; |
|
214 } |
|
215 TPositionModuleId moduleId = iPsyList->At( aIndex ); |
|
216 TRAPD(error, iModuleDb->GetModuleInfoL( moduleId, moduleInfo);); |
|
217 // If GetModuleInfoL returns KErrNotSupported we return EFalse |
|
218 if(error == KErrNone ) |
|
219 { |
|
220 return moduleInfo.IsAvailable(); |
|
221 } |
|
222 else |
|
223 { |
|
224 return EFalse; |
|
225 } |
|
226 } |
|
227 |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CLocSettings::IsPsyConfigurable |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TBool CLocPsySettings::IsPsyConfigurable( TInt aIndex ) |
|
234 { |
|
235 CLocPsyConfigUiReg* reg = NULL; |
|
236 TRAPD(error, GetPsyL( aIndex ); |
|
237 reg = CLocPsyConfigUiServiceClientImpl::DiscoverLC( |
|
238 iPsy->PsyId().iUid); |
|
239 CleanupStack::Pop(reg);); |
|
240 // If GetModuleInfoL is not supported it returns KErrNotSupported |
|
241 // If DiscoverLC fails it returns KErrNotFound or KErrNoMemory |
|
242 if (error == KErrNone && reg ) |
|
243 { |
|
244 delete reg; |
|
245 return ETrue; |
|
246 } |
|
247 else |
|
248 { |
|
249 return EFalse; |
|
250 } |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CLocSettings::SetObserver |
|
255 // ----------------------------------------------------------------------------- |
|
256 // |
|
257 void CLocPsySettings::SetObserver( MLocPsyEngObserver& aObserver ) |
|
258 { |
|
259 iObserver = &aObserver; |
|
260 } |
|
261 |
|
262 // ----------------------------------------------------------------------------- |
|
263 // CLocSettings::RemoveModelObserver |
|
264 // ----------------------------------------------------------------------------- |
|
265 // |
|
266 void CLocPsySettings::RemoveModelObserver() |
|
267 { |
|
268 iObserver = NULL; |
|
269 } |
|
270 |
|
271 // End of File |
|