commsconfig/cscapplicationui/src/cscservicecontainer.cpp
changeset 0 a4daefaec16c
child 6 fc8c25e5a2e8
equal deleted inserted replaced
-1:000000000000 0:a4daefaec16c
       
     1 /*
       
     2 * Copyright (c) 2007-2007 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:  CSC Application´s Service View´s Container
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <fbs.h>
       
    20 #include <csc.mbg>
       
    21 #include <csc.rsg>
       
    22 #include <e32std.h>
       
    23 #include <aknapp.h>
       
    24 #include <gulicon.h>
       
    25 #include <eikclbd.h>
       
    26 #include <aknlists.h>
       
    27 #include <pathinfo.h>
       
    28 #include <coecntrl.h>
       
    29 #include <AknsUtils.h>
       
    30 #include <cchclient.h>
       
    31 #include <csc.hlp.hrh>
       
    32 #include <akncontext.h>
       
    33 #include <AknIconArray.h>
       
    34 #include <StringLoader.h>
       
    35 #include <aknViewAppUi.h>
       
    36 #include <AiwServiceHandler.h>
       
    37 #include <mspnotifychangeobserver.h>
       
    38 #include <data_caging_path_literals.hrh>
       
    39 #include <cscengsettingscleanupplugininterface.h>
       
    40 
       
    41 #include "mcscservicecontainerobserver.h"
       
    42 #include "csclogger.h"
       
    43 #include "cscdialog.h"
       
    44 #include "cscconstants.h"
       
    45 #include "cscapplication.h"
       
    46 #include "cscnoteutilities.h"
       
    47 #include "cscengcchhandler.h"
       
    48 #include "cscservicecontainer.h"
       
    49 #include "cscengservicehandler.h"
       
    50 #include "cscengbrandinghandler.h"
       
    51 #include "cscengservicepluginhandler.h"
       
    52 #include "cscenguiextensionpluginhandler.h"
       
    53 
       
    54 const TUint KServiceListItemTextMaxLength = 64;
       
    55 const TUint KMaxUiExetnsionNameLength = 64;
       
    56 
       
    57 // Format of the list item string.
       
    58 _LIT( KServiceListItemTextFormat, "%d\t%S\t" );
       
    59 
       
    60 // ======== MEMBER FUNCTIONS ========
       
    61 
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 CCSCServiceContainer::CCSCServiceContainer( 
       
    67     MCSCServiceContainerObserver& aContainerObserver,
       
    68     CCSCEngServicePluginHandler& aServicePluginHandler,
       
    69     CCSCEngUiExtensionPluginHandler& aUiExtensionPluginHandler,
       
    70     CCSCEngServiceHandler& aServiceHandler,
       
    71     CCSCEngBrandingHandler& aBrandingHandler,
       
    72     CCSCEngCCHHandler& aCCHHandler ):
       
    73     iContainerObserver( aContainerObserver ),
       
    74     iServicePluginHandler( aServicePluginHandler ),
       
    75     iUiExtensionPluginHandler( aUiExtensionPluginHandler ),
       
    76     iServiceHandler( aServiceHandler ),
       
    77     iBrandingHandler( aBrandingHandler ),
       
    78     iCCHHandler( aCCHHandler )
       
    79     {
       
    80     }
       
    81 
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CCSCServiceContainer::ConstructL( const TRect& aRect )
       
    87     {
       
    88     CSCDEBUG( "CCSCServiceContainer::ConstructL - begin" );
       
    89     
       
    90     CreateWindowL(); 
       
    91     iDialog = CCSCDialog::NewL();
       
    92     
       
    93     iListBox = new (ELeave) CAknDouble2LargeStyleListBox;
       
    94     iListBox->SetContainerWindowL( *this );
       
    95     iListBox->ConstructL( this, EAknGenericListBoxFlags );
       
    96     iListBox->HideSecondRow( ETrue );
       
    97     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
    98     
       
    99     HBufC* emptyTxt = StringLoader::LoadLC( R_QTN_CSC_NO_SERVICES_INSTALLED );
       
   100     iListBox->View()->SetListEmptyTextL( *emptyTxt );
       
   101     CleanupStack::PopAndDestroy( emptyTxt );
       
   102     
       
   103     iListBox->CreateScrollBarFrameL( ETrue );
       
   104     iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
       
   105                                                  CEikScrollBarFrame::EOff,
       
   106                                                  CEikScrollBarFrame::EAuto );
       
   107     
       
   108     CTextListBoxModel* model = iListBox->Model();
       
   109     MDesCArray* textArray = model->ItemTextArray();
       
   110     iListBoxItems = static_cast<CDesCArray*>( textArray );
       
   111     
       
   112     iEikMenuBar = new ( ELeave ) CEikMenuBar();
       
   113     iEikMenuBar->ConstructL( this, NULL, R_CSC_SERVICEVIEW_MENUBAR );
       
   114     
       
   115     SetRect( aRect );
       
   116     
       
   117     UpdateServiceViewL();
       
   118     
       
   119     ActivateL();
       
   120 
       
   121     CSCDEBUG( "CCSCServiceContainer::ConstructL - end" );
       
   122     }
       
   123     
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // ---------------------------------------------------------------------------
       
   127 //
       
   128 CCSCServiceContainer* CCSCServiceContainer::NewL( 
       
   129     const TRect& aRect,
       
   130     MCSCServiceContainerObserver& aContainerObserver,
       
   131     CCSCEngServicePluginHandler& aServicePluginHandler,
       
   132     CCSCEngUiExtensionPluginHandler& aUiExtensionPluginHandler,
       
   133     CCSCEngServiceHandler& aServiceHandler,
       
   134     CCSCEngBrandingHandler& aBrandingHandler,
       
   135     CCSCEngCCHHandler& aCCHHandler )
       
   136     {
       
   137     CCSCServiceContainer* self = 
       
   138         new ( ELeave ) CCSCServiceContainer( 
       
   139             aContainerObserver,
       
   140             aServicePluginHandler, 
       
   141             aUiExtensionPluginHandler,
       
   142             aServiceHandler,
       
   143             aBrandingHandler,
       
   144             aCCHHandler );
       
   145     
       
   146     CleanupStack::PushL( self );
       
   147     self->ConstructL( aRect );
       
   148     CleanupStack::Pop( self );
       
   149     return self;
       
   150     }
       
   151 
       
   152 
       
   153 // ---------------------------------------------------------------------------
       
   154 // ---------------------------------------------------------------------------
       
   155 //
       
   156 CCSCServiceContainer::~CCSCServiceContainer()
       
   157     {
       
   158     CSCDEBUG( "CCSCServiceContainer::~CCSCServiceContainer - begin" );
       
   159     
       
   160     delete iDialog;        
       
   161     delete iArray;   
       
   162     delete iListBox;    
       
   163     delete iEikMenuBar;
       
   164     
       
   165     iListBoxItemArray.Reset();
       
   166     iListBoxItemArray.Close();
       
   167     
       
   168     CSCDEBUG( "CCSCServiceContainer::~CCSCServiceContainer - end" );
       
   169     }
       
   170 
       
   171 
       
   172 // ---------------------------------------------------------------------------
       
   173 // Updates services to listbox.
       
   174 // ---------------------------------------------------------------------------
       
   175 //
       
   176 void CCSCServiceContainer::UpdateServiceViewL()
       
   177     {
       
   178     CSCDEBUG( "CCSCServiceContainer::UpdateServiceViewL - begin" );
       
   179     
       
   180     TInt currentItemIndex = CurrentItemIndex();
       
   181     
       
   182     // Reset listbox items and item array
       
   183     iListBoxItems->Reset();
       
   184     iListBoxItemArray.Reset();
       
   185         
       
   186     // Find and add Ui Extension Plug-ins
       
   187     iUiExtensionCount = iUiExtensionPluginHandler.PluginCount();
       
   188     
       
   189     // Create icon array or cleanup iconarray if it already exists
       
   190     CArrayPtr<CGulIcon>* iconArray =  
       
   191         iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   192     
       
   193     if ( !iconArray )
       
   194         {
       
   195         iconArray = new( ELeave ) CAknIconArray( 1 );
       
   196          // Set icon array for ListBox.
       
   197         iListBox->ItemDrawer()->ColumnData()->SetIconArray( iconArray );
       
   198         }
       
   199     else
       
   200         {
       
   201         iconArray->ResetAndDestroy();
       
   202         }
       
   203 
       
   204     // move add new service plugin to top
       
   205     RArray<TUiExtensionPluginInfo> uiPlugins;
       
   206     CleanupClosePushL( uiPlugins );
       
   207     
       
   208     for( TInt i = 0; i < iUiExtensionCount; i++ )
       
   209         {
       
   210         TUiExtensionPluginInfo uiExtension = 
       
   211             iUiExtensionPluginHandler.ItemFromPluginInfoArray( i );
       
   212                         
       
   213         if ( KAccountCreationPluginUID == uiExtension.iPluginsUid )
       
   214             {
       
   215             uiPlugins.InsertL( uiExtension, 0 );
       
   216             }
       
   217         else
       
   218             {
       
   219             uiPlugins.AppendL( uiExtension );
       
   220             }
       
   221         }
       
   222 
       
   223     const TInt itemHeight( iListBox->ItemHeight() );
       
   224     TInt iconSize( KIconSizeQvgaPortrait ); // Default icon size (QVGA portrait).
       
   225     if ( KItemHeightQvgaLandscape == itemHeight ) // QVGA landscape
       
   226         {
       
   227         iconSize = KIconSizeQvgaLandscape;
       
   228         }
       
   229                
       
   230     for ( TUint i( 0 ) ; i < iUiExtensionCount ; i++ )
       
   231         {
       
   232         TUiExtensionPluginInfo uiExtension = uiPlugins[i];
       
   233                         
       
   234         if ( 0 == uiExtension.iPlace )
       
   235             {                        
       
   236             TBuf<KMaxUiExetnsionNameLength> extensionName;
       
   237             extensionName.Copy( uiExtension.iUiExtensionName );
       
   238                 
       
   239             // To keep track which kind of listbox items we have
       
   240             TListBoxItem listBoxItem;
       
   241             listBoxItem.iItemType = TListBoxItem::EUiExtension;
       
   242             listBoxItem.iPluginUid = uiExtension.iPluginsUid;
       
   243                         
       
   244             iListBoxItemArray.Append( listBoxItem );
       
   245             
       
   246             // Set icon for ui extension
       
   247             SetIconL( listBoxItem, iconArray, iconSize );
       
   248                                                 
       
   249             TBuf<KServiceListItemTextMaxLength> listBoxItemText;          
       
   250             
       
   251             listBoxItemText.Format(
       
   252                 KServiceListItemTextFormat,
       
   253                 iconArray->Count() - 1,
       
   254                 &extensionName );
       
   255             
       
   256             iListBoxItems->AppendL( listBoxItemText );
       
   257             }
       
   258         }
       
   259     
       
   260     CleanupStack::PopAndDestroy( &uiPlugins );
       
   261     
       
   262     // Get services  
       
   263     RArray<TUint> serviceIds;
       
   264     CleanupClosePushL( serviceIds );
       
   265     
       
   266     TRAPD( err, iServiceHandler.GetAllServiceIdsL( serviceIds ) );
       
   267             
       
   268     for ( TInt i(0) ; i < serviceIds.Count() && !err ; i++ )
       
   269         {                
       
   270         // Check service validity from cch before adding to listbox
       
   271         if ( iCCHHandler.IsServiceValidL( serviceIds[ i ] ) )
       
   272             {
       
   273             TBuf<KServiceListItemTextMaxLength> listBoxItemText;          
       
   274             HBufC* serviceString = NULL;
       
   275                             
       
   276             serviceString = StringLoader::LoadLC( 
       
   277                 R_QTN_CSC_SERVICE_LISTBOX_ITEM, 
       
   278                 iServiceHandler.ServiceNameL( serviceIds[ i ] ) );
       
   279                             
       
   280             // To keep track which kind of listbox items we have
       
   281             TListBoxItem listBoxItem;
       
   282             listBoxItem.iServiceId = serviceIds[ i ];
       
   283                         
       
   284             // Set icon for service
       
   285             SetIconL( listBoxItem, iconArray, iconSize );
       
   286                         
       
   287             listBoxItemText.Format(
       
   288                 KServiceListItemTextFormat,
       
   289                 iconArray->Count() - 1,
       
   290                 serviceString );
       
   291                        
       
   292             iListBoxItems->AppendL( listBoxItemText );    
       
   293                                            
       
   294             TInt32 servicePluginId( 0 );
       
   295             TInt err2( KErrNone );
       
   296                         
       
   297             // Find service plug-in id if service has one
       
   298             TRAP( 
       
   299                 err2, servicePluginId = 
       
   300                 iServiceHandler.ServiceSetupPluginIdL( serviceIds[ i ] ) );
       
   301                                                               
       
   302             if ( !err2 && servicePluginId )
       
   303                 {            
       
   304                 listBoxItem.iItemType = TListBoxItem::EServicePlugin;
       
   305                 listBoxItem.iPluginUid.iUid = servicePluginId;
       
   306                 }
       
   307             else if ( KErrNotFound == err2 )
       
   308                 {
       
   309                 listBoxItem.iItemType = TListBoxItem::EGeneralService;
       
   310                 }
       
   311                         
       
   312             iListBoxItemArray.Append( listBoxItem );    
       
   313 
       
   314             CleanupStack::PopAndDestroy( serviceString );   
       
   315             }
       
   316         }
       
   317     
       
   318     CleanupStack::PopAndDestroy( &serviceIds );  
       
   319     
       
   320     UpdateListboxL();
       
   321     
       
   322     if( iListBoxItemArray.Count() > 0 )
       
   323     	{
       
   324         if ( 0 <= currentItemIndex && 
       
   325            ( iListBoxItemArray.Count() > currentItemIndex  ) )
       
   326             {
       
   327             iListBox->SetCurrentItemIndexAndDraw( currentItemIndex );
       
   328             }
       
   329         else
       
   330             {
       
   331             iListBox->SetCurrentItemIndexAndDraw( 0 );
       
   332             }
       
   333     	}
       
   334     	
       
   335     CSCDEBUG( "CCSCServiceContainer::UpdateSerUpdateServiceViewL - end" );
       
   336     }
       
   337 
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // Update listbox. Handle item addition and drawing.
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CCSCServiceContainer::UpdateListboxL()
       
   344     {
       
   345     CSCDEBUG( "CCSCServiceContainer::UpdateListboxL - begin" );
       
   346     
       
   347     iListBox->HandleItemAdditionL(); 
       
   348     
       
   349     CSCDEBUG( "CCSCServiceContainer::UpdateListboxL - end" );
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // Returns current item index of listbox.
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 TInt CCSCServiceContainer::CurrentItemIndex() const
       
   357     {
       
   358     CSCDEBUG2( 
       
   359     "CCSCServiceContainer::CurrentItemIndex:%d",iListBox->CurrentItemIndex());
       
   360     
       
   361     return iListBox->CurrentItemIndex();
       
   362     }
       
   363 
       
   364 
       
   365 // ---------------------------------------------------------------------------
       
   366 // Returns currently selected list box item.
       
   367 // ---------------------------------------------------------------------------
       
   368 //
       
   369 TListBoxItem CCSCServiceContainer::ListBoxItem()
       
   370     {    
       
   371     return iListBoxItemArray[ CurrentItemIndex() ];
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // Returns reference to listbox.
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 CAknDouble2LargeStyleListBox& CCSCServiceContainer::ListBox()
       
   379     {    
       
   380     return *iListBox;
       
   381     }
       
   382 
       
   383 // ---------------------------------------------------------------------------
       
   384 // Returns pen down point.
       
   385 // ---------------------------------------------------------------------------
       
   386 //
       
   387 TPoint CCSCServiceContainer::PenDownPoint()
       
   388     {
       
   389     return iPenDownPoint;
       
   390     }
       
   391 
       
   392 // ---------------------------------------------------------------------------
       
   393 // Returns service count.
       
   394 // ---------------------------------------------------------------------------
       
   395 //
       
   396 TInt CCSCServiceContainer::ServiceCount()
       
   397     {
       
   398     TUint serviceCount( 0 );
       
   399     
       
   400     for ( TInt i ( 0 ) ; i < iListBoxItemArray.Count() ; i++ )
       
   401         {
       
   402         //Add count if list box item type is general service or service plugin
       
   403         if ( 
       
   404             TListBoxItem::EGeneralService == iListBoxItemArray[i].iItemType ||
       
   405             TListBoxItem::EServicePlugin == iListBoxItemArray[i].iItemType )
       
   406             {
       
   407             serviceCount++;
       
   408             }
       
   409         }
       
   410     
       
   411     return serviceCount;
       
   412     }
       
   413 
       
   414 // ---------------------------------------------------------------------------
       
   415 // Set current item index.
       
   416 // ---------------------------------------------------------------------------
       
   417 //
       
   418 void CCSCServiceContainer::SetCurrentIndex( TInt aIndex )
       
   419     {
       
   420     CSCDEBUG2( "CCSCServiceContainer::SetCurrentIndex: aIndex=%d", aIndex );
       
   421     
       
   422     if( ( aIndex < iListBoxItemArray.Count() ) && ( aIndex >= 0 ) )
       
   423         {
       
   424         iListBox->SetCurrentItemIndex( aIndex );
       
   425         }
       
   426     else
       
   427         {
       
   428         iListBox->SetCurrentItemIndex( 0 );
       
   429         }
       
   430     }
       
   431 
       
   432 
       
   433 // ---------------------------------------------------------------------------
       
   434 // Deletes service.
       
   435 // ---------------------------------------------------------------------------
       
   436 //
       
   437 void CCSCServiceContainer::DeleteServiceL()
       
   438     {
       
   439     CSCDEBUG( "CCSCServiceContainer::DeleteServiceL - begin" );
       
   440     
       
   441     if (  iListBoxItemArray.Count() )
       
   442         {
       
   443         TListBoxItem item = ListBoxItem();
       
   444         TBool  disabled = iCCHHandler.IsServiceDisabled( item.iServiceId );
       
   445         
       
   446         // if enabled -> show unable to delete note
       
   447         if ( !disabled )
       
   448             {
       
   449             CCSCNoteUtilities::ShowInformationNoteL( 
       
   450                 CCSCNoteUtilities::ECSCUnableToDeleteNote,
       
   451                     iServiceHandler.ServiceNameL( item.iServiceId ) );
       
   452             return;
       
   453             }
       
   454 
       
   455         // Show confirmation query for service deletion                        
       
   456         if ( CCSCNoteUtilities::ShowCommonQueryL( 
       
   457             CCSCNoteUtilities::ECSCDeleteServiceQuery, 
       
   458             iServiceHandler.ServiceNameL( item.iServiceId ) ) )
       
   459             {
       
   460             // First check if there is a service plugin UID.
       
   461             TInt count = iServicePluginHandler.PluginCount( 
       
   462                 CCSCEngServicePluginHandler::EInitialized );
       
   463             TBool setupPlugin( EFalse );
       
   464             for ( TInt i = 0; i < count && !setupPlugin; i++ )
       
   465                  {
       
   466                  TServicePluginInfo pluginInfo = 
       
   467                      iServicePluginHandler.ItemFromPluginInfoArray( i );
       
   468                  if ( pluginInfo.iPluginsUid == item.iPluginUid )
       
   469                      {
       
   470                      CSCDEBUG2( "   DeleteServiceL - plugin UID match found: %d",
       
   471                          item.iPluginUid );
       
   472                      setupPlugin = ETrue;
       
   473                      }
       
   474                  }
       
   475 
       
   476             if ( setupPlugin )
       
   477                 {
       
   478                 HandleServicePluginRemovationL( item.iPluginUid );
       
   479                 }
       
   480             else
       
   481                 {
       
   482                 TRAPD( err, LaunchCleanupPluginL( item.iServiceId ) );
       
   483                 if ( KErrNone != err )
       
   484                     {
       
   485                     iServiceHandler.DeleteServiceL( item.iServiceId );
       
   486                     }
       
   487                 }
       
   488             }
       
   489         }
       
   490     
       
   491     CSCDEBUG( "CCSCServiceContainer::DeleteServiceL - end" );
       
   492     }
       
   493 
       
   494 // ---------------------------------------------------------------------------
       
   495 // Handles service plugin removation.
       
   496 // ---------------------------------------------------------------------------
       
   497 //
       
   498 void CCSCServiceContainer::HandleServicePluginRemovationL( const TUid& aUid )
       
   499     {
       
   500     CSCDEBUG( 
       
   501          "CCSCServiceContainer::HandleServicePluginRemovationL - begin" );  
       
   502     
       
   503     TUint serviceId( 0 );   
       
   504     ResolveServiceIdL( aUid, serviceId );
       
   505     if ( !serviceId )
       
   506         {
       
   507         User::Leave( KErrNotFound );
       
   508         }
       
   509         
       
   510     TBool disabled = iCCHHandler.IsServiceDisabled( serviceId );
       
   511         
       
   512     // If service is not disabled, try to disable it
       
   513     if ( !disabled )
       
   514         {
       
   515         iDialog->LaunchWaitNoteL( R_QTN_CSC_REMOVING_SERVICE );
       
   516         User::LeaveIfError( iCCHHandler.DisableService( serviceId ) );
       
   517         return;
       
   518         } 
       
   519         
       
   520     // Remove service plugin
       
   521     TInt error( KErrNone );
       
   522     TRAP( error, iServicePluginHandler.DoRemovationL( aUid, EFalse ) );
       
   523         
       
   524     // If error, remove remainging setting by cleanupplugin
       
   525     if ( error )
       
   526         {
       
   527         error = KErrNone;
       
   528         TRAP( error, LaunchCleanupPluginL( serviceId ) );
       
   529                
       
   530         if ( error )
       
   531             {
       
   532             iServiceHandler.DeleteServiceL( serviceId );
       
   533             }  
       
   534         }
       
   535     }
       
   536 
       
   537 
       
   538 // ---------------------------------------------------------------------------
       
   539 // Updates container data because of layout change.
       
   540 // ---------------------------------------------------------------------------
       
   541 //
       
   542 void CCSCServiceContainer::HandleResourceChange( TInt aType )
       
   543     {
       
   544     CSCDEBUG( "CCSCServiceContainer::HandleResourceChange - begin" );
       
   545     
       
   546     if( aType == KAknsMessageSkinChange ||
       
   547         aType == KEikDynamicLayoutVariantSwitch )
       
   548         {
       
   549         TRect mainPaneRect;
       
   550         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, 
       
   551                                            mainPaneRect );
       
   552         SetRect( mainPaneRect );
       
   553         DrawNow();
       
   554         }
       
   555     
       
   556     CCoeControl::HandleResourceChange( aType );
       
   557     
       
   558     CSCDEBUG( "CCSCServiceContainer::HandleResourceChange - end" );
       
   559     }
       
   560 
       
   561 
       
   562 // ---------------------------------------------------------------------------
       
   563 // Sets listbox observer.
       
   564 // ---------------------------------------------------------------------------
       
   565 //
       
   566 void CCSCServiceContainer::SetListBoxObserver( 
       
   567     MEikListBoxObserver* aObserver )
       
   568     {
       
   569     iListBox->SetListBoxObserver( aObserver );
       
   570     }
       
   571 
       
   572 
       
   573 // ---------------------------------------------------------------------------
       
   574 // Hides dialog wait note.
       
   575 // ---------------------------------------------------------------------------
       
   576 //
       
   577  void CCSCServiceContainer::HideDialogWaitNote()
       
   578     {
       
   579     iDialog->DestroyWaitNote();
       
   580     }
       
   581 
       
   582 
       
   583 // ---------------------------------------------------------------------------
       
   584 // Launches cleanup plugin to remove settings.
       
   585 // ---------------------------------------------------------------------------
       
   586 //
       
   587  void CCSCServiceContainer::LaunchCleanupPluginL( TUint aServiceId ) const
       
   588     {
       
   589     CSCDEBUG( "CCSCServiceContainer::LaunchCleanupPluginL - begin" );
       
   590     
       
   591     RImplInfoPtrArray implInfoArray;
       
   592     CleanupStack::PushL( TCleanupItem( 
       
   593     ResetAndDestroy, &implInfoArray ) );
       
   594                     
       
   595     REComSession::ListImplementationsL(
       
   596         KCSCSettingsCleanupPluginInterfaceUid,
       
   597         implInfoArray );
       
   598         
       
   599     for ( TInt i( 0 ) ; i < implInfoArray.Count() ; i++ )
       
   600         {                    
       
   601         CCSCEngSettingsCleanupPluginInterface* plugin = 
       
   602             CCSCEngSettingsCleanupPluginInterface::NewL( 
       
   603                 implInfoArray[ i ]->ImplementationUid() );
       
   604         
       
   605         CleanupStack::PushL( plugin );
       
   606         
       
   607         if ( CCSCEngSettingsCleanupPluginInterface::ESipVoIPCleanupPlugin 
       
   608             == plugin->PluginType() )
       
   609             {
       
   610             plugin->RemoveSettingsL( aServiceId );
       
   611             }
       
   612         
       
   613         CleanupStack::PopAndDestroy( plugin );
       
   614         }
       
   615                         
       
   616     CleanupStack::PopAndDestroy( &implInfoArray );
       
   617     REComSession::FinalClose();
       
   618     
       
   619     CSCDEBUG( "CCSCServiceContainer::LaunchCleanupPluginL - end" );
       
   620     }
       
   621  
       
   622  
       
   623  // ---------------------------------------------------------------------------
       
   624  // Resolve service id from service plugi uid.
       
   625  // ---------------------------------------------------------------------------
       
   626  //
       
   627  void CCSCServiceContainer::ResolveServiceIdL( 
       
   628      const TUid& aUid, TUint& aServiceId )
       
   629      {     
       
   630      RArray<TUint> serviceIds;
       
   631      CleanupClosePushL( serviceIds );
       
   632      iServiceHandler.GetAllServiceIdsL( serviceIds );
       
   633      
       
   634      TInt serviceCount(  serviceIds.Count() );
       
   635      
       
   636      if ( serviceCount )
       
   637          {
       
   638          for ( TInt i = 0 ; i < serviceCount ; i++ )
       
   639               {
       
   640               TInt32 serviceSetupPluginId( KErrNotFound );
       
   641               TRAPD( err, serviceSetupPluginId = 
       
   642                   iServiceHandler.ServiceSetupPluginIdL( serviceIds[ i ] ) );
       
   643                   
       
   644               if ( KErrNone == err && 
       
   645                   serviceSetupPluginId == aUid.iUid )
       
   646                   {
       
   647                   aServiceId = serviceIds[ i ];
       
   648                   break;
       
   649                   }
       
   650               }
       
   651          }
       
   652      else
       
   653          {
       
   654          User::Leave( KErrNotFound );
       
   655          }
       
   656          
       
   657      CleanupStack::PopAndDestroy( &serviceIds );
       
   658      }
       
   659 
       
   660 // ---------------------------------------------------------------------------
       
   661 // From class CoeControl
       
   662 // Offer key events for controls.
       
   663 // ---------------------------------------------------------------------------
       
   664 // 
       
   665 TKeyResponse CCSCServiceContainer::OfferKeyEventL( 
       
   666     const TKeyEvent& aKeyEvent, TEventCode aType )
       
   667     {
       
   668     CSCDEBUG2( 
       
   669         "CCSCServiceContainer::OfferKeyEventL: aKeyEvent: %d", 
       
   670             aKeyEvent.iScanCode );
       
   671     
       
   672     TKeyResponse result( EKeyWasNotConsumed );
       
   673     
       
   674     if ( iEikMenuBar->ItemSpecificCommandsEnabled() && 
       
   675         EKeyBackspace  == aKeyEvent.iCode &&
       
   676         ( TListBoxItem::EUiExtension != ListBoxItem().iItemType ) )
       
   677         {
       
   678         DeleteServiceL();
       
   679         result = EKeyWasConsumed;
       
   680         }
       
   681     else
       
   682         {
       
   683         result = iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   684         }
       
   685 
       
   686     iContainerObserver.UpdateCbaL();        
       
   687     
       
   688     return result;
       
   689     }
       
   690 
       
   691 
       
   692 // ---------------------------------------------------------------------------
       
   693 // From class CoeControl
       
   694 // Returns component controls.
       
   695 // ---------------------------------------------------------------------------
       
   696 //
       
   697 CCoeControl* CCSCServiceContainer::ComponentControl( TInt aIndex ) const
       
   698     {
       
   699     switch ( aIndex )
       
   700         {
       
   701         case 0:
       
   702             return iListBox;
       
   703         default:
       
   704             return NULL;
       
   705         }
       
   706     }
       
   707 
       
   708 
       
   709 // ---------------------------------------------------------------------------
       
   710 // From class CoeControl
       
   711 // Handle pointer event.
       
   712 // ---------------------------------------------------------------------------
       
   713 //
       
   714 void CCSCServiceContainer::HandlePointerEventL(
       
   715     const TPointerEvent& aPointerEvent )
       
   716     {
       
   717     iPenDownPoint = aPointerEvent.iPosition;
       
   718     CCoeControl::HandlePointerEventL( aPointerEvent );
       
   719     }
       
   720 
       
   721 
       
   722 // ---------------------------------------------------------------------------
       
   723 // From class MCSCEngCCHObserver
       
   724 // ---------------------------------------------------------------------------
       
   725 //
       
   726 void CCSCServiceContainer::ServiceStatusChanged(
       
   727     TUint /*aServiceId*/, 
       
   728     TCCHSubserviceType /*aType*/, 
       
   729     const TCchServiceStatus& /*aServiceStatus*/ )
       
   730     {
       
   731     // not used
       
   732     }
       
   733 
       
   734 
       
   735 // ---------------------------------------------------------------------------
       
   736 // From class CoeControl
       
   737 // Handles controls size changes.
       
   738 // ---------------------------------------------------------------------------
       
   739 //
       
   740 void CCSCServiceContainer::SizeChanged()
       
   741     {
       
   742     if ( iListBox )
       
   743         {
       
   744         iListBox->SetRect( Rect() );
       
   745         }
       
   746     }
       
   747     
       
   748 
       
   749 // ---------------------------------------------------------------------------
       
   750 // From class CoeControl
       
   751 // Handles focus changes.
       
   752 // ---------------------------------------------------------------------------
       
   753 //
       
   754 void CCSCServiceContainer::FocusChanged( TDrawNow aDrawNow )
       
   755     {
       
   756     CCoeControl::FocusChanged( aDrawNow );
       
   757     
       
   758     if( iListBox )
       
   759         {
       
   760         iListBox->SetFocus( IsFocused() );
       
   761         }            
       
   762     }
       
   763     
       
   764     
       
   765 // ---------------------------------------------------------------------------
       
   766 // From class CoeControl
       
   767 // Counts components controls.
       
   768 // ---------------------------------------------------------------------------
       
   769 //
       
   770 TInt CCSCServiceContainer::CountComponentControls() const
       
   771     {
       
   772     return 1; // only iListBox
       
   773     }
       
   774 
       
   775 
       
   776 // -----------------------------------------------------------------------------
       
   777 // From class CoeControl
       
   778 // For getting help context
       
   779 // -----------------------------------------------------------------------------
       
   780 //
       
   781 void CCSCServiceContainer::GetHelpContext( 
       
   782     TCoeHelpContext& aContext ) const
       
   783     {
       
   784     aContext.iMajor = KUidCscHelp;
       
   785     aContext.iContext = KVOIP_HLP_CSC;
       
   786     }
       
   787 
       
   788 
       
   789 // ---------------------------------------------------------------------------
       
   790 // Sets icons for lisbox items.
       
   791 // ---------------------------------------------------------------------------
       
   792 //
       
   793 void CCSCServiceContainer::SetIconL( const TListBoxItem& aListBoxItem,
       
   794     CArrayPtr<CGulIcon>* aIconArray, TInt aIconSize )
       
   795     {
       
   796     CSCDEBUG( "CCSCServiceContainer::SetIconL - begin" );
       
   797          
       
   798     if ( NULL == aIconArray )
       
   799         {
       
   800         return;
       
   801         }
       
   802                  
       
   803     TFileName iconsFileName = TParsePtrC( PathInfo::RomRootPath() ).Drive();
       
   804     iconsFileName.Append( KDC_APP_BITMAP_DIR );
       
   805     iconsFileName.Append( KCSCAifFile );
       
   806     
       
   807     MAknsSkinInstance* skinInstance = AknsUtils::SkinInstance();
       
   808     
       
   809     if ( TListBoxItem::EUiExtension == aListBoxItem.iItemType )
       
   810         {   
       
   811         // specific icon for accountcreationplugin
       
   812         if ( KAccountCreationPluginUID == aListBoxItem.iPluginUid )
       
   813             {
       
   814             aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   815                     skinInstance, 
       
   816                     KAknsIIDDefault,
       
   817                     iconsFileName, 
       
   818                     EMbmCscQgn_prop_voip_new_service, 
       
   819                     EMbmCscQgn_prop_voip_new_service ) );
       
   820             }
       
   821         // specific icon for advanced settings plugin (sip voip settings)
       
   822         else if ( KAdvancedSettingsPluginUID == aListBoxItem.iPluginUid )
       
   823             {
       
   824             aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   825                     skinInstance, 
       
   826                     KAknsIIDDefault,
       
   827                     iconsFileName, 
       
   828                     EMbmCscQgn_prop_set_voip_advanced, 
       
   829                     EMbmCscQgn_prop_set_voip_advanced ) );
       
   830             }
       
   831         else // generic icon
       
   832             {
       
   833             aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   834                     skinInstance, 
       
   835                     KAknsIIDDefault,
       
   836                     iconsFileName,
       
   837                     EMbmCscQgn_prop_set_service, 
       
   838                     EMbmCscQgn_prop_set_service ) );
       
   839             }
       
   840         } 
       
   841     // Service in question, try to get branded icon. If fails use default icon
       
   842     else 
       
   843         {
       
   844         CSCDEBUG( "CCSCServiceContainer::SetIconL - branded icon" );
       
   845         CFbsBitmap* bitmap = NULL;
       
   846         CFbsBitmap* mask = NULL;
       
   847         
       
   848         // Get service brand id and branded icon(s).       
       
   849         TRAPD( err, 
       
   850             TBuf16<KBrandIdMaxLength> brandId16 ( KNullDesC );
       
   851             iServiceHandler.BrandIdL( 
       
   852                 aListBoxItem.iServiceId, 
       
   853                 brandId16 );
       
   854             
       
   855             TBuf8<KBrandIdMaxLength> brandId8 ( KNullDesC8 );
       
   856             brandId8.Copy( brandId16 );
       
   857             iBrandingHandler.GetServiceBrandIconL( brandId8, bitmap, 
       
   858                 mask, aIconSize ); );
       
   859         // Use default icons if error.
       
   860         if ( KErrNone != err )
       
   861             {
       
   862             aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   863                 skinInstance, 
       
   864                 KAknsIIDDefault,
       
   865                 iconsFileName,
       
   866                 EMbmCscQgn_prop_set_service, 
       
   867                 EMbmCscQgn_prop_set_service ) );
       
   868             }
       
   869         // Use branded icons if KErrNone.    
       
   870         else
       
   871             {
       
   872             if ( bitmap )
       
   873                 {
       
   874                 CSCDEBUG( "CCSCServiceContainer::SetIconL - branded icon" );
       
   875                 CleanupStack::PushL( bitmap );
       
   876                 CleanupStack::PushL( mask );
       
   877                 
       
   878                 CFbsBitmap* newBitmap = new (ELeave) CFbsBitmap;     
       
   879                 if ( KErrNone == newBitmap->Duplicate( bitmap->Handle() ) )
       
   880                     {
       
   881                     CleanupStack::PushL( newBitmap );
       
   882                     //ownership transferred (newBitmap)
       
   883                     
       
   884                     //Create new mask
       
   885                     CFbsBitmap* newMask = new (ELeave) CFbsBitmap; 
       
   886                     if( KErrNone == newMask->Duplicate( mask->Handle() ) )
       
   887                         {
       
   888                         CSCDEBUG( "CCSCServiceContainer::SetIconsL - branded newMASK" );
       
   889                         
       
   890                         CleanupStack::PushL ( newMask );
       
   891                         CGulIcon* icon = CGulIcon::NewL( 
       
   892                             AknIconUtils::CreateIconL( newBitmap ),
       
   893                             AknIconUtils::CreateIconL( newMask ) );
       
   894                         
       
   895                         CleanupStack::Pop( newMask );
       
   896                         CleanupStack::Pop( newBitmap );
       
   897                     
       
   898                         CleanupStack::PushL( icon );     
       
   899                         aIconArray->AppendL( icon );
       
   900                         CleanupStack::Pop( icon );
       
   901                         CSCDEBUG( "CCSCServiceContainer::SetIconsL - branded newMASK done" );
       
   902                         }
       
   903                     else
       
   904                         {
       
   905                         CSCDEBUG( "CCSCServiceContainer::SetIconsL - Error creating mask duplicate" );
       
   906                         CleanupStack::PopAndDestroy( newBitmap );
       
   907                         delete newMask;
       
   908                         newMask = NULL;
       
   909                         }
       
   910                     }
       
   911                 else
       
   912                     {
       
   913                     delete newBitmap;
       
   914                     newBitmap = NULL;
       
   915                     
       
   916                     aIconArray->AppendL( AknsUtils::CreateGulIconL( 
       
   917                         skinInstance, 
       
   918                         KAknsIIDDefault,
       
   919                         iconsFileName,
       
   920                         EMbmCscQgn_prop_set_service, 
       
   921                         EMbmCscQgn_prop_set_service ) );  
       
   922                     }
       
   923                 
       
   924                 CleanupStack::PopAndDestroy( mask );
       
   925                 CleanupStack::PopAndDestroy( bitmap );
       
   926                 }
       
   927             }
       
   928         }
       
   929              
       
   930     CSCDEBUG( "CCSCServiceContainer::SetIconsL - end" );
       
   931     }    
       
   932 
       
   933 
       
   934 // ---------------------------------------------------------------------------
       
   935 // CCSCServiceContainer::ResetAndDestroy
       
   936 // ---------------------------------------------------------------------------
       
   937 //
       
   938 void CCSCServiceContainer::ResetAndDestroy( TAny* aArray )
       
   939     {
       
   940     CSCDEBUG( "CCSCServiceContainer::ResetAndDestroy - end" );	
       
   941     
       
   942     if ( aArray )
       
   943         {
       
   944         RImplInfoPtrArray* array = 
       
   945             reinterpret_cast<RImplInfoPtrArray*>( aArray );
       
   946         array->ResetAndDestroy();
       
   947         }
       
   948     
       
   949     CSCDEBUG( "CCSCServiceContainer::ResetAndDestroy - end" );
       
   950     }
       
   951