emailservices/emailserver/cmailhandlerplugin/src/cmailcpshandler.cpp
branchRCL_3
changeset 18 6b8f3b30d0ec
parent 17 67369d1b217f
child 20 efd4f1afd43e
equal deleted inserted replaced
17:67369d1b217f 18:6b8f3b30d0ec
    52 // ---------------------------------------------------------
    52 // ---------------------------------------------------------
    53 //
    53 //
    54 CMailCpsHandler::CMailCpsHandler( MFSNotificationHandlerMgr& aOwner ): 
    54 CMailCpsHandler::CMailCpsHandler( MFSNotificationHandlerMgr& aOwner ): 
    55     CFSNotificationHandlerBase( aOwner ),
    55     CFSNotificationHandlerBase( aOwner ),
    56     iWaitingForNewMailbox( NULL ),
    56     iWaitingForNewMailbox( NULL ),
    57     iWaitingForNewWidget()
    57     iWaitingForNewWidget(),
       
    58     iUpdateHelper( NULL )
    58     {
    59     {
    59     FUNC_LOG;
    60     FUNC_LOG;
    60     iWaitingForNewWidget.SetPluginId( KNullUid );
    61     iWaitingForNewWidget.SetPluginId( KNullUid );
    61     iWaitingForNewWidget.SetId( 0 );
    62     iWaitingForNewWidget.SetId( 0 );
    62     }
    63     }
   106 // ---------------------------------------------------------
   107 // ---------------------------------------------------------
   107 //
   108 //
   108 CMailCpsHandler::~CMailCpsHandler()
   109 CMailCpsHandler::~CMailCpsHandler()
   109     {
   110     {
   110     FUNC_LOG;
   111     FUNC_LOG;
       
   112     delete iUpdateHelper;
   111     delete iLiwIf;
   113     delete iLiwIf;
   112     delete iSettings;
   114     delete iSettings;
   113     iAccountsArray.ResetAndDestroy();
   115     iAccountsArray.ResetAndDestroy();
   114     iExternalPlugins.ResetAndDestroy();
   116     iExternalPlugins.ResetAndDestroy();
   115     }
   117     }
   346 // ---------------------------------------------------------
   348 // ---------------------------------------------------------
   347 // CMailCpsHandler::UpdateFullL
   349 // CMailCpsHandler::UpdateFullL
   348 // ---------------------------------------------------------
   350 // ---------------------------------------------------------
   349 //
   351 //
   350 void CMailCpsHandler::UpdateFullL()
   352 void CMailCpsHandler::UpdateFullL()
       
   353     {
       
   354     FUNC_LOG;
       
   355     if ( !iUpdateHelper )
       
   356         {
       
   357         iUpdateHelper = CMailCpsUpdateHelper::NewL( this );
       
   358         }
       
   359     iUpdateHelper->UpdateL();
       
   360     }
       
   361 
       
   362 // ---------------------------------------------------------
       
   363 // CMailCpsHandler::DoUpdateFullL
       
   364 // ---------------------------------------------------------
       
   365 //
       
   366 void CMailCpsHandler::DoUpdateFullL()
   351     {
   367     {
   352     FUNC_LOG;
   368     FUNC_LOG;
   353     for (TInt instance = 0; instance < iLiwIf->GetWidgetInstanceCount(); instance++)
   369     for (TInt instance = 0; instance < iLiwIf->GetWidgetInstanceCount(); instance++)
   354         {
   370         {
   355         if ( iLiwIf->AllowedToPublish(instance) )
   371         if ( iLiwIf->AllowedToPublish(instance) )
   979     if ( !aParam1 || !aParam2 )
   995     if ( !aParam1 || !aParam2 )
   980         {
   996         {
   981         User::Leave( KErrArgument );
   997         User::Leave( KErrArgument );
   982         }
   998         }
   983 
   999 
   984     // Find mailbox instance from array
       
   985     CMailMailboxDetails* mailbox = FindMailboxDetails( aMailbox );
       
   986     if ( !mailbox )
       
   987         {
       
   988         return;
       
   989         }
       
   990 
       
   991     // typecast param2
  1000     // typecast param2
   992     TFSMailMsgId* parentFolder = static_cast<TFSMailMsgId*>( aParam2 );
  1001     TFSMailMsgId* parentFolder = static_cast<TFSMailMsgId*>( aParam2 );
   993 
  1002 
   994     // Check that folder is correct
  1003     // Check that folder is correct
   995     CFSMailFolder* folder = MailClient().GetFolderByUidL( aMailbox, *parentFolder );
  1004     CFSMailFolder* folder = MailClient().GetFolderByUidL( aMailbox, *parentFolder );
  1016         }
  1025         }
  1017 
  1026 
  1018     // Loop through message array
  1027     // Loop through message array
  1019     TFSMailMsgId msgId;
  1028     TFSMailMsgId msgId;
  1020     CFSMailMessage* msg( NULL );
  1029     CFSMailMessage* msg( NULL );
       
  1030     CMailMailboxDetails* mailbox;
  1021     for ( TInt ii = 0; ii < iiMax; ii++ )
  1031     for ( TInt ii = 0; ii < iiMax; ii++ )
  1022         {
  1032         {
  1023         msgId = (*newEntries)[ii];
  1033         msgId = (*newEntries)[ii];
  1024 
  1034 
  1025         msg = MailClient().GetMessageByUidL(
  1035         msg = MailClient().GetMessageByUidL(
  1034         if ( !MsgIsUnread( *msg ) )
  1044         if ( !MsgIsUnread( *msg ) )
  1035             {
  1045             {
  1036             // Ignore already read messages
  1046             // Ignore already read messages
  1037             CleanupStack::PopAndDestroy( msg );
  1047             CleanupStack::PopAndDestroy( msg );
  1038             continue;
  1048             continue;
       
  1049             }
       
  1050 
       
  1051         // Find mailbox instance from array
       
  1052         mailbox = FindMailboxDetails( aMailbox );
       
  1053         if ( !mailbox )
       
  1054             {
       
  1055             CleanupStack::PopAndDestroy( msg );
       
  1056             CleanupStack::PopAndDestroy( newEntries );
       
  1057             return;
  1039             }
  1058             }
  1040 
  1059 
  1041         // Check if message is duplicate
  1060         // Check if message is duplicate
  1042         if ( IsDuplicate( *mailbox, msgId ) )
  1061         if ( IsDuplicate( *mailbox, msgId ) )
  1043             {
  1062             {
  1990                 }
  2009                 }
  1991             }
  2010             }
  1992         }
  2011         }
  1993     return backupOrRestore;
  2012     return backupOrRestore;
  1994     }
  2013     }
       
  2014 
       
  2015 // ----------------------------------------------------------------------------
       
  2016 // class CMailCpsUpdateHelper : public CTimer
       
  2017 // Used to limit the rate of updates to Homescreen widget
       
  2018 // ----------------------------------------------------------------------------
       
  2019 //
       
  2020 
       
  2021 CMailCpsUpdateHelper::CMailCpsUpdateHelper(
       
  2022     CMailCpsHandler *aHandler )
       
  2023     : CTimer( EPriorityStandard )  // Could be EPriorityLow
       
  2024     , iCpsHandler( aHandler )
       
  2025     , iPending( EFalse )
       
  2026     {
       
  2027     FUNC_LOG;
       
  2028     }
       
  2029 
       
  2030 CMailCpsUpdateHelper* CMailCpsUpdateHelper::NewLC( CMailCpsHandler* aHandler )
       
  2031     {
       
  2032     FUNC_LOG;
       
  2033     CMailCpsUpdateHelper* self = new ( ELeave ) CMailCpsUpdateHelper( aHandler );
       
  2034     CleanupStack::PushL( self );
       
  2035     self->ConstructL();
       
  2036     return self;
       
  2037     }
       
  2038 
       
  2039 CMailCpsUpdateHelper* CMailCpsUpdateHelper::NewL( CMailCpsHandler *aHandler )
       
  2040     {
       
  2041     FUNC_LOG;
       
  2042     CMailCpsUpdateHelper* self = CMailCpsUpdateHelper::NewLC( aHandler );
       
  2043     CleanupStack::Pop( self );
       
  2044     return self;
       
  2045     }
       
  2046 
       
  2047 void CMailCpsUpdateHelper::ConstructL()
       
  2048     {
       
  2049     FUNC_LOG;
       
  2050     CTimer::ConstructL();
       
  2051     CActiveScheduler::Add( this );
       
  2052     }
       
  2053 
       
  2054 CMailCpsUpdateHelper::~CMailCpsUpdateHelper()
       
  2055     {
       
  2056     FUNC_LOG;
       
  2057     iCpsHandler = NULL; // Not owned
       
  2058     Cancel();   // Stop any pending request
       
  2059     Deque();    // Remove from CActiveScheduler
       
  2060     }
       
  2061 
       
  2062 // Notification that Homescreen widget(s) should be updated
       
  2063 void CMailCpsUpdateHelper::UpdateL()
       
  2064     {
       
  2065     FUNC_LOG;
       
  2066     if ( IsActive() )
       
  2067         {
       
  2068         // Timer is running, so just flag that an update should be sent when
       
  2069         // the timer expires.
       
  2070         iPending = ETrue;
       
  2071         }
       
  2072     else
       
  2073         {
       
  2074         // Timer is not running, so perform an update and set the timer
       
  2075         // running.
       
  2076         DoUpdateL();
       
  2077         }
       
  2078     }
       
  2079 
       
  2080 // Actually perform an update of the Homescreen widget.  Also sets the timer
       
  2081 // running and clears the pending flag.
       
  2082 void CMailCpsUpdateHelper::DoUpdateL()
       
  2083     {
       
  2084     FUNC_LOG;
       
  2085     // Set the timer running.
       
  2086     After( KMailCpsHandlerUpdateDelay );
       
  2087     // Clear the pending flag.
       
  2088     iPending = EFalse;
       
  2089     // Do the update.
       
  2090     iCpsHandler->DoUpdateFullL();
       
  2091     }
       
  2092 
       
  2093 void CMailCpsUpdateHelper::RunL()
       
  2094     {
       
  2095     FUNC_LOG;
       
  2096     if ( iPending )
       
  2097         {
       
  2098         // There was an update request since the last update, so do another
       
  2099         // update (and set the timer running again, etc.).
       
  2100         DoUpdateL();
       
  2101         }
       
  2102     }
       
  2103 
       
  2104 TInt CMailCpsUpdateHelper::RunError( TInt aError )
       
  2105     {
       
  2106     FUNC_LOG;
       
  2107     if ( KErrNone != aError )
       
  2108         {
       
  2109         Cancel();   // Stop any pending request
       
  2110         }
       
  2111     return KErrNone;    // Don't panic the thread
       
  2112     }
       
  2113