Add notify_notification_set_app_name() to set the application name for the notification
When a daemon like gnome-settings-daemon has multiple plugins, if a plugin uses notify_set_app_name() then subsequent notifications get the wrong 'Application name' in the gnome-shell persistent message tray. This new function is per-notification and is thus allows us to set a custom application name without overwriting the application name stored by notify_init(). https://bugzilla.gnome.org/show_bug.cgi?id=648947
This commit is contained in:
parent
ae361b0d96
commit
1c40dfaff4
|
@ -65,6 +65,7 @@ typedef struct
|
||||||
struct _NotifyNotificationPrivate
|
struct _NotifyNotificationPrivate
|
||||||
{
|
{
|
||||||
guint32 id;
|
guint32 id;
|
||||||
|
char *app_name;
|
||||||
char *summary;
|
char *summary;
|
||||||
char *body;
|
char *body;
|
||||||
|
|
||||||
|
@ -100,6 +101,7 @@ enum
|
||||||
{
|
{
|
||||||
PROP_0,
|
PROP_0,
|
||||||
PROP_ID,
|
PROP_ID,
|
||||||
|
PROP_APP_NAME,
|
||||||
PROP_SUMMARY,
|
PROP_SUMMARY,
|
||||||
PROP_BODY,
|
PROP_BODY,
|
||||||
PROP_ICON_NAME,
|
PROP_ICON_NAME,
|
||||||
|
@ -178,6 +180,17 @@ notify_notification_class_init (NotifyNotificationClass *klass)
|
||||||
| G_PARAM_STATIC_NICK
|
| G_PARAM_STATIC_NICK
|
||||||
| G_PARAM_STATIC_BLURB));
|
| G_PARAM_STATIC_BLURB));
|
||||||
|
|
||||||
|
g_object_class_install_property (object_class,
|
||||||
|
PROP_APP_NAME,
|
||||||
|
g_param_spec_string ("app-name",
|
||||||
|
"Application name",
|
||||||
|
"The application name to use for this notification",
|
||||||
|
NULL,
|
||||||
|
G_PARAM_READWRITE
|
||||||
|
| G_PARAM_STATIC_NAME
|
||||||
|
| G_PARAM_STATIC_NICK
|
||||||
|
| G_PARAM_STATIC_BLURB));
|
||||||
|
|
||||||
g_object_class_install_property (object_class,
|
g_object_class_install_property (object_class,
|
||||||
PROP_SUMMARY,
|
PROP_SUMMARY,
|
||||||
g_param_spec_string ("summary",
|
g_param_spec_string ("summary",
|
||||||
|
@ -230,6 +243,7 @@ notify_notification_class_init (NotifyNotificationClass *klass)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_notification_update_internal (NotifyNotification *notification,
|
notify_notification_update_internal (NotifyNotification *notification,
|
||||||
|
const char *app_name,
|
||||||
const char *summary,
|
const char *summary,
|
||||||
const char *body,
|
const char *body,
|
||||||
const char *icon);
|
const char *icon);
|
||||||
|
@ -248,8 +262,17 @@ notify_notification_set_property (GObject *object,
|
||||||
priv->id = g_value_get_int (value);
|
priv->id = g_value_get_int (value);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_APP_NAME:
|
||||||
|
notify_notification_update_internal (notification,
|
||||||
|
g_value_get_string (value),
|
||||||
|
priv->summary,
|
||||||
|
priv->body,
|
||||||
|
priv->icon_name);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_SUMMARY:
|
case PROP_SUMMARY:
|
||||||
notify_notification_update_internal (notification,
|
notify_notification_update_internal (notification,
|
||||||
|
priv->app_name,
|
||||||
g_value_get_string (value),
|
g_value_get_string (value),
|
||||||
priv->body,
|
priv->body,
|
||||||
priv->icon_name);
|
priv->icon_name);
|
||||||
|
@ -257,6 +280,7 @@ notify_notification_set_property (GObject *object,
|
||||||
|
|
||||||
case PROP_BODY:
|
case PROP_BODY:
|
||||||
notify_notification_update_internal (notification,
|
notify_notification_update_internal (notification,
|
||||||
|
priv->app_name,
|
||||||
priv->summary,
|
priv->summary,
|
||||||
g_value_get_string (value),
|
g_value_get_string (value),
|
||||||
priv->icon_name);
|
priv->icon_name);
|
||||||
|
@ -264,6 +288,7 @@ notify_notification_set_property (GObject *object,
|
||||||
|
|
||||||
case PROP_ICON_NAME:
|
case PROP_ICON_NAME:
|
||||||
notify_notification_update_internal (notification,
|
notify_notification_update_internal (notification,
|
||||||
|
priv->app_name,
|
||||||
priv->summary,
|
priv->summary,
|
||||||
priv->body,
|
priv->body,
|
||||||
g_value_get_string (value));
|
g_value_get_string (value));
|
||||||
|
@ -293,6 +318,10 @@ notify_notification_get_property (GObject *object,
|
||||||
g_value_set_string (value, priv->summary);
|
g_value_set_string (value, priv->summary);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case PROP_APP_NAME:
|
||||||
|
g_value_set_string (value, priv->app_name);
|
||||||
|
break;
|
||||||
|
|
||||||
case PROP_BODY:
|
case PROP_BODY:
|
||||||
g_value_set_string (value, priv->body);
|
g_value_set_string (value, priv->body);
|
||||||
break;
|
break;
|
||||||
|
@ -347,6 +376,7 @@ notify_notification_finalize (GObject *object)
|
||||||
|
|
||||||
_notify_cache_remove_notification (obj);
|
_notify_cache_remove_notification (obj);
|
||||||
|
|
||||||
|
g_free (priv->app_name);
|
||||||
g_free (priv->summary);
|
g_free (priv->summary);
|
||||||
g_free (priv->body);
|
g_free (priv->body);
|
||||||
g_free (priv->icon_name);
|
g_free (priv->icon_name);
|
||||||
|
@ -397,10 +427,17 @@ notify_notification_new (const char *summary,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_notification_update_internal (NotifyNotification *notification,
|
notify_notification_update_internal (NotifyNotification *notification,
|
||||||
|
const char *app_name,
|
||||||
const char *summary,
|
const char *summary,
|
||||||
const char *body,
|
const char *body,
|
||||||
const char *icon)
|
const char *icon)
|
||||||
{
|
{
|
||||||
|
if (notification->priv->app_name != app_name) {
|
||||||
|
g_free (notification->priv->app_name);
|
||||||
|
notification->priv->app_name = g_strdup (app_name);
|
||||||
|
g_object_notify (G_OBJECT (notification), "app-name");
|
||||||
|
}
|
||||||
|
|
||||||
if (notification->priv->summary != summary) {
|
if (notification->priv->summary != summary) {
|
||||||
g_free (notification->priv->summary);
|
g_free (notification->priv->summary);
|
||||||
notification->priv->summary = g_strdup (summary);
|
notification->priv->summary = g_strdup (summary);
|
||||||
|
@ -447,7 +484,9 @@ notify_notification_update (NotifyNotification *notification,
|
||||||
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
|
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
|
||||||
g_return_val_if_fail (summary != NULL && *summary != '\0', FALSE);
|
g_return_val_if_fail (summary != NULL && *summary != '\0', FALSE);
|
||||||
|
|
||||||
notify_notification_update_internal (notification, summary, body, icon);
|
notify_notification_update_internal (notification,
|
||||||
|
notification->priv->app_name,
|
||||||
|
summary, body, icon);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
@ -524,7 +563,7 @@ notify_notification_show (NotifyNotification *notification,
|
||||||
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
|
g_return_val_if_fail (NOTIFY_IS_NOTIFICATION (notification), FALSE);
|
||||||
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
||||||
|
|
||||||
if (notify_get_app_name () == NULL) {
|
if (!notify_is_initted ()) {
|
||||||
g_warning ("you must call notify_init() before showing");
|
g_warning ("you must call notify_init() before showing");
|
||||||
g_assert_not_reached ();
|
g_assert_not_reached ();
|
||||||
}
|
}
|
||||||
|
@ -557,7 +596,7 @@ notify_notification_show (NotifyNotification *notification,
|
||||||
result = g_dbus_proxy_call_sync (proxy,
|
result = g_dbus_proxy_call_sync (proxy,
|
||||||
"Notify",
|
"Notify",
|
||||||
g_variant_new ("(susssasa{sv}i)",
|
g_variant_new ("(susssasa{sv}i)",
|
||||||
notify_get_app_name (),
|
priv->app_name ? priv->app_name : notify_get_app_name (),
|
||||||
priv->id,
|
priv->id,
|
||||||
priv->icon_name ? priv->icon_name : "",
|
priv->icon_name ? priv->icon_name : "",
|
||||||
priv->summary ? priv->summary : "",
|
priv->summary ? priv->summary : "",
|
||||||
|
@ -768,6 +807,30 @@ notify_notification_set_hint (NotifyNotification *notification,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* notify_notification_set_app_name:
|
||||||
|
* @notification: a #NotifyNotification
|
||||||
|
* @app_name: the localised application name
|
||||||
|
*
|
||||||
|
* Sets the application name for the notification. If this function is
|
||||||
|
* not called or if @app_name is %NULL, the application name will be
|
||||||
|
* set from the value used in notify_init() or overridden with
|
||||||
|
* notify_set_app_name().
|
||||||
|
*
|
||||||
|
* Since: 0.7.3
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
notify_notification_set_app_name (NotifyNotification *notification,
|
||||||
|
const char *app_name)
|
||||||
|
{
|
||||||
|
g_return_if_fail (NOTIFY_IS_NOTIFICATION (notification));
|
||||||
|
|
||||||
|
g_free (notification->priv->app_name);
|
||||||
|
notification->priv->app_name = g_strdup (app_name);
|
||||||
|
|
||||||
|
g_object_notify (G_OBJECT (notification), "app-name");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* notify_notification_set_hint_int32:
|
* notify_notification_set_hint_int32:
|
||||||
* @notification: The notification.
|
* @notification: The notification.
|
||||||
|
|
|
@ -165,6 +165,9 @@ void notify_notification_set_hint (NotifyNotificatio
|
||||||
const char *key,
|
const char *key,
|
||||||
GVariant *value);
|
GVariant *value);
|
||||||
|
|
||||||
|
void notify_notification_set_app_name (NotifyNotification *notification,
|
||||||
|
const char *app_name);
|
||||||
|
|
||||||
void notify_notification_clear_hints (NotifyNotification *notification);
|
void notify_notification_clear_hints (NotifyNotification *notification);
|
||||||
|
|
||||||
void notify_notification_add_action (NotifyNotification *notification,
|
void notify_notification_add_action (NotifyNotification *notification,
|
||||||
|
|
Loading…
Reference in New Issue