mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-02-23 18:52:09 +01:00
gnotification: add sound theme support and implement the backends
This commit is contained in:
parent
80ce29f44b
commit
1a9ebb6794
@ -202,7 +202,7 @@ g_cocoa_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
const gchar *cstr_id,
|
const gchar *cstr_id,
|
||||||
GNotification *notification)
|
GNotification *notification)
|
||||||
{
|
{
|
||||||
NSString *str_title = nil, *str_text = nil, *str_id = nil;
|
NSString *str_title = nil, *str_text = nil, *str_id = nil, *str_sound_name = nil;
|
||||||
NSImage *content = nil;
|
NSImage *content = nil;
|
||||||
const char *cstr;
|
const char *cstr;
|
||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
@ -215,6 +215,8 @@ g_cocoa_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
str_text = nsstring_from_cstr (cstr);
|
str_text = nsstring_from_cstr (cstr);
|
||||||
if (cstr_id != NULL)
|
if (cstr_id != NULL)
|
||||||
str_id = nsstring_from_cstr (cstr_id);
|
str_id = nsstring_from_cstr (cstr_id);
|
||||||
|
if ((cstr = g_notification_get_sound_name (notification)))
|
||||||
|
str_sound_name = nsstring_from_cstr (cstr);
|
||||||
if ((icon = g_notification_get_icon (notification)))
|
if ((icon = g_notification_get_icon (notification)))
|
||||||
content = nsimage_from_gicon (icon);
|
content = nsimage_from_gicon (icon);
|
||||||
/* NOTE: There is no priority */
|
/* NOTE: There is no priority */
|
||||||
@ -224,6 +226,11 @@ g_cocoa_notification_backend_send_notification (GNotificationBackend *backend,
|
|||||||
userNotification.informativeText = str_text;
|
userNotification.informativeText = str_text;
|
||||||
userNotification.identifier = str_id;
|
userNotification.identifier = str_id;
|
||||||
userNotification.contentImage = content;
|
userNotification.contentImage = content;
|
||||||
|
if (!str_sound_name)
|
||||||
|
userNotification.soundName = str_sound_name;
|
||||||
|
else
|
||||||
|
userNotification.soundName = NSUserNotificationDefaultSoundName;
|
||||||
|
|
||||||
/* NOTE: Buttons only show up if your bundle has NSUserNotificationAlertStyle set to "alerts" */
|
/* NOTE: Buttons only show up if your bundle has NSUserNotificationAlertStyle set to "alerts" */
|
||||||
add_actions_to_notification (userNotification, notification);
|
add_actions_to_notification (userNotification, notification);
|
||||||
|
|
||||||
|
@ -223,6 +223,7 @@ call_notify (GDBusConnection *con,
|
|||||||
GIcon *icon;
|
GIcon *icon;
|
||||||
GVariant *parameters;
|
GVariant *parameters;
|
||||||
const gchar *body;
|
const gchar *body;
|
||||||
|
const gchar *sound_name;
|
||||||
guchar urgency;
|
guchar urgency;
|
||||||
|
|
||||||
g_variant_builder_init (&action_builder, G_VARIANT_TYPE_STRING_ARRAY);
|
g_variant_builder_init (&action_builder, G_VARIANT_TYPE_STRING_ARRAY);
|
||||||
@ -267,6 +268,13 @@ call_notify (GDBusConnection *con,
|
|||||||
g_variant_new_string (g_application_get_application_id (app)));
|
g_variant_new_string (g_application_get_application_id (app)));
|
||||||
urgency = urgency_from_priority (g_notification_get_priority (notification));
|
urgency = urgency_from_priority (g_notification_get_priority (notification));
|
||||||
g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (urgency));
|
g_variant_builder_add (&hints_builder, "{sv}", "urgency", g_variant_new_byte (urgency));
|
||||||
|
sound_name = g_notification_get_sound_name (app);
|
||||||
|
if (sound_name != NULL)
|
||||||
|
{
|
||||||
|
g_variant_builder_add (&hints_builder, "{sv}", "sound-name",
|
||||||
|
g_variant_new_string (sound_name));
|
||||||
|
}
|
||||||
|
|
||||||
icon = g_notification_get_icon (notification);
|
icon = g_notification_get_icon (notification);
|
||||||
if (icon != NULL)
|
if (icon != NULL)
|
||||||
{
|
{
|
||||||
|
@ -49,4 +49,6 @@ gboolean g_notification_get_default_action (GNotifi
|
|||||||
|
|
||||||
GVariant * g_notification_serialize (GNotification *notification);
|
GVariant * g_notification_serialize (GNotification *notification);
|
||||||
|
|
||||||
|
const gchar * g_notification_get_sound_name (GNotification *notification);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -77,6 +77,7 @@ struct _GNotification
|
|||||||
GPtrArray *buttons;
|
GPtrArray *buttons;
|
||||||
gchar *default_action;
|
gchar *default_action;
|
||||||
GVariant *default_action_target;
|
GVariant *default_action_target;
|
||||||
|
gchar *sound_name;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -122,6 +123,7 @@ g_notification_finalize (GObject *object)
|
|||||||
if (notification->default_action_target)
|
if (notification->default_action_target)
|
||||||
g_variant_unref (notification->default_action_target);
|
g_variant_unref (notification->default_action_target);
|
||||||
g_ptr_array_free (notification->buttons, TRUE);
|
g_ptr_array_free (notification->buttons, TRUE);
|
||||||
|
g_free (notification->sound_name);
|
||||||
|
|
||||||
G_OBJECT_CLASS (g_notification_parent_class)->finalize (object);
|
G_OBJECT_CLASS (g_notification_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
@ -784,5 +786,54 @@ g_notification_serialize (GNotification *notification)
|
|||||||
g_variant_builder_add (&builder, "{sv}", "buttons", g_variant_builder_end (&actions_builder));
|
g_variant_builder_add (&builder, "{sv}", "buttons", g_variant_builder_end (&actions_builder));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (notification->sound_name)
|
||||||
|
g_variant_builder_add (&builder, "{sv}", "sound-name", g_variant_new_string (notification->sound_name));
|
||||||
|
|
||||||
return g_variant_builder_end (&builder);
|
return g_variant_builder_end (&builder);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*< private >
|
||||||
|
* g_notification_get_sound_name:
|
||||||
|
* @notification: a #GNotification
|
||||||
|
*
|
||||||
|
* Gets the title of @notification.
|
||||||
|
*
|
||||||
|
* Returns: (nullable): the sound requested to be played when showing the @notification
|
||||||
|
*
|
||||||
|
* Since: 2.56
|
||||||
|
*/
|
||||||
|
const gchar *
|
||||||
|
g_notification_get_sound_name (GNotification *notification)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (G_IS_NOTIFICATION (notification), NULL);
|
||||||
|
|
||||||
|
return notification->sound_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* g_notification_set_sound_name:
|
||||||
|
* @notification: a #GNotification
|
||||||
|
* @sound_name: (nullable): the name of the sound requested to be played when
|
||||||
|
* showing the @notification, or %NULL to play the default sound
|
||||||
|
*
|
||||||
|
* Sets the name of the sound played when showing of @notification to
|
||||||
|
* @sound_name. The name of the sound should follow the freedesktop sound theme
|
||||||
|
* specification (See https://freedesktop.org/wiki/Specifications/sound-theme-spec/
|
||||||
|
* for further information).
|
||||||
|
*
|
||||||
|
* If @sound_name is NULL, the default sound will be played.
|
||||||
|
*
|
||||||
|
* Since: 2.56
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
g_notification_set_sound_name (GNotification *notification,
|
||||||
|
const gchar *sound_name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (G_IS_NOTIFICATION (notification));
|
||||||
|
|
||||||
|
g_free (notification->sound_name);
|
||||||
|
if (sound_name)
|
||||||
|
{
|
||||||
|
notification->sound_name = g_strdup (sound_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -92,6 +92,10 @@ void g_notification_set_default_action_and_target_value (GNotifi
|
|||||||
const gchar *action,
|
const gchar *action,
|
||||||
GVariant *target);
|
GVariant *target);
|
||||||
|
|
||||||
|
GLIB_AVAILABLE_IN_2_56
|
||||||
|
void g_notification_set_sound_name (GNotification *notification,
|
||||||
|
const gchar *sound_name);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user