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

📄 magictrainappui.cpp

📁 SYMBIAN S60 2ND列车时刻表软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <Train.rsg>
#include <aknlists.h> 
#include <aknselectionlist.h> 
#include <eikmenub.h> 
#include <aknmessagequerydialog.h> 
#include <eikclbd.h>
#include <pathinfo.h> 
#include <s32file.h>
#include "MagicTrain.pan"
#include "MagicTrainAppUi.h"
#include "MagicTrainAppView.h"
#include "MagicTrainDocument.h"
#include "Engine.h"
#include "AskTrainDialog.h"
#include "AskStationDialog.h"
#include "AskOneStationDialog.h"
#include "MagicTrain.hrh"
#include "DownloadEntity.h"
#include "StringUtil.h"

//http://doudouwa.siteem.com/other/doudou/TRAINS60V2.SIS
_LIT8(KDownSis,"http://doudouwa.siteem.com/other/doudou/TRAINS60V2_");
_LIT8(KDownSisExt8,".SISX");
_LIT(KDownSisExt,".SISX");

_LIT8(KUpdateS,"http://doudouwa.siteem.com/other/doudou/update/1.6/update.html");
_LIT8(KUpdateD,"http://doudouwa.siteem.com/other/doudou/update/1.6/");
_LIT8(KUpdateDExt8,".html");
_LIT(KUpdateDExt,".html");
_LIT8(KUpdateDataExt8,".txt");
_LIT(KUpdateDataExt,".txt");
_LIT(KCfgPath,"Nokia\\Installs\\ddtrain\\config.ini");

_LIT(KStationFilePath,"Nokia\\Installs\\ddtrain\\station.dll");
_LIT(KTrainFilePath,"Nokia\\Installs\\ddtrain\\train.dll");
_LIT(KTrainLineFilePath,"Nokia\\Installs\\ddtrain\\trainline.dll");

_LIT8(KVersion,"1.6");


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


// -----------------------------------------------------------------------------
// CMagicTrainAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMagicTrainAppUi::ConstructL()
    {
    // Initialise app UI with standard value.
    BaseConstructL();
    iFs.Connect();
	iEngine = Engine::NewL(this);
	// Create view object
    CEikStatusPane* statusPane = StatusPane();
    statusPane->SwitchLayoutL(R_AVKON_STATUS_PANE_LAYOUT_EMPTY);
	statusPane =NULL;
	iAppView = CMagicTrainAppView::NewL( ClientRect() ,this);

	// Create a file to write the text to
    CleanupStack::PushL( iAppView );
//    AddViewL( iAppView );
    CleanupStack::Pop( iAppView );
//    ActivateLocalViewL( iAppView->Id() );
	ConstructVersionL();
	ConstructFilePathL();
	
	AddToStackL(iAppView); 
	}

void CMagicTrainAppUi::ConstructVersionL()
{
	TFileName aFilePath;
#ifdef _DEBUG
	aFilePath.Append(_L("C:\\"));
#else
	aFilePath.Append(_L("C:\\"));
#endif
    aFilePath.Append(KCfgPath);
    RFileReadStream rs;
    TInt err;
	err = rs.Open(iFs,aFilePath,EFileRead);
	if (err != KErrNone) {
    	aFilePath.SetLength(0);
    	aFilePath.Append(PathInfo::MemoryCardRootPath());
    	aFilePath.Append(KCfgPath);
    	rs.Close();
    	if ( rs.Open(iFs,aFilePath,EFileRead) != KErrNone) {    		
    		Exit();
    	}else{
    		iDataPath.Copy(aFilePath.Left(aFilePath.Length()-10));
    	}
	}else {
		iDataPath.Copy(aFilePath.Left(aFilePath.Length()-10));
	}
	rs.ReadL(iDataVersion8,8);
	iDataVersion.Copy(iDataVersion8);
    rs.Close();
}

void CMagicTrainAppUi::SaveVersionL(const TDesC8& version)
{
	TFileName aFilePath;
#ifdef _DEBUG
	aFilePath.Append(_L("C:\\"));
#else
	aFilePath.Append(_L("C:\\"));
#endif
    aFilePath.Append(KCfgPath);
    RFileWriteStream rs;
    TInt err;
	err = rs.Open(iFs,aFilePath,EFileWrite);
	if (err != KErrNone) {
    	aFilePath.SetLength(0);
    	aFilePath.Append(PathInfo::MemoryCardRootPath());
    	aFilePath.Append(KCfgPath);
    	rs.Close();
    	if ( rs.Open(iFs,aFilePath,EFileWrite) != KErrNone) {    		
    		Exit();
    	}
	}
	rs.WriteL(iDataVersion8);
    rs.Close();
}
// -----------------------------------------------------------------------------
// CMagicTrainAppUi::CMagicTrainAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
void CMagicTrainAppUi::DynInitMenuPaneL(
    TInt /*aResourceId*/,CEikMenuPane* /*aMenuPane*/)
    {
    // No implementation required
    }

