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

📄 irsocketsappui.cpp

📁 运行在symbian 第二版上
💻 CPP
字号:
/**
*
* @brief Definition of CIrSocketsAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "IrSocketsAppUi.h"
#include "IrSocketsEngine.h"

// System includes
#include <IrSockets.rsg>    // R_IRSOCKETS_DIALOG
#include <stringloader.h> // StringLoader
#include <aknnotewrappers.h> // Note Dialogs
#include <eikmenup.h>
// User includes
#include "IrSocketsDialog.h"    // CIrSocketsDialog
#include "IrSockets.hrh" // commands

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

/**
* Symbian OS 2nd phase constructor.  Constructs and executes the application's dialog,
* setting itself as the dialog's MOP parent, and adds it to the control
* stack. Also instantiate the infrared engine (active object).
*/
void CIrSocketsAppUi::ConstructL()
{
    iEditOption = ETrue;
    BaseConstructL();
       iAppDialog = new (ELeave) CIrSocketsDialog;
    iAppDialog->SetMopParent(this);
    iAppDialog->ExecuteLD(R_IRSOCKETS_DIALOG);
    AddToStackL(iAppDialog);
    iIrSocketsEngine = CIrSocketsEngine::NewL(/*CActive::EPriorityStandard,*/ *this);
}

/**
* Destructor.
* Removes the application's dialog from the stack and deletes it.
* Remove the Infrared active object.
*/
CIrSocketsAppUi::~CIrSocketsAppUi()
{
    if (iAppDialog)
    {
        RemoveFromStack(iAppDialog);
        delete iAppDialog;
    }

    delete iIrSocketsEngine;
}

/**
* The Uikon framework calls this function, immediately before the menu pane is activated.
* Update menu items depending on current state, in particular Receive menu items 
*/
void CIrSocketsAppUi::DynInitMenuPaneL(TInt aMenuId, CEikMenuPane* aMenuPane)
{
    if (aMenuId == R_IRSOCKETS_MENU_PANE)
    {
        // Grey-out 'Receive via IR' menu item if already in Receive mode
        aMenuPane->SetItemDimmed(EIrSocketsCmdReceiveIr, iIrSocketsEngine->Accepting());

        // Grey-out 'Cancel Receive' menu item if not in Receive mode
        aMenuPane->SetItemDimmed(EIrSocketsCmdCancelReceiveIr, !iIrSocketsEngine->Accepting());

        aMenuPane->SetItemDimmed(EIrSocketsCmdEdit, iEditOption);
    }
}

/**
* From CEikAppUi, takes care of command handling.
*
* @param aCommand command to be handled
*/
void CIrSocketsAppUi::HandleCommandL(TInt aCommand)
{
    switch (aCommand)
    {
        case EIrSocketsCmdSendIr: // Send text via IR
            iAppDialog->SetEditableL(EFalse); // Change text control to view mode
            iEditOption = EFalse;
            iIrSocketsEngine->PrepareForSendingL();
            break;

        case EIrSocketsCmdEdit: // Edit the text control
            iAppDialog->SetEditableL(ETrue);
            iEditOption = ETrue;
            break;

        case EIrSocketsCmdReceiveIr: // Receive via IR mode
            iIrSocketsEngine->PrepareForReceivingL();
            break;

        case EIrSocketsCmdCancelReceiveIr: // Cancel receive via IR mode
            iIrSocketsEngine->CancelReceiveL();
            break;

        case EEikCmdExit:
            Exit();
            break;

        default:
            break;
    }
}

/**
* Retrieve string entered in text control and send to asynchronous Transmit function
*/
void CIrSocketsAppUi::ReadyToSendL()
{
    CCoeControl* textControl = iAppDialog->Control(EIrSocketsFormText);
    CEikEdwin* textEdwin = static_cast<CEikEdwin*>(textControl);
    TBuf<EFormEdwinMaxLength> textData;
    textEdwin->GetText(textData);
    iIrSocketsEngine->SendL(textData);
}

/**
* Display No Devices In Range dialog
*/
void CIrSocketsAppUi::DisplayNoDevicesDiscoveredNoteL()
{
    HBufC* noDevicesText = StringLoader::LoadLC(R_IR_EXAMPLE_NO_DEVICES_DISCOVERED);
    CAknWarningNote* note = new (ELeave) CAknWarningNote;
    note->ExecuteLD(*noDevicesText);
    CleanupStack::PopAndDestroy(noDevicesText);
}


/**
* Constructs and displays information note to indicate result of infrared send
* @param result which contains error return code
*/
void CIrSocketsAppUi::DisplaySendResultNoteL(TInt result)
{
    if(result == KErrNone) // Result ok
    {
        HBufC* okText = StringLoader::LoadLC(R_IR_EXAMPLE_SEND_OK);
        CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote;
        note->ExecuteLD(*okText);
        CleanupStack::PopAndDestroy(okText);
    }
    else // Error
    {
        HBufC* errorText = StringLoader::LoadLC(R_IR_EXAMPLE_ERROR);
        CAknWarningNote* note = new (ELeave) CAknWarningNote;
        note->ExecuteLD(*errorText);
        CleanupStack::PopAndDestroy(errorText);
    }
}

/**
* Updates the text control to display the text string received
* @param aRxData which contains the text string received
*/
void CIrSocketsAppUi::DisplayReceivedDataL(const TDesC& aRxData)
{
    // Get a pointer to the text control
    CCoeControl* textControl = iAppDialog->Control(EIrSocketsFormText);
    CEikEdwin* textEdwin = static_cast<CEikEdwin*>(textControl);
    // Set text to received string and change form mode to view only
    textEdwin->SetTextL(&aRxData);
    iAppDialog->SetEditableL(EFalse);
    iEditOption = EFalse;
    // Display information note indicating data received ok
    DisplayReceiveNoteL();
}

/**
* Displays information note indicating data received ok
*/
void CIrSocketsAppUi::DisplayReceiveNoteL()
{
    HBufC* okRecvText = StringLoader::LoadLC(R_IR_EXAMPLE_RECV_OK);
    CAknConfirmationNote* note = new (ELeave) CAknConfirmationNote;
    note->ExecuteLD(*okRecvText);
    CleanupStack::PopAndDestroy(okRecvText);
}

// End of File

⌨️ 快捷键说明

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