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

📄 wsexampleappui.cpp

📁 Symbian智能手机操作系统源代码值的参考_服务器
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        ShowInfoL( msg );
        }

    FillListBoxL( country );
    }


// ---------------------------------------------------------
//  CWSExampleAppUi::AskNumberL()
//  Ask numerical input from user
// ---------------------------------------------------------
TInt CWSExampleAppUi::AskNumberL( const TPtrC aPrompt, TInt& aReturn )
    {
    TInt err(KErrNone);
    TBuf<KTextBufferLength>    userText;
    TLex numberParser;

    do
        {
        if( err != KErrNone )
            {
            TPtrC msg(WSE_NUMBEREXPECTED);
            ShowInfoL( msg );
            }

        if( QueryTextL( aPrompt, userText ) == EFalse )
            {
            return KErrCancel;
            }

        numberParser.operator=( userText );
        err = numberParser.Val( aReturn );

        } while( err != KErrNone );

        return err;
    }


// ---------------------------------------------------------
//  CWSExampleAppUi::AskDLSZoneL()
//  Ask for daylight saving zone
// ---------------------------------------------------------
TInt CWSExampleAppUi::AskDLSZoneL( TDaylightSavingZone& aDLSZone )
    {
    TInt                    index;
    TBuf<KTextBufferLength> temp;
    TPtrC                   text(WSE_DAYLIGHTSAVINGZONE);

    CDesC16ArrayFlat* dlsZoneList = 
        new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
    CleanupStack::PushL( dlsZoneList );

    dlsZoneList->AppendL( WSE_EDSTHOME );
    dlsZoneList->AppendL( WSE_EDSTNONE );
    dlsZoneList->AppendL( WSE_EDSTEUROPEAN );
    dlsZoneList->AppendL( WSE_EDSTNORTHERN );
    dlsZoneList->AppendL( WSE_EDSTSOUTHERN );

    if( AskPopupChoiseL( text, dlsZoneList, temp, &index ) == EFalse )
        {
        CleanupStack::PopAndDestroy( dlsZoneList );
        return KErrCancel;
        }
    
    CleanupStack::PopAndDestroy( dlsZoneList );

    // this order 0..4 is coming from the order in which 
    // the texts were earlier shown to user in the listbox
    // (see above the creation of dlsZoneList)
    switch( index )
        {
    default:
        break;
    case 0:
        aDLSZone = EDstHome;
        break;
    case 1:
        aDLSZone = EDstNone;
        break;
    case 2:
        aDLSZone = EDstEuropean;
        break;
    case 3:
        aDLSZone = EDstNorthern;
        break;
    case 4:
        aDLSZone = EDstSouthern;
        break;
        }
    return KErrNone;
    }


// ---------------------------------------------------------
//  CWSExampleAppUi::SearchCitiesL()
//  Search a city and show it in the listbox
// ---------------------------------------------------------
void CWSExampleAppUi::SearchCitiesL()
    {
    TBuf<KTextBufferLength>    placeName;
    CDesC16ArrayFlat* citiesList = 
        new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
    CleanupStack::PushL( citiesList );

    // ask for the city name
    TPtrC msg(WSE_CITYNAME2);
    if( QueryTextL( msg, placeName) )
        {
        // get the list of cities matching the search string
        iWSConnection->ListCitiesL( placeName, citiesList );

        if( citiesList->Count() == 0 )
            {
            TPtrC msg(WSE_NOMATCHINGCITYFOUND);
            ShowInfoL( msg );
            }
        else
            {
            if( citiesList->Count() > 1 )
                {
                // there was more than one city mathing
                // to the search string user typed
                TPtrC msg(WSE_CHOOSECITY);
                if( AskPopupChoiseL( msg, citiesList, placeName ) )
                    {
                    // this is used to mark that a choise was made.
                    citiesList->Reset();
                    }
                }
            else
                {
                placeName.Copy( citiesList->operator[](0) );
                }

            if( citiesList->Count() <= 1 )
                {
                // Get the info of the chosen city of whose
                // name was stored in placeName and put it on display.
                // No need to wonder about return value of FindFirst
                // since the name used was initially coming from the
                // world server itself -> there is a match.
                iWSConnection->FindFirst( placeName, iCurrentCity );
                FillListBoxL( iCurrentCity );
                iShowing = EShowingCity;
                }
            }
        }
    CleanupStack::PopAndDestroy( citiesList );
    }

// ---------------------------------------------------------
//  CWSExampleAppUi::SearchCountriesL()
//  Search for a country and show it in the listbox
// ---------------------------------------------------------
void CWSExampleAppUi::SearchCountriesL()
    {
    TBuf<KTextBufferLength>    placeName;

    CDesC16ArrayFlat* countriesList = 
        new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
    CleanupStack::PushL( countriesList );

    // ask for the country name
    TPtrC msg(WSE_COUNTRYNAME);
    if( QueryTextL( msg, placeName) )
        {
        // get the list of countries matching the search string
        iWSConnection->ListCountriesL( placeName, countriesList );

        if( countriesList->Count() == 0 )
            {
            TPtrC msg(WSE_NOMATCHINGCOUNTRYFOUND);
            ShowInfoL( msg );
            }
        else
            {
            if( countriesList->Count() > 1 )
                {
                // there was more than one country mathing
                // to the search string user typed
                TPtrC msg(WSE_CHOOSECOUNTRY);
                if( AskPopupChoiseL( msg, countriesList, placeName ) )
                    {
                    // this is used to mark that a choise was made.
                    countriesList->Reset();
                    }
                }
            else
                {
                placeName.Copy( countriesList->operator[](0) );
                }

            if( countriesList->Count() <= 1 )
                {
                // Get the info of the chosen country of whose
                // name was stored in placeName and put it on display
                // No need to wonder about return value of FindFirst
                // since the name used was initially coming from the
                // world server itself -> there is a match.
                iWSConnection->FindFirst( placeName, 
                    iCurrentCountry );
                FillListBoxL( iCurrentCountry );
                iShowing = EShowingCountry;
                }
            }
        }
    CleanupStack::PopAndDestroy( countriesList );
    }