// ----------------------------------------------------------------------------
// CRegistrationAppUi::HandleKeyEventL(
//     const TKeyEvent& aKeyEvent,TEventCode /*aType*/)
// takes care of key event handling
// ----------------------------------------------------------------------------
//
TKeyResponse CMagicTrainAppUi::HandleKeyEventL(
    const TKeyEvent& /*aKeyEvent*/,TEventCode /*aType*/)
    {
    return EKeyWasNotConsumed;
    }


CMagicTrainAppUi::CMagicTrainAppUi(CMagicTrainDocument* aDoc)
    {
    // No implementation required
    	iDoc = aDoc;
    	iVersion.Copy(KVersion);
    }

// -----------------------------------------------------------------------------
// CMagicTrainAppUi::~CMagicTrainAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMagicTrainAppUi::~CMagicTrainAppUi()
    {
    iFs.Close();
    if (iEngine) delete iEngine;
    if (iAskTrainDialog) delete iAskTrainDialog;
	if (iAskStationDialog) delete iAskStationDialog;
	if (iOTResult) {
		iOTResult->ResetAndDestroy();
		iOTResult = NULL;
	}
	if (iTSSResult) {
		iTSSResult->ResetAndDestroy();
		iTSSResult = NULL;
	}
	iApaLsSession.Close();
    if ( iAppView )
        {
        delete iAppView;
        iAppView = NULL;
        }
    }

