From 1e7eafc27c6aa82a8421a90e222660b0dce690a5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ga=C3=ABl=20Bonithon?= <gael@xfce.org>
Date: Mon, 14 Oct 2024 19:51:59 +0200
Subject: [PATCH] settings: Hide critical action warning if upower action ==
 Ignore

Amends: f798a40389174341a64e7090d5d9f5174453cb34
Related: https://gitlab.xfce.org/xfce/xfce4-power-manager/-/issues/146#note_95193
---
 data/interfaces/xfpm-settings.ui |  2 +-
 settings/xfpm-settings.c         | 17 +++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/data/interfaces/xfpm-settings.ui b/data/interfaces/xfpm-settings.ui
index 216b882a..37171afb 100644
--- a/data/interfaces/xfpm-settings.ui
+++ b/data/interfaces/xfpm-settings.ui
@@ -1176,7 +1176,7 @@
                                   </packing>
                                 </child>
                                 <child>
-                                  <object class="GtkMenuButton">
+                                  <object class="GtkMenuButton" id="critical-warning-button">
                                     <property name="visible">True</property>
                                     <property name="can-focus">True</property>
                                     <property name="image">image4</property>
diff --git a/settings/xfpm-settings.c b/settings/xfpm-settings.c
index 9e31b12a..47f3207a 100644
--- a/settings/xfpm-settings.c
+++ b/settings/xfpm-settings.c
@@ -811,9 +811,7 @@ xfpm_settings_others (XfconfChannel *channel,
   {
     GtkTreeIter iter;
     GtkTreeModel *model;
-    GtkWidget *label;
     const gchar *action;
-    gchar *text;
 
     critical_level = GTK_WIDGET (gtk_builder_get_object (xml, "critical-power-level-spin"));
     gtk_widget_set_tooltip_text (critical_level, _("When all the power sources of the computer reach this charge level"));
@@ -835,11 +833,18 @@ xfpm_settings_others (XfconfChannel *channel,
         break;
     } while (gtk_tree_model_iter_next (model, &iter));
 
-    label = GTK_WIDGET (gtk_builder_get_object (xml, "critical-warning-label"));
     action = upower != NULL ? up_client_get_critical_action (upower) : "Unknown";
-    text = g_strdup_printf (_("Make sure you set a sufficiently high value here, otherwise the system will trigger its own action before xfce4-power-manager, without being able to prevent it or know exactly when it will do so. The action triggered by the system in this case will be: %s."), action);
-    gtk_label_set_text (GTK_LABEL (label), text);
-    g_free (text);
+    if (g_strcmp0 (action, "Ignore") == 0)
+    {
+      gtk_widget_hide (GTK_WIDGET (gtk_builder_get_object (xml, "critical-warning-button")));
+    }
+    else
+    {
+      GtkWidget *label = GTK_WIDGET (gtk_builder_get_object (xml, "critical-warning-label"));
+      gchar *text = g_strdup_printf (_("Make sure you set a sufficiently high value here, otherwise the system will trigger its own action before xfce4-power-manager, without being able to prevent it or know exactly when it will do so. The action triggered by the system in this case will be: %s."), action);
+      gtk_label_set_text (GTK_LABEL (label), text);
+      g_free (text);
+    }
   }
   else
   {
-- 
GitLab