1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
const Lang = imports.lang;
const Values = imports.values;
function main (argv) {
}
const Values = new Lang.Class ({
Name: 'Values',
Extends: GObject.Object,
Signals: {
'change': {
param_types: [GObject.TYPE_STRING, GObject.TYPE_VARIANT]
}
},
/**
* Name to keeyp track of what object we are using.
*/
domain: "Non",
/** @structure
* Holds the holds of the tells that listners can listen to.
*/
_tellers: {},
/** @structure
* Holds a list of lintners in a multi map:
* <code>
{ "tell1": [callback0, callback1, callback2], "tell2": [callback4]}
</code>
*/
_listners: {},
/** @structure
* holds the definitions of values with their name, type, and optionally
* user defined data that may be needed when dealing with getting and
* setting of the values:
* <code>
{"value1": {type: "string", user_data: {any}},
"value2": {type: "boolean", user_data: {any}}
}
</code>
*/
_value_defs: {},
/** @structure
* Holds the data of the values in an encopsinated way, this makes it easyer
* to deal with the values.
* <code>
{"value1": data, "value2": data}
</code>
*/
_values: {},
_value_setters: {
"x.y.z": {type: "number", setter: function (value) {
this.x_y_z = value;
}},
"a.b.c": {type: "number", setter: function (value) {
this.a_b_c = value;
}}
},
_value_getters: {
"x.y.z": {type: "number", getter: function () {
return this.x_y_z;
}},
"a.b.c": {type: "number", getter: function () {
return this.x_y_z;
}}
},
/** @method
* adds a setter to a value.
*
* @param name The name of the value to add a setter to.
* @func the function that is used for setting of data.
*/
add_setter: function (name, func) {
},
_init: function (params) {
this.parent (params);
if (params != undefined) {
if (params["domain"] != undefined) {
this.domain = params["domain"];
} else {
print ("It is recomended that a Values object has a domain.");
}
if (params["tellers"] != undefined) {
this._tellers = params["tellers"]
}
}
},
/** @method
* Method to get the value stored.
*/
get_value: function (name) {
if (this._value_setters[name] == undefined) {
print ("value \"" + name + "\" does not exist in the Values object.");
return null;
}
return _value_getters[name][getter] ();
},
/** @method
* Sets a value.
*/
set_value: function (name, value) {
if (this._value_setters[name] == undefined) {
print ("value \"" + name + "\" does not exist in the Values object.");
return;
}
if (this._value_setters[name]["type"] != typeof (value)) {
print ("The value \"" + name + "\" is of the wrong type, should be a " +
"\"" + this._value_setters[name]["type"] + "\".");
return;
}
let ret_variant = null;
switch (this._value_setters[name]["type"]) {
case "number":
ret_variant = GLib.Variant.new_int32 (value);
break;
case "boolean":
ret_variant = GLib.Variant.new_boolean (value);
break;
case "string":
ret_variant = GLib.Variant.new_string (value);
default:
print ("Balls!");
return;
}
print ("Not balls!");
this.emit ("change", name, ret_variant);
}
});
main (ARGV);
|