[Xfce4-commits] [apps/xfce4-notifyd] 01/01: Add clear-log dialog that allows to clear the icon cache

noreply at xfce.org noreply at xfce.org
Wed Feb 7 08:24:17 CET 2018


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

o   c   h   o   s   i       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository apps/xfce4-notifyd.

commit 449bb82d4ebef85047e54d84f2656ba3e42c9a03
Author: Simon Steinbeiss <simon.steinbeiss at elfenbeinturm.at>
Date:   Wed Feb 7 01:34:33 2018 +0100

    Add clear-log dialog that allows to clear the icon cache
---
 common/xfce-notify-log.c               | 142 +++++++++++++++++++++++++++++++++
 common/xfce-notify-log.h               |   2 +-
 panel-plugin/notification-plugin-log.c |  12 ++-
 xfce4-notifyd-config/main.c            |  13 +--
 4 files changed, 162 insertions(+), 7 deletions(-)

diff --git a/common/xfce-notify-log.c b/common/xfce-notify-log.c
index e8cd416..1b9f23d 100644
--- a/common/xfce-notify-log.c
+++ b/common/xfce-notify-log.c
@@ -224,6 +224,78 @@ void xfce_notify_log_insert (const gchar *app_name,
     g_free (notify_log_path);
 }
 
+gchar *
+xfce_notify_get_icon_cache_size (void)
+{
+    gchar *notify_icon_cache_path = NULL;
+    gchar *size_string;
+
+    notify_icon_cache_path = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
+                                                          XFCE_NOTIFY_ICON_PATH, FALSE);
+    if (notify_icon_cache_path)
+    {
+        GFile *icon_folder;
+        guint64 disk_usage, num_dirs, num_files;
+
+        icon_folder = g_file_new_for_path (notify_icon_cache_path);
+
+        g_file_measure_disk_usage (icon_folder,
+                                   G_FILE_MEASURE_NONE,
+                                   NULL, NULL, NULL,
+                                   &disk_usage,
+                                   &num_dirs,
+                                   &num_files,
+                                   NULL);
+        size_string = g_strdup_printf ("%d icons / %.1lf MB",
+                                       (int) num_files, (gdouble) disk_usage / 1000000);
+        g_object_unref (icon_folder);
+    }
+    g_free (notify_icon_cache_path);
+    return size_string;
+}
+
+void xfce_notify_clear_icon_cache (void)
+{
+    gchar *notify_icon_cache_path = NULL;
+
+    notify_icon_cache_path = xfce_resource_save_location (XFCE_RESOURCE_CACHE,
+                                                          XFCE_NOTIFY_ICON_PATH, FALSE);
+
+    if (notify_icon_cache_path)
+    {
+        GFile *icon_folder;
+        GFileEnumerator *folder_contents;
+
+
+        icon_folder = g_file_new_for_path (notify_icon_cache_path);
+        folder_contents = g_file_enumerate_children (icon_folder,
+                                                     G_FILE_ATTRIBUTE_STANDARD_NAME,
+                                                     G_FILE_QUERY_INFO_NONE,
+                                                     NULL,
+                                                     NULL);
+        /* Iterate over the folder and delete each file */
+        while (TRUE)
+        {
+            GFile *icon_file;
+            if (!g_file_enumerator_iterate (folder_contents, NULL, &icon_file, NULL, NULL))
+                goto out;
+            if (!icon_file)
+                break;
+            if (!g_file_delete (icon_file, NULL, NULL))
+                g_warning ("Could not delete a notification icon: %s", notify_icon_cache_path);
+        }
+        out:
+            g_object_unref (folder_contents);
+
+        /* Delete the empty folder */
+        if (!g_file_delete (icon_folder, NULL, NULL))
+            g_warning ("Could not delete the notification icon cache: %s", notify_icon_cache_path);
+
+        g_object_unref (icon_folder);
+        g_free (notify_icon_cache_path);
+    }
+}
+
 void xfce_notify_log_clear (void)
 {
     gchar *notify_log_path = NULL;
@@ -241,3 +313,73 @@ void xfce_notify_log_clear (void)
         g_free (notify_log_path);
     }
 }
