mirror of
https://github.com/oleid/gnome-shell-teatime.git
synced 2022-04-29 18:53:50 +00:00
combatiblity for gnome-shell 3.32 (maybe break for earlier versions)
This commit is contained in:
parent
e5a5e61398
commit
e94ef7f5bc
481
src/extension.js
481
src/extension.js
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
const Gio = imports.gi.Gio;
|
const Gio = imports.gi.Gio;
|
||||||
const Lang = imports.lang;
|
|
||||||
const Mainloop = imports.mainloop; // timer
|
const Mainloop = imports.mainloop; // timer
|
||||||
const Shell = imports.gi.Shell;
|
const Shell = imports.gi.Shell;
|
||||||
const St = imports.gi.St;
|
const St = imports.gi.St;
|
||||||
@ -29,10 +28,8 @@ const N_ = function (e) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
const TeaTimeFullscreenNotification = new Lang.Class({
|
class TeaTimeFullscreenNotification {
|
||||||
Name: 'TeaTimeFullscreenNotification',
|
constructor() {
|
||||||
|
|
||||||
_init: function () {
|
|
||||||
// this spans the whole monitor and contains
|
// this spans the whole monitor and contains
|
||||||
// the actual layout, which it displays in
|
// the actual layout, which it displays in
|
||||||
// the center of itself
|
// the center of itself
|
||||||
@ -80,7 +77,7 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
|||||||
reactive: true,
|
reactive: true,
|
||||||
keep_aspect_ratio: true
|
keep_aspect_ratio: true
|
||||||
});
|
});
|
||||||
this._texture.connect("button-release-event", Lang.bind(this, this.hide));
|
this._texture.connect("button-release-event", this.hide.bind(this));
|
||||||
this._layout.add_child(this._texture);
|
this._layout.add_child(this._texture);
|
||||||
|
|
||||||
this._timeline = new Clutter.Timeline({
|
this._timeline = new Clutter.Timeline({
|
||||||
@ -88,7 +85,7 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
|||||||
repeat_count: -1,
|
repeat_count: -1,
|
||||||
progress_mode: Clutter.AnimationMode.LINEAR
|
progress_mode: Clutter.AnimationMode.LINEAR
|
||||||
});
|
});
|
||||||
this._timeline.connect("new-frame", Lang.bind(this, this._newFrame));
|
this._timeline.connect("new-frame", this._newFrame.bind(this));
|
||||||
|
|
||||||
this._label = new St.Label({
|
this._label = new St.Label({
|
||||||
text: _("Your tea is ready!"),
|
text: _("Your tea is ready!"),
|
||||||
@ -98,19 +95,19 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
|||||||
|
|
||||||
this._lightbox = new imports.ui.lightbox.Lightbox(Main.uiGroup); // Seems not to work on Gnome 3.10 { fadeInTime: 0.5, fadeOutTime: 0.5 }
|
this._lightbox = new imports.ui.lightbox.Lightbox(Main.uiGroup); // Seems not to work on Gnome 3.10 { fadeInTime: 0.5, fadeOutTime: 0.5 }
|
||||||
this._lightbox.highlight(this._bin);
|
this._lightbox.highlight(this._bin);
|
||||||
},
|
}
|
||||||
destroy: function () {
|
destroy() {
|
||||||
this.hide();
|
this.hide();
|
||||||
Main.popModal(this._bin);
|
Main.popModal(this._bin);
|
||||||
this._bin.destroy();
|
this._bin.destroy();
|
||||||
this._lightbox.hide();
|
this._lightbox.hide();
|
||||||
},
|
}
|
||||||
_newFrame: function (timeline, msecs, user) {
|
_newFrame(timeline, msecs, user) {
|
||||||
let progress = timeline.get_progress();
|
let progress = timeline.get_progress();
|
||||||
let idx = Math.round(progress * this._textureFiles.length) % this._textureFiles.length;
|
let idx = Math.round(progress * this._textureFiles.length) % this._textureFiles.length;
|
||||||
this._texture.set_from_file(this._textureFiles[idx]);
|
this._texture.set_from_file(this._textureFiles[idx]);
|
||||||
},
|
}
|
||||||
show: function () {
|
show() {
|
||||||
if (typeof Layout.MonitorConstraint != 'undefined') {
|
if (typeof Layout.MonitorConstraint != 'undefined') {
|
||||||
this._monitorConstraint.index = global.screen.get_current_monitor()
|
this._monitorConstraint.index = global.screen.get_current_monitor()
|
||||||
}
|
}
|
||||||
@ -118,22 +115,19 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
|||||||
this._timeline.start();
|
this._timeline.start();
|
||||||
this._lightbox.show();
|
this._lightbox.show();
|
||||||
this._bin.show_all();
|
this._bin.show_all();
|
||||||
},
|
}
|
||||||
hide: function () {
|
hide() {
|
||||||
Main.popModal(this._bin);
|
Main.popModal(this._bin);
|
||||||
this._bin.hide();
|
this._bin.hide();
|
||||||
this._lightbox.hide();
|
this._lightbox.hide();
|
||||||
this._timeline.stop();
|
this._timeline.stop();
|
||||||
}
|
}
|
||||||
})
|
};
|
||||||
|
|
||||||
|
|
||||||
const PopupTeaMenuItem = new Lang.Class({
|
class PopupTeaMenuItem extends PopupMenu.PopupBaseMenuItem {
|
||||||
Name: 'PopupTeaMenuItem',
|
constructor(sTeaname, nBrewtime, params) {
|
||||||
Extends: PopupMenu.PopupBaseMenuItem,
|
super(params);
|
||||||
|
|
||||||
_init: function (sTeaname, nBrewtime, params) {
|
|
||||||
this.parent(params);
|
|
||||||
|
|
||||||
this.tealabel = new St.Label({
|
this.tealabel = new St.Label({
|
||||||
text: sTeaname
|
text: sTeaname
|
||||||
@ -163,259 +157,270 @@ const PopupTeaMenuItem = new Lang.Class({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
|
||||||
|
var TeaTime = class extends PanelMenu.Button {
|
||||||
|
|
||||||
const TeaTime = new Lang.Class({
|
constructor() {
|
||||||
Name: 'TeaTime',
|
super(null, "TeaTime");
|
||||||
Extends: PanelMenu.Button,
|
|
||||||
|
|
||||||
_init: function () {
|
this.myinit = function () {
|
||||||
this.parent(null, "TeaTime");
|
|
||||||
|
|
||||||
this._settings = Utils.getSettings();
|
this._settings = Utils.getSettings();
|
||||||
|
|
||||||
this._logo = new Icon.TwoColorIcon(24, Icon.TeaPot);
|
this._logo = new Icon.TwoColorIcon(24, 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(24, Icon.Pie);
|
this._graphicalTimer = new Icon.TwoColorIcon(24, 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', Lang.bind(this, this._onStyleChanged));
|
this.actor.connect('style-changed', this._onStyleChanged.bind(this));
|
||||||
|
|
||||||
this._idleTimeout = null;
|
this._idleTimeout = null;
|
||||||
|
|
||||||
this._createMenu();
|
this._createMenu();
|
||||||
},
|
};
|
||||||
_createMenu: function () {
|
|
||||||
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
|
||||||
this._settings.connect("changed::" + this.config_keys.steep_times,
|
|
||||||
Lang.bind(this, this._updateTeaList));
|
|
||||||
this._settings.connect("changed::" + this.config_keys.graphical_countdown,
|
|
||||||
Lang.bind(this, this._updateCountdownType));
|
|
||||||
|
|
||||||
this.teaItemCont = new PopupMenu.PopupMenuSection();
|
this._createMenu = function () {
|
||||||
|
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();
|
||||||
// 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', Lang.bind(this, this._showPreferences));
|
|
||||||
head.addMenuItem(item);
|
|
||||||
|
|
||||||
/*******************/
|
/*******************/
|
||||||
let bottom = new PopupMenu.PopupMenuSection();
|
// maybe one day the PopupImageMenuItem works^^
|
||||||
this._customEntry = new St.Entry({
|
let head = new PopupMenu.PopupMenuSection();
|
||||||
style_class: 'teatime-custom-entry',
|
let item = new PopupMenu.PopupMenuItem(_("Show settings")); //, 'gtk-preferences');
|
||||||
track_hover: true,
|
// item._icon.icon_size = 15;
|
||||||
hint_text: _("min:sec")
|
item.connect('activate', this._showPreferences.bind(this));
|
||||||
});
|
head.addMenuItem(item);
|
||||||
this._customEntry.get_clutter_text().set_max_length(10);
|
|
||||||
this._customEntry.get_clutter_text().connect("key-press-event", Lang.bind(this, this._createCustomTimer));
|
|
||||||
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._updateTeaList();
|
this.menu.addMenuItem(head);
|
||||||
},
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
_updateTeaList: function (config, output) {
|
this.menu.addMenuItem(this.teaItemCont);
|
||||||
// make sure the menu is empty
|
this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem());
|
||||||
this.teaItemCont.removeAll();
|
this.menu.addMenuItem(bottom);
|
||||||
|
|
||||||
// fill with new teas
|
this._updateTeaList();
|
||||||
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
};
|
||||||
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
|
this._updateTeaList = function (config, output) {
|
||||||
menuItem.connect('activate', Lang.bind(this, function () {
|
// make sure the menu is empty
|
||||||
this._stopCountdown();
|
this.teaItemCont.removeAll();
|
||||||
}));
|
|
||||||
this.teaItemCont.addMenuItem(menuItem);
|
|
||||||
for (let teaname in list) {
|
|
||||||
let time = list[teaname].get_uint32();
|
|
||||||
|
|
||||||
let menuItem = new PopupTeaMenuItem(_(teaname), time);
|
// fill with new teas
|
||||||
menuItem.connect('activate', Lang.bind(this, function () {
|
let list = this._settings.get_value(this.config_keys.steep_times).unpack();
|
||||||
this._initCountdown(time);
|
let menuItem = new PopupTeaMenuItem("Stop Timer", 0);
|
||||||
}));
|
menuItem.connect('activate', function () {
|
||||||
|
this._stopCountdown();
|
||||||
|
}.bind(this));
|
||||||
this.teaItemCont.addMenuItem(menuItem);
|
this.teaItemCont.addMenuItem(menuItem);
|
||||||
}
|
for (let teaname in list) {
|
||||||
},
|
let time = list[teaname].get_uint32();
|
||||||
_updateCountdownType: function (config, output) {
|
|
||||||
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
|
||||||
|
|
||||||
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
|
let menuItem = new PopupTeaMenuItem(_(teaname), time);
|
||||||
if (this._idleTimeout != null) {
|
menuItem.connect('activate', function () {
|
||||||
// we have a running countdown, replace the display
|
this._initCountdown(time);
|
||||||
this.actor.remove_actor(this._bGraphicalCountdown ?
|
}.bind(this));
|
||||||
this._graphicalTimer : this._textualTimer);
|
this.teaItemCont.addMenuItem(menuItem);
|
||||||
this._bGraphicalCountdown = bWantGraphicalCountdown;
|
|
||||||
this.actor.add_actor(this._bGraphicalCountdown ?
|
|
||||||
this._graphicalTimer : this._textualTimer);
|
|
||||||
|
|
||||||
this._updateTimerDisplay(this._getRemainingSec());
|
|
||||||
} // if timeout active
|
|
||||||
} // value changed
|
|
||||||
},
|
|
||||||
_createCustomTimer: function (text, event) {
|
|
||||||
if (event.get_key_symbol() == Clutter.KEY_Enter ||
|
|
||||||
event.get_key_symbol() == Clutter.KEY_Return) {
|
|
||||||
|
|
||||||
let customTime = text.get_text();
|
|
||||||
let seconds = 0;
|
|
||||||
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
|
|
||||||
if (match) {
|
|
||||||
let factor = 1;
|
|
||||||
for (var i = match.length - 2; i > 0; i--) {
|
|
||||||
let s = match[i].replace(/^0/, ''); // fix for elder GNOME <= 3.10 which don't like leading zeros
|
|
||||||
seconds += factor * parseInt(s);
|
|
||||||
factor *= 60;
|
|
||||||
}
|
|
||||||
if (seconds > 0) {
|
|
||||||
this._initCountdown(seconds);
|
|
||||||
this.menu.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this._customEntry.set_text("");
|
};
|
||||||
}
|
this._updateCountdownType = function (config, output) {
|
||||||
},
|
let bWantGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
||||||
_showNotification: function (subject, text) {
|
|
||||||
let source = (Utils.isGnome34()) ?
|
|
||||||
new MessageTray.Source(_("TeaTime applet")) :
|
|
||||||
new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
|
||||||
|
|
||||||
if (Utils.isGnome34()) {
|
if (bWantGraphicalCountdown != this._bGraphicalCountdown) {
|
||||||
source.createNotificationIcon =
|
if (this._idleTimeout != null) {
|
||||||
function () {
|
// we have a running countdown, replace the display
|
||||||
let iconBox = new St.Bin();
|
this.actor.remove_actor(this._bGraphicalCountdown ?
|
||||||
iconBox._size = this.ICON_SIZE;
|
this._graphicalTimer : this._textualTimer);
|
||||||
iconBox.child = new St.Icon({
|
this._bGraphicalCountdown = bWantGraphicalCountdown;
|
||||||
icon_name: 'utilities-teatime',
|
this.actor.add_actor(this._bGraphicalCountdown ?
|
||||||
icon_type: St.IconType.FULLCOLOR,
|
this._graphicalTimer : this._textualTimer);
|
||||||
icon_size: iconBox._size
|
|
||||||
});
|
|
||||||
return iconBox;
|
|
||||||
} // createNotificationIcon
|
|
||||||
}
|
|
||||||
|
|
||||||
Main.messageTray.add(source);
|
this._updateTimerDisplay(this._getRemainingSec());
|
||||||
|
} // if timeout active
|
||||||
|
} // value changed
|
||||||
|
};
|
||||||
|
this._createCustomTimer = function (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 notification = new MessageTray.Notification(source, subject, text);
|
let customTime = text.get_text();
|
||||||
notification.setTransient(true);
|
let seconds = 0;
|
||||||
source.notify(notification);
|
let match = customTime.match(/^(?:(\d+)(?::(\d{0,2}))?|:(\d+))$/)
|
||||||
},
|
if (match) {
|
||||||
_initCountdown: function (time) {
|
let factor = 1;
|
||||||
this._startTime = new Date();
|
if (match[3] === undefined) { // minutes and seconds?
|
||||||
this._stopTime = new Date();
|
for (var i = match.length - 2; i > 0; i--) {
|
||||||
this._cntdownStart = time;
|
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("");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._showNotification = function (subject, text) {
|
||||||
|
let source = (Utils.isGnome34()) ?
|
||||||
|
new MessageTray.Source(_("TeaTime applet")) :
|
||||||
|
new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
||||||
|
|
||||||
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
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
|
||||||
|
}
|
||||||
|
|
||||||
let dt = this._bGraphicalCountdown ?
|
Main.messageTray.add(source);
|
||||||
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
|
let notification = new MessageTray.Notification(source, subject, text);
|
||||||
|
notification.setTransient(true);
|
||||||
|
source.notify(notification);
|
||||||
|
};
|
||||||
|
this._initCountdown = function (time) {
|
||||||
|
this._startTime = new Date();
|
||||||
|
this._stopTime = new Date();
|
||||||
|
this._cntdownStart = time;
|
||||||
|
|
||||||
this.actor.remove_actor(this._logo); // show timer instead of default icon
|
this._bGraphicalCountdown = this._settings.get_boolean(this.config_keys.graphical_countdown);
|
||||||
|
|
||||||
this._updateTimerDisplay(time);
|
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.actor.add_actor(this._bGraphicalCountdown ?
|
this._stopTime.setTime(this._startTime.getTime() + time * 1000); // in msec
|
||||||
this._graphicalTimer : this._textualTimer);
|
|
||||||
|
|
||||||
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
this.actor.remove_actor(this._logo); // show timer instead of default icon
|
||||||
this._idleTimeout = Mainloop.timeout_add_seconds(dt, Lang.bind(this, this._doCountdown));
|
|
||||||
},
|
|
||||||
_stopCountdown: function () {
|
|
||||||
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: function () {
|
|
||||||
let a = new Date();
|
|
||||||
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
|
|
||||||
},
|
|
||||||
_updateTimerDisplay: function (remainingTime) {
|
|
||||||
if (this._bGraphicalCountdown) {
|
|
||||||
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
|
|
||||||
} else {
|
|
||||||
this._textualTimer.text = Utils.formatTime(remainingTime);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_doCountdown: function () {
|
|
||||||
let remainingTime = this._getRemainingSec();
|
|
||||||
|
|
||||||
if (remainingTime <= 0) {
|
this._updateTimerDisplay(time);
|
||||||
// count down finished, switch display again
|
|
||||||
this._stopCountdown();
|
|
||||||
this._playSound();
|
|
||||||
|
|
||||||
if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) {
|
this.actor.add_actor(this._bGraphicalCountdown ?
|
||||||
this.dialog = new TeaTimeFullscreenNotification();
|
this._graphicalTimer : this._textualTimer);
|
||||||
this.dialog.show();
|
|
||||||
|
if (this._idleTimeout != null) Mainloop.source_remove(this._idleTimeout);
|
||||||
|
this._idleTimeout = Mainloop.timeout_add_seconds(dt, this._doCountdown.bind(this));
|
||||||
|
};
|
||||||
|
this._stopCountdown = function () {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
this._getRemainingSec = function () {
|
||||||
|
let a = new Date();
|
||||||
|
return (this._stopTime.getTime() - a.getTime()) * 1e-3;
|
||||||
|
};
|
||||||
|
this._updateTimerDisplay = function (remainingTime) {
|
||||||
|
if (this._bGraphicalCountdown) {
|
||||||
|
this._graphicalTimer.setStatus((this._cntdownStart - remainingTime) / this._cntdownStart);
|
||||||
} else {
|
} else {
|
||||||
this._showNotification(_("Your tea is ready!"),
|
this._textualTimer.text = Utils.formatTime(remainingTime);
|
||||||
_("Drink it, while it is hot!"));
|
|
||||||
}
|
}
|
||||||
return false;
|
};
|
||||||
} else {
|
this._doCountdown = function () {
|
||||||
this._updateTimerDisplay(remainingTime);
|
let remainingTime = this._getRemainingSec();
|
||||||
return true; // continue timer
|
|
||||||
}
|
|
||||||
},
|
|
||||||
_playSound: function () {
|
|
||||||
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: function () {
|
|
||||||
imports.misc.util.spawn(["gnome-shell-extension-prefs", ExtensionUtils.getCurrentExtension().metadata['uuid']]);
|
|
||||||
return 0;
|
|
||||||
},
|
|
||||||
_onStyleChanged: function (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;
|
if (remainingTime <= 0) {
|
||||||
this._secondaryColor = new Clutter.Color({
|
// count down finished, switch display again
|
||||||
red: color.red,
|
this._stopCountdown();
|
||||||
green: color.green,
|
this._playSound();
|
||||||
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);
|
if (!Utils.isGnome34() && this._settings.get_boolean(this.config_keys.fullscreen_notification)) {
|
||||||
this._graphicalTimer.setColor(this._primaryColor, this._secondaryColor);
|
this.dialog = new TeaTimeFullscreenNotification();
|
||||||
|
this.dialog.show();
|
||||||
|
} else {
|
||||||
|
this._showNotification(_("Your tea is ready!"),
|
||||||
|
_("Drink it, while it is hot!"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this._updateTimerDisplay(remainingTime);
|
||||||
|
return true; // continue timer
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._playSound = function () {
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._showPreferences = function () {
|
||||||
|
const currExt = ExtensionUtils.getCurrentExtension();
|
||||||
|
imports.misc.util.spawn(["gnome-shell-extension-prefs", currExt.metadata['uuid']]);
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
this._onStyleChanged = function (actor) {
|
||||||
|
let themeNode = actor.get_theme_node();
|
||||||
|
let color = themeNode.get_foreground_color()
|
||||||
|
let [bHasPadding, padding] = themeNode.lookup_length("-natural-hpadding", false);
|
||||||
|
|
||||||
// forward (possible) scaling style change to child
|
this._primaryColor = color;
|
||||||
let scaling = Utils.getGlobalDisplayScaleFactor();
|
this._secondaryColor = new Clutter.Color({
|
||||||
this._logo.setScaling(scaling);
|
red: color.red,
|
||||||
this._graphicalTimer.setScaling(scaling);
|
green: color.green,
|
||||||
},
|
blue: color.blue,
|
||||||
config_keys: Utils.GetConfigKeys()
|
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);
|
||||||
|
};
|
||||||
|
this.config_keys = Utils.GetConfigKeys();
|
||||||
|
this.myinit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
function init(metadata) {
|
function init(metadata) {
|
||||||
let theme = imports.gi.Gtk.IconTheme.get_default();
|
let theme = imports.gi.Gtk.IconTheme.get_default();
|
||||||
|
122
src/icon.js
122
src/icon.js
@ -10,86 +10,90 @@
|
|||||||
* If there is a better way for that stuff, please let me know ;)
|
* If there is a better way for that stuff, please let me know ;)
|
||||||
********************************************************************/
|
********************************************************************/
|
||||||
|
|
||||||
const Lang = imports.lang;
|
|
||||||
const St = imports.gi.St;
|
const St = imports.gi.St;
|
||||||
const Clutter = imports.gi.Clutter;
|
const Clutter = imports.gi.Clutter;
|
||||||
const ExUt = imports.misc.extensionUtils;
|
const ExUt = imports.misc.extensionUtils;
|
||||||
const Me = ExUt.getCurrentExtension();
|
const Me = ExUt.getCurrentExtension();
|
||||||
const Utils = Me.imports.utils;
|
const Utils = Me.imports.utils;
|
||||||
|
|
||||||
var TwoColorIcon = new Lang.Class({
|
var TwoColorIcon = class extends St.DrawingArea {
|
||||||
Name: 'TwoColorIcon',
|
constructor(size, drawingObject) {
|
||||||
Extends: St.DrawingArea,
|
super({
|
||||||
|
|
||||||
_init: function (size, drawingObject) {
|
|
||||||
this.parent({
|
|
||||||
reactive: true,
|
reactive: true,
|
||||||
style: 'padding: 0px 2px'
|
style: 'padding: 0px 2px'
|
||||||
});
|
});
|
||||||
this._base_size = size;
|
this.myinit = function () {
|
||||||
this.setScaling(Utils.getGlobalDisplayScaleFactor());
|
this._base_size = size;
|
||||||
|
//this.setScaling(Utils.getGlobalDisplayScaleFactor());
|
||||||
|
|
||||||
this._drawingObject = drawingObject;
|
this._drawingObject = drawingObject;
|
||||||
|
|
||||||
this.connect('repaint', Lang.bind(this, this._drawIcon));
|
this.connect('repaint', function () {
|
||||||
|
this._drawIcon();
|
||||||
|
}.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: function (padding) {
|
this.setPadding = function (padding) {
|
||||||
this.margin_left = padding;
|
this.margin_left = padding;
|
||||||
this.margin_right = padding;
|
this.margin_right = padding;
|
||||||
},
|
};
|
||||||
setColor: function (primary, secundary) {
|
this.setColor = function (primary, secundary) {
|
||||||
this._primaryColor = primary;
|
this._primaryColor = primary;
|
||||||
this._secundaryColor = secundary;
|
this._secundaryColor = secundary;
|
||||||
this.queue_repaint();
|
this.queue_repaint();
|
||||||
},
|
};
|
||||||
setScaling: function (newScale) {
|
this.setScaling = function (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: function (newStatus) {
|
this.setStatus = function (newStatus) {
|
||||||
this._customStatus = newStatus;
|
this._customStatus = newStatus;
|
||||||
this.queue_repaint();
|
this.queue_repaint();
|
||||||
},
|
};
|
||||||
_drawIcon: function () {
|
this._drawIcon = function () {
|
||||||
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);
|
||||||
cr.scale(scaling, scaling);
|
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();
|
cr.restore();
|
||||||
|
} catch (e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.myinit();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
});
|
|
||||||
|
|
||||||
var TeaPot = {
|
var TeaPot = {
|
||||||
width: 484,
|
width: 484,
|
||||||
height: 295,
|
height: 295,
|
||||||
draw: function (cr, stat, primary, secundary) {
|
draw(cr, stat, primary, secundary) {
|
||||||
// draw TeaPot
|
// draw TeaPot
|
||||||
// cairo commands generated from svg2cairo
|
// cairo commands generated from svg2cairo
|
||||||
// https://github.com/akrinke/svg2cairo
|
// https://github.com/akrinke/svg2cairo
|
||||||
@ -133,7 +137,7 @@ var TeaPot = {
|
|||||||
var Pie = {
|
var Pie = {
|
||||||
width: 1,
|
width: 1,
|
||||||
height: 1,
|
height: 1,
|
||||||
draw: function (cr, stat, primary, secundary) {
|
draw(cr, stat, primary, secundary) {
|
||||||
const pi = Math.PI;
|
const pi = Math.PI;
|
||||||
const r = 0.5;
|
const r = 0.5;
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
{"shell-version": ["3.4", "3.6", "3.8", "3.10", "3.12", "3.14", "3.16", "3.18", "3.20", "3.22", "3.24", "3.26"], "uuid": "TeaTime@oleid.mescharet.de", "name": "TeaTime", "settings-schema": "org.gnome.shell.extensions.teatime", "gettext-domain": "TeaTime", "description": "A tea steeping timer"}
|
{"shell-version": ["3.32"], "uuid": "TeaTime@oleid.mescharet.de", "name": "TeaTime", "settings-schema": "org.gnome.shell.extensions.teatime", "gettext-domain": "TeaTime", "description": "A tea steeping timer"}
|
||||||
|
487
src/prefs.js
487
src/prefs.js
@ -3,7 +3,6 @@
|
|||||||
Thomas Liebetraut <thomas@tommie-lie.de>
|
Thomas Liebetraut <thomas@tommie-lie.de>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Lang = imports.lang;
|
|
||||||
const Gtk = imports.gi.Gtk;
|
const Gtk = imports.gi.Gtk;
|
||||||
const GObject = imports.gi.GObject;
|
const GObject = imports.gi.GObject;
|
||||||
|
|
||||||
@ -23,12 +22,9 @@ const Columns = {
|
|||||||
ADJUSTMENT: 2
|
ADJUSTMENT: 2
|
||||||
}
|
}
|
||||||
|
|
||||||
const TeaTimePrefsWidget = new Lang.Class({
|
var TeaTimePrefsWidget = class extends Gtk.Grid {
|
||||||
Name: 'TeaTimePrefsWidget',
|
constructor() {
|
||||||
Extends: Gtk.Grid,
|
super({
|
||||||
|
|
||||||
_init: function () {
|
|
||||||
this.parent({
|
|
||||||
orientation: Gtk.Orientation.VERTICAL,
|
orientation: Gtk.Orientation.VERTICAL,
|
||||||
column_homogeneous: false,
|
column_homogeneous: false,
|
||||||
vexpand: true,
|
vexpand: true,
|
||||||
@ -36,278 +32,281 @@ const TeaTimePrefsWidget = new Lang.Class({
|
|||||||
row_spacing: 5
|
row_spacing: 5
|
||||||
});
|
});
|
||||||
|
|
||||||
this._tealist = new Gtk.ListStore();
|
this.myinit = function () {
|
||||||
this._tealist.set_column_types([
|
this._tealist = new Gtk.ListStore();
|
||||||
GObject.TYPE_STRING,
|
this._tealist.set_column_types([
|
||||||
GObject.TYPE_INT,
|
GObject.TYPE_STRING,
|
||||||
Gtk.Adjustment
|
GObject.TYPE_INT,
|
||||||
]);
|
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", Lang.bind(this, this._refresh));
|
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", Lang.bind(this, this._save));
|
this._tealist.connect("row-changed", this._save.bind(this));
|
||||||
this._tealist.connect("row-deleted", Lang.bind(this, this._save));
|
this._tealist.connect("row-deleted", this._save.bind(this));
|
||||||
},
|
};
|
||||||
_initWindow: function () {
|
this._initWindow = function () {
|
||||||
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", Lang.bind(this, this._saveFullscreenNotifications));
|
this.fullscreenNotificationSwitch.connect("notify::active", this._saveFullscreenNotifications.bind(this));
|
||||||
|
|
||||||
this.graphicalCountdownSwitch = new Gtk.Switch();
|
this.graphicalCountdownSwitch = new Gtk.Switch();
|
||||||
this.graphicalCountdownSwitch.connect("notify::active", Lang.bind(this, this._saveGraphicalCountdown));
|
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", Lang.bind(this, this._saveUseAlarm));
|
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", Lang.bind(this, this._saveSoundFile));
|
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(labelGC, 0 /*col*/ , curRow /*row*/ , 2 /*col span*/ , 1 /*row span*/ );
|
this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
|
||||||
this.attach(this.graphicalCountdownSwitch, 2, curRow, 1, 1);
|
this.attach(this.alarmSoundFile, 1, curRow, 1, 1);
|
||||||
curRow += 1;
|
this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1);
|
||||||
|
curRow += 1;
|
||||||
|
|
||||||
this.attach(labelAS, 0 /*col*/ , curRow /*row*/ , 1 /*col span*/ , 1 /*row span*/ );
|
this.treeview = new Gtk.TreeView({
|
||||||
this.attach(this.alarmSoundFile, 1, curRow, 1, 1);
|
model: this._tealist,
|
||||||
this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1);
|
expand: true
|
||||||
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;
|
||||||
|
|
||||||
this.treeview = new Gtk.TreeView({
|
let teaname = new Gtk.TreeViewColumn({
|
||||||
model: this._tealist,
|
title: _("Tea"),
|
||||||
expand: true
|
expand: true
|
||||||
});
|
});
|
||||||
this.treeview.set_reorderable(true);
|
let renderer = new Gtk.CellRendererText({
|
||||||
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
|
editable: true
|
||||||
this.attach(this.treeview, 0, curRow, 3, 1);
|
});
|
||||||
curRow += 1;
|
// 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);
|
||||||
|
|
||||||
let teaname = new Gtk.TreeViewColumn({
|
let steeptime = new Gtk.TreeViewColumn({
|
||||||
title: _("Tea"),
|
title: _("Steep time"),
|
||||||
expand: true
|
min_width: 150
|
||||||
});
|
});
|
||||||
let renderer = new Gtk.CellRendererText({
|
let spinrenderer = new Gtk.CellRendererSpin({
|
||||||
editable: true
|
editable: true
|
||||||
});
|
});
|
||||||
// When the renderer is done editing it's value, we first write
|
// See comment above.
|
||||||
// the new value to the view's model, i.e. this._tealist.
|
spinrenderer.connect("edited", function (renderer, pathString, newValue) {
|
||||||
// This makes life a little harder due to chaining of callbacks
|
let [store, iter] = this._tealist.get_iter(Gtk.TreePath.new_from_string(pathString));
|
||||||
// and the need for this._inhibitUpdate, but it feels a lot cleaner
|
this._tealist.set(iter, [Columns.STEEP_TIME], [parseInt(newValue)]);
|
||||||
// when the UI does not know about the config storage backend.
|
}.bind(this));
|
||||||
renderer.connect("edited", Lang.bind(this, 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]);
|
|
||||||
}));
|
|
||||||
teaname.pack_start(renderer, true);
|
|
||||||
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
|
|
||||||
this.treeview.append_column(teaname);
|
|
||||||
|
|
||||||
let steeptime = new Gtk.TreeViewColumn({
|
steeptime.pack_start(spinrenderer, true);
|
||||||
title: _("Steep time"),
|
steeptime.add_attribute(spinrenderer, "adjustment", Columns.ADJUSTMENT);
|
||||||
min_width: 150
|
steeptime.add_attribute(spinrenderer, "text", Columns.STEEP_TIME);
|
||||||
});
|
this.treeview.append_column(steeptime);
|
||||||
let spinrenderer = new Gtk.CellRendererSpin({
|
|
||||||
editable: true
|
|
||||||
});
|
|
||||||
// See comment above.
|
|
||||||
spinrenderer.connect("edited", Lang.bind(this, 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)]);
|
|
||||||
}));
|
|
||||||
|
|
||||||
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", Lang.bind(this, this._addTea));
|
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", Lang.bind(this, this._removeSelectedTea));
|
this.removeButton.connect("clicked", this._removeSelectedTea.bind(this));
|
||||||
this.toolbar.insert(this.removeButton, -1);
|
this.toolbar.insert(this.removeButton, -1);
|
||||||
},
|
};
|
||||||
_refresh: function () {
|
this._refresh = function () {
|
||||||
// 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;
|
||||||
|
};
|
||||||
|
this._addTea = function () {
|
||||||
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._inhibitUpdate = false;
|
this.treeview.get_column(Columns.TEA_NAME),
|
||||||
},
|
true);
|
||||||
_addTea: function () {
|
};
|
||||||
let adj = new Gtk.Adjustment({
|
this._removeSelectedTea = function () {
|
||||||
lower: 1,
|
let [selection, store] = this.treeview.get_selection().get_selected_rows();
|
||||||
step_increment: 1,
|
let iters = [];
|
||||||
upper: 65535,
|
for (let i = 0; i < selection.length; ++i) {
|
||||||
value: 1
|
let [isSet, iter] = store.get_iter(selection[i]);
|
||||||
});
|
if (isSet) {
|
||||||
let item = this._tealist.append();
|
iters.push(iter);
|
||||||
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: function () {
|
|
||||||
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
|
||||||
// it's ok not to inhibit updates here as remove != change
|
iters.forEach(function (value, index, array) {
|
||||||
iters.forEach(function (value, index, array) {
|
store.remove(value)
|
||||||
store.remove(value)
|
});
|
||||||
});
|
|
||||||
|
|
||||||
this.treeview.get_selection().unselect_all();
|
this.treeview.get_selection().unselect_all();
|
||||||
},
|
};
|
||||||
_saveFullscreenNotifications: function (sw, data) {
|
this._saveFullscreenNotifications = function (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: function (sw, data) {
|
this._saveGraphicalCountdown = function (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: function (sw, data) {
|
this._saveUseAlarm = function (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: function (sw, data) {
|
this._saveSoundFile = function (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;
|
||||||
|
|
||||||
|
Utils.playSound(alarm_sound);
|
||||||
|
this._settings.set_string(this.config_keys.alarm_sound, alarm_sound);
|
||||||
|
this._inhibitUpdate = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this._save = function (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._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.config_keys = Utils.GetConfigKeys();
|
||||||
_save: function (store, path_, iter_) {
|
this.myinit();
|
||||||
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;
|
|
||||||
},
|
|
||||||
config_keys: Utils.GetConfigKeys()
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
function init() {}
|
function init() {}
|
||||||
|
@ -116,7 +116,6 @@ function formatTime(sec_num) {
|
|||||||
|
|
||||||
function playSound(uri) {
|
function playSound(uri) {
|
||||||
const Gst = imports.gi.Gst;
|
const Gst = imports.gi.Gst;
|
||||||
const Lang = imports.lang;
|
|
||||||
|
|
||||||
debug("Playing " + uri);
|
debug("Playing " + uri);
|
||||||
|
|
||||||
@ -125,7 +124,7 @@ function playSound(uri) {
|
|||||||
this.player = Gst.ElementFactory.make("playbin", "player");
|
this.player = Gst.ElementFactory.make("playbin", "player");
|
||||||
this.playBus = this.player.get_bus();
|
this.playBus = this.player.get_bus();
|
||||||
this.playBus.add_signal_watch();
|
this.playBus.add_signal_watch();
|
||||||
this.playBus.connect("message", Lang.bind(this,
|
this.playBus.connect("message",
|
||||||
function (playBus, message) {
|
function (playBus, message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
// IMPORTANT: to reuse the player, set state to READY
|
// IMPORTANT: to reuse the player, set state to READY
|
||||||
@ -134,7 +133,7 @@ function playSound(uri) {
|
|||||||
this.player.set_state(Gst.State.READY);
|
this.player.set_state(Gst.State.READY);
|
||||||
}
|
}
|
||||||
} // message handler
|
} // message handler
|
||||||
}));
|
}.bind(this));
|
||||||
} // if undefined
|
} // if undefined
|
||||||
this.player.set_property('uri', uri);
|
this.player.set_property('uri', uri);
|
||||||
this.player.set_state(Gst.State.PLAYING);
|
this.player.set_state(Gst.State.PLAYING);
|
||||||
|
Loading…
Reference in New Issue
Block a user