Adding a UI Entry in a package

07/15/08

Permalink 07:29:13 pm, by neilb Email , 723 words, 4248 views   English (US)
Categories: Developing for the Eee

Adding a UI Entry in a package

More on the process of packaging. Here is how to automatically add an entry into the desktop that will launch an application in your package.

If you have developed any UI code for the Eee PC, you are likely aware that the Eee PC stores its desktop entries in a file called


/opt/xandros/share/AsusLauncher/simpleui.rc.

Take a look at this file on your system. It is an XML format file. Each entry is composed of a block of XML of the element <parcel>, so for example here is the entry for firefox



<parcel simplecat="Internet" shortcut="/opt/firefox/firefox.desktop"
icon="web_norm.png"
selected_icon="web_hi.png">
<name lang="en">Web
<name lang="zh_TW">網路瀏覽器
<name lang="zh_CN">网页浏览器
<name lang="es_AR">Web
<name lang="de_DE">Web
<name lang="es_ES">Web
<name lang="fr_FR">Web
<name lang="it_IT">Web
<name lang="nl_NL">Web
<name lang="pt_PT">Internet
<name lang="ru_RU">Веб
<name lang="th_TH">เว็บ
<name lang="tr_TR">Web
</parcel>

This adds the firefox application to the Internet page of the desk top and associates icons for the selected and unselected states. The various names entries add names for various languages.

So to add a UI entry, we need the package to automatically add a parcel entry to the simpleui.rc file for your application.

Since XML uses end tags to close off the data format we need to effectively edit the file (as opposed to just appending to the file). The best tool to use is therefgore sed. Here is some sed code that automatically adds an entry to the UI.


sed -e '/<\/simpleui>/i\
<!-- MySpecialProgram version=1.0 { -->\
<parcel simplecat="Play" extraargs="/usr/bin/sudo /home/user/bin/myspecialprogram" \
icon="sysinfo_norm.png" \
selected_icon="sysinfo_hi.png"> \
<name lang="en">My Special Program</name>\
<name lang="zh_TW">My Special Program</name>\
<name lang="zh_CN">My Special Program</name>\
<desc lang="en">Does some cool stuff</desc>\
</parcel> \
\
' simpleui.rc

This code inserts a chunk of XML prior to the end of the UI control file that will add an entry to the “Play” tab to run the program /home/user/bin/myspecialprogram. In this case, I’ve assumed that myspecialprogram does some system stuff and so is launched with sudo. I’ve used the technique of wrapping the XML block in structured comments. This allows future edits to the UI file to move the XML block and yet it can still be located.

Of course, your users may not actually like your app and want to uninstall it. Here is the code to do just that.


sed -e '/<!-- MyTool version=1.0 {/,/<!-- } MyTool version=1.0 -->/d' /opt/xandros/share/AsusLauncher/simpleui.rc

To use this as part of the package we need to call the code from the scripts in the package DEBIAN directory. I use the postinst script file to perform the add and the prerm script to do the remove. So in the package DEBIAN directory

put the file postinst with the code


#! /bin/sh
sed -e '/<\/simpleui>/i\
<!-- MySpecialProgram version=1.0 { -->\
<parcel simplecat="Play" extraargs="/usr/bin/sudo /home/user/bin/myspecialprogram" \
icon="sysinfo_norm.png" \
selected_icon="sysinfo_hi.png"> \
<name lang="en">My Special Program</name>\
<name lang="zh_TW">My Special Program</name>\
<name lang="zh_CN">My Special Program</name>\
<desc lang="en">Does some cool stuff</desc>\
</parcel> \
<!-- } MySpecialProgram version=1.0 -->\
' /opt/xandros/share/AsusLauncher/simpleui.rc > /tmp/lidman-simpleui.rc
mv /tmp/lidman-simpleui.rc /opt/xandros/share/AsusLauncher/simpleui.rc

and put the file prerm with the following contents


#! /bin/sh
sed -e '/<!-- MyTool version=1.0 {/,/<!-- } MyTool version=1.0 -->/d' /opt/xandros/share/AsusLauncher/simpleui.rc
mv /tmp/lidman-simpleui.rc /opt/xandros/share/AsusLauncher/simpleui.rc

NOTE that both files use the absolute location of the simpleui.rc file.

As a final piece, ensure that the package depends on “sed” by putting


Depends: sed

in the DEBIAN/control file. This is a just for completeness issue. Eee PCs come with sed installed.

More on packaging to follow in future blog entries.

Pingbacks:

No Pingbacks for this post yet...

This post has 437 feedbacks awaiting moderation...

Digital Annealing Eee PC Blog


October 2017
Sun Mon Tue Wed Thu Fri Sat
 << <   > >>
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        

Search

Choose skin

Linkblog

Misc

XML Feeds

What is RSS?

Who's Online?

  • Guest Users: 10

powered by b2evolution free blog software