landmarks/locationlandmarks/localsearchprov/src/EPos_CPosLmLocalCatNameSearch.cpp
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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: Class for handling searching for landmark categories with a certain name.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include    <EPos_CPosLmCatNameCriteria.h>
       
    21 #include    <epos_landmarkdatabasestructure.h>
       
    22 #include    <epos_poslmdatabaseutility.h>
       
    23 #include    "EPos_CPosLmLocalCatNameSearch.h"
       
    24 
       
    25 _LIT(KPosLmSqlSelectStringLike, "SELECT %S FROM %S WHERE %S LIKE '%S'");
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // -----------------------------------------------------------------------------
       
    31 //
       
    32 CPosLmLocalCatNameSearch::CPosLmLocalCatNameSearch(
       
    33     CPosLmLocalDatabase& aDatabase,
       
    34     const CPosLmSearchCriteria& aCriteria,
       
    35     const TPosLmLocalSortPref& aSortPref,
       
    36     TInt aMaxNumOfMatches)
       
    37 :   CPosLmLocalSearchHandler(
       
    38         aDatabase, aCriteria.CriteriaType(), aSortPref, aMaxNumOfMatches),
       
    39     iSearchStatus(EPosSearchNotStarted)
       
    40     {
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 void CPosLmLocalCatNameSearch::ConstructL(
       
    47     const CPosLmSearchCriteria& aCriteria,
       
    48     CPosLmDisplayData* aDisplayData)
       
    49     {
       
    50     const CPosLmCatNameCriteria& criteria =
       
    51         static_cast<const CPosLmCatNameCriteria&>(aCriteria);
       
    52 
       
    53     ValidateCriteriaL(criteria);
       
    54 
       
    55     iCriteria = CPosLmCatNameCriteria::NewLC();
       
    56     CleanupStack::Pop(iCriteria);
       
    57 
       
    58     HBufC* embeddedText = PosLmDatabaseUtility::EmbedSingleQuoteCharactersLC(
       
    59         criteria.SearchPattern());
       
    60     iCriteria->SetSearchPatternL(*embeddedText);
       
    61     CleanupStack::PopAndDestroy(embeddedText);
       
    62 
       
    63     if (aDisplayData)
       
    64         {
       
    65         SetDisplayDataL(aDisplayData);
       
    66         }
       
    67     }
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 CPosLmLocalCatNameSearch* CPosLmLocalCatNameSearch::NewL(
       
    73     CPosLmLocalDatabase& aDatabase,
       
    74     const CPosLmSearchCriteria& aCriteria,
       
    75     const TPosLmLocalSortPref& aSortPref,
       
    76     CPosLmDisplayData* aDisplayData,
       
    77     TInt aMaxNumOfMatches)
       
    78     {
       
    79     CPosLmLocalCatNameSearch* self = new (ELeave) CPosLmLocalCatNameSearch(
       
    80         aDatabase, aCriteria, aSortPref, aMaxNumOfMatches);
       
    81     CleanupStack::PushL(self);
       
    82     self->ConstructL(aCriteria, aDisplayData);
       
    83     CleanupStack::Pop(self);
       
    84 
       
    85     return self;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 CPosLmLocalCatNameSearch::~CPosLmLocalCatNameSearch()
       
    92     {
       
    93     delete iCriteria;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CPosLmLocalCatNameSearch::ValidateCriteriaL(
       
   100     const CPosLmCatNameCriteria& aCriteria)
       
   101     {
       
   102     if (aCriteria.SearchPattern().Length() == 0)
       
   103         {
       
   104         User::Leave(KErrArgument);
       
   105         }
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // -----------------------------------------------------------------------------
       
   110 //
       
   111 TBool CPosLmLocalCatNameSearch::IsValidForCategorySearch() const
       
   112     {
       
   113     return ETrue;
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 TInt CPosLmLocalCatNameSearch::NextStepL(
       
   120     TReal32& aProgress)
       
   121     {
       
   122     if (iSearchStatus == EPosSearchNotStarted)
       
   123         {
       
   124         PrepareSearchL();
       
   125         }
       
   126 
       
   127     if (iSearchStatus == EPosCatNameSearch)
       
   128         {
       
   129         SearchL();
       
   130         }
       
   131 
       
   132     return SearchStepCompletedL(
       
   133         iSearchStatus == EPosSearchCompleted, aProgress);
       
   134     }
       
   135 
       
   136 // -----------------------------------------------------------------------------
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 void CPosLmLocalCatNameSearch::PrepareSearchL()
       
   140     {
       
   141     TInt numRowsInTable = GetRowCountL( KPosLmCategoryTable );
       
   142 
       
   143     if ( numRowsInTable == 0 )
       
   144         {
       
   145         iSearchStatus = EPosSearchCompleted;
       
   146         }
       
   147     else
       
   148         {
       
   149         iSearchStatus = EPosCatNameSearch;
       
   150         PrepareCalculateProgress( numRowsInTable );
       
   151         PrepareQueryL();
       
   152         }
       
   153     }
       
   154 
       
   155 // -----------------------------------------------------------------------------
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CPosLmLocalCatNameSearch::PrepareQueryL()
       
   159     {
       
   160     HBufC* query = HBufC::NewLC( KPosLmSqlStatementMaxLen );
       
   161 
       
   162     TPtrC searchPattern = iCriteria->SearchPattern();
       
   163     if ( HasDisplayData() )
       
   164     	{
       
   165     	// request all fields
       
   166 	    query->Des().Format(
       
   167 	    	KPosLmSqlSelectStringLike,
       
   168 	        &KPosLmSqlAll,
       
   169 	        &KPosLmCategoryTable,
       
   170 	        &KPosLmCategoryNameCol,
       
   171 	        &searchPattern );
       
   172     	}
       
   173     else
       
   174     	{
       
   175     	// request only ID column
       
   176 	    query->Des().Format(
       
   177 	    	KPosLmSqlSelectStringLike,
       
   178 	        &KPosLmCategoryIdCol,
       
   179 	        &KPosLmCategoryTable,
       
   180 	        &KPosLmCategoryNameCol,
       
   181 	        &searchPattern );
       
   182     	}
       
   183 
       
   184     if ( !HasDisplayData() && SortPref().SortType() ==
       
   185         TPosLmLocalSortPref::ECategorySorting )
       
   186         {
       
   187         AppendSortToQueryL( query );
       
   188         }
       
   189 
       
   190     PrepareViewL( iView, *query );
       
   191     CleanupStack::PopAndDestroy( query );
       
   192     }
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CPosLmLocalCatNameSearch::SearchL()
       
   198     {
       
   199     if ( SearchViewL( iView, 1 ) || IsMaxMatchesFound() )
       
   200         {
       
   201         iView.Close();
       
   202         iSearchStatus = EPosSearchCompleted;
       
   203         }
       
   204     }
       
   205