phonebookui/Phonebook2/UIControls/src/CPbk2MergePhotoConflictDlg.cpp
branchRCL_3
changeset 3 04ab22b956c2
parent 0 e686773b3f54
child 14 81f8547efd4f
equal deleted inserted replaced
0:e686773b3f54 3:04ab22b956c2
    14 * Description: 
    14 * Description: 
    15 *       Provides Image conflict resolution dialog for Contact Merge command.
    15 *       Provides Image conflict resolution dialog for Contact Merge command.
    16 *
    16 *
    17 */
    17 */
    18 
    18 
       
    19 
       
    20 
       
    21 #include <eikclbd.h>
       
    22 #include <aknlayoutscalable_apps.cdl.h>
    19 #include <aknlists.h>
    23 #include <aknlists.h>
    20 #include <AknIconArray.h>
    24 #include <AknIconArray.h>
    21 #include <eikapp.h>
    25 #include <eikapp.h>
    22 #include <gulicon.h>
    26 #include <gulicon.h>
       
    27 #include <AknIconUtils.h>
    23 #include <StringLoader.h>
    28 #include <StringLoader.h>
    24 #include <aknnavide.h>
    29 #include <aknnavide.h>
    25 #include <akntitle.h>
    30 #include <akntitle.h>
       
    31 #include <avkon.mbg>
    26 #include <Pbk2UIControls.rsg>
    32 #include <Pbk2UIControls.rsg>
    27 #include <MPbk2MergeConflict.h>
    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>
    28 #include "CPbk2MergePhotoConflictDlg.h"
    42 #include "CPbk2MergePhotoConflictDlg.h"
    29 
    43 
    30 /// Unnamed namespace for local definitions
    44 /// Unnamed namespace for local definitions
    31 namespace {
    45 namespace {
    32 
    46 
    33 _LIT( KPictureRowFormat, "%d\t   %S\t\t" );
    47 _LIT( KPictureRowFormat, "%d\t   %S\t\t" );
    34 
    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 
    35 }
    60 }
    36 
    61 
    37 // -----------------------------------------------------------------------------
    62 // -----------------------------------------------------------------------------
    38 // CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg
    63 // CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg
    39 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    40 //
    65 //
    41 CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg( CFbsBitmap* aFirstImage,
    66 CPbk2MergePhotoConflictDlg::CPbk2MergePhotoConflictDlg( MVPbkBaseContact* aFirstContact,
    42                                                         CFbsBitmap* aSecondImage, 
    67                                                         MVPbkBaseContact* aSecondContact, 
    43                                                         TInt* aResult ):
    68                                                         TInt* aResult ):
    44         iFirstImage( aFirstImage ), iSecondImage( aSecondImage ), iSelectedItem( aResult )
    69         iFirstContact( aFirstContact ), iSecondContact( aSecondContact ), iSelectedItem( aResult )
    45     {
    70     {
    46     // No implementation required
    71     // No implementation required
    47     }
    72     }
    48 
    73 
    49 // -----------------------------------------------------------------------------
    74 // -----------------------------------------------------------------------------
    50 // CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg
    75 // CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg
    51 // -----------------------------------------------------------------------------
    76 // -----------------------------------------------------------------------------
    52 //
    77 //
    53 CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg()
    78 CPbk2MergePhotoConflictDlg::~CPbk2MergePhotoConflictDlg()
    54     {
    79     {
       
    80     StopWait();
       
    81     delete iWait;
       
    82     delete iImageOperationFirst;
       
    83     delete iImageOperationSecond;
       
    84     delete iImageManager;
       
    85     delete iFirstImage;
       
    86     delete iSecondImage;
    55     delete iNaviDecorator;
    87     delete iNaviDecorator;
    56     delete iSelectedString;
    88     delete iSelectedString;
    57     }
    89     }
    58 
    90 
    59 // -----------------------------------------------------------------------------
    91 // -----------------------------------------------------------------------------
    60 // CPbk2MergePhotoConflictDlg::NewL
    92 // CPbk2MergePhotoConflictDlg::NewL
    61 // -----------------------------------------------------------------------------
    93 // -----------------------------------------------------------------------------
    62 //
    94 //
    63 EXPORT_C CPbk2MergePhotoConflictDlg* CPbk2MergePhotoConflictDlg::NewL( CFbsBitmap* aFirstImage,
    95 EXPORT_C CPbk2MergePhotoConflictDlg* CPbk2MergePhotoConflictDlg::NewL( MVPbkBaseContact* aFirstContact,
    64                                                                        CFbsBitmap* aSecondImage, 
    96                                                                        MVPbkBaseContact* aSecondContact, 
    65                                                                        TInt* aResult )
    97                                                                        TInt* aResult )
    66     {
    98     {
    67     CPbk2MergePhotoConflictDlg* self = 
    99     CPbk2MergePhotoConflictDlg* self = 
    68         new (ELeave) CPbk2MergePhotoConflictDlg( aFirstImage, aSecondImage, aResult );
   100         new (ELeave) CPbk2MergePhotoConflictDlg( aFirstContact, aSecondContact, aResult );
    69     CleanupStack::PushL(self);
   101     CleanupStack::PushL(self);
    70     self->ConstructL();
   102     self->ConstructL();
    71     CleanupStack::Pop(); // self;
   103     CleanupStack::Pop(); // self;
    72     return self;
   104     return self;
    73     }
   105     }
    80     {
   112     {
    81     SetNaviPaneL();
   113     SetNaviPaneL();
    82     SetTitlePaneL( ETrue );
   114     SetTitlePaneL( ETrue );
    83     *iSelectedItem = EPbk2ConflictedFirst;
   115     *iSelectedItem = EPbk2ConflictedFirst;
    84     iSelectedString = StringLoader::LoadL( R_QTN_PHOB_TITLE_SELECTED );
   116     iSelectedString = StringLoader::LoadL( R_QTN_PHOB_TITLE_SELECTED );
       
   117     iContactManager = &Phonebook2::Pbk2AppUi()->ApplicationServices().ContactManager();
       
   118     iImageManager = CPbk2ImageManager::NewL( *iContactManager );
    85     CAknDialog::ConstructL( R_AVKON_MENUPANE_EMPTY );
   119     CAknDialog::ConstructL( R_AVKON_MENUPANE_EMPTY );
       
   120     iWait = new (ELeave) CActiveSchedulerWait();
    86     }
   121     }
    87 
   122 
    88 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
    89 // CPbk2MergePhotoConflictDlg::PreLayoutDynInitL
   124 // CPbk2MergePhotoConflictDlg::PreLayoutDynInitL
    90 // -----------------------------------------------------------------------------
   125 // -----------------------------------------------------------------------------
   100         eikCba->EnableItemSpecificSoftkey( EFalse );
   135         eikCba->EnableItemSpecificSoftkey( EFalse );
   101         }
   136         }
   102     
   137     
   103     iListBox = static_cast<CEikFormattedCellListBox*>( Control( 1 ) );
   138     iListBox = static_cast<CEikFormattedCellListBox*>( Control( 1 ) );
   104     
   139     
   105     SetIconsL();
       
   106     SetItemsL();
   140     SetItemsL();
   107     
   141     
   108     iListBox->CreateScrollBarFrameL( ETrue );
   142     iListBox->CreateScrollBarFrameL( ETrue );
   109     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
   143     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
   110             CEikScrollBarFrame::EOff,
   144             CEikScrollBarFrame::EOff,
   149         SwitchRadioButtonL();
   183         SwitchRadioButtonL();
   150         }
   184         }
   151     return result;
   185     return result;
   152     }
   186     }
   153 
   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 
   154 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   155 // CPbk2MergePhotoConflictDlg::HandleListBoxEventL
   202 // CPbk2MergePhotoConflictDlg::HandleListBoxEventL
   156 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------
   157 //
   204 //
   158 void CPbk2MergePhotoConflictDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
   205 void CPbk2MergePhotoConflictDlg::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType )
   171 // Sets icons for the listbox.
   218 // Sets icons for the listbox.
   172 // -----------------------------------------------------------------------------
   219 // -----------------------------------------------------------------------------
   173 //
   220 //
   174 void CPbk2MergePhotoConflictDlg::SetIconsL()
   221 void CPbk2MergePhotoConflictDlg::SetIconsL()
   175     {
   222     {
   176     if ( iFirstImage == NULL || iSecondImage == NULL )
       
   177         {
       
   178         User::Leave( KErrArgument );
       
   179         }
       
   180     
       
   181     CArrayPtr<CGulIcon>* iconList = new (ELeave) CAknIconArray( 2 );
   223     CArrayPtr<CGulIcon>* iconList = new (ELeave) CAknIconArray( 2 );
   182     CleanupStack::PushL( iconList );
   224     CleanupStack::PushL( iconList );
   183 
   225   
   184     CGulIcon* first = CGulIcon::NewL( iFirstImage );
   226     CGulIcon* first = NULL;
   185     first->SetBitmapsOwnedExternally( ETrue );
   227     if ( iFirstImage )
       
   228         {
       
   229         first = CGulIcon::NewL( iFirstImage );
       
   230         first->SetBitmapsOwnedExternally( ETrue );
       
   231         }
       
   232     else
       
   233         {
       
   234         first = CreateEmptyIconL();
       
   235         }  
   186     CleanupStack::PushL( first );
   236     CleanupStack::PushL( first );
   187     iconList->AppendL( first );
   237     iconList->AppendL( first );
   188     CleanupStack::Pop( first );
   238     CleanupStack::Pop( first );
   189     
   239     
   190     CGulIcon* second = CGulIcon::NewL( iSecondImage );
   240     CGulIcon* second = NULL;
   191     second->SetBitmapsOwnedExternally( ETrue );
   241     if ( iSecondImage )
       
   242         {
       
   243         second = CGulIcon::NewL( iSecondImage );
       
   244         second->SetBitmapsOwnedExternally( ETrue );
       
   245         
       
   246         }
       
   247     else
       
   248         {
       
   249         second = CreateEmptyIconL();
       
   250         }
   192     CleanupStack::PushL( second );
   251     CleanupStack::PushL( second );
   193     iconList->AppendL( second );
   252     iconList->AppendL( second );
   194     CleanupStack::Pop( second );
   253     CleanupStack::Pop( second );
   195     
   254     
   196     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconList );
   255     iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconList );
   296             {
   355             {
   297             titlePane->SetTextToDefaultL();
   356             titlePane->SetTextToDefaultL();
   298             }
   357             }
   299         }
   358         }
   300     }
   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                 &params, aContact, *thumbType, *this ); 
       
   394                 }
       
   395             else if ( &aContact == iSecondContact )
       
   396                 {
       
   397                 iImageOperationSecond = iImageManager->GetImageAsyncL( 
       
   398                 &params, 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     }