|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Methods for CNSmlDMSyncProfile |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <SyncMLTransportProperties.h> |
|
20 #include <centralrepository.h> |
|
21 #include <featmgr.h> |
|
22 |
|
23 #include "NSmlDMSyncPrivateCRKeys.h" |
|
24 |
|
25 #include "NSmlDMSyncProfileList.h" |
|
26 #include "NSmlDMSyncProfile.h" |
|
27 #include "NSmlDMSyncDebug.h" |
|
28 #include "NSmlDMSyncAppEngine.h" |
|
29 #include "NSmlDMSyncUtil.h" |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS ============================== |
|
32 // |
|
33 |
|
34 // ----------------------------------------------------------------------------- |
|
35 // CNSmlDMSyncProfileList::NewL |
|
36 // |
|
37 // Two-phased constructor. |
|
38 // ----------------------------------------------------------------------------- |
|
39 // |
|
40 CNSmlDMSyncProfileList* CNSmlDMSyncProfileList::NewL( |
|
41 CNSmlDMSyncAppEngine* aEngine ) |
|
42 { |
|
43 FLOG( "[OMADM] CNSmlDMSyncProfileList::NewL:"); |
|
44 |
|
45 CNSmlDMSyncProfileList* self = |
|
46 new(ELeave) CNSmlDMSyncProfileList( aEngine ); |
|
47 CleanupStack::PushL(self); |
|
48 self->ConstructL(); |
|
49 CleanupStack::Pop( self ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // Destructor. |
|
55 // ----------------------------------------------------------------------------- |
|
56 // |
|
57 CNSmlDMSyncProfileList::~CNSmlDMSyncProfileList() |
|
58 { |
|
59 FLOG( "[OMADM] CNSmlDMSyncProfileList::~CNSmlDMSyncProfileList():" ); |
|
60 |
|
61 iList.Close(); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CNSmlDMSyncProfileList::ConstructL |
|
66 // |
|
67 // Symbian 2nd phase constructor can leave. |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 void CNSmlDMSyncProfileList::ConstructL(void) |
|
71 { |
|
72 FLOG( "[OMADM] CNSmlDMSyncProfileList::ConstructL:" ); |
|
73 |
|
74 } |
|
75 |
|
76 // ----------------------------------------------------------------------------- |
|
77 // CNSmlDMSyncProfileList::CNSmlDMSyncProfileList. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CNSmlDMSyncProfileList::CNSmlDMSyncProfileList( CNSmlDMSyncAppEngine* aEngine ) |
|
81 { |
|
82 FLOG( "[OMADM] CNSmlDMSyncProfileList::CNSmlDMSyncProfileList:" ); |
|
83 |
|
84 iEngine = aEngine; |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CNSmlDMSyncProfileList::Count |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 TInt CNSmlDMSyncProfileList::Count() |
|
92 { |
|
93 return iList.Count(); |
|
94 } |
|
95 |
|
96 // ----------------------------------------------------------------------------- |
|
97 // CNSmlDMSyncProfileList::Item |
|
98 // ----------------------------------------------------------------------------- |
|
99 // |
|
100 TNSmlDMSyncProfileItem CNSmlDMSyncProfileList::Item(TInt aIndex) |
|
101 { |
|
102 if ( ( aIndex < 0 ) || ( aIndex >= Count() ) ) |
|
103 { |
|
104 TUtil::Panic(KErrGeneral); |
|
105 } |
|
106 |
|
107 return iList[aIndex]; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CNSmlDMSyncProfileList::FindProfile |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 TInt CNSmlDMSyncProfileList::FindProfile(const TDesC& aProfileName) |
|
115 { |
|
116 FLOG( "[OMADM] CNSmlDMSyncProfileList::FindProfile:" ); |
|
117 |
|
118 for ( TInt index = 0; index < Count(); index++ ) |
|
119 { |
|
120 TPtrC ptr = Item(index).Name(); |
|
121 if ( ptr.Compare( aProfileName ) == 0 ) |
|
122 { |
|
123 return index; |
|
124 } |
|
125 } |
|
126 return KErrNotFound; |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // ReplaceProfileItemL |
|
131 // ----------------------------------------------------------------------------- |
|
132 // |
|
133 void CNSmlDMSyncProfileList::ReplaceProfileItemL( |
|
134 TNSmlDMSyncProfileItem& aProfileItem ) |
|
135 { |
|
136 // remove old profile with same id |
|
137 Remove( aProfileItem.iProfileId ); |
|
138 // add new profile |
|
139 User::LeaveIfError( iList.Append(aProfileItem) ); |
|
140 Sort(); |
|
141 } |
|
142 |
|
143 // ----------------------------------------------------------------------------- |
|
144 // CNSmlDMSyncProfileList::ReadProfileItemL |
|
145 // ----------------------------------------------------------------------------- |
|
146 // |
|
147 void CNSmlDMSyncProfileList::ReadProfileItemL( TInt aIndex ) |
|
148 { |
|
149 FLOG("[OMADM] CNSmlDMSyncProfileList::ReadProfileItemL:" ); |
|
150 |
|
151 CNSmlDMSyncProfile* profile = iEngine->OpenProfileL( aIndex, ESmlOpenRead ); |
|
152 |
|
153 TNSmlDMSyncProfileItem item = ReadProfileItemL( profile ); |
|
154 item.iMandatoryCheck = CheckMandatoryDataL( profile ); |
|
155 ReplaceProfileItemL( item ); |
|
156 iEngine->CloseProfile(); |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CNSmlDMSyncProfileList::ReadProfileItemsL |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 void CNSmlDMSyncProfileList::ReadProfileItemsL() |
|
164 { |
|
165 ReadProfileItemsL( EFalse ); |
|
166 } |
|
167 |
|
168 // ----------------------------------------------------------------------------- |
|
169 // CNSmlDMSyncProfileList::ReadProfileItemsL |
|
170 // ----------------------------------------------------------------------------- |
|
171 // |
|
172 void CNSmlDMSyncProfileList::ReadProfileItemsL( TBool aIncludeHidden ) |
|
173 { |
|
174 FLOG( "[OMADM] CNSmlDMSyncProfileList::ReadProfileItemsL:" ); |
|
175 |
|
176 RArray<TSmlProfileId> arr; |
|
177 iEngine->Session()->ListProfilesL( arr, ESmlDevMan ); |
|
178 CleanupClosePushL(arr); |
|
179 TNSmlDMSyncProfileItem item; |
|
180 |
|
181 TBool fotaSupported = FeatureManager::FeatureSupported( KFeatureIdSyncMlDmFota ); |
|
182 TBuf<KBufSize256> fotaProfileId; |
|
183 |
|
184 if ( fotaSupported && !aIncludeHidden ) |
|
185 { |
|
186 CRepository* centrep = CRepository::NewL( KCRUidNSmlDMSyncApp ); |
|
187 if ( centrep->Get( KNSmlDMFotaHiddenProfileIdKey, fotaProfileId ) != KErrNone ) |
|
188 { |
|
189 fotaProfileId.Zero(); |
|
190 } |
|
191 FTRACE( FPrint( |
|
192 _L("[OMADM] CNSmlDMSyncProfileList::ReadProfileItemsL() hidden FOTA profile id = \"%S\""), |
|
193 &fotaProfileId ) ); |
|
194 delete centrep; |
|
195 } |
|
196 |
|
197 for ( TInt index = 0; index < arr.Count(); index++ ) |
|
198 { |
|
199 TRAPD( error, iEngine->OpenProfileL( arr[index], ESmlOpenRead ) ); |
|
200 if ( error == KErrNone ) |
|
201 { |
|
202 TRAPD( retVal, item = ReadProfileItemL( iEngine->Profile() ) ); |
|
203 |
|
204 TBuf<KBufSize256> profileId; |
|
205 iEngine->Profile()->GetServerId( profileId ); |
|
206 if ( (retVal == KErrNone) |
|
207 && ( fotaProfileId.Compare(profileId) != 0 ) ) |
|
208 { |
|
209 iList.Append( item ); |
|
210 } |
|
211 |
|
212 iEngine->CloseProfile(); |
|
213 } |
|
214 } |
|
215 CleanupStack::PopAndDestroy( &arr ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CNSmlDMSyncProfileList::ReadProfileItemL |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TNSmlDMSyncProfileItem CNSmlDMSyncProfileList::ReadProfileItemL( |
|
223 CNSmlDMSyncProfile* aProfile ) |
|
224 { |
|
225 FLOG( "[OMADM] CNSmlDMSyncProfileList::ReadProfileItemL:" ); |
|
226 |
|
227 TNSmlDMSyncProfileItem item; |
|
228 item.iApplicationId = aProfile->CreatorId(); |
|
229 TBuf<KBufSize> buf; |
|
230 aProfile->GetName( buf ); |
|
231 item.SetName( buf ); |
|
232 item.SetId( aProfile->ProfileId() ); |
|
233 item.iSynced = aProfile->IsSynced(); |
|
234 item.iLastSync = aProfile->LastSync(); |
|
235 item.iLastSuccessSync = aProfile->LastSuccessSync(); |
|
236 item.iBearer = aProfile->BearerType(); |
|
237 item.iActive = EFalse; |
|
238 if ( aProfile->SASyncState() != ESASyncStateDisable ) |
|
239 { |
|
240 item.iActive = ETrue; |
|
241 } |
|
242 item.iDeleteAllowed = aProfile->DeleteAllowed(); |
|
243 item.iProfileLocked = aProfile->ProfileLocked(); |
|
244 |
|
245 // check whether all mandatory data exist |
|
246 item.iMandatoryCheck = CheckMandatoryDataL( aProfile ); |
|
247 return item; |
|
248 } |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 // CNSmlDMSyncProfileList::Reset |
|
252 // ----------------------------------------------------------------------------- |
|
253 // |
|
254 void CNSmlDMSyncProfileList::Reset() |
|
255 { |
|
256 FLOG( "[OMADM] CNSmlDMSyncProfileList::Reset:" ); |
|
257 |
|
258 iList.Reset(); |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CNSmlDMSyncProfileList::Remove |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 void CNSmlDMSyncProfileList::Remove( TInt aProfileId ) |
|
266 { |
|
267 FLOG( "[OMADM] CNSmlDMSyncProfileList::Remove:" ); |
|
268 |
|
269 for ( TInt index = 0; index < Count(); index++ ) |
|
270 { |
|
271 TNSmlDMSyncProfileItem item = iList[index]; |
|
272 if ( item.iProfileId == aProfileId ) |
|
273 { |
|
274 iList.Remove( index ); |
|
275 return; |
|
276 } |
|
277 } |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CNSmlDMSyncProfileList::CheckMandatoryDataL |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 TInt CNSmlDMSyncProfileList::CheckMandatoryDataL( CNSmlDMSyncProfile* aProfile ) |
|
285 { |
|
286 FLOG( "[OMADM] CNSmlDMSyncProfileList::CheckMandatoryDataL:" ); |
|
287 |
|
288 TBuf<KBufSize> buf; |
|
289 TInt num; |
|
290 |
|
291 aProfile->GetName( buf ); |
|
292 if ( TUtil::IsEmpty( buf ) ) |
|
293 { |
|
294 return EMandatoryNoProfileName; |
|
295 } |
|
296 |
|
297 aProfile->GetHostAddress( buf, num ); |
|
298 if ( TUtil::IsEmpty( buf ) ) |
|
299 { |
|
300 return EMandatoryNoHostAddress; |
|
301 } |
|
302 |
|
303 return EMandatoryOk; |
|
304 } |
|
305 |
|
306 // ----------------------------------------------------------------------------- |
|
307 // CNSmlDMSyncProfileList::IsEmpty |
|
308 // ----------------------------------------------------------------------------- |
|
309 // |
|
310 TBool CNSmlDMSyncProfileList::IsEmpty( const TDesC& aText ) |
|
311 { |
|
312 FLOG( "[OMADM] CNSmlDMSyncProfileList::IsEmpty:" ); |
|
313 |
|
314 for ( TInt index = 0; index < aText.Length(); index++ ) |
|
315 { |
|
316 TChar character = aText[index]; |
|
317 if ( !character.IsSpace() ) |
|
318 { |
|
319 return EFalse; |
|
320 } |
|
321 } |
|
322 return ETrue; |
|
323 } |
|
324 |
|
325 // ----------------------------------------------------------------------------- |
|
326 // Sort |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 void CNSmlDMSyncProfileList::Sort() |
|
330 { |
|
331 iList.Sort( TLinearOrder<TNSmlDMSyncProfileItem>( |
|
332 TNSmlDMSyncProfileItem::CompareItem) ); |
|
333 } |
|
334 |
|
335 // End of File |