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

📄 weathershow.cpp

📁 手机天气预报系统
💻 CPP
字号:
/*
 ============================================================================
 Name		: WeatherShow.cpp
 Author	  : Richie Chyi
 Copyright   : Copyright?2008
 Description : 
 ============================================================================
 */

#include<EIKENV.H> // For Test
#include <aknwaitdialog.h>
#include <stringloader.h>
#include <QiQiWeather_0xE6E51F33.rsg>

#include "WeatherShow.h"
#include "QiQiWeather.hrh"
#include "QiQiWeatherAppUi.h"
#include "Setting.h"

// Example: "http://www.google.com/ig/api?weather=Shanghai,China"
_LIT(KGoogleWeatherApiUrl, "http://www.google.com/ig/api?weather=");

CWeatherShow* CWeatherShow::NewL()
	{
	CWeatherShow* self = NewLC();
	CleanupStack::Pop(self);
	
	return self;
	}

CWeatherShow* CWeatherShow::NewLC()
	{
	CWeatherShow* self = new (ELeave)CWeatherShow;
	CleanupStack::PushL(self);
	self->ConstructL();
	
	return self;
	}

CWeatherShow::CWeatherShow()
:iWeatherDetails(static_cast<CQiQiWeatherAppUi*>(CEikonEnv::Static()->AppUi())->WeatherDetails())
	{

	}
CWeatherShow::~CWeatherShow()
	{
	if(iHttpEngine)
		{
		delete iHttpEngine;
		iHttpEngine = NULL;
		}
	
	if(iWaitDialog)
		{
		iWaitDialog->ProcessFinishedL();
		delete iWaitDialog;
		iWaitDialog = NULL;
		}
	
	if(iXMLBuffer)
		{
		delete iXMLBuffer;
		iXMLBuffer = NULL;
		}
	
	if(iXMLHandler)
		{
		delete iXMLHandler;
		iXMLHandler = NULL;
		}
	}

void CWeatherShow::ConstructL()
	{
	iHttpEngine = CQiQiHTTPEngine::NewL(*this);
	
	iWaitDialog = NULL;
	iXMLBuffer = NULL;
	}

void CWeatherShow::ResponseStatusL(TInt /*aStatusCode*/, const TDesC8& /*aSessionId*/)
	{
	
	}

void CWeatherShow::ResponseBodyDataL(const TDesC& aBuffer)
	{
	// 获取XML
	if(NULL == iXMLBuffer)
		{
		iXMLBuffer = HBufC::NewL(aBuffer.Length());
		iXMLBuffer->Des().Copy(aBuffer);
		}
	else
		{	
		iXMLBuffer = iXMLBuffer->ReAllocL(aBuffer.Length()+iXMLBuffer->Length());
		iXMLBuffer->Des().Append(aBuffer);
		}
	}

void CWeatherShow::ResponseReceivedL()
	{	
	RemoveWaitDialogL();
	
	// 开始解析XML
	iXMLHandler = CXmlHandler::NewL(iWeatherDetails, *this);
	iXMLHandler->StartParsingL(*iXMLBuffer);
	}

void CWeatherShow::ShowWeatherL()
	{	
	TBuf<KMaxUriLength> uri;
	uri.Append(KGoogleWeatherApiUrl);
	// 读取配置中的城市
	CSetting* setting = CSetting::NewLC();
	setting->ReadFromFileL();
	CSetting::CityNameForIndex(setting->CityIndex(), uri);
	
	CleanupStack::PopAndDestroy(setting);
	
	iHttpEngine->GetRequestL(uri, _L8("text/*"));
	
	// 创建等待对话框
	iWaitDialog = new (ELeave) CAknWaitDialog(reinterpret_cast<CEikDialog**>(&iWaitDialog),ETrue);
	// 设置回调
	iWaitDialog->SetCallback(this);
	// 设置超时时间为三秒
	iWaitDialog->SetTimeout(CAknNoteDialog::ELongTimeout);

	HBufC* prompt = StringLoader::LoadLC(R_WAIT_DIAOG_PROMPT);
	iWaitDialog->SetTextL(*prompt);
	
	CleanupStack::PopAndDestroy(prompt);

	iWaitDialog->ExecuteLD(R_GENERAL_WAIT_NOTE);
	}

void CWeatherShow::RemoveWaitDialogL()
	{
	if ( iWaitDialog )
		{		
		iWaitDialog->ProcessFinishedL();
		if (NULL != iHttpEngine)
			{
			iHttpEngine->Cancel();
			}
		}
	}

void CWeatherShow::DialogDismissedL(TInt aButtonId)
	{
	if(aButtonId == EAknSoftkeyCancel)
		{
		if (NULL != iHttpEngine)
			{
			iHttpEngine->Cancel();
			}
		}
	}

void CWeatherShow::ParseCompleted()
	{	
	// 更新天气
	CQiQiWeatherAppUi* appui = 
			static_cast<CQiQiWeatherAppUi*>(CEikonEnv::Static()->AppUi());
	if(appui)
		{
		appui->UpdataWeather();
		}
	}

⌨️ 快捷键说明

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