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