gssettingsuis/Gs/GSApplication/Src/GSMainView.cpp
changeset 0 8c5d936e5675
child 2 051d34a3f367
equal deleted inserted replaced
-1:000000000000 0:8c5d936e5675
       
     1 /*
       
     2 * Copyright (c) 2005 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 View.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include    <gsmainview.h>
       
    21 #include    "GSMainContainer.h"
       
    22 #include    "GsLogger.h"
       
    23 #include    "gsplugininterface.h"
       
    24 #include    "GSDocument.h"
       
    25 #include    "GSUi.h"
       
    26 #include    <GSApp.rsg>
       
    27 #include    <gsfwviewuids.h>
       
    28 
       
    29 #include    <aknlists.h>
       
    30 #include    <ConeResLoader.h>
       
    31 #include    <featmgr.h>
       
    32 #include    <akntitle.h>
       
    33 #include    <bautils.h> // Localization
       
    34 #include    <hlplch.h>
       
    35 #include    <gscommon.hrh>
       
    36 #include    <gfxtranseffect/gfxtranseffect.h>
       
    37 #include	<LayoutMetaData.cdl.h>
       
    38 
       
    39 // ========================= MEMBER FUNCTIONS ================================
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // CGSMainView::CGSMainView
       
    43 // C++ constructor.
       
    44 //
       
    45 // ---------------------------------------------------------------------------
       
    46 //
       
    47 CGSMainView::CGSMainView()
       
    48     : iResourceLoader( *iCoeEnv )
       
    49     {
       
    50     }
       
    51 
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // CGSMainView::NewL()
       
    55 // Symbian OS two-phased constructor.
       
    56 //
       
    57 // ---------------------------------------------------------------------------
       
    58 //
       
    59 CGSMainView* CGSMainView::NewL()
       
    60     {
       
    61     CGSMainView* self = NewLC();
       
    62     CleanupStack::Pop( self );
       
    63     return self;
       
    64     }
       
    65 
       
    66 
       
    67 // ---------------------------------------------------------------------------
       
    68 // CGSMainView::NewLC()
       
    69 // Symbian OS two-phased constructor.
       
    70 //
       
    71 // ---------------------------------------------------------------------------
       
    72 //
       
    73 CGSMainView* CGSMainView::NewLC()
       
    74     {
       
    75     CGSMainView* self = new( ELeave ) CGSMainView();
       
    76     CleanupStack::PushL( self );
       
    77     self->ConstructL();
       
    78     return self;
       
    79     }
       
    80 
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CGSMainView::ConstructL(const TRect& aRect)
       
    84 // Symbian OS default constuctor.
       
    85 //
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 void CGSMainView::ConstructL()
       
    89     {
       
    90     __GSLOGSTRING( "[CGSMainView] ConstructL()" );
       
    91     iAppUi = AppUi();
       
    92 
       
    93     OpenLocalizedResourceFileL( KGSMainViewResourceFileName );
       
    94     BaseConstructL( R_GS_MAIN_VIEW );
       
    95 
       
    96     iPluginArray = new CArrayPtrFlat<CGSPluginInterface>( 10 );
       
    97 
       
    98     iPluginLoader = CGSPluginLoader::NewL( iAppUi );
       
    99     iPluginLoader->SetObserver( this );
       
   100     iPluginLoader->LoadAsyncL( KGSPluginInterfaceUid, KGSMainViewUid,
       
   101         iPluginArray );
       
   102     }
       
   103 
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // CGSMainView::~CGSMainView()
       
   107 // Destructor
       
   108 //
       
   109 // ---------------------------------------------------------------------------
       
   110 //
       
   111 CGSMainView::~CGSMainView()
       
   112     {
       
   113     __GSLOGSTRING( "[CGSMainView] ~CGSMainView" );
       
   114     if ( iPluginLoader )
       
   115         {
       
   116         delete iPluginLoader;
       
   117         }
       
   118 
       
   119     if ( iPluginArray )
       
   120         {
       
   121         // Since the plugins are actually avkon views, avkon is responsible
       
   122         // for owning the plugins. This means we do not reset and destroy
       
   123         // the contents of the array in which the plugins reside. We have to
       
   124         // leave it up to avkon to tidy up.
       
   125         delete iPluginArray;
       
   126         }
       
   127 
       
   128     iResourceLoader.Close();
       
   129 
       
   130     if( iContainer && iAppUi )
       
   131         {
       
   132         iAppUi->RemoveFromViewStack( *this, iContainer );
       
   133         delete iContainer;
       
   134         }
       
   135     }
       
   136 
       
   137 
       
   138 // ---------------------------------------------------------------------------
       
   139 // TUid CGSMainView::OpenLocalizedResourceFileL()
       
   140 //
       
   141 //
       
   142 // ---------------------------------------------------------------------------
       
   143 //
       
   144 void CGSMainView::OpenLocalizedResourceFileL( const TDesC& aResourceFileName )
       
   145     {
       
   146     RFs fsSession;
       
   147     User::LeaveIfError( fsSession.Connect() );
       
   148     CleanupClosePushL( fsSession );
       
   149 
       
   150     // Find the resource file
       
   151     TParse parse;
       
   152     parse.Set( aResourceFileName, &KDC_APP_RESOURCE_DIR, NULL );
       
   153     TFileName fileName( parse.FullName() );
       
   154 
       
   155     // Get language of resource file
       
   156     BaflUtils::NearestLanguageFile( fsSession, fileName );
       
   157 
       
   158     // Open resource file
       
   159     iResourceLoader.OpenL( fileName );
       
   160 
       
   161     CleanupStack::PopAndDestroy( &fsSession );
       
   162     }
       
   163 
       
   164 
       
   165 // ---------------------------------------------------------------------------
       
   166 // TUid CGSMainView::Id()
       
   167 //
       
   168 //
       
   169 // ---------------------------------------------------------------------------
       
   170 //
       
   171 TUid CGSMainView::Id() const
       
   172     {
       
   173     return KGSMainViewUid;
       
   174     }
       
   175 
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CGSMainView::DoActivateL()
       
   179 //
       
   180 //
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CGSMainView::DoActivateL( const TVwsViewId& /*aPrevViewId*/,
       
   184                                TUid /*aCustomMessageId*/,
       
   185                                const TDesC8& /*aCustomMessage*/ )
       
   186     {
       
   187     __GSLOGSTRING( "[CGSMainView] DoActivateL()" );
       
   188     
       
   189     iPluginLoader->RequestPriority( CActive::EPriorityHigh );
       
   190     
       
   191     if( iContainer )
       
   192         {
       
   193         iAppUi->RemoveFromViewStack( *this, iContainer );
       
   194         delete iContainer;
       
   195         iContainer = NULL;
       
   196         }
       
   197     NewContainerL();
       
   198     
       
   199     // Set the empty text of list box
       
   200     _LIT( KEmptyText, "" );
       
   201     TBuf<1> empty( KEmptyText );
       
   202     iContainer->SetListBoxEmptyTextL( empty );
       
   203     
       
   204     // Do this to update listbox from already existing iPluginArray.
       
   205     iContainer->UpdateListBoxL();
       
   206     if (position.Count() > 0)
       
   207 		{
       
   208 		if (iScreenMode == Layout_Meta_Data::IsLandscapeOrientation())
       
   209 			{
       
   210 			iContainer->SetPosition(position, EFalse);
       
   211 			}
       
   212 		else
       
   213 			{
       
   214 			iContainer->SetPosition(position, ETrue);
       
   215 			}
       
   216 		}
       
   217     iAppUi->AddToViewStackL( *this, iContainer );
       
   218     // Navigating to main view will reset all child plugin selected indexes:
       
   219     for( TInt i = 0; i < iPluginArray->Count(); i++ )
       
   220         {
       
   221         CGSPluginInterface* plugin = iPluginArray->operator[]( i );
       
   222         plugin->ResetSelectedItemIndex();
       
   223         }
       
   224     GfxTransEffect::EndFullScreen();
       
   225     }
       
   226 
       
   227 
       
   228 // ---------------------------------------------------------------------------
       
   229 // CGSMainView::DoDeactivate()
       
   230 //
       
   231 //
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 void CGSMainView::DoDeactivate()
       
   235     {
       
   236     __GSLOGSTRING( "[CGSMainView] DoDeactivate()" );
       
   237     
       
   238     iPluginLoader->RequestPriority( CActive::EPriorityLow );
       
   239     
       
   240     if ( iContainer )
       
   241         {
       
   242 		if (position.Count() > 0)
       
   243 			{
       
   244 			position.Reset();
       
   245 			}
       
   246 		TRAPD(err, iContainer->GetPositionL(position));
       
   247 		iScreenMode = Layout_Meta_Data::IsLandscapeOrientation();
       
   248 		iAppUi->RemoveFromViewStack(*this, iContainer);
       
   249         delete iContainer;
       
   250         iContainer = NULL;
       
   251         }
       
   252     }
       
   253 
       
   254 
       
   255 // ---------------------------------------------------------------------------
       
   256 // CGSMainView::NewContainerL()
       
   257 //
       
   258 //
       
   259 // ---------------------------------------------------------------------------
       
   260 //
       
   261 void CGSMainView::NewContainerL()
       
   262     {
       
   263     iContainer = new( ELeave ) CGSMainContainer;
       
   264     iContainer->SetMopParent( this );
       
   265 
       
   266     TRAPD(
       
   267         error,
       
   268         iContainer->ConstructL( ClientRect() , AppUi(), iPluginArray ) );
       
   269 
       
   270     if ( error )
       
   271         {
       
   272         delete iContainer;
       
   273         iContainer = NULL;
       
   274         User::Leave( error );
       
   275         }
       
   276     }
       
   277 
       
   278 
       
   279 // ---------------------------------------------------------------------------
       
   280 // TUid CGSMainView::HandleCommandL()
       
   281 //
       
   282 //
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CGSMainView::HandleCommandL( TInt aCommand )
       
   286     {
       
   287     __GSLOGSTRING1( "[CGSMainView] HandleCommandL(%d)", aCommand );
       
   288 
       
   289     switch ( aCommand )
       
   290         {
       
   291         case EGSCmdAppOpen:
       
   292         case EAknSoftkeyOpen:
       
   293             if( iContainer )
       
   294                 {
       
   295                 CGSPluginInterface* plugin = iContainer->SelectedPlugin();
       
   296                 if ( plugin )
       
   297                 	{
       
   298                     switch (plugin->ItemType())
       
   299                         {
       
   300                         // In these cases the plugin is a view:
       
   301                         case EGSItemTypeSingleLarge:
       
   302                         case EGSItemTypeSetting:
       
   303                         case EGSItemTypeSettingIcon:
       
   304                             iAppUi->ActivateLocalViewL(plugin->Id());
       
   305                             break;
       
   306                             // In these cases the plugin is a dialog:
       
   307                         case EGSItemTypeSettingDialog:
       
   308                         case EGSItemTypeSingleLargeDialog:
       
   309                             plugin->HandleSelection(EGSSelectionByMenu);
       
   310                             break;
       
   311                         }
       
   312                 	}
       
   313                 }
       
   314             break;
       
   315         case EAknCmdHelp:
       
   316             {
       
   317             if( FeatureManager::FeatureSupported( KFeatureIdHelp ) )
       
   318                 {
       
   319                 HlpLauncher::LaunchHelpApplicationL(
       
   320                     iEikonEnv->WsSession(), iAppUi->AppHelpContextL() );
       
   321                 }
       
   322             break;
       
   323             }
       
   324         default:
       
   325             iAppUi->HandleCommandL( aCommand );
       
   326             break;
       
   327         }
       
   328     }
       
   329 
       
   330 
       
   331 // ---------------------------------------------------------------------------
       
   332 // TUid CGSMainView::HandlePluginLoaded()
       
   333 //
       
   334 //
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CGSMainView::HandlePluginLoaded( KGSPluginLoaderStatus aStatus )
       
   338     {
       
   339     __GSLOGSTRING1( "[CGSMainView::HandlePluginLoaded] aStatus:%d", aStatus );
       
   340     
       
   341     switch( aStatus )
       
   342         {
       
   343         case MGSPluginLoadObserver::EGSSuccess:
       
   344             // Should not update each time when plugin is loaded, only when 
       
   345             // finished loading spesific view plugins?
       
   346             break;
       
   347         case MGSPluginLoadObserver::EGSFinished:
       
   348             if( iContainer )
       
   349                 {
       
   350                 TRAPD( err,
       
   351                        iContainer->UpdateListBoxL(); )
       
   352                 if( err != KErrNone )
       
   353                     {
       
   354                     __GSLOGSTRING1(
       
   355                         "[CGSMainView] Error updating listbox: %d", 
       
   356                         err );
       
   357                     }
       
   358                 }
       
   359             break;
       
   360         default:
       
   361             break;
       
   362         }
       
   363 
       
   364     }
       
   365 
       
   366 
       
   367 // ---------------------------------------------------------------------------
       
   368 // CGSMainView::TransferDynamicPluginL()
       
   369 //
       
   370 //
       
   371 // ---------------------------------------------------------------------------
       
   372 //
       
   373 void CGSMainView::TransferDynamicPluginL( CGSPluginInterface* aPlugin )
       
   374     {
       
   375     __GSLOGSTRING1( "[CGSMainView] CGSMainView::TransferDynamicPluginL() - plugin id: 0x%x added to appUi.", aPlugin->Id() );
       
   376 
       
   377     CleanupStack::PushL( aPlugin );
       
   378     iAppUi->AddViewL( aPlugin );
       
   379     CleanupStack::Pop( aPlugin );
       
   380     
       
   381     // Add to the overall plugin array for this parent plugin
       
   382     iPluginArray->AppendL( aPlugin );
       
   383     
       
   384     // Resort the plugins so that they are in order
       
   385     iPluginLoader->SortPluginsL( iPluginArray );
       
   386     
       
   387     // Update the listbox with the new information
       
   388     HandlePluginLoaded( MGSPluginLoadObserver::EGSSuccess );
       
   389     }
       
   390 
       
   391 
       
   392 // -------------------------------------------------    --------------------------
       
   393 // TUid CGSMainView::TabbedViews()
       
   394 //
       
   395 //
       
   396 // ---------------------------------------------------------------------------
       
   397 //
       
   398 CArrayPtrFlat<CGSPluginInterface>* CGSMainView::TabbedViews()
       
   399     {
       
   400     return iPluginArray;
       
   401     }
       
   402 
       
   403 
       
   404 // -----------------------------------------------------------------------------
       
   405 // CGSMainView::TabChangedL()
       
   406 //
       
   407 //
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 void CGSMainView::TabChangedL( TUid selectedTabUid )
       
   411     {
       
   412     // Update selected item because changing tab in main view's children
       
   413     // affects also main view's selected item:
       
   414     iSelectedPluginUid = selectedTabUid;
       
   415     }
       
   416 
       
   417 
       
   418 // -----------------------------------------------------------------------------
       
   419 // CGSMainView::UpdateView()
       
   420 //
       
   421 //
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CGSMainView::UpdateView()
       
   425     {
       
   426     TRAP_IGNORE( iContainer->UpdateListBoxL() );
       
   427     }
       
   428     
       
   429 
       
   430 // -----------------------------------------------------------------------------
       
   431 // CGSMainView::DynInitMenuPaneL()
       
   432 //
       
   433 // dynamically handle help item if not supported
       
   434 // -----------------------------------------------------------------------------
       
   435 //
       
   436 void CGSMainView::DynInitMenuPaneL( TInt aResourceId, 
       
   437                                     CEikMenuPane* aMenuPane )
       
   438     {   
       
   439     if( aResourceId == R_GS_MENU_ITEM_HELP )
       
   440         {
       
   441         User::LeaveIfNull( aMenuPane );
       
   442         
       
   443         if ( FeatureManager::FeatureSupported( KFeatureIdHelp ))
       
   444             {
       
   445             aMenuPane->SetItemDimmed( EAknCmdHelp, EFalse );
       
   446             }
       
   447         else
       
   448             {
       
   449             aMenuPane->SetItemDimmed( EAknCmdHelp, ETrue );
       
   450             }
       
   451         }
       
   452     }
       
   453 
       
   454 //End of File