📄 ftpexamplecontainer.cpp
字号:
/*
* ============================================================================
* Name : CFtpExampleContainer from FtpExampleContainer.h
* Part of : FtpExample
* Created : 03/11/2005 by Forum Nokia
* Version : 1.0
* Copyright: Nokia Corporation
* ============================================================================
*/
// INCLUDE FILES
#include <eikrted.h> // CCEikRichTextEditor
#include <barsread.h> // TResourceReader
#include <txtrich.h> // CRichText
#include <AknQueryDialog.h>
#include <FtpExample.rsg>
#include "FtpExampleContainer.h"
#include "FtpExampleAppUi.h"
#include "FtpExampleConnectDlg.h"
#include "FtpExample.hrh"
#include "FtpExampleEngine.h"
#include "FtpExample.pan"
// CONSTANTS
_LIT(KError, "Error %d occurred");
_LIT(KConnecting, "Connecting...");
_LIT(KConnectionLost, "Connection lost.");
_LIT(KConnectionError, "Connection error %d");
_LIT(KRemoteFileSystemError, "Remote file system error %d");
_LIT(KLocalFileSystemError, "Local file system error %d");
_LIT(KUnknownError, "Unknown error");
_LIT(KCurrentDirectory, ".");
_LIT(KCdCommand, "cd");
_LIT(KGetRemoteCommand, "get (remote file)");
_LIT(KGetLocalCommand, "get (local file)");
_LIT(KPutRemoteCommand, "put (remote file)");
_LIT(KPutLocalCommand, "put (local file)");
_LIT(KMkdirCommand, "mkdir");
_LIT(KRmdirCommand, "rmdir");
_LIT(KRenameCmd, "rename (from name)");
_LIT(KRenameNewCmd, "rename (to name)");
_LIT(KDeleteCommand, "delete");
_LIT(KCancelled, "Cancelled.");
_LIT(KBehindFirewall, "Are you behind a firewall? (TConnectionMode::Epassive)");
// ================= MEMBER FUNCTIONS =======================
// constructor
CFtpExampleContainer::CFtpExampleContainer(CFtpExampleAppUi& aAppUi)
: iAppUi(aAppUi)
{
}
// destructor
CFtpExampleContainer::~CFtpExampleContainer()
{
delete iEditor;
}
// ----------------------------------------------------
// CFtpExampleContainer::NewL()
// Two-phased constructor.
// ----------------------------------------------------
//
CFtpExampleContainer* CFtpExampleContainer::NewL(const TRect& aRect, CFtpExampleAppUi& aAppUi)
{
CFtpExampleContainer* self = new (ELeave) CFtpExampleContainer(aAppUi);
CleanupStack::PushL(self);
self->ConstructL(aRect);
CleanupStack::Pop(self);
return self;
}
// ----------------------------------------------------
// CFtpExampleContainer::ConstructL()
// Symbian OS default constructor can leave.
// ----------------------------------------------------
//
void CFtpExampleContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
iEditor = new (ELeave) CEikRichTextEditor;
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(reader, R_FTPEXAMPLE_RICH_TEXT_EDITOR);
iEditor->ConstructFromResourceL(reader);
CleanupStack::PopAndDestroy(); // reader
iEditor->SetContainerWindowL(*this);
iEditor->SetMopParent(this);
iEditor->CreateScrollBarFrameL()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto );
iEditor->SetFocus(ETrue);
SetRect(aRect);
ActivateL();
SetConnected(EFalse);
}
// ----------------------------------------------------
// CFtpExampleContainer::SizeChanged()
// Responds to size changes to sets the size and
// position of the contents of this control.
// ----------------------------------------------------
//
void CFtpExampleContainer::SizeChanged()
{
iEditor->SetRect(Rect());
}
// ----------------------------------------------------
// CFtpExampleContainer::CountComponentControls()
// Gets the number of controls contained in a compound
// control.
// ----------------------------------------------------
//
TInt CFtpExampleContainer::CountComponentControls() const
{
TInt count = 0;
if (iEditor)
{
count++;
}
return count;
}
// ----------------------------------------------------
// CFtpExampleContainer::ComponentControl()
// Gets the specified component of a compound control.
// ----------------------------------------------------
//
CCoeControl* CFtpExampleContainer::ComponentControl(TInt /*aIndex*/) const
{
return iEditor;
}
// ----------------------------------------------------
// CFtpExampleContainer::OfferKeyEventL()
// When a key event occurs, the control framework calls
// this function for each control on the control stack,
// until one of them can process the key event
// (and returns EKeyWasConsumed).
// ----------------------------------------------------
//
TKeyResponse CFtpExampleContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
if (iEditor)
{
if (EKeyUpArrow == aKeyEvent.iCode)
{
iEditor->MoveCursorL (TCursorPosition::EFPageUp, EFalse);
return EKeyWasConsumed;
}
else if (EKeyDownArrow == aKeyEvent.iCode)
{
iEditor->MoveCursorL (TCursorPosition::EFPageDown, EFalse);
return EKeyWasConsumed;
}
else
{
return iEditor->OfferKeyEventL(aKeyEvent, aType);
}
}
else
{
return EKeyWasNotConsumed;
}
}
// ----------------------------------------------------
// CFtpExampleContainer::Draw()
// This function is used for window server-initiated
// redrawing of controls, and for some
// application-initiated drawing.
// ----------------------------------------------------
//
void CFtpExampleContainer::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
gc.SetPenStyle( CGraphicsContext::ENullPen );
gc.SetBrushColor( KRgbWhite );
gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
gc.DrawRect( aRect );
}
// ----------------------------------------------------
// CFtpExampleContainer::ConnectL()
// Connects to an FTP server. If a connection already
// exists, this function will only close it.
// ----------------------------------------------------
//
void CFtpExampleContainer::ConnectL()
{
// Connection is active, disconnect.
if (iConnection)
{
iAppUi.Model().Disconnect();
SetConnected(EFalse);
iAppUi.CommandExecutingL(ETrue);
}
// Connection is not active, connect.
else
{
TBuf<KServerMaxLength> server;
TBuf<KUsernameMaxLength> username;
TBuf<KPasswordMaxLength> password;
CFtpExampleConnectDlg* dlg = new (ELeave) CFtpExampleConnectDlg(server, username, password);
// Acquire hostname, username and password.
if (dlg->ExecuteLD(R_FTPEXAMPLE_DIALOG_CONNECT))
{
CAknQueryDialog* query = CAknQueryDialog::NewL();
CleanupStack::PushL(query);
query->SetPromptL(KBehindFirewall);
CleanupStack::Pop(query);
CFTPSession::TConnectionMode connectionMode = CFTPSession::EActive;
// If the client is behind a firewall, use Epassive connection mode, otherwise use EActive.
if (query->ExecuteLD(R_FTPEXAMPLE_CONFIRMATION_QUERY_FIREWALL))
{
connectionMode = CFTPSession::Epassive;
}
iAction = EConnecting;
SetTextL(KConnecting, ETrue);
iAppUi.Model().ConnectL(server, username, password, connectionMode);
iAppUi.CommandExecutingL(ETrue);
}
}
}
// ----------------------------------------------------
// CFtpExampleContainer::PwdL()
// Gets the client's current directory on the remote
// file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::PwdL()
{
AddCarriageReturnL();
iAppUi.Model().CurrentDirectory();
iAppUi.CommandExecutingL(ETrue);
}
// ----------------------------------------------------
// CFtpExampleContainer::DirL()
// Lists the files in a directory on the remote file
// system.
// ----------------------------------------------------
//
void CFtpExampleContainer::DirL()
{
AddCarriageReturnL();
iAction = EDir;
iDirBuffer.SetLength(0);
iAppUi.Model().ListDirectoryL(KCurrentDirectory, iDirBuffer);
iAppUi.CommandExecutingL(ETrue);
}
// ----------------------------------------------------
// CFtpExampleContainer::CdL()
// Sets the current directory on the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::CdL()
{
TBuf<KQueryMaxLength> directory;
if (DoQueryL(KCdCommand, directory))
{
AddCarriageReturnL();
iAppUi.Model().ChangeDirectoryL(directory);
iAppUi.CommandExecutingL(ETrue);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::MkdirL()
// Creates a directory on the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::MkdirL()
{
TBuf<KQueryMaxLength> directory;
if (DoQueryL(KMkdirCommand, directory))
{
AddCarriageReturnL();
iAppUi.Model().CreateDirectoryL(directory);
iAppUi.CommandExecutingL(ETrue);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::RmdirL()
// Deletes a directory on the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::RmdirL()
{
TBuf<KQueryMaxLength> directory;
if (DoQueryL(KRmdirCommand, directory))
{
AddCarriageReturnL();
iAppUi.Model().DeleteDirectoryL(directory);
iAppUi.CommandExecutingL(ETrue);
}
}
// ----------------------------------------------------
// CFtpExampleContainer::GetL()
// Transfers a file from the FTP server.
// ----------------------------------------------------
//
void CFtpExampleContainer::GetL(const TBool& aBinary)
{
TBuf<KQueryMaxLength> remoteFile;
TBuf<KQueryMaxLength> localFile;
if (DoQueryL(KGetRemoteCommand, remoteFile))
{
if (DoQueryL(KGetLocalCommand, localFile))
{
AddCarriageReturnL();
iAppUi.Model().RetrieveL(remoteFile, localFile, aBinary);
iAppUi.CommandExecutingL(ETrue);
}
}
}
// ----------------------------------------------------
// CFtpExampleContainer::PutL()
// Transfers a file to the FTP server.
// ----------------------------------------------------
//
void CFtpExampleContainer::PutL(const TBool& aBinary)
{
TBuf<KQueryMaxLength> remoteFile;
TBuf<KQueryMaxLength> localFile;
if (DoQueryL(KPutLocalCommand, remoteFile))
{
if (DoQueryL(KPutRemoteCommand, localFile))
{
AddCarriageReturnL();
iAppUi.Model().StoreL(localFile, remoteFile, aBinary);
iAppUi.CommandExecutingL(ETrue);
}
}
}
// ----------------------------------------------------
// CFtpExampleContainer::RenameL()
// Renames a file on the remote file system.
// ----------------------------------------------------
//
void CFtpExampleContainer::RenameL()
{
TBuf<KQueryMaxLength> fileName;
TBuf<KQueryMaxLength> newFileName;
if (DoQueryL(KRenameCmd, fileName))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -