mirror of
https://github.com/oleid/gnome-shell-teatime.git
synced 2022-04-29 18:53:50 +00:00
Beautify with js-beautify 1.10.2
This commit is contained in:
parent
9d1e631ec2
commit
5d15efdc4d
463
src/extension.js
463
src/extension.js
@ -29,283 +29,282 @@ const N_ = function (e) {
|
|||||||
|
|
||||||
|
|
||||||
let PopupTeaMenuItem = GObject.registerClass(
|
let PopupTeaMenuItem = GObject.registerClass(
|
||||||
class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem {
|
class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||||
_init(sTeaname, nBrewtime, params) {
|
_init(sTeaname, nBrewtime, params) {
|
||||||
super._init(params);
|
super._init(params);
|
||||||
|
|
||||||
this.tealabel = new St.Label({
|
this.tealabel = new St.Label({
|
||||||
text: sTeaname
|
text: sTeaname
|
||||||
});
|
|
||||||
if (nBrewtime != 0) {
|
|
||||||
this.timelabel = new St.Label({
|
|
||||||
text: Utils.formatTime(nBrewtime)
|
|
||||||
});
|
});
|
||||||
}
|
if (nBrewtime != 0) {
|
||||||
|
this.timelabel = new St.Label({
|
||||||
|
text: Utils.formatTime(nBrewtime)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
this.add(this.tealabel);
|
this.add(this.tealabel);
|
||||||
if (nBrewtime != 0) {
|
if (nBrewtime != 0) {
|
||||||
this.add(this.timelabel);
|
this.add(this.timelabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._delegate = this;
|
this._delegate = this;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
let TeaTime = GObject.registerClass(
|
let TeaTime = GObject.registerClass(
|
||||||
class TeaTime extends PanelMenu.Button {
|
class TeaTime extends PanelMenu.Button {
|
||||||
_init() {
|
_init() {
|
||||||
super._init(1.0, "TeaTime");
|
super._init(1.0, "TeaTime");
|
||||||
|
|
||||||
this.config_keys = Utils.GetConfigKeys();
|
this.config_keys = Utils.GetConfigKeys();
|
||||||
|
|
||||||
this._settings = Utils.getSettings();
|
this._settings = Utils.getSettings();
|
||||||
|
|
||||||
this._logo = new Icon.TwoColorIcon(20, Icon.TeaPot);
|
this._logo = new Icon.TwoColorIcon(20, Icon.TeaPot);
|
||||||
|
|
||||||
// set timer widget
|
// set timer widget
|
||||||
this._textualTimer = new St.Label({
|
this._textualTimer = new St.Label({
|
||||||
text: "",
|
text: "",
|
||||||
x_align: Clutter.ActorAlign.END,
|
x_align: Clutter.ActorAlign.END,
|
||||||
y_align: Clutter.ActorAlign.CENTER
|
y_align: Clutter.ActorAlign.CENTER
|
||||||
});
|
});
|
||||||
this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie);
|
this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie);
|
||||||
|
|
||||||
this.add_actor(this._logo);
|
this.add_actor(this._logo);
|
||||||
this.add_style_class_name('panel-status-button');
|
this.add_style_class_name('panel-status-button');
|
||||||
this.connect('style-changed', this._onStyleChanged.bind(this));
|
this.connect('style-changed', this._onStyleChanged.bind(this));
|
||||||
|
|
||||||
this._idleTimeout = null;
|
this._idleTimeout = null;
|
||||||
|
|
||||||
this._createMenu();
|
this._createMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
_createMenu() {
|
_createMenu() {
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this._settings.connect("changed::" + this.config_keys.steep_times,
|
this._settings.connect("changed::" + this.config_keys.steep_times,
|
||||||
this._updateTeaList.bind(this));
|
this._updateTeaList.bind(this));
|
||||||
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
|
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
|
||||||
this._updateCountdownType.bind(this));
|
this._updateCountdownType.bind(this));
|
||||||
|
|
||||||
this.teaItemCont = new PopupMenu.PopupMenuSection();
|
this.teaItemCont = new PopupMenu.PopupMenuSection();
|
||||||
|
|
||||||
/*******************/
|
/*******************/
|
||||||
// maybe one day the PopupImageMenuItem works^^
|
// maybe one day the PopupImageMenuItem works^^
|
||||||
let head = new PopupMenu.PopupMenuSection();
|
let head = new PopupMenu.PopupMenuSection();
|
||||||
let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences');
|
let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences');
|
||||||
// item._icon.icon_size = 15;
|
// item._icon.icon_size = 15;
|
||||||
item.connect('activate', this._showPreferences.bind(this));
|
item.connect('activate', this._showPreferences.bind(this));
|
||||||
head.addMenuItem(item);
|
head.addMenuItem(item);
|
||||||
|
|
||||||
/*******************/
|
/*******************/
|
||||||
let bottom = new PopupMenu.PopupMenuSection();
|
let bottom = new PopupMenu.PopupMenuSection();
|
||||||
this._customEntry = new St.Entry({
|
this._customEntry = new St.Entry({
|
||||||
style_class: 'teatime-custom-entry',
|
style_class: 'teatime-custom-entry',
|
||||||
track_hover: true,
|
track_hover: true,
|
||||||
hint_text: _("min:sec")
|
hint_text: _("min:sec")
|
||||||
});
|
});
|
||||||
this._customEntry.get_clutter_text().set_max_length(10);
|
this._customEntry.get_clutter_text().set_max_length(10);
|
||||||
this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this));
|
this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this));
|
||||||
bottom.box.add(this._customEntry);
|
bottom.box.add(this._customEntry);
|
||||||
bottom.actor.set_style("padding: 0px 18px;")
|
bottom.actor.set_style("padding: 0px 18px;")
|
||||||
|
|
||||||
/*******************/
|
/*******************/
|
||||||
|
|
||||||
this.menu.addMenuItem(head);
|
this.menu.addMenuItem(head);
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.menu.addMenuItem(this.teaItemCont);
|
this.menu.addMenuItem(this.teaItemCont);
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.menu.addMenuItem(bottom);
|
this.menu.addMenuItem(bottom);
|
||||||
|
|
||||||
this._updateTeaList();
|
this._updateTeaList();
|
||||||
}
|
}
|
||||||
|
|
||||||
_updateTeaList(config, output) {
|
_updateTeaList(config, output) {
|
||||||
// make sure the menu is empty
|
// make sure the menu is empty
|
||||||
this.teaItemCont.removeAll();
|
this.teaItemCont.removeAll();
|
||||||
|
|
||||||
// fill with new teas
|
// fill with new teas
|
||||||
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
||||||
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
|
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
|
||||||
menuItem.connect('activate', function () {
|
|
||||||
this._stopCountdown();
|
|
||||||
}.bind(this));
|
|
||||||
this.teaItemCont.addMenuItem(menuItem);
|
|
||||||
for (let teaname in list) {
|
|
||||||
let time = list[teaname].get_uint32();
|
|
||||||
|
|
||||||
let menuItem = new PopupTeaMenuItem(_(teaname), time);
|
|
||||||
menuItem.connect('activate', function () {
|
menuItem.connect('activate', function () {
|
||||||
this._initCountdown(time);
|
this._stopCountdown();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
this.teaItemCont.addMenuItem(menuItem);
|
this.teaItemCont.addMenuItem(menuItem);
|
||||||
}
|
for (let teaname in list) {
|
||||||
}
|
let time = list[teaname].get_uint32();
|
||||||
|
|
||||||
_updateCountdownType(config, output) {
|
let menuItem = new PopupTeaMenuItem(_(teaname), time);
|
||||||
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
menuItem.connect('activate', function () {
|
||||||
|
this._initCountdown(time);
|
||||||
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
|
}.bind(this));
|
||||||
if (this._idleTimeout != null) {
|
this.teaItemCont.addMenuItem(menuItem);
|
||||||
// we have a running countdown, replace the display
|
|
||||||
this.remove_actor(this._bGraphicalCountdown ?
|
|
||||||
this._graphicalTimer : this._textualTimer);
|
|
||||||
this._bGraphicalCountdown = bWantGraphicalCountdown;
|
|
||||||
this.add_actor(this._bGraphicalCountdown ?
|
|
||||||
this._graphicalTimer : this._textualTimer);
|
|
||||||
|
|
||||||
this._updateTimerDisplay(this._getRemainingSec());
|
|
||||||
} // if timeout active
|
|
||||||
} // value changed
|
|
||||||
}
|
|
||||||
|
|
||||||
_createCustomTimer(text, event) {
|
|
||||||
if (event.get_key_symbol() == Clutter.KEY_Enter ||
|
|
||||||
event.get_key_symbol() == Clutter.KEY_Return ||
|
|
||||||
event.get_key_symbol() == Clutter.KEY_KP_Enter) {
|
|
||||||
|
|
||||||
let customTime = text.get_text();
|
|
||||||
let seconds = 0;
|
|
||||||
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
|
|
||||||
if (match) {
|
|
||||||
let factor = 1;
|
|
||||||
if (match[3] === undefined) { // minutes and seconds?
|
|
||||||
for (var i = match.length - 2; i > 0; i--) {
|
|
||||||
let s = match[i] === undefined ? "" : match[i].replace(/^0/, ''); // fix for elder GNOME <= 3.10 which don't like leading zeros
|
|
||||||
if (s.match(/^\d+$/)) { // only if something left
|
|
||||||
seconds += factor * parseInt(s);
|
|
||||||
}
|
|
||||||
factor *= 60;
|
|
||||||
}
|
|
||||||
} else { // only seconds?
|
|
||||||
let s = match[3].replace(/^0/, '');
|
|
||||||
seconds = parseInt(s);
|
|
||||||
}
|
|
||||||
if (seconds > 0) {
|
|
||||||
this._initCountdown(seconds);
|
|
||||||
this.menu.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this._customEntry.set_text("");
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_showNotification(subject, text) {
|
_updateCountdownType(config, output) {
|
||||||
let source = new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
||||||
Main.messageTray.add(source);
|
|
||||||
|
|
||||||
let notification = new MessageTray.Notification(source, subject, text);
|
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
|
||||||
notification.setTransient(true);
|
if (this._idleTimeout != null) {
|
||||||
if (typeof source.showNotification === 'function') {
|
// we have a running countdown, replace the display
|
||||||
source.showNotification(notification);
|
this.remove_actor(this._bGraphicalCountdown ?
|
||||||
} else {
|
this._graphicalTimer : this._textualTimer);
|
||||||
source.notify(notification);
|
this._bGraphicalCountdown = bWantGraphicalCountdown;
|
||||||
|
this.add_actor(this._bGraphicalCountdown ?
|
||||||
|
this._graphicalTimer : this._textualTimer);
|
||||||
|
|
||||||
|
this._updateTimerDisplay(this._getRemainingSec());
|
||||||
|
} // if timeout active
|
||||||
|
} // value changed
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_initCountdown(time) {
|
_createCustomTimer(text, event) {
|
||||||
this._startTime = new Date();
|
if (event.get_key_symbol() == Clutter.KEY_Enter ||
|
||||||
this._stopTime = new Date();
|
event.get_key_symbol() == Clutter.KEY_Return ||
|
||||||
this._cntdownStart = time;
|
event.get_key_symbol() == Clutter.KEY_KP_Enter) {
|
||||||
|
|
||||||
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
let customTime = text.get_text();
|
||||||
|
let seconds = 0;
|
||||||
let dt = this._bGraphicalCountdown ?
|
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
|
||||||
Math.max(1.0, time / 90) // set time step to fit animation
|
if (match) {
|
||||||
:
|
let factor = 1;
|
||||||
1.0; // show every second for the textual countdown
|
if (match[3] === undefined) { // minutes and seconds?
|
||||||
|
for (var i = match.length - 2; i > 0; i--) {
|
||||||
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
|
let s = match[i] === undefined ? "" : match[i].replace(/^0/, ''); // fix for elder GNOME <= 3.10 which don't like leading zeros
|
||||||
|
if (s.match(/^\d+$/)) { // only if something left
|
||||||
this.remove_actor(this._logo); // show timer instead of default icon
|
seconds += factor * parseInt(s);
|
||||||
|
}
|
||||||
this._updateTimerDisplay(time);
|
factor *= 60;
|
||||||
|
}
|
||||||
this.add_actor(this._bGraphicalCountdown ?
|
} else { // only seconds?
|
||||||
this._graphicalTimer : this._textualTimer);
|
let s = match[3].replace(/^0/, '');
|
||||||
|
seconds = parseInt(s);
|
||||||
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
}
|
||||||
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
|
if (seconds > 0) {
|
||||||
}
|
this._initCountdown(seconds);
|
||||||
|
this.menu.close();
|
||||||
_stopCountdown() {
|
}
|
||||||
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
}
|
||||||
this.remove_actor(this._bGraphicalCountdown ?
|
this._customEntry.set_text("");
|
||||||
this._graphicalTimer : this._textualTimer);
|
}
|
||||||
this.add_actor(this._logo);
|
|
||||||
this._idleTimeout = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
_getRemainingSec() {
|
|
||||||
let a = new Date();
|
|
||||||
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
|
|
||||||
}
|
|
||||||
|
|
||||||
_updateTimerDisplay(remainingTime) {
|
|
||||||
if (this._bGraphicalCountdown) {
|
|
||||||
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
|
|
||||||
} else {
|
|
||||||
this._textualTimer.text = Utils.formatTime(remainingTime);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_doCountdown() {
|
_showNotification(subject, text) {
|
||||||
let remainingTime = this._getRemainingSec();
|
let source = new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
||||||
|
Main.messageTray.add(source);
|
||||||
|
|
||||||
if (remainingTime <= 0) {
|
let notification = new MessageTray.Notification(source, subject, text);
|
||||||
// count down finished, switch display again
|
notification.setTransient(true);
|
||||||
this._stopCountdown();
|
if (typeof source.showNotification === 'function') {
|
||||||
this._playSound();
|
source.showNotification(notification);
|
||||||
this._showNotification(_("Your tea is ready!"),
|
} else {
|
||||||
_("Drink it, while it is hot!"));
|
source.notify(notification);
|
||||||
return false;
|
}
|
||||||
} else {
|
|
||||||
this._updateTimerDisplay(remainingTime);
|
|
||||||
return true; // continue timer
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_playSound() {
|
_initCountdown(time) {
|
||||||
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
|
this._startTime = new Date();
|
||||||
if (bPlayAlarmSound) {
|
this._stopTime = new Date();
|
||||||
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
|
this._cntdownStart = time;
|
||||||
|
|
||||||
|
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
||||||
|
|
||||||
|
let dt = this._bGraphicalCountdown ?
|
||||||
|
Math.max(1.0, time / 90) // set time step to fit animation
|
||||||
|
:
|
||||||
|
1.0; // show every second for the textual countdown
|
||||||
|
|
||||||
|
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
|
||||||
|
|
||||||
|
this.remove_actor(this._logo); // show timer instead of default icon
|
||||||
|
|
||||||
|
this._updateTimerDisplay(time);
|
||||||
|
|
||||||
|
this.add_actor(this._bGraphicalCountdown ?
|
||||||
|
this._graphicalTimer : this._textualTimer);
|
||||||
|
|
||||||
|
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
||||||
|
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_showPreferences() {
|
_stopCountdown() {
|
||||||
const currExt = ExtensionUtils.getCurrentExtension();
|
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
||||||
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
|
this.remove_actor(this._bGraphicalCountdown ?
|
||||||
return 0;
|
this._graphicalTimer : this._textualTimer);
|
||||||
}
|
this.add_actor(this._logo);
|
||||||
|
this._idleTimeout = null;
|
||||||
|
}
|
||||||
|
|
||||||
_onStyleChanged(actor) {
|
_getRemainingSec() {
|
||||||
let themeNode = actor.get_theme_node();
|
let a = new Date();
|
||||||
let color = themeNode.get_foreground_color()
|
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
|
||||||
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
|
}
|
||||||
|
|
||||||
this._primaryColor = color;
|
_updateTimerDisplay(remainingTime) {
|
||||||
this._secondaryColor = new Clutter.Color({
|
if (this._bGraphicalCountdown) {
|
||||||
red: color.red,
|
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
|
||||||
green: color.green,
|
} else {
|
||||||
blue: color.blue,
|
this._textualTimer.text = Utils.formatTime(remainingTime);
|
||||||
alpha: color.alpha * 0.3
|
}
|
||||||
});
|
}
|
||||||
this._logo.setPadding(bHasPadding * padding);
|
|
||||||
this._graphicalTimer.setPadding(bHasPadding * padding);
|
|
||||||
this._textualTimer.margin_right = bHasPadding * padding;
|
|
||||||
this._textualTimer.margin_left = bHasPadding * padding;
|
|
||||||
|
|
||||||
this._logo.setColor(this._primaryColor, this._secondaryColor);
|
_doCountdown() {
|
||||||
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
|
let remainingTime = this._getRemainingSec();
|
||||||
|
|
||||||
// forward (possible) scaling style change to child
|
if (remainingTime <= 0) {
|
||||||
let scaling = Utils.getGlobalDisplayScaleFactor();
|
// count down finished, switch display again
|
||||||
this._logo.setScaling(scaling);
|
this._stopCountdown();
|
||||||
this._graphicalTimer.setScaling(scaling);
|
this._playSound();
|
||||||
}
|
this._showNotification(_("Your tea is ready!"),
|
||||||
});
|
_("Drink it, while it is hot!"));
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this._updateTimerDisplay(remainingTime);
|
||||||
|
return true; // continue timer
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function init(metadata) {
|
_playSound() {
|
||||||
}
|
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
|
||||||
|
if (bPlayAlarmSound) {
|
||||||
|
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_showPreferences() {
|
||||||
|
const currExt = ExtensionUtils.getCurrentExtension();
|
||||||
|
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
_onStyleChanged(actor) {
|
||||||
|
let themeNode = actor.get_theme_node();
|
||||||
|
let color = themeNode.get_foreground_color()
|
||||||
|
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
|
||||||
|
|
||||||
|
this._primaryColor = color;
|
||||||
|
this._secondaryColor = new Clutter.Color({
|
||||||
|
red: color.red,
|
||||||
|
green: color.green,
|
||||||
|
blue: color.blue,
|
||||||
|
alpha: color.alpha * 0.3
|
||||||
|
});
|
||||||
|
this._logo.setPadding(bHasPadding * padding);
|
||||||
|
this._graphicalTimer.setPadding(bHasPadding * padding);
|
||||||
|
this._textualTimer.margin_right = bHasPadding * padding;
|
||||||
|
this._textualTimer.margin_left = bHasPadding * padding;
|
||||||
|
|
||||||
|
this._logo.setColor(this._primaryColor, this._secondaryColor);
|
||||||
|
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
|
||||||
|
|
||||||
|
// forward (possible) scaling style change to child
|
||||||
|
let scaling = Utils.getGlobalDisplayScaleFactor();
|
||||||
|
this._logo.setScaling(scaling);
|
||||||
|
this._graphicalTimer.setScaling(scaling);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function init(metadata) {}
|
||||||
|
|
||||||
let _TeaTime;
|
let _TeaTime;
|
||||||
|
|
||||||
|
142
src/icon.js
142
src/icon.js
@ -18,81 +18,81 @@ const Me = ExUt.getCurrentExtension();
|
|||||||
const Utils = Me.imports.utils;
|
const Utils = Me.imports.utils;
|
||||||
|
|
||||||
var TwoColorIcon = GObject.registerClass(
|
var TwoColorIcon = GObject.registerClass(
|
||||||
class TwoColorIcon extends St.DrawingArea {
|
class TwoColorIcon extends St.DrawingArea {
|
||||||
_init(size, drawingObject) {
|
_init(size, drawingObject) {
|
||||||
super._init({
|
super._init({
|
||||||
reactive: true,
|
reactive: true,
|
||||||
style: 'padding: 0px 0px'
|
style: 'padding: 0px 0px'
|
||||||
});
|
});
|
||||||
this._base_size = size;
|
this._base_size = size;
|
||||||
//this.setScaling(Utils.getGlobalDisplayScaleFactor());
|
//this.setScaling(Utils.getGlobalDisplayScaleFactor());
|
||||||
|
|
||||||
this._drawingObject = drawingObject;
|
this._drawingObject = drawingObject;
|
||||||
|
|
||||||
this.connect('repaint', function () {
|
this.connect('repaint', function () {
|
||||||
this._drawIcon();
|
this._drawIcon();
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
// some fallback color
|
// some fallback color
|
||||||
this._primaryColor = new Clutter.Color({
|
this._primaryColor = new Clutter.Color({
|
||||||
red: 150,
|
red: 150,
|
||||||
green: 150,
|
green: 150,
|
||||||
blue: 150,
|
blue: 150,
|
||||||
alpha: 255
|
alpha: 255
|
||||||
});
|
});
|
||||||
this._secundaryColor = this._primaryColor;
|
this._secundaryColor = this._primaryColor;
|
||||||
this._customStatus = null;
|
this._customStatus = null;
|
||||||
}
|
|
||||||
|
|
||||||
setPadding(padding) {
|
|
||||||
this.margin_left = padding;
|
|
||||||
this.margin_right = padding;
|
|
||||||
}
|
|
||||||
|
|
||||||
setColor(primary, secundary) {
|
|
||||||
this._primaryColor = primary;
|
|
||||||
this._secundaryColor = secundary;
|
|
||||||
this.queue_repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
setScaling(newScale) {
|
|
||||||
this._default_scale = newScale;
|
|
||||||
this.set_width(this._base_size * this._default_scale);
|
|
||||||
this.set_height(this._base_size * this._default_scale);
|
|
||||||
this.queue_repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
setStatus(newStatus) {
|
|
||||||
this._customStatus = newStatus;
|
|
||||||
this.queue_repaint();
|
|
||||||
}
|
|
||||||
|
|
||||||
_drawIcon() {
|
|
||||||
let cr = this.get_context();
|
|
||||||
let orWdt = this._drawingObject.width;
|
|
||||||
let orHgt = this._drawingObject.height;
|
|
||||||
let [width, height] = this.get_surface_size();
|
|
||||||
|
|
||||||
cr.save();
|
|
||||||
|
|
||||||
let object_longest_edge = Math.max(orWdt, orHgt);
|
|
||||||
let surface_shortest_edge = Math.min(width, height);
|
|
||||||
let scaling = surface_shortest_edge / object_longest_edge;
|
|
||||||
let padding_x = (width - orWdt * scaling) * 0.5;
|
|
||||||
let padding_y = (height - orHgt * scaling) * 0.5;
|
|
||||||
|
|
||||||
cr.translate(padding_x, padding_y);
|
|
||||||
try {
|
|
||||||
cr.scale(scaling, scaling);
|
|
||||||
|
|
||||||
this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor);
|
|
||||||
|
|
||||||
cr.restore();
|
|
||||||
} catch (e) {
|
|
||||||
// ignore
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
setPadding(padding) {
|
||||||
|
this.margin_left = padding;
|
||||||
|
this.margin_right = padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
setColor(primary, secundary) {
|
||||||
|
this._primaryColor = primary;
|
||||||
|
this._secundaryColor = secundary;
|
||||||
|
this.queue_repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
setScaling(newScale) {
|
||||||
|
this._default_scale = newScale;
|
||||||
|
this.set_width(this._base_size * this._default_scale);
|
||||||
|
this.set_height(this._base_size * this._default_scale);
|
||||||
|
this.queue_repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
setStatus(newStatus) {
|
||||||
|
this._customStatus = newStatus;
|
||||||
|
this.queue_repaint();
|
||||||
|
}
|
||||||
|
|
||||||
|
_drawIcon() {
|
||||||
|
let cr = this.get_context();
|
||||||
|
let orWdt = this._drawingObject.width;
|
||||||
|
let orHgt = this._drawingObject.height;
|
||||||
|
let [width, height] = this.get_surface_size();
|
||||||
|
|
||||||
|
cr.save();
|
||||||
|
|
||||||
|
let object_longest_edge = Math.max(orWdt, orHgt);
|
||||||
|
let surface_shortest_edge = Math.min(width, height);
|
||||||
|
let scaling = surface_shortest_edge / object_longest_edge;
|
||||||
|
let padding_x = (width - orWdt * scaling) * 0.5;
|
||||||
|
let padding_y = (height - orHgt * scaling) * 0.5;
|
||||||
|
|
||||||
|
cr.translate(padding_x, padding_y);
|
||||||
|
try {
|
||||||
|
cr.scale(scaling, scaling);
|
||||||
|
|
||||||
|
this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor);
|
||||||
|
|
||||||
|
cr.restore();
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var TeaPot = {
|
var TeaPot = {
|
||||||
width: 484,
|
width: 484,
|
||||||
|
468
src/prefs.js
468
src/prefs.js
@ -27,289 +27,289 @@ const Columns = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var TeaTimePrefsWidget = GObject.registerClass(
|
var TeaTimePrefsWidget = GObject.registerClass(
|
||||||
class TeaTimePrefsWidget extends Gtk.Grid {
|
class TeaTimePrefsWidget extends Gtk.Grid {
|
||||||
_init() {
|
_init() {
|
||||||
super._init({
|
super._init({
|
||||||
orientation: Gtk.Orientation.VERTICAL,
|
orientation: Gtk.Orientation.VERTICAL,
|
||||||
column_homogeneous: false,
|
column_homogeneous: false,
|
||||||
vexpand: true,
|
vexpand: true,
|
||||||
margin_start: 5,
|
margin_start: 5,
|
||||||
margin_end: 5,
|
margin_end: 5,
|
||||||
margin_top: 5,
|
margin_top: 5,
|
||||||
margin_bottom: 5,
|
margin_bottom: 5,
|
||||||
row_spacing: 5
|
row_spacing: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
this.config_keys = Utils.GetConfigKeys();
|
this.config_keys = Utils.GetConfigKeys();
|
||||||
|
|
||||||
this._tealist = new Gtk.ListStore();
|
this._tealist = new Gtk.ListStore();
|
||||||
this._tealist.set_column_types([
|
this._tealist.set_column_types([
|
||||||
GObject.TYPE_STRING,
|
GObject.TYPE_STRING,
|
||||||
GObject.TYPE_INT,
|
GObject.TYPE_INT,
|
||||||
Gtk.Adjustment
|
Gtk.Adjustment
|
||||||
]);
|
]);
|
||||||
|
|
||||||
this.set_column_spacing(3);
|
this.set_column_spacing(3);
|
||||||
|
|
||||||
this._settings = Utils.getSettings();
|
this._settings = Utils.getSettings();
|
||||||
this._inhibitUpdate = true;
|
this._inhibitUpdate = true;
|
||||||
this._settings.connect("changed", this._refresh.bind(this));
|
this._settings.connect("changed", this._refresh.bind(this));
|
||||||
|
|
||||||
this._initWindow();
|
this._initWindow();
|
||||||
this._inhibitUpdate = false;
|
this._inhibitUpdate = false;
|
||||||
this._refresh();
|
this._refresh();
|
||||||
this._tealist.connect("row-changed", this._save.bind(this));
|
this._tealist.connect("row-changed", this._save.bind(this));
|
||||||
this._tealist.connect("row-deleted", this._save.bind(this));
|
this._tealist.connect("row-deleted", this._save.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
_initWindow() {
|
_initWindow() {
|
||||||
let curRow = 0;
|
let curRow = 0;
|
||||||
let labelGC = new Gtk.Label({
|
let labelGC = new Gtk.Label({
|
||||||
label: _("Graphical Countdown"),
|
label: _("Graphical Countdown"),
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
halign: Gtk.Align.START
|
halign: Gtk.Align.START
|
||||||
});
|
});
|
||||||
|
|
||||||
let labelAS = new Gtk.Label({
|
let labelAS = new Gtk.Label({
|
||||||
label: _("Alarm sound"),
|
label: _("Alarm sound"),
|
||||||
hexpand: true,
|
hexpand: true,
|
||||||
halign: Gtk.Align.START
|
halign: Gtk.Align.START
|
||||||
});
|
});
|
||||||
|
|
||||||
this.graphicalCountdownSwitch = new Gtk.Switch();
|
this.graphicalCountdownSwitch = new Gtk.Switch();
|
||||||
this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this));
|
this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this));
|
||||||
|
|
||||||
// alarm sound file chooser
|
// alarm sound file chooser
|
||||||
this.alarmSoundSwitch = new Gtk.Switch();
|
this.alarmSoundSwitch = new Gtk.Switch();
|
||||||
this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this));
|
this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this));
|
||||||
|
|
||||||
|
|
||||||
this.alarmSoundFileFilter = new Gtk.FileFilter();
|
this.alarmSoundFileFilter = new Gtk.FileFilter();
|
||||||
this.alarmSoundFileFilter.add_mime_type("audio/*");
|
this.alarmSoundFileFilter.add_mime_type("audio/*");
|
||||||
|
|
||||||
this.alarmSoundFileButton = new Gtk.Button({
|
this.alarmSoundFileButton = new Gtk.Button({
|
||||||
label: _("Select alarm sound file")
|
label: _("Select alarm sound file")
|
||||||
});
|
});
|
||||||
this.alarmSoundFileButton.connect("clicked", this._selectAlarmSoundFile.bind(this));
|
this.alarmSoundFileButton.connect("clicked", this._selectAlarmSoundFile.bind(this));
|
||||||
|
|
||||||
this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
||||||
this.attach(this.graphicalCountdownSwitch, 3, curRow, 2, 1);
|
this.attach(this.graphicalCountdownSwitch, 3, curRow, 2, 1);
|
||||||
curRow += 1;
|
curRow += 1;
|
||||||
|
|
||||||
this.attach(labelAS, 0 /*col*/ , curRow+1 /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
|
this.attach(labelAS, 0 /*col*/ , curRow + 1 /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
|
||||||
this.attach(this.alarmSoundFileButton, 1, curRow, 1, 2);
|
this.attach(this.alarmSoundFileButton, 1, curRow, 1, 2);
|
||||||
this.attach(this.alarmSoundSwitch, 3, curRow+1, 2, 1);
|
this.attach(this.alarmSoundSwitch, 3, curRow + 1, 2, 1);
|
||||||
curRow += 2;
|
curRow += 2;
|
||||||
|
|
||||||
this.treeview = new Gtk.TreeView({
|
this.treeview = new Gtk.TreeView({
|
||||||
model: this._tealist
|
model: this._tealist
|
||||||
});
|
});
|
||||||
this.treeview.set_reorderable(true);
|
this.treeview.set_reorderable(true);
|
||||||
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
|
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
|
||||||
this.attach(this.treeview, 0, curRow, 6, 1);
|
this.attach(this.treeview, 0, curRow, 6, 1);
|
||||||
curRow += 1;
|
curRow += 1;
|
||||||
|
|
||||||
let teaname = new Gtk.TreeViewColumn({
|
let teaname = new Gtk.TreeViewColumn({
|
||||||
title: _("Tea"),
|
title: _("Tea"),
|
||||||
expand: true
|
expand: true
|
||||||
});
|
});
|
||||||
let renderer = new Gtk.CellRendererText({
|
let renderer = new Gtk.CellRendererText({
|
||||||
editable: true
|
editable: true
|
||||||
});
|
});
|
||||||
// When the renderer is done editing it's value, we first write
|
// When the renderer is done editing it's value, we first write
|
||||||
// the new value to the view's model, i.e. this._tealist.
|
// the new value to the view's model, i.e. this._tealist.
|
||||||
// This makes life a little harder due to chaining of callbacks
|
// This makes life a little harder due to chaining of callbacks
|
||||||
// and the need for this._inhibitUpdate, but it feels a lot cleaner
|
// and the need for this._inhibitUpdate, but it feels a lot cleaner
|
||||||
// when the UI does not know about the config storage backend.
|
// when the UI does not know about the config storage backend.
|
||||||
renderer.connect("edited", function (renderer, pathString, newValue) {
|
renderer.connect("edited", function (renderer, pathString, newValue) {
|
||||||
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
|
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
|
||||||
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
|
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
teaname.pack_start(renderer, true);
|
teaname.pack_start(renderer, true);
|
||||||
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
|
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
|
||||||
this.treeview.append_column(teaname);
|
this.treeview.append_column(teaname);
|
||||||
|
|
||||||
let steeptime = new Gtk.TreeViewColumn({
|
let steeptime = new Gtk.TreeViewColumn({
|
||||||
title: _("Steep time"),
|
title: _("Steep time"),
|
||||||
min_width: 150
|
min_width: 150
|
||||||
});
|
});
|
||||||
let spinrenderer = new Gtk.CellRendererSpin({
|
let spinrenderer = new Gtk.CellRendererSpin({
|
||||||
editable: true
|
editable: true
|
||||||
});
|
});
|
||||||
// See comment above.
|
// See comment above.
|
||||||
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
|
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
|
||||||
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
|
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
|
||||||
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
|
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
steeptime.pack_start(spinrenderer, true);
|
steeptime.pack_start(spinrenderer, true);
|
||||||
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
|
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
|
||||||
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
|
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
|
||||||
this.treeview.append_column(steeptime);
|
this.treeview.append_column(steeptime);
|
||||||
this.treeview.expand_all();
|
this.treeview.expand_all();
|
||||||
|
|
||||||
//this.toolbar = new Gtk.Toolbar({
|
//this.toolbar = new Gtk.Toolbar({
|
||||||
// icon_size: 1
|
// icon_size: 1
|
||||||
//});
|
//});
|
||||||
// this.toolbar.get_style_context().add_class("inline-toolbar");
|
// this.toolbar.get_style_context().add_class("inline-toolbar");
|
||||||
// this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ );
|
// this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ );
|
||||||
this.addButton = Gtk.Button.new_from_icon_name("list-add-symbolic", 0 /* size: 0 - inherit */);
|
this.addButton = Gtk.Button.new_from_icon_name("list-add-symbolic", 0 /* size: 0 - inherit */ );
|
||||||
this.addButton.connect("clicked", this._addTea.bind(this));
|
this.addButton.connect("clicked", this._addTea.bind(this));
|
||||||
this.attach(this.addButton, 2 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
this.attach(this.addButton, 2 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
||||||
this.removeButton = Gtk.Button.new_from_icon_name("list-remove-symbolic", 0);
|
this.removeButton = Gtk.Button.new_from_icon_name("list-remove-symbolic", 0);
|
||||||
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
|
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
|
||||||
this.attach(this.removeButton, 4 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
this.attach(this.removeButton, 4 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
||||||
}
|
}
|
||||||
|
|
||||||
_selectAlarmSoundFile() {
|
_selectAlarmSoundFile() {
|
||||||
// recreate -> preselecting file doesn't work on second call if not ...
|
// recreate -> preselecting file doesn't work on second call if not ...
|
||||||
this.alarmSoundFile = new Gtk.FileChooserNative({
|
this.alarmSoundFile = new Gtk.FileChooserNative({
|
||||||
title: _("Select alarm sound file"),
|
title: _("Select alarm sound file"),
|
||||||
action: Gtk.FileChooserAction.OPEN,
|
action: Gtk.FileChooserAction.OPEN,
|
||||||
|
|
||||||
});
|
});
|
||||||
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
|
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
|
||||||
this.alarmSoundFile.connect("response", this._saveSoundFile.bind(this));
|
this.alarmSoundFile.connect("response", this._saveSoundFile.bind(this));
|
||||||
this.alarmSoundFile.set_file(Gio.File.new_for_uri(this.alarmSoundFileFile));
|
this.alarmSoundFile.set_file(Gio.File.new_for_uri(this.alarmSoundFileFile));
|
||||||
this.alarmSoundFile.show();
|
this.alarmSoundFile.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
_refresh() {
|
_refresh() {
|
||||||
// don't update the model if someone else is messing with the backend
|
// don't update the model if someone else is messing with the backend
|
||||||
if (this._inhibitUpdate)
|
if (this._inhibitUpdate)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
this.graphicalCountdownSwitch.active = this._settings.get_boolean(this.config_keys.graphical_countdown)
|
this.graphicalCountdownSwitch.active = this._settings.get_boolean(this.config_keys.graphical_countdown)
|
||||||
this.alarmSoundSwitch.active = this._settings.get_boolean(this.config_keys.use_alarm_sound)
|
this.alarmSoundSwitch.active = this._settings.get_boolean(this.config_keys.use_alarm_sound)
|
||||||
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
||||||
this.alarmSoundFileFile = this._settings.get_string(this.config_keys.alarm_sound);
|
this.alarmSoundFileFile = this._settings.get_string(this.config_keys.alarm_sound);
|
||||||
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
|
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
|
||||||
|
|
||||||
// stop everyone from reacting to the changes we are about to produce
|
// stop everyone from reacting to the changes we are about to produce
|
||||||
// in the model
|
// in the model
|
||||||
this._inhibitUpdate = true;
|
this._inhibitUpdate = true;
|
||||||
|
|
||||||
this._tealist.clear();
|
this._tealist.clear();
|
||||||
for (let teaname in list) {
|
for (let teaname in list) {
|
||||||
let time = list[teaname].get_uint32();
|
let time = list[teaname].get_uint32();
|
||||||
|
|
||||||
|
let adj = new Gtk.Adjustment({
|
||||||
|
lower: 1,
|
||||||
|
step_increment: 1,
|
||||||
|
upper: 65535,
|
||||||
|
value: time
|
||||||
|
});
|
||||||
|
this._tealist.set(this._tealist.append(), [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], [teaname, time, adj]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._inhibitUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_addTea() {
|
||||||
let adj = new Gtk.Adjustment({
|
let adj = new Gtk.Adjustment({
|
||||||
lower: 1,
|
lower: 1,
|
||||||
step_increment: 1,
|
step_increment: 1,
|
||||||
upper: 65535,
|
upper: 65535,
|
||||||
value: time
|
value: 1
|
||||||
});
|
});
|
||||||
this._tealist.set(this._tealist.append(), [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], [teaname, time, adj]);
|
let item = this._tealist.append();
|
||||||
|
this._tealist.set(item, [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], ["", 1, adj]);
|
||||||
|
this.treeview.set_cursor(this._tealist.get_path(item),
|
||||||
|
this.treeview.get_column(Columns.TEA_NAME),
|
||||||
|
true);
|
||||||
}
|
}
|
||||||
|
|
||||||
this._inhibitUpdate = false;
|
_removeSelectedTea() {
|
||||||
}
|
let [selection, store] = this.treeview.get_selection().get_selected_rows();
|
||||||
|
let iters = [];
|
||||||
|
for (let i = 0; i < selection.length; ++i) {
|
||||||
|
let [isSet, iter] = store.get_iter(selection[i]);
|
||||||
|
if (isSet) {
|
||||||
|
iters.push(iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// it's ok not to inhibit updates here as remove != change
|
||||||
|
iters.forEach(function (value, index, array) {
|
||||||
|
store.remove(value)
|
||||||
|
});
|
||||||
|
|
||||||
_addTea() {
|
this.treeview.get_selection().unselect_all();
|
||||||
let adj = new Gtk.Adjustment({
|
}
|
||||||
lower: 1,
|
|
||||||
step_increment: 1,
|
|
||||||
upper: 65535,
|
|
||||||
value: 1
|
|
||||||
});
|
|
||||||
let item = this._tealist.append();
|
|
||||||
this._tealist.set(item, [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], ["", 1, adj]);
|
|
||||||
this.treeview.set_cursor(this._tealist.get_path(item),
|
|
||||||
this.treeview.get_column(Columns.TEA_NAME),
|
|
||||||
true);
|
|
||||||
}
|
|
||||||
|
|
||||||
_removeSelectedTea() {
|
_saveGraphicalCountdown(sw, data) {
|
||||||
let [selection, store] = this.treeview.get_selection().get_selected_rows();
|
// don't update the backend if someone else is messing with the model
|
||||||
let iters = [];
|
if (this._inhibitUpdate)
|
||||||
for (let i = 0; i < selection.length; ++i) {
|
return;
|
||||||
let [isSet, iter] = store.get_iter(selection[i]);
|
this._inhibitUpdate = true;
|
||||||
if (isSet) {
|
this._settings.set_boolean(this.config_keys.graphical_countdown,
|
||||||
iters.push(iter);
|
sw.active);
|
||||||
|
this._inhibitUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_saveUseAlarm(sw, data) {
|
||||||
|
// don't update the backend if someone else is messing with the model
|
||||||
|
if (this._inhibitUpdate)
|
||||||
|
return;
|
||||||
|
this._inhibitUpdate = true;
|
||||||
|
this._settings.set_boolean(this.config_keys.use_alarm_sound,
|
||||||
|
sw.active);
|
||||||
|
this._inhibitUpdate = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_saveSoundFile(sw, response_id, data) {
|
||||||
|
// don't update the backend if someone else is messing with the model or not accept new file
|
||||||
|
if (this._inhibitUpdate || response_id != Gtk.ResponseType.ACCEPT)
|
||||||
|
return;
|
||||||
|
let alarm_sound = this.alarmSoundFile.get_file().get_uri();
|
||||||
|
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
|
||||||
|
|
||||||
|
let have_value = Utils.isType(alarm_sound, "string");
|
||||||
|
let setting_is_different =
|
||||||
|
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
|
||||||
|
if (have_value && setting_is_different) {
|
||||||
|
this._inhibitUpdate = true;
|
||||||
|
|
||||||
|
Utils.playSound(alarm_sound);
|
||||||
|
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
|
||||||
|
this._inhibitUpdate = false;
|
||||||
|
this.alarmSoundFileFile = alarm_sound;
|
||||||
|
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// it's ok not to inhibit updates here as remove != change
|
|
||||||
iters.forEach(function (value, index, array) {
|
|
||||||
store.remove(value)
|
|
||||||
});
|
|
||||||
|
|
||||||
this.treeview.get_selection().unselect_all();
|
_save(store, path_, iter_) {
|
||||||
}
|
const GLib = imports.gi.GLib;
|
||||||
|
|
||||||
_saveGraphicalCountdown(sw, data) {
|
// don't update the backend if someone else is messing with the model
|
||||||
// don't update the backend if someone else is messing with the model
|
if (this._inhibitUpdate)
|
||||||
if (this._inhibitUpdate)
|
return;
|
||||||
return;
|
|
||||||
this._inhibitUpdate = true;
|
|
||||||
this._settings.set_boolean(this.config_keys.graphical_countdown,
|
|
||||||
sw.active);
|
|
||||||
this._inhibitUpdate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_saveUseAlarm(sw, data) {
|
let values = [];
|
||||||
// don't update the backend if someone else is messing with the model
|
this._tealist.foreach(function (store, path, iter) {
|
||||||
if (this._inhibitUpdate)
|
values.push(GLib.Variant.new_dict_entry(
|
||||||
return;
|
GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)),
|
||||||
this._inhibitUpdate = true;
|
GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME))))
|
||||||
this._settings.set_boolean(this.config_keys.use_alarm_sound,
|
});
|
||||||
sw.active);
|
let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values);
|
||||||
this._inhibitUpdate = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
_saveSoundFile(sw, response_id, data) {
|
// all changes have happened through the UI, we can safely
|
||||||
// don't update the backend if someone else is messing with the model or not accept new file
|
// disable updating it here to avoid an infinite loop
|
||||||
if (this._inhibitUpdate || response_id != Gtk.ResponseType.ACCEPT)
|
|
||||||
return;
|
|
||||||
let alarm_sound = this.alarmSoundFile.get_file().get_uri();
|
|
||||||
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
|
|
||||||
|
|
||||||
let have_value = Utils.isType(alarm_sound, "string");
|
|
||||||
let setting_is_different =
|
|
||||||
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
|
|
||||||
if (have_value && setting_is_different) {
|
|
||||||
this._inhibitUpdate = true;
|
this._inhibitUpdate = true;
|
||||||
|
|
||||||
Utils.playSound(alarm_sound);
|
this._settings.set_value(this.config_keys.steep_times, settingsValue);
|
||||||
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
|
|
||||||
this._inhibitUpdate = false;
|
this._inhibitUpdate = false;
|
||||||
this.alarmSoundFileFile = alarm_sound;
|
|
||||||
this.alarmSoundFileButton.label = Gio.File.new_for_uri(this.alarmSoundFileFile).get_basename();
|
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
|
||||||
_save(store, path_, iter_) {
|
|
||||||
const GLib = imports.gi.GLib;
|
|
||||||
|
|
||||||
// don't update the backend if someone else is messing with the model
|
|
||||||
if (this._inhibitUpdate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
let values = [];
|
|
||||||
this._tealist.foreach(function (store, path, iter) {
|
|
||||||
values.push(GLib.Variant.new_dict_entry(
|
|
||||||
GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)),
|
|
||||||
GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME))))
|
|
||||||
});
|
|
||||||
let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values);
|
|
||||||
|
|
||||||
// all changes have happened through the UI, we can safely
|
|
||||||
// disable updating it here to avoid an infinite loop
|
|
||||||
this._inhibitUpdate = true;
|
|
||||||
|
|
||||||
this._settings.set_value(this.config_keys.steep_times, settingsValue);
|
|
||||||
|
|
||||||
this._inhibitUpdate = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function init() {}
|
function init() {}
|
||||||
|
|
||||||
function buildPrefsWidget() {
|
function buildPrefsWidget() {
|
||||||
let widget = new TeaTimePrefsWidget();
|
let widget = new TeaTimePrefsWidget();
|
||||||
if (shellVersion < 40) {
|
if (shellVersion < 40) {
|
||||||
widget.show_all();
|
widget.show_all();
|
||||||
} else {
|
} else {
|
||||||
widget.show();
|
widget.show();
|
||||||
}
|
}
|
||||||
return widget;
|
return widget;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user