landmarksui/app/src/CLmkAppUi.cpp
branchRCL_3
changeset 17 1fc85118c3ae
parent 16 8173571d354e
child 18 870918037e16
equal deleted inserted replaced
16:8173571d354e 17:1fc85118c3ae
     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:    LandmarksUi Content File -    Provides LM UI class methods.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 // INCLUDE FILES
       
    25 #include "LmkUID.h"
       
    26 #include "CLmkAppUi.h"
       
    27 #include "landmarks.hrh"
       
    28 #include "CLmkDocument.h"
       
    29 #include "CLmkByLmView.h"
       
    30 #include "CLmkByCategoryView.h"
       
    31 #include "CLmkCategorySettingsView.h"
       
    32 #include "CLmkCategoryContentsView.h"
       
    33 #include "CLmkSender.h"
       
    34 #include "Debug.h"
       
    35 #include <AknsUtils.h>
       
    36 #include <hlplch.h>
       
    37 #include <StringLoader.h>
       
    38 #include <aknnotewrappers.h>
       
    39 #include <AknQueryDialog.h>
       
    40 #include <landmarks.rsg>
       
    41 #include <lmkerrors.h>
       
    42 
       
    43 #if defined(_DEBUG)
       
    44 // CONSTANTS
       
    45 /// Unnamed namespace for local definitions
       
    46 namespace {
       
    47 
       
    48 _LIT( KPanicMsg, "CLmkAppUi");
       
    49 
       
    50 void Panic( TPanicCode aReason )
       
    51     {
       
    52     User::Panic( KPanicMsg, aReason );
       
    53     }
       
    54 }  // namespace
       
    55 #endif
       
    56 // ================= MEMBER FUNCTIONS =======================
       
    57 
       
    58 // ----------------------------------------------------------
       
    59 // CLmkAppUi::ConstructL
       
    60 // ----------------------------------------------------------
       
    61 //
       
    62 void CLmkAppUi::ConstructL()
       
    63     {
       
    64     DEBUG( CLmkAppUi::ConstructL entered );
       
    65 
       
    66     BaseConstructL( EAknEnableSkin | EAknEnableMSK | EAknSingleClickCompatible);
       
    67 
       
    68     TRAPD( err, iLmkSender = CLmkSender::NewL( Document().LmDbL() ));
       
    69     DEBUG1( CLmkAppUi::ConstructL err=%d,err );
       
    70     if(err == KErrLocked)
       
    71     	{
       
    72 	    HBufC* noteText = StringLoader::LoadL( R_LMK_ERR_EIKON_GENERAL, iEikonEnv );
       
    73 	    CleanupStack::PushL( noteText );
       
    74 	    CAknErrorNote* dialog = new(ELeave)CAknErrorNote( ETrue );
       
    75 	    dialog->SetTone( CAknNoteDialog::EErrorTone );
       
    76 	    dialog->ExecuteLD( *noteText );
       
    77 	    CleanupStack::PopAndDestroy( noteText ); //noteText
       
    78 	    User::Exit(0);
       
    79     	}
       
    80 
       
    81     DEBUG( CLmkAppUi::ConstructL: creating views );
       
    82 
       
    83     CLmkBaseView* byLmView = CLmkByLmView::NewLC( *this, *iLmkSender );
       
    84 
       
    85     AddViewL( byLmView ); // transfer ownership to CAknViewAppUi
       
    86     CleanupStack::Pop(); // byLmView
       
    87 
       
    88     CLmkBaseView* byCategoryView = CLmkByCategoryView::NewLC( *this );
       
    89 
       
    90     AddViewL( byCategoryView ); // transfer ownership to CAknViewAppUi
       
    91     CleanupStack::Pop();    // byCategoryView
       
    92 
       
    93     CLmkBaseView* categorySettingsView =
       
    94         CLmkCategorySettingsView::NewLC( *this );
       
    95 
       
    96 
       
    97     AddViewL( categorySettingsView );
       
    98     CleanupStack::Pop();
       
    99 
       
   100     CLmkBaseView* categoryContentsView =
       
   101         CLmkCategoryContentsView::NewLC( *this, *iLmkSender );
       
   102 
       
   103     AddViewL( categoryContentsView );
       
   104     CleanupStack::Pop();
       
   105 
       
   106     SetDefaultViewL( *byLmView );
       
   107 
       
   108     DEBUG( CLmkAppUi::ConstructL finished );
       
   109     }
       
   110 
       
   111 // ----------------------------------------------------
       
   112 // CLmkAppUi::~CLmkAppUi
       
   113 // Destructor
       
   114 // Frees reserved resources
       
   115 // ----------------------------------------------------
       
   116 //
       
   117 CLmkAppUi::~CLmkAppUi()
       
   118     {
       
   119     delete iLmkSender;
       
   120     }
       
   121 
       
   122 // ----------------------------------------------------
       
   123 // CLmkAppUi::HandleCommandL
       
   124 // ----------------------------------------------------
       
   125 //
       
   126 void CLmkAppUi::HandleCommandL( TInt aCommand )
       
   127     {
       
   128     DEBUG1( CLmkAppUi::HandleCommandL entered aCommand=%d, aCommand);
       
   129     switch ( aCommand )
       
   130         {
       
   131         case EAknCmdHelp:
       
   132             {
       
   133             HlpLauncher::LaunchHelpApplicationL( iEikonEnv->WsSession(),
       
   134                                                  AppHelpContextL() );
       
   135             break;
       
   136             }
       
   137         // these all are same: exit
       
   138         case EAknSoftkeyBack:
       
   139         case EAknSoftkeyExit:
       
   140         case EEikCmdExit:
       
   141             {
       
   142             Exit();
       
   143             break;
       
   144             }
       
   145         case ELmkCmdEditCats:
       
   146             {
       
   147             ActivateLocalViewL( TUid::Uid( ELmkCategorySettingsView ) );
       
   148             break;
       
   149             }
       
   150 
       
   151         default:
       
   152             break;
       
   153         }
       
   154     DEBUG( CLmkAppUi::HandleCommandL end );
       
   155     }
       
   156 
       
   157 // ----------------------------------------------------
       
   158 // CLmkAppUi::Document
       
   159 // ----------------------------------------------------
       
   160 //
       
   161 CLmkDocument& CLmkAppUi::Document() const
       
   162     {
       
   163     CLmkDocument* document =
       
   164         static_cast<CLmkDocument*>( CEikAppUi::Document() );
       
   165     __ASSERT_DEBUG( document, Panic( KLmkPanicNullMember ) );
       
   166     // Explicit cast: the document must always be of type CLmkDocument
       
   167     return *document;
       
   168     }
       
   169 
       
   170 // ----------------------------------------------------
       
   171 // CLmkAppUi::LmkSender
       
   172 // ----------------------------------------------------
       
   173 //
       
   174 CLmkSender& CLmkAppUi::LmkSender() const
       
   175     {
       
   176     __ASSERT_DEBUG( iLmkSender, Panic( KLmkPanicNullMember ) );
       
   177     return *iLmkSender;
       
   178     }
       
   179 
       
   180 // ----------------------------------------------------
       
   181 // CLmkAppUi::TabChangedL
       
   182 // ----------------------------------------------------
       
   183 //
       
   184 void CLmkAppUi::TabChangedL(TInt aIndex)
       
   185     {
       
   186 
       
   187     // Gets a subpane control by ID
       
   188     CAknNavigationControlContainer* naviCtrlContainer =
       
   189         static_cast<CAknNavigationControlContainer*>
       
   190         ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) );
       
   191     __ASSERT_DEBUG( naviCtrlContainer, Panic( KLmkPanicNullMember ) );
       
   192 
       
   193     // Return topmost object from navigation pane's object stack.
       
   194     CAknNavigationDecorator* decorator = naviCtrlContainer->Top();
       
   195     __ASSERT_DEBUG( decorator && decorator->ControlType() ==
       
   196                     CAknNavigationDecorator::ETabGroup,
       
   197                     Panic( KLmkPanicNullMember ) );
       
   198 
       
   199     CAknTabGroup* tabGroup =
       
   200         static_cast< CAknTabGroup* > ( decorator->DecoratedControl() );
       
   201     __ASSERT_DEBUG( tabGroup && aIndex >= 0 && aIndex < tabGroup->TabCount(),
       
   202                     Panic( KLmkPanicNullMember ) );
       
   203     ActivateLocalViewL( TUid::Uid( tabGroup->TabIdFromIndex( aIndex ) ) );
       
   204     }
       
   205 
       
   206 // ----------------------------------------------------
       
   207 // CLmkAppUi::ProcessKeyEventL
       
   208 // ----------------------------------------------------
       
   209 //
       
   210 TBool CLmkAppUi::ProcessKeyEventL(
       
   211     const TKeyEvent& /*aKeyEvent*/,
       
   212     TEventCode /*aType*/ )
       
   213     {
       
   214     return EKeyWasNotConsumed;
       
   215     }
       
   216 
       
   217 // ----------------------------------------------------
       
   218 // CLmkAppUi::TabObserver
       
   219 // ----------------------------------------------------
       
   220 //
       
   221 MAknTabObserver* CLmkAppUi::TabObserver()
       
   222     {
       
   223     return this;
       
   224     }
       
   225 
       
   226 // ----------------------------------------------------
       
   227 // CLmkAppUi::HandleViewDeactivation
       
   228 // ----------------------------------------------------
       
   229 //
       
   230 void CLmkAppUi::HandleViewDeactivation(const TVwsViewId &aViewIdToBeDeactivated,
       
   231                                             const TVwsViewId &    aNewlyActivatedViewId  )
       
   232     {
       
   233     // closing all intermediate state events
       
   234 	iAvkonEnv->CloseAllIntermediateStates();
       
   235 
       
   236     if( aNewlyActivatedViewId.iAppUid ==  TUid::Uid( KLmkAppUID3 ) )
       
   237         {
       
   238         	if ( aNewlyActivatedViewId.iViewUid  == TUid::Uid( ELmkByCategoryView )  && aViewIdToBeDeactivated.iViewUid  == TUid::Uid( ELmkByLmView))
       
   239         	{
       
   240         	    // Gets a subpane control by ID
       
   241         	    CAknNavigationControlContainer* naviCtrlContainer = NULL;
       
   242             TRAP_IGNORE(naviCtrlContainer =
       
   243                 static_cast<CAknNavigationControlContainer*>
       
   244                 ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ));
       
   245 
       
   246             // Return topmost object from navigation pane's object stack.
       
   247             CAknNavigationDecorator* decorator = naviCtrlContainer->Top();
       
   248             CAknTabGroup* tabGroup =
       
   249                 static_cast< CAknTabGroup* > ( decorator->DecoratedControl() );
       
   250 
       
   251         		if(tabGroup)
       
   252         		{
       
   253         			tabGroup->SetActiveTabById(ELmkByCategoryView);
       
   254         			tabGroup->DrawDeferred();
       
   255         			decorator->DrawDeferred();
       
   256         		}
       
   257         	}
       
   258 
       
   259         	if( aNewlyActivatedViewId.iViewUid  == TUid::Uid( ELmkByLmView) && aViewIdToBeDeactivated.iViewUid  == TUid::Uid( ELmkByCategoryView) )
       
   260         	{
       
   261         	    // Gets a subpane control by ID
       
   262         		CAknNavigationControlContainer* naviCtrlContainer = NULL;
       
   263             TRAP_IGNORE(naviCtrlContainer =
       
   264                 static_cast<CAknNavigationControlContainer*>
       
   265                 ( StatusPane()->ControlL( TUid::Uid( EEikStatusPaneUidNavi ) ) ) );
       
   266 
       
   267             // Return topmost object from navigation pane's object stack.
       
   268             CAknNavigationDecorator* decorator = naviCtrlContainer->Top();
       
   269             CAknTabGroup* tabGroup =
       
   270                 static_cast< CAknTabGroup* > ( decorator->DecoratedControl() );
       
   271         		if(tabGroup)
       
   272         		{
       
   273         			tabGroup->SetActiveTabById(ELmkByLmView);
       
   274         			tabGroup->DrawDeferred();
       
   275         			decorator->DrawDeferred();
       
   276         		}
       
   277         	}
       
   278         }
       
   279     }
       
   280 
       
   281 // End of File