void CMagicTrainAppUi::ShowTrainMsg(const TDesC& head,const TDesC& msg)
{
	CEikonEnv::InfoWinL(head,msg);
}
// -----------------------------------------------------------------------------
// CMagicTrainAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void CMagicTrainAppUi::HandleCommandL( TInt aCommand )
    {
    switch( aCommand )
        {
        case EEikCmdExit:
        case EAknSoftkeyExit:
        	{
				HBufC* noteText;
				noteText = StringLoader::LoadLC(R_QUERY_EXIT);
	
							
				CAknQueryDialog* dlg = CAknQueryDialog::NewL( );
				if ( dlg->ExecuteLD(R_QUERY_EXIT_QUERY, noteText->Des()))
				{
					CleanupStack::PopAndDestroy(noteText);
	//				delete dlg;
					Exit();
				}
	            CleanupStack::PopAndDestroy(noteText);
        	}	
            break;

        case ECommand1:
            {	
            	if (iAskTrainDialog) delete iAskTrainDialog;
            	iAskTrainDialog = new ( ELeave ) CAskTrainDialog(this);
				iAskTrainDialog->SetMopParent( this );
    			iAskTrainDialog->ExecuteLD( R_ASK_TRAIN_DIALOG );
    			AddToStackL( iAskTrainDialog );
            	
            }
            break;
		case ECommand2:
			{
				if (iAskStationDialog) delete iAskStationDialog;
				iAskStationDialog = new ( ELeave ) CAskStationDialog(this);
				iAskStationDialog->SetMopParent( this );
    			iAskStationDialog->ExecuteLD( R_ASK_STATION_DIALOG );
    			AddToStackL( iAskStationDialog );
    			
			}
			break;
		case ESearchOneStation:
			{
				if (iAskOneStationDialog) delete iAskOneStationDialog;
            	iAskOneStationDialog = new ( ELeave ) CAskOneStationDialog(this);
				iAskOneStationDialog->SetMopParent( this );
    			iAskOneStationDialog->ExecuteLD( R_ASK_ONESTATION_DIALOG );
    			AddToStackL( iAskOneStationDialog );
			}
			break;
		case EStationReverse:
			{
				if (iStationName1.Length() > 0 && iStationName2.Length() > 0)
				{
					TBuf<KMaxAskStatonNameLength> station;	
					station.Copy(iStationName2);
					iStationName2.Copy(iStationName1);
					iStationName1.Copy(station);
					
					if (iTSSResult) {
						iTSSResult->ResetAndDestroy();
						iTSSResult = NULL;
					}
					
					iTSSResult = new RPointerArray<CTSSResult>(10);
					TInt err = iEngine->GetTrainByTwoStations(iStationName1,iStationName2,iTSSResult);
					if (err == -1)
					{
						HBufC* noteText;
						noteText = StringLoader::LoadLC(R_ASKSTATION_NOSTATION);
						CAknInformationNote* note = new (ELeave) CAknInformationNote();
						note->ExecuteLD(*noteText);
						CleanupStack::PopAndDestroy(noteText);	
					}else if(err == -2)
					{
						HBufC* noteText;
						noteText = StringLoader::LoadLC(R_ASKSTATION_NORESULT);
						CAknInformationNote* note = new (ELeave) CAknInformationNote();
						note->ExecuteLD(*noteText);
						CleanupStack::PopAndDestroy(noteText);
					}
					if (!iTSSResult || iTSSResult->Count() == 0) {
						HBufC* noteText;
						noteText = StringLoader::LoadLC(R_ASKSTATION_NORESULT);
						CAknInformationNote* note = new (ELeave) CAknInformationNote();
						note->ExecuteLD(*noteText);
						CleanupStack::PopAndDestroy(noteText);
						break;
					}
					SetMenuBar(EStationResult);
					
					iAppView->SetTSSResult(iStationName1,iStationName2,iTSSResult);
					
				}else {
					HBufC* noteText;
					noteText = StringLoader::LoadLC(R_ASKSTATION_NOSTATION);
					CAknInformationNote* note = new (ELeave) CAknInformationNote();
					note->ExecuteLD(*noteText);
					CleanupStack::PopAndDestroy(noteText);	
				}
				break;
				 
			}
		case EAskOneStationOk:
			{
//				RFs fs;
//				fs.Connect();
//				RFileWriteStream ws;
//				ws.Open(fs,_L("C:\\Nokia\\Installs\\1.log"),EFileWrite);
//				ws.WriteL(_L("Begin"));
//				ws.CommitL();
				static_cast<CEikEdwin*>(( iAskOneStationDialog->Control( EAskOneStationDlgCIdNameEditor ) ) )->GetText( iStationName );

           		if ( iAskOneStationDialog )
		        {
		       		RemoveFromStack( iAskOneStationDialog );
		       		delete iAskOneStationDialog;
	    			iAskOneStationDialog = NULL;
		        }
//   		 		ws.WriteL(_L("1"));
//				ws.CommitL();
				iStationName.SetLength(2);
				iStationName[0]=0x5317;
				iStationName[1]=0x4EAC;
				if (iStationName.Length() > 0)
				{
					if (iOSResult) {
						iOSResult->ResetAndDestroy();
						iOSResult = NULL;
					}
//					ws.WriteL(_L("2"));
//					ws.CommitL();
					iOSResult = new RPointerArray<COSResult>(10);
//					ws.WriteL(_L("3"));
//					ws.CommitL();
					if (iEngine->GetTrainByStation(iStationName,iOSResult))
					{
//						ws.WriteL(_L("4"));
//						ws.CommitL();
						if (iOSResult->Count() == 0) {
							HBufC* noteText;
							noteText = StringLoader::LoadLC(R_ASKSTATION_NORESULT);
							CAknInformationNote* note = new (ELeave) CAknInformationNote();
							note->ExecuteLD(*noteText);
							CleanupStack::PopAndDestroy(noteText);
							break;
						}
//						ws.WriteL(_L("5"));
//						ws.CommitL();
						SetMenuBar(R_ONESTATIONRESULT_MENU);
						iAppView->SetOSResult(iStationName,iOSResult);
//						ws.WriteL(_L("6"));
//						ws.CommitL();
					}else{
						HBufC* noteText;
						noteText = StringLoader::LoadLC(R_ASKSTATION_NORESULT);
						CAknInformationNote* note = new (ELeave) CAknInformationNote();
						note->ExecuteLD(*noteText);
						CleanupStack::PopAndDestroy(noteText);		
					}

				}else {
					HBufC* noteText;
					noteText = StringLoader::LoadLC(R_ASKTRAIN_NOTINPUT);
					CAknInformationNote* note = new (ELeave) CAknInformationNote();
					note->ExecuteLD(*noteText);
					CleanupStack::PopAndDestroy(noteText);		
				}
//				ws.WriteL(_L("7"));
//				ws.CommitL();
//				ws.Close();
//				fs.Close();
			}
			break;
		case EAskStationOk:
			{
				static_cast<CEikEdwin*>(( iAskStationDialog->Control( EAskstationDlgCIdNameEditor1 ) ) )->GetText( iStationName1 );
           		static_cast<CEikEdwin*>(( iAskStationDialog->Control( EAskstationDlgCIdNameEditor2 ) ) )->GetText( iStationName2 );
           		
           		if ( iAskStationDialog )
		        {
		       		RemoveFromStack( iAskStationDialog );
		       		delete iAskStationDialog;
	    			iAskStationDialog = NULL;
		        }
   		 		
				if (iStationName1.Length() > 0 && iStationName2.Length() > 0)

⌨️ 快捷键说明

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