Moved from Blogger

So, blogger is shutting down the ability to publish via ftp. This more or less forced me to move away from their service. I decided to switch to a WordPress install on my own server (since I have experience from that). The moving process was easier than I thought it would be, but still not pain-free.

I started the move by backing up my blogger entries. This gave me an XML file of about 2 MB. I’ve heard rumours of people with large file sizes here running into time out issues.

The next stage was to back up all contents of my ftp site – if blogger felt that they had to mess around with it. I still want all my old links to work.

Then I switched to blogspot hosting. This worked great. As I wanted, all my images were kept on my server and the entries still referred back to the correct location.

Moving on, I installed WordPress. Did a quick check of all the settings. Added a non-admin user. Then clicked the big import button. I had to authorize the import and pick which of my blogs to import (I have four). Then the process of importing started and passed without any hiccups. Finally, I assigned the non-admin user as the author of the entires (the import button changes to set author when the import is completed).

What broke then? All entries and titles start with a >, looks like broken XML parsing if you ask me – but I’ll live with it. Also, source code seems to be broken right now, but I might be able to hack at that using css.

To summarize – it went better than expected, but not 100% perfect. Now I’m off to hand patch my atom and rss feeds for various planets to announce this move!

PS. A tip – you ought to be able to alter the blogger theme to redirect users to your new location. To achieve that, make the change BEFORE switching to blogspot hosting, as you cannot switch back.

>Overload

>It has been quite some time since I last blogged. Lots of things are going on, so the time to sit down and reflect has been… let’s say limited.

The last week, I sadly missed foss-sthlm, due to snow. Apparently Swedish trains are built for the summer, so I hope that there will be another get-together later this spring.
I’ve also been working hard on my embedded Linux course. The course date is kind of tight on the Easter, but hopefully STF can find a nice crowd to work with.
Finally, I’ve been spending time trying to learn QtQuick (QML, Declarative UI). I’m really enjoying Jürgen’s blog on this, as the approach feels new to me.

Qt as GTK, again

Another set of night hours spent hacking on making the GTK API wrap Qt. I focused on adding functionality and not on cleaning up, so no code this time either. I just want to show the progress.

Wrapping Qt in GTK might seem like an impossible task, but the fact is that both toolkits, in turn, wrap the same APIs themselves. So, how does the progress look this far?

Upgraded Hello World (link)
The first example, upgraded hello world, works like a charm and does what is expected. There is only one change that has to be made to the example, and the need for it will go away when I’ve started cleaning the code.
Changes made to the example:
  • Replaced the gtk/gtk.h headerfile with my substitute.

Table Packing Example (link)

The next example, table packing, simply demonstrates the grid layout abilities of GTK. There seems to be a couple of pixels between the rows for some reason (I will investigate at a later point), but apart from that, everything works. The changes made are the same as for the first example.

Changes made to the example:
  • Replaced the gtk/gtk.h header with my substitute.

Manual Menu Example (link)

Robin Burchell (w00t) has attempted something similar in the gqt project (gitorious link). We will discuss how we can join forces ASAP (I’ve been sort of unavailable this weekend). The gqt project has clean code – look great. It employs a different approach than I when it comes to mapping signals/slots/events and for handling the construction of menus.

Robin mentioned that one of the major hurdles when mapping the APIs is that GTK uses a widget based structure for menus, while Qt uses QActions for menu items. To have a swing at this, I decided to attack the manual menu example next. It took some changes to the main approach of the wrapping effort, but now I think I have it sorted out.
Changes made to the example:
  • Replaces the gtk/gtk.h header file with my substitute.
  • The popup is always shown at (100, 100) as the GdkEvent structure cannot be cast to a GdkEventButton structure.

Manual Menu Example
Another benefit of doing the manual menu example was that I had to have a better look at the events mechanism. As it seems, the “event” signal hooks into all events (like a Qt event filter). This means that there has to be a general event filter, as well as specific event filters (for when connecting to a specific event such as “delete_event”). This kind of breaks my idea of splitting out the code for creating a specific GdkEvent for each type of event in a separate class, so I need to think a bit about that (shouldn’t really be a major issue – I just don’t want code duplication).
Back to the menu widget versus action approach. As it seems, the QAction and QWidget classes’ common base is the QObject class. Thus all pointers to GtkWidget, GtkWindow, etc. needs to be pointers to QObject. That way, the menu object can be made to match quite nicely. The downside is that the code already contained quite a lot of casts. Now it has even more. For instance, a trivial function such as gtk_container_set_border_width needs casting:
void gtk_container_set_border_width(QObject *o_w, int spacing)
{
   QT_WIDGET_ASSERT(w)w->setContentsMargins(spacing,spacing,spacing,spacing);
}
The QT_WIDGET_ASSERT macro creates a QWidget pointer named w, by casting o_w using qobject_cast and then asserts that the pointer isn’t null. I’m not sure of the performance penalty of this, but I guess there is one. However, to compensate, all of GTK’s GTK_WINDOW, GTK_BOX, etc. are instead defined as simple pass-through macros. This means that performance wise it is a race between GTK_CHECK_CAST and qobject_cast.
I did consider putting the qobject_cast calls in the GTK_xxx macros, but that would not work. For instance, gtk_menu_shell_append can place a QAction in either a QMenu, or in a QMenuBar. As the function is given a QObject pointer, it can now determine (by casting) if the container is a QMenu or QMenuBar and act accordingly.
So, where to next? I belive in fixing the known bugs before continuing. Especially when working on a project such as this, which I suspect will backfire anytime soon (it has been too easy this far). This means that the next step is to do something about the GdkEvent structures to get the popup of the manual menu example to work properly (now it appears at a static location). After that? Cleaning and merging with gqt…

>GTK+ made Qt

>Disclaimer! First of all – this is not an attack on any toolkit, nor critique. Rather, it is a hacker sitting down and trying out an idea.

It has been a couple of years since I first tried out this idea (some seven, I believe). This time, licensing permits it and I believe that the timing is right. So, without further ado, let me introduce GTK+ made Qt.
Qt and GTK+, and all other toolkits out there, provide more or less the same functionality (take that with a grain of salt, but the core is true). So, my idea was to wrap Qt in a GTK+ API layer. Just to see if it could be done. Attacking the problem at this level might be considered stupid – but I like to get results fairly quickly, and this way I can work with GTK+ code directly, instead of writing a ton of underlaying code just to get something to compile.
There are tons and tons of corner cases and not so corner-ish cases that can make this break. The implementation is miles and miles from perfect and the code I’ve been testing it on is rather trivial. What I’ve done is that I’ve taken one of the examples of the GTK+ 2.0 Tutorial and made it do what it is supposed to do (sort of). Examples of what I’ve ignored in the process:
  • Event handling functions get NULL instead of a GdkEvent pointer.
  • Packing flags (e.g. homogenus and spacing when calling gtk_hbox_new) ignored – I simply use QVBoxLayout, QHBoxLayout and QGridLayout where they fit best.
  • Only a minimalist part of the API has been implemented (the process is build, add missing symbols, repeat)
  • Most GtkXxx classes are defined to a QWidget. Objects are casted up and down all over the place to work around this.

However, the problem isn’t really matching the APIs to each other and getting every pixel right. At least, that is not the current problem. Instead, matching Qt’s C++ style OO to GTK+’s is the problem. What are the differences? I hear you ask.

To create a trivial dialog in Qt, you inherit the QDialog class and then create the children in the constructor of your new class. In GTK+, you generally create a function for creating the dialog in question. In that function, all widgets (including the dialog) are created and put in a proper hierarchy. The resulting hierarchy of widgets is (95%) identical, and all the custom code to make it tick is there – it is just placed differently in the source.
Another difference that has a large impact is the fact that Qt event handles are virtual methods of QObjects and slots are QObject methods. In GTK+, they are plain C functions that are passed as function pointer to g_signal_connect calls.
So, the starting point is this example. I’ve placed that code in helloworld.cpp (we need it to build as a C++ source file, I’m sure that GCC can be convinced of that by other means, e.g. by using g++ directly, but just changing the extension does it for me).
The only change made to the source code itself is that the include of gtk/gtk.h has been replaced by the inclusion of gtk-made-qt.h (no, the name is not critique, it is just my strange humor). The header file is the container of the rest of this experiment.

The GTK+ Hello World example running in QtCreator on Windows Vista


First of all, I’ve made some rather rude typedefs and defines with regard to GLib (this just shows how much that needs to be redone to do this properly):

#define G_OBJECT(obj) ((QObject*)(obj))
#define G_CALLBACK(func) ((void*)(func))

typedef void* gpointer;
typedef bool gboolean;
typedef char gchar;

#define g_print qDebug

...

There is more of this of course, and some of it is spread out across multiple header files. Next follows the same horrific crime, but this time made to some of the GTK+ widgets:

#define GtkWidget QWidget

void gtk_widget_show(QWidget *w) { w->show(); }

#define GTK_WINDOW_TOPLEVEL (0)
QWidget *gtk_window_new(int) { return new QWidget(); }
void gtk_window_set_title(GtkWindow *w, const char *t) { w->setWindowTitle(QString(t)); }

...

#define GTK_BOX(obj) (obj->layout())
void gtk_box_pack_start(QLayout *l, QWidget *w, bool expand, bool fill, int padding) { l->addWidget(w); }

As you can see, straight forward, brute force, get the job done hacks. All this shows how close the different APIs match. This is trivial code (albeit unsafe) and adds almost no extra conversions or checks.
The really interesting part is the implementation of the g_signal_connect function. Here, bridges for both events and signals/slots are dynamically setup. So, here it is in all its glory:

void g_signal_connect(QObject *src, const char *cstrEventName, void *f, void *data)
{
QString eventName = QString(cstrEventName);

if (eventName.endsWith("_event"))
{ // This is an event, f is an eventFuncPtr
QObject *o = QGtkEventFilter::createFilter(eventName, eventFuncPtr(f), data);
if(o)
src->installEventFilter(o);
else
qWarning("Failed to match GTK event '%s' to a Qt event filter.", cstrEventName);
}
else
{ // This is a callback, f is an callbackFuncPtr
QObject *o = new QGtkCallbackBridge(src, callbackFuncPtr(f), data);

const char *signalName = 0;
if(eventName == "clicked")
signalName = SIGNAL(clicked());

if (signalName)
QObject::connect(src, signalName, o, SLOT(trigger()));
else
qWarning("Failed to match GTK signal '%s' to a Qt signal.", cstrEventName);
}
}

To my surprise, that is all that it takes. The QGtkCallbackBridge is a trivial QObject that calls the given function pointer with the QObject::sender() and the given data pointer when signalled. The QGtkEventFilter is not much more complicated. It simply filters out the event in question and triggers the given function pointer in much the same way. I’ve created a factory for the event filters, as I want them to re-create something looking like the original GdkEvent structure. There is actually one event filter class for each type of event, just so that this code can be added.
Well, I’ve not packaged the code yet. My goal is to try at least one more example first (perhaps two, given time). In the mean time, let’s see if this can be made useful (a large enough portion of the GTK+ API needs to be implemented for that) – and if the idea is interesting at all (from a political standpoint, etc). As it stands now, this might help porting GTK+ applications to Qt only platforms, or it could be used as a migration kit (not that I encourage people to migrate from GTK+ to Qt – it is a choice that every developer has to make – use whatever feels comfortable to you).

>The wether forcast mentioned snow on Wednesday. We had some yesterday and today it is really snowing away. Looks like I’ll have to buy a sledge for Lisa! Will be great fun.

Right now I’m sitting, writing about Qt’s new animation classes released in 4.6. Looking at the snow, writing about this, makes me wonder if it wouldn’t be a good idea to implement animations that delete themselves and their items when the item leaves a given bounding rectangle.
Why? Then you can define a bounding rectangle, e.g. the screen, and create snow flakes with randomized animations and just let them drop.
I remember doing something like that back in the STOS/AMOS days. You created a sprite, defined an animation pattern and then forgot about it (as I recall). This was great for the 2D shooters of the time with aliens attacking in predefined patterns. Not 100% sure how the surviving aliens (yes, you have to take bad players into account, including me) where handled. The ones you hit could be taken care of in a collision detection handing function called from the inner loop… well, nostalgia might make me look at this in a forgiving light.
Anyway, the snow is falling. There will be more tomorrow. It will probably be cold all the way to Christmas. Looks like we’re in for a white Christmas.

>One month of flying

>It has been a month since I started working in my own business. My former employer has been very kind and let me explore this while on a leave of absense, i.e. I have somewhere to return to.

This Monday I sent my first large invoice to my biggest customer. Now, time to wait for the next pay. What have I learned this far?
  • Bookkeeping – there are a lot of receipts to handle, especially when starting. Insurances, web servers, car insurance, etc.
  • Working from home – it works fairly well for me. I’ve come up with a scheme to keep myself motivated and actually working. However, a simple business lunch now takes three hours instead of one.
  • Money takes time – I’ve been given offers, signing deals, working more than ever, and my next pay check is still not due until mid January. Worth thinking about.
  • Time is not money – at least not yet. By being self employed I’m so much more flexible so that I get more quality time with my family, while making the money that I need (and some extra, but I guess that is for future expenses).

So, one month done, many more to come. This far, I’m looking forward to work every day.

>FSCONS 2009

>So, it is kind of stupid to write about these things afterwards, but the time before a conference is always filled with preparations and far too much time spent in OO.o Impress.

The last Saturday I attended FSCONS’09. This turned out to be another great event (I’ve been there two years now). I met lots of interesting people and got faces to a couple of names who’s blogs I’ve been following for a while now.
My plan for this year was to do two workshops – one on Qt for Embedded Linux (which I try to focus on), and one on the Qt SDK, trying to get people started. Both these sessions turned into something else – probably due to the unclearness of what a workshop is intended to be.
The Embedding Qt workshop (slides) had a great turn-up. The idea was to go through the configuration process of Qt/X11, Qt/embedded targetted at QVFb and then have a look at the configuration and deployment of Qt for an actual embedded target. Given a 90 minutes slot, I knew that compilation time was going to be an issue. When it turned out that only one attendee wanted to give it a try, this session turned into an ordinary talk (the one brave guy gave up after the Qt/X11 build – thank you still!). However, the talk was great, lots of interesting questions and great feedback. I really enjoyed the interaction with the audience and at the end Knut Yrvin (an actual norwegian troll) showed up, adding even more facts to the discussion.
The Qt SDK workshop (too few slides to share) also had a great turn-up. My plan was to get people to install the SDK and then show them the basics. I think that something like 5-10 people actually ran the installer, so that was a great success. The demo, however, could have needed some more planning from my side. I showed signals/slots, some widgets and the concept of layouts. For that, I used 40 minutes of my 30 minutes slot, so there where loads of unaswered questions at the end (thanks for everybody coming up to me afterwards having a chat).
To summarize – my aim with workshops did not really work in this setting, however, the quality of the audience and the resulting discussions turned this into a great event for me. I hope that you liked it as well!

>Warning – broken links ahead

>So, the day finally came when I switched from a fairly broken and badly styled MediaWiki-based web page to a WordPress-based one instead. This not only means better management abilites, a working search engine, a proper editor, etc. It also means that links are broken. I don’t write are likely to be – there are broken links out there as I have not migrated all contents. If you run into one – feel free to tell me and I’ll try to sort it out.

The result from this move will hopefully be a more professional presence on the web for my part. Unfortunately I do not have the time I want to polish the site – now I have to prepare my workshops (1, 2) for FSCONS. These events always seems to be so far away into the distant future when I sign up for them – and now it is only two weeks left…