messagingapp/msgappfw/plugin/src/ccsmsghandler.cpp
changeset 25 84d9eb65b26f
parent 23 238255e8b033
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
    30 #include <txtrich.h>
    30 #include <txtrich.h>
    31 #include <msvids.h>
    31 #include <msvids.h>
    32 #include <e32const.h>
    32 #include <e32const.h>
    33 #include <SendUiConsts.h>
    33 #include <SendUiConsts.h>
    34 #include <pushentry.h> // For services messages
    34 #include <pushentry.h> // For services messages
    35 
    35 #include <e32cmn.h>
    36 // NOTE:- DRAFTS AND OUTBOX ENTRIES ARE NOT HANDLED IN THE PLUGIN
    36 
       
    37 
       
    38 //CONSTANTS
       
    39 const TInt KMessageArrayGranularity = 50;
       
    40 
       
    41 // NOTE:- DRAFT ENTRIES ARE NOT HANDLED IN THE PLUGIN
    37 
    42 
    38 // ============================== MEMBER FUNCTIONS ============================
    43 // ============================== MEMBER FUNCTIONS ============================
    39 // ----------------------------------------------------------------------------
    44 // ----------------------------------------------------------------------------
    40 // CCsMsgHandler::NewL
    45 // CCsMsgHandler::NewL
    41 // Two Phase Construction
    46 // Two Phase Construction
   112         {
   117         {
   113 	    iMessages->Reset();
   118 	    iMessages->Reset();
   114         delete iMessages;
   119         delete iMessages;
   115         iMessages = NULL;
   120         iMessages = NULL;
   116         }
   121         }
       
   122     
       
   123     if(iMessageArray)
       
   124     {
       
   125         iMessageArray->Reset();
       
   126         iMessageArray->Close();
       
   127         delete iMessageArray;
       
   128         iMessageArray = NULL;
       
   129     }
   117 
   130 
   118     PRINT ( _L("End CCsMsgHandler::~CCsMsgHandler") );
   131     PRINT ( _L("End CCsMsgHandler::~CCsMsgHandler") );
   119     }
   132     }
   120 
   133 
   121 // ----------------------------------------------------------------------------
   134 // ----------------------------------------------------------------------------
   142 
   155 
   143     iMmsMtm = static_cast<CMmsClientMtm*>( iMtmRegistry->
   156     iMmsMtm = static_cast<CMmsClientMtm*>( iMtmRegistry->
   144             NewMtmL( KSenduiMtmMmsUid ) );
   157             NewMtmL( KSenduiMtmMmsUid ) );
   145 
   158 
   146     iState = EReadInbox;
   159     iState = EReadInbox;
       
   160 
       
   161     iMessageArray = new (ELeave)RArray <TMsvId>(KMessageArrayGranularity);
   147 
   162 
   148     iMessageCount = 0;
   163     iMessageCount = 0;
   149 
   164 
   150     PRINT ( _L("End CCsMsgHandler::ConstructL") );
   165     PRINT ( _L("End CCsMsgHandler::ConstructL") );
   151     }
   166     }
   552         {
   567         {
   553         // Unknown
   568         // Unknown
   554         ProcessEntryL(aEvent, KNullDesC, description, aEntry);       
   569         ProcessEntryL(aEvent, KNullDesC, description, aEntry);       
   555         }
   570         }
   556 
   571 
   557     if ( tmpBuffer )
   572     delete tmpBuffer;
   558         {
       
   559         delete tmpBuffer;
       
   560         }
       
   561 
   573 
   562     PRINT ( _L("Exit CCsMsgHandler::ExtractAddressesL") );
   574     PRINT ( _L("Exit CCsMsgHandler::ExtractAddressesL") );
   563     }
   575     }
   564 
   576 
       
   577 // -----------------------------------------------------------------------------
       
   578 // CCsMsgHandler::CompareOrder()
       
   579 // Method for determining the sorting behaviour of RArray of TMsvId's  
       
   580 // -----------------------------------------------------------------------------
       
   581 //
       
   582 static TInt CompareOrder(const TMsvId& aFirst, const TMsvId& aSecond)
       
   583     {
       
   584     return aSecond - aFirst;
       
   585     }
   565 // -----------------------------------------------------------------------------
   586 // -----------------------------------------------------------------------------
   566 // CCsMsgHandler::UploadMsgL()
   587 // CCsMsgHandler::UploadMsgL()
   567 // State machine to upload all messages 
   588 // State machine to upload all messages 
   568 // -----------------------------------------------------------------------------
   589 // -----------------------------------------------------------------------------
   569 //
   590 //
   570 TInt CCsMsgHandler::UploadMsgL() 
   591 TInt CCsMsgHandler::UploadMsgL() 
   571     {
   592 {
   572     switch ( iState ) 
   593     switch ( iState ) 
   573         {
   594     {
   574         case EReadInbox:
   595         case EReadInbox:
   575             {
   596         {
   576             iRootEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
   597             iRootEntry = iSession->GetEntryL(KMsvGlobalInBoxIndexEntryId);
   577 
   598 
   578             // Set sort order
   599             // Set sort order
   579             TMsvSelectionOrdering order;
   600             TMsvSelectionOrdering order;
   580             order.SetSorting(EMsvSortById);
   601             order.SetSorting(EMsvSortById);
   581             iRootEntry->SetSortTypeL(order);
   602             iRootEntry->SetSortTypeL(order);
   582 
   603 
   583             iMessages = iRootEntry->ChildrenL();	
   604             iMessages = iRootEntry->ChildrenL();
   584             iMessageCount = iRootEntry->Count();
   605             iMessageCount = iRootEntry->Count();
   585 
   606             if(iMessageCount)
   586             if ( iMessageCount ) 
   607             {
   587                 iState = EProcessInbox;
   608                 for(int i = 0; i < iMessageCount; i ++)
   588             else
   609                 {
   589                 {
   610                     iMessageArray->Append(iMessages->At(i));
   590                 iState = EReadSent;
   611                 }
   591                 CleanupL();
   612             }
   592                 }
   613 
       
   614             iState = EReadSent;
       
   615             CleanupL();              
   593 
   616 
   594             return 1;
   617             return 1;
   595             }
   618         }
   596 
       
   597         case EProcessInbox:
       
   598             {
       
   599             iMessageCount = iMessageCount - 1;
       
   600             TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount));
       
   601             if(IsMtmSupported(entry.iMtm.iUid))
       
   602                 {
       
   603                 ProcessResultsL(entry);  
       
   604                 }
       
   605 
       
   606             if ( iMessageCount ) 
       
   607                 iState = EProcessInbox;
       
   608             else 
       
   609                 {
       
   610                 iState = EReadSent;
       
   611                 CleanupL();
       
   612                 }
       
   613 
       
   614             return 1;
       
   615             }
       
   616 
   619 
   617         case EReadSent:
   620         case EReadSent:
   618             {
   621         {
   619             iRootEntry = iSession->GetEntryL(KMsvSentEntryId);
   622             iRootEntry = iSession->GetEntryL(KMsvSentEntryId);
   620 
   623 
   621             // Set sort order
   624             // Set sort order
   622             TMsvSelectionOrdering order;
   625             TMsvSelectionOrdering order;
   623             order.SetSorting(EMsvSortById);
   626             order.SetSorting(EMsvSortById);
   624             iRootEntry->SetSortTypeL(order);
   627             iRootEntry->SetSortTypeL(order);
   625 
   628 
   626             iMessages = iRootEntry->ChildrenL();    
   629             iMessages = iRootEntry->ChildrenL();    
   627             iMessageCount = iRootEntry->Count();
   630             iMessageCount = iRootEntry->Count();
   628 
   631             if(iMessageCount)
   629             if ( iMessageCount ) 
   632             {
   630                 iState = EProcessSent;
   633                 for(int i = 0; i < iMessageCount; i++ )
   631             else
   634                 {
   632                 {
   635                     iMessageArray->Append(iMessages->At(i));
   633                 iState = EReadOutbox;
   636                 }
   634                 CleanupL();
   637             }
   635                 }
   638 
       
   639             iState = EReadOutbox;
       
   640             CleanupL();
   636 
   641 
   637             return 1;
   642             return 1;
   638             }
   643         }
   639 
   644 
   640         case EProcessSent:
       
   641             {
       
   642             iMessageCount = iMessageCount - 1;
       
   643             TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount));
       
   644             if(IsMtmSupported(entry.iMtm.iUid))
       
   645                 {
       
   646                 ProcessResultsL(entry);  
       
   647                 }
       
   648 
       
   649             if ( iMessageCount ) 
       
   650                 iState = EProcessSent;
       
   651             else 
       
   652                 {
       
   653                 iState = EReadOutbox;
       
   654                 CleanupL();
       
   655                 }
       
   656 
       
   657             return 1;        
       
   658             }
       
   659             
       
   660         case EReadOutbox:
   645         case EReadOutbox:
   661             {
   646         {
   662             iRootEntry = iSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
   647             iRootEntry = iSession->GetEntryL(KMsvGlobalOutBoxIndexEntryId);
   663             
   648 
   664             // Set sort order
   649             // Set sort order
   665             TMsvSelectionOrdering order;
   650             TMsvSelectionOrdering order;
   666             order.SetSorting(EMsvSortById);
   651             order.SetSorting(EMsvSortById);
   667             iRootEntry->SetSortTypeL(order);
   652             iRootEntry->SetSortTypeL(order);
   668             
   653 
   669             iMessages = iRootEntry->ChildrenL();    
   654             iMessages = iRootEntry->ChildrenL();  
   670             iMessageCount = iRootEntry->Count();
   655             iMessageCount = iRootEntry->Count();
   671             
   656 
   672             if ( iMessageCount ) 
   657             if(iMessageCount)
   673                 iState = EProcessOutbox;
   658             {
       
   659                 for(int i = 0; i < iMessageCount; i ++)
       
   660                 {
       
   661                     iMessageArray->Append(iMessages->At(i));
       
   662                 }
       
   663                 iMessageCount=0;
       
   664             }
       
   665             iState = ESortEntries;
       
   666             CleanupL();
       
   667 
       
   668             return 1;
       
   669         }
       
   670         case ESortEntries:
       
   671         {
       
   672              //Sort the elements in the array by descending order of TMsvId's
       
   673             TLinearOrder<TMsvId> order(CompareOrder);
       
   674             iMessageArray->Sort(order);
       
   675             iState = EProcessEntries;
       
   676             return 1;
       
   677         }
       
   678         
       
   679         case EProcessEntries:
       
   680         { 
       
   681             //Process one entry at a time in sequence
       
   682             //Process the first element in the array on each call, till the end
       
   683             if(iMessageArray->Count())
       
   684             {
       
   685                 ProcessResultsL(iSession->GetEntryL(iMessageArray->operator[](0))->Entry());
       
   686                 iMessageArray->Remove(0);
       
   687             }
   674             else
   688             else
   675                 {
   689             {
   676                 iState = EComplete;
       
   677                 iMsgObserver->HandleCachingCompleted();
   690                 iMsgObserver->HandleCachingCompleted();
   678                 CleanupL();
   691                 return 0; //DONE 
   679                 return 0; // DONE
   692             }
   680                 }
   693 
   681             
   694             iState = EProcessEntries;
   682             return 1;
   695             return 1; 
   683             }
   696         }
   684             
   697     }
   685         case EProcessOutbox:
   698     return 0;    
   686             {
   699 }
   687             iMessageCount = iMessageCount - 1;
       
   688             TMsvEntry entry = iRootEntry->ChildDataL(iMessages->At(iMessageCount));
       
   689             if(IsMtmSupported(entry.iMtm.iUid))
       
   690                 {
       
   691                 ProcessResultsL(entry);  
       
   692                 }
       
   693             
       
   694             if ( iMessageCount ) 
       
   695                 iState = EProcessOutbox;
       
   696             else 
       
   697                 {
       
   698                 iState = EComplete;
       
   699                 iMsgObserver->HandleCachingCompleted();
       
   700                 CleanupL();
       
   701                 return 0; // DONE
       
   702                 }
       
   703             
       
   704             return 1;        
       
   705             }
       
   706         }
       
   707 
       
   708     return 0;
       
   709     }
       
   710 
   700 
   711 // -----------------------------------------------------------------------------
   701 // -----------------------------------------------------------------------------
   712 // CCsMsgHandler::UploadMsg()
   702 // CCsMsgHandler::UploadMsg()
   713 // CIdle callback 
   703 // CIdle callback 
   714 // -----------------------------------------------------------------------------
   704 // -----------------------------------------------------------------------------
   790     TCsType type = ECsUnknown;
   780     TCsType type = ECsUnknown;
   791     switch(aEntry.iMtm.iUid)
   781     switch(aEntry.iMtm.iUid)
   792         {
   782         {
   793         case KSenduiMtmSmsUidValue:            
   783         case KSenduiMtmSmsUidValue:            
   794             type = ECsSMS;
   784             type = ECsSMS;
       
   785             if (aEntry.iBioType == KMsgBioUidVCard.iUid)
       
   786                 {
       
   787                 type = ECsBioMsg_VCard;
       
   788                 }
   795             break;
   789             break;
   796         case KSenduiMtmBtUidValue:
   790         case KSenduiMtmBtUidValue:
   797             type = ECsBlueTooth;
   791             type = ECsBlueTooth;
   798             break;
   792             break;
   799         case KSenduiMtmMmsUidValue:        
   793         case KSenduiMtmMmsUidValue: