📄 wsexampleappui.cpp
字号:
//
//============================================================================
// Name : CWSExampleAppUi from CWSExampleAppUi.h
// Part of : WSExample
// Created : 10/08/2005 by Forum Nokia
// Implementation notes: simple ui control
//
// Version : 1.0
// Copyright: Nokia Corporation
//============================================================================
//
// INCLUDE FILES
#include <AknQueryDialog.h>
#include <t32wld.h>
#include <badesca.h>
#include <aknlists.h>
#include <eikmenup.h>
#include <aknnotewrappers.h>
#include "WSExampleAppUi.h"
#include "WSExampleDialog.h"
#include "WSEngine.h"
#include "WSExample.rsg"
#include "wsexample.hrh"
#include <avkon.hrh>
// constants
const TInt KTextBufferLength = 128;
const TInt KArrayGranularity = 5;
const TInt KTimeNumWidth = 2;
// literals for the ui
#include "literals.h"
// ---------------------------------------------------------
// CWSExampleAppUi::ConstructL()
//
// ---------------------------------------------------------
void CWSExampleAppUi::ConstructL()
{
BaseConstructL();
iWSConnection = CWSEngine::NewL();
iAppDialog = new (ELeave) CWSExampleDialog;
iAppDialog->SetMopParent( this );
// default unit is kilometers and nothing interesting on display.
iShowing = EShowingNothing;
iWSConnection->SetUnit( EWldKilometers );
iAppDialog->ExecuteLD( R_WSEXAMPLE_DIALOG );
AddToStackL( iAppDialog );
}
// ----------------------------------------------------
// CWSExampleAppUi::~CWSExampleAppUi()
// Destructor
// Frees reserved resources
// ----------------------------------------------------
CWSExampleAppUi::~CWSExampleAppUi()
{
if( iAppDialog )
{
RemoveFromStack( iAppDialog );
delete iAppDialog;
}
if( iWSConnection )
delete iWSConnection;
}
// ----------------------------------------------------
// CWSExampleAppUi::DynInitMenuPaneL()
// Alters the menu according to what information is
// currently showing in the listbox.
// ----------------------------------------------------
void CWSExampleAppUi::DynInitMenuPaneL( TInt aResourceId,
CEikMenuPane* aMenuPane)
{
if( aResourceId == R_WSEXAMPLE_MENU )
{
// if no current city has been chosen we don't allow
// the distance calculation.
aMenuPane->SetItemDimmed( EWSExampleCmdDistanceTo,
iShowing == EShowingCity?EFalse:ETrue );
aMenuPane->SetItemDimmed( EWSExampleCmdDistanceUnit,
iShowing == EShowingCity?EFalse:ETrue );
}
if( aResourceId == R_WSEXAMPLE_MENU_DATAFILE )
{
// in the database altering menu we don't show country and city
// altering options unless counrty or city is being shown.
aMenuPane->SetItemDimmed( EWSExampleCmdAddCity,
iShowing == EShowingCity?EFalse:ETrue );
aMenuPane->SetItemDimmed( EWSExampleCmdRemoveCity,
iShowing == EShowingCity?EFalse:ETrue );
aMenuPane->SetItemDimmed( EWSExampleCmdAddCountry,
iShowing == EShowingCountry?EFalse:ETrue );
aMenuPane->SetItemDimmed( EWSExampleCmdRemoveCountry,
iShowing == EShowingCountry?EFalse:ETrue );
}
}
// ----------------------------------------------------
// CWSExampleAppUi::HandleKeyEventL()
// Standard key press information forwasion.
// ----------------------------------------------------
TKeyResponse CWSExampleAppUi::HandleKeyEventL( const TKeyEvent& aKeyEvent,
TEventCode aType )
{
if( aType!=EEventKey )
{
return EKeyWasNotConsumed;
}
switch( aKeyEvent.iCode )
{
case EKeyUpArrow:
case EKeyDownArrow:
{
if( iAppDialog != NULL )
{
TKeyResponse result = iAppDialog->OfferKeyEventL( aKeyEvent,
aType );
return result;
}
}
break;
default:
break;
}
return EKeyWasNotConsumed;
}
// ----------------------------------------------------
// CWSExampleAppUi::ShowInfoL()
// Briefly shows small information note which contain
// aText as message.
// ----------------------------------------------------
void CWSExampleAppUi::ShowInfoL( const TPtrC aText )
{
CAknInformationNote* infoNote = new (ELeave) CAknInformationNote();
infoNote->ExecuteLD( aText );
}
// ----------------------------------------------------
// CWSExampleAppUi::AskPopupChoiseL()
// Shows a popupmenu list containing aList information
// On return to aReturn is copied the chosen text and
// if aIndex != NULL the index # of the chosen item
// is copied to.
// ----------------------------------------------------
TBool CWSExampleAppUi::AskPopupChoiseL( const TPtrC aPrompt,
CDesC16ArrayFlat* aList, TDes& aReturn, TInt* aIndex )
{
TBool rVal(EFalse);
CAknSinglePopupMenuStyleListBox* listBox =
new (ELeave) CAknSinglePopupMenuStyleListBox;
CleanupStack::PushL( listBox );
CAknPopupList* popupList = CAknPopupList::NewL( listBox,
R_AVKON_SOFTKEYS_OK_BACK );
CleanupStack::PushL( popupList );
listBox->ConstructL( popupList, EAknListBoxMenuList );
popupList->SetTitleL( aPrompt );
// we assume the creator of the array to delete the array.
listBox->Model()->SetOwnershipType( ELbmDoesNotOwnItemArray );
listBox->Model()->SetItemTextArray( aList );
if( popupList->ExecuteLD() )
{
aReturn.Copy( aList->operator[](listBox->CurrentItemIndex()) );
if( aIndex != NULL )
{
*aIndex = listBox->CurrentItemIndex();
}
rVal = ETrue;
}
CleanupStack::Pop( popupList );
CleanupStack::PopAndDestroy( listBox );
return rVal;
}
// ----------------------------------------------------
// CWSExampleAppUi::QueryTextL()
// Shows a dialog with aPrompt note and waits for text
// input which is then copied to aReturn
// ----------------------------------------------------
TBool CWSExampleAppUi::QueryTextL( const TPtrC aPrompt, TDes& aReturn )
{
CAknTextQueryDialog* textQuery = CAknTextQueryDialog::NewL( aReturn );
CleanupStack::PushL( textQuery );
textQuery->SetPromptL( aPrompt );
CleanupStack::Pop( textQuery );
return textQuery->ExecuteLD( R_DATAQUERY_DATA_QUERY );
}
// ----------------------------------------------------
// CWSExampleAppUi::HandleCommandL()
// Normal menu command handling
// ----------------------------------------------------
void CWSExampleAppUi::HandleCommandL( TInt aCommand )
{
switch ( aCommand )
{
case EAknSoftkeyExit:
case EEikCmdExit:
{
Exit();
break;
}
// ------------------------------------------------
// Ask for (partial) city name and show the city
// information in the lisbox.
case EWSExampleCmdSearchCities:
SearchCitiesL();
break;
// ------------------------------------------------
// Ask for (partial) country name and show
// the country information in the lisbox.
case EWSExampleCmdSearchCountries:
SearchCountriesL();
break;
// ------------------------------------------------
// Calculate distance between two cities.
case EWSExampleCmdDistanceTo:
DistanceUIL();
break;
// ------------------------------------------------
// Import world server data file.
case EWSExampleCmdImportDatafile:
ImportDataFileL();
break;
// ------------------------------------------------
// Export world server data file.
case EWSExampleCmdExportDatafile:
ExportDataFileL();
break;
// ------------------------------------------------
// Reset world server database to rom version.
case EWSExampleCmdResetDatabase:
ResetDBL();
break;
// ------------------------------------------------
// Set distance unit to kilometers.
case EWSExampleCmdUnitKm:
iWSConnection->SetUnit( EWldKilometers );
break;
// ------------------------------------------------
// Set distance unit to miles.
case EWSExampleCmdUnitMile:
iWSConnection->SetUnit( EWldMiles );
break;
// ------------------------------------------------
// Add new city to world server database.
case EWSExampleCmdAddCity:
CreateCityUIL();
break;
// ------------------------------------------------
// remove city from world server database
case EWSExampleCmdRemoveCity:
DeleteCityL();
break;
// ------------------------------------------------
// Add new country to world server database.
case EWSExampleCmdAddCountry:
CreateCountryUIL();
break;
// ------------------------------------------------
// remove country from world server database
case EWSExampleCmdRemoveCountry:
DeleteCountryL();
break;
// ------------------------------------------------
default:
break;
}
}
// ---------------------------------------------------------
// CWSExampleAppUi::FillListBoxL()
// Fill main dialog listbox with city information
// ---------------------------------------------------------
void CWSExampleAppUi::FillListBoxL( TCityData& aCityData )
{
TBuf<KTextBufferLength> formatBuffer;
CDesC16ArrayFlat* cityInfo =
new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
CleanupStack::PushL( cityInfo );
cityInfo->Reset();
formatBuffer.Copy( WSE_CITYNAME );
formatBuffer.Append( aCityData.iCity );
cityInfo->AppendL( formatBuffer );
formatBuffer.Copy( WSE_CITYCOUNTRY );
formatBuffer.Append( aCityData.iCountry );
cityInfo->AppendL( formatBuffer );
formatBuffer.Copy( WSE_CITYAREACODE );
formatBuffer.Append( aCityData.iAreaCode );
cityInfo->AppendL( formatBuffer );
switch( aCityData.iDaylightSavingZone )
{
default:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEUNKNOWN );
break;
case EDstHome:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEEDSTHOME );
break;
case EDstNone:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEEDSTNONE );
break;
case EDstEuropean:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEEDSTEUROPEAN );
break;
case EDstNorthern:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEEDSTNORTHERN );
break;
case EDstSouthern:
cityInfo->AppendL( WSE_CITYDAYLIGHTSAVINGZONEEDSTSOUTHERN );
break;
}
formatBuffer.Copy( WSE_CITYLATLONG );
formatBuffer.AppendNum( aCityData.iLatLong.MinutesLat() );
formatBuffer.Append( WSE_SLASH );
formatBuffer.AppendNum(aCityData.iLatLong.MinutesLong() );
cityInfo->AppendL( formatBuffer );
formatBuffer.Copy( WSE_CITYUTC );
formatBuffer.AppendNum( aCityData.iUniversalTimeOffset );
cityInfo->AppendL( formatBuffer );
TTime sunrise;
TTime sunset;
TBuf<KTextBufferLength> timeString;
TDateTime dateTime;
TInt err;
err = iWSConnection->Sunlight( aCityData, sunrise, sunset );
formatBuffer.Copy( WSE_CITYSUNRISETODAY );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -