landmarksui/uicontrols/src/CLmkDlgLmSelectorImpl.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 -
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 // INCLUDE FILES
       
    26 #include "CLmkDlgLmSelectorImpl.h"
       
    27 #include "CLmkMultiSelectorDialog.h"
       
    28 #include "CLmkLmItemListProvider.h"
       
    29 #include "LmkListProviderFactory.h"
       
    30 #include <lmkui.rsg>
       
    31 #include "CLmkDbUtils.h"
       
    32 #include "CLmkUiUtils.h"
       
    33 
       
    34 #include <EPos_CPosLmSearchCriteria.h>
       
    35 #include <EPos_CPosLmCategoryCriteria.h>
       
    36 #include <EPos_CPosLmCategoryManager.h>
       
    37 #include <eiktxlbx.h>
       
    38 #include <lmkerrors.h>
       
    39 
       
    40 
       
    41 #if defined(_DEBUG)
       
    42 
       
    43 // CONSTANTS
       
    44 /// Unnamed namespace for local definitions
       
    45 namespace {
       
    46 
       
    47 _LIT( KPanicMsg, "CLmkDlgLmSelectorImpl" );
       
    48 
       
    49 void Panic( TPanicCode aReason )
       
    50     {
       
    51     User::Panic( KPanicMsg, aReason );
       
    52     }
       
    53 }  // namespace
       
    54 #endif
       
    55 // ============================ MEMBER FUNCTIONS ===============================
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CLmkDlgLmSelectorImpl::CLmkDlgLmSelectorImpl
       
    59 // C++ default constructor can NOT contain any code, that
       
    60 // might leave.
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CLmkDlgLmSelectorImpl::CLmkDlgLmSelectorImpl(
       
    64     CPosLandmarkDatabase& aDb )
       
    65     : CLmkDlgSelectorImplBase( aDb )
       
    66     {
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CLmkDlgLmSelectorImpl::CLmkDlgLmSelectorImpl
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CLmkDlgLmSelectorImpl::CLmkDlgLmSelectorImpl(
       
    76     CPosLandmarkDatabase& aDb,
       
    77     CPosLmSearchCriteria* aCriteria )
       
    78     : CLmkDlgSelectorImplBase( aDb ),
       
    79       iCriteria( aCriteria )
       
    80     {
       
    81     }
       
    82 
       
    83 // -----------------------------------------------------------------------------
       
    84 // CLmkDlgLmSelectorImpl::ConstructL
       
    85 // Symbian 2nd phase constructor can leave.
       
    86 // -----------------------------------------------------------------------------
       
    87 //
       
    88 void CLmkDlgLmSelectorImpl::ConstructL()
       
    89     {
       
    90     BaseConstructL();
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CLmkDlgLmSelectorImpl::NewL
       
    95 // Two-phased constructor.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 EXPORT_C CLmkDlgLmSelectorImpl* CLmkDlgLmSelectorImpl::NewL(
       
    99     CPosLandmarkDatabase& aDb )
       
   100     {
       
   101     CLmkDlgLmSelectorImpl* self =
       
   102         new( ELeave ) CLmkDlgLmSelectorImpl( aDb );
       
   103 
       
   104     CleanupStack::PushL( self );
       
   105     self->ConstructL();
       
   106     CleanupStack::Pop();
       
   107 
       
   108     return self;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // CLmkDlgLmSelectorImpl::NewL
       
   113 // Two-phased constructor.
       
   114 // -----------------------------------------------------------------------------
       
   115 //
       
   116 EXPORT_C CLmkDlgLmSelectorImpl* CLmkDlgLmSelectorImpl::NewL(
       
   117     CPosLandmarkDatabase& aDb,
       
   118     CPosLmSearchCriteria* aCriteria )
       
   119     {
       
   120     CLmkDlgLmSelectorImpl* self =
       
   121         new( ELeave ) CLmkDlgLmSelectorImpl( aDb, aCriteria );
       
   122 
       
   123     CleanupStack::PushL( self );
       
   124     self->ConstructL();
       
   125     CleanupStack::Pop();
       
   126 
       
   127     return self;
       
   128     }
       
   129 
       
   130 // ----------------------------------------------------
       
   131 // CLmkDlgLmSelectorImpl::~CLmkDlgLmSelectorImpl
       
   132 // ----------------------------------------------------
       
   133 //
       
   134 CLmkDlgLmSelectorImpl::~CLmkDlgLmSelectorImpl()
       
   135     {
       
   136     delete iCriteria;
       
   137     }
       
   138 
       
   139 // ----------------------------------------------------
       
   140 // CLmkDlgLmSelectorImpl::SetupListProviderL
       
   141 // ----------------------------------------------------
       
   142 //
       
   143 void CLmkDlgLmSelectorImpl::SetupListProviderL()
       
   144     {
       
   145     if ( !iListProvider )
       
   146         {
       
   147         if ( iCriteria )
       
   148             {
       
   149             iListProvider =
       
   150                 LmkListProviderFactory::CreateProviderL( iDb, *iCriteria );
       
   151             }
       
   152         else
       
   153             {
       
   154             iListProvider =
       
   155                 LmkListProviderFactory::CreateProviderL( iDb,
       
   156                                                          ELandmarkSelector );
       
   157             }
       
   158         iListProvider->AddObserverL( *this );
       
   159         iListProvider->InitializeL();
       
   160         }
       
   161     }
       
   162 
       
   163 // ----------------------------------------------------
       
   164 // CLmkDlgLmSelectorImpl::ListProvider
       
   165 // ----------------------------------------------------
       
   166 //
       
   167 const CLmkListProviderBase& CLmkDlgLmSelectorImpl::ListProvider() const
       
   168     {
       
   169     __ASSERT_DEBUG( iListProvider, Panic( KLmkPanicNullMember ) );
       
   170     return *iListProvider;
       
   171     }
       
   172 
       
   173 // ----------------------------------------------------
       
   174 // CLmkDlgLmSelectorImpl::GetDlgResources
       
   175 // ----------------------------------------------------
       
   176 //
       
   177 void CLmkDlgLmSelectorImpl::GetDlgResources(
       
   178     TBool aIsSingleSelector,
       
   179     TInt& aTitlePaneResource,
       
   180     TInt& aMenuBarResource,
       
   181     TInt& aDialogResource ) const
       
   182     {
       
   183     aTitlePaneResource = R_LMK_LANDMARK_SELECTOR_TITLE;
       
   184     aMenuBarResource = R_LMK_EMPTY_MENUBAR;
       
   185 
       
   186     if ( aIsSingleSelector )
       
   187         {
       
   188         if ( iCriteria )
       
   189             { // this is a "sub-dialog" when search criteria exists
       
   190             aDialogResource = R_LMK_SELECTOR_OK_BACK_DLG;
       
   191             }
       
   192         else
       
   193             {
       
   194             aDialogResource = R_LMK_SELECTOR_OK_CANCEL_DLG;
       
   195             }
       
   196         }
       
   197     else
       
   198         {
       
   199         if ( iCriteria )
       
   200             { // this is a "sub-dialog" when search criteria exists
       
   201             aDialogResource = R_LMK_SELECTOR_OK_BACK_MULTI_DLG;
       
   202             }
       
   203         else
       
   204             {
       
   205             aDialogResource = R_LMK_SELECTOR_OK_CANCEL_MULTI_DLG;
       
   206             }
       
   207         }
       
   208     }
       
   209 
       
   210 // ----------------------------------------------------
       
   211 // CLmkDlgLmSelectorImpl::HandleListProviderEvent
       
   212 // ----------------------------------------------------
       
   213 //
       
   214 void CLmkDlgLmSelectorImpl::HandleListProviderEvent(
       
   215     TLmkListProviderEventType aEvent )
       
   216     {
       
   217     // Give event to the dialog as the first step since others
       
   218     // may then interact with the updated dialog:
       
   219     if (iCriteria)
       
   220 	    {
       
   221 	    if ( aEvent == ELmkEventCategoryDeleted )
       
   222 		    {
       
   223 		    TBool result = ETrue;
       
   224 		    TRAP_IGNORE( result = CheckDbIfCriteriaCategoryExistsL() );
       
   225 		    if ( !result )
       
   226     		    {
       
   227     		    // Delete the dialog
       
   228     		    delete iDialog;
       
   229     		    iDialog = NULL;
       
   230     		    }
       
   231 		    }
       
   232 		else if ( aEvent == ELmkEventCategoryUpdated )
       
   233 		    {
       
   234 		    TRAP_IGNORE( UpdateNaviLabelL() );
       
   235 		    }
       
   236 	    }
       
   237     if ( iDialog )
       
   238         {
       
   239          iDialog->HandleListProviderEvent( aEvent );
       
   240         }
       
   241 
       
   242     // Base class implementation:
       
   243     CLmkDlgSelectorImplBase::HandleListProviderEvent( aEvent );
       
   244     }
       
   245 
       
   246 // ----------------------------------------------------
       
   247 // CLmkDlgLmSelectorImpl::HandleListProviderError
       
   248 // ----------------------------------------------------
       
   249 //
       
   250 void CLmkDlgLmSelectorImpl::HandleListProviderError( TInt aError )
       
   251     {
       
   252     // Base class implementation:
       
   253     CLmkDlgSelectorImplBase::HandleListProviderError( aError );
       
   254 
       
   255     if ( iDialog )
       
   256         {
       
   257         iDialog->HandleListProviderError( aError );
       
   258         }
       
   259     }
       
   260 
       
   261 // ----------------------------------------------------
       
   262 // CLmkDlgLmSelectorImpl::UpdateNaviLabelL
       
   263 // ----------------------------------------------------
       
   264 //
       
   265 void CLmkDlgLmSelectorImpl::UpdateNaviLabelL()
       
   266     {
       
   267     CPosLmCategoryCriteria* criteria =
       
   268     reinterpret_cast<CPosLmCategoryCriteria*>( iCriteria );
       
   269     TPosLmItemId categoryId( KPosLmNullItemId );
       
   270     categoryId = criteria->CategoryItemId();
       
   271     HBufC* catName = CLmkDbUtils::CategoryNameL( iDb, categoryId );
       
   272     CleanupStack::PushL( catName );
       
   273     iLmkUiUtils->StoreNaviPaneL();
       
   274     iLmkUiUtils->CreateNaviLabelL(catName->Des());
       
   275     CleanupStack::PopAndDestroy(); //catName
       
   276     }
       
   277 
       
   278 // ----------------------------------------------------
       
   279 // CLmkDlgLmSelectorImpl::CheckDbIfCriteriaCategoryExistsL
       
   280 // ----------------------------------------------------
       
   281 //
       
   282 TBool CLmkDlgLmSelectorImpl::CheckDbIfCriteriaCategoryExistsL()
       
   283     {
       
   284     TBool result = ETrue;
       
   285     CPosLmCategoryCriteria* criteria =
       
   286     static_cast<CPosLmCategoryCriteria*>( iCriteria );
       
   287     TPosLmItemId categoryId( KPosLmNullItemId );
       
   288     categoryId = criteria->CategoryItemId();
       
   289     if ( categoryId )
       
   290         {
       
   291         // Construction must fail if category has been deleted:
       
   292 		CPosLmCategoryManager* mgr = CPosLmCategoryManager::NewL( iDb );
       
   293 		CleanupStack::PushL( mgr );
       
   294 		// Leaves with KErrNotFound if category doesn't exist
       
   295 		TInt err = KErrNone;
       
   296 		TRAP(err,CPosLandmarkCategory* category = mgr->ReadCategoryLC( categoryId );CleanupStack::PopAndDestroy( category ));
       
   297 	    if(err == KErrNotFound)
       
   298 		    {
       
   299 		    result = EFalse;
       
   300 		    }
       
   301 		 CleanupStack::PopAndDestroy( 1 );//mgr
       
   302         }
       
   303     return result;
       
   304     }
       
   305 //  End of File