phoneuis/easydialing/inc/easydialingcontactdatamanager.h
branchCompilerCompatibility
changeset 13 2411cd0e2ad6
parent 9 8871b09be73b
child 14 24062c24fe38
equal deleted inserted replaced
11:abbe9afab2af 13:2411cd0e2ad6
       
     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 contact data manager.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef __EASYDIALINGCONTACTDATAMANAGER_H__
       
    20 #define __EASYDIALINGCONTACTDATAMANAGER_H__
       
    21 
       
    22 #include <MPbk2ImageOperationObservers.h>
       
    23 #include <MVPbkSingleContactOperationObserver.h>
       
    24 #include <MVPbkContactStoreObserver.h>
       
    25 #include <MVPbkOperationObserver.h>
       
    26 #include <MVPbkContactViewBase.h>
       
    27 #include <CPbkContactEngine.h>  // for TPbkNameOrder
       
    28 #include <TPbk2ImageManagerParams.h>
       
    29 #include "easydialingcontactdata.h"
       
    30 
       
    31 // FORWARD DECLARATIONS
       
    32 class CVPbkContactManager;
       
    33 class MContactDataManagerObserver;
       
    34 class MVPbkFieldType;
       
    35 class CPbk2ImageManager;
       
    36 class CVPbkTopContactManager;
       
    37 class CRepository;
       
    38 
       
    39 /**
       
    40  *  CEasyDialingContactDataManager
       
    41  *  Handles the loading and storing of thumbnail bitmaps
       
    42  */
       
    43 class CEasyDialingContactDataManager : 
       
    44         public CBase,
       
    45         public MPbk2ImageGetObserver,
       
    46         public MVPbkSingleContactOperationObserver,
       
    47         public MVPbkContactStoreObserver,
       
    48         public MVPbkOperationErrorObserver,
       
    49         public MVPbkOperationResultObserver<MVPbkContactViewBase*>
       
    50         
       
    51     {
       
    52 public:
       
    53     
       
    54     
       
    55     /**
       
    56     * Constructor.
       
    57     */
       
    58     CEasyDialingContactDataManager(CVPbkContactManager* aContactManager);
       
    59     
       
    60     
       
    61     /**
       
    62      * Destructor.
       
    63      */
       
    64     ~CEasyDialingContactDataManager();
       
    65     
       
    66     
       
    67     /**
       
    68      * Second phase constructor of the class.
       
    69      */
       
    70     void ConstructL();
       
    71     
       
    72     /**
       
    73     * Sets the observer. Observer is notified when thumbnail loading is complete
       
    74     * @param aObserver
       
    75     */
       
    76     void SetObserver(MContactDataManagerObserver* aObserver);
       
    77     
       
    78     /**
       
    79     * Sets the size of the thumbnails. If the loaded thumbnail is larger than
       
    80     * the set size, thumnail is scaled to the size. If the set size is different
       
    81     * from the old one, deletes all loaded thumbnails, which causes them to be
       
    82     * reloaded when they are needed the next time.
       
    83     * @param aSize The size of the thumbnails
       
    84     */
       
    85     void SetThumbnailSize(const TSize& aSize);
       
    86     
       
    87     /**
       
    88     * Gets an id string for the thumbnail, if thumbnail exists for the contact.
       
    89     * Used when the listbox items are created.
       
    90     * @param aContact Contact link
       
    91     * @param aMatchThumbnail If true, tries to match the link to the existing thumbnails
       
    92     * @param aFav Is this contact a favourite
       
    93     * @return id string. caller needs to delete this.
       
    94     */
       
    95     HBufC* GetThumbnailIdL( MVPbkContactLink* aContact, TBool aMatchThumbnail, TBool aFav );
       
    96     
       
    97     /**
       
    98     * Gets the thumbnail for a contact item. If thumbnail is not loaded, starts
       
    99     * loading it.
       
   100     * @param aContact Contact link
       
   101     * @param aThumbnail Outparam. Contact thumbnail. NULL if contact doesn't have thumbnail
       
   102     * @param aFav Outparam. Favourite status
       
   103     * @return true if contact data has been loaded
       
   104     */
       
   105     TBool GetThumbnailAndFav(const TDesC& aId, CFbsBitmap*& aThumbnail, TBool& aFav);
       
   106     
       
   107     /**
       
   108     * Deletes all loaded thumbnails and cancel asynchronous operations.
       
   109     */
       
   110     void Reset();
       
   111     
       
   112     /**
       
   113     * Returs ETrue if voice call is available for current contact.
       
   114     */
       
   115     TBool VoiceCallAvailable( TInt aIndex );
       
   116     
       
   117     
       
   118     /**
       
   119     * Returs ETrue if video call is available for current contact.
       
   120     */
       
   121     TBool VideoCallAvailable( TInt aIndex );
       
   122     
       
   123     
       
   124     /**
       
   125     * Returs ETrue if uni-editor is available for current contact.
       
   126     */
       
   127     TBool UniEditorAvailable( TInt aIndex );
       
   128     
       
   129     
       
   130     /**
       
   131     * Returns HBufC8 descriptor containing MVPbkContactLink
       
   132     * link packaged.
       
   133     */
       
   134     HBufC8* ContactLinkLC( TInt aIndex );
       
   135     
       
   136     
       
   137     /**
       
   138      * Sets the iContactThumbnailSetting member variable to either true or false 
       
   139      * which is read and if it is false then thumbnails are not shown 
       
   140      * @param aContactThumbnailSetting which is cenrep value for ContactThumbnailSetting
       
   141      */
       
   142     void SetContactThumbnailSetting( TInt aContactThumbnailSetting );
       
   143     
       
   144     /**
       
   145      * Gets the iContactThumbnailSetting member variable to either true or false 
       
   146      * which is read and if it is false then thumbnails are not shown 
       
   147      * returns iContactThumbnailSetting which is cenrep value for ContactThumbnailSetting
       
   148      */
       
   149     TBool GetContactThumbnailSetting( );
       
   150     
       
   151 
       
   152     /**
       
   153     * Flushes the asynchronous contact data of all contacts.
       
   154     */    
       
   155     void Reload();
       
   156     
       
   157     /**
       
   158     * Checks if contact link is a favourite. This is meant to be used for contacts that
       
   159     * don't yet have contact data item. Since this needs to go through all the favourites,
       
   160     * unnecessary calls should be avoided.
       
   161     */    
       
   162     TBool IsFavL( MVPbkContactLink* aLink );
       
   163     
       
   164     /**
       
   165     * @return the number of favourites in contact db
       
   166     */
       
   167     TInt NumberOfFavsL();
       
   168     
       
   169     /**
       
   170     * Creates contact link to a favourite contact.
       
   171     * @param aIndex Index of the favourite in favourites view
       
   172     * @return the newly created link (added to cleanupstack)
       
   173     */
       
   174     MVPbkContactLink* FavLinkLC( TInt aIndex );
       
   175 
       
   176     /**
       
   177     * Creates contact string for favourite contact. This string can be used directly
       
   178     * in the contact listbox. F.ex. "Firstname Surname\tCompanyname".
       
   179     * @param aIndex Index of the favourite in favourites view
       
   180     * @param aNameOrder Name ordering to be used
       
   181     * @return the newly created string (added to cleanupstack)
       
   182     */
       
   183     HBufC* FavContactStringLC( TInt aIndex, CPbkContactEngine::TPbkNameOrder aNameOrder );
       
   184 
       
   185 public:
       
   186     
       
   187     
       
   188     /**
       
   189      * From MPbk2ImageGetObserver.
       
   190      */
       
   191     void Pbk2ImageGetComplete(MPbk2ImageOperation& aOperation, CFbsBitmap* aBitmap);
       
   192     
       
   193     
       
   194     /**
       
   195      * From MPbk2ImageGetObserver.
       
   196      */
       
   197     void Pbk2ImageGetFailed(MPbk2ImageOperation& aOperation, TInt aError);
       
   198 
       
   199 private: 
       
   200 
       
   201     
       
   202     /**
       
   203      * From MVPbkSingleContactOperationObserver.
       
   204      */
       
   205     void VPbkSingleContactOperationComplete(
       
   206             MVPbkContactOperationBase& aOperation,
       
   207             MVPbkStoreContact* aContact );
       
   208 
       
   209     
       
   210     /**
       
   211      * From MVPbkSingleContactOperationObserver.
       
   212      */
       
   213     void VPbkSingleContactOperationFailed(
       
   214             MVPbkContactOperationBase& aOperation, 
       
   215             TInt aError );
       
   216 
       
   217 private:
       
   218     
       
   219     
       
   220     /**
       
   221      * From MVPbkContactStoreObserver.
       
   222      */
       
   223     void StoreReady( MVPbkContactStore& aContactStore );
       
   224 
       
   225 
       
   226     /**
       
   227      * From MVPbkContactStoreObserver.
       
   228      */
       
   229     void StoreUnavailable( MVPbkContactStore& aContactStore, TInt aReason );
       
   230     
       
   231     
       
   232     /**
       
   233      * From MVPbkContactStoreObserver.
       
   234      */
       
   235     void HandleStoreEventL( MVPbkContactStore& aContactStore, 
       
   236             TVPbkContactStoreEvent aStoreEvent );
       
   237 
       
   238 private:
       
   239     /**
       
   240      * From MVPbkOperationErrorObserver.
       
   241      */
       
   242     void VPbkOperationFailed(
       
   243             MVPbkContactOperationBase* aOperation,
       
   244             TInt aError );
       
   245 
       
   246 private:
       
   247     /**
       
   248      * From MVPbkOperationResultObserver.
       
   249      */
       
   250     void VPbkOperationResultCompleted(
       
   251             MVPbkContactOperationBase* aOperation,
       
   252             MVPbkContactViewBase* aOperationResult );
       
   253 
       
   254 private:
       
   255        
       
   256     void InitReady();
       
   257     
       
   258     TInt FindContactIndex( MVPbkContactLink* aContact );
       
   259     
       
   260     void LoadNextContactDataL();
       
   261     
       
   262     void DoHandleImageGetCompleteL(CFbsBitmap* aBitmap, TInt aIndex);
       
   263     
       
   264     void HandleError(TInt aError);
       
   265     
       
   266     void DoHandleContactOperationCompleteL( MVPbkStoreContact* aContact, TInt aIndex);
       
   267     
       
   268     void GetAvailableServicesL( MVPbkStoreContact* aContact, TInt aIndex );
       
   269     
       
   270     void InformObserver();
       
   271 
       
   272 private:
       
   273     /** Array that contains all loaded contact data. Owned. */
       
   274     RPointerArray<CEasyDialingContactData> iContactDataArray;
       
   275 
       
   276     /** Array that contains indexes of thumbnails that are waiting to be loaded. Owned. */
       
   277     RArray<TInt> iWaitingContacts;
       
   278 
       
   279     /** Phonebook image manager. Owned. */
       
   280     CPbk2ImageManager* iImageManager;
       
   281     
       
   282     /** Parameters for image manager. Contains info about the size of thumbnails. */
       
   283     TPbk2ImageManagerParams iImageManagerParams;
       
   284     
       
   285     /** Field type. Not owned. */
       
   286     const MVPbkFieldType* iThumbnailFieldType;
       
   287     
       
   288     /** Image loading operation. Owned. */
       
   289     MPbk2ImageOperation* iImageOperation;
       
   290     
       
   291     /** Contact item for which a thumbnail is being loaded. Owned. */
       
   292     MVPbkStoreContact* iStoreContact;
       
   293     
       
   294     /** Virtual phonebook contact manager. Not owned. */
       
   295     CVPbkContactManager* iContactManager;
       
   296 
       
   297     /** Contact data manager observer. Not owned. */
       
   298     MContactDataManagerObserver* iObserver;
       
   299 
       
   300     /** Top (i.e. favourite) contacts manager. Owned. */
       
   301     CVPbkTopContactManager* iVPbkTopContactManager;
       
   302     
       
   303     /** Virtual phonebook operation handle. Owned. */
       
   304     MVPbkContactOperationBase* iContactOperation;
       
   305 
       
   306     /** Default contact store. Not owned. */
       
   307     MVPbkContactStore* iContactStore;
       
   308     
       
   309     /** Variable which tells either to show or hide contact thumbnails. */
       
   310     TBool iContactThumbnailSetting;
       
   311     
       
   312     /** ETrue if asynchronous opening of the contac store is ready. */
       
   313     TBool iStoreReady;
       
   314     
       
   315     /** View to vpbk containing all favourite contacts. Owned. */
       
   316     MVPbkContactViewBase* iFavsView;
       
   317         
       
   318     /** Virtual phonebook operation handle for getting favourites. Owned. */
       
   319     MVPbkContactOperationBase* iFavsOperation;
       
   320     };
       
   321 
       
   322 #endif //__EASYDIALINGTHUMBNAILMANAGER_H__