landmarks/locationlandmarks/localsearchprov/src/EPos_CPosLmLocalAreaSearch.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 area searching for landmarks.
       
    15 *
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <lbs.h>
       
    21 #include <EPos_CPosLmAreaCriteria.h>
       
    22 #include <epos_landmarkdatabasestructure.h>
       
    23 #include "EPos_CPosLmLocalAreaSearch.h"
       
    24 #include "EPos_PosLmSqlQueryHelper.h"
       
    25 #include "epos_cposlmnameindexiterator.h"
       
    26 
       
    27 const TInt KLmIdColumn = 1;
       
    28 
       
    29 // ============================ MEMBER FUNCTIONS ===============================
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CPosLmLocalAreaSearch::CPosLmLocalAreaSearch(
       
    35     CPosLmLocalDatabase& aDatabase,
       
    36     const CPosLmSearchCriteria& aCriteria,
       
    37     const TPosLmLocalSortPref& aSortPref,
       
    38     TInt aMaxNumOfMatches)
       
    39 :   CPosLmLocalSearchHandler(
       
    40         aDatabase, aCriteria.CriteriaType(), aSortPref, aMaxNumOfMatches ),
       
    41     iSearchStatus( ESearchNotStarted )
       
    42     {
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 void CPosLmLocalAreaSearch::ConstructL(
       
    49     const CPosLmSearchCriteria& aCriteria,
       
    50     CPosLmDisplayData* aDisplayData)
       
    51     {
       
    52     const CPosLmAreaCriteria& criteria =
       
    53         static_cast<const CPosLmAreaCriteria&>( aCriteria );
       
    54 
       
    55     criteria.GetSearchArea( iSouth, iNorth, iWest, iEast );
       
    56 
       
    57     if ( aDisplayData )
       
    58         {
       
    59         SetDisplayDataL( aDisplayData );
       
    60         }
       
    61     }
       
    62 
       
    63 // -----------------------------------------------------------------------------
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CPosLmLocalAreaSearch* CPosLmLocalAreaSearch::NewL(
       
    67     CPosLmLocalDatabase& aDatabase,
       
    68     const CPosLmSearchCriteria& aCriteria,
       
    69     const TPosLmLocalSortPref& aSortPref,
       
    70     CPosLmDisplayData* aDisplayData,
       
    71     TInt aMaxNumOfMatches)
       
    72     {
       
    73     CPosLmLocalAreaSearch* self = new (ELeave) CPosLmLocalAreaSearch(
       
    74         aDatabase, aCriteria, aSortPref, aMaxNumOfMatches);
       
    75     CleanupStack::PushL(self);
       
    76     self->ConstructL(aCriteria, aDisplayData);
       
    77     CleanupStack::Pop(self);
       
    78     return self;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 CPosLmLocalAreaSearch::~CPosLmLocalAreaSearch()
       
    85     {
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 TBool CPosLmLocalAreaSearch::IsValidForLandmarkSearch() const
       
    92     {
       
    93     return ETrue;
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TInt CPosLmLocalAreaSearch::NextStepL( TReal32& aProgress )
       
   100     {
       
   101     if ( iSearchStatus == ESearchNotStarted )
       
   102         {
       
   103         PrepareSearchL();
       
   104         }
       
   105 
       
   106     switch ( iSearchStatus )
       
   107         {
       
   108         case EPrepareUnsortedSearch:
       
   109         case EUnsortedSearch:
       
   110             UnsortedSearchL();
       
   111             break;
       
   112         case EPrepareSortedSearch:
       
   113         case ESortedSearch:
       
   114             SortedSearchL();
       
   115             break;
       
   116         default:
       
   117             iSearchStatus = ESearchCompleted;
       
   118             break;
       
   119         }
       
   120 
       
   121     return SearchStepCompletedL( iSearchStatus == ESearchCompleted, aProgress );
       
   122     }
       
   123 
       
   124 // -----------------------------------------------------------------------------
       
   125 // -----------------------------------------------------------------------------
       
   126 //
       
   127 void CPosLmLocalAreaSearch::PrepareSearchL()
       
   128     {
       
   129     TInt numRowsInTable = GetRowCountL( KPosLmLandmarkTable );
       
   130 
       
   131     if ( numRowsInTable == 0 )
       
   132         {
       
   133         iSearchStatus = ESearchCompleted;
       
   134         }
       
   135     else
       
   136         {
       
   137         PrepareCalculateProgress( numRowsInTable );
       
   138         if ( SortPref().SortType() == TPosLmLocalSortPref::ELandmarkSorting )
       
   139             {
       
   140             iSearchStatus = EPrepareSortedSearch;
       
   141             }
       
   142         else
       
   143             {
       
   144             iSearchStatus = EPrepareUnsortedSearch;
       
   145             }
       
   146         }
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 void CPosLmLocalAreaSearch::PrepareQueryL( TBool aFullData )
       
   153     {
       
   154     HBufC* query = HBufC::NewLC( KPosLmSqlStatementMaxLen );
       
   155     if ( aFullData )
       
   156     	{
       
   157     	query->Des().Format( KPosLmSqlSelect, &KPosLmSqlAll, &KPosLmLandmarkTable );
       
   158     	}
       
   159     else
       
   160     	{
       
   161     	query->Des().Format( KPosLmSqlSelect, &KPosLmLandmarkIdCol, &KPosLmLandmarkTable );
       
   162     	}
       
   163 
       
   164     PosLmSqlQueryHelper::AppendAreaCriteriaToQueryL(
       
   165         query, iSouth, iNorth, iWest, iEast );
       
   166 
       
   167     PrepareViewL( iView, *query );
       
   168     CleanupStack::PopAndDestroy( query );
       
   169     }
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 void CPosLmLocalAreaSearch::UnsortedSearchL()
       
   175     {
       
   176     if ( iSearchStatus == EPrepareUnsortedSearch )
       
   177         {
       
   178         PrepareQueryL( HasDisplayData() );
       
   179         iSearchStatus = EUnsortedSearch;
       
   180         }
       
   181 
       
   182     if ( iSearchStatus == EUnsortedSearch )
       
   183         {
       
   184         if ( SearchViewL( iView, KLmIdColumn ) || IsMaxMatchesFound() )
       
   185             {
       
   186             iSearchStatus = ESearchCompleted; 
       
   187             }
       
   188         }
       
   189     }
       
   190 
       
   191 // -----------------------------------------------------------------------------
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 void CPosLmLocalAreaSearch::SortedSearchL()
       
   195     {
       
   196     if ( iSearchStatus == EPrepareSortedSearch )
       
   197         {
       
   198         PrepareLandmarkIndexL();
       
   199         iSearchStatus = ESortedSearch;
       
   200         }
       
   201 
       
   202     if ( iSearchStatus == ESortedSearch )
       
   203         {
       
   204         EvaluateLandmarkIndexL();
       
   205         TInt ddMatches = DisplayDataCount();
       
   206         while ( !iLandmarkIndex->AtEnd() && !IsMaxMatchesFound() && !BreakOnDisplayData( ddMatches ) )
       
   207             {
       
   208             const RPosLmLocalNameIndex::CIndexItem& item = iLandmarkIndex->Current();
       
   209             if ( GetLandmarkRowL( item.Id() ) && CurrentRowMatch( iTable ) )
       
   210                 {
       
   211                 AddMatchL( item.Id(), &iTable );
       
   212                 }
       
   213             iLandmarkIndex->Next();
       
   214             }
       
   215 
       
   216         if ( !MoreInLandmarkIndex() || IsMaxMatchesFound() )
       
   217             {
       
   218             iSearchStatus = ESearchCompleted;
       
   219             }
       
   220         }
       
   221     }
       
   222 
       
   223 //-------------------------------------------------------------
       
   224 //-------------------------------------------------------------
       
   225 //
       
   226 TBool CPosLmLocalAreaSearch::CurrentRowMatch( RDbRowSet& aView )
       
   227     {
       
   228     if ( !aView.IsColNull( EPosLmLcLatitudeCol ) &&
       
   229          !aView.IsColNull( EPosLmLcLongitudeCol ) )
       
   230         {
       
   231         TRealX nan;
       
   232         nan.SetNaN();
       
   233         TReal lat = nan, lon = nan;
       
   234         
       
   235         lat = aView.ColReal( EPosLmLcLatitudeCol );
       
   236         lon = aView.ColReal( EPosLmLcLongitudeCol );
       
   237     
       
   238         if ( !Math::IsNaN( lat ) && !Math::IsNaN( lon ) )
       
   239             {
       
   240             if ( ( lat >= iSouth ) && ( lat <= iNorth ) )
       
   241                 {
       
   242                 if ( iWest <= iEast )
       
   243                     {
       
   244                     return ( lon >= iWest ) && ( lon <= iEast );
       
   245                     }
       
   246                 else // cross 180 meridian
       
   247                     {
       
   248                     return ( lon >= iWest ) || ( lon <= iEast );                
       
   249                     }
       
   250                 }
       
   251             }
       
   252         }
       
   253     return EFalse;
       
   254     }