|
1 /* |
|
2 * Copyright (c) 2005 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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDES |
|
21 #include "AspSyncUtil.h" |
|
22 #include "AspDialogUtil.h" |
|
23 #include "AspProfileDialog.h" |
|
24 #include "AspProfileWizardDialog.h" |
|
25 #include "AspAutoSyncHandler.h" |
|
26 |
|
27 #include "AspSyncUtil.rh" |
|
28 #include "AspDebug.h" |
|
29 |
|
30 #include <AiwCommon.hrh> // for application ids |
|
31 #include <DataSyncInternalPSKeys.h> |
|
32 |
|
33 #ifdef RD_DSUI_TIMEDSYNC |
|
34 #include "AspSettingViewDialog.h" |
|
35 #endif |
|
36 // ============================ MEMBER FUNCTIONS =============================== |
|
37 |
|
38 |
|
39 |
|
40 // ----------------------------------------------------------------------------- |
|
41 // CAspSyncUtil::NewL |
|
42 // |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CAspSyncUtil* CAspSyncUtil::NewL() |
|
46 { |
|
47 FLOG( _L("CAspSyncUtil::NewL START") ); |
|
48 |
|
49 CAspSyncUtil* self = new (ELeave) CAspSyncUtil(); |
|
50 CleanupStack::PushL(self); |
|
51 self->ConstructL(); |
|
52 CleanupStack::Pop(self); |
|
53 |
|
54 FLOG( _L("CAspSyncUtil::NewL END") ); |
|
55 return self; |
|
56 } |
|
57 |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // Destructor |
|
61 // |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 CAspSyncUtil::~CAspSyncUtil() |
|
65 { |
|
66 FLOG( _L("CAspSyncUtil::~CAspSyncUtil START") ); |
|
67 |
|
68 delete iResHandler; |
|
69 delete iSyncHandler; |
|
70 delete iContentList; |
|
71 |
|
72 CloseSyncSession(); |
|
73 |
|
74 FLOG( _L("CAspSyncUtil::~CAspSyncUtil END") ); |
|
75 } |
|
76 |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CAspSyncUtil::ConstructL |
|
80 // |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CAspSyncUtil::ConstructL(void) |
|
84 { |
|
85 FLOG( _L("CAspSyncUtil::ConstructL START") ); |
|
86 |
|
87 iSettingEnforcement = TUtil::SettingEnforcementState(); |
|
88 |
|
89 TAspParam param(iApplicationId, NULL); // param not used in CAspSyncHandler |
|
90 iSyncHandler = CAspSyncHandler::NewL(param); |
|
91 |
|
92 iSyncSessionOpen = EFalse; |
|
93 |
|
94 FLOG( _L("CAspSyncUtil::ConstructL END") ); |
|
95 } |
|
96 |
|
97 |
|
98 // ----------------------------------------------------------------------------- |
|
99 // CAspSyncUtil::CAspSyncUtil |
|
100 // |
|
101 // ----------------------------------------------------------------------------- |
|
102 // |
|
103 CAspSyncUtil::CAspSyncUtil() |
|
104 { |
|
105 } |
|
106 |
|
107 |
|
108 // ----------------------------------------------------------------------------- |
|
109 // CAspSyncUtil::SynchronizeL |
|
110 // |
|
111 // Called by CSyncUtilApi::SynchronizeL. |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 void CAspSyncUtil::SynchronizeL(RFile& aTaskFile) |
|
115 { |
|
116 CAspAutoSyncHandler* autoSyncHandler = CAspAutoSyncHandler::NewL(); |
|
117 CleanupStack::PushL(autoSyncHandler); |
|
118 |
|
119 autoSyncHandler->SynchronizeL(aTaskFile); |
|
120 |
|
121 CleanupStack::PopAndDestroy(autoSyncHandler); |
|
122 } |
|
123 |
|
124 |
|
125 // ----------------------------------------------------------------------------- |
|
126 // CAspSyncUtil::SynchronizeL |
|
127 // |
|
128 // Called by CSyncUtilApi::SynchronizeL. |
|
129 // ----------------------------------------------------------------------------- |
|
130 // |
|
131 void CAspSyncUtil::SynchronizeL(TInt aApplicationId, TInt aJobId, TInt aInfo1, TDes& aInfo2) |
|
132 { |
|
133 FLOG( _L("CAspSyncUtil::SynchronizeL START") ); |
|
134 |
|
135 if (!iResHandler) |
|
136 { |
|
137 iResHandler = CAspResHandler::NewL(); |
|
138 } |
|
139 |
|
140 iApplicationId = aApplicationId; |
|
141 |
|
142 OpenSyncSessionL(); |
|
143 |
|
144 TRAPD(err, DoSynchronizeL(aApplicationId, aJobId, aInfo1, aInfo2)); |
|
145 |
|
146 CloseSyncSession(); |
|
147 |
|
148 User::LeaveIfError(err); |
|
149 |
|
150 FLOG( _L("CAspSyncUtil::SynchronizeL END") ); |
|
151 } |
|
152 |
|
153 |
|
154 // ----------------------------------------------------------------------------- |
|
155 // CAspSyncUtil::ShowSettingsL |
|
156 // |
|
157 // Called by CSyncUtilApi::ShowSettingsL. |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 void CAspSyncUtil::ShowSettingsL(TInt aApplicationId, TInt aInfo1, TDes& /*aInfo2*/) |
|
161 { |
|
162 FLOG( _L("CAspSyncUtil::ShowSettingsL START") ); |
|
163 |
|
164 if (!iResHandler) |
|
165 { |
|
166 iResHandler = CAspResHandler::NewL(); |
|
167 } |
|
168 |
|
169 iApplicationId = aApplicationId; |
|
170 |
|
171 if (aApplicationId != EApplicationIdSync) |
|
172 { |
|
173 // other apps only show profile dialog |
|
174 ShowProfileDialogL(aApplicationId); |
|
175 return; |
|
176 } |
|
177 |
|
178 |
|
179 TInt dialogMode = EModeDialogWait; |
|
180 if (aInfo1 == EModeDialogNoWait) |
|
181 { |
|
182 dialogMode = EModeDialogNoWait; |
|
183 } |
|
184 |
|
185 OpenSyncSessionL(); |
|
186 |
|
187 TRAPD(err, ShowSettingsDialogL(aApplicationId, KErrNotFound, dialogMode)); |
|
188 |
|
189 if (dialogMode == EModeDialogWait) |
|
190 { |
|
191 iSettingDialog = NULL; |
|
192 CloseSyncSession(); |
|
193 } |
|
194 |
|
195 User::LeaveIfError(err); |
|
196 |
|
197 FLOG( _L("CAspSyncUtil::ShowSettingsL END") ); |
|
198 } |
|
199 |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CAspSyncUtil::ShowSettingsDialog |
|
203 // |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CAspSyncUtil::ShowSettingsDialogL(TInt aApplicationId, |
|
207 TInt aProfileId, TInt aDialogMode) |
|
208 { |
|
209 if (aApplicationId != EApplicationIdSync) |
|
210 { |
|
211 CreateContentListL(); |
|
212 CheckAppAndProviderL(aApplicationId); |
|
213 } |
|
214 |
|
215 TAspParam param(aApplicationId, &iSyncSession); |
|
216 param.iMode = aDialogMode; |
|
217 param.iProfileId = aProfileId; |
|
218 |
|
219 iSettingDialog = CAspSettingDialog::NewL(param); |
|
220 |
|
221 if (aDialogMode == EModeDialogWait) |
|
222 { |
|
223 iSettingDialog->ExecuteLD(R_ASP_SETTING_DIALOG); |
|
224 } |
|
225 else |
|
226 { |
|
227 iSettingDialog->ExecuteLD(R_ASP_SETTING_DIALOG_2); |
|
228 } |
|
229 } |
|
230 |
|
231 |
|
232 // ----------------------------------------------------------------------------- |
|
233 // CAspSyncUtil::ShowProfileDialog |
|
234 // |
|
235 // ----------------------------------------------------------------------------- |
|
236 // |
|
237 void CAspSyncUtil::ShowProfileDialogL(TInt aApplicationId) |
|
238 { |
|
239 FLOG( _L("CAspSyncUtil::ShowProfileDialogL START") ); |
|
240 |
|
241 OpenSyncSessionL(); |
|
242 |
|
243 TRAPD(err, EditProfileL(aApplicationId)); |
|
244 |
|
245 CloseSyncSession(); |
|
246 |
|
247 User::LeaveIfError(err); |
|
248 |
|
249 FLOG( _L("CAspSyncUtil::ShowProfileDialogL END") ); |
|
250 } |
|
251 |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CAspSyncUtil::EditProfileL |
|
255 // |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CAspSyncUtil::EditProfileL(TInt aAplicationId) |
|
259 { |
|
260 CreateContentListL(); |
|
261 CheckAppAndProviderL(aAplicationId); |
|
262 |
|
263 TInt profileId = KErrNotFound; |
|
264 TInt taskId = KErrNotFound; |
|
265 TInt resourceId = R_ASP_PROFILE_QUERY_TITLE; |
|
266 |
|
267 TBool ret = SelectProfileL(profileId, taskId, resourceId, KNullDesC,ETrue); |
|
268 if (!ret || profileId == KErrNotFound) |
|
269 { |
|
270 return; // no sync profile |
|
271 } |
|
272 |
|
273 if (iSettingEnforcement) |
|
274 { |
|
275 DoEditReadOnlyProfileL(aAplicationId, profileId, |
|
276 EDialogModeSettingEnforcement); |
|
277 } |
|
278 else |
|
279 { |
|
280 DoEditProfileL(aAplicationId, profileId, EDialogModeEdit); |
|
281 } |
|
282 } |
|
283 |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CAspSyncUtil::DoEditProfileL |
|
287 // |
|
288 // ----------------------------------------------------------------------------- |
|
289 // |
|
290 void CAspSyncUtil::DoEditProfileL(TInt aApplicationId, TInt aProfileId, |
|
291 TInt aDialogMode) |
|
292 { |
|
293 TAspParam param(EApplicationIdSync, &iSyncSession); |
|
294 CAspProfileList* profileList = CAspProfileList::NewLC(param); |
|
295 profileList->ReadAllProfilesL(CAspProfileList::ENoMandatoryCheck); |
|
296 |
|
297 |
|
298 param.iApplicationId = aApplicationId; |
|
299 CAspProfile* profile = CAspProfile::NewLC(param); |
|
300 |
|
301 TInt err = KErrNone; |
|
302 TRAP(err, profile->OpenL(aProfileId, CAspProfile::EOpenReadWrite, |
|
303 CAspProfile::EAllProperties)); |
|
304 |
|
305 if (err == KErrLocked) |
|
306 { |
|
307 TDialogUtil::ShowErrorNoteL(R_ASP_LOCKED_PROFILE); |
|
308 } |
|
309 User::LeaveIfError(err); |
|
310 |
|
311 iContentList->SetProfile(profile); |
|
312 TRAP(err, iContentList->InitAllTasksL()); |
|
313 |
|
314 if (err != KErrNone) |
|
315 { |
|
316 iContentList->SetProfile(NULL); |
|
317 } |
|
318 User::LeaveIfError(err); |
|
319 |
|
320 TAspParam param2(aApplicationId, &iSyncSession); |
|
321 param2.iProfile = profile; |
|
322 param2.iMode = aDialogMode; |
|
323 param2.iContentList = iContentList; |
|
324 param2.iProfileList = profileList; // needed for unique server id check |
|
325 |
|
326 #ifdef RD_DSUI_TIMEDSYNC |
|
327 CAspSettingViewDialog::ShowDialogL(param2); |
|
328 #else |
|
329 TRAP(err, CAspProfileDialog::ShowDialogL(param2)); |
|
330 #endif |
|
331 |
|
332 iContentList->SetProfile(NULL); |
|
333 User::LeaveIfError(err); |
|
334 |
|
335 CleanupStack::PopAndDestroy(profile); |
|
336 CleanupStack::PopAndDestroy(profileList); |
|
337 } |
|
338 |
|
339 |
|
340 // ----------------------------------------------------------------------------- |
|
341 // CAspSyncUtil::DoEditReadOnlyProfileL |
|
342 // |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 void CAspSyncUtil::DoEditReadOnlyProfileL(TInt aApplicationId, TInt aProfileId, |
|
346 TInt aDialogMode) |
|
347 { |
|
348 TAspParam param(aApplicationId, &iSyncSession); |
|
349 CAspProfile* profile = CAspProfile::NewLC(param); |
|
350 |
|
351 profile->OpenL(aProfileId, CAspProfile::EOpenRead, |
|
352 CAspProfile::EAllProperties); |
|
353 |
|
354 iContentList->SetProfile(profile); |
|
355 TInt err = KErrNone; |
|
356 TRAP(err, iContentList->InitAllTasksL()); |
|
357 |
|
358 if (err != KErrNone) |
|
359 { |
|
360 iContentList->SetProfile(NULL); |
|
361 } |
|
362 User::LeaveIfError(err); |
|
363 |
|
364 TAspParam param2(aApplicationId, &iSyncSession); |
|
365 param2.iProfile = profile; |
|
366 param2.iMode = aDialogMode; |
|
367 param2.iContentList = iContentList; |
|
368 |
|
369 TRAP(err, CAspProfileDialog::ShowDialogL(param2)); |
|
370 |
|
371 iContentList->SetProfile(NULL); |
|
372 User::LeaveIfError(err); |
|
373 |
|
374 CleanupStack::PopAndDestroy(profile); |
|
375 } |
|
376 |
|
377 |
|
378 // ----------------------------------------------------------------------------------------------------- |
|
379 // CAspSyncUtil::SelectProfileL |
|
380 // aCheckId currently will be always set to ETrue |
|
381 // this Check can be used in future to differentiate if its called from DoSynchronizeL() or EditProfileL() |
|
382 // ------------------------------------------------------------------------------------------------------ |
|
383 // |
|
384 TBool CAspSyncUtil::SelectProfileL(TInt& aProfileId, TInt& aTaskId, |
|
385 TInt aResourceId, const TDesC& aLocalDatabase,TBool aCheckId) |
|
386 { |
|
387 aProfileId = KErrNotFound; |
|
388 aTaskId = KErrNotFound; |
|
389 TBool ret = EFalse; |
|
390 TInt index=KErrNotFound; |
|
391 |
|
392 TAspParam param(iApplicationId, &iSyncSession); |
|
393 CAspProfileList* profileList = CAspProfileList::NewLC(param); |
|
394 |
|
395 if (aLocalDatabase.Length() > 0) |
|
396 { |
|
397 profileList->ReadEMailProfilesL(aLocalDatabase, KErrNotFound); |
|
398 if(profileList->Count() == 0) |
|
399 { |
|
400 profileList->ReadAllProfilesL(CAspProfileList::EBasePropertiesOnly); |
|
401 } |
|
402 } |
|
403 else |
|
404 { |
|
405 profileList->ReadAllProfilesL(CAspProfileList::EBasePropertiesOnly); |
|
406 } |
|
407 |
|
408 profileList->Sort(); |
|
409 |
|
410 if (profileList->Count() == 0) |
|
411 { |
|
412 if (!iSettingEnforcement) |
|
413 { |
|
414 if (TDialogUtil::ShowConfirmationQueryL(R_ASP_QUERY_NO_PROFILES)) |
|
415 { |
|
416 TAspParam param(iApplicationId, &iSyncSession); |
|
417 CAspProfileWizardDialog::ShowDialogL(param); |
|
418 } |
|
419 } |
|
420 |
|
421 ret = EFalse; |
|
422 } |
|
423 |
|
424 else if (profileList->Count() == 1) |
|
425 { |
|
426 TAspProfileItem& item = profileList->Item(0); |
|
427 aProfileId = item.iProfileId; |
|
428 aTaskId = item.iTaskId; |
|
429 ret = ETrue; |
|
430 } |
|
431 |
|
432 else |
|
433 { |
|
434 if(aCheckId) |
|
435 { |
|
436 |
|
437 |
|
438 if (iSettingEnforcement) |
|
439 { |
|
440 ret = TDialogUtil::ShowProfileQueryL(profileList, aProfileId, aResourceId); |
|
441 |
|
442 } |
|
443 else |
|
444 { |
|
445 ret = TDialogUtil::ShowProfileQueryAppL(profileList, aProfileId, aResourceId,index); |
|
446 } |
|
447 |
|
448 |
|
449 if (ret) |
|
450 { |
|
451 index = profileList->ListIndex(aProfileId); |
|
452 |
|
453 __ASSERT_DEBUG(index != KErrNotFound, TUtil::Panic(KErrGeneral)); |
|
454 |
|
455 TAspProfileItem& item = profileList->Item(index); |
|
456 |
|
457 aTaskId = item.iTaskId; |
|
458 |
|
459 } |
|
460 |
|
461 else |
|
462 { |
|
463 if(index==1) |
|
464 CAspProfileWizardDialog::ShowDialogL(param); |
|
465 //ret=EFalse; |
|
466 |
|
467 } |
|
468 } |
|
469 |
|
470 else |
|
471 { |
|
472 |
|
473 |
|
474 ret = TDialogUtil::ShowProfileQueryL(profileList, aProfileId, aResourceId); |
|
475 |
|
476 if (ret) |
|
477 { |
|
478 TInt index = profileList->ListIndex(aProfileId); |
|
479 |
|
480 __ASSERT_DEBUG(index != KErrNotFound, TUtil::Panic(KErrGeneral)); |
|
481 |
|
482 TAspProfileItem& item = profileList->Item(index); |
|
483 aTaskId = item.iTaskId; |
|
484 |
|
485 |
|
486 |
|
487 } |
|
488 |
|
489 |
|
490 } |
|
491 } |
|
492 |
|
493 CleanupStack::PopAndDestroy(profileList); |
|
494 |
|
495 return ret; |
|
496 } |
|
497 |
|
498 |
|
499 // ----------------------------------------------------------------------------- |
|
500 // CAspSyncUtil::DoSynchronizeL |
|
501 // |
|
502 // ----------------------------------------------------------------------------- |
|
503 // |
|
504 void CAspSyncUtil::DoSynchronizeL(TInt aApplicationId, TInt /*aJobId*/, |
|
505 TInt aInfo1, TDes& aInfo2) |
|
506 { |
|
507 FLOG( _L("CAspSyncUtil::DoSynchronizeL START") ); |
|
508 |
|
509 CreateContentListL(); |
|
510 CheckAppAndProviderL(aApplicationId); |
|
511 |
|
512 //check PS key |
|
513 TInt keyVal = 0;//EDataSyncNotRunning |
|
514 TInt err = RProperty::Get( KPSUidDataSynchronizationInternalKeys, |
|
515 KDataSyncStatus, |
|
516 keyVal ); |
|
517 if(err == KErrNone && keyVal) |
|
518 { |
|
519 TDialogUtil::ShowInformationNoteL(R_ASP_SYNC_ALREADY_RUNNING); |
|
520 return; |
|
521 } |
|
522 |
|
523 if (CAspProfile::OtherSyncRunning(&iSyncSession)) |
|
524 { |
|
525 TDialogUtil::ShowInformationNoteL(R_ASP_SYNC_ALREADY_RUNNING); |
|
526 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
527 return; |
|
528 } |
|
529 |
|
530 if (iApplicationId == EApplicationIdEmail && TUtil::IsEmpty(aInfo2)) |
|
531 { |
|
532 FLOG( _L("### mailbox name not defined ###") ); |
|
533 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
534 User::Leave(KErrNotFound); |
|
535 } |
|
536 |
|
537 |
|
538 TInt profileId = KErrNotFound; |
|
539 TInt taskId = KErrNotFound; |
|
540 TBool ret = EFalse; |
|
541 TInt resourceId = R_ASP_PROFILE_QUERY_TITLE; |
|
542 |
|
543 if (aApplicationId == EApplicationIdEmail) |
|
544 { |
|
545 ret = SelectProfileL(profileId, taskId, resourceId, aInfo2,ETrue); |
|
546 } |
|
547 else |
|
548 { |
|
549 ret = SelectProfileL(profileId, taskId, resourceId, KNullDesC,ETrue); |
|
550 } |
|
551 |
|
552 if (!ret || profileId == KErrNotFound) |
|
553 { |
|
554 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
555 return; // no sync profile |
|
556 } |
|
557 |
|
558 TAspParam aspParam(iApplicationId, &iSyncSession); |
|
559 CAspProfile* profile = CAspProfile::NewLC(aspParam); |
|
560 TRAPD (err1, profile->OpenL(profileId, CAspProfile::EOpenRead, |
|
561 CAspProfile::EAllProperties)); |
|
562 User::LeaveIfError(err1); |
|
563 if (aApplicationId != EApplicationIdEmail) |
|
564 { |
|
565 aInfo2 = KNullDesC; |
|
566 } |
|
567 //create task for content type ,if it is not created yet |
|
568 ret = CheckTaskAndProtocolL(profileId, aInfo2); |
|
569 |
|
570 TInt dataProviderId = TUtil::ProviderIdFromAppId(aApplicationId); |
|
571 taskId = TAspTask::FindTaskIdL(profile, dataProviderId, aInfo2); |
|
572 |
|
573 CleanupStack::PopAndDestroy(profile); |
|
574 |
|
575 if (!ret) |
|
576 { |
|
577 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
578 return; // some mandatory data missing |
|
579 } |
|
580 |
|
581 if (!CheckMandatoryL(profileId)) |
|
582 { |
|
583 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
584 return; // some mandatory data missing |
|
585 } |
|
586 |
|
587 #ifdef _DEBUG |
|
588 TBuf<KBufSize> buf; |
|
589 TUtil::GetApplicationName(buf, aApplicationId); |
|
590 FTRACE(RDebug::Print(_L("statrting sync (%S)"), &buf)); |
|
591 #endif |
|
592 |
|
593 TAspSyncParam param(aApplicationId); |
|
594 param.iProfileId = profileId; |
|
595 param.iTaskId = taskId; |
|
596 |
|
597 if (aInfo1 == EApplicationIdEmail) |
|
598 { |
|
599 // email sync 3.2 needs synchronous syncing |
|
600 param.iDialogMode = EModeDialogWait; |
|
601 } |
|
602 |
|
603 iSyncHandler->SynchronizeL(param); |
|
604 |
|
605 FLOG( _L("CAspSyncUtil::DoSynchronizeL END") ); |
|
606 } |
|
607 |
|
608 |
|
609 // ----------------------------------------------------------------------------- |
|
610 // CAspSyncUtil::CheckMandatoryL |
|
611 // |
|
612 // ----------------------------------------------------------------------------- |
|
613 // |
|
614 TBool CAspSyncUtil::CheckMandatoryL(TInt aProfileId) |
|
615 { |
|
616 TAspParam param(iApplicationId, &iSyncSession); |
|
617 CAspProfile* profile = CAspProfile::NewLC(param); |
|
618 profile->OpenL(aProfileId, CAspProfile::EOpenRead, |
|
619 CAspProfile::EAllProperties); |
|
620 |
|
621 TInt contentCount = 0; |
|
622 TInt ret = CAspProfile::CheckMandatoryData(profile, contentCount); |
|
623 CleanupStack::PopAndDestroy(profile); |
|
624 |
|
625 if (ret != EMandatoryOk) |
|
626 { |
|
627 if (iSettingEnforcement) |
|
628 { |
|
629 TDialogUtil::ShowInformationNoteL(R_ASP_NOTE_TARM_MANDATORY_MISSING); |
|
630 } |
|
631 else if (TDialogUtil::ShowConfirmationQueryL(R_ASP_QUERY_MANDATORY_MISSING)) |
|
632 { |
|
633 DoEditProfileL(iApplicationId, aProfileId, EDialogModeEditMandatory); |
|
634 } |
|
635 |
|
636 return EFalse; |
|
637 } |
|
638 |
|
639 return ETrue; |
|
640 } |
|
641 |
|
642 |
|
643 // ----------------------------------------------------------------------------- |
|
644 // CAspSyncUtil::DataProviderExist |
|
645 // |
|
646 // ----------------------------------------------------------------------------- |
|
647 // |
|
648 TBool CAspSyncUtil::DataProviderExist(TInt aApplicationId) |
|
649 { |
|
650 if (iContentList == NULL) |
|
651 { |
|
652 return ETrue; |
|
653 } |
|
654 |
|
655 TInt providerId = TUtil::ProviderIdFromAppId(aApplicationId); |
|
656 TInt index = iContentList->FindProviderIndex(providerId); |
|
657 |
|
658 if (index == KErrNotFound) |
|
659 { |
|
660 return EFalse; |
|
661 } |
|
662 return ETrue; |
|
663 } |
|
664 |
|
665 |
|
666 // ----------------------------------------------------------------------------- |
|
667 // CAspSyncUtil::CreateContentListL |
|
668 // |
|
669 // ----------------------------------------------------------------------------- |
|
670 // |
|
671 void CAspSyncUtil::CreateContentListL() |
|
672 { |
|
673 if (iContentList) |
|
674 { |
|
675 return; |
|
676 } |
|
677 |
|
678 TAspParam param(KErrNotFound, &iSyncSession); |
|
679 param.iMode = CAspContentList::EInitDataProviders; |
|
680 iContentList = CAspContentList::NewL(param); |
|
681 } |
|
682 |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CAspSyncUtil::CheckAppAndProvider |
|
686 // |
|
687 // ----------------------------------------------------------------------------- |
|
688 // |
|
689 void CAspSyncUtil::CheckAppAndProviderL(TInt aApplicationId) |
|
690 { |
|
691 TInt sid = RProcess().SecureId().iId; |
|
692 |
|
693 if (!TUtil::IsValidSID(sid)) |
|
694 { |
|
695 FLOG( _L("### CAspSyncUtil::CheckAppAndProviderL: wrong SID (%xd) ###"), sid); |
|
696 User::Leave(KErrNotSupported); // unknown caller app |
|
697 } |
|
698 |
|
699 if (!TUtil::IsValidAppId(aApplicationId)) |
|
700 { |
|
701 FLOG( _L("### CAspSyncUtil::CheckAppAndProviderL: wrong app id (%d) ###"), aApplicationId); |
|
702 User::Leave(KErrNotSupported); // unknown caller app |
|
703 } |
|
704 |
|
705 if (aApplicationId != EApplicationIdSync && !DataProviderExist(aApplicationId)) |
|
706 { |
|
707 FLOG( _L("### CAspSyncUtil::CheckAppAndProviderL: no data provider (%d) ###"), aApplicationId); |
|
708 User::Leave(KErrNotFound); // sync data provider not found |
|
709 } |
|
710 } |
|
711 |
|
712 // ----------------------------------------------------------------------------- |
|
713 // CAspSyncUtil::CheckTaskAndProtocolL |
|
714 // |
|
715 // ----------------------------------------------------------------------------- |
|
716 // |
|
717 TBool CAspSyncUtil::CheckTaskAndProtocolL(TInt aProfileId ,const TDesC& aLocalDatabase) |
|
718 { |
|
719 |
|
720 TAspParam param(iApplicationId, &iSyncSession); |
|
721 |
|
722 CAspProfile* profile = CAspProfile::NewLC(param); |
|
723 TRAPD (err, profile->OpenL(aProfileId, CAspProfile::EOpenReadWrite, |
|
724 CAspProfile::EAllProperties)); |
|
725 if (err == KErrLocked) |
|
726 { |
|
727 TDialogUtil::ShowErrorNoteL(R_ASP_LOCKED_PROFILE); |
|
728 CleanupStack::PopAndDestroy(profile); |
|
729 return EFalse; |
|
730 } |
|
731 |
|
732 TInt dataProviderId = TUtil::ProviderIdFromAppId(iApplicationId); |
|
733 iContentList->RemoveAllTasks(); |
|
734 iContentList->SetProfile(profile); |
|
735 iContentList->InitAllTasksL(); |
|
736 |
|
737 if (iApplicationId == EApplicationIdEmail) |
|
738 { |
|
739 |
|
740 TInt protocol = profile->ProtocolVersion(); |
|
741 if (protocol == EAspProtocol_1_1) |
|
742 { |
|
743 |
|
744 CleanupStack::PopAndDestroy(profile); |
|
745 iContentList->SetProfile(NULL); |
|
746 return EFalse; |
|
747 } |
|
748 |
|
749 TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, aLocalDatabase); |
|
750 if (taskId == KErrNotFound) |
|
751 { |
|
752 |
|
753 iContentList->ModifyTaskIncludedL(dataProviderId, ETrue, aLocalDatabase); |
|
754 |
|
755 } |
|
756 |
|
757 } |
|
758 else |
|
759 { |
|
760 TInt taskId = TAspTask::FindTaskIdL(profile, dataProviderId, KNullDesC); |
|
761 if (taskId == KErrNotFound) |
|
762 { |
|
763 |
|
764 iContentList->ModifyTaskIncludedL(dataProviderId, ETrue, KNullDesC); |
|
765 |
|
766 } |
|
767 } |
|
768 |
|
769 iContentList->SetProfile(NULL); |
|
770 CleanupStack::PopAndDestroy(profile); |
|
771 return ETrue; |
|
772 } |
|
773 |
|
774 // ----------------------------------------------------------------------------- |
|
775 // OpenSyncSessionL |
|
776 // |
|
777 // ----------------------------------------------------------------------------- |
|
778 // |
|
779 void CAspSyncUtil::OpenSyncSessionL() |
|
780 { |
|
781 if (!iSyncSessionOpen) |
|
782 { |
|
783 TRAPD(err, iSyncSession.OpenL()); |
|
784 |
|
785 if (err != KErrNone) |
|
786 { |
|
787 FLOG( _L("### CAspSyncUtil::OpenSyncSessionL: RSyncMLSession::OpenL failed (%d) ###"), err); |
|
788 |
|
789 iSyncSession.Close(); // can be done always |
|
790 User::Leave(err); |
|
791 } |
|
792 else |
|
793 { |
|
794 FLOG( _L("CAspSyncUtil::OpenSyncSessionL: RSyncMLSession::OpenL ok") ); |
|
795 } |
|
796 |
|
797 iSyncSessionOpen = ETrue; |
|
798 } |
|
799 } |
|
800 |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CloseSyncSession |
|
804 // |
|
805 // ----------------------------------------------------------------------------- |
|
806 // |
|
807 void CAspSyncUtil::CloseSyncSession() |
|
808 { |
|
809 if (iSyncSessionOpen) |
|
810 { |
|
811 iSyncSession.Close(); |
|
812 iSyncSessionOpen = EFalse; |
|
813 } |
|
814 } |
|
815 |
|
816 |
|
817 // End of file |
|
818 |