Behind the scenes with the Songbird book club
Friday, Oct 19. 2007 – Category: Songbird
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, and 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.
Leave a Reply
Recent posts
- my first fake tilt-shift
(Tuesday, Nov 18. 2008 – No Comments) - Album reviews in mashTape
(Tuesday, Nov 18. 2008 – No Comments) - whacked gets fatty
(Sunday, Nov 16. 2008 – 5 Comments) - Songbird 1.0.0rc2 on OpenSolaris
(Sunday, Nov 16. 2008 – 1 Comment)
Categories
- Cars
- ChinaBlog
- Code
- Computers
- Food
- Football
- Grommit
- Linkage
- Movies&TV
- Music
- Musings
- OpenSolaris
- OpenSource
- Outdoors
- Pets
- Photos
- Quotage
- Songbird
- Sun
- Travel
Grommit
Mozilla
OpenSolaris
Songbird
Archives
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- September 2006
- August 2006
- July 2006
- June 2006
- May 2006
- April 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- April 2005
- March 2005
- February 2005
- January 2005
- December 2004
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004
- February 2004
- January 2004
- December 2003
- November 2003
- October 2003
- September 2003
- August 2003
- July 2003
- June 2003
- May 2003
- April 2003
- March 2003
- February 2003
- January 2003
- December 2002
- November 2002
- October 2002
- September 2002
- August 2002
- July 2002
- June 2002
- May 2002
- April 2002
- March 2002
