Symbian programming - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Symbian programming

Description:

main window. Application UI. instantiates the application view. command handler for GUI controls ... CHeiMaailmaAppUi::HandleCommandL( TInt aCommand ) switch ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 36
Provided by: TKT2
Category:

less

Transcript and Presenter's Notes

Title: Symbian programming


1
Symbian programming
  • Part III
  • Programming Symbian devices with Symbian C

Environment and building applications
2
Content
  • Simple example
  • Symbian application source code files
  • Some details about the source files
  • Building and running
  • Deployment (OTA)

3
Application Components
  • Application View
  • main window
  • Application UI
  • instantiates the application view
  • command handler for GUI controls
  • Application document
  • non-GUI data aspects
  • instantiates the UI class

4
Application Components
  • Application
  • instantiates and starts the document class

5
Hei Maailma (Hello World)
  • source code files
  • HeiMaailma.cpp
  • HeiMaailmaApplication.cpp
  • HeiMaailmaAppUi.cpp
  • HeiMaailmaAppView.cpp
  • HeiMaailmaDocument.cpp

6
HeiMaailma.cpp
// INCLUDE FILES include lteikstart.hgt include
"HeiMaailmaApplication.h" LOCAL_C
CApaApplication NewApplication() return new
CHeiMaailmaApplication GLDEF_C TInt
E32Main() return EikStartRunApplication(
NewApplication )
7
HeiMaailmaApplication.cpp
include "HeiMaailmaDocument.h" include
"HeiMaailmaApplication.h" //
MEMBER FUNCTIONS // UID for
the application // this should correspond to the
uid defined in the mmp file const TUid
KUidHeiMaailmaApp 0x088C40EE //
--------------------------------------------------
--------------------------- // CHeiMaailmaApplicat
ionCreateDocumentL() // Creates CApaDocument
object // ----------------------------------------
------------------------------------- // CApaDocum
ent CHeiMaailmaApplicationCreateDocumentL()
// Create an HeiMaailma document, and
return a pointer to it return
(static_castltCApaDocumentgt (
CHeiMaailmaDocumentNewL( this ) ) )
8
HeiMaailmaApplication.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaApplicationAppDllUid() // Returns
application UID // -------------------------------
---------------------------------------------- //
TUid CHeiMaailmaApplicationAppDllUid() const
// Return the UID for the HeiMaailma
application return KUidHeiMaailmaApp
// End of File
9
HeiMaailmaDocument.cpp
// INCLUDE FILES include "HeiMaailmaAppUi.h" inc
lude "HeiMaailmaDocument.h" //
MEMBER
FUNCTIONS // ------------------------
--------------------------------------------------
--- // CHeiMaailmaDocumentNewL() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaDocument CHeiMaailmaDocumentNewL(
CEikApplication
aApp )
CHeiMaailmaDocument self NewLC( aApp )
CleanupStackPop( self ) return self
10
HeiMaailmaDocument.cpp
// ---------------------------------------------
-------------------------------- //
CHeiMaailmaDocumentNewLC() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaDocument CHeiMaailmaDocumentNewLC(
CEikApplication
aApp )
CHeiMaailmaDocument self new ( ELeave
) CHeiMaailmaDocument( aApp )
CleanupStackPushL( self )
self-gtConstructL() return self
11
HeiMaailmaDocument.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaDocumentConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaDocumentConstructL() // No
implementation required //
--------------------------------------------------
--------------------------- // CHeiMaailmaDocument
CHeiMaailmaDocument() // C default
constructor can NOT contain any code, that might
leave. // ----------------------------------------
------------------------------------- // CHeiMaail
maDocumentCHeiMaailmaDocument( CEikApplication
aApp ) CAknDocument( aApp ) // No
implementation required
12
HeiMaailmaDocument.cpp
// CHeiMaailmaDocumentCHeiMaailmaDocument()
Destructor. // -----------------------------------
---------------------------------------- // CHeiMa
ailmaDocumentCHeiMaailmaDocument()
// No implementation required //
CHeiMaailmaDocumentCreateAppUiL() // Constructs
CreateAppUi. // ----------------------------------
----------------------------------------- // CEikA
ppUi CHeiMaailmaDocumentCreateAppUiL()
// Create the application user interface, and
return a pointer to it // the framework
takes ownership of this object return (
static_cast ltCEikAppUigt ( new ( ELeave )
CHeiMaailmaAppUi
) )
13
HeiMaailmaAppUi.cpp
// INCLUDE FILES include ltavkon.hrhgt include
ltaknnotewrappers.hgt include ltstringloader.hgt inc
lude ltHeiMaailma.rsggt include ltf32file.hgt includ
e lts32file.hgt include "HeiMaailma.pan" include
"HeiMaailmaAppUi.h" include "HeiMaailmaAppView.h"
include "HeiMaailma.hrh" _LIT( KFileName,
"C\\private\\088C40EE\\HeiMaailma.txt" ) _LIT(
KText, "Hei Maailma!")
14
_LIT macro
  • The _LIT macro declares a string literal as a
    descriptor
  • A descriptor is an object that
  • contains both the data and the length of the data
  • is derived from the TDescC class

