forked from gcampax/node-gsettings
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
62 lines (46 loc) · 1.51 KB
/
Copy pathindex.js
File metadata and controls
62 lines (46 loc) · 1.51 KB
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
var gSettingsBinding = require('./build/Release/nodegsettings.node');
// Constructor
function GSettings( schemaId ) {
if ( ! schemaId.match(/^([a-zA-z0-9\-_]+\.)+[a-zA-z0-9\-_]+$/) )
throw new Error("'"+schemaId+"' is not a valid schema id!");
if ( ! gSettingsBinding.schema_exists(schemaId) )
throw new Error("Shema '"+schemaId+"' is not installed!");
this.schemaId = schemaId;
}
// Instance methods
GSettings.prototype.get = function( key ) {
if ( ! key.match(/^[a-z0-9\-]+$/) )
throw new Error("Invalid key name format '"+key+"' !");
return gSettingsBinding.get_gsetting( this.schemaId, key );
};
GSettings.prototype.set = function( key, value ) {
if ( ! key.match(/^[a-z0-9\-]+$/) )
throw new Error("Invalid key name format '"+key+"' !");
if ( typeof value === 'undefined' )
throw new Error("Value is undefined!");
gSettingsBinding.set_gsetting( this.schemaId, key, value );
};
GSettings.prototype.getAll = function() {
var keyList = this.getKeyList(),
keyCount = keyList.length,
settings = {},
value,
key;
for ( var i = 0; i < keyCount; i++ ) {
key = keyList[i];
value = this.get( key );
settings[key] = value;
}
return settings;
};
GSettings.prototype.getKeyList = function() {
return gSettingsBinding.get_gsetting_keys( this.schemaId );
};
GSettings.prototype.serialize = function() {
return JSON.stringify( this.getAll() );
};
// Class methods
GSettings.getSchemaList = function() {
throw "This method has not been implemented yet!";
};
module.exports = GSettings;