From 93c04e30d97c89bc61e0c0bc8a9d1d8cc3e561fb Mon Sep 17 00:00:00 2001 From: Olaf Leidinger Date: Sun, 3 Aug 2014 19:23:19 +0200 Subject: [PATCH] added audible alarm using gstreamer --- src/extension.js | 8 +++ src/prefs.js | 63 ++++++++++++++++--- ...shell.extensions.teatime.gschema.xml.in.in | 10 +++ src/utils.js | 10 +++ 4 files changed, 84 insertions(+), 7 deletions(-) diff --git a/src/extension.js b/src/extension.js index e6d0979..2b3c390 100644 --- a/src/extension.js +++ b/src/extension.js @@ -332,6 +332,8 @@ const TeaTime = new Lang.Class({ this.actor.remove_actor( this._bGraphicalCountdown ? this._graphicalTimer : this._textualTimer); this.actor.add_actor(this._logo); + this._playSound(); + if ( !bUseGnome34Workarounds && this._settings.get_boolean(Utils.TEATIME_FULLSCREEN_NOTIFICATION_KEY)) { this.dialog = new TeaTimeFullscreenNotification(); this.dialog.show(); @@ -371,6 +373,12 @@ const TeaTime = new Lang.Class({ cr.moveTo(0, 0); cr.arc(0, 0, r, 3 / 2 * pi, 3 / 2 * pi + 2 * pi * this._progress); cr.fill(); + }, + _playSound : function() { + let bPlayAlarmSound = this._settings.get_boolean(Utils.TEATIME_USE_ALARM_SOUND_KEY); + if (bPlayAlarmSound) { + Utils.playSound(this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY)); + } }, _showPreferences : function() { imports.misc.util.spawn(["gnome-shell-extension-prefs", ExtensionUtils.getCurrentExtension().metadata['uuid']]); diff --git a/src/prefs.js b/src/prefs.js index a27648b..0c6a4ea 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -52,10 +52,12 @@ const TeaTimePrefsWidget = new Lang.Class({ Gtk.Adjustment ]); + this.set_column_spacing(3); + this._settings = Utils.getSettings(); this._inhibitUpdate = true; this._settings.connect("changed", Lang.bind(this, this._refresh)); - + this._initWindow(); this._inhibitUpdate = false; this._refresh(); @@ -71,26 +73,49 @@ const TeaTimePrefsWidget = new Lang.Class({ 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", Lang.bind(this, this._saveFullscreenNotifications)); this.graphicalCountdownSwitch = new Gtk.Switch(); this.graphicalCountdownSwitch.connect("notify::active", Lang.bind(this, this._saveGraphicalCountdown)); + // alarm sound file chooser + this.alarmSoundSwitch = new Gtk.Switch(); + this.alarmSoundSwitch.connect("notify::active", Lang.bind(this, this._saveUseAlarm)); + + + 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", Lang.bind(this, this._saveSoundFile)); + + if ( !bUseGnome34Workarounds) { // Full screen notifications currently not working on GNOME 3.4, thus don't show the switch - this.attach(labelFN, 0 /*col*/, curRow /*row*/, 1 /*col span*/, 1 /*row span*/); - this.attach(this.fullscreenNotificationSwitch, 1, curRow, 1, 1); + 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*/, 1 /*col span*/, 1 /*row span*/); - this.attach(this.graphicalCountdownSwitch, 1, curRow, 1, 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.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.treeview = new Gtk.TreeView({model: this._tealist, expand: true}); this.treeview.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE); - this.attach(this.treeview, 0, curRow, 2, 1); + this.attach(this.treeview, 0, curRow, 3, 1); curRow += 1; let teaname = new Gtk.TreeViewColumn({ title: _("Tea"), expand: true }); @@ -124,7 +149,7 @@ const TeaTimePrefsWidget = new Lang.Class({ 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*/, 2 /*col span*/, 1 /*row span*/); + 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", Lang.bind(this, this._addTea)); this.toolbar.insert(this.addButton, -1); @@ -140,7 +165,9 @@ const TeaTimePrefsWidget = new Lang.Class({ this.fullscreenNotificationSwitch.active = this._settings.get_boolean(Utils.TEATIME_FULLSCREEN_NOTIFICATION_KEY) this.graphicalCountdownSwitch.active = this._settings.get_boolean(Utils.TEATIME_GRAPHICAL_COUNTDOWN_KEY) + this.alarmSoundSwitch.active = this._settings.get_boolean(Utils.TEATIME_USE_ALARM_SOUND_KEY) let list = this._settings.get_value(Utils.TEATIME_STEEP_TIMES_KEY).unpack(); + this.alarmSoundFile.set_uri(this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY)); // stop everyone from reacting to the changes we are about to produce // in the model @@ -202,6 +229,28 @@ const TeaTimePrefsWidget = new Lang.Class({ sw.active); this._inhibitUpdate = false; }, + _saveUseAlarm: function(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(Utils.TEATIME_USE_ALARM_SOUND_KEY, + sw.active); + this._inhibitUpdate = false; + }, + _saveSoundFile: function(sw, data) { + // don't update the backend if someone else is messing with the model + if (this._inhibitUpdate) + return; + if (this._settings.get_string(Utils.TEATIME_ALARM_SOUND_KEY) != this.alarmSoundFile.get_uri()) { + this._inhibitUpdate = true; + + Utils.playSound(this.alarmSoundFile.get_uri()); + + this._settings.set_string(Utils.TEATIME_ALARM_SOUND_KEY, uri); + this._inhibitUpdate = false; + } + }, _save: function(store, path_, iter_) { // don't update the backend if someone else is messing with the model if (this._inhibitUpdate) diff --git a/src/schemas/org.gnome.shell.extensions.teatime.gschema.xml.in.in b/src/schemas/org.gnome.shell.extensions.teatime.gschema.xml.in.in index d94c190..fda8e59 100644 --- a/src/schemas/org.gnome.shell.extensions.teatime.gschema.xml.in.in +++ b/src/schemas/org.gnome.shell.extensions.teatime.gschema.xml.in.in @@ -16,6 +16,16 @@ Show an animated graphical countdown. Displays a small, yet nice animation instead of an textual countdown. + + "file:///usr/share/sounds/freedesktop/stereo/complete.oga" + Drawing completed sound + A sound file played after drawing is completed. + + + true + Play sound when drawing completed + Play a sound file after drawing is completed. + diff --git a/src/utils.js b/src/utils.js index f26ded7..f43fe41 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,10 +9,13 @@ const Gettext = imports.gettext; const ExtensionUtils = imports.misc.extensionUtils; const Me = ExtensionUtils.getCurrentExtension(); const Config = imports.misc.config; +const Gst = imports.gi.Gst; const TEATIME_STEEP_TIMES_KEY = 'steep-times'; const TEATIME_FULLSCREEN_NOTIFICATION_KEY = 'fullscreen-notification'; const TEATIME_GRAPHICAL_COUNTDOWN_KEY = 'graphical-countdown'; +const TEATIME_USE_ALARM_SOUND_KEY = 'use-alarm-sound'; +const TEATIME_ALARM_SOUND_KEY = 'alarm-sound-file'; function initTranslations(domain) { let extension = ExtensionUtils.getCurrentExtension(); @@ -79,3 +82,10 @@ function formatTime(sec_num) { return (( hours == "00") ? "" : hours+':') + minutes + ':' + seconds; } + +function playSound(uri) { + Gst.init(null, 0); + let player = Gst.ElementFactory.make("playbin","player"); + player.set_property('uri', uri); + player.set_state(Gst.State.PLAYING); +}