[geary/mjog/598-sent-email-sound: 6/6] Plugin: Add new sent-sound plugin
- From: Michael Gratton <mjog src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [geary/mjog/598-sent-email-sound: 6/6] Plugin: Add new sent-sound plugin
- Date: Sat, 21 Mar 2020 06:05:12 +0000 (UTC)
commit 8c31185d1c44648dd00a0a55b0d5bee267eb04b3
Author: Michael Gratton <mike vee net>
Date: Sat Mar 21 16:52:30 2020 +1100
Plugin: Add new sent-sound plugin
Optional plugin to play the sent-mail sound from the desktop's system
sound theme when an email is sent.
Fixes #598
meson.build | 1 +
src/client/plugin/meson.build | 1 +
src/client/plugin/sent-sound/meson.build | 29 ++++++++++++
src/client/plugin/sent-sound/sent-sound.plugin.in | 4 ++
src/client/plugin/sent-sound/sent-sound.vala | 55 +++++++++++++++++++++++
5 files changed, 90 insertions(+)
---
diff --git a/meson.build b/meson.build
index 84fe0710..6a5bb77d 100644
--- a/meson.build
+++ b/meson.build
@@ -79,6 +79,7 @@ gdk = dependency('gdk-3.0', version: '>=' + target_gtk)
gee = dependency('gee-0.8', version: '>= 0.8.5')
gio = dependency('gio-2.0', version: '>=' + target_glib)
goa = dependency('goa-1.0')
+gsound = dependency('gsound')
gspell = dependency('gspell-1')
gthread = dependency('gthread-2.0', version: '>=' + target_glib)
iso_codes = dependency('iso-codes')
diff --git a/src/client/plugin/meson.build b/src/client/plugin/meson.build
index a4198c6a..ca3300d5 100644
--- a/src/client/plugin/meson.build
+++ b/src/client/plugin/meson.build
@@ -26,3 +26,4 @@ subdir('desktop-notifications')
subdir('folder-highlight')
subdir('messaging-menu')
subdir('notification-badge')
+subdir('sent-sound')
diff --git a/src/client/plugin/sent-sound/meson.build b/src/client/plugin/sent-sound/meson.build
new file mode 100644
index 00000000..305c445d
--- /dev/null
+++ b/src/client/plugin/sent-sound/meson.build
@@ -0,0 +1,29 @@
+
+plugin_name = 'sent-sound'
+
+send_sound_dependencies = plugin_dependencies
+send_sound_dependencies += gsound
+
+plugin_src = join_paths(plugin_name + '.vala')
+plugin_data = join_paths(plugin_name + '.plugin')
+plugin_dest = join_paths(plugins_dir, plugin_name)
+
+shared_module(
+ plugin_name,
+ sources: plugin_src,
+ dependencies: send_sound_dependencies,
+ include_directories: config_h_dir,
+ vala_args: geary_vala_args,
+ c_args: plugin_c_args,
+ install: true,
+ install_dir: plugin_dest
+)
+
+i18n.merge_file(
+ input: plugin_data + '.in',
+ output: plugin_data,
+ type: 'desktop',
+ po_dir: po_dir,
+ install: true,
+ install_dir: plugin_dest
+)
diff --git a/src/client/plugin/sent-sound/sent-sound.plugin.in
b/src/client/plugin/sent-sound/sent-sound.plugin.in
new file mode 100644
index 00000000..d692d2e5
--- /dev/null
+++ b/src/client/plugin/sent-sound/sent-sound.plugin.in
@@ -0,0 +1,4 @@
+[Plugin]
+Module=sent-sound
+Name=Sent Sound
+Description=Plays the desktop sent-mail sound when an email is sent
diff --git a/src/client/plugin/sent-sound/sent-sound.vala b/src/client/plugin/sent-sound/sent-sound.vala
new file mode 100644
index 00000000..a986b348
--- /dev/null
+++ b/src/client/plugin/sent-sound/sent-sound.vala
@@ -0,0 +1,55 @@
+/*
+ * Copyright © 2020 Michael Gratton <mike vee net>.
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later). See the COPYING file in this distribution.
+ */
+
+[ModuleInit]
+public void peas_register_types(TypeModule module) {
+ Peas.ObjectModule obj = module as Peas.ObjectModule;
+ obj.register_extension_type(
+ typeof(Plugin.PluginBase),
+ typeof(Plugin.SentSound)
+ );
+}
+
+/** Plays the desktop sent-mail sound when an email is sent. */
+public class Plugin.SentSound : PluginBase, NotificationExtension {
+
+
+ public NotificationContext notifications {
+ get; set construct;
+ }
+
+
+ private GSound.Context? context = null;
+ private EmailStore? store = null;
+
+
+ public override async void activate() throws GLib.Error {
+ this.context = new GSound.Context();
+ this.context.init();
+
+ this.store = yield this.notifications.get_email();
+ this.store.email_sent.connect(on_sent);
+ }
+
+ public override async void deactivate(bool is_shutdown) throws GLib.Error {
+ this.store.email_sent.disconnect(on_sent);
+ this.store = null;
+
+ this.context = null;
+ }
+
+ private void on_sent() {
+ try {
+ this.context.play_simple(
+ null, GSound.Attribute.EVENT_ID, "message-sent-email"
+ );
+ } catch (GLib.Error err) {
+ warning("Failed to play sent mail sound: %s", err.message);
+ }
+ }
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]