⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socketsappui.cpp

📁 Symbian 手机网络通信程序 sockets-vc
💻 CPP
字号:
/* Copyright (c) 2004, Nokia. All rights reserved */


// INCLUDE FILES
#include <aknquerydialog.h>
#include <avkon.hrh>
#include <eikmenup.h>
#include <eikgted.h>
#include <Sockets.rsg>

#include "Sockets.pan"
#include "SocketsAppUi.h"
#include "SocketsAppView.h"
#include "Sockets.hrh"
#include "SocketsEngine.h"

// ========================= MEMBER FUNCTIONS ==================================

// -----------------------------------------------------------------------------
// CSocketsAppUi::CSocketsAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CSocketsAppUi::CSocketsAppUi()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CSocketsAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CSocketsAppUi::ConstructL()
    {
    BaseConstructL();

    // Create view
    iAppView = CSocketsAppView::NewL( ClientRect() );
    AddToStackL( iAppView );

    // Create engine
    iSocketsEngine = CSocketsEngine::NewL( *iAppView );
    }

// -----------------------------------------------------------------------------
// CSocketsAppUi::~CSocketsAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CSocketsAppUi::~CSocketsAppUi()
    {
    delete iSocketsEngine;
    iSocketsEngine = NULL;

    if ( iAppView )
        {
        RemoveFromStack( iAppView );
        delete iAppView;
        iAppView = NULL;
        }
    }

// -----------------------------------------------------------------------------
// CSocketsAppUi::HandleCommandL()
// Handles user menu selections.
// -----------------------------------------------------------------------------
//
void CSocketsAppUi::HandleCommandL( TInt aCommand )
    {
    switch( aCommand )
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;

        case ESocketsCmdConnect:
            {
            // Create dialog to allow user to view/edit connection details
            TBuf<KMaxServerNameLength> serverName(
                                            iSocketsEngine->ServerName() );
            TInt port( iSocketsEngine->Port() );

            CAknMultiLineDataQueryDialog* dialog =
                CAknMultiLineDataQueryDialog::NewL( serverName, port );

            // Display and execute dialog, and act according to return value
            if ( dialog->ExecuteLD( R_SOCKETS_DIALOG_CONNECT ) )
                {
                iSocketsEngine->SetServerName( serverName );
                iSocketsEngine->SetPort( port );
                iSocketsEngine->ConnectL(); // Initiate connection
                }
            break;
            }
        case ESocketsCmdDisconnect:
            iSocketsEngine->Disconnect();
            break;
        case ESocketsCmdClear:
            iAppView->ClearTextL();
            break;
        default:
            User::Panic ( KPanicSockets, ESocketsBasicUi );
            break;
        }
    }

// -----------------------------------------------------------------------------
// CSocketsAppUi::DynInitMenuPaneL()
// Initialises a menu pane before it is displayed.
// -----------------------------------------------------------------------------
//
void CSocketsAppUi::DynInitMenuPaneL( TInt aMenuId, CEikMenuPane* aMenuPane )
    {
    if ( aMenuId == R_SOCKETS_MENU )
        {
        // Disable 'Connect' menu item if already connected
        aMenuPane->SetItemDimmed( ESocketsCmdConnect,
                                  iSocketsEngine->Connected() );

        // Disable 'Disconnect' menu item if not connected
        aMenuPane->SetItemDimmed( ESocketsCmdDisconnect,
                                  !iSocketsEngine->Connected() );
        }
    }

// -----------------------------------------------------------------------------
// CSocketsAppUi::HandleKeyEventL()
// Handles user key input.
// -----------------------------------------------------------------------------
//
TKeyResponse CSocketsAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
                                             TEventCode aType )
    {
    TChar theCharacter( aKeyEvent.iCode );
    if ( ( aType == EEventKey ) &&
         ( iSocketsEngine->Connected() ) &&
         ( theCharacter.IsPrint() || theCharacter == EKeyEnter ) )
        {
        // This key event will end up as 'data' when written
        // to the socket, so use TBuf8
        TBuf8<2> buf;

        // This will 'slice off' the higher order byte, OK for this example
        buf.Append( aKeyEvent.iCode );

        if ( theCharacter == EKeyEnter )
            {
            buf.Append( EKeyLineFeed );
            }

        iSocketsEngine->WriteL( buf );
        iAppView->PrintNotify( buf, CEikGlobalTextEditor::EBold );

        return( EKeyWasConsumed );
        }

    return( EKeyWasNotConsumed );
    }

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -