00001
00002
00003
00004
00005
00006
00007 #include "txtfwdop.h"
00008
00009
00010 #include <txtrich.h>
00011
00012
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
00047 if(iProgress.iState > TTxtMtmForwardOpProgress::ECreateMessage)
00048 iMsvSession.RemoveEntry(iProgress.iFinalMsgId);
00049
00050
00051 iProgress.iError = aError;
00052
00053 TRequestStatus* stat = &iObserverRequestStatus;
00054 User::RequestComplete(stat, aError);
00055
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();
00077 break;
00078
00079 case TTxtMtmForwardOpProgress::ECreateMessage:
00080 iProgress.iState = TTxtMtmForwardOpProgress::EFormatBodyText;
00081 FormatBodyTextL();
00082 break;
00083
00084 case TTxtMtmForwardOpProgress::EFormatBodyText:
00085 iProgress.iState = TTxtMtmForwardOpProgress::EFinished;
00086
00087 default:
00088 break;
00089 }
00090
00091
00092
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
00107 TMsvEntry forwardEntry = iMsvEntry->Entry();
00108
00109
00110 iMsvEntry->SetEntryL(iDestinationFolder);
00111
00112
00113 forwardEntry.iDate.HomeTime();
00114 iMsvEntry->CreateL(forwardEntry);
00115 iProgress.iFinalMsgId = forwardEntry.Id();
00116
00117
00118
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
00134 iMsvEntry->SetEntryL(iSourceMessage);
00135 CMsvStore* readStore = iMsvEntry->ReadStoreL();
00136 CleanupStack::PushL(readStore);
00137
00138
00139 iMsvEntry->SetEntryL(iProgress.iFinalMsgId);
00140 CMsvStore* writeStore = iMsvEntry->EditStoreL();
00141 CleanupStack::PushL(writeStore);
00142
00143
00144
00145
00146 readStore->RestoreBodyTextL(*body);
00147 body->InsertL(0, KTxtMtmFwdPrefix);
00148
00149
00150 writeStore->StoreBodyTextL(*body);
00151
00152 CleanupStack::PopAndDestroy(5, paraLayer);
00153
00154
00155
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
00173
00174 iObserverRequestStatus = KRequestPending;
00175
00176
00177
00178 SetActive();
00179 TRequestStatus* stat = &iStatus;
00180 User::RequestComplete(stat, KErrNone);
00181
00182
00183
00184 }