📄 ftpexamplecontainer.cpp
字号:
if (DoQueryL(KRenameNewCmd, newFileName))
{
AddCarriageReturnL();
iAppUi.Model().RenameFileL(fileName, newFileName);
iAppUi.CommandExecutingL(ETrue);
}
}
}
// ----------------------------------------------------
// CFtpExampleContainer::DeleteL()
// Deletes a file on the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::DeleteL()
{
TBuf<KQueryMaxLength> file;
if (DoQueryL(KDeleteCommand, file))
{
AddCarriageReturnL();
iAppUi.Model().DeleteFileL(file);
iAppUi.CommandExecutingL(ETrue);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::Complete()
// Called when an FTP command is completed.
// ----------------------------------------------------
//
void CFtpExampleContainer::Complete()
{
switch (iAction)
{
case EConnecting:
SetConnected(ETrue);
break;
case EDir:
TRAPD(error, SetTextL(iDirBuffer))
if (error != KErrNone)
{
Panic(error);
}
break;
case ENoAction:
break;
}
iAction = ENoAction;
TRAPD(err, iAppUi.CommandExecutingL(EFalse));
if (err != KErrNone)
{
Panic(err);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::MoreData()
// Called when an FTP command is only partially
// completed and more data is to follow.
// ----------------------------------------------------
//
void CFtpExampleContainer::MoreData()
{
TRAPD( error,
SetTextL(iDirBuffer);
iDirBuffer.SetLength(0);
iAppUi.Model().ListDirectoryL(KCurrentDirectory, iDirBuffer));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::TransferProgress()
// Reports the amount of data already transferred in bytes.
// ----------------------------------------------------
//
void CFtpExampleContainer::TransferProgress(TUint /*aProgress*/)
{
}
// ----------------------------------------------------
// CFtpExampleContainer::Cancel()
// Called when user cancels currently ongoing FTP command.
// ----------------------------------------------------
//
void CFtpExampleContainer::Cancel()
{
iAction = ENoAction;
TRAPD( error,
SetTextL(KCancelled);
iAppUi.CommandExecutingL(EFalse));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::ConnReset()
// Called when connection is lost.
// ----------------------------------------------------
//
void CFtpExampleContainer::ConnReset()
{
SetConnected(EFalse);
iAction = ENoAction;
TRAPD( error,
SetTextL(KConnectionLost, ETrue);
iAppUi.CommandExecutingL(EFalse));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::ConnectionError()
// Error in establishing the connection with the FTP server.
// ----------------------------------------------------
//
void CFtpExampleContainer::ConnectionError(TOpComp aTConnectionError)
{
switch (iAction)
{
case EConnecting:
{
SetConnected(EFalse);
break;
}
case EDir:
case ENoAction:
break;
}
iAction = ENoAction;
TBuf<25> error;
error.Format(KConnectionError, aTConnectionError);
TRAPD( err,
SetTextL(error, ETrue);
iAppUi.CommandExecutingL(EFalse));
if (err != KErrNone)
{
Panic(err);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::OperationNotSupported()
// Restart operation not supported.
// ----------------------------------------------------
//
void CFtpExampleContainer::OperationNotSupported()
{
iAction = ENoAction;
TRAPD(error, iAppUi.CommandExecutingL(EFalse));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::LocalFileSystemError()
// Called when an error occurred in the local file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::LocalFileSystemError(TOpComp aTLocalFileSystemError)
{
iAction = ENoAction;
TBuf<30> error;
error.Format(KLocalFileSystemError, aTLocalFileSystemError);
TRAPD( err,
SetTextL(error, ETrue);
iAppUi.CommandExecutingL(EFalse));
if (err != KErrNone)
{
Panic(err);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::RemoteFileSystemError()
// Called when an error occurred in the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::RemoteFileSystemError(TOpComp aTRemoteFileSystemError)
{
iAction = ENoAction;
TBuf<30> error;
error.Format(KRemoteFileSystemError, aTRemoteFileSystemError);
TRAPD( err,
SetTextL(error, ETrue);
iAppUi.CommandExecutingL(EFalse));
if (err != KErrNone)
{
Panic(err);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::EUnknownError()
// Called when an unknown error occurred.
// ----------------------------------------------------
//
void CFtpExampleContainer::EUnknownError()
{
switch (iAction)
{
case EConnecting:
SetConnected(EFalse);
break;
case EDir:
case ENoAction:
break;
}
iAction = ENoAction;
TRAPD( error,
SetTextL(KUnknownError, ETrue);
iAppUi.CommandExecutingL(EFalse));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::ServerMessage()
// Called when the FTP server send data to the client.
// ----------------------------------------------------
//
void CFtpExampleContainer::ServerMessage(const TDesC8& aMessage)
{
TRAPD(error, SetTextL(aMessage));
if (error != KErrNone)
{
Panic(error);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::SetTextL()
// Writes a message to the rich text editor.
// ----------------------------------------------------
//
void CFtpExampleContainer::SetTextL(const TDesC8& aMessage)
{
HBufC* text = HBufC::NewLC(aMessage.Length());
TPtr ptr(text->Des());
ptr.Copy(aMessage);
SetTextL(ptr);
CleanupStack::PopAndDestroy(text);
}
// ----------------------------------------------------
// CFtpExampleContainer::SetTextL()
// Writes a message to the rich text editor.
// ----------------------------------------------------
//
void CFtpExampleContainer::SetTextL(const TDesC& aMessage, const TBool& aCarriageReturn)
{
CRichText* text = iEditor->RichText();
TInt messageLength = text->DocumentLength() + aMessage.Length();
// Editor has room for KRichTextMaxLength characters. Delete older data to make room for new data.
if (messageLength > KRichTextMaxLength)
{
TInt deleteCount = messageLength - KRichTextMaxLength;
text->DeleteL(0, deleteCount);
}
if (aCarriageReturn)
{
// Make room for carriage returns
if (text->DocumentLength() > (KRichTextMaxLength-2))
{
text->DeleteL(0, 2);
}
text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
text->InsertL(text->DocumentLength(), aMessage);
text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
}
else
{
text->InsertL(text->DocumentLength(), aMessage);
}
iEditor->HandleTextChangedL();
iEditor->SetCursorPosL(text->DocumentLength(), EFalse);
}
// ----------------------------------------------------
// CFtpExampleContainer::AddCarriageReturnL()
// Adds a carriage return to the rich text editor
// ----------------------------------------------------
//
void CFtpExampleContainer::AddCarriageReturnL()
{
CRichText* text = iEditor->RichText();
// Make room for carriage return
if (text->DocumentLength() > (KRichTextMaxLength-1))
{
text->DeleteL(0,1);
}
text->InsertL(text->DocumentLength(), CEditableText::ELineBreak);
iEditor->HandleTextChangedL();
iEditor->SetCursorPosL(text->DocumentLength(), EFalse);
}
// ----------------------------------------------------
// CFtpExampleContainer::DoQueryL()
// Queries a text from user.
// ----------------------------------------------------
//
TBool CFtpExampleContainer::DoQueryL(const TDesC& aPrompt, TDes& aQueryResult)
{
CAknTextQueryDialog* dlg = CAknTextQueryDialog::NewL(aQueryResult);
CleanupStack::PushL(dlg);
dlg->SetPromptL(aPrompt);
CleanupStack::Pop(dlg);
if (dlg->ExecuteLD(R_FTPEXAMPLE_DATA_QUERY))
{
return ETrue;
}
return EFalse;
}
// ----------------------------------------------------
// CFtpExampleContainer::SetConnected()
// Sets the connection status.
// ----------------------------------------------------
//
void CFtpExampleContainer::SetConnected(const TBool& aConnected)
{
iConnection = aConnected;
}
// ----------------------------------------------------
// CFtpExampleContainer::Connected()
// Returns the connection status.
// ----------------------------------------------------
//
TBool CFtpExampleContainer::Connected() const
{
return iConnection;
}
// End of file
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -