wvuing/wvuipresence/src/CCAPEngListManager.h
changeset 0 094583676ce7
equal deleted inserted replaced
-1:000000000000 0:094583676ce7
       
     1 /*
       
     2 * Copyright (c) 2002-2005 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:  Manager for presence-list handling
       
    15  *               (Contact-list updater/ Attribute-list publisher ).
       
    16  *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CCAPENGLISTMANAGER_H
       
    22 #define CCAPENGLISTMANAGER_H
       
    23 #include "MCAListInitObserver.h"
       
    24 //  INCLUDES
       
    25 #include "MCAContactLists.h"
       
    26 #include "TCARequestQueue.h"
       
    27 
       
    28 #include <MPEngContactListTransactionObserver2.h>
       
    29 #include <MPEngAttributeListTransactionObserver2.h>
       
    30 #include <MPEngPresenceObserver2.h>
       
    31 #include <PEngWVServices2.h>
       
    32 
       
    33 #include <badesca.h>
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class CPEngAttributeListTransaction2;
       
    37 class CPEngAttributeListStore2;
       
    38 class CPEngContactListStore2;
       
    39 class MPEngContactList2;
       
    40 class MCAStoredContact;
       
    41 class MCAStoredContacts;
       
    42 class MCASettings;
       
    43 class MPEngAttributeList2;
       
    44 class CCAPresenceErrors;
       
    45 class CPEngPresenceNotifier;
       
    46 class CCAPEngListObserver;
       
    47 class CPEngNWSessionSlotID2;
       
    48 class MCAPresenceUpdater;
       
    49 class MCAContactList;
       
    50 class MCAListObserver;
       
    51 // CLASS DECLARATION
       
    52 
       
    53 /**
       
    54  *  Manager for contact/attribute list handling.
       
    55  *
       
    56  *  @lib CAPresence.dll
       
    57  *  @since 2.1
       
    58  */
       
    59 class CCAPEngListManager :	public CBase,
       
    60             public MPEngContactListTransactionObserver2,
       
    61             public MPEngAttributeListTransactionObserver2,
       
    62             public MPEngPresenceObserver2,
       
    63             public MCAContactLists
       
    64     {
       
    65 
       
    66 
       
    67     private:
       
    68         enum TNetworkOperation
       
    69             {
       
    70             EContactListUpdate,
       
    71             EAttributeListUpdate
       
    72             };
       
    73 
       
    74     public:  // Constructors and destructor
       
    75 
       
    76         /**
       
    77          * Two-phased constructor.
       
    78          */
       
    79         static CCAPEngListManager* NewL( MCASettings& aApplicationSettings,
       
    80                                          RArray<TUint32>& aHandledAttributes,
       
    81                                          MPEngPresenceObserver2& aNotifierObserver,
       
    82                                          CPEngNWSessionSlotID2* aSessionSlotID,
       
    83                                          MCAPresenceUpdater& aUpdater );
       
    84 
       
    85         /**
       
    86          * Destructor.
       
    87          */
       
    88         virtual ~CCAPEngListManager();
       
    89 
       
    90     public: // New functions
       
    91 
       
    92         /**
       
    93          * Sets login state of system. Should be called before doing
       
    94          * other operations, because this setting affects functionality
       
    95          * @since 2.1
       
    96          * @param aIsLoggedIn Is logged in
       
    97          */
       
    98         void SetLoggedIn( TBool aIsLoggedIn, CPEngNWSessionSlotID2* aSessionSlotID );
       
    99 
       
   100         /**
       
   101          * Authorizes presence to all
       
   102          * @since 2.1
       
   103          */
       
   104         void SetAuthorizationToAllL();
       
   105 
       
   106         /**
       
   107          * Authorizes presence to none
       
   108          * @since 2.1
       
   109          */
       
   110         void SetAuthorizationToNoneL();
       
   111 
       
   112         /**
       
   113          * Authorizes presence to given users
       
   114          * @since 2.1
       
   115          * @param aUsers User ids
       
   116          */
       
   117         void SetAuthorizationToFriendsL();
       
   118 
       
   119         /**
       
   120          *  Set friend list show status.
       
   121          *  @since 2.1
       
   122          *  @param aShowFriendList. ETrue if friend list can be shown, EFalse if not.
       
   123          */
       
   124         void ShowFriendList( TBool aShowFriendList );
       
   125 
       
   126         /**
       
   127          * Replace attributes in the notifier
       
   128          * with the given ones. Also restarts the notifier,
       
   129          * if needed.
       
   130          * @param aAttributes The attributes to add
       
   131          */
       
   132         void ReplaceAttributesL( RArray<TUint32>& aAttributes );
       
   133 
       
   134         /**
       
   135          * Subscribe all lists.
       
   136          * @param aSubscribe ETrue subscribe, EFalse unsubscribe
       
   137          */
       
   138         void SubscribeListsL( TBool aSubscribe );
       
   139 
       
   140     public:
       
   141         /**
       
   142          * Cancel pending requests to network
       
   143          */
       
   144         void CancelPendingRequests();
       
   145 
       
   146     public :
       
   147         /**
       
   148           * @see MCAContactLists
       
   149           */
       
   150         void AddObserver( MCAListInitObserver* aObserver ) ;
       
   151 
       
   152         /**
       
   153           * @see MCAContactLists
       
   154           */
       
   155         void RemoveObserver() ;
       
   156 
       
   157         /**
       
   158          * @see MCAContactLists
       
   159          */
       
   160         TBool IsListInitializationCompleted();
       
   161 
       
   162         TBool IsContactFetchingCompleted();
       
   163 
       
   164         void AddMainViewProcessObserver( MCAListInitObserver* aObserver );
       
   165 
       
   166         void RemoveMainViewProcessObserver();
       
   167 
       
   168     protected: // From MCAContactLists
       
   169 
       
   170         /**
       
   171          * @see MCAContactLists
       
   172          */
       
   173         TInt FetchContactsL( TBool aBaseSyncDone = EFalse );
       
   174 
       
   175         /**
       
   176         * @see MCAContactLists
       
   177         */
       
   178         void FetchServerContactsL(	const TDesC& aContactListId,
       
   179                                    CPtrCArray& aWVIds );
       
   180 
       
   181         /**
       
   182         * @see MCAContactLists
       
   183         */
       
   184         void UpdateServerContactsL( const TDesC& aContactListId,
       
   185                                     const MDesCArray& aWVIds,
       
   186                                     const MDesCArray& aNicknames );
       
   187 
       
   188         /**
       
   189          * Deletes one contact from server side contact list
       
   190          * @see MCAContactLists
       
   191          */
       
   192         void DeleteServerContactL( const TDesC& aContactListId,
       
   193                                    const TDesC& aWVId,
       
   194                                    const TBool aUpdateToServer = ETrue );
       
   195 
       
   196         /**
       
   197          * Deletes several contacts from server side contact list
       
   198          * @see MCAContactLists
       
   199          */
       
   200         void DeleteServerContactL( const TDesC& aContactListId,
       
   201                                    const MDesCArray& aWVIds,
       
   202                                    const TBool aUpdateToServer = ETrue );
       
   203 
       
   204         /**
       
   205          * Updates deleted contacts to server. This have to be called after
       
   206          * DeleteServerContactL is called without updating changes to server
       
   207          * (aUpdateToServer). Otherwise the changed data might not be update to
       
   208          * server. Use this method to make multiple updates to network with single
       
   209          * operation.
       
   210          * @see MCAContactLists
       
   211          */
       
   212         void CommitDeleteServerContactL();
       
   213 
       
   214         /**
       
   215          * Adds one contact to server side contact list
       
   216          * @see MCAContactLists
       
   217          */
       
   218         MCAStoredContact* AddServerContactL( const TDesC& aContactListId,
       
   219                                              const TDesC& aWVId,
       
   220                                              const TDesC& aNickname,
       
   221                                              TBool aCanRemove = ETrue,
       
   222                                              const TDesC* aOldWVId = NULL );
       
   223 
       
   224         /**
       
   225          * Adds several contacts to server side contact list
       
   226          * @see MCAContactLists
       
   227          */
       
   228         void AddServerContactL( const TDesC& aContactListId,
       
   229                                 const MDesCArray& aWVIds,
       
   230                                 const MDesCArray& aNicknames );
       
   231 
       
   232         /**
       
   233          * @see MCAContactLists
       
   234          */
       
   235         void UpdateContactNicknameL( const TDesC& aContactListId,
       
   236                                      const TDesC& aWVId,
       
   237                                      const TDesC& aNickname );
       
   238 
       
   239         /**
       
   240         * @see MCAContactLists
       
   241         */
       
   242         TContactListsWrapper FetchServerContactListsL( );
       
   243 
       
   244 
       
   245         /**
       
   246          * @see MCAContactLists
       
   247          */
       
   248         void ReleaseContactListsL( const TDesC& aExcludedContactList );
       
   249 
       
   250         /**
       
   251          * @see MCAContactLists
       
   252          */
       
   253         TInt SetDisplayNameL( const TDesC& aContactListID, const TDesC& aDisplayName );
       
   254 
       
   255         /**
       
   256          * @see MCAContactLists
       
   257          */
       
   258         TInt DeleteContactListL( const TDesC& aContactListID
       
   259 #ifdef IMPS_CONTACT_FETCH_BACKGROUND
       
   260                                  , TBool aFailedList = EFalse
       
   261 #endif // IMPS_CONTACT_FETCH_BACKGROUND
       
   262                                );
       
   263 
       
   264         /**
       
   265          * @see MCAContactLists
       
   266          */
       
   267         TInt CreateContactListL( const TDesC& aDisplayName );
       
   268 
       
   269         /**
       
   270          * @see MCAContactLists
       
   271          */
       
   272         const MCAPresenceErrors& LastOperationResult() const;
       
   273 
       
   274         /**
       
   275          * @see MCAContactLists
       
   276          */
       
   277         TPtrC IdentificationL( const TDesC& aUserId );
       
   278 
       
   279         /**
       
   280          * @see MCAContactLists
       
   281          */
       
   282         TBool IsSyncDone();
       
   283 
       
   284 
       
   285     private: // From MPEngPresenceObserver
       
   286 
       
   287         /**
       
   288          * @see MPEngPresenceObserver
       
   289          */
       
   290         void HandlePresenceChangeL( CPEngPresenceNotifier2& aNotifier,
       
   291                                     CPEngTrackedPresenceIDs2& aChangedPresenceIDs );
       
   292 
       
   293         /**
       
   294          * @see MPEngPresenceObserver
       
   295          */
       
   296         void HandlePresenceError( TInt aError,
       
   297                                   CPEngPresenceNotifier2& aNotifier );
       
   298 
       
   299     private: // From MPEngAttributeListTransactionObserver2
       
   300 
       
   301         /*
       
   302          * @see MPEngAttributeListTransactionObserver2
       
   303          */
       
   304         void HandleAttributeListTransactionError(
       
   305             TInt aError,
       
   306             CPEngAttributeListTransaction2& aTransaction,
       
   307             TInt aTransactionOperation );
       
   308 
       
   309         /*
       
   310          * @see MPEngAttributeListTransactionObserver2
       
   311          */
       
   312         void HandleAttributeListTransactionCompleteL(
       
   313             MPEngTransactionStatus2& aStatus,
       
   314             CPEngAttributeListTransaction2& aTransaction,
       
   315             TInt aTransactionOperation  );
       
   316 
       
   317 
       
   318     private: // From MPEngContactListTransactionObserver2
       
   319 
       
   320         /*
       
   321          * @see MPEngContactListTransactionObserver2
       
   322          */
       
   323         void HandleContactListTransactionError(
       
   324             TInt aError,
       
   325             CPEngContactListTransaction2& aTransaction,
       
   326             TInt aTransactionOperation );
       
   327 
       
   328         /*
       
   329          * @see MPEngContactListTransactionObserver2
       
   330          */
       
   331         void HandleContactListTransactionCompleteL(
       
   332             MPEngTransactionStatus2& aStatus,
       
   333             CPEngContactListTransaction2& aTransaction,
       
   334             TInt aTransactionOperation  );
       
   335 
       
   336     private:
       
   337 
       
   338         /**
       
   339          * C++ default constructor.
       
   340          */
       
   341         CCAPEngListManager( RArray<TUint32>& aHandledAttributes,
       
   342                             MPEngPresenceObserver2& aNotifierObserver,
       
   343                             MCASettings& aApplicationSettings,
       
   344                             MCAPresenceUpdater& aUpdater );
       
   345 
       
   346         /**
       
   347          * By default Symbian 2nd phase constructor is private.
       
   348          */
       
   349         void ConstructL( CPEngNWSessionSlotID2* aSessionSlotID );
       
   350 
       
   351         MPEngAttributeList2* AttributeListLC( CPEngAttributeListStore2* aListStore );
       
   352         TBool IsLoggedIn() const;
       
   353 
       
   354         void UpdateToNetworkL( TNetworkOperation aOperation, const TDesC& aListID = KNullDesC, TBool aWait = ETrue );
       
   355         void AttachAttributeListL(  MDesCArray& aContactLists, MPEngAttributeList2& aAttributeList );
       
   356         void DetachAttributeListL(  MDesCArray& aContactLists );
       
   357 
       
   358         /**
       
   359          * Restarts attribute notifier.
       
   360          * @since 3.0
       
   361          * @param aLists Contact list ids to listent to or NULL
       
   362          *               to listen to all lists
       
   363          */
       
   364         void RestartNotifierL( MDesCArray* aListIds = NULL );
       
   365         void RemoveFromNotifierL( const TDesC& aId );
       
   366         void AddToNotifierL( const TDesC& aId );
       
   367 
       
   368         /**
       
   369          * Subscribes or unsubscribes list
       
   370          * @param aList contact list
       
   371          * @param aListId contact list id
       
   372          * @param aSubscribe ETrue if the list should be subscribed
       
   373          * @param aUpdate, ETrue if we want to update list to server EFalse if not.
       
   374          */
       
   375         void SubscribeListL( MPEngContactList2& aList, const TDesC& aListId, TBool aSubscribe, TBool aUpdate = ETrue );
       
   376 
       
   377         /**
       
   378          *  This is called when logout occurs. Releases all member data.
       
   379          *  @param TBool aReleaseContactListModels Release also contact list models (ETrue)
       
   380          */
       
   381         void ReleaseListManager( TBool aReleaseContactListModels );
       
   382 
       
   383         /**
       
   384          * Add the attributes from iAttributes to
       
   385          * the MPEngAttributeList2
       
   386          */
       
   387         void AddDynamicAttributesToListL( MPEngAttributeList2* aList );
       
   388 
       
   389         /**
       
   390          * Helper methods to add contacts in multiple "rounds" with CIdle
       
   391          * when fetching server contacts
       
   392          */
       
   393         static TInt AppendContacts( TAny *aInstance );
       
   394         TInt DoAppendContacts();
       
   395 
       
   396         /**
       
   397          * Helper method for next step of fetch contacfs.
       
   398          */
       
   399         static TInt FetchContacts( TAny *aInstance );
       
   400 
       
   401         /**
       
   402          * State machine for fetching. Engine of fetching.
       
   403          */
       
   404         TInt FetchStateMachineL();
       
   405 
       
   406         TInt StartFetchIdle();
       
   407 
       
   408         /**
       
   409          * Params for appending contacts asynchronously.
       
   410          */
       
   411         struct TAppendContactsParams
       
   412             {
       
   413             MPEngContactList2* iContactList;
       
   414             CDesCArray* iWVIds;
       
   415             CDesCArray* iNicknames;
       
   416             MCAStoredContacts* iContactStorage;
       
   417             TInt iEntryIndex;
       
   418             MCAContactList* iCaContactList;
       
   419             };
       
   420 
       
   421         /**
       
   422          * Get the service tree from the current session.
       
   423          * @param aSessionSlotID session slot id
       
   424          * @return service tree
       
   425          * @since 3.1
       
   426          */
       
   427         TPEngWVCspServicesTree2 ServiceTreeL( CPEngNWSessionSlotID2& aSessionSlotID );
       
   428 
       
   429         /**
       
   430          * Check if attribute lists are supported in this session.
       
   431          * @param aSessionSlotID session slot id
       
   432          * @return ETrue if attribute lists are supported
       
   433          * @since 3.1
       
   434          */
       
   435         TBool AttribListsSupportedL( CPEngNWSessionSlotID2& aSessionSlotID );
       
   436 
       
   437         /**
       
   438          * Update attribute lists to network according to current settings
       
   439          * @since 3.1
       
   440          */
       
   441         void UpdatePresenceAuthorizeL();
       
   442 
       
   443     private:    // Data
       
   444         // Errorcode storage for async calls
       
   445         TInt iOperationError;
       
   446         // "Is application logged in"-flag
       
   447         TBool iIsLoggedIn;
       
   448         // Array of attributes handled
       
   449         RArray<TUint32>& iAttributes;
       
   450         // Handle to attribute notifier
       
   451         MPEngPresenceObserver2& iNotifierObserver;
       
   452         // Doesn't own. Handle to settings API
       
   453         MCASettings* iApplicationSettings;
       
   454         // Owns. PEC attribute list store
       
   455         CPEngAttributeListStore2* iPEngAttributeListStore;
       
   456         // Owns. PEC contact list store
       
   457         CPEngContactListStore2* iPEngContactListStore;
       
   458         // Owns. PEC contact list updater
       
   459         CPEngContactListTransaction2* iPEngContactListUpdater;
       
   460         // Owns. PEC Attribute-list publisher
       
   461         CPEngAttributeListTransaction2* iPEngAttributeListPublisher;
       
   462         // Owns. Presence notifier from Presence Engine
       
   463         CPEngPresenceNotifier2* iPEngAttributeNotifier;
       
   464         // Request queue
       
   465         TCARequestQueue iRequestQueue;
       
   466         // Error data container
       
   467         CCAPresenceErrors* iErrors;
       
   468 
       
   469         // observer for contact list events
       
   470         CCAPEngListObserver* iListObserver;
       
   471 
       
   472         TAppendContactsParams iAppendContactsParams;
       
   473 
       
   474         // alias support activated or not
       
   475         TBool iAliasSupport;
       
   476 
       
   477         // Updater for presence
       
   478         MCAPresenceUpdater& iPresenceUpdater;
       
   479 
       
   480         // Contacts for appending.
       
   481         RArray< TAppendContactsParams > iAppendContactsArray;
       
   482 
       
   483         // owned: Idle for appending contacts
       
   484         CIdle* iIdle;
       
   485 
       
   486         // owned: Idle for launching fetchcontact
       
   487         CIdle* iFetchIdle;
       
   488 
       
   489         // owns. Array of list ids to subscribe
       
   490         CDesCArray* iListIds;
       
   491 
       
   492         // Steps for contact list synchronization
       
   493         TContactFetchOperation iContactFetchStep;
       
   494 
       
   495         // Start again if set
       
   496         TBool iStartFetchAgain;
       
   497 
       
   498         // Attributelist support flag
       
   499         TBool iAttribListSupported;
       
   500 
       
   501         // DeleteServerContact array of changed lists
       
   502         RPointerArray<HBufC> iUpdateListQueue;
       
   503         // Is base sync done or not.
       
   504         TBool iBaseSyncDone;
       
   505 
       
   506         // owned : register by CCASingleListView
       
   507         MCAListInitObserver* iObserver;
       
   508 
       
   509         // register by CCAMainViewArrayPC
       
   510         MCAListInitObserver* iMainViewProcessObserver;
       
   511         // indicate that contact fetch is complete
       
   512         TBool iContactFetchingComplete;
       
   513 
       
   514         // owned : List init is done or not
       
   515         TBool iListInitInProcees;
       
   516 
       
   517     };
       
   518 
       
   519 #endif      // CCAPENGLISTMANAGER_H
       
   520 
       
   521 // End of File