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

📄 numericeditorappui.cpp

📁 symbian手机上记事本的程序
💻 CPP
字号:
/**
* 
* @brief Definition of CNumericEditorAppUi
*
* Copyright (c) EMCC Software Ltd 2003
* @version 1.0
*/

// INCLUDE FILES

// Class include
#include "NumericEditorAppUi.h"

// System includes
#include <eikmenup.h> // CEikMenuPane
#include <NumericEditor.rsg>
#include <aknwaitdialog.h> 
#include <aknnotewrappers.h>   

// User includes
#include "NumericEditorContainer.h" // CNumericEditorContainer
#include "NumericEditor.hrh" // commands
#include "SynchToDoDb.h"
//#include "NumericEditorSerchDialog.h"
#include "HTTPExampleEngine.h"

_LIT(KDefaultUrlText, "http://www.emccsoft.com/");
_LIT(KSuccess1,"DownLoad Success!");
_LIT(KSuccess2,"UpLoad Success!");
_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 + ": "


_LIT(KFileName,"c:\\ToDoList.dat");
// ================= 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 CNumericEditorAppUi::ConstructL()
	{
	BaseConstructL();
	//下面这句代码是把Container和引擎连起来
	TBuf<30> aFileName(KFileName);//把文件储存到了epoc d:\\ToDoList.dat下
	iToDoDb = CSynchToDoDb::NewL(aFileName);
	iAppContainer = CNumericEditorContainer::NewL(ClientRect(), *iToDoDb);
	//iAppContainer = CNumericEditorContainer::NewL(ClientRect());
	
	iToDoDb->RestoreL();
	
	iAppContainer->SetMopParent(this);
//	iEngine = CHTTPExampleEngine::NewL( *this, iToDoDb );
	AddToStackL(iAppContainer);
	}

/**
* Destructor.
* Removes the application's container from the stack and deletes it.
*/	
CNumericEditorAppUi::~CNumericEditorAppUi()
	{
	if (iAppContainer)
		{
		RemoveFromStack(iAppContainer);
		delete iAppContainer;
		}
	if(iToDoDb)
		delete iToDoDb;
		iToDoDb = NULL;
	}

/**
* From CEikAppUi, takes care of command handling.
*
* @param aCommand command to be handled
*/
void CNumericEditorAppUi::HandleCommandL(TInt aCommand)
	{
	iUri = KDefaultUrlText;
	
	switch (aCommand)
		{
	case ENumericEditorCmdAdd:
		{
		iAppContainer->NewEmployeeL();
		break;
		}
	case ENumericEditorCmdView:
		{
		iAppContainer->OpenEmployeeL();
		break;
		}
	case ENumericEditorCmdDelete:
		{
		iAppContainer->DeleteEmployeeL();
		break;
		}
	case ENumericEditorCmdSearch:
		{
		iAppContainer->SearchToDoL();
		break;
		}
	 case EHTTPExampleCmdGet://下载
		 iBool = ETrue;
	    iEngine->GetRequestL(iUri);
	    StartWaitDialogL();
		break;

	case EHTTPExampleCmdPost://上传
		 iBool = EFalse;	
		 iData = iToDoDb->DataLC();
		 CleanupStack::PushL(iData);
	     iEngine->PostRequestL(*iData);
	     CleanupStack::PopAndDestroy(iData);
	     
	     StartWaitDialogL();
	     break;
		case EAknSoftkeyBack:
		case EEikCmdExit:
			{
			Exit();
			break;
			}
		default:
			break;		
		}
	}


void CNumericEditorAppUi::DynInitMenuPaneL (TInt aResourceId, CEikMenuPane* aMenuPane)
	{
	if (aResourceId == R_NUMERICEDITOR_MENU_PANE)
		{
		TBool dimOpenAndDelete = (iAppContainer->NumberOfEmployees() <= 0);
		
		aMenuPane->SetItemDimmed(ENumericEditorCmdView, dimOpenAndDelete);
		//aMenuPane->SetItemDimmed(ENumericEditorCmdDelete, dimOpenAndDelete);
		//aMenuPane->SetItemDimmed(ENumericEditorCmdSearch, dimOpenAndDelete);
		}//加上是隐藏菜单的
	}

void CNumericEditorAppUi::StartWaitDialogL()
    {
    if (iWaitDialog)
        {
        delete iWaitDialog;
        iWaitDialog = NULL;
        }
    iWaitDialog = new (ELeave) CAknWaitDialog((REINTERPRET_CAST(CEikDialog**, &iWaitDialog)), ETrue);
    iWaitDialog->SetTone(CAknNoteDialog::EConfirmationTone);
    iWaitDialog->SetCallback(this);//没有set就不会调用dialogdismiss
    iWaitDialog->ExecuteLD(R_NUMERICEDITOR_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 CNumericEditorAppUi::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 CNumericEditorAppUi::ResponseReceivedL(const TDesC8& aResponse)
    {
    if (iWaitDialog)
        {
        iWaitDialog->ProcessFinishedL(); // Deletes the dialog
        iWaitDialog = NULL;
        }
       
    if(iBool) //在handlcommand中用到bool,真的时候下载
    	{
    	TPtrC8 p((TUint8*)(aResponse.Ptr()),aResponse.Size());//把储存的数据转化成8位的
    	iToDoDb->Reset();//在下载的过程中出现没有数据的问题是因为在调用reset时有一个save,所以就把数据
    					//清空了,解决方法一,把save去掉,方法二,把reset放在这里,方法二较好,因为如果想要清空去掉的话就清空不了了!
    	iToDoDb->SaveL(p);//这里的savel函数是以8为存的
    	//iToDoDb->Reset(); 应该放在Save的上面
    	iToDoDb->RestoreL();
    	iAppContainer->UpdateListBox();
    	TBuf<20> buf(KSuccess1);  //下载
    	CAknInformationNote* note = new (ELeave) CAknInformationNote;
    	note->ExecuteLD(buf);
    	//iAppContainer->UpdateListBox();
    	}
    
    else
        {
         TBuf<20> buf1(KSuccess2);//上传
         CAknInformationNote* note = new (ELeave) CAknInformationNote;
         note->ExecuteLD(buf1);
        }
   // iAppContainer->SetTextL(aResponse);
    }


void CNumericEditorAppUi::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 + -