searchfw/plugins/contactsplugin/inc/contactssearcher.h
changeset 0 f979ecb2b13e
equal deleted inserted replaced
-1:000000000000 0:f979ecb2b13e
       
     1 /*
       
     2 * Copyright (c) 2006-2007 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:   ECom search interface definition
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_CCONTACTSSEARCHER_H
       
    22 #define C_CCONTACTSSEARCHER_H
       
    23 
       
    24 //SYSTEM INCLUDES
       
    25 #include <f32file.h>
       
    26 #include <badesca.h>
       
    27 #include <searchcontentsearcher.h>
       
    28 #include <searchcondition.h>
       
    29 
       
    30 #include <MVPbkContactStoreListObserver.h>
       
    31 #include <MVPbkSingleContactOperationObserver.h>
       
    32 #include <MVPbkContactViewObserver.h>
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CSearchCondition;
       
    36 class CVPbkContactManager;
       
    37 class CVPbkContactStoreUriArray;
       
    38 class CVPbkContactLinkArray;
       
    39 class MVPbkContactOperationBase;
       
    40 class MVPbkContactLinkArray;
       
    41 class MVPbkBaseContact;
       
    42 class CSearchFScanRegistryEntry;
       
    43 class CSearchTextSearcher;
       
    44 class MSearchPluginObserver;
       
    45 class CVPbkFieldTypeRefsList;
       
    46 class MVPbkContactViewBase;
       
    47 
       
    48 
       
    49 /**
       
    50  *  This class is the searcher class for the contacts
       
    51  *
       
    52  *  This class searches the contacts using the virtual phonebook2 apis
       
    53  *
       
    54  *  @lib contactssearchplugin.lib
       
    55  */
       
    56 class CContactsSearcher : public CActive, 
       
    57                           public MSearchContentSearcher, 
       
    58 	                      public MVPbkContactStoreListObserver,
       
    59                           public MVPbkSingleContactOperationObserver,
       
    60                           public MVPbkContactViewObserver
       
    61 {	
       
    62 public:
       
    63 	
       
    64 	
       
    65    /**
       
    66     * 1st phase constructor 
       
    67     *
       
    68 
       
    69   	* @param aContentIdArray - content id
       
    70 	* @param aCondition - condition
       
    71 	* @param aPluginId - Implementation id
       
    72 	* @return returns pointer to the constructed object of type CContactsSearcher
       
    73 	*/
       
    74 	static CContactsSearcher* NewL( const RArray<TUid>& aContentIdArray, 
       
    75                                 const CSearchCondition& aCondition, 
       
    76                                 const TUid& aPluginId,
       
    77                                 MSearchPluginObserver& aObserver );
       
    78    /**
       
    79     * Destructor
       
    80     */
       
    81     virtual ~CContactsSearcher();
       
    82    
       
    83     /**
       
    84     * A function that returns the contact link at given index
       
    85     * of the iContactLinkArray
       
    86     *
       
    87     *
       
    88     * @param aIndex
       
    89     */
       
    90     MVPbkContactLink* GetContactLinkAtIndexLC(TInt aIndex);
       
    91     
       
    92 public: //from base class MSearchContentSearcher    
       
    93     /**
       
    94     * From MSearchContentSearcher
       
    95     * Releses the object.
       
    96     *
       
    97     */
       
    98     void Destroy();
       
    99     
       
   100     
       
   101     /**
       
   102      * From MSearchContentSearcher
       
   103      * Starts the search. Progress of the search is notified through aObserver. 
       
   104      * Notice that this call must be asynchronous.
       
   105      *
       
   106      * @param aObserver Observer for search progress.
       
   107      */
       
   108      void SearchL();
       
   109     
       
   110      /**
       
   111      * From MSearchContentSearcher 
       
   112      * Function returning ETrue when a search is ongoing.  EFalse otherwise.
       
   113      * 
       
   114      * @return ETrue when a search is ongoing.  EFalse otherwise.
       
   115      */
       
   116      TBool IsSearching();
       
   117     
       
   118      /**
       
   119      * From MSearchContentSearcher 
       
   120      * Cancels the ongoing search. This call must complete synchronously and no calls for
       
   121      * observers must be made after this call.
       
   122      *
       
   123      */
       
   124      void CancelSearch();
       
   125     
       
   126     /**
       
   127      * From MSearchContentSearcher 
       
   128      * Gets the results indicated by the given document ids. Asynchronous. Results will be given
       
   129      * through callback in MSearchPlugInObserver given in Search request.
       
   130      * 
       
   131      * @param aResults Results of the search process. Ownership transfers to caller.
       
   132      */
       
   133      void GetResultsL( const RPointerArray<CSearchDocumentId>& aDocumentIdArray );
       
   134     
       
   135     /**
       
   136      * From MSearchContentSearcher 
       
   137      * Cancels the result retrieval process.
       
   138      *
       
   139      */
       
   140      void CancelResultsRetrieve();
       
   141     
       
   142     /**
       
   143      * From MSearchContentSearcher 
       
   144      * Gets the current search progress. 
       
   145      *
       
   146      * @param aContentClassId On return contains the content class id, which is currently searched.
       
   147      * @param aCurrentDocument On return contains the index document that is currently being searched.
       
   148      * @param aTotalDocuments On return contains the total count of documents to be searched.
       
   149      */         
       
   150      void GetSearchProgressL( TUid& aContentClassId, TInt& aCurrentDocument, TInt& aTotalDocuments );
       
   151 
       
   152 
       
   153     /**
       
   154     * From MSearchContentSearcher , through MSearchTextSearcherObserver
       
   155     * Called when all search criteria are met.
       
   156     *
       
   157     * @param aCharPos The character position of the keyword match within the original text.
       
   158     */
       
   159     void HitL( TInt aCharPos );
       
   160   
       
   161     HBufC8* LaunchInfoL( const CSearchDocumentId& aDocumentID );
       
   162 
       
   163     
       
   164 public:
       
   165      // from base class MVPbkContactStoreListObserver
       
   166      
       
   167      /**
       
   168       * From MVPbkContactStoreListObserver  
       
   169       * Called when the opening process is complete, ie. all stores have been reported
       
   170       * either failed or successful open.
       
   171       *
       
   172       */
       
   173       void OpenComplete();  
       
   174       
       
   175      /**
       
   176       * From MVPbkContactStoreListObserver  
       
   177       * Called when a contact store is ready to use.
       
   178       */
       
   179       void StoreReady(MVPbkContactStore& aContactStore);
       
   180 
       
   181      /**
       
   182       * From MVPbkContactStoreListObserver  
       
   183       * Called when a contact store becomes unavailable.
       
   184       * Client may inspect the reason of the unavailability and decide whether or not
       
   185       * it will keep the store opened (ie. listen to the store events).
       
   186       *
       
   187       *
       
   188       * @param aContactStore The store that became unavailable.
       
   189       * @param aReason The reason why the store is unavailable.
       
   190       *                This is one of the system wide error codes.
       
   191       */
       
   192       void StoreUnavailable(MVPbkContactStore& aContactStore, TInt aReason);
       
   193 
       
   194      /**
       
   195       * From MVPbkContactStoreListObserver  
       
   196       * Called when changes occur in the contact store.
       
   197       * @see TVPbkContactStoreEvent
       
   198       * @param aContactStore The store the event occurred in.
       
   199       * @param aStoreEvent   Event that has occured.
       
   200       */
       
   201       void HandleStoreEventL(
       
   202                 MVPbkContactStore& aContactStore, 
       
   203                 TVPbkContactStoreEvent aStoreEvent);
       
   204 
       
   205     
       
   206 public:
       
   207       // From base class MVPbkSingleContactOperationObserver
       
   208           
       
   209       /**
       
   210        * From MVPbkSingleContactOperationObserver
       
   211        * Called when operation is completed.
       
   212        *
       
   213        *
       
   214        * @param aOperation the completed operation.
       
   215        * @param aContact  the contact returned by the operation.
       
   216        *                  Client must take the ownership immediately.
       
   217        *
       
   218        *                  !!! NOTICE !!!
       
   219        *                  If you use Cleanupstack for MVPbkStoreContact
       
   220        *                  Use MVPbkStoreContact::PushL or
       
   221        *                  CleanupDeletePushL from e32base.h.
       
   222        *                  (Do Not Use CleanupStack::PushL(TAny*) because
       
   223        *                  then the virtual destructor of the M-class
       
   224        *                  won't be called when the object is deleted).
       
   225        */
       
   226        void VPbkSingleContactOperationComplete(
       
   227                 MVPbkContactOperationBase& aOperation,
       
   228                 MVPbkStoreContact* aContact );
       
   229 
       
   230       /**
       
   231        * From MVPbkSingleContactOperationObserver
       
   232        * Called if the operation fails.
       
   233        *
       
   234        * @param aOperation    the failed operation.
       
   235        * @param aError        error code of the failure.
       
   236        */
       
   237        void VPbkSingleContactOperationFailed(
       
   238                 MVPbkContactOperationBase& aOperation, 
       
   239                 TInt aError );
       
   240        
       
   241 public:
       
   242        void ContactViewReadyL(
       
   243                           MVPbkContactViewBase& aView );
       
   244        //From MVPbkContactViewObserver
       
   245        /**
       
   246         * Called when a view is ready for use. 
       
   247         * 
       
   248         * This function may also be called if view is already ready. Then
       
   249         * it means that the view has been updated and the observer have
       
   250         * to take this into account.
       
   251         *
       
   252         * @param aView A contact view sending the event.
       
   253         */
       
   254        void ContactViewReady(
       
   255                       MVPbkContactViewBase& aView );
       
   256 
       
   257        /**
       
   258         * Called when a view is unavailable for a while. 
       
   259         * 
       
   260         * When the view is again available ContactViewReady will be called.
       
   261         * The contents of the view may change completely while it is
       
   262         * unavailable.
       
   263         *
       
   264         * @param aView A contact view sending the event.
       
   265         */
       
   266        void ContactViewUnavailable(
       
   267                       MVPbkContactViewBase& aView );
       
   268        
       
   269        /**
       
   270         * Called when a contact has been added to the view.
       
   271         *
       
   272         * @param aView A contact view sending the event.
       
   273         * @param aIndex An index of the contact in the view.
       
   274         * @param aContactLink A link to the added contact that is
       
   275         *                     valid only during the functio call.
       
   276         */
       
   277        void ContactAddedToView(
       
   278                       MVPbkContactViewBase& aView, 
       
   279                       TInt aIndex, 
       
   280                       const MVPbkContactLink& aContactLink );
       
   281        
       
   282        /**
       
   283         * Called when a contact has been removed from a view.
       
   284         *
       
   285         * @param aView A contact view sending the event.
       
   286         * @param aIndex An index of the removed contact.
       
   287         * @param aContactLink A link to the removed contact that is
       
   288         *                      valid only during this function call.
       
   289         */
       
   290        void ContactRemovedFromView(
       
   291                       MVPbkContactViewBase& aView, 
       
   292                       TInt aIndex, 
       
   293                       const MVPbkContactLink& aContactLink );
       
   294        
       
   295        /**
       
   296         * Called when an error occurs in the view.
       
   297         *
       
   298         * If client decides to destroy the view then it should do
       
   299         * it asynchronously because the view can access member data
       
   300         * after a call to this.
       
   301         *
       
   302         * @param aView A contact view sending the event.
       
   303         * @param aError An error code of the failure.
       
   304         * @param aErrorNotified  ETrue if the implementation has already 
       
   305         *                        notified user about the error using e.g
       
   306         *                        an ECOM plug-in, EFalse otherwise.
       
   307         */
       
   308        void ContactViewError(
       
   309                       MVPbkContactViewBase& aView, 
       
   310                       TInt aError, 
       
   311                       TBool aErrorNotified );
       
   312        
       
   313     
       
   314 protected: // From base class CActive
       
   315     
       
   316     /**
       
   317     * From CActive
       
   318     * Implements cancellation of an outstanding request.
       
   319 	*
       
   320 	* This function is called as part of the active object's Cancel().
       
   321 	*/
       
   322 	void DoCancel() ;
       
   323     
       
   324    /**
       
   325     * From CActive
       
   326 	* Handles an active object's request completion event.
       
   327 	*
       
   328 	* The function is called by the active scheduler when a request
       
   329 	* completion event occurs, i.e. after the active scheduler's
       
   330 	* WaitForAnyRequest() function completes.
       
   331 	*
       
   332 	* Before calling this active object's RunL() function, the active scheduler 
       
   333 	* has:
       
   334     * 	
       
   335 	* 1. decided that this is the highest priority active object with
       
   336 	*   a completed request
       
   337 	*
       
   338     * 2. marked this active object's request as complete (i.e. the request is no 
       
   339 	*   longer outstanding)
       
   340 	*
       
   341 	* RunL() runs under a trap harness in the active scheduler. If it leaves,
       
   342 	* then the active scheduler calls RunError() to handle the leave.
       
   343 	*
       
   344 	* Note that once the active scheduler's Start() function has been called, 
       
   345 	* all user code is run under one of the program's active object's RunL() or 
       
   346 	* RunError() functions.
       
   347 	*
       
   348 	*/
       
   349 	void RunL();
       
   350     
       
   351     	
       
   352    /**
       
   353 	* From CActive 
       
   354 	* If the RunL function leaves,
       
   355 	* then the active scheduler calls RunError() to handle the leave.
       
   356 	*
       
   357 	*/
       
   358 	TInt RunError( TInt aError );
       
   359 	
       
   360 	
       
   361 private:	
       
   362    /**
       
   363     * Constructor
       
   364     *
       
   365     *
       
   366     * @param aPluginId
       
   367     */
       
   368     CContactsSearcher( const TUid& aPluginId );
       
   369     
       
   370    /** 
       
   371     * 2nd phase constructor
       
   372     *
       
   373     * @param aContentIdArray
       
   374     * @param aCondition
       
   375     */
       
   376     void ConstructL( const RArray<TUid>& aContentIdArray, 
       
   377 	                 const CSearchCondition& aCondition,
       
   378 	                 MSearchPluginObserver& aObserver );
       
   379 	
       
   380   /**
       
   381     * Notifies the observer about the search complete
       
   382     *
       
   383     */
       
   384     void ReportFinishedL();
       
   385     
       
   386     /**
       
   387     * Cleans up the memory held
       
   388     *
       
   389     */
       
   390     void CleanUp();
       
   391  
       
   392 	/**
       
   393 	* Does actual search
       
   394 	*
       
   395 	*
       
   396 	*/
       
   397 	TBool DoActualSearchL();
       
   398 
       
   399 
       
   400 	/**
       
   401     * Fetches the contact items from the database.
       
   402     *
       
   403     */
       
   404 	void FetchContactItemsFromDbAndSearchL();
       
   405     
       
   406     /**
       
   407     * Handles the operations for a single contact after it is fetched
       
   408     *
       
   409 	*
       
   410 	* @param aContact - The contact from database 
       
   411     */
       
   412     void HandleRetrievedContactL(MVPbkStoreContact* aContact );
       
   413     
       
   414     /**
       
   415     * Fetches the data from a particular contact 
       
   416     *
       
   417     *	
       
   418 	* @param aContact - The contact from database 
       
   419     * 
       
   420     */
       
   421     void  GetDataForSingleContactL ( MVPbkBaseContact& aContact );
       
   422     
       
   423     /**
       
   424     * Add the data from contact fields
       
   425     *
       
   426 	*
       
   427 	* @param aContact - The contact from database 
       
   428     * @param afieldtype- Field to be added 
       
   429     */
       
   430     void AddContactFieldsL(MVPbkBaseContact& aContact,TInt afieldtype);
       
   431 
       
   432    
       
   433    
       
   434 private: // Data
       
   435     
       
   436     /**
       
   437      *PluginId of contacts plugin
       
   438      */ 
       
   439     TUid iPluginId;         
       
   440     
       
   441     /**
       
   442      * Number of contacts searched 
       
   443      */
       
   444     TInt iTotalNumOfContactsSearched; 
       
   445     
       
   446     /**
       
   447      *Total Number of matches
       
   448      */
       
   449     TInt iTotalHits;        
       
   450     /**
       
   451      * Flags for  store operations
       
   452      */
       
   453     TBool iStoreReadyForAccessing ;
       
   454     TBool iAtLeastOneStoreReady;
       
   455     TBool iAllContactsSearched;
       
   456     TBool iNoContactStoreAvailable;
       
   457     TBool iSearchStarted;
       
   458     TBool iSearchCancelled;
       
   459     
       
   460     
       
   461     
       
   462     /**
       
   463      * Text searcher
       
   464      * Own.  
       
   465      */
       
   466      CSearchTextSearcher* iTextSearcher; // Text searcher
       
   467     
       
   468     /**
       
   469      * Search Plugin Observer
       
   470      * Own.  
       
   471      */
       
   472      MSearchPluginObserver*      iObserver;
       
   473    	
       
   474    	
       
   475     /**
       
   476      * Contact Link array containing the contact links of all the contacts in the database
       
   477      * Own.  
       
   478      */
       
   479     CVPbkContactLinkArray* iAllContactItemsFromDb;
       
   480     
       
   481     /**
       
   482      * The contact manager for accessing the phone contacts
       
   483      * Own.  
       
   484      */
       
   485     CVPbkContactManager*  iContactManager;
       
   486     
       
   487     /**
       
   488      * The contact Uri Array 
       
   489      * Own.  
       
   490      */
       
   491      CVPbkContactStoreUriArray* iCurrentlyOpenStores;
       
   492     
       
   493      /**
       
   494      * The contact operation. Used during Find operation
       
   495      * Own.  
       
   496      */
       
   497      MVPbkContactOperationBase* iVPbkOperation;
       
   498     
       
   499     /**
       
   500      * The Field types to be searched.Used during Find operation
       
   501      * Own.  
       
   502      */
       
   503      CVPbkFieldTypeRefsList* iFieldTypeRefList ;
       
   504     
       
   505     /**
       
   506     * The contact data to be searched
       
   507     * Own.  
       
   508     */
       
   509     HBufC* iContactsDataTobeSearched ;	
       
   510     
       
   511     /**
       
   512     * The file session
       
   513     */
       
   514 	RFs ifSession;
       
   515 	
       
   516 
       
   517 	/**
       
   518      * Title,snippet,current contact data buffers
       
   519      */
       
   520     HBufC* iCurrentTitle;
       
   521     HBufC8* iCurrentSnippet;
       
   522     HBufC* iCurrentContactDataString;
       
   523     HBufC* iBufferForQuery;
       
   524    /**
       
   525     * The contact link currently being accessed
       
   526     * Own
       
   527     */
       
   528     TInt iCurrentContactLinkIndex;
       
   529       
       
   530    /**
       
   531     * The array containing the heavy results data
       
   532     * Own
       
   533     */
       
   534     RPointerArray<CSearchResult> iHeavyResultsArray;
       
   535     
       
   536    /**
       
   537     * The search strings used for searching in the contacts database 
       
   538     * Own
       
   539     */
       
   540     CDesCArrayFlat* iSearchStrings;
       
   541     
       
   542     /**
       
   543     * The array containing the map data from iHeavyResultsArray to
       
   544     * iAllContactItemsFromDb
       
   545     * 
       
   546     */
       
   547     RArray<TInt>    iContactArrayMapper;
       
   548 
       
   549     /**
       
   550     * The array containing data for deleted contacts
       
   551     * 
       
   552     */
       
   553     RArray<TBool> iCotnactDeletedList;
       
   554     
       
   555     /**
       
   556     * The current database item in use
       
   557     * 
       
   558     */
       
   559     TBool iIsFilterView;
       
   560     
       
   561     MVPbkContactViewBase* iContactViewBase;
       
   562     MVPbkContactViewBase* iFilterView;
       
   563     TInt iCurrentDatatBaseItemIndex; 
       
   564 };
       
   565 
       
   566 
       
   567 
       
   568 
       
   569 
       
   570 #endif //C_CCONTACTSSEARCHER_H
       
   571 
       
   572 
       
   573