[glib/wip/tingping/notification-sounds] gnotification: Add g_notification_set_sound_file()



commit ead84ce95c5ec19ec7f3cd899ef6ce0d1e25d628
Author: Patrick Griffis <tingping tingping se>
Date:   Sun Nov 18 09:03:46 2018 -0500

    gnotification: Add g_notification_set_sound_file()

 gio/gfdonotificationbackend.c | 12 ++++++++++++
 gio/gnotification-private.h   |  2 ++
 gio/gnotification.c           | 42 ++++++++++++++++++++++++++++++++++++++++++
 gio/gnotification.h           |  4 ++++
 4 files changed, 60 insertions(+)
---
diff --git a/gio/gfdonotificationbackend.c b/gio/gfdonotificationbackend.c
index e4b3ce48d..34b98d705 100644
--- a/gio/gfdonotificationbackend.c
+++ b/gio/gfdonotificationbackend.c
@@ -243,6 +243,7 @@ call_notify (GDBusConnection     *con,
   const gchar *body;
   guchar urgency;
   const char *sound_name = NULL;
+  GFile *sound_file;
   GNotificationSound sound;
 
   g_variant_builder_init (&action_builder, G_VARIANT_TYPE_STRING_ARRAY);
@@ -326,6 +327,17 @@ call_notify (GDBusConnection     *con,
   if (sound == G_NOTIFICATION_SOUND_NONE)
     g_variant_builder_add (&hints_builder, "{sv}", "suppress-sound", g_variant_new_boolean (TRUE));
 
+  sound_file = g_notification_get_sound_file (notification);
+  if (sound_file != NULL)
+    {
+      gchar *path = g_file_get_path (sound_file);
+      if (g_path_is_absolute (path))
+        g_variant_builder_add (&hints_builder, "{sv}", "sound-file", g_variant_new_string (path));
+      else
+        g_warning ("Relative path passed to GNotification (%s)", path);
+      g_free (path);
+    }
+
   body = g_notification_get_body (notification);
 
   parameters = g_variant_new ("(susssasa{sv}i)",
diff --git a/gio/gnotification-private.h b/gio/gnotification-private.h
index a9623d1f6..1211bd93a 100644
--- a/gio/gnotification-private.h
+++ b/gio/gnotification-private.h
@@ -32,6 +32,8 @@ GIcon *                 g_notification_get_icon                         (GNotifi
 
 GNotificationSound      g_notification_get_sound                        (GNotification *notification);
 
+GFile *                 g_notification_get_sound_file                   (GNotification *notification);
+
 GNotificationPriority   g_notification_get_priority                     (GNotification *notification);
 
 guint                   g_notification_get_n_buttons                    (GNotification *notification);
diff --git a/gio/gnotification.c b/gio/gnotification.c
index 75eb4208d..3e4b27f2f 100644
--- a/gio/gnotification.c
+++ b/gio/gnotification.c
@@ -23,6 +23,7 @@
 #include "gdbusutils.h"
 #include "gicon.h"
 #include "gaction.h"
+#include "gfile.h"
 #include "gioenumtypes.h"
 
 /**
@@ -77,6 +78,7 @@ struct _GNotification
   GPtrArray *buttons;
   gchar *default_action;
   GVariant *default_action_target;
+  GFile *sound_file;
   GNotificationSound sound;
 };
 
@@ -123,6 +125,7 @@ g_notification_finalize (GObject *object)
   if (notification->default_action_target)
     g_variant_unref (notification->default_action_target);
   g_ptr_array_free (notification->buttons, TRUE);
+  g_clear_object (&notification->sound_file);
 
   G_OBJECT_CLASS (g_notification_parent_class)->finalize (object);
 }
@@ -284,6 +287,25 @@ g_notification_get_sound (GNotification *notification)
   return notification->sound;
 }
 
+
+/*< private >
+ * g_notification_get_sound_file:
+ * @notification: a #GNotification
+ *
+ * Gets the sound file currently set on @notification.
+ *
+ * Returns: (transfer none): the sound file associated with @notification
+ *
+ * Since: 2.60
+ */
+GFile *
+g_notification_get_sound_file (GNotification *notification)
+{
+  g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL);
+
+  return notification->sound_file;
+}
+
 /**
  * g_notification_set_icon:
  * @notification: a #GNotification
@@ -324,6 +346,26 @@ g_notification_set_sound (GNotification      *notification,
   notification->sound = sound;
 }
 
+/**
+ * g_notification_set_sound_file:
+ * @notification: a #GNotification
+ * @sound_file: a #GFile to be played with the @notification
+ *
+ * Sets the sound of @notification. The result of this sound
+ * depends upon the backend and notification service used.
+ *
+ * Since: 2.60
+ */
+void
+g_notification_set_sound_file (GNotification      *notification,
+                               GFile              *sound_file)
+{
+  g_return_if_fail (G_IS_NOTIFICATION (notification));
+  g_return_if_fail (G_IS_FILE (sound_file));
+
+  notification->sound_file = g_object_ref (sound_file);
+}
+
 /*< private >
  * g_notification_get_priority:
  * @notification: a #GNotification
diff --git a/gio/gnotification.h b/gio/gnotification.h
index 3b9746296..129d6745b 100644
--- a/gio/gnotification.h
+++ b/gio/gnotification.h
@@ -55,6 +55,10 @@ GLIB_AVAILABLE_IN_2_60
 void                    g_notification_set_sound                        (GNotification      *notification,
                                                                          GNotificationSound  sound);
 
+GLIB_AVAILABLE_IN_2_60
+void                    g_notification_set_sound_file                   (GNotification      *notification,
+                                                                         GFile              *file);
+
 GLIB_DEPRECATED_IN_2_42_FOR(g_notification_set_priority)
 void                    g_notification_set_urgent                       (GNotification *notification,
                                                                          gboolean       urgent);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]