|
1 /* |
|
2 * Copyright (c) 2010 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: Implementation of psy settings engine private class. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "pospsysettingsengineprivate.h" |
|
20 #include "pospsysettingsengine.h" |
|
21 |
|
22 #include <qglobal.h> |
|
23 #include <EPos_CPosModules.h> |
|
24 #include <EPos_CPosModuleIdList.h> |
|
25 #include <EPos_CPosModuleUpdate.h> |
|
26 |
|
27 // constants |
|
28 const TInt KNameLength = 50; |
|
29 |
|
30 //--------------------------------------------------------------------- |
|
31 // PosPsySettingsEnginePrivate::PosPsySettingsEnginePrivate() |
|
32 // Constructor |
|
33 //--------------------------------------------------------------------- |
|
34 PosPsySettingsEnginePrivate::PosPsySettingsEnginePrivate( |
|
35 PositionTechnologyChangeObserver& posTechChangeObserver) : |
|
36 mPosTechChangeObserver(posTechChangeObserver) |
|
37 { |
|
38 |
|
39 // initialize the CPosModules pointer |
|
40 QT_TRAP_THROWING ( mPosModules = CPosModules::OpenL(); |
|
41 // Register for settings change. |
|
42 mPosModules->SetObserverL( *this )); |
|
43 } |
|
44 |
|
45 //--------------------------------------------------------------------- |
|
46 // PosPsySettingsEnginePrivate::~PosPsySettingsEnginePrivate() |
|
47 // Destructor |
|
48 //--------------------------------------------------------------------- |
|
49 PosPsySettingsEnginePrivate::~PosPsySettingsEnginePrivate() |
|
50 { |
|
51 // delete mPosModules |
|
52 if (mPosModules) |
|
53 { |
|
54 // remove the observer |
|
55 mPosModules->RemoveObserver(); |
|
56 delete mPosModules; |
|
57 mPosModules = NULL; |
|
58 } |
|
59 // delete the psyname |
|
60 TInt cnt = mNameList.count(); |
|
61 for(TInt i=0;i<cnt;++i) |
|
62 { |
|
63 delete mNameList[i]; |
|
64 mNameList[i] = NULL; |
|
65 } |
|
66 mNameList.clear(); |
|
67 |
|
68 // delete the list of psy info |
|
69 mPsyInfoList.Reset(); |
|
70 } |
|
71 |
|
72 //--------------------------------------------------------------------- |
|
73 // PosPsySettingsEnginePrivate::listPsys( QList<PosPsyInfo>& psyList ) |
|
74 // |
|
75 //--------------------------------------------------------------------- |
|
76 int PosPsySettingsEnginePrivate::listPsys(QList<PosPsyInfo>& psyList) |
|
77 { |
|
78 // Get the list of available psy |
|
79 TRAPD( error, listPsysL() ); |
|
80 |
|
81 if (error == KErrNone) |
|
82 { |
|
83 // copy the psy from RArray to the Qlist |
|
84 TInt cnt = mPsyInfoList.Count(); |
|
85 for (TInt i = 0; i < cnt; ++i) |
|
86 { |
|
87 psyList.append(mPsyInfoList[i]); |
|
88 } |
|
89 return KErrNone; |
|
90 } |
|
91 else |
|
92 { |
|
93 return error; |
|
94 } |
|
95 |
|
96 } |
|
97 |
|
98 //--------------------------------------------------------------------- |
|
99 // PosPsySettingsEnginePrivate::changePsyState( TUid psyModuleId, PosPsyState psyState ) |
|
100 // |
|
101 //--------------------------------------------------------------------- |
|
102 int PosPsySettingsEnginePrivate::changePsyState(TUid psyModuleId, |
|
103 PosPsyState psyState) |
|
104 { |
|
105 // update the psy state |
|
106 TRAPD( error, changePsyStateL( psyModuleId, psyState ) ); |
|
107 return error; |
|
108 } |
|
109 |
|
110 //--------------------------------------------------------------------- |
|
111 // PosPsySettingsEnginePrivate::listPsysL( ) |
|
112 // |
|
113 //--------------------------------------------------------------------- |
|
114 void PosPsySettingsEnginePrivate::listPsysL() |
|
115 { |
|
116 // reset the list of psyinfo |
|
117 mPsyInfoList.Reset(); |
|
118 |
|
119 // get the list of psy module ids |
|
120 CPosModuleIdList* idList = mPosModules->ModuleIdListLC(); |
|
121 // for each psy in the list,do the following : |
|
122 // - get module info |
|
123 // - check visibility of psy,if true then do the following : |
|
124 // -> store the uid,name, state of psy in the PosPsyInfo structure |
|
125 // -> append to the list of psys. |
|
126 TInt cnt = idList->Count(); |
|
127 for (TInt i = 0; i < cnt; ++i) |
|
128 { |
|
129 TPositionModuleInfo moduleInfo; |
|
130 mPosModules->GetModuleInfoL((*idList)[i], moduleInfo); |
|
131 |
|
132 // check visibility |
|
133 if (mPosModules->IsModuleVisibleL((*idList)[i])) |
|
134 { |
|
135 |
|
136 PosPsyInfo psyInfo; |
|
137 // Set the module Id. |
|
138 psyInfo.mPsyModuelId = moduleInfo.ModuleId(); |
|
139 |
|
140 // Set module name |
|
141 TBuf<KNameLength> moduleName; |
|
142 moduleInfo.GetModuleName(moduleName); |
|
143 // converting Tbuf to qstring |
|
144 QString* name = new QString((QChar*) moduleName.Ptr(), |
|
145 moduleName.Length()); |
|
146 mNameList.append( name ); |
|
147 psyInfo.mPsyName = *name; |
|
148 |
|
149 // Set the state of the psy |
|
150 if (moduleInfo.IsAvailable()) |
|
151 { |
|
152 psyInfo.mPsyState = PsyEnable; |
|
153 } |
|
154 else |
|
155 { |
|
156 psyInfo.mPsyState = PsyDisable; |
|
157 } |
|
158 |
|
159 // append the psyinfo to the list |
|
160 mPsyInfoList.AppendL(psyInfo); |
|
161 } |
|
162 } |
|
163 |
|
164 CleanupStack::PopAndDestroy(idList); |
|
165 } |
|
166 |
|
167 //--------------------------------------------------------------------- |
|
168 // PosPsySettingsEnginePrivate::changePsyStateL( TUid psyModuleId, PosPsyState psyState ) |
|
169 // |
|
170 //--------------------------------------------------------------------- |
|
171 void PosPsySettingsEnginePrivate::changePsyStateL(TUid psyModuleId, |
|
172 PosPsyState psyState) |
|
173 { |
|
174 // create an instance of CPosModuleUpdate to help in updating the attributes |
|
175 // of Psy |
|
176 CPosModuleUpdate* updateParams = CPosModuleUpdate::NewLC(); |
|
177 // Depending on the changed state update the availability of the psy |
|
178 // i.e enable/disable |
|
179 if (psyState == PsyEnable) |
|
180 { |
|
181 updateParams->SetUpdateAvailability(ETrue); |
|
182 } |
|
183 else |
|
184 { |
|
185 updateParams->SetUpdateAvailability(EFalse); |
|
186 } |
|
187 // update the state of the psy whose id is mentioned |
|
188 mPosModules->UpdateModuleL(psyModuleId, *updateParams); |
|
189 |
|
190 CleanupStack::PopAndDestroy(updateParams); |
|
191 |
|
192 } |
|
193 |
|
194 //--------------------------------------------------------------------- |
|
195 // PosPsySettingsEnginePrivate::changePsyStateL( TUid psyModuleId, PosPsyState psyState ) |
|
196 // |
|
197 //--------------------------------------------------------------------- |
|
198 void PosPsySettingsEnginePrivate::HandleSettingsChangeL( |
|
199 TPosModulesEvent aEvent) |
|
200 { |
|
201 // Check the event type,only for installation,removal, |
|
202 // change in visibility, |
|
203 // get the newly available list of psy |
|
204 if (aEvent.iType == EPosModulesEventModuleInstalled || |
|
205 aEvent.iType == EPosModulesEventModuleRemoved || |
|
206 aEvent.iType == EPosModulesEventVisibilityChanged) |
|
207 { |
|
208 listPsysL(); |
|
209 // call the engine's handlePositionTechnologyChange |
|
210 mPosTechChangeObserver.handlePositionTechnologyChange(); |
|
211 } |
|
212 } |
|
213 |