Fix indendation

After the "Fix TeaTime not working with gnome-shell 3.35.90 and newer"
commit, a bunch of blocks no longer have correct indentation.

These blocks were left as is on purpose to make the diff of that commit
easier to read.

This commit fixes the indentation of these blocks. This commit makes no
changes other then the indentation changes and as such contains no
functional changes.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
Hans de Goede 2020-02-17 17:53:56 +01:00
parent f02770da31
commit 89a04a36fb
3 changed files with 444 additions and 444 deletions

View File

@ -173,268 +173,268 @@ class TeaTime extends PanelMenu.Button {
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.actor.add_actor(this._logo); this.actor.add_actor(this._logo);
this.actor.add_style_class_name('panel-status-button'); this.actor.add_style_class_name('panel-status-button');
this.actor.connect('style-changed', this._onStyleChanged.bind(this)); this.actor.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._stopCountdown(); this._initCountdown(time);
}.bind(this)); }.bind(this));
this.teaItemCont.addMenuItem(menuItem); 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 () {
this._initCountdown(time);
}.bind(this));
this.teaItemCont.addMenuItem(menuItem);
}
} }
_updateCountdownType(config, output) { _updateCountdownType(config, output) {
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown); let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
if (bWantGraphicalCountdown != this._bGraphicalCountdown) { if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
if (this._idleTimeout != null) { if (this._idleTimeout != null) {
// we have a running countdown, replace the display // we have a running countdown, replace the display
this.actor.remove_actor(this._bGraphicalCountdown ? this.actor.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer); this._graphicalTimer : this._textualTimer);
this._bGraphicalCountdown = bWantGraphicalCountdown; this._bGraphicalCountdown = bWantGraphicalCountdown;
this.actor.add_actor(this._bGraphicalCountdown ? this.actor.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer); this._graphicalTimer : this._textualTimer);
this._updateTimerDisplay(this._getRemainingSec()); this._updateTimerDisplay(this._getRemainingSec());
} // if timeout active } // if timeout active
} // value changed } // value changed
} }
_createCustomTimer(text, event) { _createCustomTimer(text, event) {
if (event.get_key_symbol() == Clutter.KEY_Enter || if (event.get_key_symbol() == Clutter.KEY_Enter ||
event.get_key_symbol() == Clutter.KEY_Return || event.get_key_symbol() == Clutter.KEY_Return ||
event.get_key_symbol() == Clutter.KEY_KP_Enter) { event.get_key_symbol() == Clutter.KEY_KP_Enter) {
let customTime = text.get_text(); let customTime = text.get_text();
let seconds = 0; let seconds = 0;
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/) let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
if (match) { if (match) {
let factor = 1; let factor = 1;
if (match[3] === undefined) { // minutes and seconds? if (match[3] === undefined) { // minutes and seconds?
for (var i = match.length - 2; i > 0; i--) { 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 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 if (s.match(/^\d+$/)) { // only if something left
seconds += factor * parseInt(s); seconds += factor * parseInt(s);
}
factor *= 60;
} }
} else { // only seconds? factor *= 60;
let s = match[3].replace(/^0/, '');
seconds = parseInt(s);
}
if (seconds > 0) {
this._initCountdown(seconds);
this.menu.close();
} }
} 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("");
} }
this._customEntry.set_text("");
}
} }
_showNotification(subject, text) { _showNotification(subject, text) {
let source = (Utils.isGnome34()) ? let source = (Utils.isGnome34()) ?
new MessageTray.Source(_("TeaTime applet")) : new MessageTray.Source(_("TeaTime applet")) :
new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime'); new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
if (Utils.isGnome34()) { if (Utils.isGnome34()) {
source.createNotificationIcon = source.createNotificationIcon =
function () { function () {
let iconBox = new St.Bin(); let iconBox = new St.Bin();
iconBox._size = this.ICON_SIZE; iconBox._size = this.ICON_SIZE;
iconBox.child = new St.Icon({ iconBox.child = new St.Icon({
icon_name: 'utilities-teatime', icon_name: 'utilities-teatime',
icon_type: St.IconType.FULLCOLOR, icon_type: St.IconType.FULLCOLOR,
icon_size: iconBox._size icon_size: iconBox._size
}); });
return iconBox; return iconBox;
} // createNotificationIcon } // createNotificationIcon
} }
Main.messageTray.add(source); Main.messageTray.add(source);
let notification = new MessageTray.Notification(source, subject, text); let notification = new MessageTray.Notification(source, subject, text);
notification.setTransient(true); notification.setTransient(true);
source.notify(notification); source.notify(notification);
} }
_initCountdown(time) { _initCountdown(time) {
this._startTime = new Date(); this._startTime = new Date();
this._stopTime = new Date(); this._stopTime = new Date();
this._cntdownStart = time; this._cntdownStart = time;
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown); this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
let dt = this._bGraphicalCountdown ? let dt = this._bGraphicalCountdown ?
Math.max(1.0, time / 90) // set time step to fit animation Math.max(1.0, time / 90) // set time step to fit animation
: :
1.0; // show every second for the textual countdown 1.0; // show every second for the textual countdown
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
this.actor.remove_actor(this._logo); // show timer instead of default icon this.actor.remove_actor(this._logo); // show timer instead of default icon
this._updateTimerDisplay(time); this._updateTimerDisplay(time);
this.actor.add_actor(this._bGraphicalCountdown ? this.actor.add_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer); this._graphicalTimer : this._textualTimer);
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this)); this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
} }
_stopCountdown() { _stopCountdown() {
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
this.actor.remove_actor(this._bGraphicalCountdown ? this.actor.remove_actor(this._bGraphicalCountdown ?
this._graphicalTimer : this._textualTimer); this._graphicalTimer : this._textualTimer);
this.actor.add_actor(this._logo); this.actor.add_actor(this._logo);
this._idleTimeout = null; this._idleTimeout = null;
} }
_getRemainingSec() { _getRemainingSec() {
let a = new Date(); let a = new Date();
return (this._stopTime.getTime() - a.getTime()) * 1e-3; return (this._stopTime.getTime() - a.getTime()) * 1e-3;
} }
_updateTimerDisplay(remainingTime) { _updateTimerDisplay(remainingTime) {
if (this._bGraphicalCountdown) { if (this._bGraphicalCountdown) {
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart); this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
} else { } else {
this._textualTimer.text = Utils.formatTime(remainingTime); this._textualTimer.text = Utils.formatTime(remainingTime);
} }
} }
_doCountdown() { _doCountdown() {
let remainingTime = this._getRemainingSec(); let remainingTime = this._getRemainingSec();
if (remainingTime <= 0) { if (remainingTime <= 0) {
// count down finished, switch display again // count down finished, switch display again
this._stopCountdown(); this._stopCountdown();
this._playSound(); this._playSound();
if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) { if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) {
this.dialog = new TeaTimeFullscreenNotification(); this.dialog = new TeaTimeFullscreenNotification();
this.dialog.show(); this.dialog.show();
} else {
this._showNotification(_("Your tea is ready!"),
_("Drink it, while it is hot!"));
}
return false;
} else { } else {
this._updateTimerDisplay(remainingTime); this._showNotification(_("Your tea is ready!"),
return true; // continue timer _("Drink it, while it is hot!"));
} }
return false;
} else {
this._updateTimerDisplay(remainingTime);
return true; // continue timer
}
} }
_playSound() { _playSound() {
let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound); let bPlayAlarmSound = this._settings.get_boolean(this.config_keys.use_alarm_sound);
if (bPlayAlarmSound) { if (bPlayAlarmSound) {
Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound)); Utils.playSound(this._settings.get_string(this.config_keys.alarm_sound));
} }
} }
_showPreferences() { _showPreferences() {
const currExt = ExtensionUtils.getCurrentExtension(); const currExt = ExtensionUtils.getCurrentExtension();
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]); imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
return 0; return 0;
} }
_onStyleChanged(actor) { _onStyleChanged(actor) {
let themeNode = actor.get_theme_node(); let themeNode = actor.get_theme_node();
let color = themeNode.get_foreground_color() let color = themeNode.get_foreground_color()
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false); let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
this._primaryColor = color; this._primaryColor = color;
this._secondaryColor = new Clutter.Color({ this._secondaryColor = new Clutter.Color({
red: color.red, red: color.red,
green: color.green, green: color.green,
blue: color.blue, blue: color.blue,
alpha: color.alpha * 0.3 alpha: color.alpha * 0.3
}); });
this._logo.setPadding(bHasPadding * padding); this._logo.setPadding(bHasPadding * padding);
this._graphicalTimer.setPadding(bHasPadding * padding); this._graphicalTimer.setPadding(bHasPadding * padding);
this._textualTimer.margin_right = bHasPadding * padding; this._textualTimer.margin_right = bHasPadding * padding;
this._textualTimer.margin_left = bHasPadding * padding; this._textualTimer.margin_left = bHasPadding * padding;
this._logo.setColor(this._primaryColor, this._secondaryColor); this._logo.setColor(this._primaryColor, this._secondaryColor);
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor); this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
// forward (possible) scaling style change to child // forward (possible) scaling style change to child
let scaling = Utils.getGlobalDisplayScaleFactor(); let scaling = Utils.getGlobalDisplayScaleFactor();
this._logo.setScaling(scaling); this._logo.setScaling(scaling);
this._graphicalTimer.setScaling(scaling); this._graphicalTimer.setScaling(scaling);
} }
}); });

