-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathprefs.js
65 lines (53 loc) · 2.01 KB
/
prefs.js
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
const Lang = imports.lang;
const Gtk = imports.gi.Gtk;
const Gio = imports.gi.Gio;
const Self = imports.misc.extensionUtils.getCurrentExtension();
const Utils = Self.imports.utils;
let settings;
function init() {
settings = Utils.getSettings();
}
function buildPrefsWidget() {
const main = Gtk.Builder.new_from_file(Self.dir.get_path() + '/preferences/extension.xml');
const widget = main.get_object('prefs_widget');
const versionLabel = main.get_object('version_info');
versionLabel.set_text('[Wallpaper Changer v' + Self.metadata.version + ']');
const providerList = main.get_object('field_provider');
for (let provider in Utils.getProviders()) {
providerList.append(provider, provider);
}
settings.bind('minutes', main.get_object('field_minutes'), 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('hours', main.get_object('field_hours'), 'value', Gio.SettingsBindFlags.DEFAULT);
settings.bind('provider', main.get_object('field_provider'), 'active-id', Gio.SettingsBindFlags.DEFAULT);
settings.bind('debug', main.get_object('field_debug'), 'active', Gio.SettingsBindFlags.DEFAULT);
if (providerList.get_active() === -1) {
providerList.set_active(0);
}
_updateProviderTab(main, true)();
settings.connect('changed::provider', Lang.bind(this, _updateProviderTab(main)));
widget.show_all();
return widget;
}
function _updateProviderTab(main, dry) {
return function () {
const providerPlace = main.get_object('provider_prefs');
const providerPrefs = Utils.getProvider(settings.get_string('provider')).getPreferences().get_object('prefs_page');
providerPlace.forall(function (child) {
providerPlace.remove(child);
child.destroy();
});
if (providerPrefs) {
const children = [];
providerPrefs.forall(function (child) {
providerPrefs.remove(child);
children.unshift(child);
});
children.forEach(function (child) {
providerPlace.add(child);
});
if (!dry) {
providerPlace.show_all();
}
}
}
}