ipsservices/ipssosplugin/inc/ipsplgeventhandler.h
changeset 0 8466d47a6819
child 8 e1b6206813b4
child 18 578830873419
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007 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: This file defines classes MIpsPlgPropertyObserver, CMBoxEventObserver, CIPSAccountInfo, CIpsPlgEventHandler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef IPSPLGEVENTHANDLER_H
       
    20 #define IPSPLGEVENTHANDLER_H
       
    21 
       
    22 
       
    23 #include "ipsplgsettingsobserver.h"
       
    24 #include "ipsplgpropertywatcher.h"
       
    25 #include <e32property.h>
       
    26 
       
    27 class CIpsPlgSosBasePlugin;
       
    28 class CMsvSession;
       
    29 class CRepository;
       
    30 class CIpsPlgSettingsObserver;
       
    31 class CIpsPlgSyncStateObserver;
       
    32 class CIpsSetDataApi;
       
    33 /**
       
    34 * MIpsPlgPropertyObserver
       
    35 *
       
    36 */
       
    37 class MIpsPlgPropertyObserver
       
    38     {
       
    39 public:
       
    40     virtual void HandlePropertyEventL(
       
    41             TInt aEvent,
       
    42             TInt aMailbox,
       
    43             TInt aPluginId ,
       
    44             TInt aError ) = 0;
       
    45     };
       
    46 
       
    47 /**
       
    48 * Helper class to store observer references
       
    49 */
       
    50 class CMBoxEventObserver : public CBase
       
    51     {
       
    52 public:
       
    53     CMBoxEventObserver(
       
    54         MFSMailEventObserver& aObserver,
       
    55         const TFSMailMsgId& aMBoxId ) :
       
    56             iObserver( aObserver ),
       
    57             iMBoxId( aMBoxId ) { }
       
    58 
       
    59     MFSMailEventObserver&   iObserver;
       
    60     const TFSMailMsgId      iMBoxId;
       
    61     };
       
    62 
       
    63 /**
       
    64 * Helper class to keep track of accounts
       
    65 */
       
    66 class CIPSAccountInfo : public CBase
       
    67     {
       
    68 public:
       
    69 
       
    70     static CIPSAccountInfo* NewL(
       
    71         const TDesC& aName,
       
    72         const TFSMailMsgId& aMBoxId );
       
    73 
       
    74     virtual ~CIPSAccountInfo();
       
    75 
       
    76     HBufC*                  iName;
       
    77     const TFSMailMsgId      iMBoxId;
       
    78 
       
    79 private:
       
    80 
       
    81     CIPSAccountInfo( const TFSMailMsgId& aMBoxId );
       
    82 
       
    83     void ConstructL( const TDesC& aName );
       
    84     };
       
    85 
       
    86 /**
       
    87  *
       
    88  *  @lib ipssosplugin.lib
       
    89  *  @since
       
    90  */
       
    91 class CIpsPlgEventHandler : public CBase,
       
    92                             public MMsvSessionObserver,
       
    93                             public MIpsPlgSettingsObserverCallback,
       
    94                             public MIpsPlgPropertyObserver,
       
    95                             public MFSMailExceptionEventCallback
       
    96     {
       
    97 
       
    98 public://from MFSMailExceptionEventCallback
       
    99 
       
   100     void ExceptionEventCallbackL( TFSMailMsgId aMailboxId, TInt aEventType, TBool aResponse );
       
   101 
       
   102 public: //from MIpsPlgPropertyObserver
       
   103     void HandlePropertyEventL(
       
   104             TInt aEvent, TInt aMailbox, TInt aPluginId, TInt aError );
       
   105 
       
   106 public: // from MMsvSessionObserver
       
   107 
       
   108     virtual void HandleSessionEventL(
       
   109         TMsvSessionEvent aEvent,
       
   110         TAny* aArg1, TAny* aArg2, TAny* aArg3);
       
   111 
       
   112 public: //from MIpsPlgSettingsObserverCallback
       
   113 
       
   114     virtual void SettingsChangedL( TFSMailMsgId aAccount );
       
   115 
       
   116 public:
       
   117 
       
   118     /**
       
   119      * Two-phased constructor.
       
   120      */
       
   121      static CIpsPlgEventHandler* NewL(
       
   122         CIpsPlgSosBasePlugin& aBasePlugin );
       
   123 
       
   124     /**
       
   125      * Destructor.
       
   126      */
       
   127     virtual ~CIpsPlgEventHandler();
       
   128 
       
   129     /**
       
   130      * Sets msv session pointer, and does initialization that need
       
   131      * valid session
       
   132      * @param aSession valid msv session pointer
       
   133      */
       
   134     void CompleteConstructL( CMsvSession* aSession );
       
   135 
       
   136     /**
       
   137      * Add observer for common plugin events like changes in mailboxes
       
   138      * @param aObserver interface to observer object
       
   139      */
       
   140     void AddPluginObserverL( MFSMailEventObserver* aObserver );
       
   141 
       
   142     /**
       
   143      * Removes plugin observer
       
   144      * @param aObserver indicates object to be removed
       
   145      */
       
   146 	void RemovePluginObserver( MFSMailEventObserver* aObserver );
       
   147 
       
   148     /**
       
   149      * Sets observer to mailbox events like changes in messages and folders
       
   150      * under mailbox
       
   151      * @param aMailboxId FS mailbox id, corresponds
       
   152      *                   imap/pop msv service entry id
       
   153      * @param aObserver interface to observer object
       
   154      * @param aKey key to mailbox settings
       
   155      */
       
   156     void SubscribeMailboxEventsL(
       
   157         const TFSMailMsgId& aMailboxId,
       
   158         MFSMailEventObserver& aObserver,
       
   159         TUint32 aKey );
       
   160 
       
   161     /**
       
   162      * Removes mailbox event observer
       
   163      * @param aMailboxId fs mailbox id
       
   164      * @param aObserver observer object to be removed
       
   165      */
       
   166     void UnsubscribeMailboxEvents(
       
   167         const TFSMailMsgId& aMailboxId,
       
   168         MFSMailEventObserver& aObserver );
       
   169 
       
   170     /**
       
   171      * Signal event to all plugin instances via p&s (property) api
       
   172      * @param aMailboxId entry id to mailbox
       
   173      * @param aEvent event enumeration
       
   174      * @param aError error code
       
   175      * @return error code from RProperty::Set function
       
   176      */
       
   177     TInt SetNewPropertyEvent( TInt aMailbox, TInt aEvent, TInt aError );
       
   178 
       
   179     /**
       
   180      * Adds property observer, p&s (property) events are signaled to these
       
   181      * observers
       
   182      * @param aObservers interface to observer object
       
   183      * @return error code from RProperty::Define function
       
   184      */
       
   185     TInt RegisterPropertyObserverL( MIpsPlgPropertyObserver* aObserver );
       
   186 
       
   187     /**
       
   188      * Removes property observer
       
   189      * @param aObserver pointer to observer to be removed, if null or
       
   190      *                  unregisterd observer then function simply returns
       
   191      */
       
   192     void UnRegisterPropertyObserver( MIpsPlgPropertyObserver* aObserver );
       
   193 
       
   194     /**
       
   195      * Used by CIpsPlgPropetyWatcher active object
       
   196      * @param aEvent property event
       
   197      */
       
   198     void NotifyPropertyEventL( TIpsPlgPropertyEvent aEvent );
       
   199 
       
   200     /**
       
   201      * used to inform ui offline state if connection attempt
       
   202      * was not successfull
       
   203      * @param aAccount FS mailbox id
       
   204      */
       
   205     void SignalMailboxOfflineStateL( const TFSMailMsgId& aAccount );
       
   206 
       
   207     /**
       
   208      * Send user password query request to fs email ui
       
   209      * @param aMbox entry id of mailbox service
       
   210      * @param aCallback callback interface to connection operation, defaut NULL
       
   211      */
       
   212     void QueryUsrPassL( TMsvId aMbox, MIpsPlgConnectOpCallback* aCallback=NULL );
       
   213 
       
   214     /**
       
   215      * Send user password (=credentials) set signal to all plugin
       
   216      * instances via p&s (property) mechanism
       
   217      * @param aMailboxId entry id of mailbox
       
   218      * @param aCancelled indicates is user cancelled password dialog
       
   219      */
       
   220     void SignalCredientialsSetL( TInt aMailboxId, TBool aCancelled );
       
   221 
       
   222 private:
       
   223 
       
   224     /**
       
   225     * Checks the source type of event and also
       
   226     * checks is the event from IPS type  ( imap/pop ) entry
       
   227     *
       
   228     * @param aSourceType return parameted indicating is the source:
       
   229     *   -service
       
   230     *   -message
       
   231     *   -folder
       
   232     *
       
   233     * @return ETrue if event is from IPS source
       
   234     */
       
   235     TBool IsEventFromIpsSourceL( TAny* aArg1,
       
   236             TUid& aSourceType,
       
   237             TMsvEntry& aEntry );
       
   238 
       
   239     /**
       
   240     * Passes events to FS framework after a delay.
       
   241     * NOTE: delay not implemented until there is proof to its necessity
       
   242     */
       
   243     void SendDelayedEventL(
       
   244         TFSMailEvent aEvent,
       
   245         TFSMailMsgId aMailbox,
       
   246         TAny* aArg1,
       
   247         TAny* aArg2,
       
   248         TAny* aArg3 );
       
   249 
       
   250     /**
       
   251     * gets TMsvIds of all IPS mail accouts for later use.
       
   252     * @param aAccounts Reference to list of accounts
       
   253     */
       
   254     void IPSAccountsL();
       
   255 
       
   256     /**
       
   257     *
       
   258     *
       
   259     */
       
   260     void HandleEntriesCreatedL( TAny* aArg1, TAny* aArg2, TAny* aArg3 );
       
   261 
       
   262     /**
       
   263     *
       
   264     *
       
   265     */
       
   266     void HandleEntriesMovedL( TAny* aArg1, TAny* aArg2, TAny* aArg3 );
       
   267 
       
   268     /**
       
   269     *
       
   270     *
       
   271     */
       
   272     void HandleEntriesDeletedL( TAny* aArg1, TAny* aArg2, TAny* aArg3 );
       
   273 
       
   274     /**
       
   275     *
       
   276     *
       
   277     */
       
   278     void HandleEntriesChangedL( TAny* aArg1, TAny* aArg2, TAny* aArg3 );
       
   279     
       
   280     //<cmail>    
       
   281     /**
       
   282     *
       
   283     *
       
   284     */
       
   285     void HandleMediaChangedL( TAny* aArg1, TAny* aArg2, TAny* aArg3 );
       
   286     
       
   287     /**
       
   288     *
       
   289     *
       
   290     */
       
   291     TUid MtmId() const;
       
   292     //</cmail>
       
   293     
       
   294     /**
       
   295     *
       
   296     *
       
   297     */
       
   298     TBool IsConnectionChangeL( TAny* aArg1, TAny* aArg2 );
       
   299 
       
   300     /**
       
   301     *
       
   302     *
       
   303     */
       
   304     TBool IsAccountNameChangeL( TAny* aArg1, TAny* aArg2 );
       
   305 
       
   306     /**
       
   307     * Relays connection state change events to framework.
       
   308     * It is protocol plugin's responsibility to choose correct
       
   309     * event to pass to framework.
       
   310     */
       
   311 
       
   312     void RelayConnectionEventL(
       
   313         TFSMailMsgId aMBoxId,
       
   314         TSSMailSyncState aNewState );
       
   315 
       
   316 
       
   317     /**
       
   318     * Appends settings observer for each mailbox
       
   319     * @param aSettingKey central repository key to observe.
       
   320     */
       
   321     void AppendSettingsObserverL(
       
   322         TFSMailMsgId aAccount,
       
   323         TUint32 aSettingKey );
       
   324 
       
   325     /**
       
   326     * Removes mailbox's settings observer
       
   327     * @param aMailboxId mailbox who's settings observer is to be removed.
       
   328     */
       
   329     void RemoveSettingsObserver( TFSMailMsgId aMailboxId );
       
   330 
       
   331     MFSMailEventObserver* MailboxObserverL(
       
   332         TFSMailMsgId aMailbox );
       
   333     void MailboxObserversL(
       
   334         TFSMailMsgId aMailbox,
       
   335         RPointerArray<MFSMailEventObserver>& aObservers );
       
   336 
       
   337     /**
       
   338      * Constructor
       
   339      */
       
   340     CIpsPlgEventHandler(
       
   341         CIpsPlgSosBasePlugin& aBasePlugin );
       
   342 
       
   343     /**
       
   344      * Constructor for leaving methods
       
   345      */
       
   346     void ConstructL( );
       
   347 
       
   348     /**
       
   349     * Checks for duplicate accounts
       
   350     */
       
   351     TBool AccountExistsL( const TMsvEntry& aEntry );
       
   352 
       
   353     /**
       
   354     * Founds correct msg entries that are directly under folder.
       
   355     * Parent is a inbox or subscribed folder in IMAP, and service
       
   356     * in POP
       
   357     */
       
   358     void FindCorrectDeletedEntryAndParentL(
       
   359         const TMsvEmailEntry& aParent,
       
   360         const CMsvEntrySelection& aDeletedIds,
       
   361         TFSMailMsgId& aFSParent,
       
   362         RArray<TFSMailMsgId>& aFSDeletedArray );
       
   363 
       
   364 
       
   365     /**
       
   366     * Saves last signalled sync status to settings
       
   367     */
       
   368     void SaveSyncStatusL( TMsvId aMailboxId, TInt aState );
       
   369 
       
   370     /**
       
   371     * Appends folder id to array if not already in there
       
   372     */
       
   373     void SetFolderIdToArrayL( TMsvId aNewId );
       
   374 
       
   375     /**
       
   376     * Checks if folder exists in the array and removes it.
       
   377     * Returns true in case of folder id,
       
   378     * otherwise we have a message deleted.
       
   379     */
       
   380     TBool MatchFolderIdFound( TMsvId aDeletedId );
       
   381 
       
   382     /**
       
   383     * Passes root folders to recursive function
       
   384     */
       
   385     void CollectSubscribedFoldersL( TMsvId aMailboxId );
       
   386 
       
   387     /**
       
   388     * Sets property event and defines property if not yet defined
       
   389     */
       
   390     TInt SetProperty( TIpsPlgPropertyEvent aEvent );
       
   391 
       
   392     /**
       
   393      * Signal sync started event via p&s api to all plugin instances
       
   394      */
       
   395     void SignalStartSyncL( const TFSMailMsgId& aAccount );
       
   396 
       
   397     /**
       
   398      * Signal sync completed event via p&s api to all plugin instances
       
   399      */
       
   400     void SignalSyncCompletedL( const TFSMailMsgId& aAccount, TInt aError );
       
   401 
       
   402 private: // datak
       
   403 
       
   404     inline TFSMailMsgId SymId2FsId( TMsvId aId, TUint aMtmUid );
       
   405 
       
   406     inline TFSMailMsgId SymId2FsId( const TMsvEntry& aEntry );
       
   407 
       
   408     /**
       
   409     * Fills RArray FSMessage objects created from CMsvEntrySelection
       
   410     */
       
   411     inline void FillFSMessageArray(
       
   412             RArray<TFSMailMsgId>& aFSArray,
       
   413             const CMsvEntrySelection* aSelection,
       
   414             TUint aMtmUid );
       
   415 
       
   416     CRepository*                            iCenRep;
       
   417     CIpsSetDataApi*                         iSettingsApi;
       
   418 
       
   419     // not owned
       
   420     CMsvSession*                            iSession;
       
   421 
       
   422     CIpsPlgSosBasePlugin&                   iBasePlugin;
       
   423 
       
   424     //not owned.
       
   425     MFSMailEventObserver*                   iPluginObserver;
       
   426 
       
   427     RPointerArray<CMBoxEventObserver>       iMBoxObservers;
       
   428 
       
   429     RPointerArray<CIPSAccountInfo>          iIPSAccounts;
       
   430 
       
   431     RPointerArray<CIpsPlgSettingsObserver>  iIPSSettingsObservers;
       
   432 
       
   433     TBool                                   iIsConnected;
       
   434 
       
   435     CIpsPlgSettingsObserver*                iSettingsObserver;
       
   436 
       
   437     RPointerArray<MIpsPlgPropertyObserver>  iPropertyObservers;
       
   438 
       
   439     CIpsPlgPropertyWatcher*                 iPropertyWatcher;
       
   440 
       
   441     TPckgBuf<TIpsPlgPropertyEvent>          iPropertyBuf;
       
   442 
       
   443     // base plugin id
       
   444     TUint                                   iPluginId;
       
   445 
       
   446     //not owned
       
   447     MIpsPlgConnectOpCallback*               iConnOpCallback;
       
   448 
       
   449     RArray<TMsvId>                          iImapFolderIds;
       
   450 
       
   451     };
       
   452 
       
   453 
       
   454 #endif // IPSPLGEVENTHANDLER_H
       
   455 
       
   456 // End of file