00001 // TXTCPAN.H 00002 // 00003 // © 2004 Nokia Corporation. All rights reserved. 00004 // 00005 00006 // class include 00007 #include "txtfwdop.h" 00008 00009 //system include 00010 #include <txtrich.h> 00011 00012 // user include 00013 #include "txtcpan.h" 00014 00015 CTxtMtmForwardOperation* CTxtMtmForwardOperation::NewL(TMsvId aSourceMessage, TMsvId aDestinationFolder, CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus) 00016 { 00017 CTxtMtmForwardOperation* self = new (ELeave) CTxtMtmForwardOperation(aSourceMessage, aDestinationFolder, aMsvSession, aObserverRequestStatus); 00018 CleanupStack::PushL(self); 00019 self->ConstructL(); 00020 CleanupStack::Pop(self); 00021 return self; 00022 } 00023 00024 CTxtMtmForwardOperation::~CTxtMtmForwardOperation() 00025 { 00026 delete iMsvEntry; 00027 } 00028 00029 const TDesC8& CTxtMtmForwardOperation::ProgressL() 00030 { 00031 if(!IsActive()) 00032 User::Leave(KErrNotReady); 00033 iProgressBuf() = iProgress; 00034 return iProgressBuf; 00035 } 00036 00037 const TDesC8& CTxtMtmForwardOperation::FinalProgress() 00038 { 00039 __ASSERT_ALWAYS(!IsActive(), User::Panic(KTxtCPanic, ETxtcOperationIsActive)); 00040 iProgressBuf() = iProgress; 00041 return iProgressBuf; 00042 } 00043 00044 TInt CTxtMtmForwardOperation::RunError(TInt aError) 00045 { 00046 // Remove an entry if one's been created by this method 00047 if(iProgress.iState > TTxtMtmForwardOpProgress::ECreateMessage) 00048 iMsvSession.RemoveEntry(iProgress.iFinalMsgId); 00049 00050 // Populate the progress structure with the error code 00051 iProgress.iError = aError; 00052 // Complete the requesting active object with the error code 00053 TRequestStatus* stat = &iObserverRequestStatus; 00054 User::RequestComplete(stat, aError); 00055 // Returning anything other than KErrNone from this method results in a panic 00056 return KErrNone; 00057 } 00058 00059 void CTxtMtmForwardOperation::DoCancel() 00060 { 00061 if(iProgress.iState > TTxtMtmForwardOpProgress::ECreateMessage) 00062 iMsvSession.RemoveEntry(iProgress.iFinalMsgId); 00063 00064 TRequestStatus* stat = &iObserverRequestStatus; 00065 User::RequestComplete(stat, KErrCancel); 00066 } 00067 00068 void CTxtMtmForwardOperation::RunL() 00069 { 00070 User::LeaveIfError(iStatus.Int()); 00071 00072 switch(iProgress.iState) 00073 { 00074 case TTxtMtmForwardOpProgress::EInit: 00075 iProgress.iState = TTxtMtmForwardOpProgress::ECreateMessage; 00076 CreateMessageL(); // reschedules the active object 00077 break; 00078 00079 case TTxtMtmForwardOpProgress::ECreateMessage: 00080 iProgress.iState = TTxtMtmForwardOpProgress::EFormatBodyText; 00081 FormatBodyTextL(); // reschedules the active object 00082 break; 00083 00084 case TTxtMtmForwardOpProgress::EFormatBodyText: 00085 iProgress.iState = TTxtMtmForwardOpProgress::EFinished; 00086 00087 default: 00088 break; 00089 } 00090 00091 // When the state machine has been completed, this active object won't 00092 // be scheduled to complete a request 00093 if(!IsActive()) 00094 { 00095 TRequestStatus* stat = &iObserverRequestStatus; 00096 User::RequestComplete(stat, KErrNone); 00097 } 00098 } 00099 00100 void CTxtMtmForwardOperation::CreateMessageL() 00101 { 00102 delete iMsvEntry; 00103 iMsvEntry = NULL; 00104 iMsvEntry = iMsvSession.GetEntryL(iSourceMessage); 00105 00106 // Get the entry to be forwarded 00107 TMsvEntry forwardEntry = iMsvEntry->Entry(); 00108 00109 // Set the context to the destination folder 00110 iMsvEntry->SetEntryL(iDestinationFolder); 00111 00112 // Create the forwarded index entry 00113 forwardEntry.iDate.HomeTime(); 00114 iMsvEntry->CreateL(forwardEntry); 00115 iProgress.iFinalMsgId = forwardEntry.Id(); 00116 00117 // schedules the active object to complete so that this class's RunL method 00118 // will be called by the active scheduler 00119 SetActive(); 00120 TRequestStatus* stat = &iStatus; 00121 User::RequestComplete(stat, KErrNone); 00122 } 00123 00124 void CTxtMtmForwardOperation::FormatBodyTextL() 00125 { 00126 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL(); 00127 CleanupStack::PushL(paraLayer); 00128 CCharFormatLayer* charLayer = CCharFormatLayer::NewL(); 00129 CleanupStack::PushL(charLayer); 00130 CRichText* body = CRichText::NewL(paraLayer, charLayer); 00131 CleanupStack::PushL(body); 00132 00133 // Get the message store from the source entry 00134 iMsvEntry->SetEntryL(iSourceMessage); 00135 CMsvStore* readStore = iMsvEntry->ReadStoreL(); 00136 CleanupStack::PushL(readStore); 00137 00138 // Get the message store from the newly created destination entry 00139 iMsvEntry->SetEntryL(iProgress.iFinalMsgId); 00140 CMsvStore* writeStore = iMsvEntry->EditStoreL(); 00141 CleanupStack::PushL(writeStore); 00142 00143 // Get the body text from the source entry and write it 00144 // to the destination entry, prepending the forward 00145 // prefix 00146 readStore->RestoreBodyTextL(*body); 00147 body->InsertL(0, KTxtMtmFwdPrefix); 00148 00149 // this method performs a commit for us 00150 writeStore->StoreBodyTextL(*body); 00151 00152 CleanupStack::PopAndDestroy(5, paraLayer); 00153 00154 // schedules the active object to complete so that this class's RunL method 00155 // will be called by the active scheduler 00156 SetActive(); 00157 TRequestStatus* stat = &iStatus; 00158 User::RequestComplete(stat, KErrNone); 00159 00160 } 00161 00162 CTxtMtmForwardOperation::CTxtMtmForwardOperation(TMsvId aSourceMessage, TMsvId aDestinationFolder, CMsvSession& aMsvSession, TRequestStatus& aObserverRequestStatus) 00163 : CMsvOperation(aMsvSession, EPriorityStandard, aObserverRequestStatus), 00164 iSourceMessage(aSourceMessage), 00165 iDestinationFolder(aDestinationFolder) 00166 { 00167 CActiveScheduler::Add(this); 00168 } 00169 00170 void CTxtMtmForwardOperation::ConstructL() 00171 { 00172 // set the requesting active object's request status to pending so that 00173 // it doesn't complete 00174 iObserverRequestStatus = KRequestPending; 00175 00176 // schedules the active object to complete so that this class's RunL method 00177 // will be called by the active scheduler 00178 SetActive(); 00179 TRequestStatus* stat = &iStatus; 00180 User::RequestComplete(stat, KErrNone); 00181 00182 // Note that the active object is scheduled here instead of calling CreateMessageL() so that 00183 // leaves are handled in the RunError method 00184 }
Copyright ©2010 Nokia Corporation and/or its subsidiary(-ies).
All rights
reserved. Unless otherwise stated, these materials are provided under the terms of the Eclipse Public License
v1.0.