15
TDesC
  • functions
  • Ptr()
  • Length()
  • Size()
  • Compare()
  • ...

16
HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppUiConstructL() //
Initialise app UI with standard value.
BaseConstructL() // Create view
object iAppView CHeiMaailmaAppViewNewL(
ClientRect() ) // Create a file to write the
text to RFs fsSession UserLeaveIfError(fsSess
ion.Connect()) CleanupClosePushL( fsSession )
17
HeiMaailmaAppUi.cpp
TInt err fsSession.MkDirAll(KFileName) if (
KErrNone ! err ) CleanupStackPopAndDestro
y(1) // fsSession return RFile
file err file.Replace(fsSession, KFileName,
EFileWrite ) CleanupClosePushL( file ) if (
KErrNone ! err ) CleanupStackPopAndDestro
y(2) // file, fsSession return
RFileWriteStream outputFileStream( file
) CleanupClosePushL( outputFileStream
) outputFileStream ltlt KText CleanupStackPop
AndDestroy(3) // outputFileStream, file,
fsSession
18
HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiCHeiMaailmaAppUi() // C
default constructor can NOT contain any code,
that might leave. // -----------------------------
------------------------------------------------ /
/ CHeiMaailmaAppUiCHeiMaailmaAppUi()
// No implementation required
19
HeiMaailmaAppUi.cpp
// ----------------------------------------------
------------------------------- //
CHeiMaailmaAppUiCHeiMaailmaAppUi() //
Destructor. // -----------------------------------
------------------------------------------ // CHei
MaailmaAppUiCHeiMaailmaAppUi() if (
iAppView ) delete iAppView
iAppView NULL
20
HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppUiHandleCommandL() // Takes care
of command handling. // --------------------------
--------------------------------------------------
- // void CHeiMaailmaAppUiHandleCommandL( TInt
aCommand ) switch( aCommand )
case EEikCmdExit case
EAknSoftkeyExit Exit()
break case ECommand1
// Load a string from the
resource file and display it HBufC
textResource StringLoaderLoadLC(
R_COMMAND1_TEXT ) CAknInformationNote
informationNote
21
HeiMaailmaAppUi.cpp
informationNote new ( ELeave )
CAknInformationNote // Show the
information Note with // textResource
loaded with StringLoader.
informationNote-gtExecuteLD( textResource)
// Pop HBuf from CleanUpStack and Destroy
it. CleanupStackPopAndDestroy(
textResource )
break case ECommand2 RFs
fsSession RFile rFile // Connects a
client process to the fileserver UserLeaveIfE
rror(fsSession.Connect()) CleanupClosePushL(fs
Session)
22
HeiMaailmaAppUi.cpp
//Open file where the stream text
is UserLeaveIfError(rFile.Open(fsSession,KFil
eName, EFileStreamText))//EFileShareReadersOnly))
// EFileStreamText)) CleanupClosePushL(rFile)
// copy stream from file to RFileStream
object RFileReadStream inputFileStream(rFile)
CleanupClosePushL(inputFileStream)
// HBufC descriptor is created from the
RFileStream object. HBufC fileData
HBufCNewLC(inputFileStream, 32)
CAknInformationNote informationNote
informationNote new ( ELeave )
CAknInformationNote // Show the
information Note informationNote-gtExec
uteLD( fileData)
23
HeiMaailmaAppUi.cpp
// Pop loaded resources from the cleanup
stack CleanupStackPopAndDestroy(4) //
filedata, inputFileStream, rFile,
fsSession fsSession.Close() break
default Panic( EHeiMaailmaUi
) break
24
HeiMaailmaAppUi.cpp
// -----------------------------------------------
------------------------------ // Called by the
framework when the application status pane //
size is changed. Passes the new client rectangle
to the // AppView // ----------------------------
-------------------------------------------------
// void CHeiMaailmaAppUiHandleStatusPaneSizeChan
ge() iAppView-gtSetRect( ClientRect() )
// End of File
25
HeiMaailmaAppView.cpp
// INCLUDE FILES include ltcoemain.hgt include
"HeiMaailmaAppView.h" //
MEMBER FUNCTIONS //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
NewL() // Two-phased constructor. //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppViewNewL( const TRect aRect )
CHeiMaailmaAppView self
CHeiMaailmaAppViewNewLC( aRect )
CleanupStackPop( self ) return self
26
HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewNewLC() // Two-phased
constructor. // ----------------------------------
------------------------------------------- // CHe
iMaailmaAppView CHeiMaailmaAppViewNewLC( const
TRect aRect ) CHeiMaailmaAppView self
new ( ELeave ) CHeiMaailmaAppView
CleanupStackPushL( self )
self-gtConstructL( aRect ) return self
27
HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewConstructL() // Symbian 2nd
phase constructor can leave. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppViewConstructL( const TRect
aRect ) // Create a window for this
application view CreateWindowL() // Set
the windows size SetRect( aRect ) //
Activate the window, which makes it ready to be
drawn ActivateL()
28
HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewCHeiMaailmaAppView() // C
default constructor can NOT contain any code,
that might leave. // -----------------------------
------------------------------------------------ /
/ CHeiMaailmaAppViewCHeiMaailmaAppView()
// No implementation required //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppView() // Destructor. //
--------------------------------------------------
--------------------------- // CHeiMaailmaAppView
CHeiMaailmaAppView() // No
implementation required
29
HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewDraw() // Draws the
display. // --------------------------------------
--------------------------------------- // void
CHeiMaailmaAppViewDraw( const TRect /aRect/
) const // Get the standard graphics
context CWindowGc gc SystemGc() //
Gets the control's extent TRect drawRect(
Rect()) // Clears the screen gc.Clear(
drawRect )
30
HeiMaailmaAppView.cpp
// -----------------------------------------------
------------------------------ //
CHeiMaailmaAppViewSizeChanged() // Called by
framework when the view size is changed. //
--------------------------------------------------
--------------------------- // void
CHeiMaailmaAppViewSizeChanged()
DrawNow() // End of File
31
Screen shots
32
Screen shots
33
(No Transcript)
34
The application development
A problem
Design
Implementation
Testing
Deployment
35
OTA
  • Over-The-Air
  • User downloads the application from internet
    using e.g. GPRS
  • The device knows how to handle the packet
  • SIS for Symbian
  • JAR for Java
  • CAB for Windows
  • MIME type associated with the application
Write a Comment
User Comments (0)
About PowerShow.com