View File

@ -24,73 +24,73 @@ class TwoColorIcon extends St.DrawingArea {
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) { setPadding(padding) {
this.margin_left = padding; this.margin_left = padding;
this.margin_right = padding; this.margin_right = padding;
} }
setColor(primary, secundary) { setColor(primary, secundary) {
this._primaryColor = primary; this._primaryColor = primary;
this._secundaryColor = secundary; this._secundaryColor = secundary;
this.queue_repaint(); this.queue_repaint();
} }
setScaling(newScale) { setScaling(newScale) {
this._default_scale = newScale; this._default_scale = newScale;
this.set_width(this._base_size * this._default_scale); this.set_width(this._base_size * this._default_scale);
this.set_height(this._base_size * this._default_scale); this.set_height(this._base_size * this._default_scale);
this.queue_repaint(); this.queue_repaint();
} }
setStatus(newStatus) { setStatus(newStatus) {
this._customStatus = newStatus; this._customStatus = newStatus;
this.queue_repaint(); this.queue_repaint();
} }
_drawIcon() { _drawIcon() {
let cr = this.get_context(); let cr = this.get_context();
let orWdt = this._drawingObject.width; let orWdt = this._drawingObject.width;
let orHgt = this._drawingObject.height; let orHgt = this._drawingObject.height;
let [width, height] = this.get_surface_size(); let [width, height] = this.get_surface_size();
cr.save(); cr.save();
let object_longest_edge = Math.max(orWdt, orHgt); let object_longest_edge = Math.max(orWdt, orHgt);
let surface_shortest_edge = Math.min(width, height); let surface_shortest_edge = Math.min(width, height);
let scaling = surface_shortest_edge / object_longest_edge; let scaling = surface_shortest_edge / object_longest_edge;
let padding_x = (width - orWdt * scaling) * 0.5; let padding_x = (width - orWdt * scaling) * 0.5;
let padding_y = (height - orHgt * scaling) * 0.5; let padding_y = (height - orHgt * scaling) * 0.5;
cr.translate(padding_x, padding_y); cr.translate(padding_x, padding_y);
try { try {
cr.scale(scaling, scaling); cr.scale(scaling, scaling);
this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor); this._drawingObject.draw(cr, this._customStatus, this._primaryColor, this._secundaryColor);
cr.restore(); cr.restore();
} catch (e) { } catch (e) {
// ignore // ignore
} }
} }
}); });

