Friday, October 17, 2008

Ubiquity in Thunderbird 0.1 is UP!

Note: 0.1 is the release version only for my zenit wiki page. It is not the official release number.

If you don’t want to read my blog post just go here for the 0.1 release:

http://zenit.senecac.on.ca/wiki/index.php/Make_Ubiquity_Work_In_Thunderbird

Alright, where to begin talking about this goliath. Well, when I first decided to take this thing on, I knew it would be big. I knew there would be tons of code. I knew there would be TONS of things I didn’t understand. What I didn’t expect was such a vast difference between Firefox and Thunderbird.

Simple things like opening a URL completely broke in Thunderbird. Ubiquity runs using an annotation service, sadly that doesn’t exist in Thunderbird. What are you to do when half the code you’re working with is exploding on you? Well, everyone in our group did the most logical thing to start off with. If something is breaking, just comment it out!

Setting up the error console to spit out javascript errors was a process we first learned when we all started on this project. I managed to get the majority of errors to stop popping up, but I still had a few that just wouldn’t go away. A lot of stuff about “services” not wanting to work and certain blocks containing no data (being NULL) simply wouldn’t go away. Thankfully, two other students (Vladamir and Justin) got a past some of the errors I was struggling with, and got Ubiquity to pop up. Hurray!

Unfortunately, when I pulled their build down the previewBlock seemed to crap out on me. Well, there went another solid week of fighting with the code to get preview commands to work properly. I finally got that up and running but it wasn’t doing entirely everything I wanted it to do. For example, the map display from the map command wouldn’t even show up. I got a nice little preview block with text stating what the command did, but no map window.

Well, a few days of asking questions and looking for direction, Vladamir sent his latest build up to the repository. The map window was popping up, but it wasn’t displaying properly. Oh well, I figured I’ll just leave that for later and get commands that need access to new windows creating windows properly first. By this time we had a page to file tickets strictly for Ubiquity Thunderbird. http://labs.toolness.com/trac/ticket/326 I’m considering completing that as part of my 0.2. We’ll see if anyone else claims it by the time I get around to it.

Figuring out how to get windows to pop up in Thunderbird was fairly easy. I spent about an hour playing around with a few functions in the Ubiquity source to see if I could do anything with them. At this point in time, for some strange reason... don’t ask me why, I was thinking that Utils was coming from either Firefox or Thunderbird. I think around this point, I managed to confuse myself (which happens often). There was just so much source to keep track of, I simply made a mistake assuming this wasn’t a built in Ubiquity command. So I ran around throughout the entire source code finding every Utils.openURLInBrowser that I could and replacing it with my 1 liner that popped up the appropriate page the command was trying to generate.

No problems! Command windows were firing up here and there, and I was happy. I figured I did a good job, and I’d just have to start editing some external commands to get them to pop up windows as well. However, instead of going off on that route (thank god I didn’t) I decided to tackle the newly popping up windows and figure out what wasn’t working, and why. Well, I managed to figure out that even though windows were popping up, they still needed Firefox to function properly (which really is a no brainer considering the second I clicked on a tab that needed Firefox it would explode and throw an exception). Almost every tab within the command window requires you to link it to a browser in order for it to work properly. Even then, commands that executed local URLs still exploded, but remote URLs worked fine. Normally I would think it would be the other way around.

Around this time I came to the conclusion that there needed to be some way to tell if Ubiquity was running under Firefox or Ubiquity. I mean, if we’re going to completely alter Ubiquity code to run under Thunderbird, it would suck if someone has to rewrite an entire function just to get it running under Firefox or vice versa. Having one command pop up a window in Firefox but not Thunderbird would be kind of silly. I mentioned this to jono and told him about the whole issue having to replace every Utils command so that a Thunderbird window would load instead of exceptions being thrown. Jono said to me, “Why don’t you just edit Utils and put your code in there?” Well this is one of those... “...” moments. You kind sit there going “I can do that?” First thing I naturally do is ask where I can find Utils, but before anyone can answer, I see a little file called Utils.js. “Nevermind”, I say.

Ok so Utils is a Ubiquity command. Great... thank god I didn’t go altering external commands to get their windows to pop up. That would have been a massive waste of time. So I look at Utils.openUrlinBrowser, comment out EVERYTHING, and put my line of code in to pop up a window. I remove every line that I had replaced Utils.openUrlinBrowser with and put Utils.openUrlinBrowser back in. Ok well... now I have ONE line of code that pops up windows for Thunderbird commands. Great... fantastic... I wasted so much time going through the source finding every command I could and “fixing” it so that a window pops up. I could have just done it here. This is just one of those moments where I feel like a supreme idiot. Not just any kind of supreme idiot mind you... the kind that you’d lock away in a crazy house and your cell mate would say, “Man you’re dumb.” Oh well, I’m over it already.

