summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <tingping@tingping.se>2018-11-18 09:03:46 -0500
committerPatrick Griffis <tingping@tingping.se>2018-11-18 09:19:47 -0500
commitf55ab3c298c7c200e852b5ede8c4383bffff3b63 (patch)
treee7aa65710a6f36219b5de8f71d429c8dac30fd03
parent29fe398911e47d8e9715bcc97edc7f24c7c1b8eb (diff)
downloadglib-wip/tingping/notification-sounds.tar.gz
gnotification: Add g_notification_set_sound_file()wip/tingping/notification-sounds
-rw-r--r--gio/gfdonotificationbackend.c17
-rw-r--r--gio/gnotification-private.h2
-rw-r--r--gio/gnotification.c42
-rw-r--r--gio/gnotification.h4
4 files changed, 65 insertions, 0 deletions
diff --git a/gio/gfdonotificationbackend.c b/gio/gfdonotificationbackend.c
index e4b3ce48d..52d7a62df 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,22 @@ 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 (path != NULL && g_path_is_absolute (path))
+ {
+ gchar *path_utf8 = g_filename_to_utf8 (path, -1, NULL, NULL, NULL);
+ if (path_utf8 != NULL)
+ g_variant_builder_add (&hints_builder, "{sv}", "sound-file", g_variant_new_string (path_utf8));
+ g_free (path_utf8);
+ g_free (path);
+ }
+ else
+ g_warning ("Relative path passed to GNotification (%s)", 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);