00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #if !defined(__E32STD_H__)
00017 #include <e32std.h>
00018 #endif
00019
00020 #if !defined(__TXTETEXT_H__)
00021 #include <txtetext.h>
00022 #endif
00023
00024 #if !defined(__TXTRICH_H__)
00025 #include <txtrich.h>
00026 #endif
00027
00028 #if !defined(__APPARC_H__)
00029 #include <apparc.h>
00030 #endif
00031
00032 #if !defined(__MSVUIDS_H__)
00033 #include <msvuids.h>
00034 #endif
00035
00036 #if !defined(__MSVIDS_H__)
00037 #include <msvids.h>
00038 #endif
00039
00040 #include "TXTSERV.H"
00041 #include "TXTSCPMV.H"
00042 #include "TXTSPAN.H"
00043
00044
00045
00046
00047
00048
00049 CTxtActiveOper::CTxtActiveOper(RFs& aFs, CMsvServerEntry& aServerEntry)
00050 : CActive(0), iServerEntry(aServerEntry), iFs(aFs)
00051 {
00052 CActiveScheduler::Add(this);
00053 iFs.Connect();
00054 }
00055
00056 CTxtActiveOper::~CTxtActiveOper()
00057 {
00058 Cancel();
00059 }
00060
00061 void CTxtActiveOper::Start(TMsvId& aSourceId, TMsvId& aDestId, TRequestStatus& aStatus)
00062
00063
00064
00065 {
00066 iSourceId = aSourceId;
00067 iDestId = aDestId;
00068
00069 iStatus = KRequestPending;
00070 iReportStatus = &aStatus;
00071 SetActive();
00072 aStatus = KRequestPending;
00073 TRequestStatus *sP=&iStatus;
00074 User::RequestComplete(sP, KErrNone);
00075 }
00076
00077 void CTxtActiveOper::DoCancel()
00078 {
00079 }
00080
00081
00082 void CTxtActiveOper::RunL()
00083
00084
00085
00086 {
00087 TRAPD(errorCode, DoRunL());
00088
00089
00090
00091 if (errorCode)
00092 {
00093 iCurrentCaller->Progress().iErrorCode = errorCode;
00094 User::RequestComplete(iReportStatus, KErrNone);
00095 }
00096 }
00097
00098
00099
00100
00101
00102
00103 CTxtCopyMoveBase* CTxtCopyMoveBase::NewL(CTxtActiveOper* aActiveOperation, const CMsvEntrySelection& aSource,
00104 CMsvServerEntry& aDestination, TMsvId& aServiceEntryId, TParse& aParse)
00105 {
00106 CTxtCopyMoveBase* self = new (ELeave) CTxtCopyMoveBase(aActiveOperation,aSource,
00107 aDestination, aServiceEntryId, aParse);
00108 CleanupStack::PushL(self);
00109 self->ConstructL();
00110 CleanupStack::Pop();
00111 return self;
00112 }
00113
00114 CTxtCopyMoveBase* CTxtCopyMoveBase::CopyConstructL(const CMsvEntrySelection& aSource)
00115 {
00116 CTxtActiveOper* newActive = iActiveOperation->CopyConstructL();
00117 return NewL(newActive, aSource, iDestination, iServiceEntryId, iServiceDestinationpath);
00118 }
00119
00120 CTxtCopyMoveBase::CTxtCopyMoveBase(CTxtActiveOper* aActiveOperation, const CMsvEntrySelection& aSource,
00121 CMsvServerEntry& aDestination, TMsvId& aServiceEntryId, TParse& aParse)
00122 : CActive( KMsgTxtRefreshMailboxPriority ),
00123 iActiveOperation(aActiveOperation), iSource(aSource), iDestination(aDestination),
00124 iServiceEntryId(aServiceEntryId), iServiceDestinationpath(aParse)
00125 {
00126 }
00127
00128 void CTxtCopyMoveBase::ConstructL()
00129 {
00130 iDestId = iDestination.Entry().Id();
00131 iActiveOperation->SetCurrentCaller(this);
00132 if (iActiveOperation->MoveIsToService())
00133 {
00134 __ASSERT_ALWAYS(iDestination.Entry().iServiceId == iServiceEntryId, gPanic(ETxtsInvalidService));
00135 }
00136 CActiveScheduler::Add(this);
00137 }
00138
00139 CTxtCopyMoveBase::~CTxtCopyMoveBase()
00140 {
00141 Cancel();
00142 delete iActiveOperation;
00143 iActiveOperation = NULL;
00144 }
00145
00146 void CTxtCopyMoveBase::DoCancel()
00147
00148
00149
00150 {
00151 delete iActiveOperation;
00152 iActiveOperation = NULL;
00153 iTxtCopyMoveState = ETxtFinished;
00154 }
00155
00156 void CTxtCopyMoveBase::Start(TRequestStatus& aStatus)
00157
00158
00159
00160 {
00161 iReportStatus = &aStatus;
00162
00163 iMsgCounter = -1;
00164
00165 iProgress.iTotalMsgs=iSource.Count();
00166 iProgress.iMsgsProcessed=0;
00167 iProgress.iErrorCode=KErrNone;
00168
00169 if(iSource.Count())
00170 {
00171 iTxtCopyMoveState=ETxtRetrievingMessage;
00172 }
00173 else
00174 {
00175 iTxtCopyMoveState=ETxtFinished;
00176 }
00177 aStatus = KRequestPending;
00178 SetActive();
00179 TRequestStatus *sP=&iStatus;
00180 User::RequestComplete(sP, KErrNone);
00181 }
00182
00183
00184 void CTxtCopyMoveBase::RunL()
00185 {
00186 TRAPD(errorCode, DoRunL());
00187
00188
00189
00190 if (errorCode)
00191 {
00192 User::RequestComplete(iReportStatus, errorCode);
00193 }
00194 }
00195
00196
00197 void CTxtCopyMoveBase::CheckDeleteSource()
00198
00199 {
00200 if (iMsgCounter>=0)
00201 {
00202 if (iActiveOperation->DeleteSourceAfterwards())
00203 {
00204
00205 iDestination.SetEntry(iSource[iMsgCounter]);
00206 TMsvId parent = iDestination.Entry().Parent();
00207 iDestination.SetEntry(parent);
00208 iDestination.DeleteEntry(iSource[iMsgCounter]);
00209 }
00210 }
00211 }
00212
00213
00214 void CTxtCopyMoveBase::SetupNewEntryL(TMsvId& aSourceMsgId, TMsvId& aNewDestMsvId)
00215
00216 {
00217
00218
00219 iDestination.SetEntry(aSourceMsgId);
00220 TMsvEntry entry;
00221 entry.iServiceId = iDestination.Entry().iServiceId;
00222 entry.iRelatedId = iDestination.Entry().iRelatedId;
00223 entry.iType = iDestination.Entry().iType;
00224 entry.iMtm = iDestination.Entry().iMtm;
00225 entry.iDate = iDestination.Entry().iDate;
00226 entry.iSize = iDestination.Entry().iSize;
00227 entry.iError = iDestination.Entry().iError;
00228
00229 entry.iMtmData1 = iDestination.Entry().iMtmData1;
00230 entry.iMtmData2 = iDestination.Entry().iMtmData2;
00231 entry.iMtmData3 = iDestination.Entry().iMtmData3;
00232
00233 TFileName name=iDestination.Entry().iDescription;
00234 TFileName path=iDestination.Entry().iDetails;
00235 entry.iDescription.Set(name);
00236 entry.iDetails.Set(path);
00237
00238
00239 if (iActiveOperation->MoveIsToService())
00240 {
00241 __ASSERT_DEBUG(name.Length()>0,gPanic(ETxtsInvalidFileName));
00242 __ASSERT_DEBUG(name.Locate(KPathDelimiter)<0,gPanic(ETxtsInvalidFileName));
00243
00244 if (name.Length()==0)
00245 User::Leave(KErrArgument);
00246 if (name.Locate(KPathDelimiter)>=0)
00247 User::Leave(KErrArgument);
00248
00249 entry.iDetails.Set(iServiceDestinationpath.FullName());
00250 entry.iServiceId = iServiceEntryId;
00251 }
00252 else
00253 {
00254 entry.iServiceId = KMsvLocalServiceIndexEntryId;
00255 }
00256
00257
00258 iDestination.SetEntry(iDestId);
00259 iDestination.CreateEntry(entry);
00260
00261 aNewDestMsvId=entry.Id();
00262 iProgress.iNewId = aNewDestMsvId;
00263 }
00264
00265 void CTxtCopyMoveBase::DoRunL()
00266 {
00267
00268 User::LeaveIfError(iStatus.Int());
00269 if (iProgress.iErrorCode != KErrNone)
00270 {
00271 User::RequestComplete(iReportStatus,KErrNone);
00272 return;
00273 }
00274
00275
00276 CheckDeleteSource();
00277
00278 switch (iTxtCopyMoveState)
00279 {
00280 case ETxtRetrievingMessage:
00281
00282 {
00283 iMsgCounter++;
00284
00285
00286 TMsvId newSourceMsgId=iSource[iMsgCounter];
00287 TMsvId newDestMsvId=KMsvNullIndexEntryId;
00288 if (iActiveOperation->CopiedHeader()) SetupNewEntryL(newSourceMsgId,newDestMsvId);
00289
00290 iProgress.iMsgsProcessed++;
00291
00292 if(iMsgCounter == iSource.Count()-1)
00293 {
00294 iTxtCopyMoveState = ETxtFinished;
00295 }
00296
00297 iActiveOperation->Start(newSourceMsgId,newDestMsvId,iStatus);
00298 SetActive();
00299 }
00300 break;
00301 case ETxtFinished:
00302
00303 __ASSERT_DEBUG(iReportStatus != NULL, gPanic(ETxtsStrayRequest));
00304 User::RequestComplete(iReportStatus,KErrNone);
00305 break;
00306 }
00307 }
00308
00309
00310 TTxtProgress& CTxtCopyMoveBase::Progress()
00311
00312
00313
00314 {
00315 return iProgress;
00316 }
00317
00318
00319
00320
00321
00322
00323 void CTxtCopyToLocalOp::DoRunL()
00324
00325
00326
00327
00328 {
00329 User::LeaveIfError(iStatus.Int());
00330
00331 User::LeaveIfError(iServerEntry.SetEntry(iSourceId));
00332 TMsvEntry entry = iServerEntry.Entry();
00333
00334
00335 User::LeaveIfError(iServerEntry.SetEntry( iDestId ));
00336 TxtUtils::GetEntryFileNameL(iFileName, entry);
00337
00338 DoMessageCopyToLocalL();
00339 }
00340
00341 void CTxtCopyToLocalOp::DoMessageCopyToLocalL()
00342
00343 {
00344
00345 CMsvStore* wstore=NULL;
00346 wstore=iServerEntry.EditStoreL();
00347 CleanupStack::PushL(wstore);
00348 User::LeaveIfNull(wstore);
00349
00350
00351 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
00352 CleanupStack::PushL(paraLayer);
00353 CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
00354 CleanupStack::PushL(charLayer);
00355 CRichText* body = CRichText::NewL(paraLayer,charLayer, CEditableText::EFlatStorage, 70 );
00356 CleanupStack::PushL(body);
00357 body->ImportTextFileL(0,iFileName,CPlainText::EOrganiseByLine);
00358
00359
00360 wstore->StoreBodyTextL(*body);
00361 wstore->CommitL();
00362
00363
00364 CleanupStack::PopAndDestroy(4);
00365 TInt err=KErrNone;
00366 if (DeleteSourceAfterwards())
00367 err=iFs.Delete(iFileName);
00368 User::RequestComplete(iReportStatus, err);
00369 }
00370
00371
00372 void CTxtCopyFromLocalOp::DoRunL()
00373
00374
00375
00376
00377 {
00378
00379 User::LeaveIfError(iStatus.Int());
00380
00381
00382 User::LeaveIfError(iServerEntry.SetEntry( iDestId ));
00383 TMsvEntry entry = iServerEntry.Entry();
00384
00385
00386 TxtUtils::GetEntryFileNameL(iFileName, entry);
00387
00388
00389 RFile file;
00390 if (file.Open(iFs,iFileName,EFileRead) == KErrNone)
00391 {
00392 file.Close();
00393
00394 User::LeaveIfError(CApaApplication::GenerateFileName(iFs,iFileName));
00395 TParse newName;
00396 newName.Set(iFileName,NULL,NULL);
00397 entry.iDescription.Set(newName.NameAndExt());
00398 User::LeaveIfError(iServerEntry.ChangeEntry(entry));
00399 }
00400
00401
00402 User::LeaveIfError(iServerEntry.SetEntry( iSourceId ));
00403
00404 DoMessageCopyFromLocalL(entry);
00405 }
00406
00407
00408 void CTxtCopyFromLocalOp::DoMessageCopyFromLocalL(const TMsvEntry& aEntry)
00409
00410 {
00411 CMsvStore* rstore=iServerEntry.ReadStoreL();
00412 CleanupStack::PushL(rstore);
00413
00414 if (rstore->HasBodyTextL())
00415 {
00416
00417 CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
00418 CleanupStack::PushL(paraLayer);
00419 CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
00420 CleanupStack::PushL(charLayer);
00421 CRichText* body = CRichText::NewL(paraLayer,charLayer, CEditableText::EFlatStorage, 70);
00422 CleanupStack::PushL(body);
00423 rstore->RestoreBodyTextL(*body);
00424
00425 body->ExportAsTextL(iFileName,CPlainText::EOrganiseByLine,70);
00426
00427
00428 RFile outFile;
00429 if (outFile.Open(iFs, iFileName, EFileWrite) == KErrNone)
00430 {
00431 outFile.SetModified(aEntry.iDate);
00432 outFile.Close();
00433 }
00434 CleanupStack::PopAndDestroy(3);
00435 }
00436
00437 CleanupStack::PopAndDestroy();
00438
00439 User::RequestComplete(iReportStatus, KErrNone);
00440 }
00441
00442
00443 void CTxtCopyWithinServiceOp::DoRunL()
00444
00445
00446
00447 {
00448 TInt err=KErrNone;
00449 User::LeaveIfError(iStatus.Int());
00450
00451 User::LeaveIfError(iServerEntry.SetEntry(iSourceId));
00452 TMsvEntry sourceEntry = iServerEntry.Entry();
00453
00454
00455 TFileName sourceFileName;
00456 TxtUtils::GetEntryFileNameL(sourceFileName, sourceEntry);
00457 iFileName = sourceFileName;
00458
00459
00460 err = iServerEntry.SetEntry(iDestId);
00461 if (err)
00462 {
00463 User::RequestComplete(iReportStatus, err);
00464 return;
00465 }
00466
00467 DoMessageCopyWithinServiceL();
00468 }
00469
00470
00471 void CTxtCopyWithinServiceOp::DoMessageCopyWithinServiceL()
00472
00473 {
00474 TMsvEntry destEntry = iServerEntry.Entry();
00475 TFileName destFileName;
00476 TxtUtils::GetEntryFileNameL(destFileName, destEntry);
00477
00478 iFs.MkDir(destFileName);
00479
00480 RFile outFile;
00481
00482 if (outFile.Open(iFs, destFileName, EFileRead) == KErrNone)
00483 {
00484 outFile.Close();
00485 User::RequestComplete(iReportStatus, KErrAlreadyExists);
00486 return;
00487 }
00488
00489 TInt err = outFile.Create(iFs, destFileName, EFileWrite);
00490 if (err)
00491 {
00492 User::RequestComplete(iReportStatus, err);
00493 return;
00494 }
00495
00496 RFile inFile;
00497 err = inFile.Open(iFs, iFileName, EFileRead);
00498 if (err)
00499 {
00500 inFile.Close();
00501 User::RequestComplete(iReportStatus, err);
00502 return;
00503 }
00504
00505
00506 TFileText inTextFile;
00507 TFileText outTextFile;
00508 inTextFile.Set(inFile);
00509 outTextFile.Set(outFile);
00510 TBuf<201> buf;
00511 TInt len = 200;
00512 while (len>0)
00513 {
00514 buf.FillZ();
00515 inTextFile.Read(buf);
00516 len=buf.Length();
00517 outTextFile.Write(buf);
00518 }
00519
00520 outFile.SetModified(destEntry.iDate);
00521
00522
00523 inFile. Close();
00524 outFile.Close();
00525 if (DeleteSourceAfterwards())
00526 err=iFs.Delete(iFileName);
00527 User::RequestComplete(iReportStatus, KErrNone);
00528 }
00529
00530
00531 void CTxtDeleteOp::DoRunL()
00532
00533
00534
00535 {
00536 TInt err=KErrNone;
00537 User::LeaveIfError(iStatus.Int());
00538
00539 User::LeaveIfError(iServerEntry.SetEntry(iSourceId));
00540 TMsvEntry entry = iServerEntry.Entry();
00541 TxtUtils::GetEntryFileNameL(iFileName, entry);
00542
00543 err=iFs.Delete(iFileName);
00544 User::RequestComplete(iReportStatus, err);
00545 }
00546
00547
00548
00549
00550
00551
00552
00553
00554
00555 CTxtActiveOper* CTxtCopyToLocalOp::CopyConstructL()
00556 {
00557 return new (ELeave) CTxtCopyToLocalOp(iFs, iServerEntry);
00558 }
00559
00560 TBool CTxtCopyToLocalOp::CopiedHeader() const
00561 {
00562 return ETrue;
00563 }
00564 TBool CTxtCopyToLocalOp::DeleteSourceAfterwards() const
00565 {
00566 return EFalse;
00567 }
00568
00569 TBool CTxtCopyToLocalOp::MoveIsToService() const
00570 {
00571 return EFalse;
00572 }
00573
00574
00575
00576 CTxtActiveOper* CTxtCopyFromLocalOp::CopyConstructL()
00577 {
00578 return new (ELeave) CTxtCopyFromLocalOp(iFs, iServerEntry);
00579 }
00580
00581 TBool CTxtCopyFromLocalOp::CopiedHeader() const
00582 {
00583 return ETrue;
00584 }
00585
00586 TBool CTxtCopyFromLocalOp::DeleteSourceAfterwards() const
00587 {
00588 return EFalse;
00589 }
00590
00591 TBool CTxtCopyFromLocalOp::MoveIsToService() const
00592 {
00593 return ETrue;
00594 }
00595
00596
00597
00598 CTxtActiveOper* CTxtCopyWithinServiceOp::CopyConstructL()
00599 {
00600 return new (ELeave) CTxtCopyWithinServiceOp(iFs, iServerEntry);
00601 }
00602
00603 TBool CTxtCopyWithinServiceOp::CopiedHeader() const
00604 {
00605 return ETrue;
00606 }
00607
00608 TBool CTxtCopyWithinServiceOp::DeleteSourceAfterwards() const
00609 {
00610 return EFalse;
00611 }
00612
00613 TBool CTxtCopyWithinServiceOp::MoveIsToService() const
00614 {
00615 return ETrue;
00616 }
00617
00618
00619
00620 CTxtActiveOper* CTxtMoveToLocalOp::CopyConstructL()
00621 {
00622 return new (ELeave) CTxtMoveToLocalOp(iFs, iServerEntry);
00623 }
00624
00625 TBool CTxtMoveToLocalOp::DeleteSourceAfterwards() const
00626 {
00627 return ETrue;
00628 }
00629
00630
00631
00632 CTxtActiveOper* CTxtMoveFromLocalOp::CopyConstructL()
00633 {
00634 return new (ELeave) CTxtMoveFromLocalOp(iFs, iServerEntry);
00635 }
00636
00637 TBool CTxtMoveFromLocalOp::DeleteSourceAfterwards() const
00638 {
00639 return ETrue;
00640 }
00641
00642
00643
00644 CTxtActiveOper* CTxtMoveWithinServiceOp::CopyConstructL()
00645 {
00646 return new (ELeave) CTxtMoveWithinServiceOp(iFs, iServerEntry);
00647 }
00648
00649 TBool CTxtMoveWithinServiceOp::DeleteSourceAfterwards() const
00650 {
00651 return ETrue;
00652 }
00653
00654
00655
00656 CTxtActiveOper* CTxtDeleteOp::CopyConstructL()
00657 {
00658 return new (ELeave) CTxtDeleteOp(iFs, iServerEntry);
00659 }
00660
00661 TBool CTxtDeleteOp::CopiedHeader() const
00662 {
00663 return EFalse;
00664 }
00665
00666 TBool CTxtDeleteOp::DeleteSourceAfterwards() const
00667 {
00668 return ETrue;
00669 }
00670
00671 TBool CTxtDeleteOp::MoveIsToService() const
00672 {
00673 return EFalse;
00674 }
00675
00676