Wiley.Developing.Software.for.Symbian.OS.2nd.Edition.Dec.2007 (779887), страница 33
Текст из файла (страница 33)
The example target platform line:[0x101F7961], 0, 0, 0, {"S60ProductID"}is a requisite statement that the ‘component’ named S60ProductID,with a UID of 0x101F7961, and version number 0.0.0 or higher, mustexist in order for the installation to continue. Note that in the case ofhardware dependency, like the case just mentioned, brackets are used toenclose the UID instead of parentheses.5.9.4Language SupportMultiple translated versions of an application can exist within a singleSIS file. When a user installs a SIS file, they are prompted to select whichlanguage they would like installed.To specify the language variants that you want to be included, add alanguage line at the top of your PKG file.
The language line begins with‘&’ and contains a list of comma-separated language codes. Below is alist of some common languages. Reference the Symbian OS library in theSDK documentation for the complete list.AM – US EnglishAS – Austrian GermanAU – Australian EnglishBF – Belgian FrenchBL – Belgian FlemishCS – CzechDA – DanishDU – DutchEN – UK EnglishFI – FinnishFR – FrenchGE – German158SYMBIAN OS BUILD ENVIRONMENTHK – Hong Kong ChineseHU – HungarianIC – IcelandicIF – International FrenchIT – ItalianJA – JapaneseNO – NorwegianNZ – New ZealandPL – PolishPO – PortugueseRU – RussianSF – Swiss FrenchSG – Swiss GermanSK – SlovakSL – SlovenianSP – SpanishSW – SwedishTC – Taiwan ChineseTH – ThaiTU – TurkishZH – Prc ChineseAn example language line is:&EN, FR, FIwhich specifies that the SIS file contains English, French, and Finnishlanguage variants.If a language line is not included, &EN is assumed.How does makesis use the language information?So far, we have used only language-independent statements in oursample PKG file, which will install exactly the same regardless of anadded language line, or a language selection by the user.In order to use the language information, you must use languagedependent versions of the applicable PKG statements.Language-dependent filesThe first rule in internationalizing an application is to keep the languagedependent parts of your application separate (i.e., in different files) fromthe language-independent parts.
For example, Symbian OS uses resourcefiles to contain text strings, and a separate resource file would exist forINSTALLING APPLICATIONS ON THE SMARTPHONE159each language. When the user selects a particular language to install, youwant to install the appropriate resource file for that language.As an example, the following .PKG line specifies the installation of aresource file based on the language:&EN, FR, FI...{"c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.en","c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.fr"," c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.fi",}-"!\resource\apps\SimpleEx.rsc"In this example, makesis includes all three resource files in the SIS file.However, the language chosen during the installation determines whichfile is actually copied to smartphone file \resource\apps\SimpleEx.rsc.
The order in which the source files are listed must agree with theorder of the languages in the language statement – so that UK Englishchooses SimpleEx.en, French chooses SimpleEx.fr, and Finnishchooses SimpleEx.fi.Note that, if you use this language-dependent version of a file specification line, you must include a source file for each of the languages listedin the language line.As another example, you could also have language-dependent versionsof a text notice, such as:{"license.en.txt","license.fr.txt","license.fi.txt"} - " ", FILETEXT,TEXTCONTINUEOther language-dependent statementsWhen specifying multiple languages you will need to ensure that yourproduct header provides a component name for each language, and thatyour target platform lines (as well as other requisite lines) provide productid strings for each language.
Although it is common for the componentname to be in English for each language variant, there still needs to bea string entered for each language, otherwise an error will occur whenmakesis runs.The following shows the PKG file shown previously with modificationto support multiple languages.; SimpleEx.pkg - S60;&EN,FR,FI; standard SIS file header#{"SimpleEx_EN","SimpleEx_FR","SimpleEx_FI"},(0x10005B94),1,0,0;Supports S60160SYMBIAN OS BUILD ENVIRONMENT[0x101F7961], 0, 0, 0, {"S60ProductID","S60ProductID","S60ProductID"}"c:\Symbian\9.2\S60_3rd_FP1\epoc32\release\gcce\urel\SimpleEx.exe"-"!:\sys\bin\SimpleEx.exe""c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.rsc"-"!:\resource\apps\SimpleEx.rsc"{"c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.en","c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.fr"," c:\Symbian\9.2\S60_3rd_FP1 \epoc32\data\z\resource\apps\SimpleEx.fi",} -"!\resource\apps\SimpleEx.rsc"5.9.5Signing Your SIS FileAs mentioned in Chapter 2, in Symbian OS v9 you must have your SIS filedigitally signed before it can be installed on the phone.
You can sign theapplication yourself using the signsis tool if either your application hasno security capabilities (i.e., no CAPABILITY line or CAPABILITY Nonein your MMP file or Carbide project), if you have a developer certificateor if your application contains only user-level capabilities. Applicationsigning is discussed in detail in Chapter 7.6Strings, Buffers, and Data CollectionsThis chapter covers the basic string and data buffer APIs, as well as othercommon data organization classes. These classes are part of what isknown in Symbian OS as the Base APIs, and they reside in euser.dll.This chapter covers the following types of data classes:•Descriptors for handling strings and binary data.•Dynamic buffers for buffers that grow at runtime.•Array classes.•Other data organization classes like linked lists and circular queues.The chapter includes numerous examples, and the complete source ofthe examples can be downloaded from the book’s website.
The examplesoutput their results via a printf()-style function, to what is known asa text console.Before diving into string and buffer management, let’s take a look athow a text console program works. This provides an easy way to compileand run the examples in this chapter on the emulator and do experimentsof your own without writing a full GUI program.6.1 Introducing the Text ConsoleSymbian OS provides a text console API class called CConsoleBasethat allows you to output formatted text to the screen, without theoverhead of using the GUI framework.
The class also accepts keyboardinput. While the text console is not very useful for product software, it’sexcellent for learning and experimenting with non-GUI-related SymbianOS functionality.162STRINGS, BUFFERS, AND DATA COLLECTIONSBelow is a very minimal console CPP file that outputs ‘Hello’ to thetext console so you can get the general idea. For simplicity, the exampledoes not TRAP the call to the Console::NewL() leaving function, buta later example shows how this should be done correctly, to ensure thatE32Main() doesn’t contain functions that can leave.#include <e32base.h>#include <e32cons.h>CConsoleBase* console;TInt E32Main(){_LIT(KName,"Tests");_LIT(KAnyKey,"[Press any key]");console=Console::NewL(KName,TSize(KConsFullScreen,KConsFullScreen));console->Printf(_L("Hello\n"));console->Printf(KAnyKey);console->Getch();delete console;return(0);}Symbian OS uses LIT and L to define string literals.
We will discussthem in section 6.2.3.CConsoleBase::Printf() works in much the same way that astandard C printf() function works – it accepts a format string, anda variable number of arguments to output using the specified formattedstring.
The above example shows the simplest possible form, with noformat elements or arguments beyond the text string itself. The formatstring has the same syntax as the C printf() format string, but has someextra, Symbian OS-specific format identifiers. For example, %S is used toprint the contents of a string descriptor – you will use that one frequently.The method CConsoleBase::Getch() is used to wait for andretrieve a key from the keyboard, although the return value is discarded.The following example shows an expanded version of a consoleprogram that provides a general framework for running experiments,including the examples in this chapter. It also correctly creates a cleanupstack and handles error leaves correctly.#include <e32base.h>#include <e32cons.h>CConsoleBase* console;void RunExampleL(){console->Printf(_L("Example Code\n"));// Add example code here}void RunConsoleL(){_LIT(KName,"Tests");console=Console::NewL(KName,TSize(KConsFullScreen,KConsFullScreen));CleanupStack::PushL(console);INTRODUCING THE TEXT CONSOLE163RunExampleL();_LIT(KAnyKey,"[Press any key]\n");console->Printf(KAnyKey);console->Getch();CleanupStack::PopAndDestroy(console);}TInt E32Main(){__UHEAP_MARK;CTrapCleanup* cleanupStack = CTrapCleanup::New();TRAPD(error,RunConsoleL());__ASSERT_ALWAYS((KErrNone!=error),User::Panic(_L("Example"),error));delete cleanupStack;__UHEAP_MARKEND;return(0);}The code in E32Main() creates a cleanup stack for your test codeto use if needed.