mirror of
https://github.com/oleid/gnome-shell-teatime.git
synced 2022-04-29 18:53:50 +00:00
js-beautified source code
This commit is contained in:
parent
b99cf2f204
commit
2d2fc839fa
100
src/extension.js
100
src/extension.js
@ -31,7 +31,9 @@ const bUseGnome34Workarounds = imports.misc.extensionUtils.versionCheck( ["3.4"]
|
||||
Utils.initTranslations();
|
||||
|
||||
const _ = Gettext.gettext;
|
||||
const N_ = function(e) { return e; };
|
||||
const N_ = function (e) {
|
||||
return e;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -43,7 +45,10 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
||||
// the actual layout, which it displays in
|
||||
// the center of itself
|
||||
|
||||
this._bin = new St.Bin({ x_align: St.Align.MIDDLE, y_align: St.Align.MIDDLE});
|
||||
this._bin = new St.Bin({
|
||||
x_align: St.Align.MIDDLE,
|
||||
y_align: St.Align.MIDDLE
|
||||
});
|
||||
|
||||
if (typeof Layout.MonitorConstraint != 'undefined') {
|
||||
// MonitorConstraint was introduced in gnome-3.6
|
||||
@ -54,7 +59,10 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
||||
|
||||
// a table imitating a vertical box layout to hold the texture and
|
||||
// a label underneath it
|
||||
this._layout = new St.BoxLayout({ vertical: true, y_align: Clutter.ActorAlign.CENTER });
|
||||
this._layout = new St.BoxLayout({
|
||||
vertical: true,
|
||||
y_align: Clutter.ActorAlign.CENTER
|
||||
});
|
||||
this._bin.set_child(this._layout);
|
||||
|
||||
// find all the textures
|
||||
@ -76,14 +84,24 @@ const TeaTimeFullscreenNotification = new Lang.Class({
|
||||
}
|
||||
this._textureFiles.sort();
|
||||
|
||||
this._texture = new Clutter.Texture({ reactive: true, keep_aspect_ratio: true });
|
||||
this._texture = new Clutter.Texture({
|
||||
reactive: true,
|
||||
keep_aspect_ratio: true
|
||||
});
|
||||
this._texture.connect("button-release-event", Lang.bind(this, this.hide));
|
||||
this._layout.add_child(this._texture);
|
||||
|
||||
this._timeline = new Clutter.Timeline({ duration: 2000, repeat_count: -1, progress_mode: Clutter.AnimationMode.LINEAR });
|
||||
this._timeline = new Clutter.Timeline({
|
||||
duration: 2000,
|
||||
repeat_count: -1,
|
||||
progress_mode: Clutter.AnimationMode.LINEAR
|
||||
});
|
||||
this._timeline.connect("new-frame", Lang.bind(this, this._newFrame));
|
||||
|
||||
this._label = new St.Label({ text: _("Your tea is ready!"), style_class: "dash-label" });
|
||||
this._label = new St.Label({
|
||||
text: _("Your tea is ready!"),
|
||||
style_class: "dash-label"
|
||||
});
|
||||
this._layout.add_child(this._label);
|
||||
|
||||
this._lightbox = new imports.ui.lightbox.Lightbox(Main.uiGroup); // Seems not to work on Gnome 3.10 { fadeInTime: 0.5, fadeOutTime: 0.5 }
|
||||
@ -125,16 +143,26 @@ const PopupTeaMenuItem = new Lang.Class({
|
||||
_init: function (sTeaname, nBrewtime, params) {
|
||||
this.parent(params);
|
||||
|
||||
this.tealabel = new St.Label({ text: sTeaname });
|
||||
this.timelabel = new St.Label({ text: Utils.formatTime(nBrewtime) });
|
||||
this.tealabel = new St.Label({
|
||||
text: sTeaname
|
||||
});
|
||||
this.timelabel = new St.Label({
|
||||
text: Utils.formatTime(nBrewtime)
|
||||
});
|
||||
|
||||
if (this.actor instanceof St.BoxLayout) {
|
||||
// will be used for gnome-shell 3.10 and possibly above where this.actor is BoxLayout
|
||||
this.actor.add(this.tealabel, { expand: true });
|
||||
this.actor.add(this.tealabel, {
|
||||
expand: true
|
||||
});
|
||||
this.actor.add(this.timelabel);
|
||||
} else {
|
||||
this.addActor(this.tealabel, {expand: true });
|
||||
this.addActor(this.timelabel, {expand: false });
|
||||
this.addActor(this.tealabel, {
|
||||
expand: true
|
||||
});
|
||||
this.addActor(this.timelabel, {
|
||||
expand: false
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -152,9 +180,11 @@ const TeaTime = new Lang.Class({
|
||||
this._logo = new Icon.TwoColorIcon(24, Icon.TeaPot);
|
||||
|
||||
// set timer widget
|
||||
this._textualTimer = new St.Label({ text: "",
|
||||
this._textualTimer = new St.Label({
|
||||
text: "",
|
||||
x_align: Clutter.ActorAlign.END,
|
||||
y_align: Clutter.ActorAlign.CENTER });
|
||||
y_align: Clutter.ActorAlign.CENTER
|
||||
});
|
||||
this._graphicalTimer = new Icon.TwoColorIcon(24, Icon.Pie);
|
||||
|
||||
this.actor.add_actor(this._logo);
|
||||
@ -184,9 +214,11 @@ const TeaTime = new Lang.Class({
|
||||
|
||||
/*******************/
|
||||
let bottom = new PopupMenu.PopupMenuSection();
|
||||
this._customEntry = new St.Entry({ style_class: 'teatime-custom-entry',
|
||||
this._customEntry = new St.Entry({
|
||||
style_class: 'teatime-custom-entry',
|
||||
track_hover: true,
|
||||
hint_text: _("min:sec") });
|
||||
hint_text: _("min:sec")
|
||||
});
|
||||
this._customEntry.get_clutter_text().set_max_length(10);
|
||||
this._customEntry.get_clutter_text().connect("key-press-event", Lang.bind(this, this._createCustomTimer));
|
||||
bottom.box.add(this._customEntry);
|
||||
@ -224,11 +256,11 @@ const TeaTime = new Lang.Class({
|
||||
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.actor.remove_actor(this._bGraphicalCountdown ?
|
||||
this._graphicalTimer : this._textualTimer);
|
||||
this._bGraphicalCountdown = bWantGraphicalCountdown;
|
||||
this.actor.add_actor( this._bGraphicalCountdown
|
||||
? this._graphicalTimer : this._textualTimer);
|
||||
this.actor.add_actor(this._bGraphicalCountdown ?
|
||||
this._graphicalTimer : this._textualTimer);
|
||||
|
||||
this._updateTimerDisplay(this._getRemainingSec());
|
||||
} // if timeout active
|
||||
@ -257,17 +289,20 @@ const TeaTime = new Lang.Class({
|
||||
}
|
||||
},
|
||||
_showNotification: function (subject, text) {
|
||||
let source = ( bUseGnome34Workarounds )
|
||||
? new MessageTray.Source(_("TeaTime applet"))
|
||||
: new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
||||
let source = (bUseGnome34Workarounds) ?
|
||||
new MessageTray.Source(_("TeaTime applet")) :
|
||||
new MessageTray.Source(_("TeaTime applet"), 'utilities-teatime');
|
||||
|
||||
if (bUseGnome34Workarounds) { source.createNotificationIcon =
|
||||
if (bUseGnome34Workarounds) {
|
||||
source.createNotificationIcon =
|
||||
function () {
|
||||
let iconBox = new St.Bin();
|
||||
iconBox._size = this.ICON_SIZE;
|
||||
iconBox.child = new St.Icon({ icon_name: 'utilities-teatime',
|
||||
iconBox.child = new St.Icon({
|
||||
icon_name: 'utilities-teatime',
|
||||
icon_type: St.IconType.FULLCOLOR,
|
||||
icon_size: iconBox._size });
|
||||
icon_size: iconBox._size
|
||||
});
|
||||
return iconBox;
|
||||
} // createNotificationIcon
|
||||
}
|
||||
@ -285,9 +320,10 @@ const TeaTime = new Lang.Class({
|
||||
|
||||
this._bGraphicalCountdown = this._settings.get_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY);
|
||||
|
||||
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
|
||||
|
||||
@ -295,8 +331,8 @@ const TeaTime = new Lang.Class({
|
||||
|
||||
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, Lang.bind(this, this._doCountdown));
|
||||
@ -317,8 +353,8 @@ const TeaTime = new Lang.Class({
|
||||
|
||||
if (remainingTime <= 0) {
|
||||
// count down finished, switch display again
|
||||
this.actor.remove_actor( this._bGraphicalCountdown
|
||||
? this._graphicalTimer : this._textualTimer);
|
||||
this.actor.remove_actor(this._bGraphicalCountdown ?
|
||||
this._graphicalTimer : this._textualTimer);
|
||||
this.actor.add_actor(this._logo);
|
||||
this._playSound();
|
||||
|
||||
|
@ -22,7 +22,10 @@ const TwoColorIcon = new Lang.Class({
|
||||
Extends: St.DrawingArea,
|
||||
|
||||
_init: function (size, drawingObject) {
|
||||
this.parent({ reactive : true, style: 'padding: 0px 2px' });
|
||||
this.parent({
|
||||
reactive: true,
|
||||
style: 'padding: 0px 2px'
|
||||
});
|
||||
this.set_width(size);
|
||||
this.set_height(size);
|
||||
this._drawingObject = drawingObject;
|
||||
@ -134,8 +137,8 @@ const Pie = {
|
||||
|
||||
Utils.setCairoColorFromClutter(cr, secundary);
|
||||
cr.moveTo(0, 0);
|
||||
cr.arc(0, 0, r, 3 / 2 * pi + 2 * pi * stat, 3 / 2 * pi + 2
|
||||
* pi);
|
||||
cr.arc(0, 0, r, 3 / 2 * pi + 2 * pi * stat, 3 / 2 * pi + 2 *
|
||||
pi);
|
||||
cr.fill();
|
||||
|
||||
Utils.setCairoColorFromClutter(cr, primary);
|
||||
|
98
src/prefs.js
98
src/prefs.js
@ -23,7 +23,9 @@ const bUseGnome34Workarounds = imports.misc.extensionUtils.versionCheck( ["3.4"]
|
||||
Utils.initTranslations();
|
||||
|
||||
const _ = Gettext.gettext;
|
||||
const N_ = function(e) { return e; };
|
||||
const N_ = function (e) {
|
||||
return e;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -38,11 +40,13 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
Extends: Gtk.Grid,
|
||||
|
||||
_init: function () {
|
||||
this.parent({ orientation: Gtk.Orientation.VERTICAL,
|
||||
this.parent({
|
||||
orientation: Gtk.Orientation.VERTICAL,
|
||||
column_homogeneous: false,
|
||||
vexpand: true,
|
||||
margin: 5,
|
||||
row_spacing: 5 });
|
||||
row_spacing: 5
|
||||
});
|
||||
|
||||
this._tealist = new Gtk.ListStore();
|
||||
this._tealist.set_column_types([
|
||||
@ -65,16 +69,22 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
},
|
||||
_initWindow: function () {
|
||||
let curRow = 0;
|
||||
let labelFN = new Gtk.Label({ label: _("Fullscreen Notifications"),
|
||||
let labelFN = new Gtk.Label({
|
||||
label: _("Fullscreen Notifications"),
|
||||
hexpand: true,
|
||||
halign: Gtk.Align.START });
|
||||
let labelGC = new Gtk.Label({ label: _("Graphical Countdown"),
|
||||
halign: Gtk.Align.START
|
||||
});
|
||||
let labelGC = new Gtk.Label({
|
||||
label: _("Graphical Countdown"),
|
||||
hexpand: true,
|
||||
halign: Gtk.Align.START });
|
||||
halign: Gtk.Align.START
|
||||
});
|
||||
|
||||
let labelAS = new Gtk.Label({ label: _("Alarm sound"),
|
||||
let labelAS = new Gtk.Label({
|
||||
label: _("Alarm sound"),
|
||||
hexpand: true,
|
||||
halign: Gtk.Align.START });
|
||||
halign: Gtk.Align.START
|
||||
});
|
||||
|
||||
this.fullscreenNotificationSwitch = new Gtk.Switch();
|
||||
this.fullscreenNotificationSwitch.connect("notify::active", Lang.bind(this, this._saveFullscreenNotifications));
|
||||
@ -89,7 +99,8 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
|
||||
this.alarmSoundFile = new Gtk.FileChooserButton({
|
||||
title: _("Select alarm sound file"),
|
||||
action: Gtk.FileChooserAction.OPEN});
|
||||
action: Gtk.FileChooserAction.OPEN
|
||||
});
|
||||
this.alarmSoundFileFilter = new Gtk.FileFilter();
|
||||
this.alarmSoundFile.set_filter(this.alarmSoundFileFilter);
|
||||
this.alarmSoundFileFilter.add_mime_type("audio/*");
|
||||
@ -112,13 +123,21 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
this.attach(this.alarmSoundSwitch, 2, curRow, 1, 1);
|
||||
curRow += 1;
|
||||
|
||||
this.treeview = new Gtk.TreeView({model: this._tealist, expand: true});
|
||||
this.treeview = new Gtk.TreeView({
|
||||
model: this._tealist,
|
||||
expand: true
|
||||
});
|
||||
this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE);
|
||||
this.attach(this.treeview, 0, curRow, 3, 1);
|
||||
curRow += 1;
|
||||
|
||||
let teaname = new Gtk.TreeViewColumn({ title: _("Tea"), expand: true });
|
||||
let renderer = new Gtk.CellRendererText({ editable: true });
|
||||
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
|
||||
@ -132,8 +151,13 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
teaname.add_attribute(renderer, "text", Columns.TEA_NAME);
|
||||
this.treeview.append_column(teaname);
|
||||
|
||||
let steeptime = new Gtk.TreeViewColumn({ title: _("Steep time"), min_width: 150 });
|
||||
let spinrenderer = new Gtk.CellRendererSpin({ editable: true });
|
||||
let steeptime = new Gtk.TreeViewColumn({
|
||||
title: _("Steep time"),
|
||||
min_width: 150
|
||||
});
|
||||
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));
|
||||
@ -146,13 +170,21 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
this.treeview.append_column(steeptime);
|
||||
|
||||
|
||||
this.toolbar = new Gtk.Toolbar({ icon_size: 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 = new Gtk.ToolButton({
|
||||
icon_name: "list-add-symbolic",
|
||||
use_action_appearance: false
|
||||
});
|
||||
this.addButton.connect("clicked", Lang.bind(this, this._addTea));
|
||||
this.toolbar.insert(this.addButton, -1);
|
||||
this.removeButton = new Gtk.ToolButton({ icon_name: "list-remove-symbolic", use_action_appearance: false });
|
||||
this.removeButton = new Gtk.ToolButton({
|
||||
icon_name: "list-remove-symbolic",
|
||||
use_action_appearance: false
|
||||
});
|
||||
this.removeButton.connect("clicked", Lang.bind(this, this._removeSelectedTea));
|
||||
this.toolbar.insert(this.removeButton, -1);
|
||||
},
|
||||
@ -176,20 +208,26 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
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]);
|
||||
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: function () {
|
||||
let adj = new Gtk.Adjustment({ lower: 1, step_increment: 1, upper: 65535, value: 1 });
|
||||
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._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);
|
||||
@ -205,8 +243,8 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
}
|
||||
// it's ok not to inhibit updates here as remove != change
|
||||
iters.forEach(function (value, index, array) {
|
||||
store.remove(value) }
|
||||
);
|
||||
store.remove(value)
|
||||
});
|
||||
|
||||
this.treeview.get_selection().unselect_all();
|
||||
},
|
||||
@ -275,8 +313,7 @@ const TeaTimePrefsWidget = new Lang.Class({
|
||||
});
|
||||
|
||||
|
||||
function init() {
|
||||
}
|
||||
function init() {}
|
||||
|
||||
function buildPrefsWidget() {
|
||||
let widget = new TeaTimePrefsWidget();
|
||||
@ -284,4 +321,3 @@ function buildPrefsWidget() {
|
||||
widget.show_all();
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
26
src/utils.js
26
src/utils.js
@ -30,9 +30,9 @@ function getExtensionLocaleDir() {
|
||||
// otherwise assume that extension has been installed in the
|
||||
// same prefix as gnome-shell
|
||||
let localLocaleDir = ExtensionUtils.getCurrentExtension().dir.get_child('locale');
|
||||
let selectedDir = (localLocaleDir.query_exists(null))
|
||||
? localLocaleDir.get_path()
|
||||
: Config.LOCALEDIR;
|
||||
let selectedDir = (localLocaleDir.query_exists(null)) ?
|
||||
localLocaleDir.get_path() :
|
||||
Config.LOCALEDIR;
|
||||
|
||||
debug("Using locale dir: " + selectedDir);
|
||||
|
||||
@ -73,10 +73,12 @@ function getSettings(schema) {
|
||||
|
||||
let schemaObj = schemaSource.lookup(schema, true);
|
||||
if (!schemaObj)
|
||||
throw new Error('Schema ' + schema + ' could not be found for extension '
|
||||
+ extension.metadata.uuid + '. Please check your installation.');
|
||||
throw new Error('Schema ' + schema + ' could not be found for extension ' +
|
||||
extension.metadata.uuid + '. Please check your installation.');
|
||||
|
||||
return new Gio.Settings({ settings_schema: schemaObj });
|
||||
return new Gio.Settings({
|
||||
settings_schema: schemaObj
|
||||
});
|
||||
}
|
||||
|
||||
function formatTime(sec_num) {
|
||||
@ -90,9 +92,15 @@ function formatTime(sec_num) {
|
||||
let minutes = Math.floor((sec_num - (hours * 3600)) / 60);
|
||||
let seconds = Math.round(sec_num - (hours * 3600) - (minutes * 60));
|
||||
|
||||
if (hours < 10) {hours = "0"+hours;}
|
||||
if (minutes < 10) {minutes = "0"+minutes;}
|
||||
if (seconds < 10) {seconds = "0"+seconds;}
|
||||
if (hours < 10) {
|
||||
hours = "0" + hours;
|
||||
}
|
||||
if (minutes < 10) {
|
||||
minutes = "0" + minutes;
|
||||
}
|
||||
if (seconds < 10) {
|
||||
seconds = "0" + seconds;
|
||||
}
|
||||
|
||||
return ((hours == "00") ? "" : hours + ':') + minutes + ':' + seconds;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user