// ---------------------------------------------------------
//  CWSExampleAppUi::ImportDataFileL()
//  Import world server data file
// ---------------------------------------------------------
void CWSExampleAppUi::ImportDataFileL()
    {
    TBuf<KTextBufferLength>     fileName;
    TInt                        err;

    TPtrC msg(WSE_IMPORTFILENAME);
    if( QueryTextL( msg, fileName) )
        {
        if( (err = iWSConnection->DataFileImport( fileName ))
            == KErrNone )
            {
            TPtrC msg(WSE_SUCCESS);
            ShowInfoL( msg );
            }
        else
            {
            // Should be noted that if user export a datafile
            // the world server use that saved file until 
            // the export is made again on different name.
            // What this mean is when trying to import
            // exported file you'll get -14(KErrInUse) if the
            // file you import is file you last exported.
            // World server remember this connection also
            // through boot of the system.
            fileName.Copy( WSE_ERROR );
            fileName.AppendNum( err );
            ShowInfoL( fileName );
            }
        }
    }


// ---------------------------------------------------------
//  CWSExampleAppUi::ExportDataFileL()
//  Export world server data file
// ---------------------------------------------------------
void CWSExampleAppUi::ExportDataFileL()
    {
    TBuf<KTextBufferLength>    fileName;

    TPtrC msg(WSE_EXPORTFILENAME);
    if( QueryTextL( msg, fileName) )
        {
        if( iWSConnection->DataFileExport( fileName ) == KErrNone )
            {
            TPtrC msg(WSE_SUCCESS);
            ShowInfoL( msg );
            }
        else
            {
            TPtrC msg(WSE_ERRORDURINGEXPORT);
            ShowInfoL( msg );
            }
        }
    }

// ---------------------------------------------------------
//  CWSExampleAppUi::ResetDBL()
//  Reset world server database to rom version
// ---------------------------------------------------------
void CWSExampleAppUi::ResetDBL()
    {
    if( iWSConnection->ResetDatabase() == KErrNone )
        {
        TPtrC msg(WSE_DATABASERESET);
        ShowInfoL( msg );
        }
    else
        {
        TPtrC msg(WSE_ERRORDURINGRESET);
        ShowInfoL( msg );
        }
    }

// ---------------------------------------------------------
//  CWSExampleAppUi::DeleteCityL()
//  Delete city from world server database
// ---------------------------------------------------------
void CWSExampleAppUi::DeleteCityL()
    {
    CDesC16ArrayFlat* citiesList = 
        new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
    CleanupStack::PushL( citiesList );

    TBuf<KTextBufferLength> temp;

    temp.Copy( WSE_EMPTY );
    iWSConnection->ListCitiesL( temp, citiesList );

    // ask for the city name with the list of all cities
    TPtrC msg(WSE_DELETECITY);
    if( AskPopupChoiseL( msg, citiesList, temp ) == EFalse )
        {
        CleanupStack::PopAndDestroy( citiesList );
        return;
        }

    CleanupStack::PopAndDestroy( citiesList );

    if( iWSConnection->RemoveCity( temp ) != KErrNone )
        {
        // you'll usually get this when deleting
        // a city located in rom.
        TPtrC msg(WSE_ERRORWHILEREMOVINGCITY);
        ShowInfoL( msg );
        }
    }

// ---------------------------------------------------------
//  CWSExampleAppUi::DeleteCountryL()
//  Delete country from world server database
// ---------------------------------------------------------
void CWSExampleAppUi::DeleteCountryL()
    {
    TBuf<KTextBufferLength> temp;

    CDesC16ArrayFlat* countriesList = 
        new (ELeave)CDesC16ArrayFlat( KArrayGranularity );
    CleanupStack::PushL( countriesList );

    temp.Copy( WSE_EMPTY );
    iWSConnection->ListCountriesL( temp, countriesList );

    // ask for the country name with the list of all countries
    TPtrC msg(WSE_DELETECOUNTRY);
    if( AskPopupChoiseL( msg, countriesList, temp ) == EFalse )
        {
        CleanupStack::PopAndDestroy( countriesList );
        return;
        }
    CleanupStack::PopAndDestroy( countriesList );

    if( iWSConnection->RemoveCountry( temp ) != KErrNone )
        {
        // you'll usually get this when deleting
        // a country located in rom.
        TPtrC msg(WSE_ERRORWHILEREMOVINGCOUNTRY);
        ShowInfoL( msg );
        }
    else
        {
        TPtrC msg(WSE_REMOVED);
        ShowInfoL( msg );
        }
    }

// End of File  

⌨️ 快捷键说明

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