Editing Documentation/Maemo 5 Developer Guide/Application Development/Writing a new maemo application

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 3: Line 3:
A simple text editor with a few essential features is used as a example. Let us name it as ''MaemoPad''.
A simple text editor with a few essential features is used as a example. Let us name it as ''MaemoPad''.
-
MaemoPad has the following basic features: ''New'', ''Open'', ''Save'', ''Save As...'', ''Cut'', ''Copy'', ''Paste'', ''Font'', ''Full Screen'', ''Full Screen'' hardware key handling, ''Send-Via email/bluetooth'' and ''Close''. For simplicity, it does not contain advanced features like ''Undo'', ''Redo'', different fonts in one document, pictures, tables, etc.
+
MaemoPad has the following basic features: ''New'', ''Open'', ''Save'', ''Save As...'', ''Cut'', ''Copy'', ''Paste'', ''Font'', ''Full Screen'', ''Full Screen'' hardware key handling, ''Send-Via email/bluetooth'' and ''Close''. For simplicity, it does not contain advanced features like ``Undo'', ``Redo'', different fonts in one document, pictures, tables, etc.
The figure below is a screenshot of the text editor.
The figure below is a screenshot of the text editor.
-
[[Image:Maemopad2.png|500px|alt=Screenshot of MaemoPad|MaemoPad text editor]]
+
[[Image:Maemopad2.png|500px]]
== Creating the application file structure ==
== Creating the application file structure ==
-
In general, a Maemo application uses the [[../../GNU Build System|GNU Build System]] and has the following files and subdirectories:
+
In general, a Maemo application uses the [[../../GNU_Build_System|GNU Build System]] and has the following files and subdirectories:
* <code>src/</code>: Contains the source files.
* <code>src/</code>: Contains the source files.
-
* <code>debian/</code>: Contains the files related to Debian packaging
+
* <code>debian/</code>: Contains the files related to debian packaging
* <code>data/</code>: Contains all data files needed to run the application. Maemopad will need the following data files:
* <code>data/</code>: Contains all data files needed to run the application. Maemopad will need the following data files:
-
**<code>maemopad.desktop</code> file  
+
**<code>.desktop</code> file  
-
**D-Bus <code>maemopad.service</code> file  
+
**D-Bus <code>.service</code> file  
**application icons in a separate directory called <code>icons/</code>
**application icons in a separate directory called <code>icons/</code>
* <code>po/</code>: Contains the localization files. Maemopad contains the following files:
* <code>po/</code>: Contains the localization files. Maemopad contains the following files:
Line 24: Line 24:
* <code>autogen.sh</code> is a shell script that provides automatic build system preparation.
* <code>autogen.sh</code> is a shell script that provides automatic build system preparation.
* <code>configure.ac</code> is an input file for <code>autoconf</code> that contains <code>autoconf</code> macros that test the system features the package needs or can use. It produces the <code>configure</code> script.
* <code>configure.ac</code> is an input file for <code>autoconf</code> that contains <code>autoconf</code> macros that test the system features the package needs or can use. It produces the <code>configure</code> script.
-
* <code>Makefile.am</code> is used by <code>automake</code> to produce a standards-compliant <code>Makefile.in</code>. The <code>Makefile.am</code> in the top source directory is usually very simple and includes the files and subdirectories needed to make the application: <code>src/</code>, <code>po/</code> and <code>data/</code> and all the <code>Makefile</code>s in <code>src/</code>, <code>po/</code>, and <code>data/</code> directories.
+
* <code>Makefile.am</code> is used by <code>automake</code> to produce a standards-compliant <code>Makefile.in</code>. The <code>Makefile.am</code> in the top source directory is usually very simple and includes the files and subdirectories needed to make the application: <code>src/, po/ and data/</code> and all the <code>Makefile</code>s in <code>src/, po/, and data/</code> directories.
You can compile the source as follows:
You can compile the source as follows:
Line 32: Line 32:
   [sbox-FREMANTLE_X86 ~] >$ make
   [sbox-FREMANTLE_X86 ~] >$ make
