Commit 1a4573cc authored by Guido Gunther's avatar Guido Gunther
Browse files

notification-content: Allow to show/hide body and actions


Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent dbdc004f
......@@ -21,6 +21,7 @@
enum {
PROP_0,
PROP_NOTIFICATION,
PROP_SHOW_BODY,
LAST_PROP
};
static GParamSpec *props[LAST_PROP];
......@@ -35,6 +36,8 @@ struct _PhoshNotificationContent {
GtkWidget *lbl_body;
GtkWidget *img_image;
GtkWidget *box_actions;
gboolean show_body;
};
typedef struct _PhoshNotificationContent PhoshNotificationContent;
......@@ -90,7 +93,7 @@ set_body (GBinding *binding,
const char* body = g_value_get_string (from_value);
gboolean visible;
visible = body != NULL && g_strcmp0 (body, "");
visible = body != NULL && g_strcmp0 (body, "") && self->show_body;
gtk_widget_set_visible (self->lbl_body, visible);
g_value_set_string (to_value, body);
......@@ -201,6 +204,10 @@ phosh_notification_content_set_property (GObject *object,
phosh_notification_content_set_notification (self,
g_value_get_object (value));
break;
case PROP_SHOW_BODY:
self->show_body = g_value_get_boolean (value);
break;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -220,6 +227,9 @@ phosh_notification_content_get_property (GObject *object,
case PROP_NOTIFICATION:
g_value_set_object (value, self->notification);
break;
case PROP_SHOW_BODY:
g_value_set_boolean (value, self->show_body);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -262,6 +272,19 @@ phosh_notification_content_class_init (PhoshNotificationContentClass *klass)
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
/**
* PhoshNotificationContent:show-body:
*
* Whether the body of the notification is shown
*/
props[PROP_SHOW_BODY] =
g_param_spec_boolean ("show-body",
"",
"",
TRUE,
G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE |
G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROP, props);
gtk_widget_class_set_template_from_resource (widget_class,
......@@ -302,6 +325,8 @@ phosh_notification_content_init (PhoshNotificationContent *self)
{
g_autoptr (GActionMap) map = NULL;
self->show_body = TRUE;
map = G_ACTION_MAP (g_simple_action_group_new ());
g_action_map_add_action_entries (map,
entries,
......@@ -312,14 +337,28 @@ phosh_notification_content_init (PhoshNotificationContent *self)
G_ACTION_GROUP (map));
gtk_widget_init_template (GTK_WIDGET (self));
g_object_bind_property (self,
"show-body",
self->lbl_body,
"visible",
G_BINDING_DEFAULT);
g_object_bind_property (self,
"show-body",
self->box_actions,
"visible",
G_BINDING_DEFAULT);
}
GtkWidget *
phosh_notification_content_new (PhoshNotification *notification)
phosh_notification_content_new (PhoshNotification *notification, gboolean show_body)
{
return g_object_new (PHOSH_TYPE_NOTIFICATION_CONTENT,
"notification", notification,
"show-body", show_body,
NULL);
}
......
......@@ -21,7 +21,8 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (PhoshNotificationContent, phosh_notification_content, PHOSH, NOTIFICATION_CONTENT, GtkListBoxRow)
GtkWidget *phosh_notification_content_new (PhoshNotification *notification);
GtkWidget *phosh_notification_content_new (PhoshNotification *notification,
gboolean show_body);
PhoshNotification *phosh_notification_content_get_notification (PhoshNotificationContent *self);
......
......@@ -154,7 +154,7 @@ create_row (gpointer item, gpointer data)
{
PhoshNotification *notification = item;
return phosh_notification_content_new (notification);
return phosh_notification_content_new (notification, TRUE);
}
......
......@@ -32,7 +32,7 @@ test_phosh_notification_content_new (void)
NULL,
now);
content = phosh_notification_content_new (noti);
content = phosh_notification_content_new (noti, TRUE);
noti_test = phosh_notification_content_get_notification (PHOSH_NOTIFICATION_CONTENT (content));
......@@ -65,7 +65,7 @@ test_phosh_notification_content_no_summary (void)
NULL,
now);
phosh_notification_content_new (noti);
phosh_notification_content_new (noti, TRUE);
}
......@@ -104,7 +104,7 @@ test_phosh_notification_content_actions (void)
NULL,
now);
content = phosh_notification_content_new (noti);
content = phosh_notification_content_new (noti, TRUE);
g_signal_connect (noti, "actioned", G_CALLBACK (actioned), NULL);
......@@ -140,7 +140,7 @@ test_phosh_notification_content_bad_action (void)
NULL,
now);
/* Boom */
phosh_notification_content_new (noti);
phosh_notification_content_new (noti, TRUE);
}
g_test_trap_subprocess (NULL, 0, 0);
g_test_trap_assert_failed ();
......@@ -168,7 +168,7 @@ test_phosh_notification_content_set_prop_invalid (void)
NULL,
now);
content = phosh_notification_content_new (noti);
content = phosh_notification_content_new (noti, TRUE);
BAD_PROP_SET (content, phosh_notification_content, PhoshNotificationContent);
}
......@@ -192,7 +192,7 @@ test_phosh_notification_content_get_prop_invalid (void)
NULL,
now);
content = phosh_notification_content_new (noti);
content = phosh_notification_content_new (noti, TRUE);
BAD_PROP_GET (content, phosh_notification_content, PhoshNotificationContent);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment