phoneuis/easydialing/inc/easydialingplugin.h
branchRCL_3
changeset 9 8871b09be73b
child 14 24062c24fe38
equal deleted inserted replaced
4:c84cf270c54f 9:8871b09be73b
       
     1 /*
       
     2 * Copyright (c) 2010 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: Easy dialing plugin implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __CEASYDIALINGPLUGIN_H__
       
    20 #define __CEASYDIALINGPLUGIN_H__
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include "dialingextensioninterface.h"
       
    25 #include <MPsResultsObserver.h>
       
    26 #include <mccaconnection.h>
       
    27 #include <mccaconnectionext.h>
       
    28 #include "measydialingcenreplistenerobserver.h"
       
    29 #include "mcontactdatamanagerobserver.h"
       
    30 #include "medcontactorobserver.h"
       
    31 
       
    32 // Phonebook engine API
       
    33 #include <CPbkContactEngine.h>
       
    34 #include <MVPbkContactStoreListObserver.h>
       
    35 
       
    36 // ListBox Observer API
       
    37 #include <eiklbo.h>
       
    38 
       
    39 // MAknInputBlockCancelHandler
       
    40 #include <akninputblock.h> 
       
    41 
       
    42 
       
    43 // CONSTANTS
       
    44 
       
    45 /** Maximum constact search string length. */
       
    46 const TInt KEDMaxSearchStringLength = 200;
       
    47 
       
    48 /** Maximum string length for listbox model string. */
       
    49 const TInt KEDMaxContactStringLength = 600;
       
    50 
       
    51 /** Maximum phone number length. */
       
    52 const TInt KEDMaxPhoneNumberLength = 64;
       
    53 
       
    54 // MACROS
       
    55 
       
    56 // DATA TYPES
       
    57 
       
    58 // FUNCTION PROTOTYPES
       
    59 
       
    60 // FORWARD DECLARATIONS
       
    61 
       
    62 class CPSRequestHandler;
       
    63 class CPsQuery;
       
    64 class CVPbkContactStoreUriArray;
       
    65 class CVPbkContactManager;
       
    66 class CEasyDialingListBox;
       
    67 class MVPbkContactLink;
       
    68 class CEasyDialingCenrepListener;
       
    69 class CEasyDialingContactDataManager;
       
    70 class CEDContactorService;
       
    71 class CEikMenuPane;
       
    72 class CAsyncCallBack;
       
    73 
       
    74 
       
    75 // CLASS DECLARATION
       
    76 
       
    77 /**
       
    78 * Easy dialing plugin.
       
    79 */
       
    80 class CEasyDialingPlugin : public CDialingExtensionInterface,
       
    81                            public MVPbkContactStoreListObserver,
       
    82                            public MPsResultsObserver,
       
    83                            public MCCAObserver,
       
    84                            public MEasyDialingCenrepListenerObserver,
       
    85                            public MContactDataManagerObserver,
       
    86                            public MEDContactorObserver,
       
    87                            public MEikListBoxObserver,
       
    88                            public MAknInputBlockCancelHandler
       
    89 {
       
    90 public:
       
    91     
       
    92     /**
       
    93     * Static constructor. 
       
    94     * @return: Created object.
       
    95     */
       
    96     static CEasyDialingPlugin* NewL();
       
    97 
       
    98     /**
       
    99     * Destructor. 
       
   100     */
       
   101     virtual ~CEasyDialingPlugin();
       
   102 
       
   103 public: // from CCoeControl 
       
   104 
       
   105     /**
       
   106     * From CCoeControl.
       
   107     */
       
   108     TKeyResponse OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType );
       
   109 
       
   110     /**
       
   111     * From CCoeControl
       
   112     */
       
   113     TInt CountComponentControls() const;
       
   114     
       
   115     /**
       
   116     * From CCoeControl
       
   117     */
       
   118     CCoeControl* ComponentControl( TInt aIndex ) const;
       
   119     
       
   120     /**
       
   121     * From CCoeControl
       
   122     */
       
   123     void MakeVisible( TBool aVisible );
       
   124 
       
   125 protected:
       
   126     
       
   127     /**
       
   128     * See CCoeControl
       
   129     */
       
   130     void SizeChanged();
       
   131     
       
   132     /**
       
   133     * See CCoeControl
       
   134     */
       
   135     void FocusChanged( TDrawNow aDrawNow );
       
   136     
       
   137 public: // from CDialingExtensionInterface
       
   138     
       
   139     /**
       
   140     * Does further initialization to component.
       
   141     * @param: parent container of this control.
       
   142     */
       
   143     virtual void InitializeL( CCoeControl& aParent );
       
   144     
       
   145     /**
       
   146     * Reset the previour easy dialing search.
       
   147     */
       
   148     void Reset();
       
   149     
       
   150     /**
       
   151     * Adds an observer to dialing extension.
       
   152     * @param: aObserver: observer to be added.
       
   153     */
       
   154     void AddObserverL( MDialingExtensionObserver* aObserver );
       
   155    
       
   156     /**
       
   157     * Removes an observer from dialing extension.
       
   158     * @param: aObserver: observer to be removed.
       
   159     */
       
   160     void RemoveObserver( MDialingExtensionObserver* aObserver );
       
   161     
       
   162     /**
       
   163      * Sets input string (search string) to easy dialing.
       
   164      * @param: aDesC: input string descriptor.
       
   165      */
       
   166     void SetInputL( const TDesC& aDesC );
       
   167     
       
   168     /**
       
   169      * Returns the number of matching contacts in previous search.
       
   170      * @return: number of matches.
       
   171      */
       
   172     TInt MatchingContactCount();
       
   173 
       
   174     /**
       
   175      * Gets the resource id of plugin's control button area resource.
       
   176      * 
       
   177      * @return  Resource id.
       
   178      */
       
   179     TInt CbaResourceId();
       
   180     
       
   181     /**
       
   182      * From CDialingExtensionInterface.
       
   183      * Gets the resource id of plugin's menu bar resource.
       
   184      * 
       
   185      * @return  Resource id.
       
   186      */
       
   187     TInt MenuResourceId();
       
   188     
       
   189     /**
       
   190      * From CDialingExtensionInterface.
       
   191      * Gets the resource id of plugin's menu bar resource.
       
   192      * 
       
   193      * @param   aMenuPane   Menu pane
       
   194      * @param   aMenuResourceId Menu bar resource id.
       
   195      * @return  Resource id.
       
   196      */
       
   197     TBool InitializeMenuPaneL( CEikMenuPane& aMenuPane, TInt aMenuResourceId );
       
   198     
       
   199     /**
       
   200      * From CDialingExtensionInterface.
       
   201      * Gets the resource id of plugin's menu bar resource.
       
   202      * 
       
   203      * @param   aCommand   Command id.
       
   204      * @return  ETrue if command was handled, EFalse otherwise.
       
   205      */
       
   206     TBool HandleCommandL( TInt aCommand );
       
   207 
       
   208     /**
       
   209      * Tells if extension is currently enabled from settings.
       
   210      * @return  ETrue if extension is enabled, EFalse otherwise.
       
   211      */
       
   212     TBool IsEnabled();
       
   213     
       
   214 public:
       
   215     
       
   216     /**
       
   217      * From MVPbkContactStoreListObserver.
       
   218      */
       
   219     void StoreReady(MVPbkContactStore& aContactStore);
       
   220     
       
   221     /**
       
   222      * From MVPbkContactStoreListObserver.
       
   223      */
       
   224     void StoreUnavailable(MVPbkContactStore& aContactStore, TInt aReason);
       
   225     
       
   226     /**
       
   227      * From MVPbkContactStoreListObserver.
       
   228      */
       
   229     void HandleStoreEventL( MVPbkContactStore& aContactStore, 
       
   230                             TVPbkContactStoreEvent aStoreEvent);
       
   231     
       
   232     /**
       
   233      * From MVPbkContactStoreListObserver.
       
   234      */
       
   235     void OpenComplete();
       
   236     
       
   237     /**
       
   238     * From MEasyDialingCenrepListenerObserver.
       
   239     */
       
   240     void EasyDialingSettingsChanged( TInt aValue );
       
   241     
       
   242     /**
       
   243     * From MEasyDialingCenrepListenerObserver.
       
   244     */
       
   245     void EasyDialingContactThumbnailsSettingsChanged( TInt aThumbnailSettingValue );
       
   246         
       
   247     /**
       
   248     * From MContactDataManagerObserver.
       
   249     */
       
   250     void AllContactDataLoaded();
       
   251     
       
   252     /**
       
   253     * From MEDContactorObserver.
       
   254     */
       
   255     void InformContactorEvent( MEDContactorObserver::TEvent aEvent );
       
   256     
       
   257     /**
       
   258     * From MEikListBoxObserver.
       
   259     */
       
   260     void HandleListBoxEventL( CEikListBox* aListBox, TListBoxEvent aEventType );
       
   261 
       
   262     /**
       
   263     * From MAknInputBlockCancelHandler.
       
   264     */
       
   265     void AknInputBlockCancel();
       
   266     
       
   267 
       
   268 private:
       
   269 
       
   270     /**
       
   271     * Constructor.
       
   272     */
       
   273     CEasyDialingPlugin ();
       
   274 
       
   275     /**
       
   276     * Second phase constructor.
       
   277     */
       
   278     void ConstructL ();
       
   279 
       
   280     void InitPredictiveContactSearchL();
       
   281         
       
   282     /**
       
   283     * From MPsResultsObserver.
       
   284     */
       
   285     virtual void HandlePsResultsUpdate( RPointerArray<CPsClientData>& aResults, RPointerArray<CPsPattern>& aSeqs );
       
   286     virtual void HandlePsError( TInt aErrorCode );
       
   287     virtual void CachingStatus( TCachingStatus& aStatus, TInt& aError );
       
   288     
       
   289     /**
       
   290      * FindContactFieldPCSIndex
       
   291      * Searches the index that stores the given contact field.
       
   292      * To see possible contact field numbering, see file "vpbkeng.rsg".
       
   293      * @param: contact field to search for. See file "vpbkeng.rsg"
       
   294      * for contact field numbering.
       
   295      * @return: index of the contact field. KErrNotFound if field was not found.
       
   296      * Non-negative return values are for indexing CPsClientData array.
       
   297      */
       
   298     TInt FindContactFieldPCSIndexL( TInt aIndex );
       
   299         
       
   300     /**
       
   301      * HandlePsResultsUpdateL
       
   302      * A leaving function to be trapped in HandlePsResultsUpdate.
       
   303      */
       
   304     void HandlePsResultsUpdateL( RPointerArray<CPsClientData>& aResults, RPointerArray<CPsPattern>& aSeqs );
       
   305     
       
   306 public:
       
   307     
       
   308     /**
       
   309      * MCCAObserver function handling exit of CCA launcher.
       
   310      */
       
   311     void CCASimpleNotifyL( TNotifyType aType, TInt aReason );
       
   312 
       
   313 private:
       
   314     
       
   315     /*
       
   316      * Informs all observers registered with AddObserverL.
       
   317      * @param: aEvent: event id to be informed.
       
   318      */
       
   319     void InformObservers( MDialingExtensionObserver::TEvent aEvent );
       
   320 
       
   321 
       
   322 private: 
       
   323 
       
   324     /**
       
   325     * This method perform the drawing functionality of the component.
       
   326     * @param: aRect: The rect to be rendered
       
   327     * @return None
       
   328     */
       
   329     void Draw( const TRect& aRect ) const;
       
   330     
       
   331     /**
       
   332     * Initiates predictive contact search.
       
   333     */
       
   334     void LaunchSearchL();
       
   335     
       
   336     /**
       
   337      * Opens ca launcher for currently selected contact.
       
   338      */
       
   339     void LaunchCurrentContactL();
       
   340     
       
   341     /**
       
   342      * Creates listbox model string.
       
   343      */
       
   344     void CreateListBoxContactStringL(
       
   345             const TDesC& aContactString,
       
   346             MVPbkContactLink *aLink,
       
   347             TBool aMatchThumbnails,
       
   348             TBool aFav );
       
   349     
       
   350     /**
       
   351      * Creates string with first name, last name and company name.
       
   352      */
       
   353     HBufC* CreateContactStringLC( CPsClientData* aResult, CPbkContactEngine::TPbkNameOrder aNameOrder );
       
   354     
       
   355     /** Possible actions launched by this plugin. */
       
   356     enum TEasyDialingAction
       
   357         {
       
   358         ENoActionDefined,
       
   359         ECallCurrentContact,
       
   360         EVideoCallCurrentContact,
       
   361         ESendMessageCurrentContact,
       
   362         ELaunchCurrentContact,
       
   363 		ELaunchSearch
       
   364         };
       
   365  
       
   366    /**
       
   367      * Initiates asynchronous callback to launch action and sets
       
   368      * input blocker active. 
       
   369      */
       
   370     void AsyncActionLaunchL( const TEasyDialingAction aAction );
       
   371        
       
   372     /**
       
   373      * Callback for CAsyncCallBack. Launches action set in iActionToBeLaunched
       
   374      * and stops input block when launch is done.
       
   375      */
       
   376     static TInt AsyncCallBackToLaunchAction( TAny* aPtr );
       
   377     
       
   378     /**
       
   379      * Launches action defined in iActionToBeLaunched.
       
   380      */
       
   381     void DoLaunchActionL();
       
   382     
       
   383     /**
       
   384      * Cancels async action launch and input block.
       
   385      */
       
   386     void CancelActionLaunchAndInputBlock();
       
   387     
       
   388     
       
   389 private:
       
   390 
       
   391     /** Textual version of current search string. */
       
   392     TBuf<KEDMaxSearchStringLength> iSearchString;
       
   393 
       
   394     /** Handle to predictive search engine. Owned. */
       
   395     CPSRequestHandler* iPredictiveContactSearchHandler;
       
   396     
       
   397     /** PCS type of presentation of the current search string. Owned. */
       
   398     CPsQuery* iPredictiveSearchQuery;
       
   399     
       
   400     /** If ETrue, completing PCS searches are not displayed but just discarded. */
       
   401     TBool iDiscardCompletingSearches;
       
   402     
       
   403     /** ETrue if contact database has been changed and a new search is needed. */
       
   404     TBool iNewSearchNeeded;
       
   405     
       
   406     /** Array of used data stores. Owned. */
       
   407     RPointerArray<TDesC> iContactDataStores;
       
   408     
       
   409     /** Contact store array. Owned. */
       
   410     CVPbkContactStoreUriArray* iContactStoreUriArray;
       
   411     
       
   412     /** Contact manager handle. Owned. */
       
   413     CVPbkContactManager* iContactManager;
       
   414 	
       
   415     /** Search result field index for first name field. */
       
   416 	TInt iFirstNamePCSIndex;
       
   417     
       
   418     /** Search result field index for last name field. */
       
   419 	TInt iLastNamePCSIndex;
       
   420     
       
   421     /** Search result field index for first name field. */
       
   422 	TInt iCompanyNamePCSIndex;
       
   423 
       
   424 	/** Array containing observers to this class. Owned. */
       
   425 	RPointerArray<MDialingExtensionObserver> iObservers;
       
   426 	
       
   427 	/** Contact listbox. Owned. */
       
   428 	CEasyDialingListBox* iContactListBox;
       
   429 
       
   430 	/** Listbox model from search results. Owned. */
       
   431 	CDesCArrayFlat* iListBoxModel;
       
   432 	
       
   433 	/** Number of found matching contacts from most recent search. */
       
   434 	TInt iNumberOfNames;
       
   435 	
       
   436 	/** Handle to contact launcher. */
       
   437     MCCAConnectionExt* iContactLauncher;
       
   438     
       
   439     /** ETrue if contact launcher (a.k.a. communication launcher) is open. */
       
   440     TBool iContactLauncherActive;
       
   441     
       
   442     /** If true, contact listbox must not reset focus when contact launcher exits. */
       
   443     TBool iRememberFocus;
       
   444     
       
   445 	/** Working buffer for creating contact string to listbox. */
       
   446     TBuf<KEDMaxContactStringLength> iContactStringCreationBuffer;
       
   447 
       
   448     /** Central repository listener. Owned. */
       
   449     CEasyDialingCenrepListener* iCenrepListener;
       
   450     
       
   451     /** Contact data manager. Owned. */
       
   452     CEasyDialingContactDataManager* iContactDataManager;
       
   453     
       
   454     /** Easy dialing contactor service. Owned. */
       
   455     CEDContactorService* iContactorService;
       
   456 
       
   457     /** Easy dialing resource file offset in current application. */
       
   458     TInt iResourceFileOffset;
       
   459     
       
   460     /** Blocks user input when action is being launched. NULL if not active. Owned. */
       
   461     CAknInputBlock* iInputBlocker;
       
   462     
       
   463     /** Used to launch action asynchronously. Owned.*/
       
   464     CAsyncCallBack* iAsyncCallBack;
       
   465     
       
   466     /** Action to be launched next asynchronously. */
       
   467     TEasyDialingAction iActionToBeLaunched;
       
   468        
       
   469 };
       
   470 
       
   471 
       
   472 #endif //__CEASYDIALINGPLUGIN_H__
       
   473 
       
   474 // End of File