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

📄 myhttpbaseview.cpp

📁 This application is explain how to Test http connection in symbian c++
💻 CPP
字号:
/***************************************************************************** 
COPYRIGHT All rights reserved Sony Ericsson Mobile Communications AB 2006. 
The software is the copyrighted work of Sony Ericsson Mobile Communications AB. 
The use of the software is subject to the terms of use or of the end-user license 
agreement which accompanies or is included with the software. The software is 
provided "as is" and Sony Ericsson specifically disclaim any warranty or 
condition whatsoever regarding merchantability or fitness for a specific 
purpose, title or non-infringement. No warranty of any kind is made in 
relation to the condition, suitability, availability, accuracy, reliability, 
merchantability and/or non-infringement of the software provided herein. 
*****************************************************************************/

// MyHttpBaseView.cpp

#include "MyHttpBaseView.h"
#include "HttpClient.h"
#include "MyHttpGlobals.h"
#include <MyHttp.rsg>
#include "MyHttp.hrh"

#include <EIKLABEL.H>
#include <EIKEDWIN.H>


_LIT(KEmpty,      "(Empty)");
_LIT(KReady,      "Ready");
_LIT(KConnecting, "Connecting...");
_LIT(KConnected,  "Connected");



CMyHttpBaseView* CMyHttpBaseView::NewLC(CQikAppUi& aAppUi)
  {
  CMyHttpBaseView* self = new (ELeave) CMyHttpBaseView(aAppUi);
  CleanupStack::PushL(self);
  self->ConstructL();
  return self;
  }

CMyHttpBaseView::~CMyHttpBaseView()
  {
  if(iClient)
    {
    delete iClient;
    iClient = NULL;
    }
  }

TVwsViewId CMyHttpBaseView::ViewId() const
  {
  return TVwsViewId(KUidMyHttpID, KUidMyHttpBaseViewID);
  }

void CMyHttpBaseView::AddResult(const TDesC& aText)
  {
  CEikEdwin* content = LocateControlByUniqueHandle<CEikEdwin>(EMyHttpContent);
  if(content)
    {
    content->Text()->InsertL(content->CursorPos(), aText);
    content->SetDimmed(EFalse);
    content->SetSize(content->MinimumSize());
    content->HandleTextChangedL();
    content->DrawDeferred();
    }
  else
    User::InfoPrint(_L("EMyHttpContent Err"));
  }

void CMyHttpBaseView::SetConnected()
  {
  SetTextL(ETrue, KConnected);
  }

void CMyHttpBaseView::SetDisconnected()
  {
  SetTextL(ETrue, KReady);
  }

void CMyHttpBaseView::StartNetRead()
  {
  if(iClient)
    {
    delete iClient;
    iClient = NULL;
    }
  SetTextL(EFalse, KNullDesC);
  iClient = CHttpClient::NewL(*this);
  SetTextL(ETrue, KConnecting);
  iClient->StartClientL();
  }

void CMyHttpBaseView::ViewConstructL()
  {
  ViewConstructFromResourceL(R_MYHTTP_BASEVIEW_UI_CONFIGURATIONS, 0);

  InitComponentArrayL();

  // Create the Label and add it to the container
  CEikLabel* info = new (ELeave) CEikLabel();
  Controls().AppendLC(info, EMyHttpInfo);
  info->ConstructL();
  info->SetTextL(KReady);
  info->SetRect(TRect(TPoint(20, 5), info->MinimumSize()));
  info->SetUniqueHandle(EMyHttpInfo);
  info->SetObserver(this);
  CleanupStack::Pop(info);

  // Create the Label and add it to the container
  CEikEdwin* content = new (ELeave) CEikEdwin();
  Controls().AppendLC(content, EMyHttpContent);
  content->ConstructL(CEikEdwin::EDisplayOnly, 13, 1024, 11);
  content->SetTextL(&KEmpty);
  content->SetRect(TRect(TPoint(3, 25), content->MinimumSize()));
  content->SetUniqueHandle(EMyHttpContent);
  content->SetObserver(this);
  CleanupStack::Pop(content);

  _LIT(KTitleText, "SHello");
  SetViewContext(KTitleText);
  }

CMyHttpBaseView::CMyHttpBaseView(CQikAppUi& aAppUi)
  : CQikViewBase(aAppUi, KNullViewId)
  {
  }

void CMyHttpBaseView::ConstructL()
  {
  BaseConstructL();
  }

void CMyHttpBaseView::Draw(const TRect& /*aRect*/) const
  {
	TRect drawRect = Rect();
	CWindowGc& gc = SystemGc();
	gc.Clear();

	// Draw an outline rectangle for info
	drawRect.SetRect(TPoint(5,5), TSize(drawRect.Width()-10, 16));
	gc.DrawRect(drawRect);
  }

void CMyHttpBaseView::SetViewContext(const TDesC& aText)
  {
  MQikViewContext* viewContext = ViewContext();
  viewContext->AddTextL(EMyHttpTitleText, 
                        aText,
                        EHLeftVCenter, 
                        TCoeFont::AnnotationFont());
  }

void CMyHttpBaseView::SetTextL(TBool aInfo, const TDesC& aText)
  {
  if(aInfo)
    {
    CEikLabel* info = LocateControlByUniqueHandle<CEikLabel>(EMyHttpInfo);
    if(info)
      {
      info->SetTextL(aText);
      info->SetDimmed(EFalse);
      info->SetSize(info->MinimumSize());
      info->DrawDeferred();
      }
    else
      User::InfoPrint(_L("EMyHttpInfo Err"));
    }
  else
    {
    CEikEdwin* content = LocateControlByUniqueHandle<CEikEdwin>(EMyHttpContent);
    if(content)
      {
      content->SetTextL(&aText);
      content->SetDimmed(EFalse);
      content->SetSize(content->MinimumSize());
      content->DrawDeferred();
      }
    else
      User::InfoPrint(_L("EMyHttpContent Err"));
    }
  }

⌨️ 快捷键说明

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