mirror of
https://github.com/morgan9e/gnome-shell-extension-freon
synced 2026-04-14 00:14:14 +09:00
added preference dialog and schemas
This commit is contained in:
68
convenience.js
Normal file
68
convenience.js
Normal file
@@ -0,0 +1,68 @@
|
||||
/* -*- mode: js; js-basic-offset: 4; indent-tabs-mode: nil -*- */
|
||||
|
||||
const Gettext = imports.gettext;
|
||||
const Gio = imports.gi.Gio;
|
||||
|
||||
const Config = imports.misc.config;
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
|
||||
/**
|
||||
* initTranslations:
|
||||
* @domain: (optional): the gettext domain to use
|
||||
*
|
||||
* Initialize Gettext to load translations from extensionsdir/locale.
|
||||
* If @domain is not provided, it will be taken from metadata['gettext-domain']
|
||||
*/
|
||||
function initTranslations(domain) {
|
||||
let extension = ExtensionUtils.getCurrentExtension();
|
||||
|
||||
domain = domain || extension.metadata['gettext-domain'];
|
||||
|
||||
// check if this extension was built with "make zip-file", and thus
|
||||
// has the locale files in a subfolder
|
||||
// otherwise assume that extension has been installed in the
|
||||
// same prefix as gnome-shell
|
||||
let localeDir = extension.dir.get_child('locale');
|
||||
if (localeDir.query_exists(null))
|
||||
Gettext.bindtextdomain(domain, localeDir.get_path());
|
||||
else
|
||||
Gettext.bindtextdomain(domain, Config.LOCALEDIR);
|
||||
}
|
||||
|
||||
/**
|
||||
* getSettings:
|
||||
* @schema: (optional): the GSettings schema id
|
||||
*
|
||||
* Builds and return a GSettings schema for @schema, using schema files
|
||||
* in extensionsdir/schemas. If @schema is not provided, it is taken from
|
||||
* metadata['settings-schema'].
|
||||
*/
|
||||
function getSettings(schema) {
|
||||
let extension = ExtensionUtils.getCurrentExtension();
|
||||
|
||||
schema = schema || extension.metadata['settings-schema'];
|
||||
|
||||
const GioSSS = Gio.SettingsSchemaSource;
|
||||
|
||||
// check if this extension was built with "make zip-file", and thus
|
||||
// has the schema files in a subfolder
|
||||
// otherwise assume that extension has been installed in the
|
||||
// same prefix as gnome-shell (and therefore schemas are available
|
||||
// in the standard folders)
|
||||
let schemaDir = extension.dir.get_child('schemas');
|
||||
let schemaSource;
|
||||
if (schemaDir.query_exists(null))
|
||||
schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
|
||||
GioSSS.get_default(),
|
||||
false);
|
||||
else
|
||||
schemaSource = GioSSS.get_default();
|
||||
|
||||
let schemaObj = schemaSource.lookup(schema, true);
|
||||
if (!schemaObj)
|
||||
throw new Error('Schema ' + schema + ' could not be found for extension '
|
||||
+ extension.metadata.uuid + '. Please check your installation.');
|
||||
|
||||
return new Gio.Settings({ settings_schema: schemaObj });
|
||||
}
|
||||
|
||||
62
prefs.js
Normal file
62
prefs.js
Normal file
@@ -0,0 +1,62 @@
|
||||
const GLib = imports.gi.GLib;
|
||||
const GObject = imports.gi.GObject;
|
||||
const Gio = imports.gi.Gio;
|
||||
const Gtk = imports.gi.Gtk;
|
||||
const Lang = imports.lang;
|
||||
|
||||
const Gettext = imports.gettext.domain('gnome-shell-extensions');
|
||||
const _ = Gettext.gettext;
|
||||
|
||||
const ExtensionUtils = imports.misc.extensionUtils;
|
||||
const Me = ExtensionUtils.getCurrentExtension();
|
||||
const Convenience = Me.imports.convenience;
|
||||
|
||||
function init() {
|
||||
Convenience.initTranslations();
|
||||
}
|
||||
|
||||
const CPUTemperaturePrefsWidget = new GObject.Class({
|
||||
Name: 'CPUTemperature.Prefs.Widget',
|
||||
GTypeName: 'CPUTemperaturePrefsWidget',
|
||||
Extends: Gtk.Grid,
|
||||
|
||||
_init: function(params) {
|
||||
this.parent(params);
|
||||
// this.margin = this.row_spacing = this.column_spacing = 30;
|
||||
|
||||
this._settings = Convenience.getSettings();
|
||||
this.attach(new Gtk.Label({ label: 'Seconds before next update' }), 0, 0, 1, 1);
|
||||
let update_time = Gtk.Scale.new_with_range(Gtk.Orientation.HORIZONTAL, 0, 100, 5);
|
||||
update_time.set_value(this._settings.get_int('hpadding'));
|
||||
update_time.set_digits(0);
|
||||
update_time.set_hexpand(true);
|
||||
update_time.connect('value-changed', Lang.bind(this, this._onUpdateTimeChanged));
|
||||
this.attach(update_time, 1, 0, 1, 1);
|
||||
|
||||
|
||||
this.attach(new Gtk.Label({ label: 'Unit' }), 0, 2, 1, 1);
|
||||
let radio = null;
|
||||
centigrade = new Gtk.RadioButton({ group: radio, label: "Centigrade", valign: Gtk.Align.START });
|
||||
|
||||
fahrenheit = new Gtk.RadioButton({ group: centigrade, label: "Fahrenheit", valign: Gtk.Align.START });
|
||||
this.attach(centigrade, 1, 2, 1, 1);
|
||||
this.attach(fahrenheit, 2, 2, 1, 1);
|
||||
|
||||
|
||||
|
||||
// this._place3.set_active (true);
|
||||
this._update_time = update_time;
|
||||
},
|
||||
|
||||
_onUpdateTimeChanged: function (update_time) {
|
||||
this._settings.set_int('update_time', this._update_time.get_value());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
function buildPrefsWidget() {
|
||||
let widget = new CPUTemperaturePrefsWidget();
|
||||
widget.show_all();
|
||||
|
||||
return widget;
|
||||
}
|
||||
BIN
schemas/gschemas.compiled
Normal file
BIN
schemas/gschemas.compiled
Normal file
Binary file not shown.
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schemalist gettext-domain="gnome-shell-extensions">
|
||||
<schema path="/org/gnome/shell/extensions/cpu-temperature/" id="org.gnome.shell.extensions.cpu-temperature">
|
||||
<key type="i" name="hpadding">
|
||||
<default>6</default>
|
||||
<summary>Hpadding between icons (pixels)</summary>
|
||||
<description>This hpadding will be applied to the icons in the status area. Default is 12 pixels, we recommend at least 6.</description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<schemalist gettext-domain="gnome-shell-extensions">
|
||||
|
||||
<enum id='org.gnome.shell.extensions.cpu-temperature.Unit'>
|
||||
<value value='Centigrade' nick='Centigrade'/>
|
||||
<value value='Fahrenheit' nick='Fahrenheit'/>
|
||||
</enum>
|
||||
|
||||
<schema path="/org/gnome/shell/extensions/cpu-temperature/" id="org.gnome.shell.extensions.cpu-temperature">
|
||||
<key type="i" name="update_time">
|
||||
<default>15</default>
|
||||
<summary>Seconds before next update</summary>
|
||||
<description>This is the seconds after CPU temperature extension updates the data from the syetem. The default is 15.</description>
|
||||
</key>
|
||||
<key type="i" name="update_time">
|
||||
<default>15</default>
|
||||
<summary>Seconds before next update</summary>
|
||||
<description>This is the seconds after CPU temperature extension updates the data from the syetem. The default is 15.</description>
|
||||
</key>
|
||||
</schema>
|
||||
</schemalist>
|
||||
Reference in New Issue
Block a user