phonebookui/Phonebook2/Application/src/CPbk2SettingsView.cpp
changeset 0 e686773b3f54
child 21 9da50d567e3c
equal deleted inserted replaced
-1:000000000000 0:e686773b3f54
       
     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:  Phonebook 2 settings application view.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include "CPbk2SettingsView.h"
       
    21 
       
    22 // Phonebook 2
       
    23 #include "CPbk2AppUi.h"
       
    24 #include "CPbk2Document.h"
       
    25 #include <Pbk2Commands.hrh>
       
    26 #include <MPbk2ViewExplorer.h>
       
    27 #include <CPbk2SettingsListControl.h>
       
    28 #include <CPbk2ControlContainer.h>
       
    29 #include <MPbk2ViewActivationTransaction.h>
       
    30 #include <Pbk2UIControls.hrh>
       
    31 #include <CPbk2UIExtensionManager.h>
       
    32 #include <MPbk2UIExtensionFactory.h>
       
    33 #include <MPbk2SettingsViewExtension.h>
       
    34 #include <MPbk2SettingsControlExtension.h>
       
    35 #include <CPbk2ContactUiControlSubstitute.h>
       
    36 #include <MPbk2CommandHandler.h>
       
    37 #include <MPbk2ApplicationServices.h>
       
    38 #include <csxhelp/phob.hlp.hrh>
       
    39 #include <Phonebook2.rsg>
       
    40 #include <Pbk2UIControls.rsg>
       
    41 
       
    42 // System includes
       
    43 #include <StringLoader.h>
       
    44 #include <aknnavide.h>  // CAknNavigationDecorator
       
    45 
       
    46 // Debugging headers
       
    47 #include <Pbk2Debug.h>
       
    48 
       
    49 // --------------------------------------------------------------------------
       
    50 // CPbk2SettingsView::CPbk2SettingsView
       
    51 // --------------------------------------------------------------------------
       
    52 //
       
    53 CPbk2SettingsView::CPbk2SettingsView()
       
    54     {
       
    55     }
       
    56 
       
    57 // --------------------------------------------------------------------------
       
    58 // CPbk2SettingsView::~CPbk2SettingsView
       
    59 // --------------------------------------------------------------------------
       
    60 //
       
    61 CPbk2SettingsView::~CPbk2SettingsView()
       
    62     {
       
    63     Release( iSettingsExtension );
       
    64     Release( iSettingsControlExtension );
       
    65     }
       
    66 
       
    67 // --------------------------------------------------------------------------
       
    68 // CPbk2SettingsView::NewL
       
    69 // --------------------------------------------------------------------------
       
    70 //
       
    71 CPbk2SettingsView* CPbk2SettingsView::NewL()
       
    72     {
       
    73     CPbk2SettingsView* self = new ( ELeave ) CPbk2SettingsView();
       
    74     CleanupStack::PushL( self );
       
    75     self->ConstructL();
       
    76     CleanupStack::Pop( self );
       
    77     return self;
       
    78     }
       
    79 
       
    80 // --------------------------------------------------------------------------
       
    81 // CPbk2SettingsView::ConstructL
       
    82 // --------------------------------------------------------------------------
       
    83 //
       
    84 inline void CPbk2SettingsView::ConstructL()
       
    85     {
       
    86     BaseConstructL( R_PHONEBOOK2_SETTINGS_APPVIEW );
       
    87     }
       
    88 
       
    89 // --------------------------------------------------------------------------
       
    90 // CPbk2SettingsView::HandleCommandL
       
    91 // --------------------------------------------------------------------------
       
    92 //
       
    93 void CPbk2SettingsView::HandleCommandL( TInt aCommandId )
       
    94     {
       
    95     if ( !iSettingsExtension->HandleCommandL( aCommandId ) )
       
    96         {
       
    97         switch ( aCommandId )
       
    98             {
       
    99             case EAknSoftkeyBack:               // FALLTHROUGH
       
   100             case EPbk2CmdOpenPreviousView:
       
   101                 {                    
       
   102                 CPbk2ViewState* state = ViewStateLC();
       
   103                 // To be sure that there is a view uid available.
       
   104                 // In some rare cases there is no view uid.
       
   105                 if ( iPreviousViewId.iAppUid == TUid::Uid( 0 ) && 
       
   106                      iPreviousViewId.iViewUid == TUid::Uid( 0 ) )
       
   107                     {                    
       
   108                     Pbk2AppUi()->Pbk2ViewExplorer()->ActivatePreviousViewL
       
   109                         ( state );                    
       
   110                     }
       
   111                 else
       
   112                     {
       
   113                     Pbk2AppUi()->Pbk2ViewExplorer()->ActivatePhonebook2ViewL
       
   114                         ( iPreviousViewId.iViewUid, state );                    
       
   115                     }
       
   116                 CleanupStack::PopAndDestroy(state);
       
   117                 break;
       
   118                 }
       
   119             case EPbk2CmdEditSetting:
       
   120                 {
       
   121                 iControl->EditItemL(
       
   122                         iControl->ListBox()->CurrentItemIndex(), ETrue );       
       
   123                 break;
       
   124                 }
       
   125             case EAknCmdHelp:
       
   126                 {
       
   127                 // Help does not need uiControl so we fake it,
       
   128                 // then we can use commandhandler for help
       
   129                 CPbk2ContactUiControlSubstitute* uiControlSubstitute =
       
   130                     CPbk2ContactUiControlSubstitute::NewL();
       
   131                 CleanupStack::PushL( uiControlSubstitute );
       
   132 
       
   133                 Pbk2AppUi()->ApplicationServices().CommandHandlerL()->
       
   134                     HandleCommandL
       
   135                         ( aCommandId, *uiControlSubstitute, this );
       
   136                 CleanupStack::PopAndDestroy( uiControlSubstitute );
       
   137                 break;
       
   138                 }
       
   139             default:
       
   140                 {
       
   141                 AppUi()->HandleCommandL( aCommandId );
       
   142                 break;
       
   143                 }
       
   144             };
       
   145         }
       
   146     }
       
   147 
       
   148 // --------------------------------------------------------------------------
       
   149 // CPbk2SettingsView::DynInitMenuPaneL
       
   150 // --------------------------------------------------------------------------
       
   151 //
       
   152 void CPbk2SettingsView::DynInitMenuPaneL
       
   153         ( TInt aResourceId, CEikMenuPane* aMenuPane )
       
   154     {
       
   155     iSettingsExtension->DynInitMenuPaneL( aResourceId, aMenuPane );
       
   156     }
       
   157 
       
   158 // --------------------------------------------------------------------------
       
   159 // CPbk2SettingsView::Id
       
   160 // --------------------------------------------------------------------------
       
   161 //
       
   162 TUid CPbk2SettingsView::Id() const
       
   163     {
       
   164     return Phonebook2::KPbk2SettingsViewUid;
       
   165     }
       
   166 
       
   167 // --------------------------------------------------------------------------
       
   168 // CPbk2SettingsView::HandleStatusPaneSizeChange
       
   169 // --------------------------------------------------------------------------
       
   170 //
       
   171 void CPbk2SettingsView::HandleStatusPaneSizeChange()
       
   172     {
       
   173     // Resize the container to fill the client rectangle
       
   174     if ( iContainer )
       
   175         {
       
   176         iContainer->SetRect( ClientRect() );
       
   177         }
       
   178     }
       
   179 
       
   180 // --------------------------------------------------------------------------
       
   181 // CPbk2SettingsView::DoActivateL
       
   182 // --------------------------------------------------------------------------
       
   183 //
       
   184 void CPbk2SettingsView::DoActivateL( const TVwsViewId& aPrevViewId,
       
   185         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/ )
       
   186     {
       
   187     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   188         ("CPbk2SettingsView(%x)::DoActivateL()"), this );
       
   189 
       
   190     if ( !iSettingsExtension )
       
   191         {
       
   192         iSettingsExtension =
       
   193             Pbk2AppUi()->PhonebookDocument()->ExtensionManager().FactoryL()->
       
   194                 CreatePbk2SettingsViewExtensionL
       
   195                     ( Pbk2AppUi()->ApplicationServices().ContactManager() );
       
   196         }
       
   197 
       
   198     HBufC* title = StringLoader::LoadLC( R_PHOB_SET_TITLE );
       
   199 
       
   200     MPbk2ViewActivationTransaction* viewActivationTransaction =
       
   201         Pbk2AppUi()->Pbk2ViewExplorer()->HandleViewActivationLC
       
   202             ( Id(), aPrevViewId, title, NULL,
       
   203               Phonebook2::EUpdateNaviPane | Phonebook2::EUpdateTitlePane |
       
   204               Phonebook2::EUpdateContextPane );
       
   205 
       
   206     CreateControlsL();
       
   207 
       
   208     // Create empty navigation pane
       
   209     if (!iNaviPane)
       
   210         {
       
   211         iNaviPane = static_cast<CAknNavigationControlContainer*>(
       
   212             iAvkonAppUi->StatusPane()->ControlL(
       
   213             TUid::Uid(EEikStatusPaneUidNavi)));
       
   214         }
       
   215     if ( !iNaviDecorator )
       
   216         {
       
   217         iNaviDecorator = iNaviPane->CreateNavigationLabelL();
       
   218         iNaviPane->PushL(*iNaviDecorator);
       
   219         }
       
   220 
       
   221     // Transaction is commited after all leaving code has been executed
       
   222     viewActivationTransaction->Commit();
       
   223     CleanupStack::PopAndDestroy( 2 ); // viewActivationTransaction, title
       
   224 
       
   225     iContainer->SetHelpContext( TCoeHelpContext( ApplicationUid(),
       
   226         KPHOB_HLP_SETTINGS ));
       
   227         
       
   228     iPreviousViewId = aPrevViewId;        
       
   229     }
       
   230 
       
   231 // --------------------------------------------------------------------------
       
   232 // CPbk2SettingsView::DoDeactivate
       
   233 // --------------------------------------------------------------------------
       
   234 //
       
   235 void CPbk2SettingsView::DoDeactivate()
       
   236     {
       
   237     PBK2_DEBUG_PRINT(PBK2_DEBUG_STRING
       
   238         ("CPbk2SettingsView(%x)::DoDeactivate()"), this );
       
   239 
       
   240     if (iNaviPane && iNaviDecorator)
       
   241         {
       
   242         iNaviPane->Pop(iNaviDecorator);
       
   243         }
       
   244     delete iNaviDecorator;
       
   245     iNaviDecorator = NULL;
       
   246 
       
   247     if ( iContainer )
       
   248         {
       
   249         AppUi()->RemoveFromStack( iContainer );
       
   250         delete iContainer;
       
   251         iContainer = NULL;
       
   252         }
       
   253 
       
   254     Release( iSettingsExtension );
       
   255     iSettingsExtension = NULL;
       
   256     Release( iSettingsControlExtension );
       
   257     iSettingsControlExtension = NULL;
       
   258     }
       
   259 
       
   260 // --------------------------------------------------------------------------
       
   261 // CPbk2SettingsView::GetViewSpecificMenuFilteringFlagsL
       
   262 // --------------------------------------------------------------------------
       
   263 //
       
   264 TInt CPbk2SettingsView::GetViewSpecificMenuFilteringFlagsL() const
       
   265     {
       
   266     return 0;
       
   267     }
       
   268 
       
   269 // --------------------------------------------------------------------------
       
   270 // CPbk2SettingsView::CreateControlsL
       
   271 // --------------------------------------------------------------------------
       
   272 //
       
   273 inline void CPbk2SettingsView::CreateControlsL()
       
   274     {
       
   275     if ( !iSettingsControlExtension )
       
   276         {
       
   277         iSettingsControlExtension =
       
   278             iSettingsExtension->CreatePbk2SettingsControlExtensionL();
       
   279         }
       
   280 
       
   281     if ( !iContainer )
       
   282         {
       
   283         // Create the container and control
       
   284         CContainer* container = CContainer::NewLC( this, NULL, *this );
       
   285 
       
   286         container->SetHelpContext
       
   287             ( TCoeHelpContext( ApplicationUid(), KPHOB_HLP_SETTINGS ) );
       
   288 
       
   289         CPbk2SettingsListControl* control = CPbk2SettingsListControl::NewL
       
   290             ( container,
       
   291               Pbk2AppUi()->ApplicationServices().SortOrderManager(),
       
   292               *iSettingsControlExtension );
       
   293         CleanupStack::PushL( control );
       
   294 
       
   295         container->SetControl( control, ClientRect() ); // takes ownership
       
   296         CleanupStack::Pop( control );
       
   297 
       
   298         container->SetMopParent( this );
       
   299         container->MakeVisible( ETrue );
       
   300 
       
   301         AppUi()->AddToStackL( *this, container );
       
   302         CleanupStack::Pop( container );
       
   303         iContainer = container;
       
   304         iControl = control;
       
   305 
       
   306         container->ActivateL();
       
   307         }
       
   308     }
       
   309 
       
   310 //  End of File