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

📄 httpexampleappui.cpp

📁 symbian S60 2nd 一个好用的HTTP的例子,可以直接拿来用的
💻 CPP
字号:
/**
*
* @brief Definition of CHTTPExampleAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "HTTPExampleAppUi.h"

// System includes
#include <aknwaitdialog.h>              // CAknWaitDialog
#include <aknnotewrappers.h>            // CAknInformationNote
#include <avkon.hrh>                    // EAknSoftkeyOk
#include <HTTPExample.rsg>              // Resource IDs

// User includes
#include "HTTPExampleContainer.h"       // CHTTPExampleContainer
#include "HTTPExample.hrh"              // Command IDs
#include "HTTPExampleUriQueryDialog.h"  // CHTTPExampleUriQueryDialog

// CONSTANTS
_LIT(KDefaultUrlText, "http://www.emccsoft.com/");
_LIT(KStatusFormat, "%d: %S");      // Format string for status returned from web server, e.g. "200: OK" or "404: Not Found"
const TInt KStatusCodeLength = 10;  // Enough room in a descriptor for code + ": "


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

/**
* Symbian OS 2nd phase constructor.  Constructs the application's container,
* setting itself as the container's MOP parent, and adds it to the control
* stack.
*/
void CHTTPExampleAppUi::ConstructL()
    {
    BaseConstructL();
    iAppContainer = CHTTPExampleContainer::NewL(ClientRect());
    iAppContainer->SetMopParent(this);
    AddToStackL(iAppContainer);

    iEngine = CHTTPExampleEngine::NewL(*this);
    }

/**
* Destructor.
* Removes the application's container from the stack and deletes it.
*/
CHTTPExampleAppUi::~CHTTPExampleAppUi()
    {
    if (iAppContainer)
        {
        RemoveFromStack(iAppContainer);
        delete iAppContainer;
        }
    delete iEngine;
//    delete iWaitDialog;
    }

/**
* From CEikAppUi, takes care of command handling.
*
* @param aCommand command to be handled
*/
void CHTTPExampleAppUi::HandleCommandL(TInt aCommand)
    {
    // Initialise URL text
    iUri = KDefaultUrlText;

    switch (aCommand)
        {
        case EHTTPExampleCmdGet:
            if (PromptForUriL())
                {
                iEngine->GetRequestL(iUri);
//                StartWaitDialogL();
                }
            break;

        case EHTTPExampleCmdPost:
            if (PromptForNameL())
                {
                iEngine->PostRequestL(iName);
//                StartWaitDialogL();
                }
            break;

        case EAknSoftkeyBack:
        case EAknSoftkeyExit:
        case EEikCmdExit:
            {
            Exit();
            break;
            }
        default:
            break;
        }
    }


/**
* Prompt the user for a URI to get.
*
* @return ETrue if the user selects OK to dismiss the dialog, otherwise EFalse
*/
TBool CHTTPExampleAppUi::PromptForUriL()
    {
    CHTTPExampleUriQueryDialog* uriQueryDlg = new (ELeave) CHTTPExampleUriQueryDialog(iUri);
    TInt ret = uriQueryDlg->ExecuteLD(R_HTTPEXAMPLE_URI_QUERY);
    return (ret == EAknSoftkeyOk);
/*    CAknTextQueryDialog* uriQueryDlg = new (ELeave) CAknTextQueryDialog(iUri);
    TInt ret = uriQueryDlg->ExecuteLD(R_HTTPEXAMPLE_URI_QUERY);
    return (ret == EAknSoftkeyOk);*/
   }


/**
* Prompt the user for their name, to send as a parameter in a POST request.
*
* @return ETrue if the user selects OK to dismiss the dialog, otherwise EFalse
*/
TBool CHTTPExampleAppUi::PromptForNameL()
    {
    CAknTextQueryDialog* textQueryDlg = new (ELeave) CAknTextQueryDialog(iName);
    textQueryDlg->SetMaxLength(EMaxNameLength);
    TInt ret = textQueryDlg->ExecuteLD(R_HTTPEXAMPLE_NAME_QUERY);
    return (ret == EAknSoftkeyOk);
    }

/*
void CHTTPExampleAppUi::StartWaitDialogL()
    {
    if (iWaitDialog)
        {
        delete iWaitDialog;
        iWaitDialog = NULL;
        }
    iWaitDialog = new (ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**, &iWaitDialog)), ETrue);
    iWaitDialog->SetTone(CAknNoteDialog::EConfirmationTone);
    iWaitDialog->ExecuteLD(R_HTTPEXAMPLE_WAIT_NOTE); 
    }
*/

/**
* Callback from engine invoked when a request status is received.
*
* @param aStatusCode The numerical HTTP status code (e.g. 404)
* @param aStatusText The status text returned by the server (e.g. "Not found")
*/
void CHTTPExampleAppUi::ResponseStatusL(TInt aStatusCode, const TDesC& aStatusText)
    {
    HBufC* buf = HBufC::NewLC(aStatusText.Length() + KStatusCodeLength);
    buf->Des().Format(KStatusFormat, aStatusCode, &aStatusText);
    CAknInformationNote* note = new (ELeave) CAknInformationNote;
    note->ExecuteLD(*buf);
    CleanupStack::PopAndDestroy(buf);
    }


/**
* Callback from engine invoked when the complete response has been received.
*
* @param aResponse Text of the HTTP response
*/
void CHTTPExampleAppUi::ResponseReceivedL(const TDesC& aResponse)
    {
/*    if (iWaitDialog)
        {
        iWaitDialog->ProcessFinishedL(); // Deletes the dialog
        iWaitDialog = NULL;
        }*/
    iAppContainer->SetTextL(aResponse);
    }

/*
void CHTTPExampleAppUi::DialogDismissedL(TInt aButtonId)
    {
    iWaitDialog = NULL;

    if ((iEngine != NULL) && (aButtonId == EEikBidCancel))
        {
        iEngine->Cancel();
        }
    }
*/

// End of File

⌨️ 快捷键说明

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