ipsservices/ipssosplugin/inc/ipsplgtextsearcher.h
changeset 0 8466d47a6819
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2005-2008 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: This file defines classes MIpsPlgTextSearcherObserver, TIpsPlgKeywordSearchStatus, CIpsPlgTextSearcher
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef IPSPLGTEXTSEARCHER_H
       
    20 #define IPSPLGTEXTSEARCHER_H
       
    21 
       
    22 // INCLUDE FILES
       
    23 // Removed for 3.2
       
    24 //#include <IdsCommonDefines.h>
       
    25 // Removed for 3.2
       
    26 //#include <KeywordSearchStatus.h>
       
    27 
       
    28 // FORWARD DECLARATIONS
       
    29 
       
    30 class MIpsPlgTextSearcherObserver
       
    31     {
       
    32     public:
       
    33         /**
       
    34         * Called from the text searcher when all search criteria are met.
       
    35         *
       
    36         * @param    aSnippet         The snippet
       
    37         * @param    aSnippetCharPos  The character position of the keyword 
       
    38         *                            match within the snippet
       
    39         * @param    aStartIncomplete Indicates that the snippet start is 
       
    40         *                            incomplete
       
    41         * @param    aEndIncomplete   Indicates that the snippet end is 
       
    42         *                            incomplete
       
    43         */
       
    44         virtual void HitL( 
       
    45             const TDesC& aSnippet, 
       
    46             TInt aSnippetCharPos, 
       
    47             TBool aStartIncomplete,
       
    48             TBool aEndIncomplete ) = 0;
       
    49     };
       
    50 /**
       
    51 * Original class TKeywordSearchStatus
       
    52 * from  <KeywordSearchStatus.h>. Replaced
       
    53 * for 3.2 version
       
    54 * Search status belonging to a single search keyword.
       
    55 */
       
    56 class TIpsPlgKeywordSearchStatus
       
    57 	{
       
    58 	public:
       
    59 		// Boolean indicating whether this keyword has been found
       
    60 		TBool		iFound;
       
    61 		
       
    62 		// Integer indicating in what wordposition this keyword was found
       
    63 		TInt		iFoundAsNthWord;
       
    64 	};
       
    65 	
       
    66 /**
       
    67 * Original enum used TIdsCriteriaOperation from <IdsCommonDefines.h>
       
    68 * Replaced for 3.2 version
       
    69 */	
       
    70 // Binary operators for the search criteria.
       
    71 enum TIpsPlgCriteriaOperation
       
    72     {
       
    73     EIpsPlgCriteriaOperationAND,
       
    74     EIpsPlgCriteriaOperationOR,
       
    75     EIpsPlgCriteriaOperationNOT
       
    76     };
       
    77 
       
    78 /**
       
    79 * Class handling the search of several keywords in a block of text.
       
    80 * A hit is informed via the MIpsPlgTextSearcherObserver.
       
    81 *
       
    82 * Data/text can be supplied in steps and does not need to be known in advance.
       
    83 */
       
    84 NONSHARABLE_CLASS( CIpsPlgTextSearcher ) : public CBase
       
    85     {
       
    86     public: // Constructors and destructor
       
    87         /** 
       
    88         * Symbian OS 2 phased constructor.
       
    89         *
       
    90         * @param    aObserver    Text searcher's observer
       
    91         *
       
    92         * @return    A pointer to the created instance of CIpsPlgTextSearcher.
       
    93         */
       
    94         static CIpsPlgTextSearcher* NewL( 
       
    95             MIpsPlgTextSearcherObserver& aObserver );
       
    96 
       
    97         /** 
       
    98         * Symbian OS 2 phased constructor
       
    99         *
       
   100         * @param    aObserver    Text searcher's observer
       
   101         *
       
   102         * @return    A pointer to the created instance of CIpsPlgTextSearcher.
       
   103         */
       
   104         static CIpsPlgTextSearcher* NewLC( 
       
   105             MIpsPlgTextSearcherObserver& aObserver );
       
   106         
       
   107         /**
       
   108         * Destructor.
       
   109         */
       
   110         virtual ~CIpsPlgTextSearcher();
       
   111 
       
   112     public:    // New functions
       
   113         /**
       
   114         * Cleans up internal data.  Must be called before each new search 
       
   115         * is started. Does not clean up the parameters set via SetParametersL.
       
   116         * 
       
   117         * When same search parameters are needed with different search text, 
       
   118         * call Cleanup but not SetParametersL.
       
   119         */
       
   120         void Cleanup();
       
   121 
       
   122         /**
       
   123         * Sets the search parameters for the search.
       
   124         *
       
   125         * @param    aKeywords      Keywords for the search.
       
   126         * @param    aOperator      Determines the operation for the search 
       
   127         *                          (AND, OR, ...)
       
   128         * @param    aCaseSensitive Flag indicating case sensitivity
       
   129         * @param    aRecommendedSnippetLength Recommended snippet length.
       
   130         */
       
   131         void SetParametersL( 
       
   132             const CDesCArray& aKeywords, 
       
   133             TIpsPlgCriteriaOperation aOperator, 
       
   134             TBool aCaseSensitive,
       
   135             TInt aRecommendedSnippetLength );
       
   136         
       
   137         /**
       
   138         * Starts the text search with the previous supplied parameters set 
       
   139         * by SetParametersL. 16 bit version.
       
   140         *
       
   141         * @param    aToBeSearchedDes    16 bit descriptor to be searched.
       
   142         * @return ETrue when a hit was found.  EFalse otherwise.
       
   143         */
       
   144         TBool SearchL( const TDesC& aToBeSearchedDes );
       
   145         
       
   146         /**
       
   147         * Starts the text search with the previous supplied parameters set by 
       
   148         * SetParametersL. 8 bit version.
       
   149         *
       
   150         * @param    aToBeSearchedDes    8 bit descriptor to be searched.
       
   151         * @return ETrue when a hit was found.  EFalse otherwise.
       
   152         */
       
   153         TBool SearchL( const TDesC8& aToBeSearchedDes );
       
   154 
       
   155     private:    // New functions
       
   156         /**
       
   157         * Compares the to be searched string with the list of keywords.  
       
   158         * 16 bit version.
       
   159         *
       
   160         * @param aToBeSearchedDes          Text to be searched.
       
   161         * @param aKeywords                 Array of keywords to be matched.
       
   162         * @param aKeywordSearchStatusArray Array storing the search result 
       
   163         *                                  for each individual search keyword
       
   164         * @param aOperator                 Determines the operation for 
       
   165         *                                  the search (AND, OR, ...)
       
   166         * @param aCaseSensitive            Flag indicating case sensitivity
       
   167         *
       
   168         * @return ETrue when a hit was found.  EFalse otherwise.
       
   169         */
       
   170         TBool DoStringCompareWithKeywordsL( 
       
   171             const TDesC& aToBeSearchedDes,
       
   172             const CDesCArray& aKeywords, 
       
   173             RArray<TIpsPlgKeywordSearchStatus>& aKeywordSearchStatusArray,
       
   174             TIpsPlgCriteriaOperation aOperator, 
       
   175             TBool aCaseSensitive );
       
   176 
       
   177         /**
       
   178         * Compares the to be searched string with the list of keywords.  
       
   179         * 8 bit version.
       
   180         *
       
   181         * @param aToBeSearchedDes          Text to be searched.
       
   182         * @param aKeywords                 Array of keywords to be matched.
       
   183         * @param aKeywordSearchStatusArray Array storing the search result 
       
   184         *                                  for each individual search keyword
       
   185         * @param aOperator                 Determines the operation for 
       
   186         *                                  the search (AND, OR, ...)
       
   187         * @param aCaseSensitive            Flag indicating case sensitivity
       
   188         *
       
   189         * @return ETrue when a hit was found.  EFalse otherwise.
       
   190         */
       
   191         TBool DoStringCompareWithKeywordsL( 
       
   192             const TDesC8& aToBeSearchedDes,
       
   193             const CDesC8Array& aKeywords, 
       
   194             RArray<TIpsPlgKeywordSearchStatus>& aKeywordSearchStatusArray,
       
   195             TIpsPlgCriteriaOperation aOperator, 
       
   196             TBool aCaseSensitive );
       
   197 
       
   198         /**
       
   199         * Creates the snippet from the 1st found keyword.  16 bit version.
       
   200         * 
       
   201         * @param aToBeSearchedDes Text that was searched.
       
   202         * @param aSnippetCharPos  The character position of the keyword match 
       
   203         *                         within the snippet
       
   204         * @param aStartIncomplete Indicates that the snippet start is 
       
   205         *                         incomplete
       
   206         * @param aEndIncomplete   Indicates that the snippet end is incomplete
       
   207         *
       
   208         * @return A pointer to the newly created snippet.
       
   209         */
       
   210         HBufC* CreateSnippetLC( 
       
   211             const TDesC& aToBeSearchedDes, 
       
   212             TInt& aSnippetCharPos,
       
   213             TBool& aStartIncomplete, 
       
   214             TBool& aEndIncomplete ) const;
       
   215 
       
   216         /**
       
   217         * Creates the snippet from the 1st found keyword.  8 bit version.
       
   218         * 
       
   219         * @param aToBeSearchedDes Text that was searched.
       
   220         * @param ASnippetCharPos  The character position of the keyword match 
       
   221         *                         within the snippet
       
   222         * @param aStartIncomplete Indicates that the snippet start is 
       
   223         *                         incomplete
       
   224         * @param aEndIncomplete   Indicates that the snippet end is incomplete
       
   225         * @return A pointer to the newly created snippet.
       
   226         */
       
   227         HBufC* CreateSnippetLC( 
       
   228             const TDesC8& aToBeSearchedDes, 
       
   229             TInt& aSnippetCharPos,
       
   230             TBool& aStartIncomplete, 
       
   231             TBool& aEndIncomplete );
       
   232 
       
   233         /**
       
   234          * Makes a conversion from unicode
       
   235          *
       
   236          * @param aFs             Reference to a file session 
       
   237          * @param aUnicodeSource  Source text to be converted
       
   238          * @param aTargetEncoding The UID of the non-Unicode character set from 
       
   239          *                        or to which to convert.
       
   240          * @return   Converted non-unicode descriptor
       
   241          */
       
   242         HBufC8* ConvertFromUnicodeL(
       
   243             RFs& aFs, 
       
   244             const TDesC16& aUnicodeSource,
       
   245             TUint aTargetEncoding );
       
   246 
       
   247         /**
       
   248          * Makes a conversion into unicode
       
   249          *
       
   250          * @param aFs             Reference to a file session.
       
   251          * @param aSource         Source text to be converted.
       
   252          * @param aSourceEncoding The UID of the non-Unicode character set 
       
   253          *                        from or to which to convert.
       
   254          * @return   Converted unicode descriptor
       
   255          */
       
   256         HBufC16* ConvertToUnicodeL( 
       
   257             RFs& aFs, 
       
   258             const TDesC8& aSource,
       
   259             TUint aSourceEncoding );
       
   260 
       
   261     private:    // More constructors
       
   262         /** 
       
   263         * Performs the first phase of two phase construction.
       
   264         *
       
   265         * @param    aObserver    Text searcher's observer
       
   266         */
       
   267         CIpsPlgTextSearcher( MIpsPlgTextSearcherObserver& aObserver );
       
   268         
       
   269         /**
       
   270         * Performs the second phase construction.
       
   271         */
       
   272         void ConstructL();
       
   273 
       
   274 
       
   275     private:
       
   276         // A file session for the unicode converter
       
   277         RFs iRFs;
       
   278     
       
   279         // Text searcher's observer
       
   280         MIpsPlgTextSearcherObserver& iObserver;
       
   281 
       
   282         // Array that contains 16 bit keywords to search. Not owned
       
   283         const CDesCArray* iSearchKeywords;        
       
   284         
       
   285         // Array that contains 8 bit versions from keywords to search
       
   286         // These are copied from the 16bit version when search is done in text 
       
   287         // that is available in 8 bit format
       
   288         CDesC8ArrayFlat* iSearchKeywords8;
       
   289         
       
   290         // Determines the operation for the search (AND, OR, ...)
       
   291         TIpsPlgCriteriaOperation iOperator;
       
   292         
       
   293         // Flag indicating case sensitivity
       
   294         TBool iCaseSensitive;
       
   295         
       
   296         // Flag indicating whether search parameters where set.
       
   297         TBool iHaveParameters;
       
   298         
       
   299         // Array storing the search result for each individual search keyword
       
   300         RArray<TIpsPlgKeywordSearchStatus> iKeywordSearchStatusArray;
       
   301 
       
   302         // Character position of the 1st keyword match
       
   303         TInt iFirstMatchKeywordCharPos;
       
   304         
       
   305         // Recommended snippet length.
       
   306         TInt iSearchResultRecommendedSnippetLength;
       
   307     };
       
   308 
       
   309 #endif  // IPSPLGTEXTSEARCHER_H