2013-05-22 00:33:09 +00:00
|
|
|
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
|
|
|
|
/* Olaf Leidinger <oleid@mescharet.de>
|
|
|
|
Thomas Liebetraut <thomas@tommie-lie.de>
|
|
|
|
*/
|
|
|
|
|
2017-11-03 19:52:04 +00:00
|
|
|
const Gio = imports.gi.Gio;
|
|
|
|
const Lang = imports.lang;
|
2013-05-22 00:33:09 +00:00
|
|
|
const ExtensionUtils = imports.misc.extensionUtils;
|
2017-11-03 19:52:04 +00:00
|
|
|
const Me = ExtensionUtils.getCurrentExtension();
|
|
|
|
const Config = imports.misc.config;
|
|
|
|
const Gst = imports.gi.Gst;
|
2013-05-22 00:33:09 +00:00
|
|
|
|
|
|
|
const TEATIME_STEEP_TIMES_KEY = 'steep-times';
|
2013-11-01 22:58:00 +00:00
|
|
|
const TEATIME_FULLSCREEN_NOTIFICATION_KEY = 'fullscreen-notification';
|
2014-02-18 22:29:48 +00:00
|
|
|
const TEATIME_GRAPHICAL_COUNTDOWN_KEY = 'graphical-countdown';
|
2014-08-03 17:23:19 +00:00
|
|
|
const TEATIME_USE_ALARM_SOUND_KEY = 'use-alarm-sound';
|
|
|
|
const TEATIME_ALARM_SOUND_KEY = 'alarm-sound-file';
|
2013-05-22 00:33:09 +00:00
|
|
|
|
2017-11-03 19:34:16 +00:00
|
|
|
const ENABLE_LOGGING = false;
|
2013-10-31 09:46:02 +00:00
|
|
|
|
2017-11-03 19:34:16 +00:00
|
|
|
function debug(text) {
|
2017-11-03 19:52:04 +00:00
|
|
|
if (ENABLE_LOGGING)
|
|
|
|
log("**TeaTime >: " + text);
|
2017-11-03 19:34:16 +00:00
|
|
|
}
|
2013-10-31 09:46:02 +00:00
|
|
|
|
2017-11-03 19:34:16 +00:00
|
|
|
function getExtensionLocaleDir() {
|
2017-11-03 19:52:04 +00:00
|
|
|
// check if this extension was built with "make zip-file", and thus
|
|
|
|
// has the locale files in a subfolder
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
debug("Using locale dir: " + selectedDir);
|
|
|
|
|
|
|
|
return selectedDir;
|
2017-11-03 19:34:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function initTranslations(domain) {
|
2017-11-03 19:52:04 +00:00
|
|
|
let extension = ExtensionUtils.getCurrentExtension();
|
2017-11-03 19:34:16 +00:00
|
|
|
|
2017-11-03 19:52:04 +00:00
|
|
|
domain = domain || extension.metadata['gettext-domain'];
|
2017-11-03 19:34:16 +00:00
|
|
|
|
2017-11-20 21:56:44 +00:00
|
|
|
imports.gettext.bindtextdomain(domain, getExtensionLocaleDir());
|
2013-10-31 09:25:41 +00:00
|
|
|
}
|
|
|
|
|
2017-11-20 22:22:15 +00:00
|
|
|
function getTranslationFunc() {
|
|
|
|
let extension = ExtensionUtils.getCurrentExtension();
|
|
|
|
let domain = extension.metadata['gettext-domain'];
|
|
|
|
|
|
|
|
if (typeof getTranslationFunc.initialized == 'undefined') {
|
|
|
|
initTranslations(domain);
|
|
|
|
getTranslationFunc.initialized = true;
|
|
|
|
}
|
|
|
|
return imports.gettext.domain(domain).gettext;
|
|
|
|
}
|
2013-10-31 09:46:02 +00:00
|
|
|
|
2013-05-22 00:33:09 +00:00
|
|
|
function getSettings(schema) {
|
2017-11-03 19:52:04 +00:00
|
|
|
let extension = ExtensionUtils.getCurrentExtension();
|
|
|
|
|
|
|
|
schema = schema || extension.metadata['settings-schema'];
|
|
|
|
|
|
|
|
const GioSSS = Gio.SettingsSchemaSource;
|
|
|
|
|
|
|
|
// check if this extension was built with "make zip-file", and thus
|
|
|
|
// has the schema files in a subfolder
|
|
|
|
// otherwise assume that extension has been installed in the
|
|
|
|
// same prefix as gnome-shell (and therefore schemas are available
|
|
|
|
// in the standard folders)
|
|
|
|
let schemaDir = extension.dir.get_child('schemas');
|
|
|
|
let schemaSource;
|
|
|
|
if (schemaDir.query_exists(null)) {
|
|
|
|
schemaSource = GioSSS.new_from_directory(schemaDir.get_path(),
|
|
|
|
GioSSS.get_default(),
|
|
|
|
false);
|
|
|
|
} else {
|
|
|
|
schemaSource = GioSSS.get_default();
|
|
|
|
}
|
|
|
|
|
|
|
|
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.');
|
|
|
|
|
|
|
|
return new Gio.Settings({
|
|
|
|
settings_schema: schemaObj
|
|
|
|
});
|
2013-05-22 00:33:09 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 23:23:57 +00:00
|
|
|
function formatTime(sec_num) {
|
2017-11-03 19:52:04 +00:00
|
|
|
/* toLocaleFormat would be nicer, however it doesn't work with
|
|
|
|
Debian Wheezy and some later gnome versions */
|
|
|
|
|
|
|
|
// based on code from
|
|
|
|
// http://stackoverflow.com/questions/6312993/javascript-seconds-to-time-with-format-hhmmss
|
|
|
|
|
|
|
|
let hours = Math.floor(sec_num / 3600);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ((hours == "00") ? "" : hours + ':') + minutes + ':' + seconds;
|
2013-05-22 00:33:09 +00:00
|
|
|
}
|
2014-08-03 17:23:19 +00:00
|
|
|
|
|
|
|
function playSound(uri) {
|
2017-11-03 19:52:04 +00:00
|
|
|
if (typeof this.player == 'undefined') {
|
|
|
|
Gst.init(null, 0);
|
|
|
|
this.player = Gst.ElementFactory.make("playbin", "player");
|
|
|
|
this.playBus = this.player.get_bus();
|
|
|
|
this.playBus.add_signal_watch();
|
|
|
|
this.playBus.connect("message", Lang.bind(this,
|
|
|
|
function (playBus, message) {
|
|
|
|
if (message != null) {
|
|
|
|
// IMPORTANT: to reuse the player, set state to READY
|
|
|
|
let t = message.type;
|
|
|
|
if (t == Gst.MessageType.EOS || t == Gst.MessageType.ERROR) {
|
|
|
|
this.player.set_state(Gst.State.READY);
|
|
|
|
}
|
|
|
|
} // message handler
|
|
|
|
}));
|
|
|
|
} // if undefined
|
|
|
|
this.player.set_property('uri', uri);
|
|
|
|
this.player.set_state(Gst.State.PLAYING);
|
2014-08-03 17:23:19 +00:00
|
|
|
}
|
2014-10-14 20:10:49 +00:00
|
|
|
|
|
|
|
function setCairoColorFromClutter(cr, c) {
|
2017-11-03 19:52:04 +00:00
|
|
|
let s = 1.0 / 255;
|
|
|
|
cr.setSourceRGBA(s * c.red, s * c.green, s * c.blue, s * c.alpha);
|
2017-11-20 21:56:44 +00:00
|
|
|
}
|