2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2009,2011 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
10 function set_branch_pref (branch, name, value) {
11 if (typeof(value) == "string") {
12 branch.setCharPref(name, value);
13 } else if (typeof(value) == "number") {
14 branch.setIntPref(name, value);
15 } else if (typeof(value) == "boolean") {
16 branch.setBoolPref(name, value);
20 function default_pref (name, value) {
21 var branch = preferences.getDefaultBranch(null);
22 set_branch_pref(branch, name, value);
25 function user_pref (name, value) {
26 var branch = preferences.getBranch(null);
27 set_branch_pref(branch, name, value);
30 function get_branch_pref (branch, name) {
31 switch (branch.getPrefType(name)) {
32 case branch.PREF_STRING:
33 return branch.getCharPref(name);
35 return branch.getIntPref(name);
36 case branch.PREF_BOOL:
37 return branch.getBoolPref(name);
43 function get_localized_pref (name) {
45 return preferences.getBranch(null).getComplexValue(name, Ci.nsIPrefLocalizedString).data;
51 function get_pref (name) {
52 var branch = preferences.getBranch(null);
53 return get_branch_pref(branch, name);
56 function get_default_pref (name) {
57 var branch = preferences.getDefaultBranch(null);
58 return get_branch_pref(branch, name);
61 function clear_pref (name) {
62 var branch = preferences.getBranch(null);
63 return branch.clearUserPref(name);
66 function clear_default_pref (name) {
67 var branch = preferences.getDefaultBranch(null);
68 return branch.deleteBranch(name);
71 function pref_has_user_value (name) {
72 var branch = preferences.getBranch(null);
73 return branch.prefHasUserValue(name);
76 function pref_has_default_value (name) {
77 var branch = preferences.getDefaultBranch(null);
78 return branch.prefHasUserValue(name);
81 function session_pref (name, value) {
85 return default_pref(name, value);
88 function watch_pref (pref, hook) {
89 /* Extract pref into branch.pref */
90 let match = pref.match(/^(.*[.])?([^.]*)$/);
93 let branch = preferences.getBranch(br).QueryInterface(Ci.nsIPrefBranch2);
95 observe: function (subject, topic, data) {
96 if (topic == "nsPref:changed" && data == key) {
101 branch.addObserver("", observer, false);