[gnome-builder/gnome-builder-43] plugins/notification: add default message for notification title



commit 98bb8f6561689c501742970c61aeb12e53e671da
Author: Christian Hergert <chergert redhat com>
Date:   Tue Sep 20 14:29:21 2022 -0700

    plugins/notification: add default message for notification title
    
    This should fix an "empty notification title" in the omnibar when building
    with not message received from the workers.

 src/plugins/notification/ide-notification-addin.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/src/plugins/notification/ide-notification-addin.c 
b/src/plugins/notification/ide-notification-addin.c
index 73484fcfd..b3a76701c 100644
--- a/src/plugins/notification/ide-notification-addin.c
+++ b/src/plugins/notification/ide-notification-addin.c
@@ -50,6 +50,22 @@ G_DEFINE_FINAL_TYPE_WITH_CODE (IdeNotificationAddin,
                                IDE_TYPE_OBJECT,
                                G_IMPLEMENT_INTERFACE (IDE_TYPE_PIPELINE_ADDIN, addin_iface_init))
 
+static gboolean
+title_with_default (GBinding     *binding,
+                    const GValue *from_value,
+                    GValue       *to_value,
+                    gpointer      user_data)
+{
+  g_autofree char *str = g_strstrip (g_value_dup_string (from_value));
+
+  if (ide_str_empty0 (str))
+    g_value_set_static_string (to_value, _("Building…"));
+  else
+    g_value_take_string (to_value, g_steal_pointer (&str));
+
+  return TRUE;
+}
+
 static gboolean
 should_supress_message (IdeNotificationAddin *self,
                         const gchar          *message)
@@ -162,7 +178,9 @@ ide_notification_addin_pipeline_started (IdeNotificationAddin *self,
     {
       /* Setup new in-app notification */
       self->notif = ide_notification_new ();
-      g_object_bind_property (pipeline, "message", self->notif, "title", G_BINDING_SYNC_CREATE);
+      g_object_bind_property_full (pipeline, "message", self->notif, "title",
+                                   G_BINDING_SYNC_CREATE,
+                                   title_with_default, NULL, NULL, NULL);
       ide_notification_attach (self->notif, IDE_OBJECT (pipeline));
 
       /* Withdraw previous shell notification (it's now invalid) */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]