|
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: |
|
15 * Provides Image conflict resolution dialog for Contact Merge command. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #include <eikclbd.h> |
|
22 #include <aknlayoutscalable_apps.cdl.h> |
|
23 #include <aknlists.h> |
|
24 #include <AknIconArray.h> |
|
25 #include <eikapp.h> |
|
26 #include <gulicon.h> |
|
27 #include <AknIconUtils.h> |
|
28 #include <StringLoader.h> |
|
29 #include <aknnavide.h> |
|
30 #include <akntitle.h> |
|
31 #include <avkon.mbg> |
|
32 #include <Pbk2UIControls.rsg> |
|
33 #include <MPbk2MergeConflict.h> |
|
34 #include <CPbk2ImageManager.h> |
|
35 #include <TPbk2ImageManagerParams.h> |
|
36 #include <MVPbkBaseContact.h> |
|
37 #include <MVPbkFieldType.h> |
|
38 #include <VPbkEng.rsg> |
|
39 #include <MPbk2AppUi.h> |
|
40 #include <MPbk2ApplicationServices.h> |
|
41 #include <CVPbkContactManager.h> |
|
42 #include "CPbk2MergePhotoConflictDlg.h" |
|
43 |
|
44 /// Unnamed namespace for local definitions |
|
45 namespace { |
|
46 |
|
47 _LIT( KPictureRowFormat, "%d\t %S\t\t" ); |
|
48 |
|
49 inline CGulIcon* CreateEmptyIconL() |
|
50 { |
|
51 CFbsBitmap* image = NULL; |
|
52 CFbsBitmap* mask = NULL; |
|
53 AknIconUtils::CreateIconL( image, mask, |
|
54 AknIconUtils::AvkonIconFileName(), |
|
55 EMbmAvkonQgn_prop_empty, |
|
56 EMbmAvkonQgn_prop_empty_mask ); |
|
57 return CGulIcon::NewL( image, mask ); |
|
58 } |
|
59 |
|
60 } |
|
61 |
|
62 // ----------------------------------------------------------------------------- |
|
63 // CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg |
|
64 // ----------------------------------------------------------------------------- |
|
65 // |
|
66 CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg( MVPbkBaseContact* aFirstContact, |
|
67 MVPbkBaseContact* aSecondContact, |
|
68 TInt* aResult ): |
|
69 iFirstContact( aFirstContact ), iSecondContact( aSecondContact ), iSelectedItem( aResult ) |
|
70 { |
|
71 // No implementation required |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg() |
|
79 { |
|
80 StopWait(); |
|
81 delete iWait; |
|
82 delete iImageOperationFirst; |
|
83 delete iImageOperationSecond; |
|
84 delete iImageManager; |
|
85 delete iFirstImage; |
|
86 delete iSecondImage; |
|
87 delete iNaviDecorator; |
|
88 delete iSelectedString; |
|
89 } |
|
90 |
|
91 // ----------------------------------------------------------------------------- |
|
92 // CPbk2MergePhotoConflictDlg::NewL |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 EXPORT_C CPbk2MergePhotoConflictDlg* CPbk2MergePhotoConflictDlg::NewL( MVPbkBaseContact* aFirstContact, |
|
96 MVPbkBaseContact* aSecondContact, |
|
97 TInt* aResult ) |
|
98 { |
|
99 CPbk2MergePhotoConflictDlg* self = |
|
100 new (ELeave) CPbk2MergePhotoConflictDlg( aFirstContact, aSecondContact, aResult ); |
|
101 CleanupStack::PushL(self); |
|
102 self->ConstructL(); |
|
103 CleanupStack::Pop(); // self; |
|
104 return self; |
|
105 } |
|
106 |
|
107 // ----------------------------------------------------------------------------- |
|
108 // CPbk2MergePhotoConflictDlg::ConstructL |
|
109 // ----------------------------------------------------------------------------- |
|
110 // |
|
111 void CPbk2MergePhotoConflictDlg::ConstructL() |
|
112 { |
|
113 SetNaviPaneL(); |
|
114 SetTitlePaneL( ETrue ); |
|
115 *iSelectedItem = EPbk2ConflictedFirst; |
|
116 iSelectedString = StringLoader::LoadL( R_QTN_PHOB_TITLE_SELECTED ); |
|
117 iContactManager = &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager(); |
|
118 iImageManager = CPbk2ImageManager::NewL( *iContactManager ); |
|
119 CAknDialog::ConstructL( R_AVKON_MENUPANE_EMPTY ); |
|
120 iWait = new (ELeave) CActiveSchedulerWait(); |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CPbk2MergePhotoConflictDlg::PreLayoutDynInitL |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 void CPbk2MergePhotoConflictDlg::PreLayoutDynInitL() |
|
128 { |
|
129 CAknDialog::PreLayoutDynInitL(); |
|
130 |
|
131 CEikButtonGroupContainer& cba = ButtonGroupContainer(); |
|
132 CEikCba* eikCba = static_cast<CEikCba*>( cba.ButtonGroup() ); |
|
133 if( eikCba ) |
|
134 { |
|
135 eikCba->EnableItemSpecificSoftkey( EFalse ); |
|
136 } |
|
137 |
|
138 iListBox = static_cast<CEikFormattedCellListBox*>( Control( 1 ) ); |
|
139 |
|
140 SetItemsL(); |
|
141 |
|
142 iListBox->CreateScrollBarFrameL( ETrue ); |
|
143 iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( |
|
144 CEikScrollBarFrame::EOff, |
|
145 CEikScrollBarFrame::EAuto ); |
|
146 |
|
147 iListBox->HandleItemAdditionL(); |
|
148 iListBox->SetListBoxObserver( this ); // MEikListBoxObserver |
|
149 } |
|
150 |
|
151 // ----------------------------------------------------------------------------- |
|
152 // CPbk2MergePhotoConflictDlg::OkToExitL |
|
153 // ----------------------------------------------------------------------------- |
|
154 // |
|
155 TBool CPbk2MergePhotoConflictDlg::OkToExitL( TInt aButtonId ) |
|
156 { |
|
157 if ( aButtonId == EAknSoftkeyDone || aButtonId == EAknSoftkeyCancel ) |
|
158 { |
|
159 TRAP_IGNORE( SetTitlePaneL( EFalse ) ); |
|
160 return ETrue; |
|
161 } |
|
162 return EFalse; |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CPbk2MergePhotoConflictDlg::OfferKeyEventL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 TKeyResponse CPbk2MergePhotoConflictDlg::OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
170 { |
|
171 TKeyResponse result = EKeyWasNotConsumed; |
|
172 |
|
173 if ( aKeyEvent.iCode == EKeyEscape ) |
|
174 { |
|
175 result = CEikDialog::OfferKeyEventL( aKeyEvent, aType ); |
|
176 return result; |
|
177 } |
|
178 |
|
179 result = iListBox->OfferKeyEventL( aKeyEvent, aType ); |
|
180 |
|
181 if ( aType == EEventKeyDown && aKeyEvent.iScanCode == EStdKeyDevice3 ) |
|
182 { |
|
183 SwitchRadioButtonL(); |
|
184 } |
|
185 return result; |
|
186 } |
|
187 |
|
188 void CPbk2MergePhotoConflictDlg::SizeChanged() |
|
189 { |
|
190 CAknDialog::SizeChanged(); |
|
191 TSize size = iListBox->ItemDrawer()->FormattedCellData()->SubCellSize(0); |
|
192 |
|
193 if ( iSize != size ) |
|
194 { |
|
195 iSize = size; |
|
196 TRAP_IGNORE( InitBitmapAsyncL( *iFirstContact ) ); |
|
197 StartWait(); |
|
198 } |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CPbk2MergePhotoConflictDlg::HandleListBoxEventL |
|
203 // ----------------------------------------------------------------------------- |
|
204 // |
|
205 void CPbk2MergePhotoConflictDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType ) |
|
206 { |
|
207 if( AknLayoutUtils::PenEnabled() ) |
|
208 { |
|
209 if ( aEventType == EEventItemSingleClicked ) |
|
210 { |
|
211 SwitchRadioButtonL(); |
|
212 } |
|
213 } |
|
214 } |
|
215 |
|
216 // ----------------------------------------------------------------------------- |
|
217 // CPbk2MergePhotoConflictDlg::SetIconsL |
|
218 // Sets icons for the listbox. |
|
219 // ----------------------------------------------------------------------------- |
|
220 // |
|
221 void CPbk2MergePhotoConflictDlg::SetIconsL() |
|
222 { |
|
223 CArrayPtr<CGulIcon>* iconList = new (ELeave) CAknIconArray( 2 ); |
|
224 CleanupStack::PushL( iconList ); |
|
225 |
|
226 CGulIcon* first = NULL; |
|
227 if ( iFirstImage ) |
|
228 { |
|
229 first = CGulIcon::NewL( iFirstImage ); |
|
230 first->SetBitmapsOwnedExternally( ETrue ); |
|
231 } |
|
232 else |
|
233 { |
|
234 first = CreateEmptyIconL(); |
|
235 } |
|
236 CleanupStack::PushL( first ); |
|
237 iconList->AppendL( first ); |
|
238 CleanupStack::Pop( first ); |
|
239 |
|
240 CGulIcon* second = NULL; |
|
241 if ( iSecondImage ) |
|
242 { |
|
243 second = CGulIcon::NewL( iSecondImage ); |
|
244 second->SetBitmapsOwnedExternally( ETrue ); |
|
245 |
|
246 } |
|
247 else |
|
248 { |
|
249 second = CreateEmptyIconL(); |
|
250 } |
|
251 CleanupStack::PushL( second ); |
|
252 iconList->AppendL( second ); |
|
253 CleanupStack::Pop( second ); |
|
254 |
|
255 iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconList ); |
|
256 CleanupStack::Pop( iconList ); |
|
257 } |
|
258 |
|
259 // ----------------------------------------------------------------------------- |
|
260 // CPbk2MergePhotoConflictDlg::SetItemsL |
|
261 // Sets items to the listbox. |
|
262 // ----------------------------------------------------------------------------- |
|
263 // |
|
264 void CPbk2MergePhotoConflictDlg::SetItemsL() |
|
265 { |
|
266 CDesCArray* itemArray = new ( ELeave ) CDesCArrayFlat( 2 ); |
|
267 |
|
268 RBuf listItem; |
|
269 listItem.Create( KPictureRowFormat().Length() + iSelectedString->Length() ); |
|
270 listItem.Format( KPictureRowFormat, EPbk2ConflictedFirst, iSelectedString ); |
|
271 itemArray->AppendL( listItem ); |
|
272 listItem.Close(); |
|
273 |
|
274 listItem.Create( KPictureRowFormat().Length() + iSelectedString->Length() ); |
|
275 listItem.Format( KPictureRowFormat, EPbk2ConflictedSecond, &KNullDesC ); |
|
276 itemArray->AppendL( listItem ); |
|
277 listItem.Close(); |
|
278 |
|
279 iListBox->Model()->SetItemTextArray( itemArray ); |
|
280 iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray ); |
|
281 |
|
282 iListBox->HandleItemAdditionL(); |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CPbk2MergePhotoConflictDlg::SwitchRadioButtonL |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 void CPbk2MergePhotoConflictDlg::SwitchRadioButtonL() |
|
290 { |
|
291 TInt itemIndex = iListBox->CurrentItemIndex(); |
|
292 if ( *iSelectedItem != itemIndex) |
|
293 { |
|
294 CDesCArray* itemArray = static_cast<CDesC16ArrayFlat*>( iListBox->Model()->ItemTextArray() ); |
|
295 |
|
296 // deselect item |
|
297 RBuf listItem; |
|
298 listItem.Create( KPictureRowFormat().Length() ); |
|
299 listItem.Format( KPictureRowFormat, *iSelectedItem , &KNullDesC ); |
|
300 itemArray->Delete( *iSelectedItem ); |
|
301 itemArray->InsertL( *iSelectedItem, listItem ); |
|
302 listItem.Close(); |
|
303 |
|
304 // select item |
|
305 listItem.Create( KPictureRowFormat().Length() + iSelectedString->Length() ); |
|
306 listItem.Format( KPictureRowFormat, itemIndex, iSelectedString ); |
|
307 itemArray->Delete( itemIndex ); |
|
308 itemArray->InsertL( itemIndex, listItem ); |
|
309 listItem.Close(); |
|
310 |
|
311 *iSelectedItem = itemIndex; |
|
312 iListBox->DrawDeferred(); |
|
313 } |
|
314 } |
|
315 |
|
316 // ----------------------------------------------------------------------------- |
|
317 // CPbk2MergeConflictsDlg::SetNaviPaneL |
|
318 // ----------------------------------------------------------------------------- |
|
319 // |
|
320 void CPbk2MergePhotoConflictDlg::SetNaviPaneL() |
|
321 { |
|
322 CEikStatusPane* statusPane = iAvkonAppUi->StatusPane(); |
|
323 if ( statusPane && statusPane->PaneCapabilities( TUid::Uid( EEikStatusPaneUidNavi ) ).IsPresent() ) |
|
324 { |
|
325 CAknNavigationControlContainer* naviPane = static_cast<CAknNavigationControlContainer*> |
|
326 ( statusPane->ControlL ( TUid::Uid( EEikStatusPaneUidNavi ) ) ); |
|
327 |
|
328 HBufC* naviLabel = StringLoader::LoadLC( R_QTN_PHOB_TITLE_SELECT_IMAGE ); |
|
329 |
|
330 iNaviDecorator = naviPane->CreateNavigationLabelL( *naviLabel ); |
|
331 CleanupStack::PopAndDestroy( naviLabel ); |
|
332 naviPane->PushL( *iNaviDecorator ); |
|
333 } |
|
334 } |
|
335 |
|
336 // ----------------------------------------------------------------------------- |
|
337 // CPbk2MergeConflictsDlg::SetTitlePaneL |
|
338 // ----------------------------------------------------------------------------- |
|
339 // |
|
340 void CPbk2MergePhotoConflictDlg::SetTitlePaneL( TBool aCustom ) |
|
341 { |
|
342 CEikStatusPane* statusPane = iAvkonAppUi->StatusPane(); |
|
343 if ( statusPane && statusPane->PaneCapabilities( TUid::Uid( EEikStatusPaneUidTitle ) ).IsPresent() ) |
|
344 { |
|
345 CAknTitlePane* titlePane = static_cast<CAknTitlePane*> |
|
346 ( statusPane->ControlL ( TUid::Uid( EEikStatusPaneUidTitle ) ) ); |
|
347 |
|
348 if ( aCustom ) |
|
349 { |
|
350 HBufC* title = StringLoader::LoadLC( R_QTN_PHOB_TITLE_CONFLICT_RESOLUTION ); |
|
351 titlePane->SetTextL( *title ); |
|
352 CleanupStack::PopAndDestroy( title ); |
|
353 } |
|
354 else |
|
355 { |
|
356 titlePane->SetTextToDefaultL(); |
|
357 } |
|
358 } |
|
359 } |
|
360 |
|
361 // -------------------------------------------------------------------------- |
|
362 // CPbk2MergePhotoConflictDlg::InitBitmapAsyncL |
|
363 // -------------------------------------------------------------------------- |
|
364 // |
|
365 void CPbk2MergePhotoConflictDlg::InitBitmapAsyncL( MVPbkBaseContact& aContact ) |
|
366 { |
|
367 // cancel previous operations |
|
368 if ( &aContact == iFirstContact ) |
|
369 { |
|
370 delete iImageOperationFirst; |
|
371 iImageOperationFirst = NULL; |
|
372 } |
|
373 |
|
374 const MVPbkFieldType* thumbType = iContactManager->FieldTypes().Find( |
|
375 R_VPBK_FIELD_TYPE_THUMBNAILPIC ); |
|
376 |
|
377 if( thumbType ) |
|
378 { |
|
379 if( iImageManager->HasImage( aContact, *thumbType ) ) |
|
380 { |
|
381 // Define parameters for thumbnail |
|
382 TPbk2ImageManagerParams params; |
|
383 TInt useCropping = 0x0008; |
|
384 |
|
385 params.iSize = iSize; |
|
386 params.iFlags = TPbk2ImageManagerParams::EScaleImage | |
|
387 TPbk2ImageManagerParams::EKeepAspectRatio | |
|
388 useCropping; //CROP IMAGE |
|
389 // contact has image. load it. |
|
390 if ( &aContact == iFirstContact ) |
|
391 { |
|
392 iImageOperationFirst = iImageManager->GetImageAsyncL( |
|
393 ¶ms, aContact, *thumbType, *this ); |
|
394 } |
|
395 else if ( &aContact == iSecondContact ) |
|
396 { |
|
397 iImageOperationSecond = iImageManager->GetImageAsyncL( |
|
398 ¶ms, aContact, *thumbType, *this ); |
|
399 } |
|
400 } |
|
401 } |
|
402 } |
|
403 |
|
404 // -------------------------------------------------------------------------- |
|
405 // CPbk2MergePhotoConflictDlg::StopWait |
|
406 // -------------------------------------------------------------------------- |
|
407 // |
|
408 void CPbk2MergePhotoConflictDlg::StopWait() |
|
409 { |
|
410 if ( iWait->IsStarted() ) |
|
411 { |
|
412 iWait->AsyncStop(); |
|
413 } |
|
414 } |
|
415 |
|
416 // -------------------------------------------------------------------------- |
|
417 // CPbk2MergePhotoConflictDlg::StartWait |
|
418 // -------------------------------------------------------------------------- |
|
419 // |
|
420 void CPbk2MergePhotoConflictDlg::StartWait() |
|
421 { |
|
422 if ( !iWait->IsStarted() ) |
|
423 { |
|
424 iWait->Start(); |
|
425 } |
|
426 } |
|
427 |
|
428 // -------------------------------------------------------------------------- |
|
429 // CPbk2MergePhotoConflictDlg::Pbk2ImageGetComplete |
|
430 // -------------------------------------------------------------------------- |
|
431 // |
|
432 void CPbk2MergePhotoConflictDlg::Pbk2ImageGetComplete( |
|
433 MPbk2ImageOperation& aOperation, |
|
434 CFbsBitmap* aBitmap ) |
|
435 { |
|
436 if ( &aOperation == iImageOperationFirst ) |
|
437 { |
|
438 delete iImageOperationFirst; |
|
439 iImageOperationFirst = NULL; |
|
440 delete iFirstImage; |
|
441 iFirstImage = aBitmap; |
|
442 |
|
443 TRAPD( err, InitBitmapAsyncL( *iSecondContact ) ); |
|
444 |
|
445 if ( err != KErrNone ) |
|
446 { |
|
447 StopWait(); |
|
448 TRAP_IGNORE( SetIconsL() ); |
|
449 } |
|
450 else |
|
451 { |
|
452 StartWait(); |
|
453 } |
|
454 } |
|
455 |
|
456 else if ( &aOperation == iImageOperationSecond ) |
|
457 { |
|
458 delete iImageOperationSecond; |
|
459 iImageOperationSecond = NULL; |
|
460 delete iSecondImage; |
|
461 iSecondImage = aBitmap; |
|
462 TRAP_IGNORE( SetIconsL() ); |
|
463 |
|
464 StopWait(); |
|
465 } |
|
466 } |
|
467 |
|
468 // -------------------------------------------------------------------------- |
|
469 // CPbk2MergePhotoConflictDlg::Pbk2ImageGetFailed |
|
470 // -------------------------------------------------------------------------- |
|
471 // |
|
472 void CPbk2MergePhotoConflictDlg::Pbk2ImageGetFailed( |
|
473 MPbk2ImageOperation& aOperation, |
|
474 TInt /*aError*/ ) |
|
475 { |
|
476 StopWait(); |
|
477 |
|
478 if ( &aOperation == iImageOperationFirst ) |
|
479 { |
|
480 delete iImageOperationFirst; |
|
481 iImageOperationFirst = NULL; |
|
482 } |
|
483 else if ( &aOperation == iImageOperationSecond ) |
|
484 { |
|
485 delete iImageOperationSecond; |
|
486 iImageOperationSecond = NULL; |
|
487 } |
|
488 } |