Phillip Pearson - web + electronics notes

tech notes and web hackery from a new zealander who was vaguely useful on the web back in 2002 (see: python community server, the blogging ecosystem, the new zealand coffee review, the internet topic exchange).


Hacking Pidgin to only flash the tray icon when your nick is mentioned in a chat

Pidgin is awesome - it's a cross-platform IM client (I'm running it on Windows) for pretty much every IM network except Skype. One thing I've wanted to change for a while is the 'blink window on received message' function; many of my coworkers are using Adium or iChat or some other OS X app that only tries to grab your attention if (a) you receive a personal IM, or (b) your username is mentioned in a chat.

Here are some notes about the process, to refresh my memory if I come back to this in a few months' time, or maybe to help others get into the Pidgin code, if anyone is working in a similar area...

It's surprisingly easy (for a project with so many dependencies) to get up and running with a build environment on Windows. Once you've got Cygwin installed, there's a script that will fetch all the build deps and the latest source for you, then you're ready to go with make -f Makefile.mingw install.

There are two hooks that result in the window being flashed; the prefs (see prefs.xml in your .purple directory) are called /pidgin/win32/blink_im (which, if set, blinks the window when you get a private message) and /plugins/gtk/purplerc/win32/winprefs/chat_blink (which, if set, blinks the window when you get a message in a chat). Not sure why one is a main Pidgin setting and one is inside the gtk plugin, but there you go.

The Tools | Preferences | Conversations | Flash window when IMs are received option is set in pidgin/gtkprefs.c.

The Tools | Plugins | Windows Pidgin Options | Flash window when chat messages are received option is set in pidgin/plugins/win32/winprefs/winprefs.c. I wonder if this could be moved into the Conversations config pane?

Another interesting option is Tools | Preferences | Sounds | Someone says your username in chat (set in finch/gntsound.c and pidgin/gtksound.c), which plays a sound when someone says your name. I normally work with sounds turned off, though.

Here's my patch to add an option to the Windows plugin to flash the window when your username is mentioned. I also get it to flash the window if someone says phil, myelin or pearsonp; you'll probably want to remove that bit from the patch.

diff -r pidgin-2.4.2/pidgin/plugins/win32/winprefs/winprefs.c ../pidgin-2.4.2/pidgin/plugins/win32/winprefs/winprefs.c
> static const char *PREF_CHAT_BLINK_NAME = "/plugins/gtk/win32/winprefs/chat_blink_name";
< if(purple_prefs_get_bool(PREF_CHAT_BLINK))
> if(purple_prefs_get_bool(PREF_CHAT_BLINK_NAME)) {
> PurpleConvChat *chat = purple_conversation_get_chat_data(conv);
> purple_debug_info("winprefs", "Received a message from %s (I am %s, nick %s): %s\n", who, account->username, chat->nick, *message);
> if((account->username != NULL && purple_utf8_has_word(*message, account->username))
> || (chat != NULL && chat->nick != NULL && purple_utf8_has_word(*message, chat->nick))
> || purple_utf8_has_word(*message, "phil")
> || purple_utf8_has_word(*message, "myelin")
> || purple_utf8_has_word(*message, "pearsonp")) {
> purple_debug_info("winprefs", "Chat message contains a string we're looking for: blinking window.\n");
> winpidgin_conv_blink(conv, flags);
> }
> } else if(purple_prefs_get_bool(PREF_CHAT_BLINK))
> pidgin_prefs_checkbox(_("_Flash window when your username is mentioned in a chat message"),

... more like this: []