SBDataRemoteUtils.jsm
Go to the documentation of this file.
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 :miv */
3 /*
4  *=BEGIN SONGBIRD GPL
5  *
6  * This file is part of the Songbird web player.
7  *
8  * Copyright(c) 2005-2009 POTI, Inc.
9  * http://www.songbirdnest.com
10  *
11  * This file may be licensed under the terms of of the
12  * GNU General Public License Version 2 (the ``GPL'').
13  *
14  * Software distributed under the License is distributed
15  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
16  * express or implied. See the GPL for the specific language
17  * governing rights and limitations.
18  *
19  * You should have received a copy of the GPL along with this
20  * program. If not, go to http://www.gnu.org/licenses/gpl.html
21  * or write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23  *
24  *=END SONGBIRD GPL
25  */
26 
32 //------------------------------------------------------------------------------
33 //
34 // Songbird data remote utility JSM configuration.
35 //
36 //------------------------------------------------------------------------------
37 
39 [
40  "SBNewDataRemote",
41  "SBDataGetStringValue",
42  "SBDataGetIntValue",
43  "SBDataGetBoolValue",
44  "SBDataSetStringValue",
45  "SBDataSetBoolValue",
46  "SBDataSetIntValue",
47  "SBDataIncrementValue",
48  "SBDataDecrementValue",
49  "SBDataToggleBoolValue",
50  "SBDataFireEvent",
51  "SBDataDeleteBranch"
52 ];
53 
54 
55 //------------------------------------------------------------------------------
56 //
57 // Songbird data remote utility defs.
58 //
59 //------------------------------------------------------------------------------
60 
61 // Component manager defs.
62 if (typeof(Cc) == "undefined")
63  var Cc = Components.classes;
64 if (typeof(Ci) == "undefined")
65  var Ci = Components.interfaces;
66 if (typeof(Cr) == "undefined")
67  var Cr = Components.results;
68 if (typeof(Cu) == "undefined")
69  var Cu = Components.utils;
70 
71 
72 //------------------------------------------------------------------------------
73 //
74 // sbIDataRemote wrapper
75 //
76 // This object provides the ability to set key-value pairs
77 // into a global "data store," and to have various callback
78 // effects occur when anyone changes an observed value.
79 //
80 // The callback binding can be placed on a dom element to
81 // change its properties or attributes based upon the value
82 // (either directly, or as a boolean, and/or as the result
83 // of a given evaluation expression).
84 //
85 // The mozilla preferences system is used as the underlying
86 // data storage layer to power this interface. Because the
87 // preferences are available to all open windows in xulrunner,
88 // these data remotes should function as globals across
89 // the application. This is both powerful and dangerous, and
90 // while this interface is available to all, everyone should
91 // be very careful to properly namespace their data strings.
92 //
93 // SBDataBindElementProperty Param List:
94 // key - The data ID to bind upon
95 // elem - The element ID to be bound
96 // attr - The name of the property or attribute to change
97 // bool - Optionally assign the data as BOOLEAN data (true/false props,
98 // "true"/"false" attrs)
99 // not - Optionally assign the data as a boolean NOT of the value
100 // eval - Optionally apply an eval string where `value = eval( eval_string );`
101 //XXXeps add data remote DOM utilities.
102 //
103 //------------------------------------------------------------------------------
104 
116 function SB_NewDataRemote( aKey, aRoot )
117 {
118  var dataRemote = Cc["@songbirdnest.com/Songbird/DataRemote;1"]
119  .createInstance(Ci.sbIDataRemote);
120  dataRemote.init( aKey, aRoot );
121  return dataRemote;
122 }
123 
131 function SBNewDataRemote( aKey, aRoot )
132 {
133  return SB_NewDataRemote( aKey, aRoot );
134 }
135 
144 function SBDataGetStringValue( aKey )
145 {
146  var data = SB_NewDataRemote( aKey, null );
147  return data.stringValue;
148 }
149 
159 function SBDataGetIntValue( aKey )
160 {
161  var data = SB_NewDataRemote( aKey, null );
162  return data.intValue;
163 }
164 
172 function SBDataGetBoolValue( aKey )
173 {
174  var data = SB_NewDataRemote( aKey, null );
175  return data.boolValue;
176 }
177 
188 function SBDataSetStringValue( aKey, aStringValue )
189 {
190  var data = SB_NewDataRemote( aKey, null );
191  data.stringValue = aStringValue;
192  return aStringValue;
193 }
194 
205 function SBDataSetBoolValue( aKey, aBoolValue )
206 {
207  var data = SB_NewDataRemote( aKey, null );
208  data.boolValue = aBoolValue;
209  return aBoolValue;
210 }
211 
222 function SBDataSetIntValue( aKey, aIntValue )
223 {
224  var data = SB_NewDataRemote( aKey, null );
225  data.intValue = aIntValue;
226  return aIntValue;
227 }
228 
239 function SBDataIncrementValue( aKey, aCeiling )
240 {
241  // if no ceiling is given use the *ceiling*
242  if ( aCeiling == null || isNaN(aCeiling) )
243  aCeiling = Number.MAX_VALUE;
244 
245  var data = SB_NewDataRemote( aKey, null );
246  var newVal = (data.intValue + 1); // getter call
247  if ( newVal > aCeiling )
248  newVal = aCeiling;
249  data.intValue = newVal; // setter call
250  return newVal;
251 }
252 
264 function SBDataDecrementValue( aKey, aFloor )
265 {
266  // if no floor is given, use the *floor*
267  if ( aFloor == null || isNaN(aFloor) )
268  aFloor = -Number.MAX_VALUE;
269 
270  var data = SB_NewDataRemote(aKey, null);
271  var newVal = (data.intValue - 1); // getter call
272  if ( newVal < aFloor )
273  newVal = aFloor;
274  data.intValue = newVal; // setter call
275  return newVal;
276 }
277 
286 function SBDataToggleBoolValue( aKey )
287 {
288  var data = SB_NewDataRemote(aKey, null);
289  var newVal = !data.boolValue;
290  data.boolValue = newVal;
291  return newVal;
292 }
293 
306 function SBDataFireEvent( aKey )
307 {
308  var data = SB_NewDataRemote( aKey, null );
309  return ++data.intValue;
310 }
311 
318 function SBDataDeleteBranch( aKey )
319 {
320  var data = SB_NewDataRemote( aKey, null );
321  data.deleteBranch();
322 }
323 
const Cu
const Cc
function SBDataGetIntValue(aKey)
Get the value of the data in integer format.
function SBDataGetStringValue(aKey)
Get the value of the data in string format.
function SBDataToggleBoolValue(aKey)
Change the boolean value. The true/false value of the data associated with the key will be reversed...
function SBDataDeleteBranch(aKey)
Called to remove the data remote specified by aKey and all its children.
function SBDataGetBoolValue(aKey)
Get the value of the data in boolean format.
function SBDataSetIntValue(aKey, aIntValue)
Set an integer value. Changes the value of the data remote to the integer passed in, regardless of its value before.
function SBDataSetBoolValue(aKey, aBoolValue)
Set a boolean value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
function SBNewDataRemote(aKey, aRoot)
Create a new data remote object.
function SB_NewDataRemote(aKey, aRoot)
Create a new data remote object.
function SBDataDecrementValue(aKey, aFloor)
Decrement the integer value. Decrement the integer value associated with the key passed in...
return null
Definition: FeedWriter.js:1143
const Cr
const Ci
function SBDataFireEvent(aKey)
Cause a notification to be fired. The data associated with the key will be modified so that observers...
function SBDataSetStringValue(aKey, aStringValue)
Set a string value. Changes the value of the data remote to the boolean passed in, regardless of its value before.
observe data
Definition: FeedWriter.js:1329
function dataRemote(aKey, aRoot)
function SBDataIncrementValue(aKey, aCeiling)
Increment the integer value. Increment the integer value associated with the key passed in...
EXPORTED_SYMBOLS