ipsservices/ipssosplugin/src/ipsplgeventhandler.cpp
changeset 18 578830873419
parent 0 8466d47a6819
child 20 ecc8def7944a
equal deleted inserted replaced
4:e7aa27f58ae1 18:578830873419
   103         }
   103         }
   104     delete iCenRep;
   104     delete iCenRep;
   105     iIPSSettingsObservers.ResetAndDestroy();
   105     iIPSSettingsObservers.ResetAndDestroy();
   106     iIPSSettingsObservers.Close();
   106     iIPSSettingsObservers.Close();
   107     iPropertyObservers.Close();
   107     iPropertyObservers.Close();
   108     delete iSettingsApi;
       
   109     iImapFolderIds.Close();
   108     iImapFolderIds.Close();
   110     }
   109     }
   111 
   110 
   112 // ---------------------------------------------------------------------------
   111 // ---------------------------------------------------------------------------
   113 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   125 // ---------------------------------------------------------------------------
   127 // ---------------------------------------------------------------------------
   126 // ---------------------------------------------------------------------------
   128 void CIpsPlgEventHandler::ConstructL( )
   127 void CIpsPlgEventHandler::ConstructL( )
   129     {
   128     {
   130     FUNC_LOG;
   129     FUNC_LOG;
   131     iCenRep = CRepository::NewL( KCRUidExtendedSettingsUid );
   130     // <qmail>
       
   131     // commented out from qmail when extented settings 
       
   132     // cen rep not exist in environment
       
   133     //iCenRep = CRepository::NewL( KCRUidExtendedSettingsUid );
       
   134     // </qmail>
   132     iPluginId = iBasePlugin.PluginId();
   135     iPluginId = iBasePlugin.PluginId();
   133     RegisterPropertyObserverL( this );
   136     RegisterPropertyObserverL( this );
   134     }
   137     }
   135 
   138 
   136 // ----------------------------------------------------------------------------
   139 // ----------------------------------------------------------------------------
   137 // ----------------------------------------------------------------------------
   140 // ----------------------------------------------------------------------------
   138 void CIpsPlgEventHandler::CompleteConstructL( CMsvSession* aSession )
   141 void CIpsPlgEventHandler::CompleteConstructL( CMsvSession* aSession )
   139     {
   142     {
   140     FUNC_LOG;
   143     FUNC_LOG;
   141     iSession = aSession;
   144     iSession = aSession;
   142     iSettingsApi = CIpsSetDataApi::NewL( *iSession );
       
   143 
   145 
   144     // this collects all folderids to array from mailboxes that
   146     // this collects all folderids to array from mailboxes that
   145     // have registered observers, this is need to do here because
   147     // have registered observers, this is need to do here because
   146     // observers might be registered before calling complete construct
   148     // observers might be registered before calling complete construct
   147     RArray<TMsvId> mboxes( KEventGranularity );
   149     RArray<TMsvId> mboxes( KEventGranularity );
   519     event.iArg1 = aArg1;
   521     event.iArg1 = aArg1;
   520     event.iArg2 = aArg2;
   522     event.iArg2 = aArg2;
   521     event.iArg3 = aArg3;
   523     event.iArg3 = aArg3;
   522 
   524 
   523     RPointerArray<MFSMailEventObserver> observers;
   525     RPointerArray<MFSMailEventObserver> observers;
   524     CleanupClosePushL( observers );
       
   525 
   526 
   526     if( aEvent == TFSEventNewMailbox ||
   527     if( aEvent == TFSEventNewMailbox ||
   527         aEvent == TFSEventMailboxRenamed ||
   528         aEvent == TFSEventMailboxRenamed ||
   528         aEvent == TFSEventMailboxDeleted )
   529         aEvent == TFSEventMailboxDeleted )
   529         {
   530         {
   540         //other events go to mailbox specific observers
   541         //other events go to mailbox specific observers
   541         MailboxObserversL( aMailbox, observers );
   542         MailboxObserversL( aMailbox, observers );
   542         }
   543         }
   543     for( TInt i = 0; i < observers.Count(); ++i )
   544     for( TInt i = 0; i < observers.Count(); ++i )
   544         {
   545         {
   545         // ignore leave so that other observers get event even if
   546         observers[i]->EventL(
   546         // one leaves
       
   547         TRAP_IGNORE(observers[i]->EventL(
       
   548             event.iEvent,
   547             event.iEvent,
   549             event.iAccountId,
   548             event.iAccountId,
   550             event.iArg1,
   549             event.iArg1,
   551             event.iArg2,
   550             event.iArg2,
   552             event.iArg3 ));
   551             event.iArg3 );
   553         }
   552         }
   554     CleanupStack::PopAndDestroy( &observers );
   553     observers.Close();
   555     }
   554     }
   556 
   555 
   557 // ----------------------------------------------------------------------------
   556 // ----------------------------------------------------------------------------
   558 // ----------------------------------------------------------------------------
   557 // ----------------------------------------------------------------------------
   559 void CIpsPlgEventHandler::IPSAccountsL()
   558 void CIpsPlgEventHandler::IPSAccountsL()
   639                 tNew.iDetails,
   638                 tNew.iDetails,
   640                 mbox ) );
   639                 mbox ) );
   641             SendDelayedEventL( event, mbox,
   640             SendDelayedEventL( event, mbox,
   642                 arg1, arg2 , arg3 );
   641                 arg1, arg2 , arg3 );
   643             }
   642             }
   644         
   643         if ( type == KUidMsvMessageEntry )
   645         // discard any new mail events if message is marked as deleted in imap
       
   646         const TMsvEmailEntry& emlEntry(tNew);
       
   647         TBool isMarkedAsDeleted = EFalse;
       
   648         if ( mbox.PluginId() == KIpsPlgImap4PluginUid
       
   649                 && (EDisconnectedDeleteOperation == emlEntry.DisconnectedOperation()
       
   650                 || emlEntry.DeletedIMAP4Flag()) )
       
   651             {
       
   652             isMarkedAsDeleted = ETrue;
       
   653             }
       
   654         
       
   655         
       
   656         if ( type == KUidMsvMessageEntry && !isMarkedAsDeleted )
       
   657             {
   644             {
   658             TMsvId* parent = static_cast<TMsvId*>(aArg2);
   645             TMsvId* parent = static_cast<TMsvId*>(aArg2);
       
   646             // NOTE: assumed that event contains only one new message
   659             event = TFSEventNewMail;
   647             event = TFSEventNewMail;
   660             TFSMailMsgId mbox;
   648             TFSMailMsgId mbox;
   661 
   649 
   662             if ( tNew.iServiceId == KMsvLocalServiceIndexEntryIdValue
   650             if ( tNew.iServiceId == KMsvLocalServiceIndexEntryIdValue
   663                 || tNew.Parent() == KMsvDraftEntryIdValue )
   651                 || tNew.Parent() == KMsvDraftEntryIdValue )
   684                     }
   672                     }
   685                 }
   673                 }
   686 
   674 
   687             // set entries array pointer
   675             // set entries array pointer
   688             RArray<TFSMailMsgId> array(KEventGranularity);
   676             RArray<TFSMailMsgId> array(KEventGranularity);
   689             CleanupClosePushL( array );
       
   690 
   677 
   691             FillFSMessageArray(
   678             FillFSMessageArray(
   692                 array,
   679                 array,
   693                 static_cast<const CMsvEntrySelection*>(aArg1),
   680                 static_cast<const CMsvEntrySelection*>(aArg1),
   694                 tNew.iMtm.iUid );
   681                 tNew.iMtm.iUid );
   699             TFSMailMsgId tfsid( iPluginId, *parent);
   686             TFSMailMsgId tfsid( iPluginId, *parent);
   700             arg2 = static_cast<TAny*>(&tfsid);
   687             arg2 = static_cast<TAny*>(&tfsid);
   701 
   688 
   702             SendDelayedEventL( event, mbox,
   689             SendDelayedEventL( event, mbox,
   703                 arg1, arg2 , arg3 );
   690                 arg1, arg2 , arg3 );
   704             CleanupStack::PopAndDestroy( &array );
   691             array.Close();
   705             }
   692             }
   706         else if ( type == KUidMsvFolderEntry )
   693         else if ( type == KUidMsvFolderEntry )
   707             {
   694             {
   708             event = TFSEventNewFolder;
   695             event = TFSEventNewFolder;
   709             mbox = SymId2FsId( tNew.iServiceId, tNew.iMtm.iUid );
   696             mbox = SymId2FsId( tNew.iServiceId, tNew.iMtm.iUid );
   710 
   697 
   711             // set entries array pointer
   698             // set entries array pointer
   712             RArray<TFSMailMsgId> array(1);
   699             RArray<TFSMailMsgId> array(1);
   713             CleanupClosePushL( array );
       
   714             array.Append( SymId2FsId( tNew ) );
   700             array.Append( SymId2FsId( tNew ) );
   715             arg1 = &array;
   701             arg1 = &array;
   716 
   702 
   717             // set parent pointer
   703             // set parent pointer
   718             TMsvId* parent = static_cast<TMsvId*>(aArg2);
   704             TMsvId* parent = static_cast<TMsvId*>(aArg2);
   720             arg2 = static_cast<TAny*>(&tfsid);
   706             arg2 = static_cast<TAny*>(&tfsid);
   721 
   707 
   722             SendDelayedEventL( event, mbox,
   708             SendDelayedEventL( event, mbox,
   723                 arg1, arg2 , arg3 );
   709                 arg1, arg2 , arg3 );
   724 
   710 
   725             CleanupStack::PopAndDestroy( &array );
   711             array.Close();
   726 
   712 
   727             if( tNew.iMtm.iUid == KSenduiMtmImap4UidValue )
   713             if( tNew.iMtm.iUid == KSenduiMtmImap4UidValue )
   728                 {
   714                 {
   729                 SetFolderIdToArrayL( tNew.Id() );
   715                 SetFolderIdToArrayL( tNew.Id() );
   730                 }
   716                 }
   757         TAny* arg3=NULL;
   743         TAny* arg3=NULL;
   758 
   744 
   759         TFSMailEvent event( TFSMailboxUnavailable );
   745         TFSMailEvent event( TFSMailboxUnavailable );
   760 
   746 
   761         RArray<TFSMailMsgId> array(KEventGranularity);
   747         RArray<TFSMailMsgId> array(KEventGranularity);
   762         CleanupClosePushL( array );
       
   763         FillFSMessageArray(
   748         FillFSMessageArray(
   764             array,
   749             array,
   765             static_cast<const CMsvEntrySelection*>(aArg1),
   750             static_cast<const CMsvEntrySelection*>(aArg1),
   766             tMoved.iMtm.iUid );
   751             tMoved.iMtm.iUid );
   767 
   752 
   801             mbox,
   786             mbox,
   802             arg1,
   787             arg1,
   803             arg2,
   788             arg2,
   804             arg3 );
   789             arg3 );
   805 
   790 
   806         CleanupStack::PopAndDestroy( &array );
   791         array.Close();
   807         // set null to prevent later usage in framework side
   792         // set null to prevent later usage in framework side
   808         // causes kern exec 3 panic...
   793         // causes kern exec 3 panic...
   809         arg1 = arg2 = arg3 = NULL;
   794         arg1 = arg2 = arg3 = NULL;
   810         }
   795         }
   811     }
   796     }
   899 	            }
   884 	            }
   900 
   885 
   901             // message in remote folder (inbox)
   886             // message in remote folder (inbox)
   902             TFSMailMsgId mbox(iPluginId, tEntry.iServiceId );
   887             TFSMailMsgId mbox(iPluginId, tEntry.iServiceId );
   903             RArray<TFSMailMsgId> array( KEventGranularity );
   888             RArray<TFSMailMsgId> array( KEventGranularity );
   904             CleanupClosePushL( array );
       
   905             TFSMailMsgId parentId( iPluginId, tEntry.Id() );
   889             TFSMailMsgId parentId( iPluginId, tEntry.Id() );
       
   890 
   906 
   891 
   907             if ( tEntry.iMtm.iUid == KSenduiMtmImap4UidValue )
   892             if ( tEntry.iMtm.iUid == KSenduiMtmImap4UidValue )
   908                 {
   893                 {
   909                 isFolderId = MatchFolderIdFound( deletedId );
   894                 isFolderId = MatchFolderIdFound( deletedId );
   910                 }
   895                 }
   940                     arg1,
   925                     arg1,
   941                     arg2,
   926                     arg2,
   942                     arg3 );
   927                     arg3 );
   943                 }
   928                 }
   944 
   929 
   945             CleanupStack::PopAndDestroy( &array );
   930             array.Close();
   946             }
   931             }
   947         else if ( tEntry.iMtm.iUid == KSenduiMtmSmtpUidValue )
   932         else if ( tEntry.iMtm.iUid == KSenduiMtmSmtpUidValue )
   948             {
   933             {
   949             // seems that case when deleding from draft, symbian
   934             // seems that case when deleding from draft, symbian
   950             // sends event that contains some child part's id of
   935             // sends event that contains some child part's id of
   983                 // Should be panic at this point?
   968                 // Should be panic at this point?
   984                 return;
   969                 return;
   985                 }
   970                 }
   986 
   971 
   987             RArray<TFSMailMsgId> array(1);
   972             RArray<TFSMailMsgId> array(1);
   988             CleanupClosePushL( array );
       
   989             array.Append( msg );
   973             array.Append( msg );
   990             arg1 = &array;
   974             arg1 = &array;
   991             arg2 = &parent;
   975             arg2 = &parent;
   992             event = TFSEventMailDeleted;
   976             event = TFSEventMailDeleted;
   993             SendDelayedEventL(
   977             SendDelayedEventL(
   994                 event,
   978                 event,
   995                 mbox,
   979                 mbox,
   996                 arg1,
   980                 arg1,
   997                 arg2,
   981                 arg2,
   998                 arg3 );
   982                 arg3 );
   999             CleanupStack::PopAndDestroy( &array );
   983             array.Close();
  1000             }
   984             }
  1001         else
   985         else
  1002             {
   986             {
  1003             //deletion happened under some other service that IPS.
   987             //deletion happened under some other service that IPS.
  1004             return;
   988             return;
  1033         }
  1017         }
  1034 
  1018 
  1035     TFSMailEvent event = static_cast<TFSMailEvent>( KErrNotFound );
  1019     TFSMailEvent event = static_cast<TFSMailEvent>( KErrNotFound );
  1036 
  1020 
  1037     RArray<TFSMailMsgId> array(1);
  1021     RArray<TFSMailMsgId> array(1);
  1038     CleanupClosePushL( array );
       
  1039 
  1022 
  1040     if ( tChanged.iType == KUidMsvMessageEntry )
  1023     if ( tChanged.iType == KUidMsvMessageEntry )
  1041         {
  1024         {
  1042         TMsvEmailEntry emailEntry(tChanged);
  1025         TMsvEmailEntry emailEntry(tChanged);
  1043         if( emailEntry.DeletedIMAP4Flag() /*|| tChanged.Deleted()*/ )
  1026         if( emailEntry.DeletedIMAP4Flag() /*|| tChanged.Deleted()*/ )
  1123             }
  1106             }
  1124 
  1107 
  1125         SendDelayedEventL( event,
  1108         SendDelayedEventL( event,
  1126             mbox, arg1, arg2, arg3 );
  1109             mbox, arg1, arg2, arg3 );
  1127         }
  1110         }
  1128     CleanupStack::PopAndDestroy( &array );
  1111     array.Close();
  1129     // set null to prevent later usage in framework side
  1112     // set null to prevent later usage in framework side
  1130     // causes kern exec 3 panic...
  1113     // causes kern exec 3 panic...
  1131     arg1 = arg2 = arg3 = NULL;
  1114     arg1 = arg2 = arg3 = NULL;
  1132     }
  1115     }
  1133 //<cmail>
  1116 //<cmail>
  1333         {
  1316         {
  1334         iIPSSettingsObservers[find]->SetKeyAndActivateL( aSettingKey, observers );
  1317         iIPSSettingsObservers[find]->SetKeyAndActivateL( aSettingKey, observers );
  1335         }
  1318         }
  1336     else
  1319     else
  1337         {
  1320         {
  1338         CIpsPlgSettingsObserver* obs =
  1321         // <qmail>
       
  1322         // commented out from qmail when extented settings 
       
  1323         // cen rep not exist in environment
       
  1324         /*CIpsPlgSettingsObserver* obs =
  1339             CIpsPlgSettingsObserver::NewL( aAccount, *iCenRep, *this );
  1325             CIpsPlgSettingsObserver::NewL( aAccount, *iCenRep, *this );
  1340         obs->SetKeyAndActivateL( aSettingKey, observers );
  1326         obs->SetKeyAndActivateL( aSettingKey, observers );
  1341         iIPSSettingsObservers.AppendL( obs );
  1327         iIPSSettingsObservers.AppendL( obs );*/
       
  1328         // </qmail>
  1342         }
  1329         }
  1343     observers.Close();
  1330     observers.Close();
  1344     }
  1331     }
  1345 
  1332 
  1346 // ----------------------------------------------------------------------------
  1333 // ----------------------------------------------------------------------------
  1554     FUNC_LOG;
  1541     FUNC_LOG;
  1555     }
  1542     }
  1556 
  1543 
  1557 // ----------------------------------------------------------------------------
  1544 // ----------------------------------------------------------------------------
  1558 // ----------------------------------------------------------------------------
  1545 // ----------------------------------------------------------------------------
  1559 void CIpsPlgEventHandler::SaveSyncStatusL( TMsvId aMailboxId, TInt aState )
  1546 void CIpsPlgEventHandler::SaveSyncStatusL( TMsvId aMailboxId, TInt /*aState*/ )
  1560     {
  1547     {
  1561     FUNC_LOG;
  1548     FUNC_LOG;
  1562     TMsvEntry tEntry;
  1549     TMsvEntry tEntry;
  1563     TMsvId service;
  1550     TMsvId service;
  1564     if( !iSession )
  1551     if( !iSession )
  1567         }
  1554         }
  1568     TInt err = iSession->GetEntry( aMailboxId, service, tEntry );
  1555     TInt err = iSession->GetEntry( aMailboxId, service, tEntry );
  1569 
  1556 
  1570     if( err == KErrNone )
  1557     if( err == KErrNone )
  1571         {
  1558         {
  1572         iSettingsApi->SaveSyncStatusL( tEntry, aState );
       
  1573         }
  1559         }
  1574     }
  1560     }
  1575 
  1561 
  1576 // ----------------------------------------------------------------------------
  1562 // ----------------------------------------------------------------------------
  1577 // ----------------------------------------------------------------------------
  1563 // ----------------------------------------------------------------------------
  1688     return match;
  1674     return match;
  1689     }
  1675     }
  1690 
  1676 
  1691 // ----------------------------------------------------------------------------
  1677 // ----------------------------------------------------------------------------
  1692 // ----------------------------------------------------------------------------
  1678 // ----------------------------------------------------------------------------
  1693 void CIpsPlgEventHandler::CollectSubscribedFoldersL( TMsvId aMailboxId )
  1679 void CIpsPlgEventHandler::CollectSubscribedFoldersL( TMsvId /*aMailboxId*/ )
  1694     {
  1680     {
  1695     FUNC_LOG;
  1681     FUNC_LOG;
  1696     if ( iSession )
  1682     if ( iSession )
  1697         {
  1683         {
  1698         iSettingsApi->GetSubscribedImapFoldersL( aMailboxId, iImapFolderIds );
       
  1699         }
  1684         }
  1700     }
  1685     }
  1701 
  1686 
  1702 // ----------------------------------------------------------------------------
  1687 // ----------------------------------------------------------------------------
  1703 // ----------------------------------------------------------------------------
  1688 // ----------------------------------------------------------------------------