1
const Lang = imports.lang;
3
const Values = imports.values;
11
const Values = new Lang.Class ({
13
Extends: GObject.Object,
16
param_types: [GObject.TYPE_STRING, GObject.TYPE_VARIANT]
21
* Name to keeyp track of what object we are using.
26
* Holds the holds of the tells that listners can listen to.
31
* Holds a list of lintners in a multi map:
33
{ "tell1": [callback0, callback1, callback2], "tell2": [callback4]}
39
* holds the definitions of values with their name, type, and optionally
40
* user defined data that may be needed when dealing with getting and
41
* setting of the values:
43
{"value1": {type: "string", user_data: {any}},
44
"value2": {type: "boolean", user_data: {any}}
51
* Holds the data of the values in an encopsinated way, this makes it easyer
52
* to deal with the values.
54
{"value1": data, "value2": data}
61
"x.y.z": {type: "number", setter: function (value) {
65
"a.b.c": {type: "number", setter: function (value) {
74
"x.y.z": {type: "number", getter: function () {
78
"a.b.c": {type: "number", getter: function () {
84
* adds a setter to a value.
86
* @param name The name of the value to add a setter to.
87
* @func the function that is used for setting of data.
89
add_setter: function (name, func) {
93
_init: function (params) {
97
if (params != undefined) {
98
if (params["domain"] != undefined) {
99
this.domain = params["domain"];
101
print ("It is recomended that a Values object has a domain.");
104
if (params["tellers"] != undefined) {
105
this._tellers = params["tellers"]
111
* Method to get the value stored.
113
get_value: function (name) {
114
if (this._value_setters[name] == undefined) {
115
print ("value \"" + name + "\" does not exist in the Values object.");
119
return _value_getters[name][getter] ();
125
set_value: function (name, value) {
127
if (this._value_setters[name] == undefined) {
128
print ("value \"" + name + "\" does not exist in the Values object.");
132
if (this._value_setters[name]["type"] != typeof (value)) {
133
print ("The value \"" + name + "\" is of the wrong type, should be a " +
134
"\"" + this._value_setters[name]["type"] + "\".");
138
let ret_variant = null;
140
switch (this._value_setters[name]["type"]) {
142
ret_variant = GLib.Variant.new_int32 (value);
145
ret_variant = GLib.Variant.new_boolean (value);
148
ret_variant = GLib.Variant.new_string (value);
153
print ("Not balls!");
154
this.emit ("change", name, ret_variant);