Sunday, March 22, 2009

Ubiquity Extension and Its Preferences

In Firefox, it provides Preferences System for extensions to store data or user preferences. To see all of the currently stored preferences in your Firefox, type 'about:config' into the location bar and press return. For example, here is a list of preferences filtered by the 'ubiquity' keyword:

When Ubiquity extension is installed, it comes with a set of default preferences which is stored in the preferences.js file under "<UB>/defaults/preferences" folder where "<UB>" is the Ubiquity installation location (for example, it's at C:\Documents and Settings\<user>\Application Data\Mozilla\Firefox\Profiles\eid50wk9.default\extensions on Window XP).

The content of preferences.js in Ubiquity 0.2pre19 looks like this :

pref("extensions.ubiquity.language", "en");
pref("extensions.ubiquity.trustedDomains",
"ubiquity.mozilla.com");
pref("extensions.ubiquity.skin", "old");
pref("extensions.ubiquity.standardFeedsUri",
"https://ubiquity.mozilla.com/standard-feeds/");
pref("extensions.ubiquity.enablePageLoadHandlers", true);
pref("extensions.ubiquity.displayAlertOnError", false);
pref("extensions.ubiquity.isResetScheduled", false);
pref("extensions.ubiquity.remoteUriTimeout", 60000);
pref("extensions.ubiquity.bugReportUri",
"https://ubiquity.mozilla.com/report-bug/new/");

Referencing from JavaScript

To reference the Preferences System from within the JavaScript code, first, you need to have a reference to XPCOM service given the ClassID of the Preference Manager service. To do that, you must add the following line of code to your file:
       var prefManager = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefBranch);

Now that you have access to the preference manager you can get and set preferences using getIntPref()/getBoolPref()/getCharPref() and setIntPref()/setBoolPref()/setCharPref(). For example, to retrieve the default setting of "extensions.ubiquity.language", you use

var lang = prefs.getCharPref("extensions.ubiquity.language");

1 comment:

Patt P. said...

I really amazed to have this wonderful post
casual meet up sex