emailuis/emailui/inc/FreestyleEmailUiContactHandler.h
branchRCL_3
changeset 64 3533d4323edc
child 73 c8382f7b54ef
equal deleted inserted replaced
63:d189ee25cf9d 64:3533d4323edc
       
     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 interface
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef FREESTYLEEMAILUICONTACTHANDLER_H_
       
    20 #define FREESTYLEEMAILUICONTACTHANDLER_H_
       
    21 
       
    22 #include <e32base.h>
       
    23 #include <MVPbkSingleContactOperationObserver.h>
       
    24 #include <MVPbkContactStoreListObserver.h>
       
    25 #include <AiwCommon.h>
       
    26 
       
    27 // CCA Launcher view
       
    28 #include <mccaconnection.h>
       
    29 
       
    30 #include <cpbkxremotecontactlookupserviceuicontext.h>
       
    31 
       
    32 #include "FreestyleEmailUiCLSListsObserver.h"
       
    33 
       
    34 // Forward declarations
       
    35 
       
    36 class CFSMailBox;
       
    37 class RFs;
       
    38 class CFSEmailUiClsListsHandler;
       
    39 class CVPbkContactManager;
       
    40 class CFSEmailUiClsItem;
       
    41 class MVPbkContactOperationBase;
       
    42 class MVPbkStoreContact;
       
    43 class MFSEmailUiContactHandlerObserver;
       
    44 class MVPbkContactLinkArray;
       
    45 class CAiwServiceHandler;
       
    46 class CContactItem;
       
    47 class MPbkGlobalSetting;
       
    48 class CEikonEnv;
       
    49 
       
    50 /** Contact handler commands. */
       
    51 enum TContactHandlerCmd
       
    52     {
       
    53     EAddToContactL = 1,
       
    54     EFindAndCallToContactByEmailL,
       
    55     ECallToContact,
       
    56     EShowContactDetailsL,
       
    57     EGetAddressesFromPhonebook,
       
    58     ESearchContacts,
       
    59     ECreateMessage,
       
    60     EIdle
       
    61     };
       
    62 
       
    63 enum TContactUpdateType
       
    64     {
       
    65     EContactUpdateNumber = 1,
       
    66     EContactUpdateEmail
       
    67     };
       
    68 
       
    69 enum TContactHandlerState 
       
    70 	{
       
    71 	EContactHandlerIdle = 1,
       
    72 	EContactHandlerSearchMatches,
       
    73 	EContactHandlerAddToContacts,
       
    74 	EContactHandlerCallToContactByEmail,
       
    75 	EContactHandlerGetAddressesFromPhonebook,
       
    76 	EContactHandlerGetSmsAddressFromPhonebook,
       
    77 	EContactHandlerGetMmsAddressFromPhonebook,
       
    78 	EContactHandlerGetVoiceMsgAddressFromPhonebook,
       
    79 	EContactHandlerShowContactDetails,
       
    80 	EContactHandlerCreateMessage
       
    81 	};
       
    82 
       
    83 enum TContactHandlerRemoteLookupMode
       
    84 	{
       
    85 	EContactHandlerRemoteSelector = 1,
       
    86 	EContactHandlerRemoteNormal,
       
    87 	EContactHandlerRemoteQueryGiven
       
    88 	};
       
    89 
       
    90 enum TAddToContactsType
       
    91 	{
       
    92 	EContactHandlerCreateNewContact = 1,
       
    93 	EContactHandlerUpdateExisting
       
    94 	};
       
    95 
       
    96 class CFSEmailUiContactHandler: 
       
    97 	public CBase,
       
    98 	public MFSEmailUiClsListsObserver,
       
    99 	public MVPbkSingleContactOperationObserver,
       
   100 	public MVPbkContactStoreListObserver,
       
   101 	public MAiwNotifyCallback, 
       
   102 	public MCCAObserver
       
   103 
       
   104 {
       
   105 public:
       
   106     static CFSEmailUiContactHandler* NewL( RFs& aSession );
       
   107     static CFSEmailUiContactHandler* NewLC( RFs& aSession );
       
   108     
       
   109 	~CFSEmailUiContactHandler();
       
   110 	
       
   111 	/**
       
   112 	 * Implements "Add to Contacts" funcionality. 
       
   113 	 * It will launch AIW service (phonebook2) to create those views  
       
   114 	 *
       
   115 	 * @param aDes = phonenumber/emailaddress to be added
       
   116 	 * @param aUpdatetype = EContactUpdateNumber/EContactUpdateEmail
       
   117 	 * @param aAddtoContactsType = ECreateNew/EUpdateExisting
       
   118 	 * @param aObserver, when AIW service is completed observer operationComplete( EAddToContactL, NULL ) is called
       
   119 	 * if there's a error operationError is called. If caller isn't interested of result, this can be left as NULL
       
   120 	 */
       
   121 	void AddToContactL( const TDesC& aDes, TContactUpdateType aUpdateType,
       
   122 						TAddToContactsType aAddtoContactsType,
       
   123 	                    MFSEmailUiContactHandlerObserver* aObserver = NULL );
       
   124 	/**
       
   125 	 * Query whether to create a "new contact" or "update existing"
       
   126 	 * @param TAddtoContactsType = ECreateNew/EUpdateExisting
       
   127 	 * @return: EFalse if user choosed "cancel" instead of choosing one option
       
   128 	 */
       
   129     TBool AddtoContactsQueryL( TAddToContactsType& aType );
       
   130     
       
   131 	/**
       
   132 	 * Implements "Calling to contact provided by email" funcionality. 
       
   133 	 * It will search for the Contact and then launch AIW call service.
       
   134 	 *
       
   135 	 * @param aEmailAddress = emailaddress of the contact
       
   136 	 * @param aCallToDefaultNumber = ETrue, call is made to default phonenumber. EFalse = User is queried of the number.
       
   137 	 * @param aObserver, when AIW service is completed observer operationComplete( EFindAndCallToContactByEmailL, NULL ) 
       
   138 	 * is called if there's a error operationError is called. If caller isn't interested of result, this can be left as NULL
       
   139 	 */	
       
   140 	void FindAndCallToContactByEmailL( const TDesC& aEmailAddress, 
       
   141 									   CFSMailBox* aMailBox,
       
   142 	                                   MFSEmailUiContactHandlerObserver* aObserver = NULL,
       
   143 	                                   TBool aCallToDefaultNumber = EFalse );
       
   144 	
       
   145 	/**
       
   146 	 * Implements "Sending message to contact provided by email" funcionality. 
       
   147 	 * It will search for the Contact and then launch create message dialog
       
   148 	 *
       
   149 	 * @param aEmailAddress = emailaddress of the contact
       
   150 	 * @param aCallToDefaultNumber = ETrue, call is made to default phonenumber. EFalse = User is queried of the number.
       
   151 	 * is called if there's a error operationError is called. If caller isn't interested of result, this can be left as NULL
       
   152 	 */	
       
   153 	void FindAndCreateMsgToContactByEmailL( const TDesC& aEmailAddress,
       
   154 											CFSMailBox* aMailBox );
       
   155 
       
   156 	
       
   157 	/**
       
   158 	 * Implements "Show Contact details" funcionality. 
       
   159 	 * It will search for the Contact and then launch AIW call service.
       
   160 	 *
       
   161 	 * @param aAddress = email address of the contact
       
   162 	 * @param TContactUpdateType = ETrue, call is made to default phonenumber. EFalse = User is queried of the number.
       
   163 	 * @param aObserver, when AIW service is completed observer operationComplete( EShowContactDetailsL, NULL ) 
       
   164 	 * is called if there's a error operationError is called. If caller isn't interested of result, this can be left as NULL
       
   165 	 */
       
   166 	void ShowContactDetailsL( const TDesC& aAddress, TContactUpdateType aType,
       
   167 	                          MFSEmailUiContactHandlerObserver* aObserver = NULL );
       
   168 	
       
   169 	/**
       
   170 	 * Implements "Call" funcionality synchronously
       
   171 	 * It launches either VoIP or Normal phone according to system setting
       
   172 	 *
       
   173 	 * @param aContactLink = Link for contact to be called for. If NULL aContactNumber is used
       
   174 	 * @param aContactNumber = Phonenumber of the contact, this is ignored if aContactLink
       
   175 	 * @param aVoipOverride = Force VoIP call 
       
   176 	 */
       
   177 	void MakeAiwCallL( MVPbkContactLink* aContactLink, 
       
   178 					   const TDesC& aContactNumber, 
       
   179 					   TBool aVoipOverride = EFalse );
       
   180 
       
   181 	/**
       
   182 	 * Search for contacts by PCS engine. This is asynchronous call, and results are in
       
   183 	 * ArrayUpdated( resultsArray )
       
   184 	 *
       
   185 	 * @param aText = new search text.
       
   186 	 * @param aClsListObserver = observer to collect results
       
   187 	 * @param aMailBox = current mailbox, needed to know which MRU list to use
       
   188 	 */
       
   189 	void SearchMatchesL( const TDesC& aText, MFSEmailUiContactHandlerObserver* aObserver,
       
   190 						 CFSMailBox* aMailBox, TInt aMode = -1 );
       
   191 	
       
   192 	/**
       
   193 	 * Reset the status of contact Handlers, cancel all active asynchronous calls. This should be called
       
   194 	 * at least when changing view.
       
   195 	 */
       
   196 	void Reset();
       
   197 	
       
   198 	/**
       
   199 	 * Check whether the language currently is use, is supported by PCS engine. This enables/disables
       
   200 	 * ShowContactDetailsL, FindAndCallToContactByEmailL, SearchMatchesL functions.
       
   201 	 *
       
   202 	 * @return ETrue = is supported  
       
   203 	 */
       
   204 	TBool IsLanguageSupportedL();
       
   205 	
       
   206 	/**
       
   207 	 * Launch remote contact lookup in selector mode, where user can select contact to be used
       
   208 	 * 	 
       
   209 	 * @return ETrue = Contact retrieved
       
   210 	 * @param aMailbox = from which mailbox do we search for.
       
   211 	 * @param aQueryString = search string
       
   212 	 * @param aDisplayName = function returns selected contact's display name
       
   213 	 * @param aEmailAddress = function returns selected contacts's email address
       
   214 	 */
       
   215 	TBool GetNameAndEmailFromRemoteLookupL( CFSMailBox& aMailBox, const TDesC& aQueryString,
       
   216 							  TDes& aDisplayname, TDes& aEmailAddress );
       
   217 
       
   218 	/**
       
   219 	 * Launch remote contact lookup in selector mode, where user can select contact to be used
       
   220 	 * 	 
       
   221 	 * @return HBufC* = Display name of the selected contact, NULL if no contact selected
       
   222 	 * @param aMailbox = from which mailbox do we search for.
       
   223 	 * @param aQuery = search string
       
   224 	 * @param aPhoneNumber = function returns selected contact's phonenumber, RBuf will be allocated 
       
   225 	 */
       
   226 	HBufC* GetNameAndNumberFromRemoteLookupL( CFSMailBox& aMailBox, const TDesC& aQuery, RBuf& aPhoneNumber );
       
   227 	
       
   228 	/**
       
   229 	 * Launch remote contact lookup for selected mailbox
       
   230 	 * 	 
       
   231 	 * @param aMailbox = from which mailbox do we search for.
       
   232 	 */
       
   233 	void LaunchRemoteLookupL( CFSMailBox& aMailBox );
       
   234 	
       
   235 	/**
       
   236 	 * Launch remote contact lookup for selected mailbox with given query
       
   237 	 * 	 
       
   238 	 * @param aMailbox = from which mailbox do we search for.
       
   239 	 * @param aQuery = search string to be used
       
   240 	 */
       
   241 	void LaunchRemoteLookupWithQueryL( CFSMailBox& aMailBox, const TDesC& aQuery );
       
   242 
       
   243 	/**
       
   244 	 * Compare emailAddress to last searched contact's emailaddress and return 
       
   245 	 * the display name if they match
       
   246 	 * 	 
       
   247 	 * @param aEmailAddress = email address to compare
       
   248 	 * @return HBufC* = Display name of the contact if addresses match,
       
   249 	 * otherwise NULL
       
   250 	 */
       
   251 	HBufC* GetLastSearchNameL( const TDesC& aEmailAddress );	
       
   252 	
       
   253 	CVPbkContactManager* GetContactManager();
       
   254 	
       
   255 	/**
       
   256 	 * Lauches multiple item fetch dialog through AIW launcher framework.
       
   257 	 * Results are returned to observer
       
   258 	 *
       
   259 	 * @param aObserver = observer to collect results
       
   260 	 */
       
   261 	void GetAddressesFromPhonebookL( MFSEmailUiContactHandlerObserver* aObserver );
       
   262 	
       
   263     // <cmail> video call
       
   264     /**
       
   265      * Enables/disables video call.
       
   266      *
       
   267      * @param aState ETrue for 'enable', EFalse for 'disable'
       
   268      */
       
   269     void SetVideoCall( TBool aState );
       
   270     // </cmail>
       
   271 
       
   272 // from base class MFSEmailUiClsListsObserver
       
   273 
       
   274     void ArrayUpdatedL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems );	
       
   275     void OperationErrorL( TInt aErrorCode );
       
   276     
       
   277 // from base class MVPbkSingleContactOperationObserver
       
   278 
       
   279     void VPbkSingleContactOperationCompleteL(
       
   280     		    MVPbkContactOperationBase& aOperation,
       
   281     		    MVPbkStoreContact* aContact );
       
   282     
       
   283     
       
   284 	void VPbkSingleContactOperationComplete(
       
   285 	    MVPbkContactOperationBase& aOperation,
       
   286 	    MVPbkStoreContact* aContact );
       
   287 	
       
   288 	void VPbkSingleContactOperationFailedL(
       
   289 		    MVPbkContactOperationBase& aOperation, TInt aError );
       
   290 	void VPbkSingleContactOperationFailed(
       
   291 	    MVPbkContactOperationBase& aOperation, TInt aError );
       
   292 
       
   293 // from base class MVPbkContactStoreListObserver
       
   294 
       
   295      /**
       
   296       * From MVPbkContactStoreListObserver  
       
   297       * Called when the opening process is complete, ie. all stores have been reported
       
   298       * either failed or successfully opened.
       
   299       *
       
   300       * @since S60 v3.2
       
   301       */
       
   302       void OpenComplete();  
       
   303       
       
   304      /**
       
   305       * From MVPbkContactStoreListObserver  
       
   306       * Called when a contact store is ready to use.
       
   307       * @since S60 v3.2
       
   308       */
       
   309       void StoreReady(MVPbkContactStore& aContactStore);
       
   310 
       
   311      /**
       
   312       * From MVPbkContactStoreListObserver  
       
   313       * Called when a contact store becomes unavailable.
       
   314       * Client may inspect the reason of the unavailability and decide whether or not
       
   315       * it will keep the store opened (ie. listen to the store events).
       
   316       *
       
   317       * @since S60 v3.2
       
   318       *
       
   319       * @param aContactStore The store that became unavailable.
       
   320       * @param aReason The reason why the store is unavailable.
       
   321       *                This is one of the system wide error codes.
       
   322       */
       
   323       void StoreUnavailable(MVPbkContactStore& aContactStore, TInt aReason);
       
   324 
       
   325      /**
       
   326       * From MVPbkContactStoreListObserver  
       
   327       * Called when changes occur in the contact store.
       
   328       * @see TVPbkContactStoreEvent
       
   329       * @param aContactStore The store the event occurred in.
       
   330       * @param aStoreEvent   Event that has occured.
       
   331       */
       
   332       void HandleStoreEventL(
       
   333                 MVPbkContactStore& aContactStore, 
       
   334                 TVPbkContactStoreEvent aStoreEvent);
       
   335 
       
   336 //from base class MAiwNotifyCallback
       
   337 	
       
   338 	TInt HandleNotifyL(
       
   339 	            TInt aCmdId,
       
   340 	            TInt aEventId,
       
   341 	            CAiwGenericParamList& aEventParamList,
       
   342 	            const CAiwGenericParamList& aInParamList);
       
   343 	
       
   344 	void ClearObservers();
       
   345       
       
   346 // from MCCAObserver      
       
   347     void CCASimpleNotifyL( TNotifyType aType, TInt aReason );
       
   348       
       
   349 private:
       
   350     
       
   351     CFSEmailUiContactHandler( RFs& aSession );
       
   352     
       
   353     void ConstructL( RFs& aSession );
       
   354     
       
   355 // <cmail> call observer's MFSEmailUiContactHandlerObserver::OperationErrorL( TContactHandlerCmd aCmd, TInt aError ) 
       
   356     void ObserverOperationErrorL( TContactHandlerCmd aCmd, TInt aErrorCode );
       
   357     
       
   358 
       
   359 private:
       
   360     
       
   361 	TInt SelectBetweenCsAndVoip() const;
       
   362     void HandleCallL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems );
       
   363     
       
   364 	void CreateMessageL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems );
       
   365 	void SendMessageL( CAiwGenericParamList& aEventParamList, TInt aServiceType );
       
   366  	void GetSmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink );
       
   367 	void GetMmsAddressFromPhonebookAndSendL( MVPbkContactLink* aContactLink, TBool aIsVoiceMessage = EFalse );
       
   368  
       
   369     TBool IsRemoteLookupSupported();
       
   370     
       
   371     void GetContactFieldsL( RArray<TInt>& aFieldIds, RPointerArray<HBufC>& aNumbers, 
       
   372     					   MVPbkStoreContact* aContact );
       
   373     
       
   374     TPtrC GetContactTitle( MVPbkStoreContact* aContact );
       
   375     
       
   376     void ShowDetailsL( const RPointerArray<CFSEmailUiClsItem>& aMatchingItems );
       
   377     
       
   378     void FindContactLinkL( const TDesC& aDes );
       
   379     
       
   380     void FormatFieldIds();
       
   381     void ResetFieldIds();
       
   382 
       
   383     /*
       
   384      * Launches remote lookup UI
       
   385      * @param aQueryString Default query string in user input field
       
   386      * @param aResult Structure containing exit reason and selected item
       
   387      * @param aLookupMode The mode in which the lookup is performed.
       
   388      */
       
   389     void DoRemoteLookupL( CFSMailBox& aMailBox, const TDesC& aQueryString, 
       
   390         CPbkxRemoteContactLookupServiceUiContext::TResult& aResult, 
       
   391         CPbkxRemoteContactLookupServiceUiContext::TMode aLookupMode =
       
   392             CPbkxRemoteContactLookupServiceUiContext::EModeContactSelector );
       
   393 
       
   394     // Gets the name and email address from given contact item
       
   395     void GetNameAndEmail( TDes& aName, TDes& aEmail, CContactItem& aItem ) const;
       
   396     
       
   397     // Gets the phone number from given contact item
       
   398     HBufC* GetPhoneNumberAndNameL( RBuf& aPhoneNumber, CContactItem& aItem ) const;
       
   399 
       
   400     // Displays call query
       
   401     TBool CallQueryL( const TDesC& aDisplayName );
       
   402 
       
   403     // Creates copy of given CLS items and appends them to given array.
       
   404     void CopyItemsL( const RPointerArray<CFSEmailUiClsItem>& aItems,
       
   405         RPointerArray<CFSEmailUiClsItem>& aArray );
       
   406 
       
   407     // Sets the address used for previous contact search
       
   408     void SetPreviousEmailAddressL( const TDesC& aAddress );
       
   409     
       
   410     void RemoteContactQueryL();
       
   411     
       
   412     TContactHandlerCmd CurrentCommand();
       
   413 
       
   414 private: // data
       
   415     
       
   416     CFSEmailUiClsListsHandler* iClsListHandler;
       
   417     TContactHandlerState iState;
       
   418     CFSEmailUiClsItem* iSearchMatch;
       
   419 
       
   420     MFSEmailUiContactHandlerObserver* iHandlerObserver;
       
   421     HBufC* iPreviousEmailAddress;
       
   422     CFSEmailUiClsItem* iLastClsItem;
       
   423     TBool iOpenComplete;
       
   424     TBool iStoreReady;
       
   425     
       
   426     CFSMailBox* iMailBox;
       
   427     TBool iUseSenderText;
       
   428     
       
   429     
       
   430     CVPbkContactManager* iContactManager;
       
   431     
       
   432     MVPbkContactOperationBase* iLinkOperation;
       
   433     MVPbkContactOperationBase* iLinkOperationFetch;
       
   434     const MVPbkContactLink* iCurrentLink;
       
   435     RPointerArray<CFSEmailUiClsItem> iContactObjects;
       
   436     
       
   437     MVPbkContactLinkArray* iLinksSet;
       
   438             
       
   439     CAiwServiceHandler* iServiceHandler;
       
   440     
       
   441     RArray<TInt> iLastnameFields;
       
   442     RArray<TInt> iFirstnameFields;
       
   443     RArray<TInt> iEmailFields;
       
   444     RArray<TInt> iPhoneNumberFields;
       
   445     
       
   446     MVPbkStoreContact* iContactForMsgCreation;
       
   447     TContactHandlerState iMsgCreationHelperState;
       
   448     
       
   449     /// Own: used to query preferred telephony information
       
   450     MPbkGlobalSetting* iPersistentSetting;
       
   451     RFs& iFs;
       
   452     
       
   453     /// Flag for indicating that caching error was received  
       
   454     TBool iCachingInProgressError;
       
   455     
       
   456     // Flag for making video call
       
   457     TBool iVideoCall;
       
   458 
       
   459     // connection to CCMA launcher    
       
   460     MCCAConnection* iConnection;
       
   461 
       
   462     CEikonEnv* iEnv;
       
   463 };
       
   464 
       
   465 #endif /*FREESTYLEEMAILUICONTACTHANDLER_H_*/