▲ Top

Blog

Posting to the N97 home screen from Qt/S60

The Nokia N97 has a home screen, where applications can add 'widgets'; the C++ API is rather limited, and restricts you to a few simple layouts:

  • One big image
  • An image with 1/2/3 lines of text next to it
  • 3 lines of text without an image

I've written a small wrapper class (well, two, including the private helper class) for C++/Qt applications to let you interface with this API in a more comfortable manner (QString support, etc) - the code is on gitorious.

As a small example:

// Replace the hex id below with your application UID3
// See http://urlx.eu/_NDAzOQ - 'Choosing the UID3 value',
// and make this match TARGET.UID3= in your .pro file.
N97HomeScreenWidget* homeScreenWidget =
    new N97HomeScreenWidget(
        N97HomeScreenWidget::ThreeTextLines,
        "Qt Test",
        "0xA89FA3A0", this
);

homeScreenWidget->setText(
    N97HomeScreenWidget::LineItem1,
    tr("Hello, World")
);

// there's also some signals you can connect to for
// user interaction events on the home screen

// Create the widget if neccessary, and push updates.
homeScreenWidget->update();


// The widget stays around when the application's
// not running, and when the object is deleted.
// To remove:
homeScreenWidget->remove();

For images, you can either specify a path, or a QPixmap.

0 comments.

Multiple Sites with One SSL Certificate

There's two ways of doing this that I use; one is fairly clean:

  • Get a wildcard certificate (*.example.com)
  • Put all of your sites as subdomains (eg foo.example.com, bar.example.com)

While it "just works", it restricts your choice of domains; an alternative solution, which isn't really suitable for your users, but fine if you just want secure access to an admin panel (your blog, PhpBB, etc) on several different domains, you can hack something together with Apache, mod_proxy, mod_rewrite, and some cookies:

Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Thu, 01 Jan 1970 00:00:00 +0000"

RewriteEngine on

RewriteRule ^unset$ https://example.com/ [L,R=301,CO=site:example.com:example.com]

# foo.example.com
RewriteRule ^foo$ https://example.com/ [L,R=301,CO=site:foo:example.com]

RewriteCond %{HTTP_COOKIE} site=foo
RewriteRule ^(.*)$ http://foo.example.com/$1 [L,P]

# bar.example.com
RewriteRule ^bar$ https://example.com/ [L,R=301,CO=site:bar:example.com]

RewriteCond %{HTTP_COOKIE} site=bar
RewriteRule ^(.*)$ http://bar.example.com/$1 [L,P]

If you install the above as ".htaccess" in the root of https://example.com, then https://example.com/foo will make https://example.com/ act as a proxy for http://foo.example.com, https://example.com/bar will make https://example.com/ act as a proxy for http://bar.example.com, and https://example.com/unset will make it display whatever it normally displays.

I hope someone finds this useful.

5 comments.

Qt4 GUI Testing with Hooq

One of the things I've had the pleasure of working with for Mendeley is Hooq; Hooq is a GPL/LGPL-licensed system for testing Qt4 GUI applications, on multiple platforms (Linux and Windows being where most of the focus has been at the moment). It's mostly GPL, but an LGPL library is loaded into applications being tested, at runtime.

With apologies in advance for the incredibly unfriendly UI at the moment (patches welcome :p), here's a lots-of-pictures demonstration on using it to test a trivial application.

After building the demo application and Hooq, and running hooq, you'll get a screen like the following:

Screenshot of a fresh Hooq installation

For organisation, Hooq uses the concept of a 'test set' - this can be one per application, tests for different areas of the same application, or whatever you choose. First, you need to create one - select "New Test Set..." from the file menu, and you'll get another ugly dialog:

Screenshot of Hooq's Test Set dialog

After filling it in and clicking OK, you'll be back to the main screen, except that 'Test set' will be filled in (screenshot); type in 'Foo' in the box at the bottom, then click 'Record' (screenshot). The demo application will then start - if you type in "Hello, World" you should see something like this:

QTextEdit with "Hello, World" in it

Click the close button in the window decorations, and the Hooq window will now have a test entry, with run and edit buttons:

Hooq main window with a test in it

After clicking on the edit button highlighted above, you'll get a script editor (Hooq uses QtScript for test scripts):

Hooq's script editor

If you then click in the margin on the line after "QTextEdit_0.sendText(string0)", there'll then be a breakpoint marker on that line:

Hooq script editor with a breakpoint set

If you then click the run button in the toolbar, the script will stop running at that line:

Hooq after triggering a breakpoint

At this point, if you click 'pick property' in the toolbar (new icons welcome), you can then click on any widget in the application being tested, and get a list of its Q_PROPERTYs:

Q_PROPERTY list

For this example, scroll down to "plainText", and click compare; this will insert a check into the JavaScript code in the editor:

Script editor with added compare()

Remove the breakpoint, and run it a few times; it should repeat your input and quit each time, without an error; however, if you change the "string0" variable at the top from "Hello, World" to something else, like "Hello, World!", then click run, the test will error, if you don't also change the compare statement:

Thrown exception in Hooq

This is more useful when the test hasn't changed, but when the application itself has (i.e. a regression). Hooq also has a "Run All" feature, to run all the tests in a set unattended, and show a summary at the end.

As some more detailed information:

Hooq loads a shared library into the application being tested (via gdb under Linux, and a very ugly hack under Windows) which recieves every QEvent in the application, and sends user input events, encoded in XML, to a hooq client (the GUI client is shown above, but there's also a CLI one that just records and plays the XML data). In the GUI client, the XML is converted into a tree of sorts, and then a few modifications are optionally made (selectable via the "Options" menu):

Hooq options menu

These options are:

Ignore Mouse Movements
Don't create JavaScript code for mouse events, except where they end up creating drag and drop events.
Simplify Mouse Movements
Only available if the above is off; instead of creating code for every single 1-pixel mouse movement made, create simplified code, like "move in a straight line from (x1, y1) to (x2, y2) over 300 milliseconds"
Simplify Strings
Repeated keyPress/keyRelease events are composed into "sendText" events, which take a string parameter. Like the two above options, this greatly decreases the length, and increases the readability of the generated code.
Use Variables For Strings
Any string used by sendText is stored in a JavaScript variable, instead of being hardcoded every time it is used; this makes it easier to modify the script in the future.
Use Variables For Object References
This doesn't change the meaning of the code at all, but generally makes the code shorter.
Include Raw XML as Comment
Mainly useful for debugging; includes the raw XML code received over the socket as a JavaScript comment
Ignore Qt Internal Widgets
Qt in some circumstances (such as drag and drop under X11) automatically creates magic widgets; this option makes Hooq ignore them.

26 comments.

Accessing joysticks with Qt

I got another email asking for the code for my interface between SDL's joystick stuff and Qt that I wrote for my final year university project; I've been meaning to tidy this up a little and publish it for some time, but never quite got around to it - well, I finally have:

http://files.fredemmott.co.uk/SDL-joystick-qt.tar.bz2 - just a .h and a .cpp, ISC-licensed.

1 comments.

Archive