📄 udpsocketappui.cpp
字号:
/*
* ============================================================================
* Name : CUdpSocketAppUi from UdpSocketAppui.cpp
* Part of : UdpSocket
* Created : 07.03.2006 by ToBeReplacedByAuthor
* Implementation notes:
* Initial content was generated by Series 60 Application Wizard.
* Version :
* Copyright: ToBeReplacedByCopyright
* ============================================================================
*/
// INCLUDE FILES
#include <avkon.hrh>
#include <aknquerydialog.h> // for CAknMultiLineDataQueryDialog
#include <eikmenup.h> // for CEikMenuPane
#include <UdpSocket.rsg>
#include "UdpSocket.hrh"
#include "UdpSocketAppui.h"
#include "UdpSocketContainer.h"
// ================= MEMBER FUNCTIONS =======================
//
// ----------------------------------------------------------
// CUdpSocketAppUi::ConstructL()
//
// ----------------------------------------------------------
//
void CUdpSocketAppUi::ConstructL()
{
BaseConstructL();
iAppContainer = new (ELeave) CUdpSocketContainer;
iAppContainer->SetMopParent( this );
iAppContainer->ConstructL( ClientRect() );
AddToStackL( iAppContainer );
iEngine = CUdpSocketEngine::NewL(*this);
}
// ----------------------------------------------------
// CUdpSocketAppUi::~CUdpSocketAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
//
CUdpSocketAppUi::~CUdpSocketAppUi()
{
if (iAppContainer)
{
RemoveFromStack( iAppContainer );
delete iAppContainer;
}
delete iEngine;
}
// Functions from CUdpSocketEngine::MObserver
void CUdpSocketAppUi::OnSendL(const TDesC& aMsg, TInt aError)
{
OutputMsgL(R_QTN_PROMPT_LOCAL);
if(aError==KErrNone)
{
iAppContainer->OutputMsgL(aMsg);
}
else
{
OutputErrL(aError);
}
}
void CUdpSocketAppUi::OnReceiveL(const TDesC& aMsg, TInt aError)
{
OutputMsgL(R_QTN_PROMPT_REMOTE);
if(aError==KErrNone)
{
iAppContainer->OutputMsgL(aMsg);
}
else
{
OutputErrL(aError);
}
}
// ------------------------------------------------------------------------------
// CUdpSocketAppUi::DynInitMenuPaneL(TInt aResourceId,CEikMenuPane* aMenuPane)
// This function is called by the EIKON framework just before it displays
// a menu pane. Its default implementation is empty, and by overriding it,
// the application can set the state of menu items dynamically according
// to the state of application data.
// ------------------------------------------------------------------------------
//
void CUdpSocketAppUi::DynInitMenuPaneL(
TInt aResourceId,CEikMenuPane* aMenuPane)
{
if(aResourceId!=R_UDPSOCKET_MENU)
{
return;
}
if(iEngine->RemoteSpecified())
{
aMenuPane->SetItemDimmed(EUdpSocketCmdSetRemote, ETrue);
if(iAppContainer->LocalMsgLength()==0)
{
aMenuPane->SetItemDimmed(EUdpSocketCmdSend, ETrue);
}
}
else
{
aMenuPane->SetItemDimmed(EUdpSocketCmdSend, ETrue);
}
}
// ----------------------------------------------------
// CUdpSocketAppUi::HandleCommandL(TInt aCommand)
// takes care of command handling
// ----------------------------------------------------
//
void CUdpSocketAppUi::HandleCommandL(TInt aCommand)
{
switch ( aCommand )
{
case EAknSoftkeyBack:
case EEikCmdExit:
{
Exit();
break;
}
case EUdpSocketCmdSetRemote:
{
// Create dialog to allow user to view/edit connection details
_LIT(KRemoteIP, "127.0.0.1");
TBuf<15> ip = KRemoteIP();
TInt port = 8001;
CAknMultiLineDataQueryDialog* dialog =
CAknMultiLineDataQueryDialog::NewL(ip, port);
// Display and execute dialog, and act according to return value
if ( dialog->ExecuteLD(R_UDPSOCKET_ADDRESS_QUERY) )
{
iEngine->SetRemoteL(ip, port);
}
break;
}
case EUdpSocketCmdSend:
{
iAppContainer->SelectLocalMsgL();
HBufC* buf = HBufC::NewLC(iAppContainer->LocalMsgLength());
TPtr ptr = buf->Des();
iAppContainer->GetLocalMsg(ptr);
iEngine->SendL(*buf);
CleanupStack::PopAndDestroy();
break;
}
default:
break;
}
}
void CUdpSocketAppUi::OutputMsgL(TInt aResourceId)
{
HBufC* buf = iCoeEnv->AllocReadResourceLC(aResourceId);
iAppContainer->OutputMsgL(*buf);
CleanupStack::PopAndDestroy();
}
void CUdpSocketAppUi::OutputErrL(TInt aError)
{
TBuf<32> msg;
HBufC* buf = iCoeEnv->AllocReadResourceLC(R_QTN_PROMPT_ERROR);
msg.Copy(*buf);
CleanupStack::PopAndDestroy();
msg.Append(' ');
msg.AppendNum(aError);
iAppContainer->OutputMsgL(msg);
}
// End of File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -