profilesapplication/Profiles/ProfileApp/SettingsViewSrc/CProfileTabHandler.cpp
branchRCL_3
changeset 19 cd54903d48da
equal deleted inserted replaced
18:b7fa36b488f8 19:cd54903d48da
       
     1 /*
       
     2 * Copyright (c) 2002 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:  Tab handler for handling tabs in Profiles
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // CLASS HDEADER
       
    21 #include "CProfileTabHandler.h"
       
    22 
       
    23 // INTERNAL INCLUDES
       
    24 #include "CProfileEngineHandler.h"
       
    25 #include "CProfileIndexHandler.h"
       
    26 #include "ProfileEngineConstants.h"
       
    27 
       
    28 // EXTERNAL INCLUDES
       
    29 #include <aknnavi.h>
       
    30 #include <coeaui.h>
       
    31 #include <akntabgrp.h>
       
    32 #include <aknnavide.h>
       
    33 #include <AknUtils.h> // AknTextUtils
       
    34 #include <MProfilesNamesArray.h>
       
    35 
       
    36 #include <MProfileName.h>
       
    37 
       
    38 // ============================ MEMBER FUNCTIONS ===============================
       
    39 
       
    40 // -----------------------------------------------------------------------------
       
    41 // CProfileTabHandler::CProfileTabHandler
       
    42 // C++ constructor can NOT contain any code, that might leave.
       
    43 // -----------------------------------------------------------------------------
       
    44 //
       
    45 CProfileTabHandler::CProfileTabHandler(
       
    46     CProfileEngineHandler& aEngineHandler,
       
    47     CProfileIndexHandler& aIndexHandler,
       
    48     CAknNavigationControlContainer& aNaviPane )
       
    49     :   iEngineHandler( aEngineHandler ),
       
    50         iIndexHandler( aIndexHandler ),
       
    51         iNaviPane( aNaviPane )
       
    52     {
       
    53     }
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // CProfileTabHandler::ConstructL
       
    57 // Symbian 2nd phase constructor can leave.
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 void CProfileTabHandler::ConstructL()
       
    61     {
       
    62     CreateTabGroupL();
       
    63     iNaviPane.PushL( *iNaviDecorator );
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CProfileTabHandler::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 EXPORT_C CProfileTabHandler* CProfileTabHandler::NewL(
       
    72     CProfileEngineHandler& aEngineHandler,
       
    73     CProfileIndexHandler& aIndexHandler,
       
    74     CAknNavigationControlContainer& aNaviPane )
       
    75     {
       
    76     CProfileTabHandler* self = new( ELeave ) CProfileTabHandler(
       
    77         aEngineHandler, aIndexHandler, aNaviPane );
       
    78     CleanupStack::PushL( self );
       
    79     self->ConstructL();
       
    80     CleanupStack::Pop( self );
       
    81     return self;
       
    82     }
       
    83 
       
    84 // Destructor
       
    85 CProfileTabHandler::~CProfileTabHandler()
       
    86     {
       
    87     if( iNaviDecorator )
       
    88         {
       
    89         iNaviPane.Pop( iNaviDecorator );
       
    90         delete iNaviDecorator;
       
    91         }
       
    92     }
       
    93 
       
    94 // -----------------------------------------------------------------------------
       
    95 // CProfileTabHandler::TabGroup
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C CAknTabGroup* CProfileTabHandler::TabGroup() const
       
    99     {
       
   100     return iTabGroup;
       
   101     }
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CProfileTabHandler::SetActiveTab
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CProfileTabHandler::SetActiveTab( TInt aIndex )
       
   108     {
       
   109     iTabGroup->SetActiveTabByIndex( aIndex );
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CProfileTabHandler::RefreshTabsL
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 void CProfileTabHandler::RefreshTabsL()
       
   117     {
       
   118     MProfilesNamesArray* array = iEngineHandler.IdArray();
       
   119     TInt count( array->MdcaCount() );
       
   120     if( iTabGroup->TabCount() == count )
       
   121         {
       
   122         RBuf name;
       
   123         name.CreateL( KProfileMaxNameLength );
       
   124         CleanupClosePushL( name );
       
   125         for( TInt index( 0 ); index < count; index++ )
       
   126             {
       
   127             name.Copy( array->ProfileName( index )->ShortName() );
       
   128             AknTextUtils::DisplayTextLanguageSpecificNumberConversion( name );
       
   129             iTabGroup->ReplaceTabTextL( index, name );
       
   130             }
       
   131         CleanupStack::PopAndDestroy( &name );
       
   132         }
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // CProfileTabHandler::SetTabObserver
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CProfileTabHandler::SetTabObserver( MAknTabObserver* aTabObserver )
       
   140     {
       
   141     iTabObserver = aTabObserver;
       
   142     }
       
   143 
       
   144 // -----------------------------------------------------------------------------
       
   145 // CProfileTabHandler::TabChangedL
       
   146 // CAknTabGroup notifies that tab has changed.
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CProfileTabHandler::TabChangedL( TInt aIndex )
       
   150     {
       
   151     iIndexHandler.StoreIndices();
       
   152     iIndexHandler.SetCurrentProfileIndex( aIndex );
       
   153     if( iTabObserver )
       
   154         {
       
   155         iTabObserver->TabChangedL( aIndex );
       
   156         }
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CProfileTabHandler::CreateTabGroupL
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CProfileTabHandler::CreateTabGroupL()
       
   164     {
       
   165     // Remove all existing tabs, just in case
       
   166     if( iNaviDecorator )
       
   167         {
       
   168         iNaviPane.Pop( iNaviDecorator );
       
   169         delete iNaviDecorator;
       
   170         iNaviDecorator = NULL;
       
   171         }
       
   172 
       
   173     // Create tab group
       
   174     iNaviDecorator = iNaviPane.CreateTabGroupL( this );
       
   175     iTabGroup = static_cast<CAknTabGroup*>( iNaviDecorator->DecoratedControl() );
       
   176 
       
   177     MProfilesNamesArray* array = iEngineHandler.IdArray();
       
   178 
       
   179     RBuf name;
       
   180     name.CreateL( KProfileMaxNameLength );
       
   181     CleanupClosePushL( name );
       
   182     // Add tabs to tab group
       
   183     TInt count( array->MdcaCount() );
       
   184     for( TInt index( 0 ); index < count; index++ )
       
   185         {
       
   186         name.Copy( array->ProfileName( index )->ShortName() );
       
   187         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( name );
       
   188         iTabGroup->AddTabL( index, name );
       
   189         }
       
   190     CleanupStack::PopAndDestroy( &name );
       
   191     
       
   192     // Set tab width
       
   193     TInt tab( KTabWidthWithThreeLongTabs );
       
   194     if( count == 1 )
       
   195         {
       
   196         tab = KTabWidthWithOneTab;
       
   197         }
       
   198     else if( count == 2 )
       
   199         {
       
   200         tab = KTabWidthWithTwoLongTabs;
       
   201         }
       
   202     iTabGroup->SetTabFixedWidthL( tab );
       
   203 
       
   204     // Set active tab
       
   205     iTabGroup->SetActiveTabByIndex( iIndexHandler.CurrentProfileIndex() );
       
   206     }
       
   207 
       
   208 //  End of File