emailservices/emailserver/cmailhandlerplugin/src/cmailcpshandler.cpp
branchRCL_3
changeset 22 d620048b4810
parent 20 efd4f1afd43e
child 23 dcf0eedfc1a3
equal deleted inserted replaced
20:efd4f1afd43e 22:d620048b4810
   481                 HBufC* mailboxAndCount = StringLoader::LoadLC( R_EMAILWIDGET_TEXT_MAILBOX_AND_MAILCOUNT,
   481                 HBufC* mailboxAndCount = StringLoader::LoadLC( R_EMAILWIDGET_TEXT_MAILBOX_AND_MAILCOUNT,
   482                                                                *strings,
   482                                                                *strings,
   483                                                                *ints );
   483                                                                *ints );
   484 
   484 
   485                 iLiwIf->PublishActiveMailboxNameL(
   485                 iLiwIf->PublishActiveMailboxNameL(
   486 				        aWidgetInstance,
   486                         aWidgetInstance,
   487                         aRowNumber, *mailboxAndCount);
   487                         aRowNumber, *mailboxAndCount);
   488 
   488 
   489                 CleanupStack::PopAndDestroy(mailboxAndCount);
   489                 CleanupStack::PopAndDestroy(mailboxAndCount);
   490                 CleanupStack::PopAndDestroy(ints);
   490                 CleanupStack::PopAndDestroy(ints);
   491                 CleanupStack::PopAndDestroy(strings);
   491                 CleanupStack::PopAndDestroy(strings);
   493             else
   493             else
   494                 {
   494                 {
   495                 // show only mailbox name
   495                 // show only mailbox name
   496 
   496 
   497                 iLiwIf->PublishActiveMailboxNameL(
   497                 iLiwIf->PublishActiveMailboxNameL(
   498 				        aWidgetInstance,
   498                         aWidgetInstance,
   499                         aRowNumber, accountName);
   499                         aRowNumber, accountName);
   500                 }
   500                 }
   501             }
   501             }
   502         }
   502         }
   503     else if(!mailBoxFound)
   503     else if(!mailBoxFound)
   504         {
   504         {
   505         // Publishing empty descriptor for rows that should not contain
   505         // Publishing empty descriptor for rows that should not contain
   506         // anything on widget UI.
   506         // anything on widget UI.
   507         iLiwIf->PublishActiveMailboxNameL( aWidgetInstance,
   507         iLiwIf->PublishActiveMailboxNameL( aWidgetInstance,
   508 		                                   aRowNumber,
   508                                            aRowNumber,
   509 										   KNullDesC);
   509                                            KNullDesC);
   510         }
   510         }
   511     }
   511     }
   512 
   512 
   513 
   513 
   514 // ---------------------------------------------------------
   514 // ---------------------------------------------------------
   535             delete mailbox;
   535             delete mailbox;
   536             // Check that folder is correct
   536             // Check that folder is correct
   537             CFSMailFolder* folder = MailClient().GetFolderByUidL( mailBoxId, parentFolder );
   537             CFSMailFolder* folder = MailClient().GetFolderByUidL( mailBoxId, parentFolder );
   538             if ( !folder )
   538             if ( !folder )
   539                 {
   539                 {
   540 				UpdateEmptyMessagesL( aWidgetInstance, aRow );
   540                 UpdateEmptyMessagesL( aWidgetInstance, aRow );
   541                 return;
   541                 return;
   542                 }
   542                 }
   543             CleanupStack::PushL( folder );
   543             CleanupStack::PushL( folder );
   544 
   544 
   545             TInt msgCount = folder->GetMessageCount();
   545             TInt msgCount = folder->GetMessageCount();
   755 
   755 
   756     if ( aMailBoxNumber < iAccountsArray.Count() )
   756     if ( aMailBoxNumber < iAccountsArray.Count() )
   757         {
   757         {
   758         mailBoxId = iAccountsArray[aMailBoxNumber]->iMailboxId;
   758         mailBoxId = iAccountsArray[aMailBoxNumber]->iMailboxId;
   759         iLiwIf->PublishMailboxIconL( aWidgetInstance,
   759         iLiwIf->PublishMailboxIconL( aWidgetInstance,
   760 		                             aRowNumber,
   760                                      aRowNumber,
   761 									 EMbmCmailhandlerpluginQgn_indi_cmail_drop_email_account,
   761                                      EMbmCmailhandlerpluginQgn_indi_cmail_drop_email_account,
   762 									 mailBoxId);
   762                                      mailBoxId);
   763         }
   763         }
   764     else
   764     else
   765         {
   765         {
   766         iLiwIf->PublishMailboxIconL( aWidgetInstance, aRowNumber, KNullIcon, mailBoxId);
   766         iLiwIf->PublishMailboxIconL( aWidgetInstance, aRowNumber, KNullIcon, mailBoxId);
   767         }
   767         }
   884             UpdateFullL();
   884             UpdateFullL();
   885             break;
   885             break;
   886             }
   886             }
   887         case TFSEventNewMail:
   887         case TFSEventNewMail:
   888             {
   888             {
   889             HandleNewMailEventL( aMailbox, aParam1, aParam2 );
       
   890             SetUpdateNeeded( aMailbox );
   889             SetUpdateNeeded( aMailbox );
   891             UpdateFullL();
   890             UpdateFullL();
   892             break;
   891             break;
   893             }
   892             }
   894         case TFSEventMailDeleted:
   893         case TFSEventMailDeleted:
   895             {
   894             {
   896             HandleMailDeletedEventL( aMailbox, aParam1, aParam2 );
       
   897             SetUpdateNeeded( aMailbox );
   895             SetUpdateNeeded( aMailbox );
   898             UpdateFullL();
   896             UpdateFullL();
   899             break;
   897             break;
   900             }
   898             }
   901         case TFSEventMailChanged:
   899         case TFSEventMailChanged:
   981             break;
   979             break;
   982             }
   980             }
   983         }
   981         }
   984     }
   982     }
   985 
   983 
   986 // ---------------------------------------------------------
       
   987 // CMailCpsHandler::HandleNewMailEventL
       
   988 // ---------------------------------------------------------
       
   989 //
       
   990 void CMailCpsHandler::HandleNewMailEventL(
       
   991     TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 )
       
   992     {
       
   993     FUNC_LOG;
       
   994 
       
   995     iSettings->ToggleWidgetNewMailIconL( ETrue, aMailbox );
       
   996 
       
   997     // Basic assertions
       
   998     if ( !aParam1 || !aParam2 )
       
   999         {
       
  1000         User::Leave( KErrArgument );
       
  1001         }
       
  1002 
       
  1003     // typecast param2
       
  1004     TFSMailMsgId* parentFolder = static_cast<TFSMailMsgId*>( aParam2 );
       
  1005 
       
  1006     // Check that folder is correct
       
  1007     CFSMailFolder* folder = MailClient().GetFolderByUidL( aMailbox, *parentFolder );
       
  1008     if ( !folder )
       
  1009         {
       
  1010         User::Leave( KErrNotFound );
       
  1011         }
       
  1012     CleanupStack::PushL( folder );
       
  1013     if ( folder->GetFolderType() != EFSInbox )
       
  1014         {
       
  1015         CleanupStack::PopAndDestroy( folder );
       
  1016         return;
       
  1017         }
       
  1018     CleanupStack::PopAndDestroy( folder );
       
  1019 
       
  1020     // typecast param1
       
  1021     RArray<TFSMailMsgId>* newEntries(
       
  1022             static_cast< RArray<TFSMailMsgId>* >( aParam1 ) );
       
  1023     CleanupClosePushL( *newEntries );
       
  1024     const TInt iiMax( newEntries->Count() );
       
  1025     if ( iiMax == 0 )
       
  1026         {
       
  1027         User::Leave( KErrArgument );
       
  1028         }
       
  1029 
       
  1030     // Loop through message array
       
  1031     TFSMailMsgId msgId;
       
  1032     CFSMailMessage* msg( NULL );
       
  1033     CMailMailboxDetails* mailbox;
       
  1034     for ( TInt ii = 0; ii < iiMax; ii++ )
       
  1035         {
       
  1036         msgId = (*newEntries)[ii];
       
  1037 
       
  1038         msg = MailClient().GetMessageByUidL(
       
  1039             aMailbox, *parentFolder, (*newEntries)[ii], EFSMsgDataEnvelope );
       
  1040         if ( !msg )
       
  1041             {
       
  1042             User::Leave( KErrNotFound );
       
  1043             }
       
  1044         CleanupStack::PushL( msg );
       
  1045 
       
  1046         // Check if message read
       
  1047         if ( !MsgIsUnread( *msg ) )
       
  1048             {
       
  1049             // Ignore already read messages
       
  1050             CleanupStack::PopAndDestroy( msg );
       
  1051             continue;
       
  1052             }
       
  1053 
       
  1054         // Find mailbox instance from array
       
  1055         mailbox = FindMailboxDetails( aMailbox );
       
  1056         if ( !mailbox )
       
  1057             {
       
  1058             CleanupStack::PopAndDestroy( msg );
       
  1059             CleanupStack::PopAndDestroy( newEntries );
       
  1060             return;
       
  1061             }
       
  1062 
       
  1063         // Check if message is duplicate
       
  1064         if ( IsDuplicate( *mailbox, msgId ) )
       
  1065             {
       
  1066             // Ignore already known messages
       
  1067             CleanupStack::PopAndDestroy( msg );
       
  1068             continue;
       
  1069             }
       
  1070 
       
  1071         CMailMessageDetails* messageDetails = CMailMessageDetails::NewL(
       
  1072             msg->GetMessageId(),
       
  1073             mailbox,
       
  1074             msg->GetSender()->GetEmailAddress(),
       
  1075             msg->GetSubject(),
       
  1076             msg->GetDate() );
       
  1077         CleanupStack::PopAndDestroy( msg );
       
  1078         CleanupStack::PushL( messageDetails );
       
  1079 
       
  1080         // Place message to array
       
  1081         mailbox->iMessageDetailsArray.AppendL( messageDetails );
       
  1082         CleanupStack::Pop( messageDetails );
       
  1083         }
       
  1084     CleanupStack::PopAndDestroy( newEntries );
       
  1085     }
       
  1086 
       
  1087 // ---------------------------------------------------------
       
  1088 // CMailCpsHandler::HandleMailDeletedEventL
       
  1089 // ---------------------------------------------------------
       
  1090 //
       
  1091 void CMailCpsHandler::HandleMailDeletedEventL(
       
  1092     TFSMailMsgId aMailbox, TAny* aParam1, TAny* aParam2 )
       
  1093     {
       
  1094     FUNC_LOG;
       
  1095     // Basic assertions
       
  1096     if ( !aParam1 || !aParam2 )
       
  1097         {
       
  1098         User::Leave( KErrArgument );
       
  1099         }
       
  1100     // Typecast parameters
       
  1101     RArray<TFSMailMsgId>* entries(
       
  1102             static_cast< RArray<TFSMailMsgId>* >( aParam1 ) );
       
  1103     CleanupClosePushL( *entries );
       
  1104     if ( entries->Count() == 0 )
       
  1105         {
       
  1106         User::Leave( KErrArgument );
       
  1107         }
       
  1108 
       
  1109     // Find correct mailbox
       
  1110     CMailMailboxDetails* mailbox = FindMailboxDetails( aMailbox );
       
  1111     if ( !mailbox )
       
  1112         {
       
  1113         CleanupStack::PopAndDestroy( entries );
       
  1114         return;
       
  1115         }
       
  1116 
       
  1117     const TInt iiMax( entries->Count() );
       
  1118     const TInt jjMax( mailbox->iMessageDetailsArray.Count() );
       
  1119     // Loop through entries in the array
       
  1120     for ( TInt ii = 0; ii < iiMax; ii++ )
       
  1121         {
       
  1122         // Loop through messages in the local cache
       
  1123         for ( TInt jj = 0; jj < jjMax; jj++ )
       
  1124             {
       
  1125             if ( mailbox->iMessageDetailsArray[jj]->iMsgId.Id() ==
       
  1126                 (*entries)[ii].Id() )
       
  1127                 {
       
  1128                 CMailMessageDetails* details = mailbox->iMessageDetailsArray[jj];
       
  1129                 delete details;
       
  1130                 details = NULL;
       
  1131                 mailbox->iMessageDetailsArray.Remove(jj);
       
  1132                 break; // breaks out from the inner loop and starts new outer loop if necessary
       
  1133                 }
       
  1134             else
       
  1135                 {
       
  1136                 }
       
  1137             }
       
  1138         }
       
  1139 
       
  1140     CleanupStack::PopAndDestroy( entries );
       
  1141     }
       
  1142 
   984 
  1143 // ---------------------------------------------------------
   985 // ---------------------------------------------------------
  1144 // CMailCpsHandler::GetUnreadCountL
   986 // CMailCpsHandler::GetUnreadCountL
  1145 // ---------------------------------------------------------
   987 // ---------------------------------------------------------
  1146 //
   988 //
  1664 
  1506 
  1665     return ETrue;
  1507     return ETrue;
  1666     }
  1508     }
  1667 
  1509 
  1668 // -----------------------------------------------------------------------------
  1510 // -----------------------------------------------------------------------------
  1669 // CMailCpsHandler::IsDuplicate
       
  1670 // -----------------------------------------------------------------------------
       
  1671 TBool CMailCpsHandler::IsDuplicate( const CMailMailboxDetails& aMailbox, const TFSMailMsgId& aMsgId )
       
  1672     {
       
  1673     FUNC_LOG;
       
  1674     TBool isDuplicate( EFalse );
       
  1675     const TInt size( aMailbox.iMessageDetailsArray.Count() );
       
  1676     for ( TInt jj = 0; jj < size; jj++ )
       
  1677         {
       
  1678         if ( aMailbox.iMessageDetailsArray[jj]->iMsgId.Id() == aMsgId.Id() )
       
  1679             {
       
  1680             isDuplicate = ETrue;
       
  1681             }
       
  1682         }
       
  1683     return isDuplicate;
       
  1684     }
       
  1685 
       
  1686 // -----------------------------------------------------------------------------
       
  1687 //  CMailCpsHandler::LaunchWidgetSettingsL()
  1511 //  CMailCpsHandler::LaunchWidgetSettingsL()
  1688 // -----------------------------------------------------------------------------
  1512 // -----------------------------------------------------------------------------
  1689 //
  1513 //
  1690 void CMailCpsHandler::LaunchWidgetSettingsL( const TDesC& aContentId )
  1514 void CMailCpsHandler::LaunchWidgetSettingsL( const TDesC& aContentId )
  1691     {
  1515     {