File: prefs.js

package info (click to toggle)
gnome-shell-extension-bluetooth-quick-connect 16-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 172 kB
  • sloc: javascript: 502; xml: 29; makefile: 10
file content (90 lines) | stat: -rw-r--r-- 3,033 bytes parent folder | download
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
// Copyright 2018 Bartosz Jaroszewski
// SPDX-License-Identifier: GPL-2.0-or-later
// (see extension.js for details)

const Gio = imports.gi.Gio;
const Gtk = imports.gi.Gtk;

const Gettext = imports.gettext.domain('gnome-shell-extensions');
const _ = Gettext.gettext;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();
const Settings = Me.imports.settings.Settings;


class SettingsBuilder {
    constructor() {
        this._settings = new Settings().settings;
        this._builder = new Gtk.Builder();
    }

    build() {
        this._builder.add_from_file(Me.path + '/Settings.ui');
        this._settingsBox = this._builder.get_object('bluetooth_quick_connect_settings');


        this._viewport = new Gtk.Viewport();
        this._viewport.add(this._settingsBox);
        this._widget = new Gtk.ScrolledWindow();
        this._widget.add(this._viewport);


        this._builder.get_object('auto_power_off_settings_button').connect('clicked', () => {
            let dialog = new Gtk.Dialog({
                title: 'Auto power off settings',
                transient_for: this._widget.get_toplevel(),
                use_header_bar: true,
                modal: true
            });


            let box = this._builder.get_object('auto_power_off_settings');
            dialog.get_content_area().add(box);

            dialog.connect('response', (dialog) => {
                dialog.get_content_area().remove(box);
                dialog.destroy();
            });

            dialog.show_all();
        });


        this._bind();

        return this._widget;
    }

    _bind() {
        let autoPowerOnSwitch = this._builder.get_object('auto_power_on_switch');
        this._settings.bind('bluetooth-auto-power-on', autoPowerOnSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

        let autoPowerOffSwitch = this._builder.get_object('auto_power_off_switch');
        this._settings.bind('bluetooth-auto-power-off', autoPowerOffSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

        let autoPowerOffInterval = this._builder.get_object('auto_power_off_interval');
        this._settings.bind('bluetooth-auto-power-off-interval', autoPowerOffInterval, 'value', Gio.SettingsBindFlags.DEFAULT);

        let keepMenuOnToggleSwitch = this._builder.get_object('keep_menu_on_toggle');
        this._settings.bind('keep-menu-on-toggle', keepMenuOnToggleSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

        let refreshButtonOnSwitch = this._builder.get_object('refresh_button_on');
        this._settings.bind('refresh-button-on', refreshButtonOnSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);

        let debugModeOnSwitch = this._builder.get_object('debug_mode_on');
        this._settings.bind('debug-mode-on', debugModeOnSwitch, 'active', Gio.SettingsBindFlags.DEFAULT);
    }

}

function init() {
}

function buildPrefsWidget() {
    let settings = new SettingsBuilder();
    let widget = settings.build();
    widget.show_all();

    return widget;
}