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 // INCLUDE FILES |
|
21 |
|
22 #include "AspProfileSelectionDialog.h" |
|
23 #include "AspSchedule.h" |
|
24 #include "AspProfileWizard.h" |
|
25 #include "AspSyncUtil.rh" |
|
26 #include "AspDebug.h" |
|
27 #include <csxhelp/ds.hlp.hrh> |
|
28 |
|
29 #include <AspSyncUtil.mbg> // for bitmap enumerations |
|
30 #include <Avkon.mbg> |
|
31 #include <akniconarray.h> // for GulArray |
|
32 |
|
33 |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CAspProfileSelectionDialog::ShowDialogL |
|
41 // |
|
42 // ----------------------------------------------------------------------------- |
|
43 TBool CAspProfileSelectionDialog::ShowDialogL(TAspParam& aParam) |
|
44 { |
|
45 CAspProfileSelectionDialog* dialog = CAspProfileSelectionDialog::NewL(aParam); |
|
46 |
|
47 TBool ret = dialog->ExecuteLD(R_ASP_AUTO_SYNC_PROFILE_DIALOG); |
|
48 |
|
49 return ret; |
|
50 } |
|
51 |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CAspProfileSelectionDialog::NewL |
|
55 // |
|
56 // ----------------------------------------------------------------------------- |
|
57 CAspProfileSelectionDialog* CAspProfileSelectionDialog::NewL(TAspParam& aParam) |
|
58 { |
|
59 FLOG( _L("CAspProfileSelectionDialog::NewL START") ); |
|
60 |
|
61 CAspProfileSelectionDialog* self = new (ELeave) CAspProfileSelectionDialog(aParam); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 CleanupStack::Pop(self); |
|
65 |
|
66 FLOG( _L("CAspProfileSelectionDialog::NewL END") ); |
|
67 return self; |
|
68 } |
|
69 |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CAspProfileSelectionDialog::CAspProfileSelectionDialog |
|
73 // |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CAspProfileSelectionDialog::CAspProfileSelectionDialog(TAspParam& aParam) |
|
77 { |
|
78 iSyncSession = aParam.iSyncSession; |
|
79 iApplicationId = aParam.iApplicationId; |
|
80 iProfileId = aParam.iProfileId; |
|
81 iDialogParam = &aParam; |
|
82 |
|
83 __ASSERT_ALWAYS(iSyncSession, TUtil::Panic(KErrGeneral)); |
|
84 } |
|
85 |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CAspProfileSelectionDialog::ConstructL |
|
89 // |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CAspProfileSelectionDialog::ConstructL() |
|
93 { |
|
94 FLOG( _L("CAspProfileSelectionDialog::ConstructL START") ); |
|
95 |
|
96 CAknDialog::ConstructL(R_ASP_AUTO_SYNC_PROFILE_DIALOG_MENU); |
|
97 |
|
98 TAspParam param(iApplicationId, iSyncSession); |
|
99 CAspProfileList* list = CAspProfileList::NewLC(param); |
|
100 list->ReadAllProfilesL(CAspProfileList::ENoMandatoryCheck); |
|
101 |
|
102 TAspFilterInfo info; |
|
103 info.iFilterType = TAspFilterInfo::EIncludeRemoteProfile; |
|
104 iProfileList = list->FilteredListL(info); |
|
105 iProfileList->Sort(); |
|
106 CleanupStack::PopAndDestroy(list); |
|
107 |
|
108 param.iMode = CAspContentList::EInitDataProviders; |
|
109 iContentList = CAspContentList::NewL(param); |
|
110 |
|
111 |
|
112 // get previous title so it can be restored |
|
113 iStatusPaneHandler = CStatusPaneHandler::NewL(iAvkonAppUi); |
|
114 iStatusPaneHandler->StoreOriginalTitleL(); |
|
115 |
|
116 iCommandSetId = R_ASP_CBA_OPTIONS_SELECT_BACK; |
|
117 |
|
118 FLOG( _L("CAspProfileSelectionDialog::ConstructL END") ); |
|
119 } |
|
120 |
|
121 |
|
122 // ---------------------------------------------------------------------------- |
|
123 // Destructor |
|
124 // |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 CAspProfileSelectionDialog::~CAspProfileSelectionDialog() |
|
128 { |
|
129 FLOG( _L("CAspProfileSelectionDialog::~CAspProfileSelectionDialog START") ); |
|
130 |
|
131 delete iProfileList; |
|
132 delete iContentList; |
|
133 delete iStatusPaneHandler; |
|
134 |
|
135 if (iAvkonAppUi) |
|
136 { |
|
137 iAvkonAppUi->RemoveFromStack(this); |
|
138 } |
|
139 |
|
140 FLOG( _L("CAspProfileSelectionDialog::~CAspProfileSelectionDialog END") ); |
|
141 } |
|
142 |
|
143 |
|
144 //------------------------------------------------------------------------------ |
|
145 // CAspProfileSelectionDialog::ActivateL |
|
146 // |
|
147 // Called by system when dialog is activated. |
|
148 //------------------------------------------------------------------------------ |
|
149 // |
|
150 void CAspProfileSelectionDialog::ActivateL() |
|
151 { |
|
152 CAknDialog::ActivateL(); |
|
153 |
|
154 // this cannot be in ConstructL which is executed before dialog is launched |
|
155 iAvkonAppUi->AddToStackL(this); |
|
156 } |
|
157 |
|
158 |
|
159 //------------------------------------------------------------------------------ |
|
160 // CAspContentListDialog::GetHelpContext |
|
161 // |
|
162 //------------------------------------------------------------------------------ |
|
163 // |
|
164 void CAspProfileSelectionDialog::GetHelpContext(TCoeHelpContext& aContext) const |
|
165 { |
|
166 aContext.iMajor = KUidSmlSyncApp; |
|
167 //aContext.iContext = KDS_HLP_SET_CONN_SETTINGS; |
|
168 } |
|
169 |
|
170 |
|
171 // ----------------------------------------------------------------------------- |
|
172 // CAspProfileSelectionDialog::HandleListBoxEventL |
|
173 // |
|
174 // ----------------------------------------------------------------------------- |
|
175 void CAspProfileSelectionDialog::HandleListBoxEventL(CEikListBox* /*aListBox*/, |
|
176 TListBoxEvent /*aEventType*/) |
|
177 { |
|
178 } |
|
179 |
|
180 |
|
181 // ----------------------------------------------------------------------------- |
|
182 // CAspProfileSelectionDialog::PreLayoutDynInitL |
|
183 // |
|
184 // ----------------------------------------------------------------------------- |
|
185 // |
|
186 void CAspProfileSelectionDialog::PreLayoutDynInitL() |
|
187 { |
|
188 iListBox = (CAknSingleGraphicStyleListBox*) (ControlOrNull(EAspAutoSyncProfileDialogList)); |
|
189 |
|
190 __ASSERT_ALWAYS(iListBox, TUtil::Panic(KErrGeneral)); |
|
191 |
|
192 iListBox->SetListBoxObserver(this); |
|
193 iListBox->CreateScrollBarFrameL(ETrue); |
|
194 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
195 CEikScrollBarFrame::EOn, CEikScrollBarFrame::EAuto); |
|
196 |
|
197 SetIconsL(); |
|
198 |
|
199 |
|
200 TInt index = iProfileList->ListIndex(iProfileId); |
|
201 if (index == KErrNotFound) |
|
202 { |
|
203 // select first profile |
|
204 if (iProfileList->Count() > 0) |
|
205 { |
|
206 TAspProfileItem& item = iProfileList->Item(0); |
|
207 iProfileId = item.iProfileId; |
|
208 } |
|
209 } |
|
210 |
|
211 UpdateListBoxL(); |
|
212 |
|
213 |
|
214 iStatusPaneHandler->SetTitleL(R_ASP_TITLE_AUTOMATIC_SYNC_PROFILE_SELECTION); |
|
215 iStatusPaneHandler->SetNaviPaneTitleL(KNullDesC); |
|
216 } |
|
217 |
|
218 |
|
219 // ---------------------------------------------------------------------------- |
|
220 // CAspProfileSelectionDialog::SetIconsL |
|
221 // |
|
222 // ---------------------------------------------------------------------------- |
|
223 // |
|
224 void CAspProfileSelectionDialog::SetIconsL() |
|
225 { |
|
226 if (!iListBox) |
|
227 { |
|
228 return; |
|
229 } |
|
230 |
|
231 TFileName bitmapName; |
|
232 CAspResHandler::GetBitmapFileName(bitmapName); |
|
233 CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(KDefaultArraySize); |
|
234 CleanupStack::PushL(icons); |
|
235 |
|
236 |
|
237 icons->AppendL(IconL(KAknsIIDQgnPropCheckboxOff, bitmapName, |
|
238 EMbmAvkonQgn_prop_checkbox_off, |
|
239 EMbmAvkonQgn_prop_checkbox_off_mask)); |
|
240 |
|
241 /* |
|
242 icons->AppendL(IconL(KAknsIIDQgnIndiMarkedAdd, bitmapName, |
|
243 EMbmAvkonQgn_indi_marked_add, |
|
244 EMbmAvkonQgn_indi_marked_add_mask)); |
|
245 */ |
|
246 |
|
247 icons->AppendL(IconL(KAknsIIDQgnIndiSettProtectedAdd, bitmapName, |
|
248 EMbmAspsyncutilQgn_indi_sett_protected_add, |
|
249 EMbmAspsyncutilQgn_indi_sett_protected_add_mask)); |
|
250 |
|
251 // delete old icons |
|
252 CArrayPtr<CGulIcon>* arr = iListBox->ItemDrawer()->ColumnData()->IconArray(); |
|
253 if (arr) |
|
254 { |
|
255 arr->ResetAndDestroy(); |
|
256 delete arr; |
|
257 arr = NULL; |
|
258 } |
|
259 |
|
260 iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons); |
|
261 CleanupStack::Pop(icons); |
|
262 } |
|
263 |
|
264 |
|
265 // ----------------------------------------------------------------------------- |
|
266 // CAspProfileSelectionDialog::IconL |
|
267 // |
|
268 // ----------------------------------------------------------------------------- |
|
269 // |
|
270 CGulIcon* CAspProfileSelectionDialog::IconL(TAknsItemID aId, const TDesC& aFileName, TInt aFileIndex, TInt aFileMaskIndex) |
|
271 { |
|
272 return TDialogUtil::CreateIconL(aId, aFileName, aFileIndex, aFileMaskIndex); |
|
273 } |
|
274 |
|
275 |
|
276 //------------------------------------------------------------------------------ |
|
277 // CAspProfileSelectionDialog::DynInitMenuPaneL |
|
278 // |
|
279 // Called by system before menu is shown. |
|
280 //------------------------------------------------------------------------------ |
|
281 // |
|
282 void CAspProfileSelectionDialog::DynInitMenuPaneL(TInt aResourceID, CEikMenuPane* aMenuPane) |
|
283 { |
|
284 if (aResourceID != R_ASP_AUTO_SYNC_PROFILE_DIALOG_MENU_PANE) |
|
285 { |
|
286 return; |
|
287 } |
|
288 |
|
289 TInt index = iListBox->CurrentItemIndex(); |
|
290 if (index != KErrNotFound) |
|
291 { |
|
292 TAspProfileItem& item = iProfileList->Item(index); |
|
293 |
|
294 if (iProfileId == item.iProfileId) |
|
295 { |
|
296 TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdSelect); |
|
297 } |
|
298 } |
|
299 else |
|
300 { |
|
301 TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdSelect); |
|
302 TDialogUtil::DeleteMenuItem(aMenuPane, EAspMenuCmdView); |
|
303 } |
|
304 } |
|
305 |
|
306 |
|
307 //------------------------------------------------------------------------------ |
|
308 // CAspProfileSelectionDialog::ProcessCommandL |
|
309 // |
|
310 // Handle commands from menu. |
|
311 //------------------------------------------------------------------------------ |
|
312 // |
|
313 void CAspProfileSelectionDialog::ProcessCommandL(TInt aCommandId) |
|
314 { |
|
315 HideMenu(); |
|
316 |
|
317 switch (aCommandId) |
|
318 { |
|
319 case EAspMenuCmdHelp: |
|
320 { |
|
321 break; |
|
322 } |
|
323 |
|
324 case EAspMenuCmdSelect: |
|
325 { |
|
326 HandleOKL(); |
|
327 break; |
|
328 } |
|
329 |
|
330 case EAspMenuCmdView: |
|
331 { |
|
332 ShowContentListL(); |
|
333 break; |
|
334 } |
|
335 |
|
336 case EAspMenuCmdExit: |
|
337 case EAknCmdExit: |
|
338 case EEikCmdExit: |
|
339 { |
|
340 // close dialog and exit calling application |
|
341 iAvkonAppUi->ProcessCommandL(EAknCmdExit); |
|
342 break; |
|
343 } |
|
344 |
|
345 default: |
|
346 break; |
|
347 } |
|
348 } |
|
349 |
|
350 |
|
351 //------------------------------------------------------------------------------ |
|
352 // CAspProfileSelectionDialog::OkToExitL |
|
353 // |
|
354 //------------------------------------------------------------------------------ |
|
355 // |
|
356 TBool CAspProfileSelectionDialog::OkToExitL(TInt aButtonId) |
|
357 { |
|
358 (*iDialogParam).iReturnValue = EFalse; |
|
359 (*iDialogParam).iProfileId = iProfileId; |
|
360 |
|
361 if (aButtonId == EEikBidCancel) |
|
362 { |
|
363 return ETrue; |
|
364 } |
|
365 |
|
366 if (aButtonId == EAknSoftkeyBack) |
|
367 { |
|
368 (*iDialogParam).iReturnValue = ETrue; |
|
369 return ETrue; |
|
370 } |
|
371 |
|
372 if (aButtonId == EAknSoftkeyOpen) // MSK |
|
373 { |
|
374 HandleOKL(); |
|
375 return EFalse; // leave dialog open |
|
376 } |
|
377 |
|
378 return CAknDialog::OkToExitL(aButtonId); |
|
379 } |
|
380 |
|
381 |
|
382 // ---------------------------------------------------------------------------- |
|
383 // CAspProfileSelectionDialog::OfferKeyEventL |
|
384 // |
|
385 // ---------------------------------------------------------------------------- |
|
386 // |
|
387 TKeyResponse CAspProfileSelectionDialog::OfferKeyEventL(const TKeyEvent& aKeyEvent, |
|
388 TEventCode aType) |
|
389 { |
|
390 |
|
391 // catch listbox item "gain focus" here |
|
392 if (aType == EEventKeyUp) |
|
393 { |
|
394 UpdateCbaL(); |
|
395 return CAknDialog::OfferKeyEventL( aKeyEvent, aType); |
|
396 } |
|
397 |
|
398 if (aType == EEventKey) |
|
399 { |
|
400 switch (aKeyEvent.iCode) |
|
401 { |
|
402 case EKeyEnter: |
|
403 case EKeyOK: |
|
404 { |
|
405 HandleOKL(); |
|
406 return EKeyWasConsumed; |
|
407 } |
|
408 |
|
409 case EKeyEscape: // framework calls this when dialog must shut down |
|
410 { |
|
411 return CAknDialog::OfferKeyEventL(aKeyEvent, aType); |
|
412 } |
|
413 |
|
414 default: |
|
415 { |
|
416 break; |
|
417 } |
|
418 } |
|
419 } |
|
420 |
|
421 return CAknDialog::OfferKeyEventL( aKeyEvent, aType); |
|
422 } |
|
423 |
|
424 |
|
425 // ---------------------------------------------------------------------------- |
|
426 // CAspProfileSelectionDialog::HandleResourceChange |
|
427 // |
|
428 // ---------------------------------------------------------------------------- |
|
429 // |
|
430 void CAspProfileSelectionDialog::HandleResourceChange(TInt aType) |
|
431 { |
|
432 if (aType == KEikDynamicLayoutVariantSwitch) //Handle change in layout orientation |
|
433 { |
|
434 TRect mainPaneRect; |
|
435 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane, mainPaneRect); |
|
436 SetRect(mainPaneRect); |
|
437 iListBox->SetSize(mainPaneRect.Size()); |
|
438 CCoeControl::HandleResourceChange(aType); |
|
439 DrawDeferred(); |
|
440 return; |
|
441 } |
|
442 |
|
443 if (aType == KAknsMessageSkinChange) |
|
444 { |
|
445 TRAP_IGNORE(SetIconsL()); |
|
446 } |
|
447 |
|
448 CCoeControl::HandleResourceChange(aType); |
|
449 } |
|
450 |
|
451 |
|
452 //------------------------------------------------------------------------------ |
|
453 // CAspProfileSelectionDialog::HandleOKL |
|
454 // |
|
455 //------------------------------------------------------------------------------ |
|
456 // |
|
457 void CAspProfileSelectionDialog::HandleOKL() |
|
458 { |
|
459 if (iCommandSetId == R_ASP_CBA_OPTIONS_VIEW_CONTENT_BACK) |
|
460 { |
|
461 ShowContentListL(); |
|
462 return; |
|
463 } |
|
464 |
|
465 TInt index = iListBox->CurrentItemIndex(); |
|
466 if (index != KErrNotFound) |
|
467 { |
|
468 TAspProfileItem& item = iProfileList->Item(index); |
|
469 |
|
470 if (item.iProfileId != iProfileId) |
|
471 { |
|
472 iProfileId = item.iProfileId; // uselect |
|
473 UpdateListBoxL(); |
|
474 } |
|
475 } |
|
476 |
|
477 } |
|
478 |
|
479 |
|
480 // ---------------------------------------------------------------------------- |
|
481 // CAspProfileSelectionDialog::UpdateListBoxL |
|
482 // |
|
483 // Add settings headers into listbox. |
|
484 // ---------------------------------------------------------------------------- |
|
485 // |
|
486 void CAspProfileSelectionDialog::UpdateListBoxL() |
|
487 { |
|
488 _LIT(KFormat, "%d\t%S"); |
|
489 |
|
490 CDesCArray* arr = (CDesCArray*) iListBox->Model()->ItemTextArray(); |
|
491 arr->Reset(); |
|
492 |
|
493 TInt count = iProfileList->Count(); |
|
494 for (TInt i=0; i<count; i++ ) |
|
495 { |
|
496 TAspProfileItem& item = iProfileList->Item(i); |
|
497 |
|
498 TBuf<KBufSize> buf; |
|
499 |
|
500 if (item.iProfileId == iProfileId) |
|
501 { |
|
502 buf.Format(KFormat, 1, &item.iProfileName); |
|
503 } |
|
504 else |
|
505 { |
|
506 buf.Format(KFormat, 0, &item.iProfileName); |
|
507 } |
|
508 |
|
509 arr->AppendL(buf); |
|
510 } |
|
511 |
|
512 iListBox->HandleItemAdditionL(); |
|
513 } |
|
514 |
|
515 |
|
516 // ----------------------------------------------------------------------------- |
|
517 // CAspProfileSelectionDialog::UpdateCbaL |
|
518 // |
|
519 // ----------------------------------------------------------------------------- |
|
520 // |
|
521 void CAspProfileSelectionDialog::UpdateCbaL() |
|
522 { |
|
523 TInt index = iListBox->CurrentItemIndex(); |
|
524 if (index == KErrNotFound) |
|
525 { |
|
526 return; |
|
527 } |
|
528 |
|
529 TAspProfileItem& item = iProfileList->Item(index); |
|
530 CEikButtonGroupContainer& cba = ButtonGroupContainer(); |
|
531 |
|
532 if (item.iProfileId == iProfileId) |
|
533 { |
|
534 if (iCommandSetId != R_ASP_CBA_OPTIONS_VIEW_CONTENT_BACK) |
|
535 { |
|
536 cba.SetCommandSetL(R_ASP_CBA_OPTIONS_VIEW_CONTENT_BACK); |
|
537 cba.DrawDeferred(); |
|
538 iCommandSetId = R_ASP_CBA_OPTIONS_VIEW_CONTENT_BACK; |
|
539 } |
|
540 } |
|
541 else |
|
542 { |
|
543 if (iCommandSetId != R_ASP_CBA_OPTIONS_SELECT_BACK) |
|
544 { |
|
545 cba.SetCommandSetL(R_ASP_CBA_OPTIONS_SELECT_BACK); |
|
546 cba.DrawDeferred(); |
|
547 iCommandSetId = R_ASP_CBA_OPTIONS_SELECT_BACK; |
|
548 } |
|
549 } |
|
550 } |
|
551 |
|
552 |
|
553 // ---------------------------------------------------------------------------- |
|
554 // CAspProfileSelectionDialog::ShowContentListL |
|
555 // |
|
556 // ---------------------------------------------------------------------------- |
|
557 // |
|
558 void CAspProfileSelectionDialog::ShowContentListL() |
|
559 { |
|
560 TInt index = iListBox->CurrentItemIndex(); |
|
561 if (index == KErrNotFound) |
|
562 { |
|
563 return; |
|
564 } |
|
565 |
|
566 TAspProfileItem& item = iProfileList->Item(index); |
|
567 |
|
568 TAspParam param(iApplicationId, iSyncSession); |
|
569 CAspProfile* profile = CAspProfile::NewLC(param); |
|
570 |
|
571 profile->OpenL(item.iProfileId, CAspProfile::EOpenRead, |
|
572 CAspProfileList::EBasePropertiesOnly); |
|
573 iContentList->SetProfile(profile); |
|
574 TRAPD(err, iContentList->InitAllTasksL()); |
|
575 iContentList->SetProfile(NULL); |
|
576 User::LeaveIfError(err); |
|
577 CleanupStack::PopAndDestroy(profile); |
|
578 |
|
579 |
|
580 CDesCArray* arr = new (ELeave) CDesCArrayFlat(KDefaultArraySize); |
|
581 CleanupStack::PushL(arr); |
|
582 |
|
583 TInt count = iContentList->ProviderCount(); |
|
584 for (TInt i=0; i<count; i++) |
|
585 { |
|
586 TAspProviderItem& item = iContentList->ProviderItem(i); |
|
587 |
|
588 TInt index = iContentList->FindTaskIndexForProvider(item.iDataProviderId); |
|
589 if (index != KErrNotFound) |
|
590 { |
|
591 HBufC* hBuf = CAspResHandler::GetContentNameLC(item.iDataProviderId, |
|
592 item.iDisplayName); |
|
593 arr->AppendL(hBuf->Des()); |
|
594 CleanupStack::PopAndDestroy(hBuf); |
|
595 } |
|
596 } |
|
597 |
|
598 HBufC* hBuf = CAspResHandler::ReadLC(R_ASP_TITLE_AUTOMATIC_SYNC_CONTENT_LIST); |
|
599 |
|
600 TDialogUtil::ShowPopupDialogL(hBuf->Des(), arr); |
|
601 |
|
602 CleanupStack::PopAndDestroy(hBuf); |
|
603 CleanupStack::PopAndDestroy(arr); |
|
604 } |
|
605 |
|
606 |
|
607 |
|
608 // End of File |
|