Commit d2b06fba authored by Guido Gunther's avatar Guido Gunther

Work on handling actions

Signed-off-by: Guido Gunther's avatarGuido Günther <guido.gunther@puri.sm>
parent 26505aeb
Pipeline #33870 passed with stages
in 8 minutes and 19 seconds
......@@ -22,6 +22,7 @@ enum {
PROP_SUMMARY,
PROP_BODY,
PROP_APP_ICON,
PROP_ACTIONS,
LAST_PROP
};
static GParamSpec *props[LAST_PROP];
......@@ -40,6 +41,7 @@ typedef struct _PhoshNotification
GtkWidget *lbl_summary;
GtkWidget *lbl_body;
GtkWidget *img_icon;
GtkWidget *box_actions;
gchar *app_icon;
} PhoshNotification;
......@@ -68,6 +70,9 @@ phosh_notification_set_property (GObject *object,
case PROP_APP_ICON:
phosh_notification_set_app_icon (self, g_value_get_string (value));
break;
case PROP_ACTIONS:
phosh_notification_set_actions (self, g_value_get_boxed (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -96,6 +101,9 @@ phosh_notification_get_property (GObject *object,
case PROP_APP_ICON:
g_value_set_string (value, self->app_icon);
break;
case PROP_ACTIONS:
/* TBD */
/* fallthrough */
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
......@@ -123,7 +131,6 @@ phosh_notification_finalize (GObject *object)
G_OBJECT_CLASS (phosh_notification_parent_class)->finalize (object);
}
static void
phosh_notification_class_init (PhoshNotificationClass *klass)
{
......@@ -166,6 +173,14 @@ phosh_notification_class_init (PhoshNotificationClass *klass)
"",
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
props[PROP_ACTIONS] =
g_param_spec_boxed (
"actions",
"Actions",
"Notification Actions",
G_TYPE_STRV,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
g_object_class_install_properties (object_class, LAST_PROP, props);
/**
......@@ -184,6 +199,7 @@ phosh_notification_class_init (PhoshNotificationClass *klass)
gtk_widget_class_bind_template_child (widget_class, PhoshNotification, lbl_summary);
gtk_widget_class_bind_template_child (widget_class, PhoshNotification, lbl_body);
gtk_widget_class_bind_template_child (widget_class, PhoshNotification, img_icon);
gtk_widget_class_bind_template_child (widget_class, PhoshNotification, box_actions);
gtk_widget_class_bind_template_callback (widget_class, evbox_button_press_event_cb);
}
......@@ -197,7 +213,8 @@ phosh_notification_init (PhoshNotification *self)
PhoshNotification *
phosh_notification_new (const char *app_name,const char *summary,
const char *body, const char *app_icon)
const char *body, const char *app_icon,
const gchar * const *actions)
{
PhoshWayland *wl = phosh_wayland_get_default ();
......@@ -206,6 +223,7 @@ phosh_notification_new (const char *app_name,const char *summary,
"summary", summary,
"body", body,
"app_icon", app_icon,
"actions", actions,
/* layer surface */
"layer-shell", phosh_wayland_get_zwlr_layer_shell_v1(wl),
"anchor", ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP,
......@@ -265,3 +283,65 @@ phosh_notification_set_app_name (PhoshNotification *self, const gchar *app_name)
g_object_notify_by_pspec (G_OBJECT (self), props[PROP_APP_NAME]);
}
void
phosh_notification_set_actions (PhoshNotification *self, const GStrv actions)
{
int i;
g_autoptr(GList) children = NULL;
GList *l;
g_return_if_fail (PHOSH_IS_NOTIFICATION (self));
children = gtk_container_get_children(GTK_CONTAINER(self->box_actions));
for(l = children; l; l = l->next)
gtk_widget_destroy(GTK_WIDGET(l->data));
if(!actions)
gtk_widget_hide(self->box_actions);
else
gtk_widget_show(self->box_actions);
for(i = 0; actions && actions[i]; i += 2) {
const gchar *cur_action_id = actions[i];
const gchar *cur_button_text = actions[i+1];
GtkWidget *btn, *lbl;
g_autofree gchar *cur_button_text_escaped = NULL;
if(!cur_button_text || !cur_action_id || !*cur_action_id)
break;
/* Gnome applications seem to send a "default" action which often has no
label or text, because it is intended to be executed when clicking
the notification window.
See https://developer.gnome.org/notification-spec/
As we do not support this for the moment we hide buttons without labels. */
/* FIXME; implement */
if (g_strcmp0 (cur_button_text, "") == 0)
continue;
btn = gtk_button_new();
g_object_set_data_full(G_OBJECT(btn), "--action-id",
g_strdup(cur_action_id),
(GDestroyNotify)g_free);
gtk_widget_show(btn);
gtk_container_add(GTK_CONTAINER(self->box_actions), btn);
#if 0
g_signal_connect(G_OBJECT(btn), "clicked",
G_CALLBACK(xfce_notify_window_button_clicked),
window);
#endif
cur_button_text_escaped = g_markup_printf_escaped("<span size='small'>%s</span>",
cur_button_text);
lbl = gtk_label_new(NULL);
gtk_label_set_markup(GTK_LABEL(lbl), cur_button_text_escaped);
gtk_label_set_use_markup(GTK_LABEL(lbl), TRUE);
gtk_widget_show(lbl);
gtk_container_add(GTK_CONTAINER(btn), lbl);
}
if(gtk_widget_get_realized(GTK_WIDGET(self)))
gtk_widget_queue_draw(GTK_WIDGET(self));
}
......@@ -23,9 +23,11 @@ G_DECLARE_FINAL_TYPE (PhoshNotification, phosh_notification, PHOSH, NOTIFICATION
PhoshNotification *phosh_notification_new (const char *app_name,
const char *summary,
const char *body,
const char *app_icon);
const char *app_icon,
const char * const *actions);
void phosh_notification_set_summary (PhoshNotification *self, const gchar *summary);
void phosh_notification_set_app_name (PhoshNotification *self, const gchar *app_name);
void phosh_notification_set_app_icon (PhoshNotification *self, const gchar *app_icon);
void phosh_notification_set_actions (PhoshNotification *self, const GStrv actions);
G_END_DECLS
......@@ -99,7 +99,7 @@ handle_get_capabilities (PhoshNotifyDbusNotifications *skeleton,
GDBusMethodInvocation *invocation)
{
const gchar *const capabilities[] = {
"body", "icon-static", NULL,
"actions", "body", "icon-static", NULL,
};
g_debug ("DBus call GetCapabilities");
......@@ -207,6 +207,8 @@ handle_notify (PhoshNotifyDbusNotifications *skeleton,
g_variant_unref(item);
}
if (expire_timeout == -1)
expire_timeout = NOTIFICATION_DEFAULT_TIMEOUT;
......@@ -220,12 +222,14 @@ handle_notify (PhoshNotifyDbusNotifications *skeleton,
"summary", summary,
"body", body,
"app_icon", image_path ?: app_icon,
"actions", actions,
NULL);
} else {
id = self->next_id++;
notification = g_object_ref_sink (phosh_notification_new (app_name, summary,
body, image_path ?: app_icon));
body, image_path ?: app_icon,
actions));
g_hash_table_insert (self->notifications,
GUINT_TO_POINTER (id),
notification);
......
......@@ -99,7 +99,19 @@
</packing>
</child>
<child>
<placeholder/>
<object class="GtkBox" id="box_actions">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<style>
<class name="phosh-notification"/>
......
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