mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 10:42:11 +01:00
gnotification: Add g_notification_set_sound_file()
This commit is contained in:
parent
29fe398911
commit
f55ab3c298
@ -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)",
|
||||
|
@ -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);
|
||||
|
@ -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 (¬ification->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
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user