Friday, February 22, 2008

Creating Firefox searchplugins for any site - including Qt !

You know, Firefox and friends have a nice search system but there are so many websites that just don't have a canned search plugin you can install like the Wikipedia and Google ones. Because I use Qt and Python for most work on Neo Ports Manager I tend to RTFM a lot and one of the things I truly love about using KDE's Konqueror webbrowser is I can go to the address bar and

qt3: someclass

and it will take me there, in fact I have it setup in Flock at the moment to use qt3, qt4 e.t.c as keywords to take me to the index. The thing is, I would like to search, after all there is a bloody search bar !


I tried looking online on how to make one but didn't find any thing helpful, I think the stuff was written for Firefox 1.x so to heck with it. I opened profile and looked for where the search scripts were located. My laptop and desktop use Flock as the default web browser but the only difference this should make here is that my profile is stored in ~/.flock instead of ~/.mozila/*

The searchplugins are in your user profile, for me with flock it is:

/home/Terry/.flock/browser/t247gnll.default/searchplugin

On Windows the profile goes in your %UserProfile%\Application Data\ in a folder such as mozilla\firefox\profile-name or flock\browser\profilename depending on the browser you are using. Don't have a Mac so dunno where it goes on there but thats why there is a FAQ online ;-)


In here are several XML files,

Terry@dixie$ ls                                                            7:25
dictcc.xml         gmail.xml          qt3.xml            youtube.xml
dictionarycom.xml  photobucket.xml    weathercom.xml
Terry@dixie$                                                               7:26

Each one is a search plugin in the search bar in the top right of my browser, qt3.xml is a file of my own creation.


If you are like me, when you are surfing the fine web you occasionally look at the URL's of the web pages you visit, since I spend alot of time looking around at the Qt documentation I know that the documentation for each class is stored as ClassName.html in a specific folder on trolltechs web servers. This means if you can find out how your favorite website stores it's files you can create a search plugin for nearly any website on the world wide web !!!!


I opened the dictcc.xml file to see how it is done, so simple it is easy as pie. And unlike Operas easy way of doing it in the GUI, we can set an ICON to use in the search bar :-)

Qt class docs are in http://doc.trolltech.com/major-version.minor-version/classname.html so we want the text we type in the search bar to be replace the classname part of the URL with out search text, we do that with a little string interpolation.



        Qt Toolkit
        Qt3 - Search all classes
        UTF-8
        data:image/x-icon;base64,
iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAABtUlEQVQokY2Rv0sbYRjHv+97d1zu
8gtzwauGGmgjXU+hpaVCMlUMDnZox4IS/AvcCg4Obv4HLZk6dNLFJJ3SQoYkpSTQVUMj8Vf10KaX
O+Jd7u2QkHha0O/4PJ8Pz/PwkE8/XuB+cWwGBv6eNIAri7nuLeG4Yde/WidNGwxqXNBS0uRjod+S
QxQAGa7EXOSz7Uquw9jIJwRP5+V0JkzpoDKakM+2y7sdUSJzS4HEjAiC/Vq3tGNUCyaAxdVwH6PD
TSq5jiiRzKaSfBOIJYSwwkVjfGZT8cn0+xfzcM/2CPVvFmN4uRRQ4wIA49LNruufty7OWr25137G
UC+aHuH0lw0goYlD+qzljKncwyfC9IwI4PTA8QiDE6/Rnuq1DI5W40Lj59VevTs+xetHTmSCo5Sc
HzrZdX161gdAneI9E7SURAhKO0bkAfd2bWxlQ1neUKIxXj/ulXc7hEBLyR5h4pHwbMHftdiH9/p5
yzEu3b8Xvf72AHwBGowMyNHjXBf5j3+qBfPG46QgNdvu87Q/nQl5hH6O9u1a0frdtAGMx3ktKYei
XGnbePUuyPHkP8KdoXcj3vwDRIGtlNEJQYAAAAAASUVORK5CYII=
        


  


I saw that icons were encoded in Base64 much like with E-Mail attachments by looking at the dictcc.xml file so I wanted to include an icon for my qt3.xml search plug.


So I went to trolltechs website, downloaded their logo, opened it in kolourpaint and resize/scale'ed it down to 16x16. I then searched for a base64 encoder/decoder that could handle more then plain text, because opening an image file in a text editor to copy/paste is a pain in the neck. I consider this fair-use of the logo, if Trolltech doesn't they can write me a search plugin ^_^.

I copy and pasted the encoded form of the icon into the file as you can see above and volia we have a search plugin muhauahauha ! Then saved the file, restarted flock, wrote "QLineEdit" in the search bar without qoutes and clicked the 'Qt Toolkit' entry and flock opened a new tab with the QLineEdit class documentation for Qt3.3 ;-).


In a few minutes I will make a Qt4 one and change the ShortNames accordingly. With a little attention to detail this means a search plugin can be created by most any user for most any website. In fact with a little work I could probably set it up so I could search the [SAS] or PC-BSD forums this way, either through the search functions ability to look for topics posted or by thread #'s to go straight to a thread (which would not be fun to have to search by!).

I wonder if with a little poking around at the Open Search and XML specifications if I could have the searchTerms passed on to a perl script to do a a few tricks and pass it back in... I should look at that option some day hehe.


I love it when people make it so you can plug into an application without having to compile crap !

No comments:

Post a Comment