Debian: prepare debian/changelog for uploading a new snapshot
[conkeror.git] / modules / pref.js
blob61815d59220dd89b07c6cd7164eb95c5cc0b24dd
1 /**
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
7 * COPYING file.
8 **/
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);
34 case branch.PREF_INT:
35 return branch.getIntPref(name);
36 case branch.PREF_BOOL:
37 return branch.getBoolPref(name);
38 default:
39 return null;
43 function get_localized_pref (name) {
44 try {
45 return preferences.getBranch(null).getComplexValue(name, Ci.nsIPrefLocalizedString).data;
46 } catch (e) {
47 return null;
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) {
82 try {
83 clear_pref (name);
84 } catch (e) {}
85 return default_pref(name, value);
88 function watch_pref (pref, hook) {
89 /* Extract pref into branch.pref */
90 let match = pref.match(/^(.*[.])?([^.]*)$/);
91 let br = match[1];
92 let key = match[2];
93 let branch = preferences.getBranch(br).QueryInterface(Ci.nsIPrefBranch2);
94 let observer = {
95 observe: function (subject, topic, data) {
96 if (topic == "nsPref:changed" && data == key) {
97 hook();
101 branch.addObserver("", observer, false);
104 provide("pref");