This is just some static backup of the original site, don't expect every link to work!

source: modules/vI_identityDataExtras.js

ng_0.9 0.10.3
Last change on this file was a2e62f, checked in by rene <rene@…>, 4 years ago

chamged braille-interface to texttospeach

  • Property mode set to 100644
File size: 11.1 KB
Line 
1/* ***** BEGIN LICENSE BLOCK *****
2    This program is free software; you can redistribute it and/or modify
3    it under the terms of the GNU General Public License as published by
4    the Free Software Foundation; either version 2 of the License, or
5    (at your option) any later version.
6
7    This program is distributed in the hope that it will be useful,
8    but WITHOUT ANY WARRANTY; without even the implied warranty of
9    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10    GNU General Public License for more details.
11
12    You should have received a copy of the GNU General Public License
13    along with this program; if not, write to the Free Software
14    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
15
16    The Original Code is the Virtual Identity Extension.
17
18    The Initial Developer of the Original Code is Rene Ejury.
19    Portions created by the Initial Developer are Copyright (C) 2007
20    the Initial Developer. All Rights Reserved.
21
22    Contributor(s):
23 * ***** END LICENSE BLOCK ***** */
24
25var EXPORTED_SYMBOLS = ["identityDataExtras", "registerIdExtrasObject", "identityDataExtrasObject", "identityDataExtrasCheckboxObject"];
26
27const {
28  classes: Cc,
29  interfaces: Ci,
30  utils: Cu,
31  results: Cr
32} = Components;
33
34Cu.import("resource://v_identity/vI_log.js");
35Cu.import("resource://v_identity/vI_prefs.js");
36
37let Log = setupLogging("virtualIdentity.identityDataExtras");
38
39let stringBundle = Cc["@mozilla.org/intl/stringbundle;1"]
40  .getService(Ci.nsIStringBundleService)
41  .createBundle("chrome://v_identity/locale/vI_storageExtras.properties");
42
43let idExtrasObjects = [];
44
45function registerIdExtrasObject(h) {
46  idExtrasObjects.push(h);
47}
48
49function identityDataExtras(currentWindow, rdfDatasource, resource) {
50  this._currentWindow = currentWindow;
51  this.extras = [];
52 
53  var this_object = this;
54  idExtrasObjects.map(function(identityDataExtrasObject) {
55    try {
56      this_object.extras.push(new identityDataExtrasObject(this_object._currentWindow));
57    } catch (e) {
58      Log.error("identityDataExtras '" + identityDataExtrasObject + "' returned an error:", e)
59      dumpCallStack(e);
60    }
61  });
62  if (rdfDatasource)
63    this.loopThroughExtras(
64      function (extra) {
65        extra.value = rdfDatasource._getRDFValue(resource, extra.field);
66      });
67}
68identityDataExtras.prototype = {
69  _currentWindow: null,
70
71  loopThroughExtras: function (k, returnVal) {
72    for (var i = 0; i < this.extras.length; i++) {
73      try {
74        returnVal = k(this.extras[i], i, returnVal)
75      } catch (e) {
76        Log.error("identityDataExtras '" + this.extras[i].field + "' returned an error:", e);
77        dumpCallStack(e);
78      }
79    }
80    return returnVal;
81  },
82
83  // just give a duplicate of the current identityDataExtras, else we will work with pointers
84  getDuplicate: function () {
85    var newExtras = new identityDataExtras(this._currentWindow);
86    this.loopThroughExtras(function (extra, i) {
87      newExtras.extras[i].value = extra.value;
88    });
89    return newExtras;
90  },
91
92  // copys all values of an identity. This way we can create a new object with a different document-context
93  copy: function (extras) {
94    this.loopThroughExtras(function (extra, i) {
95      extra.value = extras.extras[i].value;
96    });
97  },
98
99  equal: function (identityDataExtras) {
100    var returnVal = true;
101    return this.loopThroughExtras(function (extra, i, returnVal) {
102      return extra.active ? (extra.equal(identityDataExtras.extras[i]) && returnVal) : returnVal;
103    }, returnVal);
104  },
105
106  getMatrix: function () {
107    var returnVal = "";
108    return this.loopThroughExtras(function (extra, i, returnVal) {
109      if (extra.active && extra.valueHtml)
110        returnVal += "<tr>" +
111        "<td class='col1 extras '>" + stringBundle.GetStringFromName("vident.identityData.extras." + extra.field) + "</td>" +
112        "<td class='col2 extras '>" + extra.valueHtml + "</td>" +
113        "</tr>"
114      return returnVal;
115    }, returnVal);
116  },
117
118  getCompareMatrix: function () {
119    var returnVal = "";
120    return this.loopThroughExtras(function (extra, i, returnVal) {
121      if (extra.active) {
122        var classEqual = (extra.lastCompareResult) ? "equal" : "unequal";
123        returnVal += "<tr>" +
124          "<td class='col1 extras " + classEqual + "'>" + stringBundle.GetStringFromName("vident.identityData.extras." + extra.field) + "</td>" +
125          "<td class='col2 extras " + classEqual + "'>" + extra.lastCompareValue + "</td>" +
126          "<td class='col3 extras " + classEqual + "'>" + extra.valueHtml + "</td>" +
127          "</tr>"
128      }
129      return returnVal
130    }, returnVal);
131  },
132
133  status: function () {
134    var returnVal = "";
135    return this.loopThroughExtras(function (extra) {
136      return returnVal += returnVal ? " " : "" + extra.status;
137    }, returnVal);
138  },
139
140  readIdentityValues: function (identity) {
141    this.loopThroughExtras(function (extra) {
142      extra.readIdentityValue(identity)
143    });
144  },
145
146  setValuesToEnvironment: function () {
147    this.loopThroughExtras(function (extra) {
148      extra.setValueToEnvironment()
149    });
150  },
151
152  getValuesFromEnvironment: function () {
153    this.loopThroughExtras(function (extra) {
154      extra.getValueFromEnvironment()
155    });
156  },
157
158  // add value's to the pref object, required for rdfDataTreeCollection
159  addPrefs: function (pref) {
160    this.loopThroughExtras(function (extra) {
161      pref[extra.field + "Col"] = extra.valueNice;
162    });
163  }
164}
165
166function identityDataExtrasObject(currentWindow) {
167  this._currentWindow = currentWindow;
168}
169identityDataExtrasObject.prototype = {
170  _currentWindow: null, // the current Window the object was created for
171
172  value: null, // will contain the current value of the object and can be accessed from outside
173  field: null, // short description of the field
174  option: null, // option from preferences, boolean
175
176  lastCompareValue: "",
177  lastCompareResult: false,
178
179  get _texttospeach() {
180    return prefroot.getCharPref("accessibility.usetexttospeech");
181  },
182
183  get valueHtml() {
184    if (!this.value)
185      return "";
186    let boolclass = ((this.value == "true") ? " checked" : "");
187    let accessclass = ((this._texttospeach == "true") ? " texttospeach" : " image");
188    let value = ((this._texttospeach == "true") ? this.valueNice : "&nbsp;");
189    return "<div class='bool" + boolclass + accessclass + "'>" +
190      "<label>" + value + "</label></div>"
191  },
192  get valueNice() {
193    if (!this.value)
194      return "";
195    return (this.value == "true") ? "yes" : "no";
196  },
197  get status() {
198    if (this.active && this.value)
199      return this.field + "='" + this.value + "'";
200    return "";
201  },
202  get active() {
203    return vIprefs.get("storage") && vIprefs.get(this.option)
204  },
205  equal: function (compareIdentityDataExtrasObject) {
206    this.lastCompareValue = compareIdentityDataExtrasObject.valueHtml;
207    this.lastCompareResult = (!this.value || !compareIdentityDataExtrasObject.value || this.value == compareIdentityDataExtrasObject.value);
208    //     if (!this.lastCompareResult) {
209    //       Log.debug("extras not equal " + this.field + " (current:'" + this.value + "' != target:'" + compareIdentityDataExtrasObject.value + "')");
210    //     }
211    return this.lastCompareResult;
212  },
213  // function to read the value from a given identity (probably not part of identity)
214  readIdentityValue: function (identity) {},
215  // function to set or read the value from/to the environment
216  setValueToEnvironment: function () {
217    let id = this._currentWindow.document.documentElement.id;
218    switch (id) {
219    case "msgcomposeWindow":
220      this.setValueToEnvironment_msgCompose();
221      break;
222    case "messengerWindow":
223      this.setValueToEnvironment_messenger();
224      break;
225    case "vI_rdfDataTreeWindow":
226    case "vI_rdfDataEditor":
227      this.setValueToEnvironment_dataEditor();
228      break;
229    default:
230      Log.error("getValueFromEnvironment unknown window: " + id)
231    }
232  },
233  getValueFromEnvironment: function () {
234    let id = this._currentWindow.document.documentElement.id;
235    switch (id) {
236    case "msgcomposeWindow":
237      this.getValueFromEnvironment_msgCompose();
238      break;
239    case "messengerWindow":
240      this.getValueFromEnvironment_messenger();
241      break;
242    case "vI_rdfDataTreeWindow":
243    case "vI_rdfDataEditor":
244      this.getValueFromEnvironment_dataEditor();
245      break;
246    default:
247      Log.error("getValueFromEnvironment unknown window: " + id)
248    }
249  },
250  setValueToEnvironment_msgCompose: function () {
251    Log.error("setValueToEnvironment not implemented for msgCompose and " + this.field)
252  },
253  setValueToEnvironment_messenger: function () {
254    Log.error("setValueToEnvironment not implemented for Messenger and " + this.field)
255  },
256  setValueToEnvironment_dataEditor: function () {
257    Log.error("setValueToEnvironment not implemented for dataEditor and " + this.field)
258  },
259  getValueFromEnvironment_msgCompose: function () {
260    Log.error("setValueToEnvironment not implemented for msgCompose and " + this.field)
261  },
262  getValueFromEnvironment_messenger: function () {
263    Log.error("setValueToEnvironment not implemented for Messenger and " + this.field)
264  },
265  getValueFromEnvironment_dataEditor: function () {
266    Log.error("setValueToEnvironment not implemented for dataEditor and " + this.field)
267  }
268}
269
270
271function identityDataExtrasCheckboxObject(currentWindow) {
272  this._currentWindow = currentWindow;
273}
274identityDataExtrasCheckboxObject.prototype = {
275  _currentWindow: null, // the current Window the object was created for
276
277  __proto__: identityDataExtrasObject.prototype,
278
279  updateFunction_msgCompose: function () {},
280  elementID_msgCompose: null,
281
282  readIdentityValue: function (identity) {
283    if (this.active)
284      this.value = (this.func_valueFromIdentity(identity)) ? "true" : "false";
285  },
286
287  setValueToEnvironment_msgCompose: function () {
288    var element = this._currentWindow.document.getElementById(this.elementID_msgCompose);
289    if (!this.active || (this.value == null) || !element)
290      return;
291
292    this.updateFunction_msgCompose();
293    if ((element.getAttribute("checked") == "true") != (this.value == "true")) {
294      Log.debug("change " + this.field + " to " + this.value + " with doCommand");
295      element.doCommand();
296    }
297  },
298
299  setValueToEnvironment_dataEditor: function () {
300    if (this.value != null) {
301      this._currentWindow.document.getElementById("vI_" + this.option).setAttribute("checked", this.value);
302      this._currentWindow.document.getElementById("vI_" + this.option + "_store").setAttribute("checked", "true");
303    }
304    this._currentWindow.document.getElementById("vI_" + this.option + "_store").doCommand();
305  },
306
307  getValueFromEnvironment_msgCompose: function () {
308    var element = this._currentWindow.document.getElementById(this.elementID_msgCompose)
309    if (this.active && element) {
310      this.updateFunction_msgCompose();
311      this.value = ((element.getAttribute("checked") == "true") ? "true" : "false");
312    }
313  },
314
315  getValueFromEnvironment_dataEditor: function () {
316    if (this._currentWindow.document.getElementById("vI_" + this.option + "_store").getAttribute("checked") == "true") {
317      var elementValue = this._currentWindow.document.getElementById("vI_" + this.option).getAttribute("checked");
318      this.value = (elementValue == "true") ? "true" : "false"
319    } else
320      this.value = null;
321  }
322}
Note: See TracBrowser for help on using the repository browser.