个人工具

“UbuntuHelp:UMEGuide/ApplicationDevelopment/PortingCAppsToUME”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: {{From|https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME}} {{Languages|UbuntuHelp:UMEGuide/ApplicationDevelopment/PortingCAppsToUME}} This uses some info...)
 
第2行: 第2行:
 
{{Languages|UbuntuHelp:UMEGuide/ApplicationDevelopment/PortingCAppsToUME}}
 
{{Languages|UbuntuHelp:UMEGuide/ApplicationDevelopment/PortingCAppsToUME}}
 
This uses some information [http://moblin.org/howto_porting-maemo.html from upstream]. If you are feeling really brave do [http://lists.maemo.org/pipermail//maemo-developers/2006-August/005316.html this] first.
 
This uses some information [http://moblin.org/howto_porting-maemo.html from upstream]. If you are feeling really brave do [http://lists.maemo.org/pipermail//maemo-developers/2006-August/005316.html this] first.
 
 
== Objective ==
 
== Objective ==
 
This shows how to port an application  written in C (liferea) to Ubuntu Mobile. [http://liferea.sourceforge.net/ Liferea] is an aggregator for online news feeds written in C utilizing GTK for its graphical interface.
 
This shows how to port an application  written in C (liferea) to Ubuntu Mobile. [http://liferea.sourceforge.net/ Liferea] is an aggregator for online news feeds written in C utilizing GTK for its graphical interface.
 
 
== Assumed Knowledge ==
 
== Assumed Knowledge ==
 
You have set up the UME development environment as show [https://wiki.ubuntu.com/MobileAndEmbedded/CreatingAnImageForUMEDevice here]. Also that you can change the Flash UI as explained [http://ianlawrence.info/random-stuff/location-services-on-ubuntu-mobile here]. You should be familiar with or have the desire to learn C programming, including the 'auto' tools. A good tutorial on automake is [http://sourceware.org/autobook/ here]
 
You have set up the UME development environment as show [https://wiki.ubuntu.com/MobileAndEmbedded/CreatingAnImageForUMEDevice here]. Also that you can change the Flash UI as explained [http://ianlawrence.info/random-stuff/location-services-on-ubuntu-mobile here]. You should be familiar with or have the desire to learn C programming, including the 'auto' tools. A good tutorial on automake is [http://sourceware.org/autobook/ here]
 
 
'''Dependencies Needed'''
 
'''Dependencies Needed'''
 
 
aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner
 
aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner
 
 
== Overview ==
 
== Overview ==
 
Porting applications basically comes down to two things:
 
Porting applications basically comes down to two things:
 
 
1. Use <code><nowiki>HildonProgram</nowiki></code> and <code><nowiki>HildonWindow</nowiki></code> classes instead of the <code><nowiki>GtkWindow</nowiki></code> class.
 
1. Use <code><nowiki>HildonProgram</nowiki></code> and <code><nowiki>HildonWindow</nowiki></code> classes instead of the <code><nowiki>GtkWindow</nowiki></code> class.
 
 
2. Use the <code><nowiki>HildonWindow</nowiki></code> menu bar instead of the <code><nowiki>GTKMenuBar</nowiki></code>
 
2. Use the <code><nowiki>HildonWindow</nowiki></code> menu bar instead of the <code><nowiki>GTKMenuBar</nowiki></code>
 
 
== Get the source and try to compile ==
 
== Get the source and try to compile ==
 
<code><nowiki>user@machine:/home/ian/Dev/Ume/ports/src# apt-get source liferea</nowiki></code>
 
<code><nowiki>user@machine:/home/ian/Dev/Ume/ports/src# apt-get source liferea</nowiki></code>
 
this downloads the source
 
this downloads the source
 
 
<pre><nowiki>liferea-1.4.2
 
<pre><nowiki>liferea-1.4.2
 
liferea_1.4.2.orig.tar.gz
 
liferea_1.4.2.orig.tar.gz
 
liferea_1.4.2-0ubuntu1.diff.gz
 
liferea_1.4.2-0ubuntu1.diff.gz
 
liferea_1.4.2-0ubuntu1.dsc</nowiki></pre>
 
liferea_1.4.2-0ubuntu1.dsc</nowiki></pre>
 
 
this gives some ./autoconf errors like:
 
this gives some ./autoconf errors like:
 
<pre><nowiki>No package 'libxslt' found
 
<pre><nowiki>No package 'libxslt' found
 
No package 'sqlite3' found
 
No package 'sqlite3' found
 
No package 'libglade-2.0' found</nowiki></pre>
 
No package 'libglade-2.0' found</nowiki></pre>
 
 
which are the applications dependencies, so install the packages needed if you have not already done so:
 
which are the applications dependencies, so install the packages needed if you have not already done so:
 
<code><nowiki>aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner</nowiki></code>
 
<code><nowiki>aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner</nowiki></code>
 
 
this passed autoconf but running make gave an error of:
 
this passed autoconf but running make gave an error of:
 
 
<pre><nowiki>gtkhtml2.c: In function 'gtkhtml2_launch_url':
 
<pre><nowiki>gtkhtml2.c: In function 'gtkhtml2_launch_url':
 
gtkhtml2.c:458: error: too many arguments to function 'update_request_new'
 
gtkhtml2.c:458: error: too many arguments to function 'update_request_new'
第50行: 第37行:
 
make[4]: *** [liblihtmlg_la-gtkhtml2.lo] Error 1
 
make[4]: *** [liblihtmlg_la-gtkhtml2.lo] Error 1
 
make[4]: Leaving directory `/home/ian/Desktop/liferea-1.4.2/src/gtkhtml2'</nowiki></pre>
 
make[4]: Leaving directory `/home/ian/Desktop/liferea-1.4.2/src/gtkhtml2'</nowiki></pre>
 
 
It seems to be hitting by [http://www.nabble.com/Stable-Release-1.4.2-t4432014.html this] bug.
 
It seems to be hitting by [http://www.nabble.com/Stable-Release-1.4.2-t4432014.html this] bug.
 
 
So downloaded the [http://sourceforge.net/project/downloading.php?group_id=87005&use_mirror=osdn&filename=liferea-1.4.3.tar.gz&1674222 latest bugfix stable release 1.4.2b] and this compiled successfully and also ran make ok so now it is time to 'Hildonize' it.  
 
So downloaded the [http://sourceforge.net/project/downloading.php?group_id=87005&use_mirror=osdn&filename=liferea-1.4.3.tar.gz&1674222 latest bugfix stable release 1.4.2b] and this compiled successfully and also ran make ok so now it is time to 'Hildonize' it.  
 
 
== HILDONIZING ==
 
== HILDONIZING ==
 
 
It is useful to know that the default location for C header files is in <code><nowiki>/usr/include</nowiki></code>. Inside this directory we have another directory hildon-1 and inside this directory we have hildon, so the full path to the hildon header files is:
 
It is useful to know that the default location for C header files is in <code><nowiki>/usr/include</nowiki></code>. Inside this directory we have another directory hildon-1 and inside this directory we have hildon, so the full path to the hildon header files is:
 
<code><nowiki>/usr/include/hildon-1/hildon</nowiki></code>
 
<code><nowiki>/usr/include/hildon-1/hildon</nowiki></code>
 
 
First modify the file configure.ac
 
First modify the file configure.ac
 
Around line 42 add the line:
 
Around line 42 add the line:
 
 
<code><nowiki> AC_ARG_ENABLE(hildon,    AS_HELP_STRING([--enable-hildon],[compile for Hildon environment @<:@default=no@:>@]),,enable_hildon=no)</nowiki></code>
 
<code><nowiki> AC_ARG_ENABLE(hildon,    AS_HELP_STRING([--enable-hildon],[compile for Hildon environment @<:@default=no@:>@]),,enable_hildon=no)</nowiki></code>
 
 
and then on lines 212 - 225 add:
 
and then on lines 212 - 225 add:
 
 
<pre><nowiki>dnl ********
 
<pre><nowiki>dnl ********
 
dnl Hildon
 
dnl Hildon
 
dnl ********
 
dnl ********
 
 
if test "x$enable_hildon" = "xyes"; then
 
if test "x$enable_hildon" = "xyes"; then
 
dnl AC_MSG_CHECKING([for GtkHTML2 support])
 
dnl AC_MSG_CHECKING([for GtkHTML2 support])
第79行: 第57行:
 
enable_hildon=no
 
enable_hildon=no
 
fi
 
fi
 
 
AM_CONDITIONAL(WITH_HILDON, test "x$enable_hildon" = "xyes")</nowiki></pre>
 
AM_CONDITIONAL(WITH_HILDON, test "x$enable_hildon" = "xyes")</nowiki></pre>
 
 
and then finally on line 548 echo the information back so that there is visual confirmation to the user that Hildon is enabled:
 
and then finally on line 548 echo the information back so that there is visual confirmation to the user that Hildon is enabled:
 
 
<code><nowiki>echo "Build Hildon support............ : $enable_hildon"</nowiki></code>
 
<code><nowiki>echo "Build Hildon support............ : $enable_hildon"</nowiki></code>
 
 
these changes enable the passing of the argument --enable-hildon on the command line like:
 
these changes enable the passing of the argument --enable-hildon on the command line like:
 
 
<code><nowiki>./configure --enable-hildon</nowiki></code>
 
<code><nowiki>./configure --enable-hildon</nowiki></code>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=configure.ac
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=configure.ac
 
 
After making these changes run autoreconf:
 
After making these changes run autoreconf:
 
<code><nowiki>user@machine:~/Dev/Ume/liferea-1.4.2b$ autoreconf</nowiki></code>
 
<code><nowiki>user@machine:~/Dev/Ume/liferea-1.4.2b$ autoreconf</nowiki></code>
 
 
This step is necessary because autoreconf runs autoconf, autoheader, aclocal, automake, libtoolize, and autopoint (when appropriate) to update the Build System in the specified directories and their subdirectories. In other words it registers the changes made to configure.ac
 
This step is necessary because autoreconf runs autoconf, autoheader, aclocal, automake, libtoolize, and autopoint (when appropriate) to update the Build System in the specified directories and their subdirectories. In other words it registers the changes made to configure.ac
 
 
 
Next change Makefile.am  
 
Next change Makefile.am  
 
This is located in the <code><nowiki>liferea-1.4.2b/src</nowiki></code> directory. On line 67 add the Hildon libraries <code><nowiki>$(HILDON_LIBS)</nowiki></code> to <code><nowiki>liferea_bin_LDADD</nowiki></code>  
 
This is located in the <code><nowiki>liferea-1.4.2b/src</nowiki></code> directory. On line 67 add the Hildon libraries <code><nowiki>$(HILDON_LIBS)</nowiki></code> to <code><nowiki>liferea_bin_LDADD</nowiki></code>  
 
 
<pre><nowiki>liferea_bin_LDADD = net/liblinet.a \
 
<pre><nowiki>liferea_bin_LDADD = net/liblinet.a \
 
parsers/libliparsers.a \
 
parsers/libliparsers.a \
第107行: 第74行:
 
ui/libliui.a \
 
ui/libliui.a \
 
$(PACKAGE_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS) $(DBUS_LIBS) $(NM_LIBS) $(INTLLIBS) $(GNUTLS_LIBS) $(HILDON_LIBS)</nowiki></pre>
 
$(PACKAGE_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS) $(DBUS_LIBS) $(NM_LIBS) $(INTLLIBS) $(GNUTLS_LIBS) $(HILDON_LIBS)</nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=Makefile.am
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=Makefile.am
 
 
this enables liferea to link against the Hildon libraries.
 
this enables liferea to link against the Hildon libraries.
 
 
Next change the Makefile.am inside the liferea-1.4.2b/src/ui directory.  
 
Next change the Makefile.am inside the liferea-1.4.2b/src/ui directory.  
 
On line 11 add:  
 
On line 11 add:  
 
<code><nowiki>libliui_a_CFLAGS = $(PACKAGE_CFLAGS) $(DBUS_CFLAGS) $(HILDON_CFLAGS)</nowiki></code>
 
<code><nowiki>libliui_a_CFLAGS = $(PACKAGE_CFLAGS) $(DBUS_CFLAGS) $(HILDON_CFLAGS)</nowiki></code>
 
 
this passes the <code><nowiki>$(HILDON_CFLAGS)</nowiki></code> to the compiler
 
this passes the <code><nowiki>$(HILDON_CFLAGS)</nowiki></code> to the compiler
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_Makefile.am
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_Makefile.am
 
 
These are all the changes needed to be made to autotools. Next copy the liferea.glade file which is in the root liferea-1.4.2b directory and rename it to liferea_hildon.glade  This means that if the --enable-hildon flag is passed at compile time the liferea_hildon.glade file is used and if not liferea.glade is used.
 
These are all the changes needed to be made to autotools. Next copy the liferea.glade file which is in the root liferea-1.4.2b directory and rename it to liferea_hildon.glade  This means that if the --enable-hildon flag is passed at compile time the liferea_hildon.glade file is used and if not liferea.glade is used.
 
 
Here are the differences between the two files:
 
Here are the differences between the two files:
 
 
<pre><nowiki>user@machine:/home/user/liferea-1.4.2b$ diff -Nu liferea.glade liferea_hildon.glade  
 
<pre><nowiki>user@machine:/home/user/liferea-1.4.2b$ diff -Nu liferea.glade liferea_hildon.glade  
 
--- liferea.glade      2007-08-19 13:56:50.000000000 -0400
 
--- liferea.glade      2007-08-19 13:56:50.000000000 -0400
第141行: 第100行:
 
<widget class="GtkVBox" id="vbox1">
 
<widget class="GtkVBox" id="vbox1">
 
<property name="visible">True</property></nowiki></pre>
 
<property name="visible">True</property></nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea.glade
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea.glade
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea_hildon.glade
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea_hildon.glade
 
 
In short the mainwindow is a <code><nowiki>GtkVBox</nowiki></code> in the hildon version and a <code><nowiki>GtkWindow</nowiki></code> normally. This change is explained [http://maemo.org/development/documentation/how-tos/3-x/howto_porting_to_maemo_bora.html in this tutorial] in the section 'Hildonizing Main View'
 
In short the mainwindow is a <code><nowiki>GtkVBox</nowiki></code> in the hildon version and a <code><nowiki>GtkWindow</nowiki></code> normally. This change is explained [http://maemo.org/development/documentation/how-tos/3-x/howto_porting_to_maemo_bora.html in this tutorial] in the section 'Hildonizing Main View'
 
 
Now liferea needs to know to pull in the appropriate glade file depending on whether it is compiled for hildon or not.  
 
Now liferea needs to know to pull in the appropriate glade file depending on whether it is compiled for hildon or not.  
 
 
In the file <code><nowiki>liferea-1.4.2b/src/ui/ui_shell.c</nowiki></code> inside the function <code><nowiki>static void liferea_shell_init (LifereaShell *ls)</nowiki></code> line 113 now looks like:
 
In the file <code><nowiki>liferea-1.4.2b/src/ui/ui_shell.c</nowiki></code> inside the function <code><nowiki>static void liferea_shell_init (LifereaShell *ls)</nowiki></code> line 113 now looks like:
 
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", "mainwindow", GETTEXT_PACKAGE);
 
ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", "mainwindow", GETTEXT_PACKAGE);
第156行: 第110行:
 
ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", "mainwindow", GETTEXT_PACKAGE);
 
ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", "mainwindow", GETTEXT_PACKAGE);
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
Also the file <code><nowiki>liferea-1.4.2b/src/ui/ui_dialog.c</nowiki></code> inside the function <code><nowiki>GtkWidget *liferea_dialog_new (const gchar *filename, const gchar *name)</nowiki></code> line 139 now looks like:
 
Also the file <code><nowiki>liferea-1.4.2b/src/ui/ui_dialog.c</nowiki></code> inside the function <code><nowiki>GtkWidget *liferea_dialog_new (const gchar *filename, const gchar *name)</nowiki></code> line 139 now looks like:
 
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", name, GETTEXT_PACKAGE);
 
ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", name, GETTEXT_PACKAGE);
第164行: 第116行:
 
ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", name, GETTEXT_PACKAGE);
 
ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", name, GETTEXT_PACKAGE);
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_shell.c
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_shell.c
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_dialog.c
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_dialog.c
 
 
All the other changes to Liferea are in <code><nowiki>liferea-1.4.2b/src/ui/ui_mainwindow.c</nowiki></code>  
 
All the other changes to Liferea are in <code><nowiki>liferea-1.4.2b/src/ui/ui_mainwindow.c</nowiki></code>  
 
 
On line 34 add the header file include:
 
On line 34 add the header file include:
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
#  include <hildon/hildon-program.h>
 
#  include <hildon/hildon-program.h>
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
On line 66 in the function <code><nowiki>static struct mainwindow</nowiki></code> create the <code><nowiki>HildonProgram</nowiki></code> structure like:
 
On line 66 in the function <code><nowiki>static struct mainwindow</nowiki></code> create the <code><nowiki>HildonProgram</nowiki></code> structure like:
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
第183行: 第131行:
 
GtkWindow *window;
 
GtkWindow *window;
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
On line 536 in the function <code><nowiki>static struct mainwindow *ui_mainwindow_new(void)</nowiki></code> make an instance of a <code><nowiki>HildonProgram</nowiki></code> like:
 
On line 536 in the function <code><nowiki>static struct mainwindow *ui_mainwindow_new(void)</nowiki></code> make an instance of a <code><nowiki>HildonProgram</nowiki></code> like:
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
第194行: 第141行:
 
mw->window = GTK_WINDOW (window);
 
mw->window = GTK_WINDOW (window);
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
Also the maemo tutorial mentioned above notes 'Also remove functions accel_set_func and accel_edited_callback' so on line 1255 add:
 
Also the maemo tutorial mentioned above notes 'Also remove functions accel_set_func and accel_edited_callback' so on line 1255 add:
 
<pre><nowiki>#ifndef MAEMO_CHANGES
 
<pre><nowiki>#ifndef MAEMO_CHANGES
第200行: 第146行:
 
gtk_window_add_accel_group (mw->window, accel_group);
 
gtk_window_add_accel_group (mw->window, accel_group);
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea.png
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea.png
 
 
=== Now on to the menu functions. ===
 
=== Now on to the menu functions. ===
 
 
[http://blogs.igalia.com/svillar/?p=16 This blog post] provided the inspiration for this.
 
[http://blogs.igalia.com/svillar/?p=16 This blog post] provided the inspiration for this.
 
 
Trying to use the <code><nowiki>GtkUIManager</nowiki></code> caused a problem. The reason is that hildon_window_set_menu expects a <code><nowiki>GtkMenu</nowiki></code> as second argument, but the <code><nowiki>GtkUIManager</nowiki></code> gives a <code><nowiki>GtkMenuBar</nowiki></code>
 
Trying to use the <code><nowiki>GtkUIManager</nowiki></code> caused a problem. The reason is that hildon_window_set_menu expects a <code><nowiki>GtkMenu</nowiki></code> as second argument, but the <code><nowiki>GtkUIManager</nowiki></code> gives a <code><nowiki>GtkMenuBar</nowiki></code>
 
 
Adding an utility function to the code that converts from a <code><nowiki>GtkMenuBar</nowiki></code> to a <code><nowiki>GtkMenu</nowiki></code> solves this. The very nice thing is that it still uses the definitions in the glade file. On line 1269 add:
 
Adding an utility function to the code that converts from a <code><nowiki>GtkMenuBar</nowiki></code> to a <code><nowiki>GtkMenu</nowiki></code> solves this. The very nice thing is that it still uses the definitions in the glade file. On line 1269 add:
 
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
<pre><nowiki>#ifdef MAEMO_CHANGES
 
GtkWidget *main_menu;
 
GtkWidget *main_menu;
 
GList *iter;
 
GList *iter;
 
 
/* Create new main menu */
 
/* Create new main menu */
 
main_menu = gtk_menu_new();
 
main_menu = gtk_menu_new();
 
 
iter = gtk_container_get_children (GTK_CONTAINER (mw->menubar));
 
iter = gtk_container_get_children (GTK_CONTAINER (mw->menubar));
 
while (iter) {
 
while (iter) {
 
GtkWidget *menu;
 
GtkWidget *menu;
 
 
menu = GTK_WIDGET (iter->data);
 
menu = GTK_WIDGET (iter->data);
 
gtk_widget_reparent(menu, main_menu);
 
gtk_widget_reparent(menu, main_menu);
 
 
iter = g_list_next (iter);
 
iter = g_list_next (iter);
 
}
 
}
 
 
hildon_window_set_menu(HILDON_WINDOW(mw->window), GTK_MENU(main_menu));
 
hildon_window_set_menu(HILDON_WINDOW(mw->window), GTK_MENU(main_menu));
 
#endif</nowiki></pre>
 
#endif</nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_mainwindow.c
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_mainwindow.c
 
 
That is all the changes made so now move the project to the target filesystem and run:
 
That is all the changes made so now move the project to the target filesystem and run:
 
 
<pre><nowiki>./configure --enable-hildon --prefix=/usr/ --libdir=/usr/lib
 
<pre><nowiki>./configure --enable-hildon --prefix=/usr/ --libdir=/usr/lib
 
make
 
make
 
make install</nowiki></pre>
 
make install</nowiki></pre>
 
 
and then start the UI for the target filesystem. Click on the shell image and run
 
and then start the UI for the target filesystem. Click on the shell image and run
 
<pre><nowiki>export DISPLAY=:2
 
<pre><nowiki>export DISPLAY=:2
 
liferea</nowiki></pre>
 
liferea</nowiki></pre>
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=hildonized.png
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=hildonized.png
 
 
Here it is running in the maemo environment too
 
Here it is running in the maemo environment too
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea_maemo.png
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea_maemo.png
 
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea-1.4.2b.tar.gz
 
https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea-1.4.2b.tar.gz
  
 
[[category:UbuntuHelp]]
 
[[category:UbuntuHelp]]

2007年11月30日 (五) 21:59的版本

This uses some information from upstream. If you are feeling really brave do this first.

Objective

This shows how to port an application written in C (liferea) to Ubuntu Mobile. Liferea is an aggregator for online news feeds written in C utilizing GTK for its graphical interface.

Assumed Knowledge

You have set up the UME development environment as show here. Also that you can change the Flash UI as explained here. You should be familiar with or have the desire to learn C programming, including the 'auto' tools. A good tutorial on automake is here Dependencies Needed aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner

Overview

Porting applications basically comes down to two things: 1. Use HildonProgram and HildonWindow classes instead of the GtkWindow class. 2. Use the HildonWindow menu bar instead of the GTKMenuBar

Get the source and try to compile

user@machine:/home/ian/Dev/Ume/ports/src# apt-get source liferea this downloads the source

liferea-1.4.2
liferea_1.4.2.orig.tar.gz
liferea_1.4.2-0ubuntu1.diff.gz
liferea_1.4.2-0ubuntu1.dsc

this gives some ./autoconf errors like:

No package 'libxslt' found
No package 'sqlite3' found
No package 'libglade-2.0' found

which are the applications dependencies, so install the packages needed if you have not already done so: aptitude install libgtkhtml2-0 libgtkhtml2-dev libxml-perl libxslt1-dev libglade2-0 libglade2-dev libsqlite3-0 libsqlite3-dev libhildondesktop-dev xulrunner this passed autoconf but running make gave an error of:

gtkhtml2.c: In function 'gtkhtml2_launch_url':
gtkhtml2.c:458: error: too many arguments to function 'update_request_new'
gtkhtml2.c:458: warning: assignment from incompatible pointer type
gtkhtml2.c:459: error: dereferencing pointer to incomplete type
gtkhtml2.c:460: error: dereferencing pointer to incomplete type
gtkhtml2.c:461: error: dereferencing pointer to incomplete type
gtkhtml2.c:462: error: dereferencing pointer to incomplete type
gtkhtml2.c:463: error: dereferencing pointer to incomplete type
gtkhtml2.c:465: error: too few arguments to function 'update_execute_request'
make[4]: *** [liblihtmlg_la-gtkhtml2.lo] Error 1
make[4]: Leaving directory `/home/ian/Desktop/liferea-1.4.2/src/gtkhtml2'

It seems to be hitting by this bug. So downloaded the latest bugfix stable release 1.4.2b and this compiled successfully and also ran make ok so now it is time to 'Hildonize' it.

HILDONIZING

It is useful to know that the default location for C header files is in /usr/include. Inside this directory we have another directory hildon-1 and inside this directory we have hildon, so the full path to the hildon header files is: /usr/include/hildon-1/hildon First modify the file configure.ac Around line 42 add the line: AC_ARG_ENABLE(hildon, AS_HELP_STRING([--enable-hildon],[compile for Hildon environment @<:@default=no@:>@]),,enable_hildon=no) and then on lines 212 - 225 add:

dnl ********
dnl Hildon
dnl ********
if test "x$enable_hildon" = "xyes"; then
dnl AC_MSG_CHECKING([for GtkHTML2 support])
PKG_CHECK_MODULES([HILDON], hildon-1 >= 1.0.5,enable_hildon=yes,enable_hildon=no)
AC_SUBST(HILDON_CFLAGS)
AC_SUBST(HILDON_LIBS)
else
enable_hildon=no
fi
AM_CONDITIONAL(WITH_HILDON, test "x$enable_hildon" = "xyes")

and then finally on line 548 echo the information back so that there is visual confirmation to the user that Hildon is enabled: echo "Build Hildon support............ : $enable_hildon" these changes enable the passing of the argument --enable-hildon on the command line like: ./configure --enable-hildon https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=configure.ac After making these changes run autoreconf: user@machine:~/Dev/Ume/liferea-1.4.2b$ autoreconf This step is necessary because autoreconf runs autoconf, autoheader, aclocal, automake, libtoolize, and autopoint (when appropriate) to update the Build System in the specified directories and their subdirectories. In other words it registers the changes made to configure.ac Next change Makefile.am This is located in the liferea-1.4.2b/src directory. On line 67 add the Hildon libraries $(HILDON_LIBS) to liferea_bin_LDADD

liferea_bin_LDADD =	net/liblinet.a \
			parsers/libliparsers.a \
			fl_sources/libliflsources.a \
			notification/liblinotification.a \
			ui/libliui.a \
			$(PACKAGE_LIBS) $(X_LIBS) $(X_PRE_LIBS) -lX11 $(X_EXTRA_LIBS) $(DBUS_LIBS) $(NM_LIBS) $(INTLLIBS) $(GNUTLS_LIBS) $(HILDON_LIBS)

https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=Makefile.am this enables liferea to link against the Hildon libraries. Next change the Makefile.am inside the liferea-1.4.2b/src/ui directory. On line 11 add: libliui_a_CFLAGS = $(PACKAGE_CFLAGS) $(DBUS_CFLAGS) $(HILDON_CFLAGS) this passes the $(HILDON_CFLAGS) to the compiler https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_Makefile.am These are all the changes needed to be made to autotools. Next copy the liferea.glade file which is in the root liferea-1.4.2b directory and rename it to liferea_hildon.glade This means that if the --enable-hildon flag is passed at compile time the liferea_hildon.glade file is used and if not liferea.glade is used. Here are the differences between the two files:

user@machine:/home/user/liferea-1.4.2b$ diff -Nu liferea.glade liferea_hildon.glade 
--- liferea.glade       2007-08-19 13:56:50.000000000 -0400
+++ liferea_hildon.glade        2007-09-25 14:17:38.000000000 -0400
@@ -2,11 +2,8 @@
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--*- mode: xml -*-->
<glade-interface>
-  <widget class="GtkWindow" id="mainwindow">
-    <property name="title" translatable="yes">Liferea</property>
-    <property name="default_width">640</property>
-    <property name="default_height">480</property>
-    <property name="icon_name">liferea</property>
+  <widget class="GtkVBox" id="mainwindow">
+    <property name="visible">True</property>
<child>
<widget class="GtkVBox" id="vbox1">
<property name="visible">True</property>

https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea.glade https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea_hildon.glade In short the mainwindow is a GtkVBox in the hildon version and a GtkWindow normally. This change is explained in this tutorial in the section 'Hildonizing Main View' Now liferea needs to know to pull in the appropriate glade file depending on whether it is compiled for hildon or not. In the file liferea-1.4.2b/src/ui/ui_shell.c inside the function static void liferea_shell_init (LifereaShell *ls) line 113 now looks like:

#ifdef MAEMO_CHANGES
	ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", "mainwindow", GETTEXT_PACKAGE);
#else
	ls->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", "mainwindow", GETTEXT_PACKAGE);
#endif

Also the file liferea-1.4.2b/src/ui/ui_dialog.c inside the function GtkWidget *liferea_dialog_new (const gchar *filename, const gchar *name) line 139 now looks like:

#ifdef MAEMO_CHANGES
		ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea_hildon.glade", name, GETTEXT_PACKAGE);
#else
		ld->priv->xml = glade_xml_new (PACKAGE_DATA_DIR G_DIR_SEPARATOR_S PACKAGE G_DIR_SEPARATOR_S "liferea.glade", name, GETTEXT_PACKAGE);
#endif

https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_shell.c https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_dialog.c All the other changes to Liferea are in liferea-1.4.2b/src/ui/ui_mainwindow.c On line 34 add the header file include:

#ifdef MAEMO_CHANGES
#  include <hildon/hildon-program.h>
#endif

On line 66 in the function static struct mainwindow create the HildonProgram structure like:

#ifdef MAEMO_CHANGES
	HildonProgram	*program;
	GtkWidget	*container;
	GtkWidget	*window;
#else
	GtkWindow	*window;
#endif

On line 536 in the function static struct mainwindow *ui_mainwindow_new(void) make an instance of a HildonProgram like:

#ifdef MAEMO_CHANGES
	mw->program = HILDON_PROGRAM(hildon_program_get_instance());
	mw->container = window;
	mw->window = hildon_window_new();
	gtk_container_add(GTK_CONTAINER(mw->window), GTK_WIDGET(mw->container));
	hildon_program_add_window(mw->program, HILDON_WINDOW(mw->window));
#else
	mw->window = GTK_WINDOW (window);
#endif

Also the maemo tutorial mentioned above notes 'Also remove functions accel_set_func and accel_edited_callback' so on line 1255 add:

#ifndef MAEMO_CHANGES	
	accel_group = gtk_ui_manager_get_accel_group (ui_manager);
	gtk_window_add_accel_group (mw->window, accel_group);
#endif

PortingCAppsToUME?action=AttachFile&do=get&target=liferea.png

Now on to the menu functions.

This blog post provided the inspiration for this. Trying to use the GtkUIManager caused a problem. The reason is that hildon_window_set_menu expects a GtkMenu as second argument, but the GtkUIManager gives a GtkMenuBar Adding an utility function to the code that converts from a GtkMenuBar to a GtkMenu solves this. The very nice thing is that it still uses the definitions in the glade file. On line 1269 add:

#ifdef MAEMO_CHANGES
	GtkWidget *main_menu;
	GList *iter;
	/* Create new main menu */
	main_menu = gtk_menu_new();
	iter = gtk_container_get_children (GTK_CONTAINER (mw->menubar));
	while (iter) {
		GtkWidget *menu;
		menu = GTK_WIDGET (iter->data);
		gtk_widget_reparent(menu, main_menu);
		iter = g_list_next (iter);
	}
	hildon_window_set_menu(HILDON_WINDOW(mw->window), GTK_MENU(main_menu));
#endif

https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=ui_mainwindow.c That is all the changes made so now move the project to the target filesystem and run:

./configure --enable-hildon --prefix=/usr/ --libdir=/usr/lib
make
make install

and then start the UI for the target filesystem. Click on the shell image and run

export DISPLAY=:2
liferea

PortingCAppsToUME?action=AttachFile&do=get&target=hildonized.png Here it is running in the maemo environment too PortingCAppsToUME?action=AttachFile&do=get&target=liferea_maemo.png https://help.ubuntu.com/community/UMEGuide/ApplicationDevelopment/PortingCAppsToUME?action=AttachFile&do=get&target=liferea-1.4.2b.tar.gz