Pidgin and Webkit Message Views

(This is a report for Summer of Code 2009, and is intentionally very technical. Regular readers are requested to not harass me over my recent geeky posts.)

First a screenshot of a theme I liked (Ravenant), and a theme that works decently:

Screenshot-first

(I’m not going to fool you, and I know many themes don’t work entirely well. And I’ll conveniently blame that on Webkit, and I’ll bring up the rendering issues in a moment.)

Repository and Directories

In my midterm report I mentioned that I was using Git for version control. Soon after, I moved to monotone. I’ve been pushing my changes to the same Git repository for backup, but under a different branch name. So if you want to check out my code for testing, here’s what you do:


$ git clone git://github.com/tdrhq/pidgin-clone.git
$ cd pidgin-clone
$ git checkout -b webkit remotes/origin/im.pidgin.soc.2009.webkitmessageview

[EDIT: I changed the last checkout command to use remotes/origin/im…]

If anybody wishes to pull from my Monotone repository, we could arrange for that.

Since the midterm, I also added support for multiple message styles. Each of the styles go into a directory under ~/.purple/styles/. So e.g., you might have a directory called ~/.purple/styles/Ravenant.AdiumStyles/Content if you have installed the Ravenant style.

You’ll also want to enable the Adium IMs plugin for message styles to work. (Otherwise you’ll still be using WebKit, but without themes.)

What works and doesn’t work

I promise I’m not going to suddenly decide to code while writing this report, so hence and therefore, even if some of the Todo’s that I mention below seem obvious to fix, I will not fix them until this report is done. :-)

There are very few visible changes since the midterm: You can switch between Message Styles now, and I removed support for on-the-fly changing variants. Any changes to the style or options will take effect only in new conversations.

Internally, I’ve changed many things since the midterm. E.g.,

  • I use signals instead of UiOps, which is more cleaner, but has its drawbacks. (The current signals that gtkconv emit don’t give the alias and timestamp for the message. Not hard to change the signal itself, but still…).
  • I’ve been more careful about waiting for the Webkit document to load completely before appending messages (otherwise the JavaScript fails silently.).
  • Since more than one Message style may be loaded at the same time I had to do some refactoring (this refactoring will also enable having different Styles for chats and IMs).
  • I currently parse the style’s Info.plist file completely according to [1], and use the DefaultFontFamily and DefaultFontSize. (Some of the other keys depend on changes in Webkit gtk; and I don’t know how to implement ImageMask.)
  • User’s selection of style options are saved on a per-style basis. (e.g., for each style I store the last variant the user used.)

Among things that don’t work: most noticeable are the rendering issues. In the first screenshot, you can see that the gradient isn’t smooth. This seems to be an issue with almost all themes that seem to use translucent PNGs for drawing these gradients. (For the record, I am using WebKit trunk.) Some other themes have positioning issues, but are mostly useable.

Another thing I would like to do in the future is HTML-tidy each message and strip off the <html> and <body> tags. Not a show-stopper, but it’ll be easier on Style designers to have standards compliant messages.

Here’s a screenshot of the Adium IMs plugin options:

Screenshot-options

I have never done Gtk layouting in the past, and I spent a lot of time just getting this little thing together, using a nasty GtkTable, and so despite how ugly it looks, I’m proud of it. (Sean gave me some better ideas as to how to do the layout, and I’ll be doing them soon. As I said, not while this report is in progress.)

As you can see, this does not provide the same level of customizability that the Adium’s “Messages” preference tab provides. (For those like me without access to a Mac, here’s what it looks like on Adium. Screenshot from here.)

This plugin does not implement the “Status.html” and “FileTransfer.html” parts of [1]. This should be fairly easy to implement though. Also the sections on “Image Zooming”, “JavaScript enhancements”, and “Groupchat styling” are not implemented. (Groupchat works, but in a way that is not distinguished from regular IMs.) [Oh crap, so many todos? I better get coding.]

This plugin, like Adium itself, does not support inline typing notifications. This needs changes into the style specification itself. It shouldn’t be too hard, we could allow the style to specify a JavaScript function “setTypingStatus”, that would be called every time the typing status changes. Not too hard, but I would definitely like an opinion from Adium devs on this one.

Disabling the Adium style plugin, and just using plain webkit still breaks inline typing notification. GtkIMHtml had some specific “hacks” for typing notification, which can actually be done using JavaScript with WebKit. My contention with this idea was that this adds additional complexity to GtkConv.c (which is already huge!) and this JS overlaps with the JS of implementing inline typing notifications in the Style, and if ever Pidgin chooses to use Adium styles as default, this would be wasted code.

