diff --git a/src/extension.js b/src/extension.js index 5ca3e60..489027e 100644 --- a/src/extension.js +++ b/src/extension.js @@ -173,268 +173,268 @@ class TeaTime extends PanelMenu.Button { 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 - this._textualTimer = new St.Label({ - text: "", - x_align: Clutter.ActorAlign.END, - y_align: Clutter.ActorAlign.CENTER - }); - this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie); + // set timer widget + this._textualTimer = new St.Label({ + text: "", + x_align: Clutter.ActorAlign.END, + y_align: Clutter.ActorAlign.CENTER + }); + this._graphicalTimer = new Icon.TwoColorIcon(20, Icon.Pie); - this.actor.add_actor(this._logo); - this.actor.add_style_class_name('panel-status-button'); - this.actor.connect('style-changed', this._onStyleChanged.bind(this)); + this.actor.add_actor(this._logo); + this.actor.add_style_class_name('panel-status-button'); + this.actor.connect('style-changed', this._onStyleChanged.bind(this)); - this._idleTimeout = null; + this._idleTimeout = null; - this._createMenu(); + this._createMenu(); } _createMenu() { - this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); - this._settings.connect("changed::" + this.config_keys.steep_times, - this._updateTeaList.bind(this)); - this._settings.connect("changed::" + this.config_keys.graphical_countdown, - this._updateCountdownType.bind(this)); + this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); + this._settings.connect("changed::" + this.config_keys.steep_times, + this._updateTeaList.bind(this)); + this._settings.connect("changed::" + this.config_keys.graphical_countdown, + this._updateCountdownType.bind(this)); - this.teaItemCont = new PopupMenu.PopupMenuSection(); + this.teaItemCont = new PopupMenu.PopupMenuSection(); - /*******************/ - // maybe one day the PopupImageMenuItem works^^ - let head = new PopupMenu.PopupMenuSection(); - let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences'); - // item._icon.icon_size = 15; - item.connect('activate', this._showPreferences.bind(this)); - head.addMenuItem(item); + /*******************/ + // maybe one day the PopupImageMenuItem works^^ + let head = new PopupMenu.PopupMenuSection(); + let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences'); + // item._icon.icon_size = 15; + item.connect('activate', this._showPreferences.bind(this)); + head.addMenuItem(item); - /*******************/ - let bottom = new PopupMenu.PopupMenuSection(); - this._customEntry = new St.Entry({ - style_class: 'teatime-custom-entry', - track_hover: true, - hint_text: _("min:sec") - }); - this._customEntry.get_clutter_text().set_max_length(10); - this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this)); - bottom.box.add(this._customEntry); - bottom.actor.set_style("padding: 0px 18px;") + /*******************/ + let bottom = new PopupMenu.PopupMenuSection(); + this._customEntry = new St.Entry({ + style_class: 'teatime-custom-entry', + track_hover: true, + hint_text: _("min:sec") + }); + this._customEntry.get_clutter_text().set_max_length(10); + this._customEntry.get_clutter_text().connect("key-press-event", this._createCustomTimer.bind(this)); + bottom.box.add(this._customEntry); + bottom.actor.set_style("padding: 0px 18px;") - /*******************/ + /*******************/ - this.menu.addMenuItem(head); - this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); - this.menu.addMenuItem(this.teaItemCont); - this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); - this.menu.addMenuItem(bottom); + this.menu.addMenuItem(head); + this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); + this.menu.addMenuItem(this.teaItemCont); + this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); + this.menu.addMenuItem(bottom); - this._updateTeaList(); + this._updateTeaList(); } _updateTeaList(config, output) { - // make sure the menu is empty - this.teaItemCont.removeAll(); + // make sure the menu is empty + this.teaItemCont.removeAll(); - // fill with new teas - let list = this._settings.get_value(this.config_keys.steep_times).unpack(); - let menuItem = new PopupTeaMenuItem("Stop Timer", 0); + // fill with new teas + let list = this._settings.get_value(this.config_keys.steep_times).unpack(); + 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 () { - this._stopCountdown(); + this._initCountdown(time); }.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 () { - this._initCountdown(time); - }.bind(this)); - this.teaItemCont.addMenuItem(menuItem); - } + } } _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 (this._idleTimeout != null) { - // we have a running countdown, replace the display - this.actor.remove_actor(this._bGraphicalCountdown ? - this._graphicalTimer : this._textualTimer); - this._bGraphicalCountdown = bWantGraphicalCountdown; - this.actor.add_actor(this._bGraphicalCountdown ? - this._graphicalTimer : this._textualTimer); + if (bWantGraphicalCountdown != this._bGraphicalCountdown) { + if (this._idleTimeout != null) { + // we have a running countdown, replace the display + this.actor.remove_actor(this._bGraphicalCountdown ? + this._graphicalTimer : this._textualTimer); + this._bGraphicalCountdown = bWantGraphicalCountdown; + this.actor.add_actor(this._bGraphicalCountdown ? + this._graphicalTimer : this._textualTimer); - this._updateTimerDisplay(this._getRemainingSec()); - } // if timeout active - } // value changed + 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) { + 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; + 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); } - } else { // only seconds? - let s = match[3].replace(/^0/, ''); - seconds = parseInt(s); - } - if (seconds > 0) { - this._initCountdown(seconds); - this.menu.close(); + 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(""); } + this._customEntry.set_text(""); + } } _showNotification(subject, text) { - let source = (Utils.isGnome34()) ? - new MessageTray.Source(_("TeaTime applet")) : - new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime'); + let source = (Utils.isGnome34()) ? + new MessageTray.Source(_("TeaTime applet")) : + new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime'); - if (Utils.isGnome34()) { - source.createNotificationIcon = - function () { - let iconBox = new St.Bin(); - iconBox._size = this.ICON_SIZE; - iconBox.child = new St.Icon({ - icon_name: 'utilities-teatime', - icon_type: St.IconType.FULLCOLOR, - icon_size: iconBox._size - }); - return iconBox; - } // createNotificationIcon - } + if (Utils.isGnome34()) { + source.createNotificationIcon = + function () { + let iconBox = new St.Bin(); + iconBox._size = this.ICON_SIZE; + iconBox.child = new St.Icon({ + icon_name: 'utilities-teatime', + icon_type: St.IconType.FULLCOLOR, + icon_size: iconBox._size + }); + return iconBox; + } // createNotificationIcon + } - Main.messageTray.add(source); + Main.messageTray.add(source); - let notification = new MessageTray.Notification(source, subject, text); - notification.setTransient(true); - source.notify(notification); + let notification = new MessageTray.Notification(source, subject, text); + notification.setTransient(true); + source.notify(notification); } _initCountdown(time) { - this._startTime = new Date(); - this._stopTime = new Date(); - this._cntdownStart = time; + this._startTime = new Date(); + this._stopTime = new Date(); + 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 ? - Math.max(1.0, time / 90) // set time step to fit animation - : - 1.0; // show every second for the textual 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._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._graphicalTimer : this._textualTimer); + this.actor.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)); + if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); + this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this)); } _stopCountdown() { - if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); - this.actor.remove_actor(this._bGraphicalCountdown ? - this._graphicalTimer : this._textualTimer); - this.actor.add_actor(this._logo); - this._idleTimeout = null; + if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout); + this.actor.remove_actor(this._bGraphicalCountdown ? + this._graphicalTimer : this._textualTimer); + this.actor.add_actor(this._logo); + this._idleTimeout = null; } _getRemainingSec() { - let a = new Date(); - return (this._stopTime.getTime() - a.getTime()) * 1e-3; + 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); - } + if (this._bGraphicalCountdown) { + this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart); + } else { + this._textualTimer.text = Utils.formatTime(remainingTime); + } } _doCountdown() { - let remainingTime = this._getRemainingSec(); + let remainingTime = this._getRemainingSec(); - if (remainingTime <= 0) { - // count down finished, switch display again - this._stopCountdown(); - this._playSound(); + if (remainingTime <= 0) { + // count down finished, switch display again + this._stopCountdown(); + this._playSound(); - if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) { - this.dialog = new TeaTimeFullscreenNotification(); - this.dialog.show(); - } else { - this._showNotification(_("Your tea is ready!"), - _("Drink it, while it is hot!")); - } - return false; + if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) { + this.dialog = new TeaTimeFullscreenNotification(); + this.dialog.show(); } else { - this._updateTimerDisplay(remainingTime); - return true; // continue timer + this._showNotification(_("Your tea is ready!"), + _("Drink it, while it is hot!")); } + return false; + } else { + this._updateTimerDisplay(remainingTime); + return true; // continue timer + } } _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)); - } + 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; + 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); + 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._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); + 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); + // forward (possible) scaling style change to child + let scaling = Utils.getGlobalDisplayScaleFactor(); + this._logo.setScaling(scaling); + this._graphicalTimer.setScaling(scaling); } }); diff --git a/src/icon.js b/src/icon.js index 3706ca8..0a4a403 100644 --- a/src/icon.js +++ b/src/icon.js @@ -24,73 +24,73 @@ class TwoColorIcon extends St.DrawingArea { reactive: true, style: 'padding: 0px 0px' }); - this._base_size = size; - //this.setScaling(Utils.getGlobalDisplayScaleFactor()); + this._base_size = size; + //this.setScaling(Utils.getGlobalDisplayScaleFactor()); - this._drawingObject = drawingObject; + this._drawingObject = drawingObject; - this.connect('repaint', function () { - this._drawIcon(); - }.bind(this)); + this.connect('repaint', function () { + this._drawIcon(); + }.bind(this)); - // some fallback color - this._primaryColor = new Clutter.Color({ - red: 150, - green: 150, - blue: 150, - alpha: 255 - }); - this._secundaryColor = this._primaryColor; - this._customStatus = null; + // some fallback color + this._primaryColor = new Clutter.Color({ + red: 150, + green: 150, + blue: 150, + alpha: 255 + }); + this._secundaryColor = this._primaryColor; + this._customStatus = null; } setPadding(padding) { - this.margin_left = padding; - this.margin_right = padding; + this.margin_left = padding; + this.margin_right = padding; } setColor(primary, secundary) { - this._primaryColor = primary; - this._secundaryColor = secundary; - this.queue_repaint(); + 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(); + 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(); + 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(); + let cr = this.get_context(); + let orWdt = this._drawingObject.width; + let orHgt = this._drawingObject.height; + let [width, height] = this.get_surface_size(); - cr.save(); + 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; + 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); + cr.translate(padding_x, padding_y); + try { + 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(); - } catch (e) { - // ignore - } + cr.restore(); + } catch (e) { + // ignore + } } }); diff --git a/src/prefs.js b/src/prefs.js index cccab95..23044e1 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -35,284 +35,284 @@ class TeaTimePrefsWidget extends Gtk.Grid { this.config_keys = Utils.GetConfigKeys(); - this._tealist = new Gtk.ListStore(); - this._tealist.set_column_types([ - GObject.TYPE_STRING, - GObject.TYPE_INT, - Gtk.Adjustment - ]); + this._tealist = new Gtk.ListStore(); + this._tealist.set_column_types([ + GObject.TYPE_STRING, + GObject.TYPE_INT, + Gtk.Adjustment + ]); - this.set_column_spacing(3); + this.set_column_spacing(3); - this._settings = Utils.getSettings(); - this._inhibitUpdate = true; - this._settings.connect("changed", this._refresh.bind(this)); + this._settings = Utils.getSettings(); + this._inhibitUpdate = true; + this._settings.connect("changed", this._refresh.bind(this)); - this._initWindow(); - this._inhibitUpdate = false; - this._refresh(); - this._tealist.connect("row-changed", this._save.bind(this)); - this._tealist.connect("row-deleted", this._save.bind(this)); + this._initWindow(); + this._inhibitUpdate = false; + this._refresh(); + this._tealist.connect("row-changed", this._save.bind(this)); + this._tealist.connect("row-deleted", this._save.bind(this)); } _initWindow() { - let curRow = 0; - let labelFN = new Gtk.Label({ - label: _("Fullscreen Notifications"), - hexpand: true, - halign: Gtk.Align.START - }); - let labelGC = new Gtk.Label({ - label: _("Graphical Countdown"), - hexpand: true, - halign: Gtk.Align.START - }); + let curRow = 0; + let labelFN = new Gtk.Label({ + label: _("Fullscreen Notifications"), + hexpand: true, + halign: Gtk.Align.START + }); + let labelGC = new Gtk.Label({ + label: _("Graphical Countdown"), + hexpand: true, + halign: Gtk.Align.START + }); - let labelAS = new Gtk.Label({ - label: _("Alarm sound"), - hexpand: true, - halign: Gtk.Align.START - }); + let labelAS = new Gtk.Label({ + label: _("Alarm sound"), + hexpand: true, + halign: Gtk.Align.START + }); - this.fullscreenNotificationSwitch = new Gtk.Switch(); - this.fullscreenNotificationSwitch.connect("notify::active", this._saveFullscreenNotifications.bind(this)); + this.fullscreenNotificationSwitch = new Gtk.Switch(); + this.fullscreenNotificationSwitch.connect("notify::active", this._saveFullscreenNotifications.bind(this)); - this.graphicalCountdownSwitch = new Gtk.Switch(); - this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this)); + this.graphicalCountdownSwitch = new Gtk.Switch(); + this.graphicalCountdownSwitch.connect("notify::active", this._saveGraphicalCountdown.bind(this)); - // alarm sound file chooser - this.alarmSoundSwitch = new Gtk.Switch(); - this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this)); + // alarm sound file chooser + this.alarmSoundSwitch = new Gtk.Switch(); + this.alarmSoundSwitch.connect("notify::active", this._saveUseAlarm.bind(this)); - this.alarmSoundFile = new Gtk.FileChooserButton({ - title: _("Select alarm sound file"), - action: Gtk.FileChooserAction.OPEN - }); - this.alarmSoundFileFilter = new Gtk.FileFilter(); - this.alarmSoundFile.set_filter(this.alarmSoundFileFilter); - this.alarmSoundFileFilter.add_mime_type("audio/*"); - this.alarmSoundFile.connect("selection_changed", this._saveSoundFile.bind(this)); + this.alarmSoundFile = new Gtk.FileChooserButton({ + title: _("Select alarm sound file"), + action: Gtk.FileChooserAction.OPEN + }); + this.alarmSoundFileFilter = new Gtk.FileFilter(); + this.alarmSoundFile.set_filter(this.alarmSoundFileFilter); + this.alarmSoundFileFilter.add_mime_type("audio/*"); + this.alarmSoundFile.connect("selection_changed", this._saveSoundFile.bind(this)); - if (!Utils.isGnome34()) { - // 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(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); + if (!Utils.isGnome34()) { + // 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(this.fullscreenNotificationSwitch, 2, curRow, 1, 1); curRow += 1; + } - this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ ); - this.attach(this.alarmSoundFile, 1, curRow, 1, 1); - this.attach(this.alarmSoundSwitch, 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; - this.treeview = new Gtk.TreeView({ - model: this._tealist, - expand: true - }); - this.treeview.set_reorderable(true); - this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE); - this.attach(this.treeview, 0, curRow, 3, 1); - curRow += 1; + this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ ); + this.attach(this.alarmSoundFile, 1, curRow, 1, 1); + this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1); + curRow += 1; - let teaname = new Gtk.TreeViewColumn({ - title: _("Tea"), - expand: true - }); - let renderer = new Gtk.CellRendererText({ - editable: true - }); - // When the renderer is done editing it's value, we first write - // 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); + this.treeview = new Gtk.TreeView({ + model: this._tealist, + expand: true + }); + 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 steeptime = new Gtk.TreeViewColumn({ - title: _("Steep time"), - min_width: 150 - }); - 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)); + let teaname = new Gtk.TreeViewColumn({ + title: _("Tea"), + expand: true + }); + let renderer = new Gtk.CellRendererText({ + editable: true + }); + // When the renderer is done editing it's value, we first write + // 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); - 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); + let steeptime = new Gtk.TreeViewColumn({ + title: _("Steep time"), + min_width: 150 + }); + 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({ - icon_size: 1 - }); - this.toolbar.get_style_context().add_class("inline-toolbar"); - this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ ); - this.addButton = new Gtk.ToolButton({ - icon_name: "list-add-symbolic", - use_action_appearance: false - }); - this.addButton.connect("clicked", this._addTea.bind(this)); - this.toolbar.insert(this.addButton, -1); - this.removeButton = new Gtk.ToolButton({ - icon_name: "list-remove-symbolic", - use_action_appearance: false - }); - this.removeButton.connect("clicked", this._removeSelectedTea.bind(this)); - this.toolbar.insert(this.removeButton, -1); + this.toolbar = new Gtk.Toolbar({ + icon_size: 1 + }); + this.toolbar.get_style_context().add_class("inline-toolbar"); + this.attach(this.toolbar, 0 /*col*/ , curRow /*row*/ , 3 /*col span*/ , 1 /*row span*/ ); + this.addButton = new Gtk.ToolButton({ + icon_name: "list-add-symbolic", + use_action_appearance: false + }); + this.addButton.connect("clicked", this._addTea.bind(this)); + this.toolbar.insert(this.addButton, -1); + this.removeButton = new Gtk.ToolButton({ + icon_name: "list-remove-symbolic", + use_action_appearance: false + }); + this.removeButton.connect("clicked", this._removeSelectedTea.bind(this)); + this.toolbar.insert(this.removeButton, -1); } _refresh() { - // don't update the model if someone else is messing with the backend - if (this._inhibitUpdate) - return; + // don't update the model if someone else is messing with the backend + if (this._inhibitUpdate) + 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.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 file_name = this._settings.get_string(this.config_keys.alarm_sound); - this.alarmSoundFile.set_uri(file_name); + 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) + let list = this._settings.get_value(this.config_keys.steep_times).unpack(); + let file_name = this._settings.get_string(this.config_keys.alarm_sound); + this.alarmSoundFile.set_uri(file_name); - // stop everyone from reacting to the changes we are about to produce - // in the model - this._inhibitUpdate = true; + // stop everyone from reacting to the changes we are about to produce + // in the model + this._inhibitUpdate = true; - this._tealist.clear(); - for (let teaname in list) { - let time = list[teaname].get_uint32(); + this._tealist.clear(); + for (let teaname in list) { + 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({ lower: 1, step_increment: 1, upper: 65535, - value: 1 + value: time }); - 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._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({ + 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() { - 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); - } + 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) - }); + } + // 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(); + this.treeview.get_selection().unselect_all(); } _saveFullscreenNotifications(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.fullscreen_notification, - sw.active); - this._inhibitUpdate = false; + // 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.fullscreen_notification, + sw.active); + this._inhibitUpdate = false; } _saveGraphicalCountdown(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.graphical_countdown, - sw.active); - this._inhibitUpdate = false; + // 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.graphical_countdown, + 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; + // 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, data) { - // don't update the backend if someone else is messing with the model - if (this._inhibitUpdate) - return; - let alarm_sound = this.alarmSoundFile.get_uri(); - Utils.debug(this._settings.get_string(this.config_keys.alarm_sound) + "-->" + alarm_sound); + // don't update the backend if someone else is messing with the model + if (this._inhibitUpdate) + return; + let alarm_sound = this.alarmSoundFile.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; + 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; - } + Utils.playSound(alarm_sound); + this._settings.set_string(this.config_keys.alarm_sound, alarm_sound); + this._inhibitUpdate = false; + } } _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 - if (this._inhibitUpdate) - return; + // 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); + 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; + // 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._settings.set_value(this.config_keys.steep_times, settingsValue); - this._inhibitUpdate = false; + this._inhibitUpdate = false; } });