landmarksui/app/src/CLmkByCategoryView.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-2010 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:    Provides LM main view class methods.
       
    15  *
       
    16  */
       
    17 
       
    18 // INCLUDE FILES
       
    19 
       
    20 #include <EPos_CPosLandmarkDatabase.h>
       
    21 #include <aknViewAppUi.h>
       
    22 #include <landmarks.rsg>
       
    23 #include <eikmenup.h>
       
    24 #include <featmgr.h>
       
    25 #include <StringLoader.h>
       
    26 #include <lmkerrors.h>  // for landmarksui panic codes
       
    27 #include "CLmkDocument.h"
       
    28 #include "CLmkAppUi.h"
       
    29 #include "CLmkByCategoryView.h"
       
    30 #include "CLmkByCategoryContainer.h"
       
    31 #include "CLmkAppSelectorImplBase.h"
       
    32 #include "landmarks.hrh"
       
    33 #include "MLmkListMemento.h"
       
    34 #include "Debug.h"
       
    35 #include "LmkConsts.h"
       
    36 #include "clmkmapnavigationinterface.h"
       
    37 
       
    38 #if defined(_DEBUG)
       
    39 // CONSTANTS
       
    40 /// Unnamed namespace for local definitions
       
    41 namespace
       
    42     {
       
    43     _LIT( KPanicMsg, "CLmkByCategoryView" );
       
    44 
       
    45     void Panic(TPanicCode aReason)
       
    46         {
       
    47         User::Panic(KPanicMsg, aReason);
       
    48         }
       
    49     } // namespace
       
    50 #endif
       
    51 
       
    52 // ================= MEMBER FUNCTIONS =======================
       
    53 // ----------------------------------------------------------------------------
       
    54 // CLmkByCategoryView::NewLC( MLmkKeyProcessor& aKeyProcessor )
       
    55 // Two-phased constructor.
       
    56 // ----------------------------------------------------------------------------
       
    57 //
       
    58 CLmkByCategoryView* CLmkByCategoryView::NewLC(MLmkKeyProcessor& aKeyProcessor)
       
    59     {
       
    60     CLmkByCategoryView* self = new (ELeave) CLmkByCategoryView(aKeyProcessor);
       
    61     CleanupStack::PushL(self);
       
    62     self->ConstructL();
       
    63     return self;
       
    64     }
       
    65 // ----------------------------------------------------------------------------
       
    66 // CLmkByCategoryView::CLmkByCategoryView
       
    67 // C++ default constructor can NOT contain any code, that
       
    68 // might leave.
       
    69 // ----------------------------------------------------------------------------
       
    70 //
       
    71 CLmkByCategoryView::CLmkByCategoryView(MLmkKeyProcessor& aKeyProcessor) :
       
    72     CLmkBaseView(aKeyProcessor)
       
    73     {
       
    74     }
       
    75 
       
    76 // ----------------------------------------------------------------------------
       
    77 // CLmkByCategoryView::ConstructL
       
    78 // Symbian 2nd phase constructor can leave.
       
    79 // ----------------------------------------------------------------------------
       
    80 //
       
    81 void CLmkByCategoryView::ConstructL()
       
    82     {
       
    83     if (iEikonEnv->StartedAsServerApp())
       
    84         {
       
    85         BaseConstructL(R_LMK_BYCATEGORY_EMBEDDED_VIEW);
       
    86         isEmbeddedLaunch = ETrue;
       
    87         }
       
    88     else
       
    89         {
       
    90         BaseConstructL(R_LMK_BYCATEGORY_VIEW);
       
    91         }
       
    92 
       
    93     CLmkAppUi* lmkAppUi = static_cast<CLmkAppUi*> (AppUi());
       
    94     CPosLandmarkDatabase& db = lmkAppUi->Document().LmDbL();
       
    95     iMapNavInterface = CLmkMapNavigationInterface::NewL(db);
       
    96     AttachAIWMenuInterestL();
       
    97     }
       
    98 
       
    99 // ----------------------------------------------------------------------------
       
   100 // CLmkByCategoryView::~CLmkByCategoryView
       
   101 // ----------------------------------------------------------------------------
       
   102 //
       
   103 CLmkByCategoryView::~CLmkByCategoryView()
       
   104     {
       
   105     if (iContainer)
       
   106         {
       
   107         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   108         }
       
   109     delete iContainer;
       
   110     delete iListMemento;
       
   111     }
       
   112 
       
   113 // ----------------------------------------------------------------------------
       
   114 // CLmkByCategoryView::AttachAIWMenuInterestL
       
   115 // ----------------------------------------------------------------------------
       
   116 //
       
   117 void CLmkByCategoryView::AttachAIWMenuInterestL()
       
   118     {
       
   119     iMapNavInterface->AttachAIWInterestL(R_LMK_NEW_LANDMARK_SUBMENU,
       
   120             R_LMK_AIW_INTEREST_SELECTFROMMAP);
       
   121     iMapNavInterface->AttachAIWInterestL(R_LMK_BYCATEGORY_MENU,
       
   122             R_LMK_AIW_INTEREST_SHOWONMAP);
       
   123     }
       
   124 
       
   125 // ----------------------------------------------------------------------------
       
   126 // CLmkByCategoryView::BorrowMemento
       
   127 // ----------------------------------------------------------------------------
       
   128 //
       
   129 const MLmkListMemento& CLmkByCategoryView::BorrowMemento()
       
   130     {
       
   131     // This method gets never called before memento is created:
       
   132     __ASSERT_DEBUG( iListMemento, Panic( KLmkPanicIllegalMementoAccess ) );
       
   133     return *iListMemento;
       
   134     }
       
   135 
       
   136 // ----------------------------------------------------------------------------
       
   137 // CLmkByCategoryView::ProcessKeyEventL
       
   138 // ----------------------------------------------------------------------------
       
   139 //
       
   140 TBool CLmkByCategoryView::ProcessKeyEventL(const TKeyEvent& aKeyEvent,
       
   141         TEventCode aType)
       
   142     {
       
   143     return CLmkBaseView::ProcessKeyEventL(aKeyEvent, aType);
       
   144     }
       
   145 
       
   146 // ----------------------------------------------------------------------------
       
   147 // TUid CLmkByCategoryView::Id
       
   148 // ----------------------------------------------------------------------------
       
   149 //
       
   150 TUid CLmkByCategoryView::Id() const
       
   151     {
       
   152     return TUid::Uid(ELmkByCategoryView);
       
   153     }
       
   154 
       
   155 // ----------------------------------------------------------------------------
       
   156 // CLmkByCategoryView::HandleCommandL
       
   157 // ----------------------------------------------------------------------------
       
   158 //
       
   159 void CLmkByCategoryView::HandleCommandL(TInt aCommand)
       
   160     {
       
   161     TInt aiwCmd = iMapNavInterface->GetServiceCmdByMenuCmd(aCommand);
       
   162 
       
   163     // Handles Map and Navigation commands
       
   164     if (KAiwCmdNone != aiwCmd)
       
   165         {
       
   166         switch (aiwCmd)
       
   167             {
       
   168             case KAiwCmdMnShowMap:
       
   169                 {
       
   170                 TInt catId = iContainer->GetCurrentCategoryId();
       
   171                 iMapNavInterface->ShowCategoryOnMapL(catId, aCommand,
       
   172                         CLmkMapNavigationInterface::EByCategoryView);
       
   173                 break;
       
   174                 }
       
   175             case KAiwCmdMnSelectFromMap:
       
   176                 {
       
   177                 iMapNavInterface->SetObserver(&iContainer->SelectorImpl());
       
   178                 iMapNavInterface->GetLandmarkFromMapL(aCommand);
       
   179                 break;
       
   180                 }
       
   181             }
       
   182         return;
       
   183         }
       
   184     switch (aCommand)
       
   185         {
       
   186         case ELmkCmdNewLmCurrentLocation:
       
   187         case ELmkCmdNewLmEmpty:
       
   188         case ELmkCmdLaunchPositionSettings:
       
   189             {
       
   190             iContainer->SelectorImpl().ProcessCommandL(aCommand);
       
   191             break;
       
   192             }
       
   193         case ELmkCmdOpenCat:
       
   194             {
       
   195             // Store current status before activating category contents view:
       
   196             iContainer->SelectorImpl().StoreMemento();
       
   197             AppUi()->ActivateLocalViewL(TUid::Uid(ELmkCategoryContentsView));
       
   198             break;
       
   199             }
       
   200         default:
       
   201             {
       
   202             AppUi()->HandleCommandL(aCommand);
       
   203             break;
       
   204             }
       
   205         }
       
   206     }
       
   207 
       
   208 // ----------------------------------------------------------------------------
       
   209 // CLmkByCategoryView::DynInitMenuPaneL
       
   210 // ----------------------------------------------------------------------------
       
   211 //
       
   212 void CLmkByCategoryView::DynInitMenuPaneL(TInt aResourceId,
       
   213         CEikMenuPane* aMenuPane)
       
   214     {
       
   215     TInt count(iContainer->SelectorImpl().ListVisibleItemCount());
       
   216     iMapNavInterface->HandleMenuOperationL(aResourceId, aMenuPane,
       
   217             ELmkCmdMnNav);
       
   218     switch (aResourceId)
       
   219         {
       
   220         case R_LMK_BYCATEGORY_MENU:
       
   221             {
       
   222             if (count == 0)
       
   223                 {
       
   224                 aMenuPane->SetItemDimmed(ELmkCmdOpenCat, ETrue);
       
   225                 TInt count = aMenuPane->NumberOfItemsInPane();
       
   226                 // Dim show on map when no categories
       
   227                 for (TInt i = 0; i < count; ++i)
       
   228                     {
       
   229                     CEikMenuPaneItem::SData& itemData =
       
   230                             aMenuPane->ItemDataByIndexL(i);
       
   231                     if (iMapNavInterface->GetServiceCmdByMenuCmd(
       
   232                             itemData.iCommandId) == KAiwCmdMnShowMap)
       
   233                         {
       
   234                         aMenuPane->SetItemDimmed(itemData.iCommandId, ETrue);
       
   235                         }
       
   236                     }
       
   237                 }
       
   238             else
       
   239                 {
       
   240                 TInt cnt = aMenuPane->NumberOfItemsInPane();
       
   241                 for (TInt i = 0; i < cnt; ++i)
       
   242                     {
       
   243                     CEikMenuPaneItem::SData& itemData =
       
   244                             aMenuPane->ItemDataByIndexL(i);
       
   245                     if (iMapNavInterface->GetServiceCmdByMenuCmd(
       
   246                             itemData.iCommandId) == KAiwCmdMnShowMap)
       
   247                         {
       
   248                         aMenuPane->SetItemDimmed(itemData.iCommandId, EFalse);
       
   249                         aMenuPane->SetItemSpecific(itemData.iCommandId, ETrue);
       
   250                         }
       
   251                     }
       
   252                 }
       
   253             break;
       
   254             }
       
   255         case R_LMK_MAIN_MENU:
       
   256             {
       
   257             CLmkBaseView::HandleHelpFeature(aMenuPane);
       
   258             break;
       
   259             }
       
   260         case R_LMK_NEW_LANDMARK_SUBMENU:
       
   261             {
       
   262             if (FeatureManager::FeatureSupported(
       
   263                     KFeatureIdLocationFrameworkCore))
       
   264                 {
       
   265                 aMenuPane->SetItemDimmed(ELmkCmdNewLmCurrentLocation, EFalse);
       
   266                 }
       
   267             else
       
   268                 {
       
   269                 aMenuPane->SetItemDimmed(ELmkCmdNewLmCurrentLocation, ETrue);
       
   270                 }
       
   271 
       
   272             if (iIsHideCoordinate)
       
   273                 {
       
   274                 aMenuPane->SetItemDimmed(ELmkCmdNewLmEmpty, ETrue);
       
   275                 }
       
   276             else
       
   277                 {
       
   278                 aMenuPane->SetItemDimmed(ELmkCmdNewLmEmpty, EFalse);
       
   279                 }
       
   280             break;
       
   281             }
       
   282         default:
       
   283             {
       
   284             break;
       
   285             }
       
   286         }
       
   287     }
       
   288 
       
   289 // ----------------------------------------------------------------------------
       
   290 // CLmkByCategoryView::DoActivateL
       
   291 // ----------------------------------------------------------------------------
       
   292 //
       
   293 void CLmkByCategoryView::DoActivateL(const TVwsViewId& /*aPrevViewId*/,
       
   294         TUid /*aCustomMessageId*/, const TDesC8& /*aCustomMessage*/)
       
   295     {
       
   296     DEBUG( CLmkByCategoryView::DoActivateL entered );
       
   297     TRAP_IGNORE(EnableMskMenuL(EFalse));
       
   298     TRAP_IGNORE(EnableMskLabelL(EFalse));
       
   299     if (!iContainer)
       
   300         {
       
   301         iContainer = CLmkByCategoryContainer::NewL(*this, this, ClientRect(),
       
   302                 *this);
       
   303 
       
   304         CLmkAppSelectorImplBase& selector = iContainer->SelectorImpl();
       
   305         AppUi()->AddToStackL(*this, iContainer);
       
   306 #ifdef RD_SCALABLE_UI_V2
       
   307         //for touch event
       
   308         iContainer->SetListBoxObserver(this);
       
   309 #endif//RD_SCALABLE_UI_V2
       
   310         if (!iListMemento)
       
   311             { // Memento not created yet, create it now:
       
   312             iListMemento = selector.MementoL();
       
   313             }
       
   314         selector.SetMemento(*iListMemento);
       
   315         selector.RestoreMemento();
       
   316         EnableMskLabelL(EFalse);
       
   317         }
       
   318     }
       
   319 
       
   320 // ----------------------------------------------------------------------------
       
   321 // CLmkByCategoryView::DoDeactivate
       
   322 // ----------------------------------------------------------------------------
       
   323 //
       
   324 void CLmkByCategoryView::DoDeactivate()
       
   325     {
       
   326     if (iContainer)
       
   327         {
       
   328         iContainer->SelectorImpl().StoreMemento();
       
   329         AppUi()->RemoveFromViewStack(*this, iContainer);
       
   330         }
       
   331     TRAP_IGNORE( EnableMskMenuL( EFalse ) );
       
   332     TRAP_IGNORE( EnableMskLabelL( EFalse ) );
       
   333     delete iContainer;
       
   334     iContainer = NULL;
       
   335     }
       
   336 
       
   337 // ---------------------------------------------------------
       
   338 // CLmkByCategoryView::Update()
       
   339 // ---------------------------------------------------------
       
   340 //
       
   341 void CLmkByCategoryView::Update()
       
   342     {
       
   343     iContainer->SetRect(ClientRect());
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------
       
   347 // CLmkByCategoryView::EnableMskMenuL()
       
   348 // ---------------------------------------------------------
       
   349 //
       
   350 void CLmkByCategoryView::EnableMskMenuL(TBool aEnable)
       
   351     {
       
   352     CEikButtonGroupContainer* cbaGrp = Cba();
       
   353     if (cbaGrp)
       
   354         {
       
   355         if (aEnable)
       
   356             {
       
   357             cbaGrp->RemoveCommandFromStack(KMskCommandPos, ELmkCmdOpenLm);
       
   358             TInt
       
   359                     cbaRes =
       
   360                             isEmbeddedLaunch
       
   361                                              ? R_LMK_SOFTKEYS_OPTIONS_BACK_CONTEXTOPTIONS
       
   362                                                 : R_LMK_SOFTKEYS_OPTIONS_EXIT_CONTEXTOPTIONS;
       
   363             cbaGrp->SetCommandSetL(cbaRes);
       
   364             }
       
   365         //This context menu will always be dimmed.
       
   366         cbaGrp->MakeCommandVisible(EAknSoftkeyContextOptions, EFalse);
       
   367         }
       
   368     }
       
   369 
       
   370 // ---------------------------------------------------------
       
   371 // CLmkByCategoryView::EnableMskLabelL()
       
   372 // ---------------------------------------------------------
       
   373 //
       
   374 void CLmkByCategoryView::EnableMskLabelL(TBool aEnable)
       
   375     {
       
   376     CEikButtonGroupContainer* cbaGrp = Cba();
       
   377     if (cbaGrp)
       
   378         {
       
   379         if (aEnable)
       
   380             {
       
   381             HBufC* mskOpenTxt = NULL;
       
   382             mskOpenTxt = StringLoader::LoadLC(R_LMK_MSK_OPEN, iEikonEnv);
       
   383             cbaGrp->RemoveCommandFromStack(KMskCommandPos,
       
   384                     EAknSoftkeyContextOptions);
       
   385             cbaGrp->AddCommandToStackL(KMskCommandPos, ELmkCmdOpenCat,
       
   386                     mskOpenTxt->Des());
       
   387             cbaGrp->MakeCommandVisible(ELmkCmdOpenCat, ETrue);
       
   388             CleanupStack::PopAndDestroy(mskOpenTxt);
       
   389             }
       
   390         else
       
   391             {
       
   392             cbaGrp->MakeCommandVisible(ELmkCmdOpenCat, EFalse);
       
   393             }
       
   394         }
       
   395     }
       
   396 
       
   397 #ifdef RD_SCALABLE_UI_V2
       
   398 // ---------------------------------------------------------
       
   399 // CLmkByCategoryView::HandleListBoxEventL()
       
   400 // ---------------------------------------------------------
       
   401 //
       
   402 void CLmkByCategoryView::HandleListBoxEventL(CEikListBox* /*aListBox*/,
       
   403         TListBoxEvent aEventType)
       
   404     {
       
   405     switch (aEventType)
       
   406         {
       
   407         // Add enter key handling
       
   408         case EEventEnterKeyPressed:
       
   409             {
       
   410             // Store current status before activating category contents view:
       
   411             if (iContainer->SelectorImpl().ListVisibleItemCount() > 0)
       
   412                 {
       
   413                 iContainer->SelectorImpl().StoreMemento();
       
   414                 static_cast<CAknViewAppUi*> (iAvkonAppUi)-> ActivateLocalViewL(
       
   415                         TUid::Uid(ELmkCategoryContentsView));
       
   416                 }
       
   417             break;
       
   418             }
       
   419         //case EEventItemDoubleClicked:
       
   420         case EEventItemSingleClicked:
       
   421             {
       
   422             HandleCommandL(ELmkCmdOpenCat);
       
   423             break;
       
   424             }
       
   425         default:
       
   426             break;
       
   427         }
       
   428     }
       
   429 #endif//RD_SCALABLE_UI_V2
       
   430 
       
   431 // End of File