voipplugins/accountcreationplugin/src/acpproviderlistcontainer.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2007-2008 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:  Implements CAcpProviderListContainer methods
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <aknlists.h>
       
    20 #include <pathinfo.h>
       
    21 #include <AknsUtils.h>
       
    22 #include <acpicons.mbg>
       
    23 #include <AknIconArray.h>
       
    24 #include <StringLoader.h>
       
    25 #include <accountcreationplugin.rsg>
       
    26 #include <data_caging_path_literals.hrh>
       
    27 #include <imageconversion.h>
       
    28 #include <fbs.h>
       
    29 #include <gulicon.h>
       
    30 #include <AknIconUtils.h>
       
    31 #include <eikclbd.h>
       
    32 
       
    33 #include "acpcontroller.h"
       
    34 #include "acpproviderlistcontainer.h"
       
    35 #include "accountcreationpluginlogger.h"
       
    36 #include "accountcreationpluginconstants.h"
       
    37 
       
    38 
       
    39 const TInt KComponentControlCount = 1;
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CAcpProviderListContainer::CAcpProviderListContainer
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 CAcpProviderListContainer::CAcpProviderListContainer( 
       
    46     CAcpController& aController )
       
    47     : iController( aController )
       
    48     {
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CAcpProviderListContainer::ConstructL
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 void CAcpProviderListContainer::ConstructL( const TRect& aRect )
       
    56     {
       
    57     ACPLOG( "CAcpProviderListContainer::ConstructL begin" );
       
    58     
       
    59     CreateWindowL();
       
    60     ConstructListBoxL();
       
    61     SetRect( aRect );
       
    62     ActivateL();
       
    63     
       
    64     ACPLOG( "CAcpProviderListContainer::ConstructL end" );
       
    65     }
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CAcpProviderListContainer::NewL
       
    69 // ---------------------------------------------------------------------------
       
    70 //      
       
    71 CAcpProviderListContainer* CAcpProviderListContainer::NewL( 
       
    72     CAcpController& aController,
       
    73     const TRect& aRect )
       
    74     {    
       
    75     CAcpProviderListContainer* self = 
       
    76         CAcpProviderListContainer::NewLC( aController, aRect );
       
    77     CleanupStack::Pop( self );
       
    78     return self;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CAcpProviderListContainer::NewLC
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CAcpProviderListContainer* CAcpProviderListContainer::NewLC(
       
    86     CAcpController& aController,
       
    87     const TRect& aRect )
       
    88     {    
       
    89     CAcpProviderListContainer* self = 
       
    90         new ( ELeave ) CAcpProviderListContainer( aController );
       
    91     CleanupStack::PushL( self );
       
    92     self->ConstructL( aRect );
       
    93     return self;
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------------------------
       
    97 // CAcpProviderListContainer::~CAcpProviderListContainer
       
    98 // ---------------------------------------------------------------------------
       
    99 //
       
   100 CAcpProviderListContainer::~CAcpProviderListContainer()
       
   101     {
       
   102     ACPLOG( "CAcpProviderListContainer::~CAcpProviderListContainer begin" );
       
   103     delete iListBox;
       
   104     ACPLOG( "CAcpProviderListContainer::~CAcpProviderListContainer end" );
       
   105     }
       
   106 
       
   107 // ---------------------------------------------------------------------------
       
   108 // CAcpProviderListContainer::AddProvidersToListboxL
       
   109 // Adds and updates listbox with providers.
       
   110 // ---------------------------------------------------------------------------
       
   111 //
       
   112 void CAcpProviderListContainer::AddProvidersToListboxL( )
       
   113     {
       
   114     ACPLOG( "CAcpProviderListContainer::AddProvidersToListboxL begin" );
       
   115 
       
   116     CTextListBoxModel* model = iListBox->Model();
       
   117     MDesCArray* textArray = model->ItemTextArray();
       
   118     CDesCArray* listBoxItems = static_cast<CDesCArray*>( textArray );
       
   119     
       
   120     if ( !listBoxItems->Count() )
       
   121         {
       
   122         TInt count = iController.CountOfProviders(); // Amount of provider.
       
   123     
       
   124         LoadProviderIconsL( count ); // Load icons of providers.
       
   125     
       
   126         for ( TInt i = 0; i < count; i++ )
       
   127             {
       
   128             // Entry for listbox.
       
   129             TBuf<KMaxSettingLength> listBoxItemText( KNullDesC ); 
       
   130             // Get provider name for adding it to the list later on.
       
   131             TPtrC namePtr = iController.ProviderNameFromIndexL( i );
       
   132             // Formats the listbox entry with the index and the provider name.  
       
   133             listBoxItemText.Format( KListFormat, i,&namePtr );
       
   134             // Add the entry to the list.
       
   135             listBoxItems->AppendL( listBoxItemText );
       
   136             }
       
   137     
       
   138         iListBox->HandleItemAdditionL();
       
   139         iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   140         }
       
   141 
       
   142     ACPLOG( "CAcpProviderListContainer::AddProvidersToListboxL end" );
       
   143 
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CAcpProviderListContainer::ListBox
       
   148 // Returns handle to the listbox.
       
   149 // ---------------------------------------------------------------------------
       
   150 //    
       
   151 CAknSingleLargeStyleListBox* CAcpProviderListContainer::ListBox()
       
   152     {
       
   153     return iListBox;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CAcpProviderListContainer::CurrentItemIndex
       
   158 // Returns index of selected listbox item. 
       
   159 // ---------------------------------------------------------------------------
       
   160 //
       
   161 TInt CAcpProviderListContainer::CurrentItemIndex() const
       
   162     {
       
   163     return iListBox->CurrentItemIndex();
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CAcpProviderListContainer::LoadDefaultIconsL
       
   168 // Loads default icons.
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 void CAcpProviderListContainer::LoadProviderIconsL( TInt aCount )
       
   172     {
       
   173     ACPLOG( "CAcpProviderListContainer::LoadProviderIconsL begin" );
       
   174 
       
   175     if ( aCount > 0 )
       
   176         {
       
   177         // Delete previous icon array.
       
   178         CArrayPtr<CGulIcon>* oldArray = iListBox->ItemDrawer()->ColumnData()->
       
   179             IconArray();
       
   180         if ( oldArray )
       
   181             {
       
   182             iListBox->ItemDrawer()->ColumnData()->SetIconArray( NULL );
       
   183             delete oldArray;
       
   184             }
       
   185         
       
   186         // Create a new icon array.
       
   187         CAknIconArray* iconArray = new( ELeave ) CAknIconArray( aCount );
       
   188 
       
   189         for ( TInt i = 0; i < aCount; i++ )
       
   190             {
       
   191             // Try to get bitmap and mask for provider.
       
   192             CFbsBitmap* bitmap( NULL );
       
   193             CFbsBitmap* mask( NULL );
       
   194             
       
   195             iController.ProviderBitmapsFromIndexL( i, bitmap, mask );
       
   196  
       
   197             if ( !bitmap ) // Mask can be NULL.
       
   198                 {
       
   199                 // Default icon.
       
   200                 LoadDefaultIconsL( iconArray );
       
   201                 }
       
   202             else
       
   203                 {
       
   204                 // Provider icon.
       
   205                 CGulIcon* providerIcon = CGulIcon::NewL( bitmap, mask );
       
   206 
       
   207                 // Owned by provider.
       
   208                 providerIcon->SetBitmapsOwnedExternally( ETrue );
       
   209 
       
   210                 CleanupStack::PushL( providerIcon );
       
   211                 // Insert into icon array.
       
   212                 iconArray->AppendL( providerIcon );
       
   213                 CleanupStack::Pop( providerIcon );
       
   214                 }
       
   215             }
       
   216 
       
   217         // Set an icon array to the listbox.
       
   218         iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   219         }
       
   220 
       
   221     ACPLOG( "CAcpProviderListContainer::LoadProviderIconsL end" );
       
   222     }
       
   223 
       
   224 // ---------------------------------------------------------------------------
       
   225 // CAcpProviderListContainer::ResetListBox
       
   226 // Resets the listbox.
       
   227 // ---------------------------------------------------------------------------
       
   228 //
       
   229 void CAcpProviderListContainer::ResetListBox()
       
   230     {
       
   231     ACPLOG( "CAcpProviderListContainer::ResetListBox begin" );
       
   232     
       
   233     CDesCArrayFlat* array = static_cast<CDesCArrayFlat*>(
       
   234         iListBox->Model()->ItemTextArray() );
       
   235     
       
   236     if ( array )
       
   237         {
       
   238         array->Reset();
       
   239         }
       
   240     
       
   241     iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   242     
       
   243     ACPLOG( "CAcpProviderListContainer::ResetListBox end" );
       
   244     }
       
   245 
       
   246 // ---------------------------------------------------------------------------
       
   247 // CAcpProviderListContainer::ConstructListBoxL
       
   248 // Creates listbox item for provider list items.
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 void CAcpProviderListContainer::ConstructListBoxL()
       
   252     {
       
   253     ACPLOG( "CAcpProviderListContainer::ConstructListBoxL begin" );
       
   254 
       
   255     // Create listbox and array for listbox items.
       
   256     iListBox = new( ELeave ) CAknSingleLargeStyleListBox;
       
   257     iListBox->SetContainerWindowL( *this );
       
   258     iListBox->ConstructL( this, EAknGenericListBoxFlags );    
       
   259     iListBox->CreateScrollBarFrameL( ETrue );
       
   260     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   261         CEikScrollBarFrame::EOff, 
       
   262         CEikScrollBarFrame::EAuto );
       
   263     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   264 
       
   265     CDesCArrayFlat* array = new ( ELeave ) CDesCArrayFlat( KArrayGranuality );
       
   266     iListBox->Model()->SetItemTextArray( array );
       
   267 
       
   268     // Set listbox background data when there are no providers available.
       
   269     HBufC* empty = StringLoader::LoadLC( R_ACP_PROVIDER_LIST_NO_PROVIDERS );
       
   270     iListBox->View()->SetListEmptyTextL( *empty );
       
   271     CleanupStack::PopAndDestroy( empty );
       
   272 
       
   273     ACPLOG( "CAcpProviderListContainer::ConstructListBoxL end" );
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CAcpProviderListContainer::LoadDefaultIconsL
       
   278 // Loads default icons.
       
   279 // ---------------------------------------------------------------------------
       
   280 //
       
   281 void CAcpProviderListContainer::LoadDefaultIconsL( 
       
   282     CArrayPtr<CGulIcon>* aIconArray )
       
   283     {
       
   284     ACPLOG( "CAcpProviderListContainer::LoadDefaultIconsL begin" );
       
   285 
       
   286     // This when going to ROM (PhoneMemoryRootPath is used only for testing).
       
   287     TFileName fileName = 
       
   288         TParsePtrC( PathInfo::RomRootPath() ).Drive();
       
   289     fileName.Append( KDC_APP_BITMAP_DIR );
       
   290     fileName.Append( KIconFileName );
       
   291 
       
   292     // Just one icon for providers which does not have own icon.
       
   293     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   294 
       
   295     CGulIcon* defaultIcon( NULL );
       
   296     TRAPD( err, defaultIcon = AknsUtils::CreateGulIconL( 
       
   297         skinInstance, 
       
   298         KAknsIIDDefault,
       
   299         fileName, 
       
   300         EMbmAcpiconsQgn_prop_set_conn_voip, 
       
   301         EMbmAcpiconsQgn_prop_set_conn_voip ) );
       
   302 
       
   303     if ( KErrNone != err )
       
   304         {
       
   305         ACPLOG2( "CreateGulIconL error: %d", err );
       
   306         }
       
   307 
       
   308     CleanupStack::PushL( defaultIcon );
       
   309     aIconArray->AppendL( defaultIcon );
       
   310     CleanupStack::Pop( defaultIcon );
       
   311 
       
   312     ACPLOG( "CAcpProviderListContainer::LoadDefaultIconsL end");
       
   313     }
       
   314 
       
   315 // ---------------------------------------------------------------------------
       
   316 // CAcpProviderListContainer::ComponentControl
       
   317 // From class CoeControl
       
   318 // ---------------------------------------------------------------------------
       
   319 //
       
   320 CCoeControl* CAcpProviderListContainer::ComponentControl( 
       
   321     TInt /*aIndex*/ ) const
       
   322     {
       
   323     return iListBox;
       
   324     }
       
   325 
       
   326 // ---------------------------------------------------------------------------
       
   327 // From class CoeControl
       
   328 // CAcpProviderListContainer::OfferKeyEventL
       
   329 // ---------------------------------------------------------------------------
       
   330 //
       
   331 TKeyResponse CAcpProviderListContainer::OfferKeyEventL( 
       
   332     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   333     {
       
   334     return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------------------------
       
   338 // CAcpProviderListContainer::CountComponentControls
       
   339 // From class CoeControl.
       
   340 // ---------------------------------------------------------------------------
       
   341 //
       
   342 TInt CAcpProviderListContainer::CountComponentControls() const
       
   343     {
       
   344     return KComponentControlCount;
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------------------------
       
   348 // CAcpProviderListContainer::SizeChanged
       
   349 // From class CoeControl.
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CAcpProviderListContainer::SizeChanged()
       
   353     {
       
   354     iListBox->SetRect( Rect() );
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CAcpProviderListContainer::FocusChanged
       
   359 // From class CoeControl.
       
   360 // ---------------------------------------------------------------------------
       
   361 //
       
   362 void CAcpProviderListContainer::FocusChanged( TDrawNow aDrawNow )
       
   363     {
       
   364     CCoeControl::FocusChanged( aDrawNow );
       
   365 
       
   366     if ( iListBox )
       
   367         {
       
   368         iListBox->SetFocus( IsFocused() );
       
   369         }
       
   370     }
       
   371 
       
   372 // ---------------------------------------------------------------------------
       
   373 // CAcpProviderListContainer::HandleResourceChange
       
   374 // From class CCoeControl.
       
   375 // Called by framework when layout is changed.
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 void CAcpProviderListContainer::HandleResourceChange( TInt aType )
       
   379     {
       
   380     CCoeControl::HandleResourceChange(aType);
       
   381 
       
   382     // *****************************
       
   383     // ADDED FOR SCALABLE UI SUPPORT
       
   384     // *****************************
       
   385     if ( KEikDynamicLayoutVariantSwitch == aType )
       
   386         {
       
   387         TRect rect;
       
   388         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect );
       
   389         SetRect( rect );
       
   390         }
       
   391     }
       
   392 
       
   393 // End of file.