+
+static void
+xfce_notify_clear_log_dialog_cb (GtkWidget *dialog, gint response, gpointer user_data)
+{
+    GtkWidget *checkbutton = user_data;
+    gboolean active;
+
+    active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (checkbutton));
+
+    if (response == GTK_RESPONSE_DELETE_EVENT ||
+        response == GTK_RESPONSE_CANCEL)
+        return;
+    else if (active) {
+        xfce_notify_clear_icon_cache ();
+        xfce_notify_log_clear ();
+    }
+    else {
+        xfce_notify_log_clear ();
+    }
+}
+
+GtkWidget *xfce_notify_clear_log_dialog (void)
+{
+    GtkWidget *dialog, *grid, *icon, *label, *content_area, *checkbutton;
+    GtkDialogFlags flags = GTK_DIALOG_MODAL;
+    gchar *message;
+    const char *str = _("Clear just the log or the icon cache too?");
+    const char *format = "<span weight='bold' size='large'>%s</span>";
+    char *markup;
+
+    dialog = gtk_dialog_new_with_buttons (_("Clear notification log"),
+                                          NULL,
+                                          flags,
+                                          _("Cancel"),
+                                          GTK_RESPONSE_CANCEL,
+                                          _("Clear"),
+                                          GTK_RESPONSE_OK,
+                                          NULL);
+    content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
+    grid = gtk_grid_new ();
+    gtk_grid_set_column_spacing (GTK_GRID (grid), 12);
+    gtk_widget_set_margin_start (grid, 12);
+    gtk_widget_set_margin_end (grid, 12);
+    gtk_widget_set_margin_top (grid, 12);
+    gtk_widget_set_margin_bottom (grid, 12);
+
+    icon = gtk_image_new_from_icon_name ("edit-clear", GTK_ICON_SIZE_DIALOG);
+
+    message = g_strdup_printf ("%s (%s)",_("Clear icon cache"), xfce_notify_get_icon_cache_size ());
+    label = gtk_label_new (NULL);
+    markup = g_markup_printf_escaped (format, str);
+    gtk_label_set_markup (GTK_LABEL (label), markup);
+    g_free (markup);
+
+    checkbutton = gtk_check_button_new_with_label (message);
+
+    gtk_grid_attach (GTK_GRID (grid), icon, 0, 0, 1, 2);
+    gtk_grid_attach (GTK_GRID (grid), label, 1, 0, 1, 1);
+    gtk_grid_attach (GTK_GRID (grid), checkbutton, 1, 1, 1, 1);
+
+    gtk_container_add (GTK_CONTAINER (content_area), grid);
+    gtk_widget_show_all (dialog);
+
+    g_signal_connect (dialog, "response",
+                      G_CALLBACK (xfce_notify_clear_log_dialog_cb),
+                      checkbutton);
+    gtk_window_set_icon_name (GTK_WINDOW (dialog), "edit-clear");
+
+    return dialog;
+}
diff --git a/common/xfce-notify-log.h b/common/xfce-notify-log.h
index cfb1bac..88ca74f 100644
--- a/common/xfce-notify-log.h
+++ b/common/xfce-notify-log.h
@@ -40,6 +40,6 @@ void       xfce_notify_log_insert (const gchar *app_name,
                                    gint expire_timeout,
                                    const gchar **actions);
 
-void       xfce_notify_log_clear (void);
+GtkWidget *xfce_notify_clear_log_dialog (void);
 
 #endif /* __XFCE_NOTIFY_LOG_H_ */
diff --git a/panel-plugin/notification-plugin-log.c b/panel-plugin/notification-plugin-log.c
index 159af49..8cd606a 100644
--- a/panel-plugin/notification-plugin-log.c
+++ b/panel-plugin/notification-plugin-log.c
@@ -83,6 +83,16 @@ notification_plugin_menu_clear (GtkWidget *widget, gpointer user_data)
 
 
 
+static void
+notification_plugin_clear_log_dialog (void) {
+  GtkWidget *dialog;
+
+  dialog = xfce_notify_clear_log_dialog ();
+  gtk_dialog_run (GTK_DIALOG (dialog));
+  gtk_widget_destroy (dialog);
+}
+
+
 void
 notification_plugin_menu_populate (NotificationPlugin *notification_plugin)
 {
@@ -319,7 +329,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
 G_GNUC_END_IGNORE_DEPRECATIONS
   gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
   gtk_widget_show (mi);
-  g_signal_connect (mi, "activate", G_CALLBACK (xfce_notify_log_clear),
+  g_signal_connect (mi, "activate", G_CALLBACK (notification_plugin_clear_log_dialog),
                     NULL);
 
   mi = gtk_menu_item_new_with_mnemonic (_("_Notification settingsā€¦"));
diff --git a/xfce4-notifyd-config/main.c b/xfce4-notifyd-config/main.c
index 8e1b9ad..1240c8d 100644
--- a/xfce4-notifyd-config/main.c
+++ b/xfce4-notifyd-config/main.c
@@ -707,11 +707,14 @@ xfce4_notifyd_log_refresh (GtkButton *button, gpointer user_data) {
 static void xfce_notify_log_clear_button_clicked (GtkButton *button, gpointer user_data) {
     GtkWidget *log_listbox = ((NotificationLogWidgets *) user_data)->log_listbox;
     GtkCallback func = listbox_remove_all;
-
-    /* Clear the log file and empty the listbox widget */
-    gtk_container_foreach (GTK_CONTAINER (log_listbox), func, log_listbox);
-    xfce_notify_log_clear ();
-    xfce4_notifyd_log_populate (user_data);
+    GtkWidget *dialog;
+
+    dialog = xfce_notify_clear_log_dialog ();
+    gint result = gtk_dialog_run (GTK_DIALOG (dialog));
+    /* Clear the listbox widget too in case the log is cleared */
+    if (result == GTK_RESPONSE_OK)
+        gtk_container_foreach (GTK_CONTAINER (log_listbox), func, log_listbox);
+    gtk_widget_destroy (dialog);
 }
 
 static void xfce4_notifyd_show_help(GtkButton *button,

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


More information about the Xfce4-commits mailing list