devicediagnostics/devdiagapp/src/devdiagsuitecontainer.cpp
changeset 0 3ce708148e4d
child 2 a5fecba4b1e4
equal deleted inserted replaced
-1:000000000000 0:3ce708148e4d
       
     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:  Main container that displayes suites.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "devdiagsuitecontainer.h"
       
    22 #include "devdiagengine.h"   
       
    23 
       
    24 #include <StringLoader.h>
       
    25 #include <aknlists.h>
       
    26 #include <DiagPlugin.h>  
       
    27 #include <DiagPluginPool.h> 
       
    28 #include <DiagSuitePlugin.h>   
       
    29 #include <AknIconArray.h>           // CAknIconArray
       
    30 #include <AknIconUtils.h>           // AknIconUtils
       
    31 #include <gulicon.h>                // CGulIcon
       
    32 
       
    33 #include <eikclbd.h>                // CColumnListBoxData
       
    34 #include <AknIconArray.h>
       
    35 #include <AknsUtils.h>
       
    36 #include <textresolver.h>
       
    37 
       
    38 ///@@@KSR: changes for BAD Warnings - KNSmlTab" was declared but never referenced
       
    39 //_LIT( KNSmlTab,     "\t" );
       
    40 _LIT( KListSuiteElementFormat,  "%d\t%S" );
       
    41 
       
    42 const TInt KIconArrayGranularity(5);
       
    43 
       
    44 // ========================== MEMBER FUNCTIONS =================================
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 // CDevDiagSuiteContainer::NewL
       
    48 // Two-phased constructor.
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CDevDiagSuiteContainer* CDevDiagSuiteContainer::NewL( CDevDiagSuiteView* aView,
       
    52                                                          CDevDiagEngine& aEngine,
       
    53                                                 const TRect&    aRect )
       
    54     {
       
    55     CDevDiagSuiteContainer* self = new( ELeave ) 
       
    56                                      CDevDiagSuiteContainer( aView, aEngine );
       
    57     
       
    58     CleanupStack::PushL( self );
       
    59     self->ConstructL( aRect );
       
    60     CleanupStack::Pop();
       
    61 
       
    62     return self;
       
    63     }
       
    64 
       
    65 // -----------------------------------------------------------------------------
       
    66 // CDevDiagSuiteContainer::CDevDiagSuiteContainer
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CDevDiagSuiteContainer::CDevDiagSuiteContainer( CDevDiagSuiteView* aView,
       
    72                                                     CDevDiagEngine& aEngine )
       
    73     : iView( aView ), iEngine(aEngine)
       
    74     {
       
    75     }
       
    76 
       
    77 // -----------------------------------------------------------------------------
       
    78 // CDevDiagSuiteContainer::ConstructL
       
    79 // Symbian 2nd phase constructor can leave.
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 void CDevDiagSuiteContainer::ConstructL( const TRect& aRect )
       
    83     {
       
    84     CreateWindowL();
       
    85 
       
    86 	iListBox = new ( ELeave ) CAknSingleLargeStyleListBox;
       
    87 	
       
    88 	iListBox->SetContainerWindowL( *this );
       
    89 	iListBox->ConstructL( this, EAknListBoxSelectionList );
       
    90 
       
    91 	iListBox->CreateScrollBarFrameL( ETrue );
       
    92 	iListBox->ScrollBarFrame()->SetScrollBarVisibilityL( 
       
    93 	                                            CEikScrollBarFrame::EOff,
       
    94 	                                            CEikScrollBarFrame::EAuto );
       
    95        
       
    96     CArrayPtr< CGulIcon >* icons = new ( ELeave ) CAknIconArray(
       
    97         KIconArrayGranularity );
       
    98    
       
    99     iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   100     
       
   101 	iListBox->UpdateScrollBarsL();
       
   102 	//iListBox->ScrollBarFrame()->MoveVertThumbTo( 0 );		
       
   103 
       
   104 	iListBox->SetListBoxObserver( this );
       
   105 			
       
   106     SetRect( aRect );
       
   107     ActivateL();    
       
   108     }
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // CDevDiagSuiteContainer::~CDevDiagSuiteContainer
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CDevDiagSuiteContainer::~CDevDiagSuiteContainer()
       
   115     {
       
   116     delete iListBox;
       
   117         
       
   118     //iChildren.ResetAndDestroy();
       
   119     iChildren.Close();
       
   120     }
       
   121     
       
   122 // -----------------------------------------------------------------------------
       
   123 // CDevDiagSuiteContainer::SizeChanged
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CDevDiagSuiteContainer::SizeChanged()
       
   127     {
       
   128     iListBox->SetRect( Rect() );    // Mandatory, otherwise not drawn
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CDevDiagSuiteContainer::HandleResourceChange
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void CDevDiagSuiteContainer::HandleResourceChange( TInt aType )
       
   136     {    
       
   137     CCoeControl::HandleResourceChange( aType );
       
   138     
       
   139     //Handle change in layout orientation
       
   140     if ( aType == KEikDynamicLayoutVariantSwitch || aType == KAknsMessageSkinChange )
       
   141         {
       
   142         if ( aType == KAknsMessageSkinChange )
       
   143         	{
       
   144         	// Skin changed; we'll have to reload the icon array
       
   145             CArrayPtr<CGulIcon>* iconArray =
       
   146                 iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   147             if ( iconArray )
       
   148                 {
       
   149     	        iconArray->ResetAndDestroy();
       
   150 	            delete iconArray;
       
   151 	            iconArray = NULL;
       
   152     	        }
       
   153     	    TRAP_IGNORE( AddIconsL() );
       
   154         	}
       
   155 
       
   156         TRect mainPaneRect;
       
   157         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPaneRect );
       
   158         SetRect( mainPaneRect );
       
   159 		DrawDeferred();
       
   160 		}	
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // CDevDiagSuiteContainer::CountComponentControls
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 TInt CDevDiagSuiteContainer::CountComponentControls() const
       
   168     {
       
   169     TInt retval( 0 );
       
   170     if ( iListBox )
       
   171         {
       
   172         retval = 1;
       
   173         }
       
   174     return retval; // return nbr of controls inside this container
       
   175     }
       
   176 
       
   177 // -----------------------------------------------------------------------------
       
   178 // CDevDiagSuiteContainer::ComponentControl
       
   179 // -----------------------------------------------------------------------------
       
   180 //
       
   181 CCoeControl* CDevDiagSuiteContainer::ComponentControl( TInt aIndex ) const
       
   182     {
       
   183     switch ( aIndex )
       
   184         {
       
   185         case 0:
       
   186             {
       
   187             return iListBox;
       
   188             }
       
   189         default:
       
   190             {
       
   191             return NULL;
       
   192             }
       
   193         }
       
   194     }
       
   195 
       
   196 // -----------------------------------------------------------------------------
       
   197 // CDevDiagSuiteContainer::Draw
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 void CDevDiagSuiteContainer::Draw( const TRect& /* aRect */ ) const
       
   201     {
       
   202     }
       
   203 
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CDevDiagSuiteContainer::HandleControlEventL
       
   207 // -----------------------------------------------------------------------------
       
   208 //
       
   209 
       
   210 void CDevDiagSuiteContainer::HandleControlEventL( CCoeControl* /* aControl */,
       
   211                                                 TCoeEvent /* aEventType */ )
       
   212     {
       
   213     }
       
   214 
       
   215 // -----------------------------------------------------------------------------
       
   216 // CDevDiagSuiteContainer::OfferKeyEventL
       
   217 // -----------------------------------------------------------------------------
       
   218 //
       
   219 
       
   220 TKeyResponse CDevDiagSuiteContainer::OfferKeyEventL( const TKeyEvent& aKeyEvent,
       
   221                                                              TEventCode aType )
       
   222 	{
       
   223 
       
   224 	if ( iListBox && aType == EEventKey )
       
   225 		{
       
   226 		switch ( aKeyEvent.iCode )
       
   227 			{
       
   228 			case EStdKeyHome:
       
   229 				{			
       
   230 			    break;           
       
   231 				}
       
   232 				
       
   233 			case EKeyEscape:
       
   234 				{
       
   235 			
       
   236 				iAvkonAppUi->ProcessCommandL( EEikCmdExit );
       
   237 				
       
   238 		    	break;
       
   239 				}
       
   240 			case EKeyUpArrow:
       
   241 			case EKeyDownArrow:
       
   242 			    {
       
   243 			    TKeyResponse retVal =
       
   244 			        iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   245                 return retVal;
       
   246 			    }
       
   247 			case EKeyLeftArrow:
       
   248 			case EKeyRightArrow:
       
   249 			    {
       
   250 			    break;  // AppUi handles the tab changes
       
   251 			    }
       
   252 			default:
       
   253 			    {
       
   254 			    return iListBox->OfferKeyEventL( aKeyEvent, aType );
       
   255 			    }
       
   256 			}
       
   257 		}
       
   258 	
       
   259 	return EKeyWasNotConsumed;
       
   260 	}
       
   261 
       
   262 // -----------------------------------------------------------------------------
       
   263 // CDevDiagSuiteContainer::HandleListBoxEventL
       
   264 // -----------------------------------------------------------------------------
       
   265 //
       
   266 void CDevDiagSuiteContainer::HandleListBoxEventL( CEikListBox* /*aListBox*/, 
       
   267                                                  TListBoxEvent aEventType )
       
   268 	{	
       
   269 	// if the Select Key has been pressed
       
   270 	if ((aEventType == MEikListBoxObserver::EEventEnterKeyPressed) ||
       
   271 	(aEventType == MEikListBoxObserver::EEventItemClicked))
       
   272 		{ 
       
   273 		
       
   274 		}
       
   275 	}
       
   276 
       
   277 
       
   278 #ifdef __SERIES60_HELP
       
   279 // -----------------------------------------------------------------------------
       
   280 // CDevDiagSuiteContainer::GetHelpContext
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CDevDiagSuiteContainer::GetHelpContext( TCoeHelpContext& /*aContext*/ ) const
       
   284 	{	
       
   285 	//aContext.iMajor = KUidSmlSyncApp;
       
   286     //aContext.iContext = KDM_HLP_DIAGNOSTICS_APPLICATION;
       
   287 	}
       
   288 
       
   289 #else
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // CDevDiagSuiteContainer::GetHelpContext
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CDevDiagSuiteContainer::GetHelpContext( TCoeHelpContext& /*aContext*/ ) const
       
   296 	{
       
   297 	}
       
   298 #endif // __SERIES60_HELP
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CDevDiagSuiteContainer::FocusChanged
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 void CDevDiagSuiteContainer::FocusChanged( TDrawNow /*aDrawNow*/ )
       
   305 	{
       
   306 	if ( iListBox )
       
   307 		{
       
   308 		iListBox->SetFocus( IsFocused() );
       
   309 		}
       
   310 	}
       
   311 
       
   312 // -----------------------------------------------------------------------------
       
   313 // Display a group of plug-ins that are under the parent suite. 
       
   314 // -----------------------------------------------------------------------------
       
   315 //
       
   316 void CDevDiagSuiteContainer::DisplayChildrenL( TUid aParentUid )
       
   317     {
       
   318     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   319 
       
   320     // Add listbox items.
       
   321     CDesCArray* pluginTextArray = static_cast< CDesCArray* >(
       
   322         iListBox->Model()->ItemTextArray() );
       
   323     pluginTextArray->Reset();
       
   324 
       
   325     // Get the root suite.
       
   326     MDiagPlugin* plugin;
       
   327     HBufC* formattedName = NULL;
       
   328     if ( iEngine.PluginPool().FindPlugin( aParentUid, plugin ) == KErrNone )
       
   329         {
       
   330 
       
   331         iChildren.Reset(); //plug-ins are owned by the engine.
       
   332        
       
   333         MDiagSuitePlugin* suite = static_cast< MDiagSuitePlugin* >( plugin );
       
   334         suite->GetChildrenL( iChildren, MDiagSuitePlugin::ESortByPosition );
       
   335         
       
   336         AddIconsL(); //Update icon array to match texts
       
   337      
       
   338         for ( TInt j = 0; j < iChildren.Count(); j++ )
       
   339             {            
       
   340             HBufC* name = iChildren[j]->GetPluginNameL(
       
   341                 MDiagPlugin::ENameLayoutListSingle );
       
   342             CleanupStack::PushL( name );           
       
   343             
       
   344             formattedName = HBufC::NewLC( name->Length() + 
       
   345                                         KListSuiteElementFormat().Length() );
       
   346             formattedName->Des().Format( KListSuiteElementFormat(), j ,name );    
       
   347                 
       
   348             pluginTextArray->AppendL( *formattedName );
       
   349             
       
   350             CleanupStack::PopAndDestroy( formattedName );
       
   351             CleanupStack::PopAndDestroy( name );
       
   352             }
       
   353                 
       
   354         iListBox->SetFocus( ETrue );
       
   355         iListBox->HandleItemAdditionL();
       
   356         iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   357         iListBox->DrawDeferred();
       
   358         }
       
   359     else 
       
   360         {
       
   361         User::Leave(KErrNotFound);
       
   362         }
       
   363     }
       
   364 
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // Append aPlugin name onto the listbox.
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void CDevDiagSuiteContainer::DisplayPluginL( MDiagPlugin* aPlugin )
       
   371     {
       
   372     iListBox->Model()->SetOwnershipType( ELbmOwnsItemArray );
       
   373 
       
   374     // Add listbox items.
       
   375     CDesCArray* pluginTextArray = static_cast< CDesCArray* >(
       
   376         iListBox->Model()->ItemTextArray() );
       
   377         
       
   378     iChildren.Append( aPlugin );
       
   379                            
       
   380     HBufC* name = aPlugin->GetPluginNameL(
       
   381                 MDiagPlugin::ENameLayoutListSingle );
       
   382     CleanupStack::PushL( name );           
       
   383     
       
   384     CArrayPtr< CGulIcon >* icons =
       
   385         iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   386           
       
   387     icons->AppendL( aPlugin->CreateIconL() );
       
   388             
       
   389     HBufC* formattedName = HBufC::NewLC( name->Length() + 
       
   390                                   KListSuiteElementFormat().Length() );
       
   391     formattedName->Des().Format( KListSuiteElementFormat(), (iChildren.Count() -1), name );    
       
   392                 
       
   393     pluginTextArray->AppendL( *formattedName );
       
   394             
       
   395     CleanupStack::PopAndDestroy( formattedName );
       
   396     CleanupStack::PopAndDestroy( name );
       
   397                                    
       
   398     iListBox->SetFocus( ETrue );
       
   399     iListBox->HandleItemAdditionL();
       
   400     iListBox->ItemDrawer()->ColumnData()->EnableMarqueeL( ETrue );
       
   401     iListBox->DrawDeferred();
       
   402     }
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // Returns currently selected plug-in.
       
   406 // -----------------------------------------------------------------------------
       
   407 //
       
   408 void CDevDiagSuiteContainer::SelectedPlugin(MDiagPlugin*& aPlugin) const
       
   409     {
       
   410     aPlugin = iChildren[ iListBox->CurrentItemIndex() ];
       
   411     }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CDevDiagSuiteContainer::AddIconsL
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 void CDevDiagSuiteContainer::AddIconsL()
       
   418     {        
       
   419     CArrayPtr<CGulIcon>* icons = NULL;
       
   420     
       
   421     if ( !iListBox->ItemDrawer()->ColumnData()->IconArray() )         
       
   422         {
       
   423         icons = new (ELeave) CArrayPtrFlat<CGulIcon>(KIconArrayGranularity);
       
   424         iListBox->ItemDrawer()->ColumnData()->SetIconArray( icons );
       
   425         }
       
   426     else 
       
   427         {
       
   428         icons = iListBox->ItemDrawer()->ColumnData()->IconArray();
       
   429         }
       
   430     	
       
   431     for ( TInt i = 0; i < iChildren.Count(); ++i )
       
   432         {
       
   433         icons->AppendL( iChildren[i]->CreateIconL( ));
       
   434         }   
       
   435     }
       
   436 
       
   437 
       
   438 
       
   439 
       
   440 // End of File