psln/PslnFramework/src/PslnFWBaseView.cpp
changeset 37 89c890c70182
parent 34 6b5204869ed5
child 45 667edd0b8678
equal deleted inserted replaced
34:6b5204869ed5 37:89c890c70182
     1 /*
       
     2 * Copyright (c) 2005-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:  Base view for all plugin views.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "pslnfwbaseview.h"
       
    21 #include "pslnfwbasecontainer.h"
       
    22 #include "PslnConst.h"
       
    23 #include "PslnDebug.h"
       
    24 
       
    25 // For Download and Help command handling
       
    26 #include <psln.hrh>
       
    27 #include <hlplch.h>
       
    28 
       
    29 // AVKON utilities
       
    30 #include <aknnavide.h>
       
    31 #include <akntitle.h>
       
    32 #include <aknViewAppUi.h>
       
    33 #include <akntabgrp.h>
       
    34 
       
    35 // General Utilities
       
    36 #include <barsread.h>
       
    37 #include <bautils.h>
       
    38 #include <data_caging_path_literals.hrh>
       
    39 #include <StringLoader.h>
       
    40 
       
    41 // Static view locations.
       
    42 const TInt KPslnFWGeneralThemeViewLocation = 0;
       
    43 
       
    44 // ========================= MEMBER FUNCTIONS ================================
       
    45 // ---------------------------------------------------------------------------
       
    46 // C++ constructor
       
    47 // ---------------------------------------------------------------------------
       
    48 EXPORT_C CPslnFWBaseView::CPslnFWBaseView() : iResourceLoader( *iCoeEnv ),
       
    49     iMyTabIndex ( KErrNotFound )
       
    50     {
       
    51     }
       
    52 
       
    53 // ---------------------------------------------------------------------------
       
    54 // Destructor
       
    55 // ---------------------------------------------------------------------------
       
    56 EXPORT_C CPslnFWBaseView::~CPslnFWBaseView()
       
    57     {
       
    58     iResourceLoader.Close();
       
    59     if ( iContainer )
       
    60         {
       
    61         CAknViewAppUi* appUi = AppUi();
       
    62         if ( appUi )
       
    63             {
       
    64             appUi->RemoveFromStack( iContainer );
       
    65             }
       
    66         delete iContainer;
       
    67         }
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------------------------
       
    71 // CPslnFWBaseView::Container
       
    72 // ---------------------------------------------------------------------------
       
    73 EXPORT_C CPslnFWBaseContainer* CPslnFWBaseView::Container()
       
    74     {
       
    75     return iContainer;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CPslnFWBaseView::SetCurrentItem
       
    80 // ---------------------------------------------------------------------------
       
    81 EXPORT_C void CPslnFWBaseView::SetCurrentItem( TInt aIndex )
       
    82     {
       
    83     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetCurrentItem");
       
    84     if ( aIndex > 0 )
       
    85         {
       
    86         iCurrentItem = aIndex;
       
    87         }
       
    88     else
       
    89         {
       
    90         // If invalid index, set to first.
       
    91         iCurrentItem = 0;
       
    92         }
       
    93     }
       
    94 
       
    95 // ---------------------------------------------------------------------------
       
    96 // CPslnFWBaseView::HandleListBoxEventL
       
    97 // ---------------------------------------------------------------------------
       
    98 EXPORT_C void CPslnFWBaseView::HandleListBoxEventL( CEikListBox* /*aListBox*/,
       
    99                                                 TListBoxEvent aEventType )
       
   100     {
       
   101     switch ( aEventType )
       
   102         {
       
   103         case EEventItemClicked:
       
   104             if ( iContainer && iContainer->iMSKObserver )
       
   105                 {
       
   106                 iContainer->iMSKObserver->CheckMiddleSoftkeyLabelL();
       
   107                 }
       
   108             break;
       
   109         case EEventEnterKeyPressed:
       
   110         case EEventItemDoubleClicked:
       
   111         case EEventItemSingleClicked:
       
   112             HandleListBoxSelectionL();
       
   113             break;
       
   114         default:
       
   115            break;
       
   116         }
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // Sets navi_pane.
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 EXPORT_C void CPslnFWBaseView::SetNaviPaneL()
       
   124     {
       
   125     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetNaviPaneL BEGIN");
       
   126     if ( !iNaviControlContainer )
       
   127         {
       
   128         CAknViewAppUi* appUi = AppUi();
       
   129         if ( appUi )
       
   130             {
       
   131             CEikStatusPane* sp = appUi->StatusPane();
       
   132             iNaviControlContainer = static_cast<CAknNavigationControlContainer*>
       
   133                 ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   134             }
       
   135         }
       
   136 
       
   137     _LIT( KPanicText, "CPslnFWBaseView" );
       
   138     __ASSERT_DEBUG( iNaviControlContainer, User::Panic( KPanicText, KErrGeneral ) );
       
   139     	        
       
   140     if ( iNaviPaneContext )
       
   141         {
       
   142         iNaviControlContainer->PushL( *iNaviPaneContext );
       
   143         }
       
   144     else
       
   145         {
       
   146         iNaviControlContainer->PushDefaultL();
       
   147         }
       
   148     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetNaviPaneL END");
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CPslnFWBaseView::CreateNaviPaneContextL
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 EXPORT_C void CPslnFWBaseView::CreateNaviPaneContextL( TInt /*aResourceId*/ )
       
   156     {
       
   157     // Deprecated.
       
   158     }
       
   159 
       
   160 // ---------------------------------------------------------------------------
       
   161 // Sets navi_pane decorator.
       
   162 // ---------------------------------------------------------------------------
       
   163 //
       
   164 EXPORT_C void CPslnFWBaseView::SetNaviPaneDecorator(
       
   165     CAknNavigationDecorator* aDecorator )
       
   166     {
       
   167     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetNaviPaneDecorator");
       
   168     iNaviPaneContext = aDecorator;
       
   169     }
       
   170 
       
   171 // ---------------------------------------------------------------------------
       
   172 // Sets navi_pane and activates a tab.
       
   173 // ---------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C void CPslnFWBaseView::SetNaviPaneL( const TInt aTabLocation )
       
   176     {
       
   177     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetNaviPaneL w/ param BEGIN");
       
   178     if ( !iNaviControlContainer )
       
   179         {
       
   180         CAknViewAppUi* appUi = AppUi();
       
   181         if ( appUi )
       
   182             {
       
   183             CEikStatusPane* sp = appUi->StatusPane();
       
   184             iNaviControlContainer = static_cast<CAknNavigationControlContainer*>
       
   185                 ( sp->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   186             }
       
   187         }
       
   188     if ( iNaviPaneContext && ( aTabLocation > 0 ) )
       
   189         {
       
   190         CAknTabGroup* tabGrp = static_cast <CAknTabGroup*>
       
   191                     ( iNaviPaneContext->DecoratedControl() );
       
   192         tabGrp->SetActiveTabByIndex( aTabLocation );
       
   193         iNaviControlContainer->PushL( *iNaviPaneContext );
       
   194         }
       
   195     else
       
   196         {
       
   197         iNaviControlContainer->PushDefaultL();
       
   198         }
       
   199     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetNaviPaneL w/ param END");
       
   200     }
       
   201 
       
   202 // ---------------------------------------------------------------------------
       
   203 // Activates the view.
       
   204 // ---------------------------------------------------------------------------
       
   205 //
       
   206 EXPORT_C void CPslnFWBaseView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   207                                         TUid /*aCustomMessageId*/,
       
   208                                         const TDesC8& /*aCustomMessage*/ )
       
   209     {
       
   210     PSLN_TRACE_DEBUG("CPslnFWBaseView::DoActivateL END");
       
   211     iPrevViewId = aPrevViewId;
       
   212     CAknViewAppUi* appUi = AppUi();
       
   213     if ( !iContainer )
       
   214         {
       
   215         CreateContainerL();
       
   216         if ( appUi )
       
   217             {
       
   218             AppUi()->AddToStackL( *this, iContainer );
       
   219             }
       
   220         iContainer->iListBox->SetListBoxObserver( this );
       
   221         }
       
   222 
       
   223 #ifdef RD_CONTROL_PANEL
       
   224     TInt titlePaneResID = KErrNotFound;
       
   225     SetTitlePaneL( titlePaneResID );
       
   226     // Retrieve title pane and set it.
       
   227     CEikStatusPane* sp = iAvkonAppUi->StatusPane();
       
   228     if ( sp )
       
   229         {
       
   230         CAknTitlePane* titlePane = static_cast<CAknTitlePane*>(
       
   231             sp->ControlL( TUid::Uid( EEikStatusPaneUidTitle ) ) );
       
   232         if ( ( titlePaneResID > KErrNone ) && titlePane )
       
   233             {
       
   234             HBufC* titlePaneText = NULL;
       
   235             titlePaneText = StringLoader::LoadLC( titlePaneResID );
       
   236             titlePane->SetTextL( titlePaneText->Des() );
       
   237             CleanupStack::PopAndDestroy( titlePaneText );
       
   238             }
       
   239         }
       
   240 #endif //RD_CONTROL_PANEL
       
   241 
       
   242     PSLN_TRACE_DEBUG("CPslnFWBaseView::DoActivateL END");
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // Deactivates view.
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 EXPORT_C void CPslnFWBaseView::DoDeactivate()
       
   250     {
       
   251     PSLN_TRACE_DEBUG("CPslnFWBaseView::DoDeactivate BEGIN");
       
   252     if ( iContainer )
       
   253         {
       
   254         CAknViewAppUi* appUi = AppUi();
       
   255         if ( appUi )
       
   256             {
       
   257             appUi->RemoveFromStack( iContainer );
       
   258             }
       
   259         delete iContainer;
       
   260         iContainer = NULL;
       
   261         }
       
   262     PSLN_TRACE_DEBUG("CPslnFWBaseView::DoDeactivate END");
       
   263     }
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // Sets the real tab location of the view.
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 EXPORT_C void CPslnFWBaseView::SetTabIndex( TInt aMyTabIndex )
       
   270     {
       
   271     if ( iNaviPaneContext &&
       
   272          IsValidLocation( aMyTabIndex ) )
       
   273         {
       
   274         CAknTabGroup* tabGrp = static_cast <CAknTabGroup*>
       
   275                     ( iNaviPaneContext->DecoratedControl() );
       
   276         if ( tabGrp && ( tabGrp->TabCount() > aMyTabIndex  ) )
       
   277             {
       
   278             iMyTabIndex = aMyTabIndex;
       
   279             }
       
   280         }
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // Gets the real tab location of the view.
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 EXPORT_C TInt CPslnFWBaseView::GetTabIndex() const
       
   288     {
       
   289     return iMyTabIndex;
       
   290     }
       
   291 
       
   292 // ---------------------------------------------------------------------------
       
   293 // Creates container.
       
   294 // ---------------------------------------------------------------------------
       
   295 //
       
   296 EXPORT_C void CPslnFWBaseView::CreateContainerL()
       
   297     {
       
   298     PSLN_TRACE_DEBUG("CPslnFWBaseView::CreateContainerL BEGIN");
       
   299     NewContainerL();
       
   300     iContainer->SetMopParent( this );
       
   301 
       
   302     CPslnFWBaseContainer* container = iContainer;
       
   303     iContainer = NULL;
       
   304     CleanupStack::PushL( container );
       
   305     container->ConstructL( ClientRect() );
       
   306     CleanupStack::Pop( container );
       
   307     iContainer = container;
       
   308     PSLN_TRACE_DEBUG("CPslnFWBaseView::CreateContainerL END");
       
   309     }
       
   310 
       
   311 // ---------------------------------------------------------------------------
       
   312 // Opens localized resource file from static path.
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 EXPORT_C void CPslnFWBaseView::OpenLocalizedResourceFileL(
       
   316     const TDesC& aResourceFileName,
       
   317     RConeResourceLoader& aResourceLoader )
       
   318     {
       
   319     PSLN_TRACE_DEBUG("CPslnFWBaseView::OpenLocalizedResourceFileL BEGIN");
       
   320     // Find the resource file:
       
   321     OpenLocalizedResourceFileL(
       
   322         aResourceFileName,
       
   323         aResourceLoader,
       
   324         &KDC_RESOURCE_FILES_DIR );
       
   325     PSLN_TRACE_DEBUG("CPslnFWBaseView::OpenLocalizedResourceFileL END");
       
   326     }
       
   327 
       
   328 // ---------------------------------------------------------------------------
       
   329 // Same as above, except this takes resource path from user.
       
   330 // ---------------------------------------------------------------------------
       
   331 //
       
   332 EXPORT_C void CPslnFWBaseView::OpenLocalizedResourceFileL(
       
   333             const TDesC& aResourceFileName,
       
   334             RConeResourceLoader& aResourceLoader,
       
   335             const TDesC* aPath )
       
   336     {
       
   337     PSLN_TRACE_DEBUG("CPslnFWBaseView::OpenLocalizedResourceFileL 2 BEGIN");
       
   338     // Find the resource file:
       
   339     TParse* parse = new (ELeave) TParse;
       
   340     CleanupStack::PushL( parse );
       
   341     parse->Set( aResourceFileName, aPath, NULL );
       
   342     TFileName* fileName = new (ELeave) TFileName( parse->FullName() );
       
   343     CleanupStack::PushL( fileName );
       
   344 
       
   345     // Open resource file:
       
   346     aResourceLoader.OpenL( *fileName );
       
   347 
       
   348     CleanupStack::PopAndDestroy( 2, parse ); // fileName, parse
       
   349     PSLN_TRACE_DEBUG("CPslnFWBaseView::OpenLocalizedResourceFileL 2 END");
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------------------------
       
   353 // Sets middle softkey label.
       
   354 // ---------------------------------------------------------------------------
       
   355 //
       
   356 EXPORT_C void CPslnFWBaseView::SetMiddleSoftKeyLabelL(
       
   357     const TInt aResourceId, const TInt aCommandId )
       
   358     {
       
   359     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetMiddleSoftKeyLabelL BEGIN");
       
   360     CEikButtonGroupContainer* cbaGroup = Cba();
       
   361     if ( cbaGroup )
       
   362         {
       
   363         HBufC* middleSKText = StringLoader::LoadLC( aResourceId );
       
   364         TPtr mskPtr = middleSKText->Des();
       
   365         cbaGroup->AddCommandToStackL(
       
   366             KPslnMSKControlID,
       
   367             aCommandId,
       
   368             mskPtr );
       
   369         CleanupStack::PopAndDestroy( middleSKText );
       
   370         }
       
   371     PSLN_TRACE_DEBUG("CPslnFWBaseView::SetMiddleSoftKeyLabelL END");
       
   372     }
       
   373 
       
   374 // ---------------------------------------------------------------------------
       
   375 // Handles Help command.
       
   376 // ---------------------------------------------------------------------------
       
   377 //
       
   378 EXPORT_C void CPslnFWBaseView::HandleCommandL( TInt aCommand )
       
   379     {
       
   380     CAknViewAppUi* appUi = AppUi();
       
   381     if ( !appUi )
       
   382         {
       
   383         User::Leave( KErrNotFound );
       
   384         }
       
   385     switch( aCommand )
       
   386         {
       
   387         case EAknCmdHelp:
       
   388         case EPslnCmdAppHelp:
       
   389             // launch Help
       
   390             HlpLauncher::LaunchHelpApplicationL(
       
   391                 iCoeEnv->WsSession(), appUi->AppHelpContextL());
       
   392             break;
       
   393         default:
       
   394             appUi->HandleCommandL( aCommand );
       
   395             break;
       
   396         }
       
   397     }
       
   398 
       
   399 // ---------------------------------------------------------------------------
       
   400 // Set title pane to a view.
       
   401 // ---------------------------------------------------------------------------
       
   402 //
       
   403 EXPORT_C void CPslnFWBaseView::SetTitlePaneL( TInt& /*aResourceId*/ )
       
   404     {
       
   405     // Empty implementation to be overloaded.
       
   406     }
       
   407 
       
   408 // ----------------------------------------------------------------------------
       
   409 // Checks that the location is valid.
       
   410 // ----------------------------------------------------------------------------
       
   411 //
       
   412 TBool CPslnFWBaseView::IsValidLocation( const TInt& aLoc ) const
       
   413     {
       
   414     TBool retVal = ETrue;
       
   415     // First location is always forbidden.
       
   416     if ( aLoc == KPslnFWGeneralThemeViewLocation )
       
   417         {
       
   418         retVal = EFalse;
       
   419         }
       
   420     return retVal;
       
   421     }
       
   422 
       
   423 //End of File