-
For more information about GNU autoconf and automake, see the [[Documentation/Maemo 5 Developer Guide/GNU Build System|GNU build system]] article.
+
For more information about GNU autoconf and automake, see chapter [http://wiki.maemo.org/Documentation/Maemo_5_Developer_Guide/GNU_Build_System GNU build system]
== Coding the application ==
== Coding the application ==
Line 83: Line 83:
main.c usually performs, at least, the following functions:
main.c usually performs, at least, the following functions:
-
* Initializing GTK+
+
* Initializing GTK
* Initializing localization
* Initializing localization
-
* Creating an instance of <code>HildonProgram</code>
+
* Creating an instance of HildonProgram
-
* Calling to a function, usually defined in <code>interface.c</code>, to create the main view.
+
* Calling to a function, usually defined in interface.c, to create the main view.
-
* Connecting the main view window to the created <code>HildonProgram</code>
+
* Connecting the main view window to the created HildonProgram
* Running <code>gtk_main()</code>
* Running <code>gtk_main()</code>
* Connecting the <code>delete_event</code> of the main view to a callback function to handle a proper application exit, such as destroying the main view window, freeing used memory and saving application states before exit.
* Connecting the <code>delete_event</code> of the main view to a callback function to handle a proper application exit, such as destroying the main view window, freeing used memory and saving application states before exit.
Line 121: Line 121:
   g_assert (osso);
   g_assert (osso);
   
   
-
   /* Create the window for our application: */
+
   /* Create the window for our application: */</font>
   data->window = maemopad_window_new (osso);
   data->window = maemopad_window_new (osso);
   hildon_program_add_window (data->program, data->window);
   hildon_program_add_window (data->program, data->window);
Line 148: Line 148:
=== interface.c ===
=== interface.c ===
-
This file creates the graphical user interface (GUI) and connects the signals and events to appropriate handlers defined in <code>callbacks.c</code>. See the [http://www.forum.nokia.com/info/sw.nokia.com/id/eb8a68ba-6225-4d84-ba8f-a00e4a05ff6f/Hildon_2_2_UI_Style_Guide.html Hildon UI style guide] for information on how to create GUI in Maemo. For more information on GTK+ see the [http://maemo.org/api_refs/5.0/5.0-final/gtk/ GTK+ Reference Manual].
+
This file creates the graphical user interface (GUI) and connects the signals and events to appropriate handlers defined in <code>callbacks.c</code>. See section [localhost#sec:writing_maemo_gui_applications [[Image:crossref.png|[*]]]] for information on how to create GUI in Maemo. For more information on GTK see the GTK+ Reference Manual [[/node22.html#maemoapi 52]].
As a general practice, an <code>AppUIData</code> struct variable is created when creating the GUI. And then, a <code>HildonWindow</code> and smaller components are created in different functions, such as <code>create_menu()</code>, <code>create_toolbar()</code>. When creating each component, <code>AppUIData</code> should refer to various necessary UI objects created along the way.
As a general practice, an <code>AppUIData</code> struct variable is created when creating the GUI. And then, a <code>HildonWindow</code> and smaller components are created in different functions, such as <code>create_menu()</code>, <code>create_toolbar()</code>. When creating each component, <code>AppUIData</code> should refer to various necessary UI objects created along the way.
Line 220: Line 220:
</source>
</source>
-
N.B. The <code>AppUIData</code> struct variable <code>mainview</code> is retrieved in such a way that the handlers can have a direct effect on the UI for the users.
+
N.B. The AppUIData struct variable ''mainview'' is retrieved in such a way that the handlers can have a direct effect on the UI for the users.
MaemoPad contains many functions:
MaemoPad contains many functions:
-
* File Save/Save-As/Open: This uses <code>HildonFileChooserDialog</code>.
+
* File Save/Save-As/Open: This uses HildonFileChooserDialog.
-
* Edit Cut/Copy/Paste: This uses the clipboard ([[Documentation/Maemo 5 Developer Guide/Using Data Sharing/Clipboard Usage|clipboard usage]])
+
* Edit Cut/Copy/Paste: This uses Clipboard ([/node13.html#sec:clipboard_usage 12.2])
-
* Font/Color Selector: These are explained in <code>HildonFontSelectionDialog</code> and <code>HildonColorChooser</code>.
+
* Hardware keys: MaemoPad can recognize the ``Fullscreen`` button key presses (F6). It switches the application from fullscreen mode to normal mode, and vice versa. Many other hardware key events can be added to MaemoPad, see section [localhost#sec:hardware_keys 8.3.3].
-
* [[Documentation/Maemo 5 Developer Guide/Using Data Sharing/Sharing Plug-in#Writing .22Send Via.22 Functionality to E-mail and Bluetooth|Send via Email/Bluetooth]]
+
* Font/Color Selector: These are explained in HildonFontSelectionDialog and HildonColorChooser.
 +
* Send via Email/Bluetooth: Refer to section ''<nowiki>``Send via'' functionality</nowiki>'' [/node13.html#sec:send_via_functionality 12.3] on chapter ''Using Generic Platform Components'' of Maemo Reference Manual for instructions on how to implement Send via functionality.
 +
 
 +
More information on GTK Widgets can be found on the [http://maemo.org/api_refs/4.0/gtk/GtkWidget.html GTK+ Reference Manual].
=== interface.h ===
=== interface.h ===
-
In the interface header file <code>interface.h</code>, public functions are defined for <code>main.c</code> and <code>callbacks.c</code>. In the case of MaemoPad, confirmation responses for the save changes note, <code>MaemopadError</code> enum for the Hildon error note and the <code>AppUIData</code> are also defined here. '''N.B.''' <code>AppUIData</code> can also be defined in <code>appdata.h</code> in some other applications. MaemoPad's <code>interface.h</code> looks like this:
+
In the interface header file interface.h, public functions are defined for main.c and callbacks.c. In the case of MaemoPad, confirmation responses for the save changes note, MaemopadError enum for the Hildon error note and the AppUIData are also defined here. '''N.B.''' AppUIData can also be defined in appdata.h in some other applications. MaemoPad's interface.h looks like this:
<source lang="c">
<source lang="c">
Line 299: Line 302:
</source>
</source>
-
More information on localization can be found in the [[Documentation/Maemo 5 Developer Guide/Application Development/Maemo Localization|Maemo localization]] section.
+
More information on localization can be found in section [/node17.html#sec:maemo_localization 16.4].
=== File structure ===
=== File structure ===
-
Localization files are stored in the <code>po/</code> directory. The following files are used for MaemoPad localization:
+
Localization files are stored in the po/ directory. The following files are used for MaemoPad localization:
-
* <code>Makefile.am</code>
+
* Makefile.am
-
* <code>POTFILES.in</code>
+
* POTFILES.in
-
* <code>en_GB.po</code>
+
* en_GB.po
-
<code>POTFILES.in</code> contains the list of the source code files to be localized. In MaemoPad, only main.c and interface.c contain strings that need to be localized.
+
POTFILES.in contains the list of the source code files to be localized. In MaemoPad, only main.c and interface.c contain strings that need to be localized.
-
  # List of MaemoPad source files to be localized
+
  <tt><span>''<span><font color="#9A1900"><nowiki># List of MaemoPad source files to be localized</nowiki></font></span>''</span>
-
  ../src/main.c
+
  <span><font color="#990000">..</font></span>/src/main<span><font color="#990000">.</font></span>c
-
  ../src/ui/interface.c
+
  <span><font color="#990000">..</font></span>/src/ui/interface<span><font color="#990000">.</font></span>c</tt>
-
File <code>en_GB.po</code> includes translated text for British English. It contains pairs of id/string as follows:
+
File en_GB.po includes translated text for British English. It contains pairs of id/string as follows:
-
  # ...
+
  <tt><span>''<span><font color="#9A1900"><nowiki># ...</nowiki></font></span>''</span>
-
  msgid "maemopad_yes"
+
  msgid <span><font color="#FF0000">"maemopad_yes"</font></span>
-
  msgstr "Yes"
+
  msgstr <span><font color="#FF0000">"Yes"</font></span>
-
  # ...
+
  <span>''<span><font color="#9A1900"><nowiki># ...</nowiki></font></span>''</span></tt>
'''N.B.''' The comments in .po file start with ``#``.
'''N.B.''' The comments in .po file start with ``#``.
Line 340: Line 343:
==== Creating .po files from source ====
==== Creating .po files from source ====
-
Sometimes code must be localized for applications that were not originally designed for localization. You can create .po files from source code using [http://www.gnu.org/software/gettext/ GNU xgettext], by extracting all the strings from the source files into a <code>template.po</code> file
+
Sometimes code must be localized for applications that were not originally designed for localization. You can create .po files from source code using [http://www.gnu.org/software/gettext/ GNU xgettext][], by extracting all the strings from the source files into a template.po file
  xgettext -f POTFILES.in -C -a -o template.po
  xgettext -f POTFILES.in -C -a -o template.po
Line 346: Line 349:
Read the man page for xgettext for more information, in short:
Read the man page for xgettext for more information, in short:
-
* <code>-f POTFILES.in</code> uses <code>POTFILES.in</code> to get the files to be localized
+
* ``-f POTFILES.in`` uses POTFILES.in to get the files to be localized
-
* <code>-C</code> is for C-code type of strings
+
* ``-C`` is for C-code type of strings
-
* <code>-a</code> is for ensuring that we get all strings from specified files
+
* ``-a`` is for ensuring that we get all strings from specified files
-
* <code>-o template.po</code> defines the output filename.
+
* ``-o template.po`` defines the output filename.
-
The next step is to copy this <code>template.po</code> into <code>./po/en_GB.po</code> and add or edit all the strings in British English. Other languages can be handled in the same way.
+
The next step is to copy this template.po into ./po/en_GB.po and add or edit all the strings in British English. Other languages can be handled in the same way.
== Adding application to menu ==
== Adding application to menu ==
-
In short, the <code>maemopad.desktop</code> and <code>com.nokia.maemopad.service</code> files are stored in the <code>./data</code> directory, and they look like this, respectively:
+
See section [localhost#sec:getting_app_to_task_navigator_menu 8.6.1] for information on how to perform this. In short, the maemopad.desktop and com.nokia.maemopad.service files are stored in the ./data directory, and they look like this, respectively
-
  [Desktop Entry]
+
  <code>[Desktop Entry]
  Encoding=UTF-8
  Encoding=UTF-8
  Version=0.1
  Version=0.1
Line 367: Line 370:
  X-Window-Icon-Dimmed=maemopad
  X-Window-Icon-Dimmed=maemopad
  X-Osso-Service=com.nokia.maemopad
  X-Osso-Service=com.nokia.maemopad
-
  X-Osso-Type=application/x-executable
+
  X-Osso-Type=application/x-executable</code>
('''N.B.''' Whitespace is not allowed after the lines.)
('''N.B.''' Whitespace is not allowed after the lines.)
Line 378: Line 381:
These files reside on the device here:
These files reside on the device here:
-
* <code>/usr/share/applications/hildon</code>
+
* /usr/share/applications/hildon
-
* <code>/usr/share/dbus-1/services</code>
+
* /usr/share/dbus-1/services
 +
 
 +
== Link to Maemo menu ==
When the Debian package is installed to Maemo platform, .desktop and .service files are used to link MaemoPad to the Task Navigator.
When the Debian package is installed to Maemo platform, .desktop and .service files are used to link MaemoPad to the Task Navigator.
 +
 +
== Adding help ==
 +
 +
Applications can have their own help files. Help files are XML files located under the <code>/usr/share/osso-help</code> directory. Each language is located in its own subdirectory, such as <code>/usr/share/osso-help/en_GB</code> for British English help files. MaemoPad has <code>data/help/en_GB/MaemoPad.xml</code> with very simple help content. The middle part of the contextUID must be the same as the help file name (without suffix):
 +
 +
<source lang="xml">
 +
<?xml version="1.0" encoding="UTF-8"?>
 +
<hildonhelpsource>
 +
  <folder>
 +
    <title>MaemoPad</title>
 +
    <topic>
 +
      <topictitle>Main Topic</topictitle>
 +
      <context contextUID="Example_MaemoPad_Content" />
 +
      <para>This is a help file with example content.</para>
 +
    </topic>
 +
  </folder>
 +
</hildonhelpsource>
 +
</source>
 +
 +
By using <code>hildon_help_show()</code> function (see hildon-help.h), this help content can be shown in the application. After creating a Help menu item, a callback function can be connected to it:
 +
 +
<source lang="c">
 +
void callback_help( GtkAction * action, gpointer data )
 +
{
 +
    osso_return_t retval;
 +
    /* connect pointer to our AppUIData struct */
 +
    AppUIData *mainview = NULL;
 +
    mainview = ( AppUIData * ) data;
 +
    g_assert(mainview != NULL && mainview->data != NULL );
 +
    retval = hildon_help_show(
 +
      mainview->data->osso, /* osso_context */
 +
      HELP_TOPIC_ID,        /* topic id */
 +
      HILDON_HELP_SHOW_DIALOG);
 +
}
 +
</source>
== Packaging the application ==
== Packaging the application ==
Line 387: Line 427:
{{main|Packaging}}
{{main|Packaging}}
-
A Debian package is an application packed in one file to make installing easy in Debian-based operating systems, like Maemo platform. More information about creating a Debian packages can be found in the [[Documentation/Maemo 5 Developer Guide/Packaging%2C Deploying and Distributing#Creating Debian Packages|creating Debian packages]] section of the [[Documentation/Maemo 5 Developer Guide/Packaging, Deploying and Distributing|Packaging, Deploying and Distributing chapter]]. Our goal in this section is to create a Debian package of MaemoPad, to be installed in the Maemo platform.
+
A Debian package is an application packed in one file to make installing easy in Debian-based operating systems, like Maemo platform. More information about creating a Debian packages can be found in section ''Creating Debian packages'' [/node18.html#sec:creating_debian_packages 17.1] of Maemo Reference Manual Chapter ''Packaging, Deploying and Distributing''. Our goal in this section is to create a Debian package of MaemoPad, to be installed in the Maemo platform.
-
If creating a package that can be installed using the Application Manager, be sure that the package is in an [[Documentation/Maemo 5 Developer Guide/Packaging%2C Deploying and Distributing#Sections|allowed section]].
+
If creating a package that can be installed using the Application Manager, see section ''Making application packages'' [/node18.html#sec:making_app_pack 17.2] of the same aforementioned chapter.
=== Creating debian/ Directory ===
=== Creating debian/ Directory ===
-
In order to create the package, the following files are created in the <code>debian/</code> directory:
+
In order to create the package, the following files are created in the debian/ directory:
-
* <code>changelog</code>
+
changelog
-
* <code>control</code>
+
control
-
* <code>copyright</code>
+
copyright
-
* <code>rules</code>
+
rules
-
* ... etc ...
+
... etc ...
-
The <code>rules</code> file is the file defining how the Debian package is built. The <code>rules</code> file tells where the files should be installed. Also a <code>control</code> file is needed to define what kind of packages (often different language versions) are going to be created. <code>changelog</code> and <code>copyright</code> files are also needed, or the package does not build. The <code>changelog</code> file consists of the version number of the package, and a short description about changes compared to older versions. The <code>copyright</code> file includes information in plain text about the package copyrights.
+
The 'rules' file is the file defining how the Debian package is built. The 'rules' file tells where the files should be installed. Also a 'control' file is needed to define what kind of packages (often different language versions) are going to be created. Changelog and copyright files are also needed, or the package does not build. The 'changelog' file consists of the version number of the package, and a short description about changes compared to older versions. The 'copyright' file includes information in plain text about the package copyrights.
Most important lines in rules file are:
Most important lines in rules file are:

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)

Templates used on this page: