[gnome-control-center/gbsneto/gtk4: 35/53] usage: Port to GTK4




commit 2d762680d2dc194a525fbaebe83a7da66e394f77
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date:   Thu Oct 21 12:12:05 2021 -0300

    usage: Port to GTK4

 panels/meson.build             |  2 +-
 panels/usage/cc-usage-panel.c  | 90 ++++++++++++++++++++++++++----------------
 panels/usage/cc-usage-panel.ui | 63 +++++++++++------------------
 shell/cc-panel-loader.c        |  4 +-
 4 files changed, 81 insertions(+), 78 deletions(-)
---
diff --git a/panels/meson.build b/panels/meson.build
index d480f2a06..63f3e9d60 100644
--- a/panels/meson.build
+++ b/panels/meson.build
@@ -26,7 +26,7 @@ panels = [
 #  'sharing',
   'sound',
   'universal-access',
-#  'usage',
+  'usage',
 #  'user-accounts',
 #  'wwan',
 ]
diff --git a/panels/usage/cc-usage-panel.c b/panels/usage/cc-usage-panel.c
index 39e67a527..ae8b54c7b 100644
--- a/panels/usage/cc-usage-panel.c
+++ b/panels/usage/cc-usage-panel.c
@@ -18,7 +18,6 @@
  * Author: Matthias Clasen <mclasen redhat com>
  */
 
-#include "list-box-helper.h"
 #include "cc-usage-panel.h"
 #include "cc-usage-resources.h"
 #include "cc-util.h"
@@ -108,7 +107,7 @@ set_purge_after_value_for_combo (GtkComboBox  *combo_box,
   gtk_combo_box_set_active (combo_box, i - 1);
 }
 
-static gboolean
+static GtkDialog *
 run_warning (CcUsagePanel *self,
              const gchar  *prompt,
              const gchar  *text,
@@ -117,12 +116,13 @@ run_warning (CcUsagePanel *self,
   GtkWindow *parent;
   GtkWidget *dialog;
   GtkWidget *button;
-  int result;
+  CcShell *shell;
 
-  parent = GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self)));
+  shell = cc_panel_get_shell (CC_PANEL (self));
+  parent = GTK_WINDOW (cc_shell_get_toplevel (shell));
 
   dialog = gtk_message_dialog_new (parent,
-                                   0,
+                                   GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
                                    GTK_MESSAGE_WARNING,
                                    GTK_BUTTONS_NONE,
                                    NULL);
@@ -138,25 +138,20 @@ run_warning (CcUsagePanel *self,
   button = gtk_dialog_get_widget_for_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
   gtk_style_context_add_class (gtk_widget_get_style_context (button), "destructive-action");
 
-  result = gtk_dialog_run (GTK_DIALOG (dialog));
-  gtk_widget_destroy (dialog);
+  gtk_window_present (GTK_WINDOW (dialog));
 
-  return result == GTK_RESPONSE_OK;
+  return GTK_DIALOG (dialog);
 }
 
 static void
-empty_trash (CcUsagePanel *self)
+on_empty_trash_warning_response_cb (GtkDialog    *dialog,
+                                    gint          response,
+                                    CcUsagePanel *self)
 {
   g_autoptr(GDBusConnection) bus = NULL;
-  gboolean result;
-
-  result = run_warning (self,
-                        _("Empty all items from Trash?"),
-                        _("All items in the Trash will be permanently deleted."),
-                        _("_Empty Trash"));
 
-  if (!result)
-    return;
+  if (response != GTK_RESPONSE_OK)
+    goto out;
 
   bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
   g_dbus_connection_call (bus,
@@ -165,21 +160,37 @@ empty_trash (CcUsagePanel *self)
                           "org.gnome.SettingsDaemon.Housekeeping",
                           "EmptyTrash",
                           NULL, NULL, 0, -1, NULL, NULL, NULL);
+
+out:
+  gtk_window_destroy (GTK_WINDOW (dialog));
 }
 
 static void
-purge_temp (CcUsagePanel *self)
+empty_trash (CcUsagePanel *self)
 {
-  g_autoptr(GDBusConnection) bus = NULL;
-  gboolean result;
+  GtkDialog *dialog;
 
-  result = run_warning (self,
-                        _("Delete all the temporary files?"),
-                        _("All the temporary files will be permanently deleted."),
-                        _("_Purge Temporary Files"));
+  dialog = run_warning (self,
+                        _("Empty all items from Trash?"),
+                        _("All items in the Trash will be permanently deleted."),
+                        _("_Empty Trash"));
 
-  if (!result)
-    return;
+  g_signal_connect_object (dialog,
+                           "response",
+                           G_CALLBACK (on_empty_trash_warning_response_cb),
+                           self,
+                           0);
+}
+
+static void
+on_purge_temp_warning_response_cb (GtkDialog    *dialog,
+                                   gint          response,
+                                   CcUsagePanel *self)
+{
+  g_autoptr(GDBusConnection) bus = NULL;
+
+  if (response != GTK_RESPONSE_OK)
+    goto out;
 
   bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
   g_dbus_connection_call (bus,
@@ -188,6 +199,25 @@ purge_temp (CcUsagePanel *self)
                           "org.gnome.SettingsDaemon.Housekeeping",
                           "RemoveTempFiles",
                           NULL, NULL, 0, -1, NULL, NULL, NULL);
+
+out:
+  gtk_window_destroy (GTK_WINDOW (dialog));
+}
+static void
+purge_temp (CcUsagePanel *self)
+{
+  GtkDialog *dialog;
+
+  dialog = run_warning (self,
+                        _("Delete all the temporary files?"),
+                        _("All the temporary files will be permanently deleted."),
+                        _("_Purge Temporary Files"));
+
+  g_signal_connect_object (dialog,
+                           "response",
+                           G_CALLBACK (on_purge_temp_warning_response_cb),
+                           self,
+                           0);
 }
 
 static void
@@ -264,14 +294,6 @@ cc_usage_panel_init (CcUsagePanel *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  gtk_list_box_set_header_func (self->usage_list_box,
-                                cc_list_box_update_header_func,
-                                NULL, NULL);
-
-  gtk_list_box_set_header_func (self->trash_list_box,
-                                cc_list_box_update_header_func,
-                                NULL, NULL);
-
   self->privacy_settings = g_settings_new ("org.gnome.desktop.privacy");
 
   g_settings_bind (self->privacy_settings,
diff --git a/panels/usage/cc-usage-panel.ui b/panels/usage/cc-usage-panel.ui
index 7baf997e2..8478a7628 100644
--- a/panels/usage/cc-usage-panel.ui
+++ b/panels/usage/cc-usage-panel.ui
@@ -2,14 +2,11 @@
 <!-- Generated with glade 3.18.1 -->
 <interface>
   <template class="CcUsagePanel" parent="CcPanel">
-    <property name="visible">True</property>
     <child>
       <object class="GtkScrolledWindow">
-        <property name="visible">true</property>
         <property name="hscrollbar-policy">never</property>
         <child>
-          <object class="HdyClamp">
-            <property name="visible">True</property>
+          <object class="AdwClamp">
             <property name="margin_top">32</property>
             <property name="margin_bottom">32</property>
             <property name="margin_start">12</property>
@@ -18,14 +15,12 @@
             <!-- File History -->
             <child>
               <object class="GtkBox">
-                <property name="visible">true</property>
                 <property name="orientation">vertical</property>
                 <property name="hexpand">1</property>
                 <property name="spacing">12</property>
 
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">true</property>
                     <property name="label" translatable="yes">File History</property>
                     <property name="xalign">0</property>
                     <attributes>
@@ -36,7 +31,6 @@
 
                 <child>
                   <object class="GtkLabel" id="usage_description_label">
-                    <property name="visible">true</property>
                     <property name="margin-bottom">12</property>
                     <property name="label" translatable="yes">File history keeps a record of files that you 
have used. This information is shared between applications, and makes it easier to find files that you might 
want to use.</property>
                     <property name="wrap">1</property>
@@ -47,18 +41,18 @@
 
                 <child>
                   <object class="GtkListBox" id="usage_list_box">
-                    <property name="visible">true</property>
                     <property name="can-focus">1</property>
                     <property name="selection-mode">none</property>
+                    <style>
+                      <class name="content" />
+                    </style>
                     <child>
-                      <object class="HdyActionRow">
-                        <property name="visible">true</property>
+                      <object class="AdwActionRow">
                         <property name="title" translatable="yes">File H_istory</property>
                         <property name="activatable-widget">recently_used_switch</property>
                         <property name="use-underline">true</property>
                         <child>
                           <object class="GtkSwitch" id="recently_used_switch">
-                            <property name="visible">true</property>
                             <property name="halign">end</property>
                             <property name="valign">center</property>
                           </object>
@@ -67,28 +61,26 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">true</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">true</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <child>
                               <object class="GtkLabel">
-                                <property name="visible">true</property>
                                 <property name="label" translatable="yes">File _History Duration</property>
+                                <property name="hexpand">True</property>
+                                <property name="vexpand">True</property>
                                 <property name="use_underline">1</property>
                                 <property name="mnemonic_widget">retain_history_combo</property>
                                 <property name="sensitive" bind-source="retain_history_combo" 
bind-property="sensitive"/>
                                 <property name="xalign">0</property>
                                 <property name="valign">center</property>
                               </object>
-                              <packing>
-                                <property name="expand">1</property>
-                              </packing>
                             </child>
                             <child>
                               <object class="GtkComboBoxText" id="retain_history_combo">
-                                <property name="visible">true</property>
                                 <property name="valign">center</property>
                                 <property name="entry_text_column">0</property>
                                 <property name="model">retain_history_model</property>
@@ -107,14 +99,12 @@
 
                 <child>
                   <object class="GtkBox">
-                    <property name="visible">true</property>
                     <property name="hexpand">true</property>
                     <property name="halign">end</property>
                     <property name="homogeneous">true</property>
                     <property name="spacing">12</property>
                     <child>
                       <object class="GtkButton" id="clear_recent_button">
-                        <property name="visible">true</property>
                         <property name="valign">center</property>
                         <property name="label" translatable="yes">_Clear History…</property>
                         <property name="use_underline">1</property>
@@ -130,7 +120,6 @@
                 <!-- Trash & Temporary Files -->
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">true</property>
                     <property name="margin-top">18</property>
                     <property name="label" translatable="yes">Trash &amp; Temporary Files</property>
                     <property name="xalign">0</property>
@@ -141,7 +130,6 @@
                 </child>
                 <child>
                   <object class="GtkLabel">
-                    <property name="visible">true</property>
                     <property name="label" translatable="yes">Trash and temporary files can sometimes 
include personal or sensitive information. Automatically deleting them can help to protect privacy.</property>
                     <property name="wrap">1</property>
                     <property name="max-width-chars">50</property>
@@ -150,18 +138,18 @@
                 </child>
                 <child>
                   <object class="GtkListBox" id="trash_list_box">
-                    <property name="visible">true</property>
                     <property name="can-focus">1</property>
                     <property name="selection-mode">none</property>
+                    <style>
+                      <class name="content" />
+                    </style>
                     <child>
-                      <object class="HdyActionRow">
-                        <property name="visible">true</property>
+                      <object class="AdwActionRow">
                         <property name="title" translatable="yes">Automatically Delete _Trash 
Content</property>
                         <property name="activatable-widget">purge_trash_switch</property>
                         <property name="use-underline">true</property>
                         <child>
                           <object class="GtkSwitch" id="purge_trash_switch">
-                            <property name="visible">true</property>
                             <property name="halign">end</property>
                             <property name="valign">center</property>
                           </object>
@@ -169,14 +157,12 @@
                       </object>
                     </child>
                     <child>
-                      <object class="HdyActionRow">
-                        <property name="visible">true</property>
+                      <object class="AdwActionRow">
                         <property name="title" translatable="yes">Automatically Delete Temporary 
_Files</property>
                         <property name="activatable-widget">purge_temp_switch</property>
                         <property name="use-underline">true</property>
                         <child>
                           <object class="GtkSwitch" id="purge_temp_switch">
-                            <property name="visible">true</property>
                             <property name="halign">end</property>
                             <property name="valign">center</property>
                           </object>
@@ -185,28 +171,26 @@
                     </child>
                     <child>
                       <object class="GtkListBoxRow">
-                        <property name="visible">true</property>
                         <child>
                           <object class="GtkBox">
-                            <property name="visible">true</property>
-                            <property name="margin">12</property>
+                            <property name="margin-top">12</property>
+                            <property name="margin-bottom">12</property>
+                            <property name="margin-start">12</property>
+                            <property name="margin-end">12</property>
                             <child>
                               <object class="GtkLabel">
-                                <property name="visible">true</property>
                                 <property name="label" translatable="yes">Automatically Delete 
_Period</property>
                                 <property name="use_underline">1</property>
+                                <property name="hexpand">True</property>
+                                <property name="vexpand">True</property>
                                 <property name="mnemonic_widget">purge_after_combo</property>
                                 <property name="sensitive" bind-source="purge_after_combo" 
bind-property="sensitive"/>
                                 <property name="xalign">0</property>
                                 <property name="valign">center</property>
                               </object>
-                              <packing>
-                                <property name="expand">1</property>
-                              </packing>
                             </child>
                             <child>
                               <object class="GtkComboBoxText" id="purge_after_combo">
-                                <property name="visible">true</property>
                                 <property name="valign">center</property>
                                 <property name="entry_text_column">0</property>
                                 <property name="model">purge_after_model</property>
@@ -225,14 +209,12 @@
 
                 <child>
                   <object class="GtkBox">
-                    <property name="visible">true</property>
                     <property name="hexpand">true</property>
                     <property name="halign">end</property>
                     <property name="homogeneous">true</property>
                     <property name="spacing">12</property>
                     <child>
                       <object class="GtkButton" id="purge_trash_button">
-                        <property name="visible">true</property>
                         <property name="halign">end</property>
                         <property name="valign">center</property>
                         <property name="label" translatable="yes">_Empty Trash…</property>
@@ -244,7 +226,6 @@
                     </child>
                     <child>
                       <object class="GtkButton" id="purge_temp_button">
-                        <property name="visible">true</property>
                         <property name="halign">end</property>
                         <property name="valign">center</property>
                         <property name="label" translatable="yes">_Delete Temporary Files…</property>
diff --git a/shell/cc-panel-loader.c b/shell/cc-panel-loader.c
index bd0bbb960..396d97e8f 100644
--- a/shell/cc-panel-loader.c
+++ b/shell/cc-panel-loader.c
@@ -71,7 +71,7 @@ extern GType cc_ua_panel_get_type (void);
 extern GType cc_location_panel_get_type (void);
 extern GType cc_camera_panel_get_type (void);
 extern GType cc_microphone_panel_get_type (void);
-//extern GType cc_usage_panel_get_type (void);
+extern GType cc_usage_panel_get_type (void);
 extern GType cc_lock_panel_get_type (void);
 //extern GType cc_diagnostics_panel_get_type (void);
 
@@ -132,7 +132,7 @@ static CcPanelLoaderVtable default_panels[] =
   //PANEL_TYPE("thunderbolt",      cc_bolt_panel_get_type,                 NULL),
 #endif
   PANEL_TYPE("universal-access", cc_ua_panel_get_type,                   NULL),
-  //PANEL_TYPE("usage",            cc_usage_panel_get_type,                NULL),
+  PANEL_TYPE("usage",            cc_usage_panel_get_type,                NULL),
   //PANEL_TYPE("user-accounts",    cc_user_panel_get_type,                 NULL),
 #ifdef BUILD_WACOM
   //PANEL_TYPE("wacom",            cc_wacom_panel_get_type,                cc_wacom_panel_static_init_func),


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