📄 txtscpmv.cpp
字号:
CMsvStore* wstore=NULL;
wstore=iServerEntry.EditStoreL();
CleanupStack::PushL(wstore);
User::LeaveIfNull(wstore);
// Read file text into rich text object
CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
CleanupStack::PushL(paraLayer);
CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
CleanupStack::PushL(charLayer);
CRichText* body = CRichText::NewL(paraLayer,charLayer, CEditableText::EFlatStorage, 70 );
CleanupStack::PushL(body);
body->ImportTextFileL(0,iFileName,CPlainText::EOrganiseByLine);
// Store in body
wstore->StoreBodyTextL(*body);
wstore->CommitL();
// Clean up
CleanupStack::PopAndDestroy(4); //body, charLayer, paraLayer, wstore
TInt err=KErrNone;
if (DeleteSourceAfterwards())
err=iFs.Delete(iFileName);
User::RequestComplete(iReportStatus, err);
}
void CTxtCopyFromLocalOp::DoRunL()
//
// Copy entries from local to remote, storing the plain text contents of
// the associated rich text in a newly created file.
//
{
// Error on previous stages
User::LeaveIfError(iStatus.Int());
// Get details of destination entry
User::LeaveIfError(iServerEntry.SetEntry( iDestId ));
TMsvEntry entry = iServerEntry.Entry();
// Find file from entry details
TxtUtils::GetEntryFileNameL(iFileName, entry);
// Check if file already exists.
RFile file;
if (file.Open(iFs,iFileName,EFileRead) == KErrNone)
{
file.Close();
// If so, create a new unique filename and update entry
User::LeaveIfError(CApaApplication::GenerateFileName(iFs,iFileName));
TParse newName;
newName.Set(iFileName,NULL,NULL);
entry.iDescription.Set(newName.NameAndExt());
User::LeaveIfError(iServerEntry.ChangeEntry(entry));
}
// Set the context back
User::LeaveIfError(iServerEntry.SetEntry( iSourceId ));
DoMessageCopyFromLocalL(entry);
}
void CTxtCopyFromLocalOp::DoMessageCopyFromLocalL(const TMsvEntry& aEntry)
// Copy local message to remote service: i.e. create a file
{
CMsvStore* rstore=iServerEntry.ReadStoreL();
CleanupStack::PushL(rstore);
if (rstore->HasBodyTextL())
{
// Get message text and write it to file
CParaFormatLayer* paraLayer = CParaFormatLayer::NewL();
CleanupStack::PushL(paraLayer);
CCharFormatLayer* charLayer = CCharFormatLayer::NewL();
CleanupStack::PushL(charLayer);
CRichText* body = CRichText::NewL(paraLayer,charLayer, CEditableText::EFlatStorage, 70);
CleanupStack::PushL(body);
rstore->RestoreBodyTextL(*body);
//User::LeaveIfError(iFs.MkDir(iFileName));
body->ExportAsTextL(iFileName,CPlainText::EOrganiseByLine,70);
// Change date modified to reflect what's in the TMsvEntry
RFile outFile;
if (outFile.Open(iFs, iFileName, EFileWrite) == KErrNone)
{
outFile.SetModified(aEntry.iDate);
outFile.Close();
}
CleanupStack::PopAndDestroy(3); //paraLayer, charLayer, body
}
CleanupStack::PopAndDestroy(); //rstore
User::RequestComplete(iReportStatus, KErrNone);
}
void CTxtCopyWithinServiceOp::DoRunL()
//
// Copy files over within the service.
//
{
TInt err=KErrNone;
User::LeaveIfError(iStatus.Int());
User::LeaveIfError(iServerEntry.SetEntry(iSourceId));
TMsvEntry sourceEntry = iServerEntry.Entry();
// Source settings
TFileName sourceFileName;
TxtUtils::GetEntryFileNameL(sourceFileName, sourceEntry);
iFileName = sourceFileName;
// Destination settings
err = iServerEntry.SetEntry(iDestId);
if (err)
{
User::RequestComplete(iReportStatus, err);
return;
}
DoMessageCopyWithinServiceL();
}
void CTxtCopyWithinServiceOp::DoMessageCopyWithinServiceL()
// Copy remote message to local: i.e. read file contents into message store
{
TMsvEntry destEntry = iServerEntry.Entry();
TFileName destFileName;
TxtUtils::GetEntryFileNameL(destFileName, destEntry);
iFs.MkDir(destFileName);
RFile outFile;
// Test if destination file already exists
if (outFile.Open(iFs, destFileName, EFileRead) == KErrNone)
{
outFile.Close();
User::RequestComplete(iReportStatus, KErrAlreadyExists);
return;
}
// Create destination file
TInt err = outFile.Create(iFs, destFileName, EFileWrite);
if (err)
{
User::RequestComplete(iReportStatus, err);
return;
}
// Open input file
RFile inFile;
err = inFile.Open(iFs, iFileName, EFileRead);
if (err)
{
inFile.Close();
User::RequestComplete(iReportStatus, err);
return;
}
// Copy the file over
TFileText inTextFile;
TFileText outTextFile;
inTextFile.Set(inFile);
outTextFile.Set(outFile);
TBuf<201> buf;
TInt len = 200;
while (len>0)
{
buf.FillZ();
inTextFile.Read(buf);
len=buf.Length();
outTextFile.Write(buf);
}
// Change date modified to reflect what's in the TMsvEntry
outFile.SetModified(destEntry.iDate);
// Clean up
inFile. Close();
outFile.Close();
if (DeleteSourceAfterwards())
err=iFs.Delete(iFileName);
User::RequestComplete(iReportStatus, KErrNone);
}
void CTxtDeleteOp::DoRunL()
//
// Deleting files.
//
{
TInt err=KErrNone;
User::LeaveIfError(iStatus.Int());
//
User::LeaveIfError(iServerEntry.SetEntry(iSourceId));
TMsvEntry entry = iServerEntry.Entry();
TxtUtils::GetEntryFileNameL(iFileName, entry);
err=iFs.Delete(iFileName);
User::RequestComplete(iReportStatus, err);
}
//
// These CopyConstructL methods allow other classes to get an exact copy
// of the class derived from CTxtActiveOper. Needed to recursively perform an
// operation on a set of entries.
//
// CTxtCopyToLocalOp
CTxtActiveOper* CTxtCopyToLocalOp::CopyConstructL()
{
return new (ELeave) CTxtCopyToLocalOp(iFs, iServerEntry);
}
TBool CTxtCopyToLocalOp::CopiedHeader() const
{
return ETrue;
}
TBool CTxtCopyToLocalOp::DeleteSourceAfterwards() const
{
return EFalse;
}
TBool CTxtCopyToLocalOp::MoveIsToService() const
{
return EFalse;
}
// CTxtCopyFromLocalOp
CTxtActiveOper* CTxtCopyFromLocalOp::CopyConstructL()
{
return new (ELeave) CTxtCopyFromLocalOp(iFs, iServerEntry);
}
TBool CTxtCopyFromLocalOp::CopiedHeader() const
{
return ETrue;
}
TBool CTxtCopyFromLocalOp::DeleteSourceAfterwards() const
{
return EFalse;
}
TBool CTxtCopyFromLocalOp::MoveIsToService() const
{
return ETrue;
}
// CTxtCopyWithinServiceOp
CTxtActiveOper* CTxtCopyWithinServiceOp::CopyConstructL()
{
return new (ELeave) CTxtCopyWithinServiceOp(iFs, iServerEntry);
}
TBool CTxtCopyWithinServiceOp::CopiedHeader() const
{
return ETrue;
}
TBool CTxtCopyWithinServiceOp::DeleteSourceAfterwards() const
{
return EFalse;
}
TBool CTxtCopyWithinServiceOp::MoveIsToService() const
{
return ETrue;
}
// CTxtMoveToLocalOp
CTxtActiveOper* CTxtMoveToLocalOp::CopyConstructL()
{
return new (ELeave) CTxtMoveToLocalOp(iFs, iServerEntry);
}
TBool CTxtMoveToLocalOp::DeleteSourceAfterwards() const
{
return ETrue;
}
// CTxtMoveFromLocalOp
CTxtActiveOper* CTxtMoveFromLocalOp::CopyConstructL()
{
return new (ELeave) CTxtMoveFromLocalOp(iFs, iServerEntry);
}
TBool CTxtMoveFromLocalOp::DeleteSourceAfterwards() const
{
return ETrue;
}
// CTxtMoveWithinServiceOp
CTxtActiveOper* CTxtMoveWithinServiceOp::CopyConstructL()
{
return new (ELeave) CTxtMoveWithinServiceOp(iFs, iServerEntry);
}
TBool CTxtMoveWithinServiceOp::DeleteSourceAfterwards() const
{
return ETrue;
}
// CTxtDeleteOp
CTxtActiveOper* CTxtDeleteOp::CopyConstructL()
{
return new (ELeave) CTxtDeleteOp(iFs, iServerEntry);
}
TBool CTxtDeleteOp::CopiedHeader() const
{
return EFalse;
}
TBool CTxtDeleteOp::DeleteSourceAfterwards() const
{
return ETrue;
}
TBool CTxtDeleteOp::MoveIsToService() const
{
return EFalse;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -