KickTweet or Creating a KDE3 Panel Applet

I started using Twitter again last week and wanted a Linux GUI client. I looked at the standard bunch, but none of them did it for me. I wanted something small and easy. Some had system tray modes, but I decided to make my own that would reside as a panel applet.

Doing the API interaction is easy, it's just web services and I've used libcurl enough before to have that down. It's the Qt/KDE piece that I wasn't so sure about. I got started with my good friend Google, and found a few resources. If you are interested in creating a panel applet for KDE 3.5 or so, ignore the Google results they will only serve to lead you in the wrong direction!

Getting Started
I got started by firing up KDevelop and selecting "Project -> New Project" then choosing the "C++ -> KDE -> Kicker Applet" project. This will generate a nice framework for you to start developing your application on. It's just like creating any other Qt application, but in a smaller space.

There are a few small things that you won't get unless you poke around a bit. The biggest problems I had were getting the applet to expand properly and getting my input text box to accept focus. Both of these problems were solved by reading the code from "mathapplet.cpp" by Andrew Coles in the KDE source tree.

I'll start with the expanding issue. The first fix is to change the constructor to pass KPanelApplet::Stretch instead of the default KPanelApplet::Normal, as shown below.

extern "C" {
  KPanelApplet* init( QWidget *parent, const QString& configFile) {
    return new KickTweet(configFile, KPanelApplet::Stretch, KPanelApplet::About, parent, "KickTweet");

This only fixes part of the problem though. If you load it into the panel as it is now, it will keep resizing until it has pressed all the other applets aside. This is because we need to fix the default implementation of widthForHeight(int height) and heightForWidth(int width). My fix here was to just feed back a standard value regardless of the current size requests. I copied mathapplet in sending back 110 for width and 22 for height. It doesn't seem to be causing any problems yet.

The next issue is the input box focus. Again, this is taken from the mathapplet code and it is a simple if non-obvious fix. Just add watchForFocus(tweetText); to your constructor, where tweetText is your QLineEdit or derived. This is of course only relevant if you are using a text entry widget.

You can test your applet the easy way or the hard way. I tried it the hard way for quite a while, then when I got fed up I found the easy way.

the hard way is to do "make install" then add the applet to your panel. You will not notice changes if you do this version, because even if you add and remove the applet from the panel, it is not unload from memory. To get it unloaded you must restart the panel, easily done with a call to "dcop kicker default restart" This is slow an unwieldy however, and I recommend you only use it for testing the actual integration into the panel.

The easier way to test your applet is to still do "make install" but then to run your associated desktop file with appletproxy, like so "appletproxy /opt/kde3/share/apps/kicker/applets/kicktweet.desktop". This lets you do quick and easy debugging and will send your cout and cerr to the terminal if you run it from one.

Creating a kicker applet is not nearly as hard as I thought it might be. After several missteps I now have "KickTweet" which readily scratches my Twitter itch.

KickTweet in action