|
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: |
|
15 * Data handling encapsulation for CM Application Settings UI. |
|
16 * |
|
17 */ |
|
18 |
|
19 // System includes |
|
20 #include <HbStringUtil> |
|
21 |
|
22 // User includes |
|
23 #include "cmsettingdata.h" |
|
24 #include "OstTraceDefinitions.h" |
|
25 #ifdef OST_TRACE_COMPILER_IN_USE |
|
26 #include "cmsettingdataTraces.h" |
|
27 #endif |
|
28 |
|
29 |
|
30 /*! |
|
31 \class CmSettingData |
|
32 \brief Cm Manager settings data wrapper class for Application Settings UI. |
|
33 |
|
34 This class fetches, catches exceptions, filters and orders the |
|
35 destinations and connection methods needed by Application Settings UI. |
|
36 */ |
|
37 |
|
38 // External function prototypes |
|
39 |
|
40 // Local constants |
|
41 |
|
42 // ======== LOCAL FUNCTIONS ======== |
|
43 |
|
44 // ======== MEMBER FUNCTIONS ======== |
|
45 |
|
46 /*! |
|
47 Constructor. |
|
48 */ |
|
49 CmSettingData::CmSettingData() : |
|
50 mBearers(), |
|
51 mCmManager() |
|
52 { |
|
53 OstTraceFunctionEntry0(CMSETTINGDATA_CMSETTINGDATA_ENTRY); |
|
54 OstTraceFunctionExit0(CMSETTINGDATA_CMSETTINGDATA_EXIT); |
|
55 } |
|
56 |
|
57 /*! |
|
58 Destructor. |
|
59 */ |
|
60 CmSettingData::~CmSettingData() |
|
61 { |
|
62 OstTraceFunctionEntry0(DUP1_CMSETTINGDATA_CMSETTINGDATA_ENTRY); |
|
63 OstTraceFunctionExit0(DUP1_CMSETTINGDATA_CMSETTINGDATA_EXIT); |
|
64 } |
|
65 |
|
66 /*! |
|
67 Bearer filter setter function. |
|
68 |
|
69 @param[in] bearers Connection Method bearer filter. |
|
70 */ |
|
71 void CmSettingData::setBearerFilter(const QSet<uint> &bearers) |
|
72 { |
|
73 OstTraceFunctionEntry0(CMSETTINGDATA_SETBEARERFILTER_ENTRY); |
|
74 |
|
75 mBearers = bearers; |
|
76 |
|
77 OstTraceFunctionExit0(CMSETTINGDATA_SETBEARERFILTER_EXIT); |
|
78 } |
|
79 |
|
80 /*! |
|
81 Fetches destinations suitable for Application Selection UI Dialog. |
|
82 |
|
83 @param[out] destinations Destination list. |
|
84 |
|
85 @return Settings fetching status - true if reading succeeded. |
|
86 */ |
|
87 bool CmSettingData::fetchDestinations( |
|
88 QList< QSharedPointer<Destination> > &destinations) |
|
89 { |
|
90 OstTraceFunctionEntry0(CMSETTINGDATA_FETCHDESTINATIONS_ENTRY); |
|
91 |
|
92 bool success = false; |
|
93 |
|
94 // Clear the list just in case |
|
95 destinations.clear(); |
|
96 |
|
97 // Catch all CM Manager exceptions |
|
98 try { |
|
99 getCmManager(); |
|
100 |
|
101 // Fetch all destinations |
|
102 QList<uint> destArray; |
|
103 mCmManager->allDestinations(destArray); |
|
104 int count = destArray.count(); |
|
105 |
|
106 OstTrace1( |
|
107 TRACE_NORMAL, |
|
108 CMSETTINGDATA_FETCHDESTINATIONS_RETRIEVED, |
|
109 "CmSettingData::fetchDestinations retrieved;count=%d", |
|
110 count); |
|
111 |
|
112 // Go through all destinations |
|
113 for (int i=0; i < count; i++) { |
|
114 QSharedPointer<CmDestinationShim> destination; |
|
115 destination = QSharedPointer<CmDestinationShim>( |
|
116 mCmManager->destination(destArray[i])); |
|
117 // Append to list if destination is OK |
|
118 if (validateDestination(destination.data())) { |
|
119 QSharedPointer<Destination> dest(new Destination); |
|
120 dest->id = destination->id(); |
|
121 dest->name = destination->name(); |
|
122 destinations.append(dest); |
|
123 } |
|
124 } |
|
125 |
|
126 // Destinations fetched successfully |
|
127 success = true; |
|
128 } catch (const std::exception &ex) { |
|
129 int error = qt_symbian_exception2Error(ex); |
|
130 OstTrace1( |
|
131 TRACE_NORMAL, |
|
132 CMSETTINGDATA_FETCHDESTINATIONS_EXCEPTION, |
|
133 "CmSettingData::fetchDestinations exception;error=%d", |
|
134 error); |
|
135 } |
|
136 |
|
137 OstTraceFunctionExit0(CMSETTINGDATA_FETCHDESTINATIONS_EXIT); |
|
138 return success; |
|
139 } |
|
140 |
|
141 /*! |
|
142 Fetching of connection methods suitable for Application Selection UI Dialog. |
|
143 |
|
144 @param[out] connMethods Connection Method list. |
|
145 |
|
146 @return Settings fetching status - true if reading succeeded. |
|
147 */ |
|
148 bool CmSettingData::fetchConnMethods( |
|
149 QList< QSharedPointer<ConnMethod> > &connMethods) |
|
150 { |
|
151 OstTraceFunctionEntry0(CMSETTINGDATA_FETCHCONNMETHODS_ENTRY); |
|
152 |
|
153 bool success = false; |
|
154 |
|
155 // Clear the list just in case |
|
156 connMethods.clear(); |
|
157 |
|
158 // Catch all CM Manager exceptions |
|
159 try { |
|
160 getCmManager(); |
|
161 |
|
162 // Fetch all connection methods |
|
163 QList<uint> connMethodList; |
|
164 mCmManager->connectionMethod(connMethodList, false); |
|
165 int count = connMethodList.count(); |
|
166 |
|
167 OstTrace1( |
|
168 TRACE_NORMAL, |
|
169 CMSETTINGDATA_FETCHCONNMETHODS_RETRIEVED, |
|
170 "CmSettingData::fetchConnMethods retrieved;count=%d", |
|
171 count); |
|
172 |
|
173 // Go through all connection methods |
|
174 for (int i=0; i < count; i++) { |
|
175 QSharedPointer<CmConnectionMethodShim> connMethod; |
|
176 connMethod = QSharedPointer<CmConnectionMethodShim>( |
|
177 mCmManager->connectionMethod(connMethodList[i])); |
|
178 // Append to list if connection method is OK |
|
179 if (validateConnMethod(connMethod.data())) { |
|
180 QSharedPointer<ConnMethod> connectionMethod(new ConnMethod); |
|
181 connectionMethod->id = connMethod->getIntAttribute( |
|
182 CMManagerShim::CmId); |
|
183 connectionMethod->name = connMethod->getStringAttribute( |
|
184 CMManagerShim::CmName); |
|
185 connMethods.append(connectionMethod); |
|
186 } |
|
187 } |
|
188 |
|
189 // Destinations fetched successfully |
|
190 success = true; |
|
191 } catch (const std::exception &ex) { |
|
192 int error = qt_symbian_exception2Error(ex); |
|
193 OstTrace1( |
|
194 TRACE_NORMAL, |
|
195 CMSETTINGDATA_FETCHCONNMETHODS_EXCEPTION, |
|
196 "CmSettingData::fetchDestinations exception;error=%d", |
|
197 error); |
|
198 } |
|
199 |
|
200 // Order the list by connection method name |
|
201 qSort( |
|
202 connMethods.begin(), |
|
203 connMethods.end(), |
|
204 CmSettingData::connMethodLessThan); |
|
205 |
|
206 OstTraceFunctionExit0(CMSETTINGDATA_FETCHCONNMETHODS_EXIT); |
|
207 return success; |
|
208 } |
|
209 |
|
210 /*! |
|
211 Instantiates Cm Manager Shim for this setting data object. |
|
212 This is a member function since this can throw an exception and it |
|
213 needs to be catched. |
|
214 */ |
|
215 void CmSettingData::getCmManager() |
|
216 { |
|
217 if (!mCmManager) { |
|
218 mCmManager = QSharedPointer<CmManagerShim>(new CmManagerShim()); |
|
219 } |
|
220 } |
|
221 |
|
222 /*! |
|
223 Validates the given destination. |
|
224 This function checks that the following criterias match: |
|
225 -The destination is not empty (i.e. it has least one Connection Method). |
|
226 This covers also the bearer filter, so there must be at least one |
|
227 Connection Method after the bearer filtering. |
|
228 -The destination is not hidden. |
|
229 |
|
230 @param[in] destination Destination to validate. |
|
231 |
|
232 @return Validation result - true if valid. |
|
233 */ |
|
234 bool CmSettingData::validateDestination(CmDestinationShim *destination) const |
|
235 { |
|
236 OstTraceFunctionEntry0(CMSETTINGDATA_VALIDATEDESTINATION_ENTRY); |
|
237 |
|
238 bool valid = true; |
|
239 |
|
240 // Destination must not be hidden or empty |
|
241 if (destination->isHidden() || |
|
242 destination->connectionMethodCount() == 0) { |
|
243 valid = false; |
|
244 } else if (!mBearers.isEmpty()) { |
|
245 // If filter is empty, all bearers are supported |
|
246 |
|
247 // Check that there is at least one Connection Method that |
|
248 // matches after bearer filtering |
|
249 valid = false; |
|
250 for (int i=0; i < destination->connectionMethodCount(); i++) { |
|
251 QSharedPointer<CmConnectionMethodShim> connMethod; |
|
252 connMethod = QSharedPointer<CmConnectionMethodShim>( |
|
253 destination->connectionMethod(i)); |
|
254 int bearer = connMethod->getIntAttribute(CMManagerShim::CmBearerType); |
|
255 if (mBearers.contains(bearer)) { |
|
256 // Matching bearer found from this Connection Method |
|
257 valid = true; |
|
258 break; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 OstTraceExt2( |
|
264 TRACE_NORMAL, |
|
265 CMSETTINGDATA_VALIDATEDESTINATION_RESULT, |
|
266 "CmSettingData::validateDestination result;destination=%d;valid=%hhd", |
|
267 (TInt32)destination->id(), |
|
268 valid); |
|
269 |
|
270 OstTraceFunctionExit0(CMSETTINGDATA_VALIDATEDESTINATION_EXIT); |
|
271 return valid; |
|
272 } |
|
273 |
|
274 /*! |
|
275 Validates the given connection method. |
|
276 This function checks that the following criterias match: |
|
277 -The bearer type of the connection method matches the set filter. |
|
278 -The connection method is not hidden. |
|
279 |
|
280 @param[in] connMethod Connection method to validate. |
|
281 |
|
282 @return Validation result - true if valid. |
|
283 */ |
|
284 bool CmSettingData::validateConnMethod(CmConnectionMethodShim *connMethod) const |
|
285 { |
|
286 OstTraceFunctionEntry0(CMSETTINGDATA_VALIDATECONNMETHOD_ENTRY); |
|
287 |
|
288 bool valid = true; |
|
289 |
|
290 int bearer = connMethod->getIntAttribute(CMManagerShim::CmBearerType); |
|
291 bool hidden = connMethod->getBoolAttribute(CMManagerShim::CmHidden); |
|
292 if (hidden || (!mBearers.isEmpty() && !mBearers.contains(bearer))) { |
|
293 valid = false; |
|
294 } |
|
295 |
|
296 OstTraceExt4( |
|
297 TRACE_NORMAL, |
|
298 CMSETTINGDATA_VALIDATECONNMETHOD_RESULT, |
|
299 "CmSettingData::validateConnMethod result;id=%d;valid=%hhd;hidden=%hhd;bearer=%d", |
|
300 connMethod->getIntAttribute(CMManagerShim::CmId), |
|
301 valid, |
|
302 hidden, |
|
303 bearer); |
|
304 |
|
305 OstTraceFunctionEntry0(CMSETTINGDATA_VALIDATECONNMETHOD_EXIT); |
|
306 return valid; |
|
307 } |
|
308 |
|
309 /*! |
|
310 Compares two Connection Methods. |
|
311 |
|
312 @param[in] connMethod1 Connection method to compare with. |
|
313 @param[in] connMethod2 Connection method to compare. |
|
314 |
|
315 @return Returns true if the first connection method is "less than" |
|
316 the second one. |
|
317 */ |
|
318 bool CmSettingData::connMethodLessThan( |
|
319 const QSharedPointer<ConnMethod> connMethod1, |
|
320 const QSharedPointer<ConnMethod> connMethod2) |
|
321 { |
|
322 int result = HbStringUtil::compareC(connMethod1->name, connMethod2->name); |
|
323 return (result < 0) ? true : false; |
|
324 } |