1 /* |
|
2 * Copyright (c) 2009 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: s_spsettings.cpp |
|
15 * |
|
16 */ |
|
17 #include <spsettings.h> |
|
18 #include <spentry.h> |
|
19 #include <spproperty.h> |
|
20 |
|
21 RArray< TServiceId > gServiceIds; |
|
22 RPointerArray< CSPEntry > gEntries; |
|
23 |
|
24 |
|
25 CSPSettings* myCSPSettings = NULL; |
|
26 |
|
27 |
|
28 extern TServicePropertyName gPropertyName; |
|
29 extern TInt gContactViewPluginId; |
|
30 extern HBufC* gPropertyContactStoreId; |
|
31 extern HBufC* gPropertyBrandId; |
|
32 extern TBool gPropertyInvalid; |
|
33 extern TInt gPropertyBrandLanguage; |
|
34 extern TInt gPropertyBrandVersion; |
|
35 extern TInt gPropertyXIMP; |
|
36 extern TOnOff gPropertyPresenceRequestPreference; |
|
37 extern TInt gContactViewId; |
|
38 |
|
39 CSPSettings* CSPSettings::NewL() |
|
40 { |
|
41 if (!myCSPSettings) |
|
42 { |
|
43 myCSPSettings = new ( ELeave ) CSPSettings; |
|
44 } |
|
45 return myCSPSettings; |
|
46 } |
|
47 |
|
48 CSPSettings* CSPSettings::NewLC() |
|
49 { |
|
50 CSPSettings* settings = CSPSettings::NewL(); |
|
51 CleanupStack::PushL( settings ); |
|
52 return settings; |
|
53 } |
|
54 |
|
55 CSPSettings::~CSPSettings() |
|
56 { |
|
57 gServiceIds.Close(); |
|
58 |
|
59 gEntries.ResetAndDestroy(); |
|
60 gEntries.Close(); |
|
61 delete gPropertyContactStoreId; |
|
62 delete gPropertyBrandId; |
|
63 |
|
64 |
|
65 myCSPSettings = NULL; |
|
66 gPropertyName = EPropertyUnknown; |
|
67 gContactViewPluginId = 0; |
|
68 gPropertyContactStoreId = 0; |
|
69 gPropertyBrandId = 0; |
|
70 gPropertyInvalid = EFalse; |
|
71 gPropertyBrandLanguage = 0; |
|
72 gPropertyBrandVersion = 0; |
|
73 gPropertyXIMP = 0; |
|
74 gPropertyPresenceRequestPreference = EOff; |
|
75 gContactViewId = 0; |
|
76 } |
|
77 |
|
78 void CopyEntry( const CSPEntry& aOriginal, CSPEntry& aTarget ) |
|
79 { |
|
80 aTarget.SetServiceId( aOriginal.GetServiceId() ); |
|
81 aTarget.SetServiceName( aOriginal.GetServiceName() ); |
|
82 RPropertyArray array = aOriginal.GetAllProperties(); |
|
83 for( TInt i = 0; i < array.Count(); i++ ) |
|
84 { |
|
85 TRAP_IGNORE( aTarget.AddPropertyL( *array[i] ) ); |
|
86 } |
|
87 } |
|
88 |
|
89 TInt CSPSettings::AddEntryL( CSPEntry& aEntry ) |
|
90 { |
|
91 TInt err = gServiceIds.Append( aEntry.GetServiceId() ); |
|
92 if( err ) |
|
93 { |
|
94 User::Leave( err ); |
|
95 } |
|
96 |
|
97 CSPEntry* entry = CSPEntry::NewLC(); |
|
98 CopyEntry( aEntry, *entry ); |
|
99 // If property counts difference from each other, |
|
100 // alloc failure has happened in CopyEntry |
|
101 if( aEntry.GetAllProperties().Count() != |
|
102 entry->GetAllProperties().Count() ) |
|
103 { |
|
104 User::Leave( KErrNoMemory ); |
|
105 } |
|
106 |
|
107 err = gEntries.Append( entry ); |
|
108 if( err ) |
|
109 { |
|
110 User::Leave( err ); |
|
111 } |
|
112 CleanupStack::Pop( entry ); |
|
113 return KErrNone; |
|
114 } |
|
115 |
|
116 TInt CSPSettings::FindEntryL( TServiceId aServiceId, CSPEntry& aEntry ) |
|
117 { |
|
118 for( TInt i=0; i<gServiceIds.Count(); i++ ) |
|
119 { |
|
120 if( gServiceIds[ i ] == aServiceId ) |
|
121 { |
|
122 CSPEntry* entry = gEntries[ i ]; |
|
123 |
|
124 CopyEntry( *entry, aEntry ); |
|
125 // If property counts difference from each other, |
|
126 // alloc failure has happened in CopyEntry |
|
127 if( aEntry.GetAllProperties().Count() != |
|
128 entry->GetAllProperties().Count() ) |
|
129 { |
|
130 User::Leave( KErrNoMemory ); |
|
131 } |
|
132 |
|
133 return KErrNone; |
|
134 } |
|
135 } |
|
136 |
|
137 return KErrNotFound; |
|
138 } |
|
139 |
|
140 |
|
141 TInt CSPSettings::UpdateEntryL( const CSPEntry& aEntry ) |
|
142 { |
|
143 for( TInt i=0; i<gServiceIds.Count(); i++ ) |
|
144 { |
|
145 if( gServiceIds[ i ] == aEntry.GetServiceId() ) |
|
146 { |
|
147 gEntries[i]->SetServiceName( aEntry.GetServiceName() ); |
|
148 RPropertyArray propOrig = gEntries[i]->GetAllProperties(); |
|
149 RPropertyArray propNew = aEntry.GetAllProperties(); |
|
150 TBool found = EFalse; |
|
151 for( TInt j = 0; j < propNew.Count(); j++ ) |
|
152 { |
|
153 for( TInt k = 0; k < propOrig.Count() && !found; k++ ) |
|
154 { |
|
155 if( propNew[j] == propOrig[k] ) |
|
156 { |
|
157 found = ETrue; |
|
158 } |
|
159 } |
|
160 if( !found ) |
|
161 { |
|
162 gEntries[i]->AddPropertyL( *propNew[j] ); |
|
163 } |
|
164 found = EFalse; |
|
165 } |
|
166 return KErrNone; |
|
167 } |
|
168 } |
|
169 |
|
170 return KErrNotFound; |
|
171 } |
|
172 |
|
173 TInt CSPSettings::FindPropertyL( TServiceId aServiceId, |
|
174 TServicePropertyName aPropertyName, |
|
175 CSPProperty& aProperty ) |
|
176 { |
|
177 for( TInt i=0; i<gServiceIds.Count(); i++ ) |
|
178 { |
|
179 if( gServiceIds[ i ] == aServiceId ) |
|
180 { |
|
181 CSPEntry* entry = gEntries[ i ]; |
|
182 |
|
183 const CSPProperty* property = NULL; |
|
184 |
|
185 TInt err = entry->GetProperty( property, |
|
186 aPropertyName ); |
|
187 |
|
188 if (KErrNone == err) |
|
189 { |
|
190 aProperty.CopyL(*property); |
|
191 return KErrNone; |
|
192 } |
|
193 } |
|
194 } |
|
195 |
|
196 return KErrNotFound; |
|
197 } |
|
198 |
|
199 |
|
200 TInt CSPSettings::FindServiceIdsL( RIdArray& aServiceIds ) |
|
201 { |
|
202 if( gServiceIds.Count() == 0 ) |
|
203 { |
|
204 return KErrNotFound; |
|
205 } |
|
206 |
|
207 for( TInt i=0; i<gServiceIds.Count(); i++ ) |
|
208 { |
|
209 TInt err = aServiceIds.Append( gServiceIds[ i ] ); |
|
210 if( err ) |
|
211 { |
|
212 User::Leave( err ); |
|
213 } |
|
214 } |
|
215 |
|
216 return KErrNone; |
|
217 } |
|
218 |
|
219 |
|
220 CSPSettings::CSPSettings() |
|
221 { |
|
222 } |
|
223 |
|
224 void CSPSettings::ConstructL() |
|
225 { |
|
226 } |
|
227 |
|
228 TInt CSPSettings::SettingsCountL() |
|
229 { |
|
230 return 0; |
|
231 } |
|
232 |
|
233 TInt CSPSettings::AddOrUpdatePropertyL( TServiceId /*aServiceId*/, |
|
234 const CSPProperty& /*aProperty*/ ) |
|
235 { |
|
236 return KErrNone; |
|
237 } |
|
238 |
|
239 |
|
240 |
|
241 |
|