Despite being able to plop a window pop up command in one spot and have it work for all existing code, chances are we’d still need to know what environment Ubiquity is running over. It’s great that I commented out all that code to get Thunderbird windows to pop up when a command needs one, but if it’s commented out and it’s in Firefox... well... it won’t work. Well it seems that jono felt the same way, and this was created http://labs.toolness.com/trac/ticket/353. Hey, there’s something else for me to do!

Over all I feel the entire experience was worthwhile. Working on this project was completely different than any school assignment I’ve ever done. Usually with those, you’re on your own. If you can’t get something to work, you struggle with it until someone from class or your professor has time to sit down with you and help. Exchanging code through IRC, pastebin, and the repository is a breeze, and there’s no plagiarism to boot. Throughout the entire process, I’ve felt like a child that’s first learning to walk. Or rather... a child that grew up a little bit but didn’t pay attention to anything anyone said. Totally should have paid more attention to Javascript when we were learning it. Relearning it was definitely a pain.

Of course, things breaking without knowing why was pretty frustrating. However, I find that a good, healthy nerd rage usually relieves all stress and makes me ready to go at it once again. Nerd raging usually consists of saying, “Screw it!”, getting up, watching some TV and eating some food.

Oh on another note, I spent a lot of time trying to make a XPI file out of this Ubiquity build (about a days worth of time) only to have it keep crapping out on me. Well, it appears that I needed to use python to create the XPI build, and couldn’t do it manually. Should have asked about why my XPI was failing earlier.

Stupid things I did while working on this project:

- Installed the wrong version of Thunderbird on my XP machine. I installed the right version on my Vista box! That gave me errors for a long time.
- COMPLETELY wasted the repository. I was using an editor that used Windows end lines. If you want to merge with Linux end lines you need to use a text editor that will use Linux end lines in files. I’ve been using EditPad Lite. Just a couple of clicks and you can start using Linux end lines. On that note, doing a hg merge, seeing a ton of errors, going “Meh whatever” and doing a hg push isn’t exactly the brightest thing to do. It trashes the entire repository.
- Didn’t ask enough questions. I thought I was being a pain and asked a lot of questions, but at this point I think I actually didn’t ask enough questions. If I had asked more questions, chances are I would have found out about Utils much sooner and wouldn’t have wasted a day trying to make a XPI file from my current Ubiquity build.

Sunday, October 12, 2008

OSD600 Week 6 Lab

Alright, I've finally gotten around to doing the OSD600 lab for this week. My patch can be found here...

https://landfill.bugzilla.org/bugzilla-3.0-branch/show_bug.cgi?id=6838

Code changes are as follows:

if (inString.FindChar('.', pos) != kNotFound
&& inString.CharAt(0) != '.'
&& inString.CharAt(inString.Length() - 1) != '.'
&& inString.Find("..", 0) == kNotFound)
{
aOutString.AssignLiteral("mailto:");
aOutString += aInString;
}

I left in the check for a "." after the @ symbol. I then check to see if there's no "." after the @. Don't really want someone typing in a@.com. Then I check to see if there's a "." at the end of the string. Finally, a check is made to see if there's any duplicate "."'s side by side. For example: "a@a..b".

If all of those things check out then it's a mailing address.

The hint given for this lab made everything easy. I just opened the CPP file listed, and looked for mailto:. Once I found it, I just made the changes that I thought were appropriate, rebuilt, and tested it.

Filing a bugzilla bug was pretty straight forward and easy as well.

Thursday, October 9, 2008

Ubiquity command-editor pops up!

Just got the Ubiquity command-editor function to pop up. Whether or not any of the functions inside of the command editor work is another issue. I'm probably going to have to write an extra function for Ubiquity that determines whether or not it is being run under Firefox or Thunderbird, that way it can determine what functions to call depending on the program its running under.

Either that or there will have to be a stand alone Ubiquity extension. I'm not sure what route everyone wants to go, but I'm not opposed to spending my time trying to get one extension to work in both Firefox and Thunderbird. I'm not sure if something like this is entirely possible, and could be way off base... but this is probably the direction I'm going to try to go unless I'm told it's not a good idea.

Wednesday, October 8, 2008

Need Testers!

In light of my Ubiquity extension not wanting to pop up in TB for jono I've decided I need some testers. If you want to test my Ubiquity extension, hit me up in the #seneca channel on irc.mozilla.org and I'll send you my latest build.

