landmarksui/engine/src/CLmkSearchedLmListProvider.cpp
branchRCL_3
changeset 3 3c271c9e6618
parent 0 522cd55cc3d7
equal deleted inserted replaced
0:522cd55cc3d7 3:3c271c9e6618
     1 /*
     1 /*
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:    Filtered landmarks list provider
    14  * Description:    Filtered landmarks list provider
    15 *
    15  *
    16 */
    16  */
    17 
       
    18 
    17 
    19 // SYSTEM INCLUDES
    18 // SYSTEM INCLUDES
    20 #include <EPos_CPosLmPartialReadParameters.h>
    19 #include <EPos_CPosLmPartialReadParameters.h>
    21 #include <EPos_CPosLandmark.h>
    20 #include <EPos_CPosLandmark.h>
    22 #include <EPos_TPosLmSortPref.h>
    21 #include <EPos_TPosLmSortPref.h>
    36 #include "CLmkSearchedLmListProvider.h"
    35 #include "CLmkSearchedLmListProvider.h"
    37 #include "CLmkLandmarkUiItem.h"
    36 #include "CLmkLandmarkUiItem.h"
    38 #include "CLmkAOOperation.h"
    37 #include "CLmkAOOperation.h"
    39 #include "MLmkSelectorIconMgr.h"
    38 #include "MLmkSelectorIconMgr.h"
    40 #include <lmkerrors.h>
    39 #include <lmkerrors.h>
       
    40 #include "Debug.h"
    41 
    41 
    42 // CONSTANTS
    42 // CONSTANTS
    43 _LIT(KSpaceTextCriteria,"* ");
    43 _LIT(KSpaceTextCriteria,"* ");
    44 _LIT(KDefaultTextCriteria,"*");
    44 _LIT(KDefaultTextCriteria,"*");
    45 
    45 
    46 #if defined(_DEBUG)
    46 #if defined(_DEBUG)
    47 // CONSTANTS
       
    48 /// Unnamed namespace for local definitions
    47 /// Unnamed namespace for local definitions
    49 namespace {
    48 namespace
    50 
    49     {
    51 _LIT( KPanicMsg, "CLmkSearchedLmListProvider" );
    50     _LIT( KPanicMsg, "CLmkSearchedLmListProvider" );
    52 
    51     void Panic(TPanicCode aReason)
    53 void Panic( TPanicCode aReason )
    52         {
    54     {
    53         User::Panic(KPanicMsg, aReason);
    55     User::Panic( KPanicMsg, aReason );
    54         }
    56     }
    55     } // namespace
    57 }  // namespace
       
    58 #endif
    56 #endif
       
    57 
    59 // ============================ MEMBER FUNCTIONS ===============================
    58 // ============================ MEMBER FUNCTIONS ===============================
    60 
    59 
    61 // -----------------------------------------------------------------------------
    60 // -----------------------------------------------------------------------------
    62 // CLmkSearchedLmListProvider::CLmkSearchedLmListProvider
    61 // CLmkSearchedLmListProvider::CLmkSearchedLmListProvider
    63 // C++ constructor can NOT contain any code, that
    62 // C++ constructor can NOT contain any code, that
    64 // might leave.
    63 // might leave.
    65 // -----------------------------------------------------------------------------
    64 // -----------------------------------------------------------------------------
    66 //
    65 //
    67 CLmkSearchedLmListProvider::CLmkSearchedLmListProvider(
    66 CLmkSearchedLmListProvider::CLmkSearchedLmListProvider(
    68     CPosLandmarkDatabase& aDb,
    67         CPosLandmarkDatabase& aDb, CPosLmSearchCriteria& aCriteria) :
    69     CPosLmSearchCriteria& aCriteria )
    68     CLmkLmItemListProvider(aDb), iCriteria(aCriteria),
    70     : CLmkLmItemListProvider( aDb ),
    69             iIsSecondSearchStarted(EFalse)
    71       iCriteria( aCriteria ),
       
    72       iIsSecondSearchStarted(EFalse)
       
    73     {
    70     {
    74     }
    71     }
    75 
    72 
    76 // -----------------------------------------------------------------------------
    73 // -----------------------------------------------------------------------------
    77 // CLmkSearchedLmListProvider::ConstructL
    74 // CLmkSearchedLmListProvider::ConstructL
    83     // base class 2nd phase constructor
    80     // base class 2nd phase constructor
    84     CLmkLmItemListProvider::BaseConstructL();
    81     CLmkLmItemListProvider::BaseConstructL();
    85 
    82 
    86     iReadParams = CPosLmPartialReadParameters::NewLC();
    83     iReadParams = CPosLmPartialReadParameters::NewLC();
    87     CleanupStack::Pop(); // iReadParams
    84     CleanupStack::Pop(); // iReadParams
    88     iReadParams->SetRequestedAttributes( CPosLandmark::ELandmarkName |
    85     iReadParams->SetRequestedAttributes(CPosLandmark::ELandmarkName
    89                                          CPosLandmark::EIcon | CPosLandmark::ECategoryInfo);
    86             | CPosLandmark::EIcon | CPosLandmark::ECategoryInfo);
    90 
    87 
    91     iSearch = CPosLandmarkSearch::NewL( iDb );
    88     iSearch = CPosLandmarkSearch::NewL(iDb);
    92     }
    89     }
    93 
    90 
    94 // -----------------------------------------------------------------------------
    91 // -----------------------------------------------------------------------------
    95 // CLmkSearchedLmListProvider::NewL
    92 // CLmkSearchedLmListProvider::NewL
    96 // Two-phased constructor.
    93 // Two-phased constructor.
    97 // -----------------------------------------------------------------------------
    94 // -----------------------------------------------------------------------------
    98 //
    95 //
    99 CLmkSearchedLmListProvider* CLmkSearchedLmListProvider::NewL(
    96 CLmkSearchedLmListProvider* CLmkSearchedLmListProvider::NewL(
   100     CPosLandmarkDatabase& aDb,
    97         CPosLandmarkDatabase& aDb, CPosLmSearchCriteria& aCriteria)
   101     CPosLmSearchCriteria& aCriteria )
       
   102     {
    98     {
   103     CLmkSearchedLmListProvider* self =
    99     CLmkSearchedLmListProvider* self =
   104         new ( ELeave ) CLmkSearchedLmListProvider( aDb, aCriteria );
   100             new (ELeave) CLmkSearchedLmListProvider(aDb, aCriteria);
   105 
   101 
   106     CleanupStack::PushL( self );
   102     CleanupStack::PushL(self);
   107     self->ConstructL();
   103     self->ConstructL();
   108     CleanupStack::Pop();
   104     CleanupStack::Pop();
   109 
   105 
   110     return self;
   106     return self;
   111     }
   107     }
   117 CLmkSearchedLmListProvider::~CLmkSearchedLmListProvider()
   113 CLmkSearchedLmListProvider::~CLmkSearchedLmListProvider()
   118     {
   114     {
   119     delete iReadParams;
   115     delete iReadParams;
   120     delete iSearch;
   116     delete iSearch;
   121     if (iSearchAO)
   117     if (iSearchAO)
   122 		{
   118         {
   123     	iSearchAO->StopOperation();
   119         iSearchAO->StopOperation();
   124     	}
   120         }
   125     delete iSearchAO;
   121     delete iSearchAO;
   126     }
   122     }
   127 
   123 
   128 // ---------------------------------------------------------
   124 // ---------------------------------------------------------
   129 // CLmkSearchedLmListProvider::ItemAtL
   125 // CLmkSearchedLmListProvider::ItemAtL
   130 // ---------------------------------------------------------
   126 // ---------------------------------------------------------
   131 //
   127 //
   132 CLmkUiItemBase* CLmkSearchedLmListProvider::ItemAtL( TInt aIndex )
   128 CLmkUiItemBase* CLmkSearchedLmListProvider::ItemAtL(TInt aIndex)
   133     {
   129     {
   134     __ASSERT_DEBUG( iIconMgr, Panic( KLmkPanicNullMember ) );
   130     __ASSERT_DEBUG( iIconMgr, Panic( KLmkPanicNullMember ) );
   135     //landmark with updated icon, if associated with one cat.
   131     //landmark with updated icon, if associated with one cat.
   136     CPosLandmark* landmark = GetLandmarkLC(aIndex);
   132     CPosLandmark* landmark = GetLandmarkLC(aIndex);
   137     TPtrC mbmFile;
   133     TPtrC mbmFile;
   138     TInt iconFileIndex = -1;
   134     TInt iconFileIndex = -1;
   139     TInt iconListIndex = -1;
   135     TInt iconListIndex = -1;
   140     TInt iconMasktIndex = -1;
   136     TInt iconMasktIndex = -1;
   141     TInt result = landmark->GetIcon( mbmFile, iconFileIndex, iconMasktIndex );
   137     TInt result = landmark->GetIcon(mbmFile, iconFileIndex, iconMasktIndex);
   142     if ( result == KErrNone )
   138     if (result == KErrNone)
   143         {
   139         {
   144         TRAPD(err, iconListIndex =
   140         TRAPD(err, iconListIndex =
   145                     iIconMgr->GetIconL( mbmFile, iconFileIndex ) );
   141                 iIconMgr->GetIconL( mbmFile, iconFileIndex ) );
   146         if ( err == KErrNotFound ) // icon file not found -> fallback to default
   142         if (err == KErrNotFound) // icon file not found -> fallback to default
   147             {
   143             {
   148             iconListIndex = iIconMgr->GetDefaultIconL(
   144             iconListIndex = iIconMgr->GetDefaultIconL(
   149                 MLmkSelectorIconMgr::ELandmarkDefaultIcon );
   145                     MLmkSelectorIconMgr::ELandmarkDefaultIcon);
   150             }
   146             }
   151         }
   147         }
   152     else
   148     else
   153         {
   149         {
   154         iconListIndex = iIconMgr->GetDefaultIconL(
   150         iconListIndex = iIconMgr->GetDefaultIconL(
   155             MLmkSelectorIconMgr::ELandmarkDefaultIcon );
   151                 MLmkSelectorIconMgr::ELandmarkDefaultIcon);
   156         }
   152         }
   157 
   153 
   158     CLmkLandmarkUiItem* uiItem =
   154     CLmkLandmarkUiItem* uiItem = CLmkLandmarkUiItem::NewL(landmark,
   159         CLmkLandmarkUiItem::NewL( landmark, iconListIndex );
   155             iconListIndex);
   160     CleanupStack::Pop(); // landmark, ownership transferred
   156     CleanupStack::Pop(); // landmark, ownership transferred
   161     return uiItem;
   157     return uiItem;
   162     }
   158     }
   163 
   159 
   164 // ---------------------------------------------------------
   160 // ---------------------------------------------------------
   165 // CLmkSearchedLmListProvider::PrepareListL
   161 // CLmkSearchedLmListProvider::PrepareListL
   166 // ---------------------------------------------------------
   162 // ---------------------------------------------------------
   167 //
   163 //
   168 void CLmkSearchedLmListProvider::PrepareListL()
   164 void CLmkSearchedLmListProvider::PrepareListL()
   169     {    
   165     {
       
   166     DEBUG( CLmkSearchedLmListProvider::PrepareListL start );
   170     iCount = 0;
   167     iCount = 0;
   171 
   168 
   172     iDb.SetPartialReadParametersL( *iReadParams );
   169     iDb.SetPartialReadParametersL(*iReadParams);
   173 
   170 
   174     TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName,
   171     TPosLmSortPref sortOrder(CPosLandmark::ELandmarkName,
   175                               TPosLmSortPref::EAscending );
   172             TPosLmSortPref::EAscending);
   176     CPosLmOperation* operation =
   173     CPosLmOperation* operation = iSearch->StartLandmarkSearchL(iCriteria,
   177         iSearch->StartLandmarkSearchL( iCriteria, sortOrder );
   174             sortOrder);
   178     CleanupStack::PushL( operation );
   175     CleanupStack::PushL(operation);
   179     if (iSearchAO)
   176     if (iSearchAO)
   180 		{
   177         {
   181     	iSearchAO->StopOperation();
   178         iSearchAO->StopOperation();
   182 	    delete iSearchAO; // cancel possibly pending operation
   179         delete iSearchAO; // cancel possibly pending operation
   183 	    iSearchAO = NULL;
   180         iSearchAO = NULL;
   184     	}
   181         }
   185     iSearchAO = CLmkAOOperation::NewL( operation,
   182     iSearchAO = CLmkAOOperation::NewL(operation, *this,
   186                                        *this,
   183             MLmkAOOperationObserver::ESearch, iOperationNotInUse);
   187                                        MLmkAOOperationObserver::ESearch,
   184     iOperationNotInUse = ETrue;
   188                                        iOperationNotInUse );
   185     CleanupStack::Pop(operation); // ownership transferred
   189 	iOperationNotInUse = ETrue;
       
   190     CleanupStack::Pop( operation ); // ownership transferred
       
   191     iSearchAO->StartOperation();
   186     iSearchAO->StartOperation();
       
   187     DEBUG( CLmkSearchedLmListProvider::PrepareListL End );
   192     }
   188     }
   193 
   189 
   194 // -----------------------------------------------------------------------------
   190 // -----------------------------------------------------------------------------
   195 // CLmkSearchedLmListProvider::PrepareListL
   191 // CLmkSearchedLmListProvider::PrepareListL
   196 // -----------------------------------------------------------------------------
   192 // -----------------------------------------------------------------------------
   197 //
   193 //
   198 TBool CLmkSearchedLmListProvider::PrepareListL(const TDesC& aSearchPattern,
   194 TBool CLmkSearchedLmListProvider::PrepareListL(const TDesC& aSearchPattern,
   199     							TBool aSearchOnlyInPreviousMatches)
   195         TBool aSearchOnlyInPreviousMatches)
   200 	{
   196     {
   201     iCount = 0;
   197     iCount = 0;
   202 	iRequestFromFindBox = ETrue;
   198     iRequestFromFindBox = ETrue;
   203 	iOperationNotInUse = ETrue;
   199     iOperationNotInUse = ETrue;
   204     iIsSecondSearchStarted = EFalse;
   200     iIsSecondSearchStarted = EFalse;
   205 
   201     DEBUG1( CLmkSearchedLmListProvider::PrepareListL 2 start with aSearchPattern = %d,aSearchPattern.Length());
   206 	if( aSearchPattern.Compare( KDefaultTextCriteria ) == 0
   202 
   207 			|| aSearchPattern.Length() <= 0  )
   203     if (aSearchPattern.Compare(KDefaultTextCriteria) == 0
   208 		{
   204             || aSearchPattern.Length() <= 0)
   209 		PrepareListL();
   205         {
   210 		iRequestFromFindBox = EFalse;
   206         PrepareListL();
   211 		return ETrue;
   207         iRequestFromFindBox = EFalse;
   212 		}
   208         return ETrue;
   213 
   209         }
   214 	// We need to cancel if we are searching/reading landmarks.
   210 
   215  	if (iSearchAO)
   211     // We need to cancel if we are searching/reading landmarks.
   216 	 	{
   212     if (iSearchAO)
   217 	 	iSearchAO->StopOperation();
   213         {
   218 	 	delete iSearchAO; // cancel possibly pending operation
   214         iSearchAO->StopOperation();
   219 		iSearchAO = NULL;
   215         delete iSearchAO; // cancel possibly pending operation
   220 	 	}
   216         iSearchAO = NULL;
   221 
   217         }
   222 	// Create the composite criterion
   218 
   223 	CPosLmCompositeCriteria* compCrit = CPosLmCompositeCriteria::NewLC(
   219     // Create the composite criterion
   224 	    CPosLmCompositeCriteria::ECompositionOR );
   220     CPosLmCompositeCriteria* compCrit = CPosLmCompositeCriteria::NewLC(
   225 
   221             CPosLmCompositeCriteria::ECompositionOR);
   226 	// Create the text search criterion and add it to composite
   222 
   227 	CPosLmTextCriteria* textCrit1 = CPosLmTextCriteria::NewLC();
   223     // Create the text search criterion and add it to composite
       
   224     CPosLmTextCriteria* textCrit1 = CPosLmTextCriteria::NewLC();
   228 
   225 
   229     const TInt KExtraChars = 3; // 2 chars wildcards
   226     const TInt KExtraChars = 3; // 2 chars wildcards
   230     HBufC* filterBuf = HBufC::NewLC(aSearchPattern.Length() + KExtraChars);
   227     HBufC* filterBuf = HBufC::NewLC(aSearchPattern.Length() + KExtraChars);
   231     TPtr filter = filterBuf->Des();
   228     TPtr filter = filterBuf->Des();
   232 	filter.Copy(KSpaceTextCriteria);
   229     filter.Copy(KSpaceTextCriteria);
   233 	filter.Append(aSearchPattern);
   230     filter.Append(aSearchPattern);
   234 
   231 
   235 	textCrit1->SetTextL( filter );
   232     textCrit1->SetTextL(filter);
   236     textCrit1->SetAttributesToSearch(CPosLandmark::ELandmarkName);
   233     textCrit1->SetAttributesToSearch(CPosLandmark::ELandmarkName);
   237 
   234 
   238 	User::LeaveIfError( compCrit->AddArgument( textCrit1 ) );
   235     User::LeaveIfError(compCrit->AddArgument(textCrit1));
   239 	// Ownership of the text criterion has been passed to the composite
   236     // Ownership of the text criterion has been passed to the composite
   240 	CleanupStack::PopAndDestroy( filterBuf );
   237     CleanupStack::PopAndDestroy(filterBuf);
   241 	CleanupStack::Pop( textCrit1 );
   238     CleanupStack::Pop(textCrit1);
   242 
   239 
   243 	// Create the text search criterion and add it to composite
   240     // Create the text search criterion and add it to composite
   244 	CPosLmTextCriteria* textCrit2 = CPosLmTextCriteria::NewLC();
   241     CPosLmTextCriteria* textCrit2 = CPosLmTextCriteria::NewLC();
   245 	textCrit2->SetTextL( aSearchPattern );
   242     textCrit2->SetTextL(aSearchPattern);
   246     textCrit2->SetAttributesToSearch(CPosLandmark::ELandmarkName);
   243     textCrit2->SetAttributesToSearch(CPosLandmark::ELandmarkName);
   247 
   244 
   248 	User::LeaveIfError( compCrit->AddArgument( textCrit2 ) );
   245     User::LeaveIfError(compCrit->AddArgument(textCrit2));
   249 	// Ownership of the text criterion has been passed to the composite
   246     // Ownership of the text criterion has been passed to the composite
   250 	CleanupStack::Pop( textCrit2 );
   247     CleanupStack::Pop(textCrit2);
   251 
   248 
   252     iDb.SetPartialReadParametersL( *iReadParams );
   249     iDb.SetPartialReadParametersL(*iReadParams);
   253 
   250 
   254     TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName,
   251     TPosLmSortPref sortOrder(CPosLandmark::ELandmarkName,
   255                               TPosLmSortPref::EAscending );
   252             TPosLmSortPref::EAscending);
   256 	// Start the search
   253     // Start the search
   257     // Create search operation
   254     // Create search operation
   258     CPosLmOperation* operation = iSearch->StartLandmarkSearchL(
   255     CPosLmOperation* operation = iSearch->StartLandmarkSearchL(*compCrit,
   259     					*compCrit, sortOrder, aSearchOnlyInPreviousMatches );
   256             sortOrder, aSearchOnlyInPreviousMatches);
   260 
   257 
   261  	CleanupStack::PopAndDestroy( compCrit );
   258     CleanupStack::PopAndDestroy(compCrit);
   262  	CleanupStack::PushL( operation );
   259     CleanupStack::PushL(operation);
   263 
   260 
   264 	iSearchAO = CLmkAOOperation::NewL( operation,
   261     iSearchAO = CLmkAOOperation::NewL(operation, *this,
   265                                    *this,
   262             MLmkAOOperationObserver::ESearch, ETrue);
   266                                    MLmkAOOperationObserver::ESearch,
   263     CleanupStack::Pop(operation); // ownership transferred
   267                                    ETrue );
       
   268 	CleanupStack::Pop( operation ); // ownership transferred
       
   269 
   264 
   270     iSearchAO->StartOperation();
   265     iSearchAO->StartOperation();
   271 
   266     DEBUG( CLmkSearchedLmListProvider::PrepareListL 2 End );
   272     return ETrue;
   267     return ETrue;
   273  	}
   268     }
   274 
   269 
   275 // ---------------------------------------------------------
   270 // ---------------------------------------------------------
   276 // CLmkSearchedLmListProvider::StartSecondSearchL
   271 // CLmkSearchedLmListProvider::StartSecondSearchL
   277 // ---------------------------------------------------------
   272 // ---------------------------------------------------------
   278 //
   273 //
   279 void CLmkSearchedLmListProvider::StartSecondSearchL()
   274 void CLmkSearchedLmListProvider::StartSecondSearchL()
   280 	{
   275     {
   281 	// Create the composite criterion
   276     DEBUG( CLmkSearchedLmListProvider::StartSecondSearchL start );
   282 	CPosLmCompositeCriteria* compCrit = CPosLmCompositeCriteria::NewLC(
   277 
   283 	    CPosLmCompositeCriteria::ECompositionAND );
   278     iIsSecondSearchStarted = ETrue;
   284 
   279 
   285 	// Create the category search criterion and add it to composite
   280     // Create the composite criterion
   286 	CPosLmCategoryCriteria* catCrit = CPosLmCategoryCriteria::NewLC();
   281     CPosLmCompositeCriteria* compCrit = CPosLmCompositeCriteria::NewLC(
   287 	catCrit->SetCategoryItemId( (static_cast<CPosLmCategoryCriteria&>(iCriteria)).CategoryItemId() );
   282             CPosLmCompositeCriteria::ECompositionAND);
   288 
   283 
   289 	User::LeaveIfError( compCrit->AddArgument( catCrit ) );
   284     // Create the category search criterion and add it to composite
   290 	// Ownership of the category criterion has been passed to the composite
   285     CPosLmCategoryCriteria* catCrit = CPosLmCategoryCriteria::NewLC();
   291 	CleanupStack::Pop( catCrit );
   286     catCrit->SetCategoryItemId(
   292 
   287             (static_cast<CPosLmCategoryCriteria&> (iCriteria)).CategoryItemId());
   293 	// Create the text search criterion and add it to composite
   288 
   294 	CPosLmIdListCriteria* idListCrit = CPosLmIdListCriteria::NewLC();
   289     User::LeaveIfError(compCrit->AddArgument(catCrit));
   295 	idListCrit->SetLandmarkIdsL( iIdArray );
   290     // Ownership of the category criterion has been passed to the composite
   296 
   291     CleanupStack::Pop(catCrit);
   297 	User::LeaveIfError( compCrit->AddArgument( idListCrit ) );
   292 
   298 	// Ownership of the text criterion has been passed to the composite
   293     // Create the text search criterion and add it to composite
   299 	CleanupStack::Pop( idListCrit );
   294     CPosLmIdListCriteria* idListCrit = CPosLmIdListCriteria::NewLC();
   300 
   295     idListCrit->SetLandmarkIdsL(iIdArray);
   301     iDb.SetPartialReadParametersL( *iReadParams );
   296 
   302 
   297     User::LeaveIfError(compCrit->AddArgument(idListCrit));
   303     TPosLmSortPref sortOrder( CPosLandmark::ELandmarkName,
   298     // Ownership of the text criterion has been passed to the composite
   304                               TPosLmSortPref::EAscending );
   299     CleanupStack::Pop(idListCrit);
   305 	// Start the search
   300 
       
   301     iDb.SetPartialReadParametersL(*iReadParams);
       
   302 
       
   303     TPosLmSortPref sortOrder(CPosLandmark::ELandmarkName,
       
   304             TPosLmSortPref::EAscending);
       
   305     // Start the search
   306     // Create search operation
   306     // Create search operation
   307     CPosLmOperation* operation = iSearch->StartLandmarkSearchL( *compCrit, sortOrder );
   307     CPosLmOperation* operation = iSearch->StartLandmarkSearchL(*compCrit,
   308 
   308             sortOrder);
   309  	CleanupStack::PopAndDestroy( compCrit );
   309 
   310  	CleanupStack::PushL( operation );
   310     CleanupStack::PopAndDestroy(compCrit);
   311 
   311     CleanupStack::PushL(operation);
   312 	iSearchAO = CLmkAOOperation::NewL( operation,
   312 
   313                                    *this,
   313     iSearchAO = CLmkAOOperation::NewL(operation, *this,
   314                                    MLmkAOOperationObserver::ESearch,
   314             MLmkAOOperationObserver::ESearch, ETrue);
   315                                    ETrue );
   315     CleanupStack::Pop(operation); // ownership transferred
   316 	CleanupStack::Pop( operation ); // ownership transferred
   316 
   317 
       
   318 	iIsSecondSearchStarted = EFalse;
       
   319     iSearchAO->StartOperation();
   317     iSearchAO->StartOperation();
   320 
   318     DEBUG( CLmkSearchedLmListProvider::StartSecondSearchL End );
   321 	}
   319     }
   322 
   320 
   323 // ---------------------------------------------------------
   321 // ---------------------------------------------------------
   324 // CLmkSearchedLmListProvider::HandleOperationL
   322 // CLmkSearchedLmListProvider::HandleOperationL
   325 // ---------------------------------------------------------
   323 // ---------------------------------------------------------
   326 //
   324 //
   327 void CLmkSearchedLmListProvider::HandleOperationL(
   325 void CLmkSearchedLmListProvider::HandleOperationL(TOperationTypes aType,
   328     TOperationTypes aType,
   326         TReal32 aProgress, TInt aStatus)
   329     TReal32 aProgress,
   327     {
   330     TInt aStatus )
   328     DEBUG1( CLmkSearchedLmListProvider::HandleOperationL start aType=%d,aType);
   331     {
   329     if (aType == MLmkAOOperationObserver::EDeleteLandmarks)
   332     if ( aType == MLmkAOOperationObserver::EDeleteLandmarks )
   330         {
   333     	{
   331         return;
   334     	return;
   332         }
   335     	}
   333     if (aType == MLmkAOOperationObserver::ERemoveCategory)
   336     if ( aType == MLmkAOOperationObserver::ERemoveCategory )
   334         {
   337     	{
   335         return;
   338     	return;
   336         }
   339     	}
   337     if (aType == MLmkAOOperationObserver::ESearch)
   340     if ( aType == MLmkAOOperationObserver::ESearch )
   338         {
   341         {
   339         ReadItemsToArrayL();
   342    		ReadItemsToArrayL();
   340         if (aStatus == KErrNone)
   343        	if ( aStatus == KErrNone )
   341             {
   344 	        {
   342             if (iSearchAO)
   345 	        if( iSearchAO )
   343                 {
   346 	        	{
   344                 iSearchAO->StopOperation();
   347 	        	iSearchAO->StopOperation();
   345                 delete iSearchAO;
   348 				delete iSearchAO;
   346                 iSearchAO = NULL;
   349 		        iSearchAO = NULL;
   347                 }
   350 	        	}
   348 
   351 
   349             // reset operation values
   352 			// reset operation values
   350             iOperationCmd = ELmkCmdStopOperation;//temp default value
   353 	        iOperationCmd = ELmkCmdStopOperation;//temp default value
   351             iCount = 0;
   354 	        iCount = 0;
   352 
   355 
   353             DEBUG2( CLmkSearchedLmListProvider::HandleOperationL iRequestFromFindBox=%d iIsSecondSearchStarted=%d
   356 	        if( iIsSecondSearchStarted )
   354                     ,iRequestFromFindBox,iIsSecondSearchStarted);
   357 	        	{
   355 
   358 	        	StartSecondSearchL();
   356             if (iRequestFromFindBox && iIsSecondSearchStarted == EFalse)
   359 	        	}
   357                 {
   360 
   358                 DEBUG( CLmkSearchedLmListProvider::HandleOperationL start secondsearch );
   361 	        if(iOperationNotInUse == EFalse )
   359                 StartSecondSearchL();
   362 	        	{
   360                 return;
   363 	        	NotifyObservers( ELmkEventItemAdditionComplete );
   361                 }
   364 	        	}
   362 
   365 	        else
   363             DEBUG( CLmkSearchedLmListProvider::HandleOperationL refresh list );
   366 		        {
   364 
   367 		        if (iRequestFromFindBox)
   365             iIsSecondSearchStarted = EFalse;
   368 			        {
   366 
   369 			        NotifyObservers( ELmkEventFindListReady );
   367             if (iOperationNotInUse == EFalse)
   370 			        }
   368                 {
   371 				else
   369                 NotifyObservers(ELmkEventItemAdditionComplete);
   372 					{
   370                 }
   373 		        	NotifyObservers( ELmkEventListReady );
   371             else
   374 					}
   372                 {
   375 		        }
   373                 if (iRequestFromFindBox)
   376 
   374                     {
   377 	        iOperationNotInUse = ETrue;
   375                     NotifyObservers(ELmkEventFindListReady);
   378 
   376                     }
   379             if ( iCatDelete )
   377                 else
   380                 {
   378                     {
   381                 NotifyObservers( ELmkEventCategoryDeleted );
   379                     NotifyObservers(ELmkEventListReady);
       
   380                     }
       
   381                 }
       
   382 
       
   383             iOperationNotInUse = ETrue;
       
   384 
       
   385             if (iCatDelete)
       
   386                 {
       
   387                 NotifyObservers(ELmkEventCategoryDeleted);
   382                 iCatDelete = EFalse;
   388                 iCatDelete = EFalse;
   383                 }
   389                 }
   384             else if(iCatUpdate)
   390             else if (iCatUpdate)
   385 	            {
   391                 {
   386 	            NotifyObservers( ELmkEventCategoryUpdated );
   392                 NotifyObservers(ELmkEventCategoryUpdated);
   387                 iCatUpdate = EFalse;
   393                 iCatUpdate = EFalse;
   388                 }
   394                 }
   389 
   395 
   390     		if(iItemsDeleted < iItemsToDelete)
   396             if (iItemsDeleted < iItemsToDelete)
   391     			{
   397                 {
   392     			PrepareForDeleteL();
   398                 PrepareForDeleteL();
   393     			}
   399                 }
   394     		else
   400             else
   395     			{
   401                 {
   396     			if(iWaitNote)
   402                 if (iWaitNote)
   397     				{
   403                     {
   398 		            iWaitNote->ProcessFinishedL();
   404                     iWaitNote->ProcessFinishedL();
   399 		            iWaitNote = NULL;
   405                     iWaitNote = NULL;
   400     				}
   406                     }
   401     			}
   407                 }
   402 	        return;
   408             return;
   403 	        } // end of if ( aStatus == KErrNone )
   409             } // end of if ( aStatus == KErrNone )
   404 
   410 
   405 	    if ( iCount == ELmkStepOne || iCount == ELmkStepTwo )
   411         if (iCount == ELmkStepOne || iCount == ELmkStepTwo)
   406 	        {
   412             {
   407 			if (iOperationNotInUse == EFalse )
   413             if (iOperationNotInUse == EFalse)
   408 	        	{
   414                 {
   409 	        	NotifyObservers( ELmkEventItemAdditionComplete );
   415                 NotifyObservers(ELmkEventItemAdditionComplete);
   410 	        	}
   416                 }
   411 	        else
   417             else
   412 		        {
   418                 {
   413 		        if (iRequestFromFindBox)
   419                 if (iRequestFromFindBox)
   414 			        {
   420                     {
   415 			        NotifyObservers( ELmkEventFindListReady );
   421                     NotifyObservers(ELmkEventFindListReady);
   416 			        }
   422                     }
   417 				else
   423                 else
   418 					{
   424                     {
   419 		        	NotifyObservers( ELmkEventListReady );
   425                     NotifyObservers(ELmkEventListReady);
   420 					}
   426                     }
   421 		        }
   427                 }
   422 		    iOperationNotInUse = EFalse;
   428             iRequestFromFindBox = EFalse;
   423 	        }
   429             iOperationNotInUse = EFalse;
       
   430             }
   424         }
   431         }
   425     else
   432     else
   426         { // This is not this classes' operation
   433         { // This is not this classes' operation
   427         CLmkLmItemListProvider::HandleOperationL( aType, aProgress, aStatus);
   434         CLmkLmItemListProvider::HandleOperationL(aType, aProgress, aStatus);
   428         }
   435         }
   429     }
   436     }
   430 
   437 
   431 // ---------------------------------------------------------
   438 // ---------------------------------------------------------
   432 // CLmkSearchedLmListProvider::HandleDatabaseEvent
   439 // CLmkSearchedLmListProvider::HandleDatabaseEvent
   433 // ---------------------------------------------------------
   440 // ---------------------------------------------------------
   434 //
   441 //
   435 void CLmkSearchedLmListProvider::HandleDatabaseEvent( TPosLmEvent& aEvent )
   442 void CLmkSearchedLmListProvider::HandleDatabaseEvent(TPosLmEvent& aEvent)
   436     {
   443     {
   437     iCatDelete = EFalse;
   444     iCatDelete = EFalse;
   438 
   445 
   439 	TBool needRefresh = ETrue;
   446     TBool needRefresh = ETrue;
   440 
   447 
   441 	// check any items are selected to do operations like iconchanges or add to category.
   448     // check any items are selected to do operations like iconchanges or add to category.
   442 	if( iSelectedItemsCount > 0 
   449     if (iSelectedItemsCount > 0 && iOperationCmd != ELmkCmdAddToCat
   443 		&& iOperationCmd != ELmkCmdAddToCat
   450             && iOperationCmd != ERemoveFromCat)
   444 		&& iOperationCmd != ERemoveFromCat )
   451         {
   445 		{
   452         iCount++;
   446 		iCount++;
   453         if (iSelectedItemsCount == iCount)
   447 		if( iSelectedItemsCount == iCount )
   454             {
   448 			{
   455             iSelectedItemsCount = 0;
   449 			iSelectedItemsCount = 0;
   456             iCount = 0;
   450 			iCount = 0;
   457             }
   451 			}
   458         needRefresh = EFalse;
   452 		needRefresh = EFalse;
   459         }
   453 		}
   460 
   454 
   461     switch (aEvent.iEventType)
   455     switch ( aEvent.iEventType )
   462         {
   456         {
   463         case EPosLmEventLandmarkUpdated: // lm icon changes, lm renaming
   457         case EPosLmEventLandmarkUpdated: 		// lm icon changes, lm renaming
   464         case EPosLmEventLandmarkUnknownChanges: // lm multiple deletion, lm add to category
   458         case EPosLmEventLandmarkUnknownChanges:	// lm multiple deletion, lm add to category
       
   459         case EPosLmEventUnknownChanges:
   465         case EPosLmEventUnknownChanges:
   460         case EPosLmEventLandmarkCreated:
   466         case EPosLmEventLandmarkCreated:
   461         case EPosLmEventCategoryDeleted:
   467         case EPosLmEventCategoryDeleted:
   462         case EPosLmEventCategoryUpdated:
   468         case EPosLmEventCategoryUpdated:
   463             {
   469             {
   464             iOperationNotInUse = EFalse;
   470             iOperationNotInUse = EFalse;
   465            	if (aEvent.iEventType == EPosLmEventCategoryDeleted )
   471             if (aEvent.iEventType == EPosLmEventCategoryDeleted)
   466 	            {
   472                 {
   467 	            iCatDelete = ETrue;
   473                 iCatDelete = ETrue;
   468 	            }
   474                 }
   469 	        if (aEvent.iEventType == EPosLmEventCategoryUpdated )
   475             if (aEvent.iEventType == EPosLmEventCategoryUpdated)
   470 	            {
   476                 {
   471 	            iCatUpdate = ETrue;
   477                 iCatUpdate = ETrue;
   472 	            }
   478                 }
   473 
   479 
   474 			if( needRefresh )
   480             if (needRefresh)
   475 				{
   481                 {
   476 		        if( iSearchAO )
   482                 if (iSearchAO)
   477 		        	{
   483                     {
   478 		        	iSearchAO->StopOperation();
   484                     iSearchAO->StopOperation();
   479 					delete iSearchAO;
   485                     delete iSearchAO;
   480 			        iSearchAO = NULL;
   486                     iSearchAO = NULL;
   481 		        	}
   487                     }
   482 	            iOperationNotInUse = EFalse;
   488                 iOperationNotInUse = EFalse;
   483 	            TInt err = KErrNone;
   489                 TInt err = KErrNone;
   484 	            do
   490                 do
   485 	                {
   491                     {
   486 	                TRAP( err, PrepareListL() );
   492                     TRAP( err, PrepareListL() );
   487 	                }while(err == KErrLocked);
   493                     }
   488 	            if ( err )
   494                 while (err == KErrLocked);
   489 	                {
   495                 if (err)
   490 	                HandleError( err );
   496                     {
   491 	                }
   497                     HandleError(err);
   492 				}
   498                     }
   493 			else
   499                 }
   494 				{
   500             else
   495 				NotifyObservers( ELmkEventListReady );
   501                 {
   496 				}
   502                 NotifyObservers(ELmkEventListReady);
       
   503                 }
   497             break;
   504             break;
   498             }
   505             }
   499         case EPosLmEventLandmarkDeleted:
   506         case EPosLmEventLandmarkDeleted:
   500         	{
   507             {
   501 		   	TInt index = iIdArray.Find( aEvent.iLandmarkItemId );
   508             TInt index = iIdArray.Find(aEvent.iLandmarkItemId);
   502 		   	if( index != KErrNotFound && index < iIdArray.Count())
   509             if (index != KErrNotFound && index < iIdArray.Count())
   503 		   		{
   510                 {
   504 		   		iIdArray.Remove(index);
   511                 iIdArray.Remove(index);
   505 			   	NotifyObservers( ELmkEventListReady );
   512                 NotifyObservers(ELmkEventListReady);
   506 		   		}
   513                 }
   507 		   	break;
   514             break;
   508         	}
   515             }
   509         default:
   516         default:
   510             { // Not interesting event for this provider
   517             { // Not interesting event for this provider
   511             break;
   518             break;
   512             }
   519             }
   513         }
   520         }
   514     // Remember to call base class observer method too
   521     // Remember to call base class observer method too
   515     CLmkLmItemListProvider::HandleDatabaseEvent( aEvent );
   522     CLmkLmItemListProvider::HandleDatabaseEvent(aEvent);
   516     }
   523     }
   517 
   524 
   518 // ---------------------------------------------------------
   525 // ---------------------------------------------------------
   519 // CLmkSearchedLmListProvider::ReadItemsToArrayL
   526 // CLmkSearchedLmListProvider::ReadItemsToArrayL
   520 // ---------------------------------------------------------
   527 // ---------------------------------------------------------
   521 //
   528 //
   522 void CLmkSearchedLmListProvider::ReadItemsToArrayL()
   529 void CLmkSearchedLmListProvider::ReadItemsToArrayL()
   523     {
   530     {
   524     iIdArray.Reset();
   531     iIdArray.Reset();
   525     CPosLmItemIterator* iterator = iSearch->MatchIteratorL();
   532     CPosLmItemIterator* iterator = iSearch->MatchIteratorL();
   526     CleanupStack::PushL( iterator );
   533     CleanupStack::PushL(iterator);
   527     iCount = iterator->NumOfItemsL();
   534     iCount = iterator->NumOfItemsL();
   528     if ( iCount > 0 )
   535     if (iCount > 0)
   529         { // can only be called if there are some items
   536         { // can only be called if there are some items
   530         iterator->GetItemIdsL( iIdArray, 0, iCount ); // array is first reseted
   537         iterator->GetItemIdsL(iIdArray, 0, iCount); // array is first reseted
   531         }
   538         }
   532     CleanupStack::PopAndDestroy( iterator );
   539     CleanupStack::PopAndDestroy(iterator);
   533     }
   540     }
   534 
   541 
   535 // ---------------------------------------------------------
   542 // ---------------------------------------------------------
   536 // CLmkSearchedLmListProvider::RemoveLandmarksL
   543 // CLmkSearchedLmListProvider::RemoveLandmarksL
   537 // ---------------------------------------------------------
   544 // ---------------------------------------------------------
   538 //
   545 //
   539 void CLmkSearchedLmListProvider::RemoveLandmarksL(const RArray<TPosLmItemId>& aSelectedItems )
   546 void CLmkSearchedLmListProvider::RemoveLandmarksL(
   540 	{
   547         const RArray<TPosLmItemId>& aSelectedItems)
   541 	iItemsToDelete = aSelectedItems.Count();
   548     {
   542 	iSelectedForDelete.Reset();
   549     iItemsToDelete = aSelectedItems.Count();
   543 	for(TInt i=0;i<iItemsToDelete;i++)
   550     iSelectedForDelete.Reset();
   544 		iSelectedForDelete.Append(aSelectedItems[i]);
   551     for (TInt i = 0; i < iItemsToDelete; i++)
   545 	iItemsDeleted = 0;
   552         iSelectedForDelete.Append(aSelectedItems[i]);
   546 	iIsRemoveLandmarks = ETrue;
   553     iItemsDeleted = 0;
   547 
   554     iIsRemoveLandmarks = ETrue;
   548 	if(iWaitNote)
   555 
   549 		{
   556     if (iWaitNote)
   550 		delete iWaitNote;
   557         {
   551 		iWaitNote = NULL;
   558         delete iWaitNote;
   552 		}
   559         iWaitNote = NULL;
   553 	PrepareForDeleteL();
   560         }
   554 	}
   561     PrepareForDeleteL();
       
   562     }
   555 
   563 
   556 // ---------------------------------------------------------
   564 // ---------------------------------------------------------
   557 // CLmkSearchedLmListProvider::PrepareForDelete
   565 // CLmkSearchedLmListProvider::PrepareForDelete
   558 // ---------------------------------------------------------
   566 // ---------------------------------------------------------
   559 //
   567 //
   560 void CLmkSearchedLmListProvider::PrepareForDeleteL()
   568 void CLmkSearchedLmListProvider::PrepareForDeleteL()
   561 	{
   569     {
   562 	RArray<TPosLmItemId> lmItemsChunk;
   570     RArray<TPosLmItemId> lmItemsChunk;
   563 	TInt count = iItemsDeleted;
   571     TInt count = iItemsDeleted;
   564 	if(iItemsToDelete > (iItemsDeleted + 10))
   572     if (iItemsToDelete > (iItemsDeleted + 10))
   565 		{
   573         {
   566 		iItemsDeleted = iItemsDeleted + 10;
   574         iItemsDeleted = iItemsDeleted + 10;
   567 		}
   575         }
   568 	else
   576     else
   569 		{
   577         {
   570 		iItemsDeleted = iItemsDeleted + (iItemsToDelete - iItemsDeleted);
   578         iItemsDeleted = iItemsDeleted + (iItemsToDelete - iItemsDeleted);
   571 		}
   579         }
   572 
   580 
   573 	for(TInt i=count;i<iItemsDeleted;i++)
   581     for (TInt i = count; i < iItemsDeleted; i++)
   574 		{
   582         {
   575 		lmItemsChunk.Append(iSelectedForDelete[i]);
   583         lmItemsChunk.Append(iSelectedForDelete[i]);
   576 		}
   584         }
   577 
   585 
   578 	CPosLmOperation* operation = NULL;
   586     CPosLmOperation* operation = NULL;
   579 	if(iType == MLmkAOOperationObserver::EDeleteLandmarks)
   587     if (iType == MLmkAOOperationObserver::EDeleteLandmarks)
   580 		{
   588         {
   581 		operation = iDb.RemoveLandmarksL( lmItemsChunk );
   589         operation = iDb.RemoveLandmarksL(lmItemsChunk);
   582 		}
   590         }
   583 	if(iType == MLmkAOOperationObserver::ERemoveCategory)
   591     if (iType == MLmkAOOperationObserver::ERemoveCategory)
   584 		{
   592         {
   585 		CPosLmCategoryManager* mgr = CPosLmCategoryManager::NewL( iDb );
   593         CPosLmCategoryManager* mgr = CPosLmCategoryManager::NewL(iDb);
   586 		CleanupStack::PushL(mgr);
   594         CleanupStack::PushL(mgr);
   587 		operation = mgr->RemoveCategoryFromLandmarksL( iCategoryId, lmItemsChunk );
   595         operation = mgr->RemoveCategoryFromLandmarksL(iCategoryId,
   588 		CleanupStack::PopAndDestroy();//mgr
   596                 lmItemsChunk);
   589 		}
   597         CleanupStack::PopAndDestroy();//mgr
   590 	User::LeaveIfNull( operation );
   598         }
   591 
   599     User::LeaveIfNull(operation);
   592 	CleanupStack::PushL( operation );
   600 
   593 	iSearchAO = CLmkAOOperation::NewL( operation,
   601     CleanupStack::PushL(operation);
   594 	               *this,
   602     iSearchAO = CLmkAOOperation::NewL(operation, *this, iType, EFalse);
   595 	               iType,
   603     CleanupStack::Pop(operation); // ownership transferred
   596 	               EFalse );
   604 
   597 	CleanupStack::Pop( operation ); // ownership transferred
   605     if (iSearchAO)
   598 
       
   599     if( iSearchAO )
       
   600         {
   606         {
   601         iSearchAO->StartOperation();
   607         iSearchAO->StartOperation();
   602 
   608 
   603         if(!iWaitNote)
   609         if (!iWaitNote)
   604             {
   610             {
   605             iWaitNote = new (ELeave) CAknWaitDialog(NULL, ETrue);
   611             iWaitNote = new (ELeave) CAknWaitDialog(NULL, ETrue);
   606             if(!iWaitNote->ExecuteLD(R_LMK_PROCESSING_WAIT_NOTE))
   612             if (!iWaitNote->ExecuteLD(R_LMK_PROCESSING_WAIT_NOTE))
   607                 {
   613                 {
   608                 iSearchAO->StopOperation();
   614                 iSearchAO->StopOperation();
   609                 delete iSearchAO;
   615                 delete iSearchAO;
   610                 iSearchAO = NULL;
   616                 iSearchAO = NULL;
   611                 iWaitNote = NULL;
   617                 iWaitNote = NULL;
   612                 }
   618                 }
   613             }
   619             }
   614         }
   620         }
   615 	
   621 
   616 	lmItemsChunk.Close();
   622     lmItemsChunk.Close();
   617 	}
   623     }
   618 
   624 
   619 //  End of File
   625 //  End of File