Behind the scenes with the Songbird Book Club

By stevel stevel Permalink

As I mentioned yesterday, I built my first Songbird extension, albeit a slightly contrived and not tremendously amazing one. However, it serves as a good example for the development process I suppose. Especially because this one also involved me having to dive into the Songbird source a little bit to find the exact routines I wanted. Even more especially because I’ve had no prior experience, so this really is the complete naive and ignorant Songbird/Firefox extension developer scenario.

If you pull apart (e.g. unzip) the bookclub.xpi extension, you’ll see in the chrome.manifest I only overlay one XUL item, the menubar:

overlay chrome://songbird/content/xul/menuOverlay.xul chrome://songbird-bookclub/
content/overlayMenu.xul

If that’s not a big enough clue that this is a pretty simple extension UI wise, then I dunno what is. ;-) So let’s go take a look at chrome/content/overlayMenu.xul

You’ll see the minor UI part involves doing the <menuitem>> for seeding the music blog bookmarks. The bulk of the interesting part of this extension lies in the Javascript, so let’s go take a look at seedMusicBlogBookmarks()

So up until this point, I’d managed to completely scavenge bits from the Getting Started with Add-ons guide. Now I needed to actually do something unique and original.

Damn

So I sat back a bit and thought – okay, I need to get to the bookmarks. How do I manipulate the bookmarks? Well, the bookmarks belong to the service pane (the service pane being the left hand side panel). So, knowing the OO nature of things…. I figure I probably need to figure out how to get a service pane object and then get the bookmarks object. This is where I got stymied a bit, and decided it was as good a time as any to start looking at the source.

… so this is where I actually cheated a bit and used my own personal OpenGrok instance to browse the source. But for now, let’s take a look at the currently official Songbird source browser which is Trac based. I used my keen sense of reasoning and my logic which only fails me occasionally to dive into the components/ subdirectory.

Here I saw the servicepane subdirectory. I dropped into the src/ subdirectory and saw the source for the bookmarks service in sbBookmarksService.js

I read the source for importBookmarks() which pointed me at addBookmark() and addBookmarkAt().

Yay, there was much rejoicing.

So I did what every other lousy programmer does… go see what someone else has done and copy it. I searched the source base for “addBookmark” which pointed me over to the bookmarks unit tests in test_bookmarks.js. That conveniently told me how to get access to the bookmark service, so that’s how I got the SPS, SPS.init(), and BMS stuff setup.

From here, I needed to figure out how to add a bookmark. Fortunately, from our prior diving into the bookmarks service code, we saw addBookmark, addFolder, and addBookmarkAt. Brilliant, we’re all set! So from there it was a simple matter to make the XMLHttpRequest() to grab the Birdhouse Media Web Directory URL, and parse it to grab the MP3 blogs section, call addFolder() to create my “Music Blogs” folder, and then loop through addBookmarkAt() for each blog in the directory to add it to the folder created. That should be pretty straight-forward from the rest of the code in overlayMenu.xul.

So at that point, the extension is done. So I built it, and loaded it in only to see errors about addBookmarkAt() not being defined.

WTF?

More searching for addBookmark() & addBookmarkAt() brought me to the public interface list for the bookmarks service, where I saw only addBookmark() and addFolder() were being exported. Damn, I needed access to addBookmarkAt(). So I did the simple fix and had addBookmarkAt() expose itself publicly, and wham…. everything was working beautifully.

So there, that’s my walk through for my thought process from start to finish for making a Songbird extension create bookmarks in a folder.

Both comments and trackbacks are currently closed.

1 Comment

Subscribe
  1. Windsurfer Oct 23, 2007 5:52 pm Permalink

    Cool!
    I had no idea is was so easy. I thought it would require all this low-level mumbo-jumbo. Thank you for that enlightening journey!