Tag: KickTweet

SVN to Twitter

September 19, 2008 » Geek

I’ve been really getting into developing my KickTweet project and set up a Twitter account for it at http://twitter.com/KickTweet. I wanted to feed in my subversion commits so I did some searching.

What I found was twitvn a monstrous (50-ish ‘real lines) Python script that sends commits to Twitter. I find that ridiculous. So here is my version, it drops right into the post-commit script and could be reduced to 2-3 active lines.

#!/bin/bash
REPOS="$1"
REV="$2"

TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)"
curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml

Note that the use of the ‘${TWEET:0:139}’ is a definite bashism, and not portable.

Update (2008-09-22)
Little tidbit to add into the script right before the curl call. If you want ellipses on commit messages over 140 characters, use this version.

#!/bin/bash
REPOS="$1"
REV="$2"

TWEET="SVN Log (r$REV): $(svnlook log $REPOS -r $REV)"

if [ "${#TWEET}" -gt 140 ]; then
  TWEET="${TWEET:0:137}..."
fi

curl -u KickTweet:mySecretPassword -d status="${TWEET:0:139}" http://twitter.com/statuses/update.xml

KickTweet or Creating a KDE3 Panel Applet

September 18, 2008 » Geek

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.

Caveats
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) {
    KGlobal::locale()->insertCatalogue("KickTweet");
    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.

Testing
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.

Conclusion
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