I also haven’t done anything about gtkconv->entry, which refers to this widget:

Screenshot-entry2
so GtkConv still has a dependency on GtkIMHtml.

I haven’t worked out a solution for the Security considerations I raised in my midterm review.

Code quality

I’ll now give my opinion on the quality of code I’ve written. I’ve stuck to the usual Pidgin coding style. (Except, out of habit of coding in Liferea, I have used func<space>() at most places.)

  • gtkwebview.{c|h} is fairly well written, being almost a very simple wrapper over WebkitWebView. (It compiles with warnings about “no previous prototypes for gtk_webview_xyz”, which makes absolutely no sense to me as they are declared in gtkwebview.h. I remember reading something about a GCC bug regarding this, but I’m not sure.)
  • The changes to GtkConv.c were done in one marathon session. I can’t imagine how I had the patience to do all of those, since reviewing each of those changes is painful enough. However I think I did a “decent” job here, and might have broken a few things like drag-n-drop. Also gives a few warnings about unused symbols.
  • webkit.c, and the adium styling code was initially taken from Sean’s plugin (which btw, does a lot of the Style parsing code already!). This code has grown and is now in two files: message-style.c and webkit.c, where message-style.c handles parsing the style data. The exact nature and intent of the PidginMessageStyle struct can be a little confusing, and I need to document it correctly. I need to separate the preferences code into a third module.
  • smileyparser.{h|c} is terribly written but does its job. It is intended as a replacement for the smiley text-replacement code which is part of GtkIMHtml, and as of right now is redundant but required for conceptual clarity.

There are other less significant places cases where GtkIMHtml was replaced with WebKit. (About, User Info, Chat logs.)

There are a few printf‘s at places, and I promise to replace them with purple_debug_info.

Broken Plugins

A few plugins remain broken becase they depended on gtkconv->imhtml, which no longer exists. Few of the plugins that I have removed temporarily from pidgin/plugins/Makefile.am: gestures, history, markerline, notify, timestamp, timestamp format, xmppconsole, … (I’ll get back to you on this one, I think I’ve disabled more plugins than needed.)

Links, if you reached till this point

[1] http://trac.adium.im/wiki/CreatingMessageStyles
[2] http://pidgin.im/pipermail/devel/2009-July/008542.html

Advertisements

12 Responses to Pidgin and Webkit Message Views

  1. Elliott says:

    You need to use void in prototypes that take no parameters e.g. gtk_webview_get_type and gtk_webview_new.

  2. juanfra684 says:

    Will be the plugin available for pidgin 2.6?

    • Arnie says:

      I think 2.6 is already released. There’s still a long way to go before this code becomes professional enough for Pidgin to merge it.

  3. […] ci dice infatti che ha sviluppato un plugin (un altro? Si.) per Pidgin che permetta l’utilizzo degli […]

  4. juanfra684 says:

    @Arnie: anyway thanks for your work :) . I hope that is available in 2.7 (and that the version 2.7 is available this year) :P

  5. uastasi says:

    I’ve built your branch but when I want to enable the plugin the box remains unchecked.
    Launching pidgin -d from shell I get this messages:

    16:18:05) prefs: purple_prefs_get_string: Unknown pref /plugins/gtk/adiumthemes/stylepath
    (16:18:05) prefs: /pidgin/plugins/loaded changed, scheduling save.

    • Arnie says:

      I’m suspecting that you installed a legacy theme (version < 3 in Info.plist, see my reply to IceWil), or a theme which had AllowTextColors set in Info.plist (that was broken in the Git version, I'll be committing in a version into Monotone with this fixed.) Try installing Ravenant, and see if that works.

  6. Edder Rojas says:

    I been using pidgin-webkit plugin https://launchpad.net/pidgin-webkit which is fair good so you can use it to improve yours, but is abandoned so I was thinking to learn C and improve the code, If you need me as developer we can talk about that :)

  7. IceWil says:

    Doesn’t work with Renkoo :(

    • Arnie says:

      Sigh, Renkoo has MessageViewVersion 2, which is supported by Adium but is considered “legacy”. Unfortunately the legacy version isn’t documented enough, so I don’t want to hack my way through. Renkoo does work if you change the version in Contents/Info.plist to 3. Most other legacy styles should work with this change, and by removing Contents/Resources/Template.html if it exists.

  8. Sudipto says:

    Hi. Nice how to there regarding pidgin.
    Here’s my post regarding the off the record plugin for pidgin, which encrypts messages and makes the conversation absolutely private:
    http://opensourcethefuture.blog.co.in/2009/08/28/private-encrypted-instant-messaging-in-pidgin/

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: