uiservicetab/vimpstdetailsviewplugin/inc/cvimpstdetailscontacthandler.h
branchRCL_3
changeset 23 9a48e301e94b
parent 0 5e5d6b214f4f
equal deleted inserted replaced
22:3104fc151679 23:9a48e301e94b
       
     1 /*
       
     2 * Copyright (c) 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:  contact handler class implementaion to virtual phonebook observers
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef CVIMPSTCONTACTHANDLER_H
       
    20 #define CVIMPSTCONTACTHANDLER_H
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <badesca.h>
       
    24 #include <s32file.h>
       
    25 #include <d32dbms.h> 
       
    26 
       
    27 #include <MVPbkSingleContactOperationObserver.h>
       
    28 #include <MVPbkContactFindObserver.h>
       
    29 #include <MVPbkContactStoreListObserver.h>
       
    30 #include <CVPbkContactIdConverter.h>
       
    31 
       
    32 // forward declaration
       
    33 class CVPbkContactManager;
       
    34 class MVPbkContactLinkArray;
       
    35 class MVPbkContactLink;
       
    36 class MVPbkStoreContact;
       
    37 class MVPbkContactOperationBase;
       
    38 class MVPbkContactStoreList;
       
    39 class MVIMPSTDetailsViewContactObserver;
       
    40 class MCCAParameter;
       
    41 
       
    42 enum TStoreType
       
    43     {
       
    44     EStoreUnkwon = -1,
       
    45     EStoreLocal,
       
    46     EStoreServer
       
    47     };
       
    48 /**
       
    49  *  contact handler class implementaion to virtual phoneboo observers
       
    50  *  @lib vimpstdetailsviewplugin.dll
       
    51  *  @since S60 v5.0
       
    52  */
       
    53 class CVIMPSTDetailsContactHandler :  public CActive,
       
    54 							   public MVPbkSingleContactOperationObserver,
       
    55 							   public MVPbkContactFindObserver,
       
    56 							   public MVPbkContactStoreListObserver
       
    57 	{
       
    58 
       
    59 	public:
       
    60 
       
    61 	    /**
       
    62 	     * Two-phased constructor.
       
    63 	     * @param aParameter , reference to plugin parameter
       
    64 	     * @param aObserver , reference to contact view class
       
    65 	     * @param aServiceStoreUri , service store name
       
    66 	     * @return instance of same class 
       
    67 	     * @since S60 v5.0
       
    68 	     * 
       
    69 	     */
       
    70 	    static CVIMPSTDetailsContactHandler* NewL( MCCAParameter& aParameter,
       
    71 	    									MVIMPSTDetailsViewContactObserver& aObserver,
       
    72 	    									const TDesC& aServiceStoreUri,
       
    73 	    									const TDesC& aServiceName,
       
    74 	    									TUint aserviceId);
       
    75 
       
    76 	    /**
       
    77 	     * Destructor.
       
    78 	     * @since S60 v5.0
       
    79 	     */
       
    80 	    ~CVIMPSTDetailsContactHandler();
       
    81 	    
       
    82 	    /**
       
    83 	     * set the specified link ,it take the ownership of links.
       
    84 	     * @param aLinks , links to set
       
    85 	     * @param aReadXspId , need to read xsp id from contacts.cdb or not
       
    86 	     * @since S60 v5.0
       
    87 	     */
       
    88 	    void SetLinks( MVPbkContactLinkArray* aLinks,TBool aReadXspId );
       
    89 	    
       
    90 	    /**
       
    91 	     * @return XSPuserId.
       
    92 	     * @since S60 v5.0
       
    93 	     */
       
    94 	    const TDesC& GetXSPUserId();
       
    95 	    
       
    96 	    /**
       
    97 	     * @return List of all open store.
       
    98 	     * @since S60 v5.0
       
    99 	     */
       
   100 	    MVPbkContactStoreList& ContactStoresL();
       
   101 
       
   102 	    /**
       
   103         * @return store type
       
   104         * @since S60 v5.0
       
   105         */
       
   106 	    TStoreType StoreType();
       
   107 	    
       
   108 	    /**
       
   109 	     * @return current iCurrentLink.
       
   110 	     * @since S60 v5.0
       
   111 	     */
       
   112 	    MVPbkContactLinkArray* Links() const;
       
   113 	    
       
   114 	     /**
       
   115 	     * cancel the ongoing request.
       
   116 	     * @since S60 v5.0
       
   117 	     */
       
   118 	    void CancelOngoingRequest();
       
   119 
       
   120 	public: // From CActive
       
   121 		/**
       
   122 	     * from CActive.
       
   123 	     * @since S60 v5.0
       
   124 	     */
       
   125 	    void RunL();
       
   126 
       
   127 		/**
       
   128 	     * from CActive.
       
   129 	     * @since S60 v5.0
       
   130 	     */
       
   131 	    TInt RunError(TInt aError);
       
   132 
       
   133 		/**
       
   134 	     * from CActive.
       
   135 	     * @since S60 v5.0
       
   136 	     */
       
   137 	    void DoCancel();
       
   138 
       
   139 	public: // From MVPbkSingleContactOperationObserver
       
   140 
       
   141 		/**
       
   142 	     * from MVPbkSingleContactOperationObserver.
       
   143 	     * Called when the operation is completed.
       
   144          *
       
   145          * A client has the operation as a member and it can delete the operation
       
   146          * instance in this function call. If the implementation of the store
       
   147          * calls the function from the operation instance it must not handle
       
   148          * any member data after calling it.
       
   149          *
       
   150          * @param aOperation The completed operation.
       
   151          * @param aContact The contact returned by the operation.
       
   152          *                 A client must take the ownership immediately.
       
   153          *
       
   154          *                  NOTE:
       
   155          *                  If you use CleanupStack for MVPbkStoreContact
       
   156          *                  Use MVPbkStoreContact::PushL or
       
   157          *                  CleanupDeletePushL from e32base.h.
       
   158          *                  (Do Not Use CleanupStack::PushL(TAny*) because
       
   159          *                  then the virtual destructor of the M-class
       
   160          *                  won't be called when the object is deleted).
       
   161          * @since S60 v5.0
       
   162 	     */
       
   163 	    void VPbkSingleContactOperationComplete(
       
   164 						        MVPbkContactOperationBase& aOperation,
       
   165 						        MVPbkStoreContact* aContact);
       
   166 
       
   167 		/**
       
   168 	     * from MVPbkSingleContactOperationObserver.
       
   169 	     * Called if the operation fails.
       
   170          *
       
   171          * A client has the operation as a member and it can delete the operation
       
   172          * instance in this function call. If the implementation of the store
       
   173          * calls the function from the operation instance it must not handle
       
   174          * any member data after calling it.
       
   175          *
       
   176          * @param aOperation The failed operation.
       
   177          * @param aError An error code of the failure.
       
   178          * @since S60 v5.0
       
   179 	     */
       
   180 	    void VPbkSingleContactOperationFailed(
       
   181 						        MVPbkContactOperationBase& aOperation,
       
   182 						        TInt aError);
       
   183 	
       
   184 	public: // From MVPbkContactFindObserver
       
   185 		/**
       
   186          * Called when find is complete. Caller takes ownership of the results
       
   187          * In case of an error during find, the aResults may contain only 
       
   188          * partial results of the find
       
   189          *
       
   190          * @param aResults Array of contact links that matched the find
       
   191          *                 Callee must take ownership of this object in
       
   192          *                 the start of the function, ie. in case the 
       
   193          *                 function leaves the results must be destroyed. 
       
   194          *                 The find operation can be destroyed at the end 
       
   195          *                  of this callback.
       
   196          */
       
   197         void FindCompleteL( MVPbkContactLinkArray* aResults ) ;
       
   198 
       
   199         /**
       
   200          * Called in case the find fails for some reason. The find operation
       
   201          * can be destroyed at the end of this callback.
       
   202          * 
       
   203          * @param aError One of the system wide error codes.
       
   204          *        KErrNotReady if store is not ready (not open or unavailable)
       
   205          */
       
   206         void FindFailed( TInt aError ) ;
       
   207 		
       
   208 		/* 
       
   209 		* get the display name of the contact to show in the status pane
       
   210 		*/
       
   211         
       
   212         HBufC* GetDisplayNameLC();
       
   213   
       
   214   private: // From MVPbkContactStoreListObserver
       
   215 
       
   216 		/**
       
   217 		 * from MVPbkContactStoreListObserver
       
   218 	     * Called when the opening process is complete. 
       
   219          *
       
   220          * Before this all stores have sent StoreReady or StoreUnavailable 
       
   221          * event. The client can not trust that all stores are available
       
   222          * for use when this is called.
       
   223          * @since S60 v5.0
       
   224 	     */
       
   225 	    void OpenComplete();
       
   226 
       
   227 		/**
       
   228 		 * from MVPbkContactStoreListObserver
       
   229 	     * Called when a contact store is ready to use.
       
   230          *
       
   231          * @param aContactStore The store that is ready.
       
   232 	     * @since S60 v5.0
       
   233 	     */
       
   234 	    void StoreReady(MVPbkContactStore& aContactStore );
       
   235 
       
   236 		/**
       
   237 		 * from MVPbkContactStoreListObserver
       
   238 	     * Called when a contact store becomes unavailable.
       
   239          *
       
   240          * Client may inspect the reason of the unavailability and decide
       
   241          * whether or not it will keep the store opened (ie. listen to 
       
   242          * the store events).
       
   243          *
       
   244          * @param aContactStore The store that became unavailable.
       
   245          * @param aReason The reason why the store is unavailable.
       
   246          *                This is one of the system wide error codes.
       
   247 	     * @since S60 v5.0
       
   248 	     */
       
   249 	    void StoreUnavailable(MVPbkContactStore& aContactStore, TInt aReason );
       
   250 
       
   251 		/**
       
   252 		 * from MVPbkContactStoreListObserver
       
   253 	     * Called when changes occur in the contact store.
       
   254          *
       
   255          * @see TVPbkContactStoreEvent
       
   256          * @param aContactStore A store whose event it is.
       
   257          * @param aStoreEvent The event that has occurred.
       
   258 	     * @since S60 v5.0
       
   259 	     */
       
   260 	    void HandleStoreEventL(MVPbkContactStore& aContactStore, TVPbkContactStoreEvent aStoreEvent );
       
   261 
       
   262      
       
   263 	private:
       
   264 
       
   265 		/**
       
   266 	     * default constructor
       
   267 	     * @param aObserver , contact observer
       
   268 	     * @since S60 v5.0
       
   269 	     */
       
   270 	    CVIMPSTDetailsContactHandler( MVIMPSTDetailsViewContactObserver& aObserver, TUint aserviceId );
       
   271 
       
   272 		/**
       
   273 	     * provides two phase constrcution.
       
   274 	     * @param aPluginParameter , plugin parameter
       
   275 	     * @param aServiceStoreUri , service store name
       
   276 	     * @since S60 v5.0
       
   277 	     */
       
   278 	    void ConstructL( MCCAParameter& aParameter, const TDesC& aServiceStoreUri, const TDesC& aServiceName );
       
   279 	    
       
   280 	   	/**
       
   281 	     * helper method for issue pending request.
       
   282 	     * @param aError , error if any 
       
   283 	     * @since S60 v5.0
       
   284 	     */
       
   285 	    void IssueRequest(TInt aError = KErrNone);
       
   286 	    
       
   287 	    /* API to be used for local store only
       
   288 	     * to check whether the phonebook contact is a buddy the service installed
       
   289 	     * @ param aCurrentLink of the phonebook contact
       
   290 	     * return ETrue if the link is a buddy of that service
       
   291 	     * @since S60 v5.0
       
   292 	     */
       
   293 	    TBool CheckWhetherValidLocalLinkL(
       
   294 	            const MVPbkContactLink& aCurrentLink );
       
   295 	    
       
   296 	    /* API to be used for local store service only
       
   297 	     * to check whether the local %service_name%.db (which has contact identifiers) 
       
   298 	     * exsists already
       
   299 	     */
       
   300 	    TBool DbExists();
       
   301 	    /* API to be used for local store only
       
   302 	     * open's the local %service_name%.db file
       
   303 	     */
       
   304 	    void OpenDbL();
       
   305 	    
       
   306 	     /* API to be used for local store only
       
   307 	     * close's the local %service_name%.db file
       
   308 	     */
       
   309 	    void CloseDb();
       
   310 	    
       
   311 	    /* API to be used for local store only
       
   312 	     * search the identifier aIdentifier passed in the ColNo aColNo of the db file
       
   313 	     * return ETrue if the identifier is found in the db col
       
   314 	     * @since S60 v5.0
       
   315 	     */
       
   316 	    TBool SeekRowL( TDbColNo aColNo, TInt32& aIdentifier );
       
   317 	    
       
   318 	    /* API to be used for local store only
       
   319 	     * open db table
       
   320 	     * @since S60 v5.0
       
   321 	     */	     
       
   322 	    void OpenTableL();
       
   323 
       
   324 	   
       
   325 	private:    // data
       
   326 	    
       
   327 		/**
       
   328 		* Not own : Reference to details view plugin
       
   329 		*/
       
   330 		MVIMPSTDetailsViewContactObserver& iObserver;
       
   331 
       
   332 		/**
       
   333 		* own :Reference to contact manager.
       
   334 		*/
       
   335 		CVPbkContactManager* iContactManager;
       
   336 
       
   337 		/**
       
   338 		* owns : reference to link array
       
   339 		*/ 
       
   340 		MVPbkContactLinkArray* iLinks;
       
   341 
       
   342 		/**
       
   343 		* not owns : reference to contact link which is owned by iLinks
       
   344 		*/
       
   345 		const MVPbkContactLink* iCurrentLink;
       
   346 
       
   347 		/**
       
   348 		* owns : reference to operation base contact
       
   349 		*/
       
   350 		MVPbkContactOperationBase* iRetrieveOperation;
       
   351 
       
   352 		/**
       
   353 		* owns : extracted user id from pbk xsp id 
       
   354 		*/
       
   355 		HBufC* iXSPUserId;
       
   356 
       
   357 		/**
       
   358 		* owns : if ETrue , xsp id need to read
       
   359 		*/
       
   360 		TBool iReadXspId;
       
   361 
       
   362 		/**
       
   363 		* owns : list of open store
       
   364 		*/
       
   365 		MVPbkContactStoreList* iStoreList;
       
   366 
       
   367 		/**
       
   368 		*  owns : reference to active chedular
       
   369 		*/
       
   370 		CActiveSchedulerWait iWait;
       
   371 
       
   372 		/**
       
   373 		* owns : service store uri
       
   374 		*/
       
   375 		HBufC* iServiceStoreUri;
       
   376 		
       
   377 				
       
   378 		/**
       
   379 		 * Owned : Pointer to MVPbkStoreContact
       
   380 		 */
       
   381 		MVPbkStoreContact* iStoreContact; 
       
   382 	 
       
   383 		// owns : store type
       
   384 		TStoreType iStoreType;
       
   385 		
       
   386 		//  owns, service name 
       
   387 		HBufC* iServiceName;
       
   388 		
       
   389 
       
   390         //Ownns - DB Store
       
   391         CPermanentFileStore*    iFileStore;
       
   392 
       
   393         //File Stream 
       
   394         RFs     iFs;
       
   395         
       
   396         //DataBase Object for Creating/Opening/Closing DB
       
   397         RDbStoreDatabase        iDb;
       
   398         
       
   399         // current column set
       
   400         CDbColSet*          iColset;        // owned
       
   401 
       
   402         
       
   403         RDbTable            iTable;         // current table
       
   404         
       
   405         // own , contact id converter to and from link
       
   406         CVPbkContactIdConverter* iIdConverter;
       
   407         
       
   408         TUint iServiceId;
       
   409       
       
   410 	  	};
       
   411 
       
   412 #endif // CVIMPSTCONTACTHANDLER_H
       
   413 
       
   414 // End of File