landmarksui/uicontrols/src/CLmkSelectorImplBase.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 "CLmkSelectorImplBase.h"
       
    27 #include "CLmkListProviderBase.h"
       
    28 #include "CLmkSelectorIconMgr.h"
       
    29 #include "MLmkListMemento.h"
       
    30 #include "CLmkUiUtils.h"
       
    31 #include "LmkConsts.h"
       
    32 #include <avkon.mbg>
       
    33 #include <AknIconArray.h>
       
    34 #include <eikenv.h>
       
    35 #include <lmkerrors.h>
       
    36 
       
    37 
       
    38 // CONSTANTS
       
    39 /// Unnamed namespace for local definitions
       
    40 namespace {
       
    41 const TInt KIconArrayGranularity( 10 );
       
    42 #if defined(_DEBUG)
       
    43 
       
    44 _LIT( KPanicMsg, "CLmkSelectorImplBase" );
       
    45 
       
    46 void Panic( TPanicCode aReason )
       
    47     {
       
    48     User::Panic( KPanicMsg, aReason );
       
    49     }
       
    50 #endif
       
    51 }  // namespace
       
    52 
       
    53 
       
    54 // -----------------------------------------------------------------------------
       
    55 // CLmkSelectorImplBase::TLmkRestoreData::TLmkRestoreData
       
    56 // Constructor of an internal helper class.
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CLmkSelectorImplBase::TLmkRestoreData::TLmkRestoreData()
       
    60     : iRestoreRequested( EFalse ),
       
    61       iListBox( NULL ),
       
    62       iProvider( NULL ),
       
    63       iFiltered( EFalse )
       
    64     {
       
    65     }
       
    66 
       
    67 // ============================ MEMBER FUNCTIONS ===============================
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // CLmkSelectorImplBase::CLmkSelectorImplBase
       
    71 // C++ default constructor can NOT contain any code, that
       
    72 // might leave.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 CLmkSelectorImplBase::CLmkSelectorImplBase( CPosLandmarkDatabase& aDb )
       
    76     : iDb( aDb ),
       
    77       iSelectorImplBaseLatestListEvent( ELmkEventNull )
       
    78 
       
    79     {
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CLmkSelectorImplBase::BaseConstructL
       
    84 // Symbian 2nd phase constructor can leave.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CLmkSelectorImplBase::BaseConstructL()
       
    88     {
       
    89     iEnv = CEikonEnv::Static();
       
    90     iLmkUiUtils = CLmkUiUtils::NewL();
       
    91     iLmkUiUtils->ReadLmkUiResourceFileL();
       
    92     SetupListProviderL();
       
    93     }
       
    94 
       
    95 // ----------------------------------------------------
       
    96 // CLmkSelectorImplBase::~CLmkSelectorImplBase
       
    97 // ----------------------------------------------------
       
    98 //
       
    99 CLmkSelectorImplBase::~CLmkSelectorImplBase()
       
   100     {
       
   101     delete iLmkUiUtils;
       
   102     delete iListProvider;
       
   103     delete iIconMgr;
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CLmkSelectorImplBase::SetMemento
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void CLmkSelectorImplBase::SetMemento( MLmkListMemento& aMemento )
       
   111     {
       
   112     iMemento = &aMemento;
       
   113     }
       
   114 
       
   115 // ----------------------------------------------------
       
   116 // CLmkSelectorImplBase::SetupIconMgrLC
       
   117 // ----------------------------------------------------
       
   118 //
       
   119 CAknIconArray* CLmkSelectorImplBase::SetupIconMgrLC()
       
   120     {
       
   121     CAknIconArray* icons =
       
   122         new( ELeave ) CAknIconArray( KIconArrayGranularity );
       
   123     CleanupStack::PushL( icons );
       
   124 
       
   125     delete iIconMgr;
       
   126     iIconMgr = NULL;
       
   127     iIconMgr = CLmkSelectorIconMgr::NewL( *icons );
       
   128     TFileName* iconFile = CLmkUiUtils::LmkUiIconFileLC();
       
   129 
       
   130     iIconMgr->SetDefaultIconL( CLmkSelectorIconMgr::ELandmarkDefaultIcon,
       
   131                         *iconFile, KLmkDefaultId );
       
   132 
       
   133     iIconMgr->SetDefaultIconL( CLmkSelectorIconMgr::ECategoryDefaultIcon,
       
   134                         *iconFile, KCategoryDefaultId );
       
   135 
       
   136     __ASSERT_DEBUG( iListProvider, Panic( KLmkPanicNullListProvider ) );
       
   137     iListProvider->SetIconMgrL( *iIconMgr );
       
   138     CleanupStack::PopAndDestroy();//iconFile
       
   139     return icons;
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CLmkSelectorImplBase::Store
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 void CLmkSelectorImplBase::Store(
       
   147     const CEikListBox& aListBox,
       
   148     const CLmkListProviderBase& aProvider,
       
   149     TBool aFiltered )
       
   150     {
       
   151     if ( iMemento && iSelectorImplBaseLatestListEvent == ELmkEventListReady )
       
   152         {
       
   153         iMemento->Store( aListBox, aProvider, aFiltered );
       
   154         }
       
   155     // If list is not ready then store doesn't make sense and we don't do
       
   156     // anything.
       
   157     }
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 // CLmkSelectorImplBase::Restore
       
   161 // -----------------------------------------------------------------------------
       
   162 //
       
   163 void CLmkSelectorImplBase::Restore(
       
   164     const CEikListBox& aListBox,
       
   165     const CLmkListProviderBase& aProvider,
       
   166     TBool aFiltered )
       
   167     {
       
   168     if ( iMemento )
       
   169         {
       
   170         if ( iSelectorImplBaseLatestListEvent == ELmkEventListReady )
       
   171             {
       
   172             iMemento->Restore( aListBox, aProvider, aFiltered );
       
   173             }
       
   174         else
       
   175             {
       
   176             // restore cannot be done yet, it is postponed:
       
   177             iRestoreData.iRestoreRequested = ETrue;
       
   178             iRestoreData.iListBox = &aListBox;
       
   179             iRestoreData.iProvider = &aProvider;
       
   180             iRestoreData.iFiltered = aFiltered;
       
   181             }
       
   182         }
       
   183     }
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CLmkSelectorImplBase::HandleListProviderEvent
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CLmkSelectorImplBase::HandleListProviderEvent(
       
   190     TLmkListProviderEventType aEvent )
       
   191     {
       
   192     iSelectorImplBaseLatestListEvent = aEvent;
       
   193 
       
   194     if ( ( iSelectorImplBaseLatestListEvent == ELmkEventListReady
       
   195     		|| iSelectorImplBaseLatestListEvent == ELmkEventItemAdditionComplete ) &&
       
   196          iRestoreData.iRestoreRequested )
       
   197         { // Postponed memento restoration
       
   198         __ASSERT_DEBUG( iRestoreData.iListBox && iRestoreData.iProvider,
       
   199                         Panic( KLmkPanicPostponedRestoration ) );
       
   200         iMemento->Restore( *iRestoreData.iListBox,
       
   201                            *iRestoreData.iProvider,
       
   202                            iRestoreData.iFiltered );
       
   203         // It is enough to turn off iRestoreRequested:
       
   204         iRestoreData.iRestoreRequested = EFalse;
       
   205         }
       
   206     }
       
   207 
       
   208 //  End of File