[Xfce4-commits] [apps/xfce4-notifyd] 03/06: Fix handling of known applications

noreply at xfce.org noreply at xfce.org
Mon Oct 3 23:34:21 CEST 2016


This is an automated email from the git hooks/post-receive script.

ochosi pushed a commit to branch master
in repository apps/xfce4-notifyd.

commit 718a47b4374f27f79d609da1c2da97005b27602a
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Mon Sep 5 18:20:34 2016 +0200

    Fix handling of known applications
---
 xfce4-notifyd-config/main.c                     | 159 ++++++++++++++++--------
 xfce4-notifyd-config/xfce4-notifyd-config.glade |  75 ++++++++++-
 xfce4-notifyd/xfce-notify-daemon.c              |  41 +++---
 3 files changed, 210 insertions(+), 65 deletions(-)

diff --git a/xfce4-notifyd-config/main.c b/xfce4-notifyd-config/main.c
index d9b3130..d155223 100644
--- a/xfce4-notifyd-config/main.c
+++ b/xfce4-notifyd-config/main.c
@@ -38,6 +38,9 @@
 
 #include "xfce4-notifyd-config.ui.h"
 
+#define KNOWN_APPLICATIONS_PROP       "/applications/known_applications"
+#define MUTED_APPLICATIONS_PROP       "/applications/muted_applications"
+
 static void
 xfce_notifyd_config_show_notification_callback(NotifyNotification *notification,
                                                const char         *action,
@@ -273,7 +276,7 @@ xfce4_notifyd_mute_application (GtkListBox *known_applications_listbox,
     const gchar *application_name;
     gchar *new_app_name;
 
-    muted_applications = xfconf_channel_get_arrayv (channel, "/applications/muted_applications");
+    muted_applications = xfconf_channel_get_arrayv (channel, MUTED_APPLICATIONS_PROP);
     if (muted_applications == NULL)
         muted_applications = g_ptr_array_new ();
 
@@ -302,7 +305,7 @@ xfce4_notifyd_mute_application (GtkListBox *known_applications_listbox,
     else
         g_ptr_array_add (muted_applications, val);
 
-    if (!xfconf_channel_set_arrayv (channel, "/applications/muted_applications", muted_applications))
+    if (!xfconf_channel_set_arrayv (channel, MUTED_APPLICATIONS_PROP, muted_applications))
         g_warning ("Could not add %s to the list of muted applications.", new_app_name);
 
     xfconf_array_free (muted_applications);
@@ -345,6 +348,82 @@ xfce4_notifyd_switch_activated (GtkSwitch *mute_switch,
                                     channel);
 }
 
+static void
+listbox_remove_all (GtkWidget *widget, gpointer user_data)
+{
+    GtkWidget *container = user_data;
+    gtk_container_remove (GTK_CONTAINER (container), widget);
+}
+
+static void
+xfce4_notifyd_known_applications_changed (XfconfChannel *channel,
+                               const gchar *property,
+                               const GValue *value,
+                               gpointer user_data)
+{
+    GtkWidget *known_applications_listbox = user_data;
+    GtkWidget *hbox;
+    GtkWidget *label;
+    GtkWidget *mute_switch;
+    GtkWidget *separator;
+    GtkCallback func = listbox_remove_all;
+    GPtrArray *known_applications;
+    GPtrArray *muted_applications;
+    GValue *known_application;
+    guint i, j;
+
+    known_applications = xfconf_channel_get_arrayv (channel, KNOWN_APPLICATIONS_PROP);
+    muted_applications = xfconf_channel_get_arrayv (channel, MUTED_APPLICATIONS_PROP);
+
+    /* TODO: Check the old list versus the new one and only add/remove rows
+             as needed instead instead of cleaning up the whole widget */
+    /* Clean up the list and re-fill it */
+    gtk_container_foreach (GTK_CONTAINER (known_applications_listbox), func, known_applications_listbox);
+
+    if (known_applications != NULL) {
+        for (i = 0; i < known_applications->len; i++) {
+            known_application = g_ptr_array_index (known_applications, i);
+            hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+            label = gtk_label_new (g_value_get_string (known_application));
+            gtk_label_set_xalign (GTK_LABEL (label), 0);
+            mute_switch = gtk_switch_new ();
+            gtk_switch_set_active (GTK_SWITCH (mute_switch), TRUE);
+            gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 3);
+            gtk_box_pack_end (GTK_BOX (hbox), mute_switch, FALSE, TRUE, 3);
+            gtk_list_box_insert (GTK_LIST_BOX (known_applications_listbox), hbox, -1);
+            /* Set correct initial value as to whether an application is muted */
+            if (muted_applications != NULL) {
+                for (j = 0; j < muted_applications->len; j++) {
+                    GValue *muted_application;
+                    muted_application = g_ptr_array_index (muted_applications, j);
+                    if (g_str_match_string (g_value_get_string (muted_application), g_value_get_string (known_application), FALSE) == TRUE) {
+                        gtk_switch_set_active (GTK_SWITCH (mute_switch), FALSE);
+                        break;
+                    }
+                    else
+                        continue;
+                }
+            }
+            g_signal_connect (G_OBJECT (mute_switch), "state-set", G_CALLBACK (xfce4_notifyd_switch_activated), channel);
+        }
+    }
+    xfconf_array_free (known_applications);
+    xfconf_array_free (muted_applications);
+    gtk_widget_show_all (known_applications_listbox);
+}
+
+static void
+xfce4_notifyd_do_not_disturb_activated (GtkSwitch *do_not_disturb_switch,
+                                        gboolean state,
+                                        gpointer user_data)
+{
+    GtkWidget *do_not_disturb_info = user_data;
+
+    gtk_revealer_set_reveal_child (GTK_REVEALER (do_not_disturb_info),
+                                    gtk_switch_get_active (GTK_SWITCH (do_not_disturb_switch)));
+    gtk_switch_set_active (GTK_SWITCH (do_not_disturb_switch), state);
+}
+
 static void xfce4_notifyd_show_help(GtkButton *button,
                                     GtkWidget *dialog)
 {
@@ -363,14 +442,12 @@ xfce4_notifyd_config_setup_dialog(GtkBuilder *builder)
     GtkWidget *position_combo;
     GtkWidget *help_button;
     GtkWidget *known_applications_listbox;
-    GtkWidget *no_known_apps_label;
+    GtkWidget *placeholder_label;
     GtkWidget *do_not_disturb_switch;
+    GtkWidget *do_not_disturb_info;
     GtkAdjustment *adj;
     GError *error = NULL;
     gchar *current_theme;
-    GPtrArray *known_applications;
-    GPtrArray *muted_applications;
-    guint i, j;
 
     gtk_builder_connect_signals(builder, NULL);
 
@@ -427,56 +504,38 @@ xfce4_notifyd_config_setup_dialog(GtkBuilder *builder)
     if(gtk_combo_box_get_active(GTK_COMBO_BOX(position_combo)) == -1)
         gtk_combo_box_set_active(GTK_COMBO_BOX(position_combo), GTK_CORNER_TOP_RIGHT);
 
-    do_not_disturb_switch = GTK_WIDGET(gtk_builder_get_object(builder, "do_not_disturb"));
-    xfconf_g_property_bind(channel, "/do-not-disturb", G_TYPE_BOOLEAN,
-                           G_OBJECT(do_not_disturb_switch), "active");
+    do_not_disturb_switch = GTK_WIDGET (gtk_builder_get_object (builder, "do_not_disturb"));
+    xfconf_g_property_bind (channel, "/do-not-disturb", G_TYPE_BOOLEAN,
+                            G_OBJECT (do_not_disturb_switch), "active");
+    /* Manually control the revealer for the infobar because of https://bugzilla.gnome.org/show_bug.cgi?id=710888 */
+    do_not_disturb_info = GTK_WIDGET (gtk_builder_get_object (builder, "do_not_disturb_info"));
+    gtk_revealer_set_reveal_child (GTK_REVEALER (do_not_disturb_info),
+                                   gtk_switch_get_active (GTK_SWITCH (do_not_disturb_switch)));
+    g_signal_connect (G_OBJECT (do_not_disturb_switch), "state-set",
+                      G_CALLBACK (xfce4_notifyd_do_not_disturb_activated), do_not_disturb_info);
 
     known_applications_listbox = GTK_WIDGET (gtk_builder_get_object (builder, "known_applications_listbox"));
     gtk_list_box_set_header_func (GTK_LIST_BOX (known_applications_listbox), display_header_func, NULL, NULL);
-    /* TODO: Make label nicer (markup)*/
-    /* TODO: Monitor xfconf for changes and update list */
-    no_known_apps_label = gtk_label_new ("Currently there are no known applications that send notifications.\nAs soon as an application sends a notification, it will appear in this list.");
-    gtk_list_box_set_placeholder (GTK_LIST_BOX (known_applications_listbox), no_known_apps_label);
-    /* FIXME: Handle non-existing channel for known apps */
-    known_applications = xfconf_channel_get_arrayv (channel, "/applications/known_applications");
-    muted_applications = xfconf_channel_get_arrayv (channel, "/applications/muted_applications");
-    if (known_applications != NULL) {
-        for (i = 0; i < known_applications->len; i++) {
-            GValue *known_application;
-            GtkWidget *hbox, *label, *mute_switch, *separator;
-            known_application = g_ptr_array_index(known_applications, i);
-            hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
-            label = gtk_label_new (g_value_get_string (known_application));
-            gtk_label_set_xalign (GTK_LABEL (label), 0);
-            mute_switch = gtk_switch_new ();
-            gtk_switch_set_active (GTK_SWITCH (mute_switch), TRUE);
-            gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 3);
-            gtk_box_pack_end (GTK_BOX (hbox), mute_switch, FALSE, TRUE, 3);
-            gtk_list_box_prepend (GTK_LIST_BOX (known_applications_listbox), hbox);
-            /* Set correct initial value as to whether an application is muted */
-            if (muted_applications != NULL) {
-                for (j = 0; j < muted_applications->len; j++) {
-                    GValue *muted_application;
-                    muted_application = g_ptr_array_index (muted_applications, j);
-                    if (g_str_match_string (g_value_get_string (muted_application), g_value_get_string (known_application), FALSE) == TRUE) {
-                        gtk_switch_set_active (GTK_SWITCH (mute_switch), FALSE);
-                        break;
-                    }
-                    else
-                        continue;
-                }
-            }
-            /* TODO: Connect a callback to the state-set signal of the switch to toggle mute */
-            g_signal_connect (G_OBJECT (mute_switch), "state-set", G_CALLBACK (xfce4_notifyd_switch_activated), channel);
-        }
-    }
-    xfconf_array_free (known_applications);
-    xfconf_array_free (muted_applications);
-    gtk_widget_show (no_known_apps_label);
-    gtk_widget_show_all (known_applications_listbox);
+
+    placeholder_label = gtk_label_new ("");
+    gtk_label_set_markup (GTK_LABEL (placeholder_label),"<b>Currently there are no known applications.</b>\nAs soon as an application sends a notification\nit will appear in this list.");
+    gtk_label_set_justify (GTK_LABEL (placeholder_label), GTK_JUSTIFY_CENTER);
+    gtk_widget_set_sensitive (placeholder_label, FALSE);
+    gtk_widget_set_margin_start (placeholder_label, 24);
+    gtk_widget_set_margin_end (placeholder_label, 24);
+    gtk_widget_set_margin_top (placeholder_label, 24);
+    gtk_widget_set_margin_bottom (placeholder_label, 24);
+
+    /* Initialize the list of known applications */
+    xfce4_notifyd_known_applications_changed (channel, KNOWN_APPLICATIONS_PROP, NULL, known_applications_listbox);
+    gtk_list_box_set_placeholder (GTK_LIST_BOX (known_applications_listbox), placeholder_label);
+    gtk_widget_show_all (placeholder_label);
     g_signal_connect (G_OBJECT (known_applications_listbox), "row-activated",
                       G_CALLBACK (xfce4_notifyd_row_activated),
                       channel);
+    g_signal_connect (G_OBJECT (channel),
+                      "property-changed::" KNOWN_APPLICATIONS_PROP,
+                      G_CALLBACK (xfce4_notifyd_known_applications_changed), known_applications_listbox);
 
     help_button = GTK_WIDGET(gtk_builder_get_object(builder, "help_btn"));
     g_signal_connect(G_OBJECT(help_button), "clicked",
diff --git a/xfce4-notifyd-config/xfce4-notifyd-config.glade b/xfce4-notifyd-config/xfce4-notifyd-config.glade
index 9e0f640..29d3bcd 100644
--- a/xfce4-notifyd-config/xfce4-notifyd-config.glade
+++ b/xfce4-notifyd-config/xfce4-notifyd-config.glade
@@ -325,12 +325,85 @@
                             <property name="margin_top">12</property>
                             <property name="margin_bottom">6</property>
                             <property name="hexpand">True</property>
-                            <property name="label" translatable="yes"><b>Show notifications:</b></property>
+                            <property name="label" translatable="yes"><b>Show notifications for</b></property>
                             <property name="use_markup">True</property>
                             <property name="xalign">0</property>
                           </object>
                           <packing>
                             <property name="left_attach">0</property>
+                            <property name="top_attach">2</property>
+                            <property name="width">2</property>
+                          </packing>
+                        </child>
+                        <child>
+                          <object class="GtkRevealer" id="do_not_disturb_info">
+                            <property name="visible">True</property>
+                            <property name="can_focus">False</property>
+                            <property name="margin_top">6</property>
+                            <property name="margin_bottom">12</property>
+                            <property name="transition_type">none</property>
+                            <property name="reveal_child">True</property>
+                            <child>
+                              <object class="GtkInfoBar" id="infobar1">
+                                <property name="visible">True</property>
+                                <property name="app_paintable">True</property>
+                                <property name="can_focus">False</property>
+                                <child internal-child="action_area">
+                                  <object class="GtkButtonBox" id="infobar-action_area1">
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">6</property>
+                                    <property name="layout_style">end</property>
+                                    <child>
+                                      <object class="GtkLabel" id="label10">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="label" translatable="yes">No notifications are currently shown except for messages marked as urgent.</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child internal-child="content_area">
+                                  <object class="GtkBox" id="infobar-content_area1">
+                                    <property name="can_focus">False</property>
+                                    <property name="spacing">16</property>
+                                    <child>
+                                      <object class="GtkImage" id="image1">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="icon_name">dialog-information-symbolic</property>
+                                        <property name="icon_size">1</property>
+                                      </object>
+                                      <packing>
+                                        <property name="expand">False</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">0</property>
+                                      </packing>
+                                    </child>
+                                  </object>
+                                  <packing>
+                                    <property name="expand">False</property>
+                                    <property name="fill">False</property>
+                                    <property name="position">0</property>
+                                  </packing>
+                                </child>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                            </child>
+                          </object>
+                          <packing>
+                            <property name="left_attach">0</property>
                             <property name="top_attach">1</property>
                             <property name="width">2</property>
                           </packing>
diff --git a/xfce4-notifyd/xfce-notify-daemon.c b/xfce4-notifyd/xfce-notify-daemon.c
index 2ead409..9941d3b 100644
--- a/xfce4-notifyd/xfce-notify-daemon.c
+++ b/xfce4-notifyd/xfce-notify-daemon.c
@@ -1044,13 +1044,16 @@ notify_update_known_applications (XfconfChannel *channel, gchar *new_app_name)
 {
     GPtrArray *known_applications;
     GValue *val;
+    gint index = 0;
+    gint index_before = 0;
+    gint index_after = 0;
 
     val = g_new0 (GValue, 1);
     g_value_init (val, G_TYPE_STRING);
     g_value_take_string (val, new_app_name);
 
     known_applications = xfconf_channel_get_arrayv (channel, "/applications/known_applications");
-    /* No known applications, initialize the application log */
+    /* No known applications, initialize the channel and property */
     if (known_applications == NULL || known_applications->len < 1) {
         GPtrArray *array;
         array = g_ptr_array_sized_new (1);
@@ -1067,13 +1070,18 @@ notify_update_known_applications (XfconfChannel *channel, gchar *new_app_name)
         for (i = 0; i < known_applications->len; i++) {
             GValue *known_application;
             known_application = g_ptr_array_index (known_applications, i);
-            if (g_str_match_string (new_app_name, g_value_get_string (known_application), FALSE) == TRUE) {
+            /* Remember where to put the application in alphabetical order */
+            if (g_ascii_strcasecmp (g_value_get_string (known_application), new_app_name) < 0)
+                index = i + 1;
+            /* Just to be sure that we've found the exact same application don't ignore the case when comparing strings here */
+            else if (g_strcmp0 (new_app_name, g_value_get_string (known_application)) == 0) {
                 application_is_known = TRUE;
                 break;
             }
         }
+        /* Unknown application, add it in alphabetical order */
         if (application_is_known == FALSE) {
-            g_ptr_array_add (known_applications, val);
+            g_ptr_array_insert (known_applications, index, val);
             if (!xfconf_channel_set_arrayv (channel, "/applications/known_applications", known_applications))
                 g_warning ("Could not add a new application to the log: %s", new_app_name);
         }
@@ -1095,12 +1103,11 @@ notify_application_is_muted (XfconfChannel *channel, gchar *new_app_name)
             GValue *muted_application;
             muted_application = g_ptr_array_index (muted_applications, i);
             if (g_str_match_string (new_app_name, g_value_get_string (muted_application), FALSE) == TRUE) {
-                g_warning ("Muted application: %s", new_app_name);
                 return TRUE;
             }
         }
     }
-    g_warning ("Found no match for %s", new_app_name);
+
     xfconf_array_free (muted_applications);
     return FALSE;
 }
@@ -1190,19 +1197,25 @@ notify_notify (XfceNotifyGBus *skeleton,
     if(expire_timeout == -1)
         expire_timeout = xndaemon->expire_timeout;
 
-    /* Only suppress notifications which are not marked as urgent in the "Do not disturb" mode  */
-    if (xndaemon->do_not_disturb == TRUE || notify_application_is_muted (xndaemon->settings, new_app_name) == TRUE)
+    /* Don't show notification bubbles in the "Do not disturb" mode or if the
+       application has been muted by the user. Exceptions are "urgent"
+       notifications which do not expire. */
+    if (expire_timeout != 0)
     {
-        if(xndaemon->close_timeout)
-            g_source_remove(xndaemon->close_timeout);
+        if (xndaemon->do_not_disturb == TRUE ||
+            notify_application_is_muted (xndaemon->settings, new_app_name) == TRUE)
+        {
+            /* Reset the close timeout since we're processing a new notification,
+               even if we're not showing a notification bubble */
+            if(xndaemon->close_timeout)
+                g_source_remove(xndaemon->close_timeout);
 
-        xndaemon->close_timeout = 0;
+            xndaemon->close_timeout = 0;
 
-        xfce_notify_gbus_complete_notify(skeleton, invocation, OUT_id);
-        return TRUE;
-        g_warning ("DND");
+            xfce_notify_gbus_complete_notify(skeleton, invocation, OUT_id);
+            return TRUE;
+        }
     }
-    g_free (new_app_name);
 
     if(replaces_id
        && (window = g_tree_lookup(xndaemon->active_notifications,

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list