Mozilla hacking
While learning about XPCOM, I took a deeper look at mozilla itself and
I decided to finally fix the itches I have. I use mozilla as
browser,mail reader and calendar ( when I don't use pine, konqueror
and korganizer ). On top of my list of things I don't like is the weird
"mork" database used to store the addressbook. I wouldn't mind it if it
would allow export to vcard/ics - which can be read and is used as
primary file format by all other addressbook applications. So I'm
trying to write a small extension to export the ab, and maybe
synchronize it with other apps ( Multisync does a great job already for
evolution, zaurus, ce, and many other apps ).
I think I found the magic incantation to get the addressbook, in the
mess of badly documented objects and components:
const abURI = "moz-abmdbdirectory://abook.mab";
var rdf=Components.classes["@mozilla.org/rdf/rdf-service;1"].getService(Components.interfaces.nsIRDFService);
<> var directory = rdf.GetResource(abURI).QueryInterface(Components.interfaces.nsIAbDirectory);
var childE=directory.childCards;
try {
childE.first();
var card;
while( 1 ) {
card=childE.currentItem().QueryInterface( Components.interfaces.nsIAbCard );
processCard( card );
childE.next();
}
} catch( ex ) {
// nothing - it's how enumerations end... Weird xpcom/js - isDone is also throwing exception.
}
>
The enumeration is very weird - at least for a java programmer not
used with flow-control-by-exceptions.
Few other things I discovered:
- Ignore the books/tutorial and anything that talks about how to
use DTD for internationalization and all the super-complex layouts.
- Hacking mozilla extensions can be actually fun and easy if you
find the simple way to do it, just like in java ( and just like in
java, a lot of mozilla developers love unnecessary complexity )
- All interesting things happen in the chrome directory, after you
register your stuff in the installed-chrome.txt- the scripts won't be
executed otherwise.
- You do need contents.rdf ( their manifest ), the contents
directory, a xul and a js. So far this is the minimum - pretty
reasonable.
- XPI ( installer ) is indeed very easy. Uninstalling is a
different story.
Posted by costin at April 02, 2004 09:11 AM