Category Archives: General

Avoiding Use of Deprecated API

Most Deprecated GTK+ 2 API is not in GTK+ 3

GTK+ 3 has API changes compared to GTK+ 2, but some of the new API has been added to GTK+ 2.22 and 2.24, and older API has been deprecated. gtkmm has done this too. This is intended to ease porting to GTK+ 3 (or gtkmm 3). If your application builds with GTK+ 2.24 with deprecated API disabled then it will be much easier to port to GTK+ 3 afterwards.

This requires defining C macros such as GTK_DISABLE_DEPRECATED, though you’ll want to use GDK_DISABLE_DEPRECATED, GDK_PIXBUF_DISABLE_DEPRECATED, G_DISABLE_DEPRECATED and maybe PANGO_DISABLE_DEPRECATED too. You can specify these as -D options in your Makefile.am.

However, you should not disable deprecated API in your build at all times. That just makes life unnecessarily difficult for people building from tarballs.

So over the last few years, Daniel Elstner has perfected an MM_ARG_ENABLE_WARNINGS m4 macro for use with autotools. It adds an –enable-warnings=min/max/fatal/no configure option. We use it mostly to turn on compiler-warnings-as-errors, but I think that it would be very useful to many people now during the transition to GTK+ 3.

MM_ARG_ENABLE_WARNINGS

This macro is in mm-common, which you could depend on, though it contains other stuff that is only interesting to gtkmm projects. For instance, I use it in Glom’s configure.ac file, like so:

MM_ARG_ENABLE_WARNINGS([MYPROJECT_WFLAGS],
  [-Wall],
  [-Wall -Wextra -Wno-missing-field-initializers -DGSEAL_ENABLE],
  [G GDK GDK_PIXBUF PANGO GTK])

I then use the resulting variable in my Makefile.am file, like so:

AM_CFLAGS = $(MYPROJECT_WFLAGS)

If you use non-recursive autotools (and you should) then you won’t need to repeat that much.
I also added the option to DISTCHECK_CONFIGURE_FLAGS so I am forced to fix any warnings during make distcheck, when doing a tarball release. You don’t need to do that.

Whenever I build one of these projects from git I specify –enable-warnings=fatal to autogen.sh and fix any problems that it finds. That’s why there are zero compiler warnings or use of deprecated API in Glom.

DK_ARG_ENABLE_WARNINGS

You might prefer to copy the standalone version into your project instead. There are copies of the standalone macro in various projects already. Here is an example commit that adds it to a project.

The macro call looks like this in your configure.ac, for instance:

DK_ARG_ENABLE_WARNINGS([MYPROJECT_WFLAGS],
  [-Wall -w1],
  [-pedantic -Wall -Wextra -w1],
  [G GDK GDK_PIXBUF PANGO GTK])

Translated gtkmm.org Web Site

Since May 2010, gtkmm.org has been available in Chinese as well as English, thanks to a patch from Tao Wang. It uses DocBook XML and xml2po, like any other GNOME documentation, along with some custom DocBook XSL stylesheet parameters and our web site’s CSS.

It works. Translations can be kept up to date easily when the original English changes (though they haven’t so far in this case, admittedly) because the translations are not in copies of the documents, but in regular gettext .po files. It’s not a CMS, and editing is not particularly user-friendly, but it’s no worse than the untranslated HTML that we had previously.

I recently cleaned up the web site’s directory structure so it’s more like an application or documentation manual so you can see what I mean. And the gtkmm.org translation status is available on l10n.gnome.org thanks to Claude Paroz. The gtkmm book is also translated in the same way, so now everything other than our (Doxygen) API reference is translatable.

The build could be improved by someone who knew how. You currently need to add an HTML_generation block in the Makefile.am when you add a new locale.

Liam at the Kindergarten

Liam is at the end of his first two weeks at the kindergarten, during which we spent time with him there while he got used to it. People may have noticed that my daily routine changed.

We were incredibly lucky to get a place at the Kindergarten on the corner near us, after being incredibly lucky to get a place at the crèche over the road from us. This is not a normal experience. I had given up hope of finding a place in the next few years but then the phone rang with the news.

He has far more freedom there than he is used to, and suddenly he’s not the oldest, but he is adjusting. I’m proud of him.

Non-Automatic Layout is Useless / Qt Designer has bad defaults

The widgets in a UI should adapt to different window sizes, font sizes, translated text, left-to-right/right-to-left locales, etc. This is obvious to the programmers that I work with.

I recently remembered that qt-designer didn’t do this when I last tried, which shocked me. So I looked again at a newer version to see if it would make me happier. I took some side-by-side screenshots of Glade and qt-designer on my wide monitor, to make the point.

For instance, see the slideshow to experience the first-impression that a half-competent developer is likely to get. Buttons that were in the corner will be left stranded in a sea of blank space. Widgets will appear half out of the window.

All of this is unnecessary. qt-designer/qt-creator can actually do proper automatic layout if you right-click on the layout, and choose the “Lay out” -> “Lay Out in a Grid” menu item. The default is called “Lay Out in a Form Layout”. Presumably someone decided to make Visual Basic users feel at home by duplicating their stupid environment, but that just keeps them doing stupid things and makes regular developers go elsewhere.

