|
1 /* |
|
2 * Copyright (c) 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: Service Provider Settings entry. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "spentry.h" |
|
21 #include "spproperty.h" |
|
22 #include "spdefaultvalues.h" |
|
23 |
|
24 |
|
25 // ======== MEMBER FUNCTIONS ======== |
|
26 |
|
27 // --------------------------------------------------------------------------- |
|
28 // Constructor |
|
29 // --------------------------------------------------------------------------- |
|
30 // |
|
31 CSPEntry::CSPEntry() |
|
32 { |
|
33 } |
|
34 |
|
35 |
|
36 // --------------------------------------------------------------------------- |
|
37 // Constructor |
|
38 // --------------------------------------------------------------------------- |
|
39 // |
|
40 void CSPEntry::ConstructL() |
|
41 { |
|
42 } |
|
43 |
|
44 |
|
45 // --------------------------------------------------------------------------- |
|
46 // Constructor |
|
47 // --------------------------------------------------------------------------- |
|
48 // |
|
49 EXPORT_C CSPEntry* CSPEntry::NewL() |
|
50 { |
|
51 CSPEntry* self = CSPEntry::NewLC(); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Constructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 EXPORT_C CSPEntry* CSPEntry::NewLC() |
|
62 { |
|
63 CSPEntry* self = new( ELeave ) CSPEntry; |
|
64 CleanupStack::PushL( self ); |
|
65 self->ConstructL(); |
|
66 return self; |
|
67 } |
|
68 |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // Destructor |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 EXPORT_C CSPEntry::~CSPEntry() |
|
75 { |
|
76 iServiceName.Close(); |
|
77 iPropertyArray.ResetAndDestroy(); |
|
78 iPropertyArray.Close(); |
|
79 } |
|
80 |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // Returns service ID of this entry |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 EXPORT_C TServiceId CSPEntry::GetServiceId() const |
|
87 { |
|
88 return iServiceId; |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Set service ID for this entry |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 void CSPEntry::SetServiceId( TServiceId aServiceId ) |
|
97 { |
|
98 iServiceId = aServiceId; |
|
99 } |
|
100 |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // Returns service name of this entry |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 EXPORT_C const TDesC& CSPEntry::GetServiceName() const |
|
107 { |
|
108 return iServiceName; |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // Sets service name for this settings entry. |
|
114 // --------------------------------------------------------------------------- |
|
115 // |
|
116 EXPORT_C TInt CSPEntry::SetServiceName( const TDesC& aServiceName ) |
|
117 { |
|
118 TInt err( KErrNone ); |
|
119 TInt length( aServiceName.Length() ); |
|
120 |
|
121 if ( 0 >= length || KSPMaxDesLength < length ) |
|
122 { |
|
123 err = KErrArgument; |
|
124 } |
|
125 else |
|
126 { |
|
127 iServiceName.Close(); |
|
128 err = iServiceName.Create( aServiceName ); |
|
129 } |
|
130 |
|
131 return err; |
|
132 } |
|
133 |
|
134 |
|
135 // --------------------------------------------------------------------------- |
|
136 // Adds new property for this entry. Ownerhip transfers. |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 EXPORT_C TInt CSPEntry::AddPropertyL( const CSPProperty& aProperty ) |
|
140 { |
|
141 TInt err( 0 ); |
|
142 |
|
143 TInt index = SearchProperty( aProperty.GetName() ); |
|
144 |
|
145 if ( KErrNotFound == index ) |
|
146 { |
|
147 CSPProperty* property = CSPProperty::NewLC(); |
|
148 property->CopyL( aProperty ); |
|
149 User::LeaveIfError( iPropertyArray.Append( property )); |
|
150 CleanupStack::Pop( property ); |
|
151 } |
|
152 else |
|
153 { |
|
154 err = KErrAlreadyExists; |
|
155 } |
|
156 |
|
157 return err; |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // Update the property value |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 EXPORT_C TInt CSPEntry::UpdateProperty( TServicePropertyName aPropertyName, TInt aValue ) |
|
166 { |
|
167 TInt err( 0 ); |
|
168 |
|
169 TInt index = SearchProperty( aPropertyName ); |
|
170 |
|
171 if ( KErrNotFound < index ) |
|
172 { |
|
173 CSPProperty* update = iPropertyArray[index]; |
|
174 err = update->SetValue( aValue ); |
|
175 } |
|
176 else |
|
177 { |
|
178 err = KErrNotFound; |
|
179 } |
|
180 |
|
181 return err; |
|
182 } |
|
183 |
|
184 |
|
185 // --------------------------------------------------------------------------- |
|
186 // Update the property value |
|
187 // --------------------------------------------------------------------------- |
|
188 // |
|
189 EXPORT_C TInt CSPEntry::UpdateProperty( TServicePropertyName aPropertyName, const TDesC& aValue ) |
|
190 { |
|
191 TInt err( 0 ); |
|
192 |
|
193 TInt index = SearchProperty( aPropertyName ); |
|
194 |
|
195 if ( KErrNotFound < index ) |
|
196 { |
|
197 CSPProperty* update = iPropertyArray[index]; |
|
198 err = update->SetValue( aValue ); |
|
199 } |
|
200 else |
|
201 { |
|
202 err = KErrNotFound; |
|
203 } |
|
204 |
|
205 return err; |
|
206 } |
|
207 |
|
208 // --------------------------------------------------------------------------- |
|
209 // Update the property value |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 EXPORT_C TInt CSPEntry::UpdateProperty( TServicePropertyName aPropertyName, TOnOff aValue ) |
|
213 { |
|
214 TInt err( 0 ); |
|
215 |
|
216 TInt index = SearchProperty( aPropertyName ); |
|
217 |
|
218 if ( KErrNotFound < index ) |
|
219 { |
|
220 CSPProperty* update = iPropertyArray[index]; |
|
221 err = update->SetValue( aValue ); |
|
222 } |
|
223 else |
|
224 { |
|
225 err = KErrNotFound; |
|
226 } |
|
227 |
|
228 return err; |
|
229 } |
|
230 |
|
231 // --------------------------------------------------------------------------- |
|
232 // Returns property of this entry by name. |
|
233 // --------------------------------------------------------------------------- |
|
234 // |
|
235 EXPORT_C TInt CSPEntry::GetProperty( const CSPProperty*& aProperty, |
|
236 TServicePropertyName aPropertyName ) const |
|
237 { |
|
238 TInt index = SearchProperty( aPropertyName ); |
|
239 |
|
240 if ( KErrNotFound != index ) |
|
241 { |
|
242 aProperty = iPropertyArray[index]; |
|
243 return KErrNone; |
|
244 } |
|
245 else |
|
246 { |
|
247 return KErrNotFound; |
|
248 } |
|
249 } |
|
250 |
|
251 |
|
252 // --------------------------------------------------------------------------- |
|
253 // Returns property of this entry by index. |
|
254 // --------------------------------------------------------------------------- |
|
255 // |
|
256 EXPORT_C TInt CSPEntry::GetProperty( const CSPProperty*& aProperty, |
|
257 TInt aIndex ) const |
|
258 { |
|
259 if ( iPropertyArray.Count() > aIndex && 0 <= aIndex ) |
|
260 { |
|
261 aProperty = iPropertyArray[aIndex]; |
|
262 return KErrNone; |
|
263 } |
|
264 else |
|
265 { |
|
266 return KErrArgument; |
|
267 } |
|
268 } |
|
269 |
|
270 |
|
271 // --------------------------------------------------------------------------- |
|
272 // Deletes property from this entry by index. |
|
273 // --------------------------------------------------------------------------- |
|
274 // |
|
275 EXPORT_C TInt CSPEntry::DeleteProperty( TInt aIndex ) |
|
276 { |
|
277 if ( iPropertyArray.Count() > aIndex && 0 <= aIndex ) |
|
278 { |
|
279 delete iPropertyArray[aIndex]; |
|
280 iPropertyArray[aIndex] = NULL; |
|
281 iPropertyArray.Remove( aIndex ); |
|
282 return KErrNone; |
|
283 } |
|
284 else |
|
285 { |
|
286 return KErrArgument; |
|
287 } |
|
288 } |
|
289 |
|
290 |
|
291 // --------------------------------------------------------------------------- |
|
292 // Deletes property from this entry by name. |
|
293 // --------------------------------------------------------------------------- |
|
294 // |
|
295 EXPORT_C TInt CSPEntry::DeleteProperty( TServicePropertyName aProperty ) |
|
296 { |
|
297 TInt index = SearchProperty( aProperty ); |
|
298 |
|
299 return DeleteProperty( index ); |
|
300 } |
|
301 |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // Returns reference to proporty array |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 EXPORT_C const RPropertyArray& CSPEntry::GetAllProperties() const |
|
308 { |
|
309 return iPropertyArray; |
|
310 } |
|
311 |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // Returns count of properties in this entry |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 EXPORT_C TInt CSPEntry::PropertyCount() const |
|
318 { |
|
319 return iPropertyArray.Count(); |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // Search index of requested property in this entry |
|
325 // --------------------------------------------------------------------------- |
|
326 // |
|
327 TInt CSPEntry::SearchProperty( TServicePropertyName aProperty ) const |
|
328 { |
|
329 TInt count( iPropertyArray.Count() ); |
|
330 TInt index( KErrNotFound ); |
|
331 |
|
332 TBool found( EFalse ); |
|
333 for ( TInt i( 0 ); i < count && !found; i++ ) |
|
334 { |
|
335 if ( aProperty == iPropertyArray[i]->GetName() ) |
|
336 { |
|
337 index = i; |
|
338 found = ETrue; |
|
339 } |
|
340 } |
|
341 |
|
342 return index; |
|
343 } |
|
344 |
|
345 // --------------------------------------------------------------------------- |
|
346 // Reset the service entry, remove all properties |
|
347 // --------------------------------------------------------------------------- |
|
348 // |
|
349 EXPORT_C void CSPEntry::Reset() |
|
350 { |
|
351 iServiceId = KSPNoId; |
|
352 iServiceName.Close(); |
|
353 iPropertyArray.ResetAndDestroy(); |
|
354 } |
|
355 |