Random notes from mg

a blog by Marius Gedminas

Marius is a Python hacker. He works for Programmers of Vilnius, a small Python/Zope 3 startup. He has a personal home page at http://gedmin.as. His email is marius@gedmin.as. He does not like spam, but is not afraid of it.

Fri, 29 Jul 2011

Porting FBReader to Meego 1.2 Harmattan

Andrew Olmsted built the first FBReader packages for Harmattan, after tweaking the build system a bit. The desktop version of FBReader already used Qt 4, and ran almost unmodified, but with some bugs (segfault on task switch) and ugly UI.

I started with the Ubuntu packages for FBReader, since they used a more sane build system for .debs (compared to upstream's funky shell script). Some tweaks were needed to make it build in Scratchbox: since GTK+ and Hildon libraries aren't available on Harmattan, I had to disable the building of -gtk and -maemo versions of libzlui. I also got to learn a new tool — quilt.

Fixing the segfault took a couple of days of debugging, studying the source code of both FBReader and Qt itself, and asking for help on IRC. Turns out FBReader was holding an active QPainter instance for too long, and its backing pixmap got destroyed (or, rather, converted from an OpenGL texture to a plain X11 pixmap) during a task switch, causing the crash. I'm probably describing this wrong BTW, but, in any case, adding QPainter::begin() and QPainter::end() calls in the paintEvent handler fixed the segfault.

Next, a small tweak in the .desktop file to make FBReader a single-instance application: change Exec=FBReader to Exec=single-instance /usr/bin/FBReader (I'm paraphrasing slightly).

Then, a more ambitious goal: making FBReader intercept volume keys and use them for scrolling. Google gave me a pointer to QmKeys, which was the wrong API to use here, but gave me a lead to qmkeyd2, which appears to be an open source daemon, which gave me a lead to sysuid, another open source daemon, which in turn gave me a lead to libresourceqt, and that was the right API at last.

Volume keys generate regular key events for XF86AudioRaiseVolume and XF86AudioLowerVolume, but they're also intercepted by qmkeyd2, which tells all subscribers (and sysuid is one) about them. Which subscriber gets to react is determined by the resource policy framework. So what I needed to do in FBReader was acquire the ScaleButtonResource when FBReader starts up or gets focus, and release it when FBReader quits or goes into background. That also required some IRC help until I discovered installEventFilter() and the ApplicationActivate/ApplicationDeactivate events. And QApplication::instance().

The various tools available in the developer firmware were invaluable: openssh, gdb, valgrind, strace, xev, xprop, lsof, netstat. Also, I would not have achieved my second goal without being able to look at the sources of Meego system components (qmkeyd, sysuid). Yay open source!

Here are my changes to the source code. You can find my modified Debian packaging files, as well as prebuilt binary packages (with full debug info, for gdb goodness), in my experimental harmattan apt repository. The UI is still ugly and non-native, but it doesn't matter much in fullscreen mode :) .

Note to self: when next building fbreader, make sure the 2 megabyte tags file doesn't end up in the .diff.gz. And speaking of crud in source packages, the vim package I built for Harmattan the other day contains the entire 50 meg .hg in the .orig.tar.gz. I need to figure out how to tell dh_make to omit it.

posted at 03:16 | tags: , | permanent link to this entry | 10 comments
When building source packages from a Git repo, I use the following - you should be able to adapt it to your Mercurial repos easily:

dpkg-buildpackage -rfakeroot -S -i.git -I.git
posted by thp at Fri Jul 29 13:02:47 2011
I use dpkg-buildpackage -i, which has a default regexp that skips .git and a lot of other things.  But dpkg-buildpackage doesn't create the .orig.tar.gz, does it?  I got mine when I ran dh_make --createorig in a checkout of vim's Mercurial repository.  Maybe I should've created the tarball myself (e.g. using hg archive that I discovered by looking at hg help today).
posted by Marius Gedminas at Fri Jul 29 14:18:46 2011
Stupid question -- how do i switch to fullscreen?
posted by ArkanoiD at Fri Jul 29 14:56:33 2011
To toggle fullscreen mode open the hardware keyboard and press Enter.
posted by Marius Gedminas at Fri Jul 29 15:59:12 2011
Could you provide direct download link? debs can be installed directlyötjat way - that is, if all dependencies are satisfied in advance  or provided within single deb file.
posted by jani mikkonen at Fri Jul 29 16:18:58 2011
FBReader has a bunch of dependencies.  You'd need to install 10 deb packages by hand, in the right order.  That's why I didn't include a direct download link.

I'm waiting for some equivalent of the old Maemo Extras to be set up for Harmattan.
posted by Marius Gedminas at Fri Jul 29 17:04:16 2011
Too cool!

You should also post the .deb here:

http://forum.meego.com/forumdisplay.php?f=7

Thank you, Marius!!!
posted by timsamoff at Sun Jul 31 01:51:30 2011
Hi all! I've done port of FBReader to QML in a week, and only now I've met this page :-D
Try sources at https://github.com/euroelessar/FBReader - they mostly are already at mainstream source repo at "meego" branch.
Debian package is available here: http://qutim.org/downloads/fbreader_0.14.0-1_armel.deb (It doesn't require any additional packages to fit in OVI requirements)

Marius, thanks for volume buttons support :)
posted by EuroElessar at Sat Sep 3 16:16:04 2011
There are now official FBReader packages for Harmattan (still BETA as of this moment) at http://www.fbreader.org/meego/, with proper QMLization and everything, or so I understand.

I haven't tried them out yet (don't fix what ain't broke and so on: my hack works well enough for me for now).  I intend to, when I flash a newer firmware to my N950, which is, frankly, a hassle.
posted by Marius Gedminas at Sat Oct 8 10:29:28 2011
So, the 0.99.1 beta works almost fine.  There's one problem: "Open File..." fails to do anything.  If you've enabled Developer Mode on your Harmattan phone, you can fix that by editing /usr/share/zlibrary/declarative/Main.qml: replace "rootWindow.openDialog" on line 42 with "root.openDialog".
posted by Marius Gedminas at Mon Oct 10 21:19:16 2011

Name (required)


E-mail (will not be shown)


URL


Comment (some HTML allowed)