mtmsexampleappui.cpp

来自「最新官方例子,图形,描述副,基本控件,通讯协议,等等,」· C++ 代码 · 共 150 行

CPP
150
字号
/**
* 
* @brief Definition of CMtmsExampleAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "MtmsExampleAppUi.h"

// System includes
#include <aknnotewrappers.h>    // CAknErrorNote, CAknInformationNote
#include <MtmsExample.rsg>

// User includes
#include "MtmsExampleDialog.h"  // CMtmsExampleDialog
#include "MtmsExampleEngine.h"  // CMtmsExampleEngine
#include "MtmsExample.hrh"      // commands


_LIT(KInvalidMessage, "Message is invalid");
_LIT(KMessageSent, "Message sent!");
_LIT(KMessageUnsent, "Message unsent: %d");


// ================= 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.
*/  
void CMtmsExampleAppUi::ConstructL()
    {
    BaseConstructL();

    // Create engine
    iEngine = CMtmsExampleEngine::NewL(*this);

    iAppDialog = new (ELeave) CMtmsExampleDialog;
    iAppDialog->SetMopParent(this);
    iAppDialog->ExecuteLD(R_MTMS_EXAMPLE_DIALOG);
    AddToStackL(iAppDialog);    
    }


/**
* Destructor.
* Removes the application's dialog from the stack and deletes it.
*/  
CMtmsExampleAppUi::~CMtmsExampleAppUi()
    {
    delete iEngine;
    if (iAppDialog)
        {
        RemoveFromStack(iAppDialog);
        delete iAppDialog;
        }
    }

/**
* From CEikAppUi, takes care of command handling.
*
* @param aCommand command to be handled
*/
void CMtmsExampleAppUi::HandleCommandL(TInt aCommand)
    {
    if (!iEngine->IsReady())
        return;

    switch (aCommand)
        {
        case EMtmsExampleCmdSendSMS:
            if (!GetAddressL())
				{
				break;
				}
            iEngine->CreateDraftSMSL(iAddress);
            if (!iEngine->ValidateSMS())
                {
                NotifyMessageInvalidL();
                }
            else
                {
                iEngine->SendSMSL();
                }
            break;

        case EMtmsExampleCmdSendMMS:
            if (!GetAddressL())
				{
				break;
				}
            iEngine->CreateDraftMMSL(iAddress);
            if (!iEngine->ValidateMMS())
                {
                NotifyMessageInvalidL();
                }
            else
                {
                iEngine->SendMMSL();
                }
            break;

        case EEikCmdExit:
            Exit();
            break;
        
        default:
            break;
        }
    }


void CMtmsExampleAppUi::NotifyMessageInvalidL()
    {
    CAknErrorNote* note = new (ELeave) CAknErrorNote;
    note->ExecuteLD(KInvalidMessage);
    }


TInt CMtmsExampleAppUi::GetAddressL()
    {
    CAknTextQueryDialog* dlg = new (ELeave) CAknTextQueryDialog(iAddress, CAknQueryDialog::ENoTone);
    return dlg->ExecuteLD(R_MTMS_EXAMPLE_ADDRESS_QUERY);
    }


void CMtmsExampleAppUi::HandleMessageSentL(TInt aError)
    {
    if (aError == KErrNone)
        {
        CAknInformationNote* note = new (ELeave) CAknInformationNote;
        note->ExecuteLD(KMessageSent);
        }
    else
        {
        TBuf<64> buf;
        buf.Format(KMessageUnsent, aError);
        CAknErrorNote* note = new (ELeave) CAknErrorNote;
        note->ExecuteLD(buf);
        }
    }


// End of File  

⌨️ 快捷键说明

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