By the way, I do like one thing in qt-designer more than Glade. It correctly assumes that a treeview is more likely than a text label to need to expand.

Note that qt-creator, which uses the same system, apparently via the same code, does the same thing. I checked the latest qt-creator snapshot.

gtkmm book on Kindle

I recently got a Kindle 3 which I’m really enjoying.

As an experiment, I published a Kindle version of the “Programming with gtkmm” book. I don’t actually expect to sell many, though it could be a convenience for some people. I wish I could just “Print to Kindle” from my computer.

I set the “list price” at $2.00, but it appears as $4.60 to me here in Germany. It might be $2.00 to people in the US. I get 70 cents each time for both.

The GNOME Events Box is missing

The European GNOME Events Box is currently missing because UPS delivered it to a random address in Odivelas, Portugal instead of the correct address in Sevilla, Spain, and they can’t get it back.

We are usually happy with UPS but they’ve just thrown up their hands and given us a claim form, asking us for the receipts for all the items in the box, some of which were gifts from GNOME-friendly companies.

I don’t have much confidence that UPS have really looked for the box. So if you are near Odivelas, it would be great if you could politely ask there. Please ask me for the full address via email – it doesn’t seem fair to publish it.

Trainee mini gtkmm projects

In August I mentioned the mini GTK+ C projects that our trainees completed: massifg, gmemory and GHangTux.

They recently finished some mini gtkmm C++ projects too, because I think gtkmm is a comfortable way to learn good C++ habits after GTK+. Here they are:

  • Chris Kühl’s Merkmal, a port of gmemory to gtkmm and cluttermm. It’s a card memory game.
  • Patricia Santana Cruz’s GHangtuxmm: A port of GHangTux to gtkmm. It’s a hangman game.
  • Jon Nordby’s glom-postgresql-setup, which does the awkward server configuration that typical Glom users don’t want to worry about.

They are now moving on to Qt and they’ll get some exercise on deeper OO and C++ concepts. In fact, Jon Nordy has already created a QImage plugin to support the OpenRaster image format.

Openismus contributions to GTK+

Openismus has made several contributions to GTK+ recently, getting changes into the upstream releases, doing things properly via bugzilla and the mailing lists, working with other developers even when it’s complicated, so it’s done right. This has helped my application, Glom, which uses GTK+ via gtkmm. It shows that we could do the same for you.

For some of our employees this is also a slight reward for being so busy coding with Qt right now. We love GTK+ as much as ever, regardless of one big company’s arbitrary choice to stop using it. Some of us like it even more now.

A short list of recent Openismus work on GTK+:

Tristan also created a couple of useful container widgets that were not needed in GTK+ itself so they are now in libegg. They were made possible by the extended layout support in GTK+ 3.

  • EggWrapBox
    By Tristan. This positions child widgets in sequence according to its orientation. For instance, with the horizontal orientation, the widgets will be arranged from left to right, starting a new row under the previous row when necessary, as in a toolbar or tool palette.
  • EggSpreadTable (screenshots)
    By Tristan and ported back to libegg by our David King. This positions its children by distributing them as evenly as possible across a fixed number of rows or columns, like newspaper columns.

gtkmm 2.91.2

Just a day after the GTK+ 2.91.2 release, I managed to release gtkmm 2.91.2, with (hopefully) all the new API. I have Glom and the gtkmm-documentation examples building with the latest gtkmm as a test.

I also did a release of glibmm 2.27.1, matching the glib 2.27.1 release. José Alburquerque has been working very hard on this, while also working on gstreamermm. But we really need some feedback on all the new API, particularly the Gio::DBus* stuff. Someone needs to sit down and write example code to see if it even works. We skipped the stable glibmm 2.26.x releases because this had not happened so we were not ready to call the API/ABI stable.

libgda’s SqlBuilder API

SQL is complicated and strange and subtly different depending on the server, particularly for complex queries, which means anything that a user might find useful.

Glom built SQL queries internally, concatenating strings together with some helper functions. But that was still fragile and repetitive so I recently ported Glom to use the new GdaSqlBuilder API, via its Gda::SqlBuilder C++ wrapper. I don’t know of any similar open-source API for this in C or C++.

GdaSqlBuilder doesn’t completely hide the almost-free-form structure of SQL, but it does encourage you to only write queries that makes sense. As a bonus, you don’t have to worry about correct quoting, correctly representing values as text, correctly escaping that text, or correctly quoting table and field names. It should also hide most server-specific syntax, making it easier to port applications to different database servers. I’m happy to remove some of that awkward code from Glom.

Vivien Malerba was very responsive to my feedback, so I now think that the GdaSqlBuilder API is about as good as it can be in C. I think Gda::SqlBuilder is even nicer, thanks to C++ method overloading.

But it still doesn’t feel quite right – you can’t guess what the functions do without reading the documentation, many functions have similar names, and some functions can only be used on certain types of queries at certain times. I guess the Select and non-Select queries should be in separate (related) classes, instead of just mentioning “select” in the method name, but that would lead to annoying casting in C. Maybe I’ll do that in the C++ API.