If you're a Seneca student, I'll add you as a contributor to the projects page!

Happy Birthday!

Alright lots of stuff to talk about.

Thanks to the efforts of Vladamir and Justin, Ubiquity is now popping up in Thunderbird. I've been poking around in the Ubiquity source getting a few things to work here and there, and removing errors from the error console. So far so good, cleaned up a few things (I think).

Now I've moved on to getting command previews to properly show up in the Ubiquity console. Attempting to debug my code, I've added a series of dumps to the console that just refuse to show up. I've added in the appropriate dump.enable property in TB so that's not an issue. It's almost like none of the functions are being called to pop up the preview window. Either that or my dump just isn't working at all (which would be strange because it's working else where).

If it is a case of certain functions being called, I'm sure I'm going to have tons of fun getting event handlers to work. My original plan for my project's 0.1 release was to get a few commands to work in TB. I'm starting to realize that getting remote commands to work might be a stretch, and I'm considering dumbing down my 0.1 to simply getting the preview window to operate properly. Currently the Annotation Service that Ubiquity uses to get commands to operate in Firefox isn't available in TB. Writing a "fake" annotation service to work around this problem is going to be hard and take lots of time. In fact, I suspect that it's out of my personal scope, but that still remains to be seen.

Oh yeah, as far as getting TB to pop up Ubiquity is concerned. When I sent my rebuilt extension to jono, it decided it didn't want to work. Instead TB feels like saying that jQuery is undefined. Well, that's wonderful. You'd think that considering today is my birthday, things would go smoothly. Oh well, spending my time on this was exactly how I pictured spending my bday anyways. Happy bday Scott! ;)

Wednesday, October 1, 2008

World's Worst Programmer

Yep, that's me. You'd think that after spending an entire day going through Ubiquity's source code, that I'd at least be able to do something with it. Curse you Thunderbird!

So I managed to figure out where the function is that initiates Ubiquity when the user presses the appropriate key binding. I've also managed to figure out how commands are called upon, where they're stored, and how they're written. On top of all of this I've even managed to figure out where the key binding to pop up the Ubiquity window is located. So what's the problem then?

I CAN'T GET IT TO DO ANYTHING! From what I've seen, Ubiquity activates by listening for an incoming key binding. If it receives the correct key binding (which is defaulted to CTRL+Space) it will pop up. Ok so I tried porting it over to Thunderbird and using the key binding to pop up the window. Well... I guess Thunderbird is already making use of the CTRL+Space key binding. It's a binding in Thunderbird that allows you to select and unselect a highlighted e-mail.

Ok so NO PROBLEM! I think to myself. Naturally, if I can't get it to pop up using that key binding, I suppose I'll just change the binding. So I find one that I like that isn't currently being used by Thunderbird. No dice. Still doesn't want to pop up. At this point I'm kind of thinking that there's more to it than simply having the Javascript create the Ubiquity window after hitting the binding. Incase you're wondering, I did change the appropriate layout files in the manifest files, so that's not the problem (at least I don't think so).

So, there is the possibility that the event handler listening for the key binding isn't even operating. Alright, I'll just add a function to Ubiquity that immediately pops up the window when a menu item is clicked, and I'll add that menu item under the Thunderbird Tools tab. I've done it with several test extensions I've written so far. Shouldn't be too hard to add this menu item for Ubiquity. I know where the function is that pops up the window, so I create my own function that calls upon that function in Ubiquity's browser.js file. To add the Tool bar menu item, I just copy my code from my good old "Hello World!" extension and change the appropriate fields and point it to the Ubiquity function that I wrote. Thunderbird spits out an error on my menuitem id=. Nice, it doesn't do that for my crappy little extension. Guess I'm probably missing something. I double checked the code and there's no difference in the characters declaring the variable name at all.

It's just one of these times where I feel like a cave man that's come across a car. It looks nice and shiney, and I know it probably does something cool. I just don't know what it does, how it does it, or where to begin finding out. What I'm trying to do with Ubiquity right now is like a cave man trying to use the car's exhaust as a club. Unfortunately, I don't even know how to detach the exhaust pipe. I know that the club isn't the real purpose of the car, but if I have something nice and shiney infront of me, I might as well make use of it somehow. Who knows, I might even learn how to use a wheel next if I can get this exhaust club thing going.

Despite figuring out how everything begins between Ubiquity and Firefox, I'm still the worst programmer ever. Not that I honestly thought I'd even make it as far as I did doing what I was doing. However, one thing's for sure, I probably should have listened more closely when we were learning Javascript rather than dozing off. Javascript... pfft... who will EVER need that? Oh wait...