View File

@ -35,284 +35,284 @@ class TeaTimePrefsWidget extends Gtk.Grid {
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 labelFN = new Gtk.Label({ let labelFN = new Gtk.Label({
label: _("Fullscreen Notifications"), label: _("Fullscreen Notifications"),
hexpand: true, hexpand: true,
halign: Gtk.Align.START halign: Gtk.Align.START
}); });
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.fullscreenNotificationSwitch = new Gtk.Switch(); this.fullscreenNotificationSwitch = new Gtk.Switch();
this.fullscreenNotificationSwitch.connect("notify::active", this._saveFullscreenNotifications.bind(this)); this.fullscreenNotificationSwitch.connect("notify::active", this._saveFullscreenNotifications.bind(this));
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.alarmSoundFile = new Gtk.FileChooserButton({ this.alarmSoundFile = new Gtk.FileChooserButton({
title: _("Select alarm sound file"), title: _("Select alarm sound file"),
action: Gtk.FileChooserAction.OPEN action: Gtk.FileChooserAction.OPEN
}); });
this.alarmSoundFileFilter = new Gtk.FileFilter(); this.alarmSoundFileFilter = new Gtk.FileFilter();
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter); this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
this.alarmSoundFileFilter.add_mime_type("audio/*"); this.alarmSoundFileFilter.add_mime_type("audio/*");
this.alarmSoundFile.connect("selection_changed", this._saveSoundFile.bind(this)); this.alarmSoundFile.connect("selection_changed", this._saveSoundFile.bind(this));
if (!Utils.isGnome34()) { if (!Utils.isGnome34()) {
// Full screen notifications currently not working on GNOME 3.4, thus don't show the switch // Full screen notifications currently not working on GNOME 3.4, thus don't show the switch
this.attach(labelFN, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ ); this.attach(labelFN, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.fullscreenNotificationSwitch, 2, curRow, 1, 1); this.attach(this.fullscreenNotificationSwitch, 2, curRow, 1, 1);
curRow += 1;
}
this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.graphicalCountdownSwitch, 2, curRow, 1, 1);
curRow += 1; curRow += 1;
}
this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ ); this.attach(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
this.attach(this.alarmSoundFile, 1, curRow, 1, 1); this.attach(this.graphicalCountdownSwitch, 2, curRow, 1, 1);
this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1); curRow += 1;
curRow += 1;
this.treeview = new Gtk.TreeView({ this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
model: this._tealist, this.attach(this.alarmSoundFile, 1, curRow, 1, 1);
expand: true this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1);
}); curRow += 1;
this.treeview.set_reorderable(true);
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
this.attach(this.treeview, 0, curRow, 3, 1);
curRow += 1;
let teaname = new Gtk.TreeViewColumn({ this.treeview = new Gtk.TreeView({
title: _("Tea"), model: this._tealist,
expand: true expand: true
}); });
let renderer = new Gtk.CellRendererText({ this.treeview.set_reorderable(true);
editable: true this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
}); this.attach(this.treeview, 0, curRow, 3, 1);
// When the renderer is done editing it's value, we first write curRow += 1;
// the new value to the view's model, i.e. this._tealist.
// This makes life a little harder due to chaining of callbacks
// and the need for this._inhibitUpdate, but it feels a lot cleaner
// when the UI does not know about the config storage backend.
renderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
}.bind(this));
teaname.pack_start(renderer, true);
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
this.treeview.append_column(teaname);
let steeptime = new Gtk.TreeViewColumn({ let teaname = new Gtk.TreeViewColumn({
title: _("Steep time"), title: _("Tea"),
min_width: 150 expand: true
}); });
let spinrenderer = new Gtk.CellRendererSpin({ let renderer = new Gtk.CellRendererText({
editable: true editable: true
}); });
// See comment above. // When the renderer is done editing it's value, we first write
spinrenderer.connect("edited", function (renderer, pathString, newValue) { // the new value to the view's model, i.e. this._tealist.
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString)); // This makes life a little harder due to chaining of callbacks
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]); // and the need for this._inhibitUpdate, but it feels a lot cleaner
}.bind(this)); // when the UI does not know about the config storage backend.
renderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.TEA_NAME], [newValue]);
}.bind(this));
teaname.pack_start(renderer, true);
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
this.treeview.append_column(teaname);
steeptime.pack_start(spinrenderer, true); let steeptime = new Gtk.TreeViewColumn({
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT); title: _("Steep time"),
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME); min_width: 150
this.treeview.append_column(steeptime); });
let spinrenderer = new Gtk.CellRendererSpin({
editable: true
});
// See comment above.
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
}.bind(this));
steeptime.pack_start(spinrenderer, true);
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
this.treeview.append_column(steeptime);
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 = new Gtk.ToolButton({ this.addButton = new Gtk.ToolButton({
icon_name: "list-add-symbolic", icon_name: "list-add-symbolic",
use_action_appearance: false use_action_appearance: false
}); });
this.addButton.connect("clicked", this._addTea.bind(this)); this.addButton.connect("clicked", this._addTea.bind(this));
this.toolbar.insert(this.addButton, -1); this.toolbar.insert(this.addButton, -1);
this.removeButton = new Gtk.ToolButton({ this.removeButton = new Gtk.ToolButton({
icon_name: "list-remove-symbolic", icon_name: "list-remove-symbolic",
use_action_appearance: false use_action_appearance: false
}); });
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this)); this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
this.toolbar.insert(this.removeButton, -1); this.toolbar.insert(this.removeButton, -1);
} }
_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.fullscreenNotificationSwitch.active = this._settings.get_boolean(this.config_keys.fullscreen_notification) this.fullscreenNotificationSwitch.active = this._settings.get_boolean(this.config_keys.fullscreen_notification)
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();
let file_name = this._settings.get_string(this.config_keys.alarm_sound); let file_name = this._settings.get_string(this.config_keys.alarm_sound);
this.alarmSoundFile.set_uri(file_name); this.alarmSoundFile.set_uri(file_name);
// 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: 1 value: time
}); });
let item = this._tealist.append(); this._tealist.set(this._tealist.append(), [Columns.TEA_NAME, Columns.STEEP_TIME, Columns.ADJUSTMENT], [teaname, time, adj]);
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), this._inhibitUpdate = false;
true); }
_addTea() {
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() { _removeSelectedTea() {
let [selection, store] = this.treeview.get_selection().get_selected_rows(); let [selection, store] = this.treeview.get_selection().get_selected_rows();
let iters = []; let iters = [];
for (let i = 0; i < selection.length; ++i) { for (let i = 0; i < selection.length; ++i) {
let [isSet, iter] = store.get_iter(selection[i]); let [isSet, iter] = store.get_iter(selection[i]);
if (isSet) { if (isSet) {
iters.push(iter); iters.push(iter);
}
} }
// it's ok not to inhibit updates here as remove != change }
iters.forEach(function (value, index, array) { // it's ok not to inhibit updates here as remove != change
store.remove(value) iters.forEach(function (value, index, array) {
}); store.remove(value)
});
this.treeview.get_selection().unselect_all(); this.treeview.get_selection().unselect_all();
} }
_saveFullscreenNotifications(sw, data) { _saveFullscreenNotifications(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._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.fullscreen_notification, this._settings.set_boolean(this.config_keys.fullscreen_notification,
sw.active); sw.active);
this._inhibitUpdate = false; this._inhibitUpdate = false;
} }
_saveGraphicalCountdown(sw, data) { _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._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.graphical_countdown, this._settings.set_boolean(this.config_keys.graphical_countdown,
sw.active); sw.active);
this._inhibitUpdate = false; this._inhibitUpdate = false;
} }
_saveUseAlarm(sw, data) { _saveUseAlarm(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._inhibitUpdate = true;
this._settings.set_boolean(this.config_keys.use_alarm_sound, this._settings.set_boolean(this.config_keys.use_alarm_sound,
sw.active); sw.active);
this._inhibitUpdate = false; this._inhibitUpdate = false;
} }
_saveSoundFile(sw, data) { _saveSoundFile(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;
let alarm_sound = this.alarmSoundFile.get_uri(); let alarm_sound = this.alarmSoundFile.get_uri();
Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound); Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound);
let have_value = Utils.isType(alarm_sound, "string"); let have_value = Utils.isType(alarm_sound, "string");
let setting_is_different = let setting_is_different =
this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound; this._settings.get_string(this.config_keys.alarm_sound) != alarm_sound;
if (have_value && setting_is_different) { if (have_value && setting_is_different) {
this._inhibitUpdate = true; this._inhibitUpdate = true;
Utils.playSound(alarm_sound); Utils.playSound(alarm_sound);
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound); this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
this._inhibitUpdate = false; this._inhibitUpdate = false;
} }
} }
_save(store, path_, iter_) { _save(store, path_, iter_) {
const GLib = imports.gi.GLib; const GLib = imports.gi.GLib;
// 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;
let values = []; let values = [];
this._tealist.foreach(function (store, path, iter) { this._tealist.foreach(function (store, path, iter) {
values.push(GLib.Variant.new_dict_entry( values.push(GLib.Variant.new_dict_entry(
GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)), GLib.Variant.new_string(store.get_value(iter, Columns.TEA_NAME)),
GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME)))) GLib.Variant.new_uint32(store.get_value(iter, Columns.STEEP_TIME))))
}); });
let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values); let settingsValue = GLib.Variant.new_array(GLib.VariantType.new("{su}"), values);
// all changes have happened through the UI, we can safely // all changes have happened through the UI, we can safely
// disable updating it here to avoid an infinite loop // disable updating it here to avoid an infinite loop
this._inhibitUpdate = true; this._inhibitUpdate = true;
this._settings.set_value(this.config_keys.steep_times, settingsValue); this._settings.set_value(this.config_keys.steep_times, settingsValue);
this._inhibitUpdate = false; this._inhibitUpdate = false;
} }
}); });