[gnome-control-center] applications: Update snap permissions code to recent changes



commit 99f27e802fe14bdf6e41227353836678b759ddcd
Author: Robert Ancell <robert ancell canonical com>
Date:   Tue May 17 12:10:52 2022 +1200

    applications: Update snap permissions code to recent changes
    
    Fixes #1845

 panels/applications/cc-applications-panel.c | 43 +++++++++++---------------
 panels/applications/cc-snap-row.c           |  8 ++---
 panels/applications/cc-snap-row.h           |  4 +--
 panels/applications/cc-snap-row.ui          | 48 +++++++++--------------------
 4 files changed, 38 insertions(+), 65 deletions(-)
---
diff --git a/panels/applications/cc-applications-panel.c b/panels/applications/cc-applications-panel.c
index dfa9ef184..e3bdab611 100644
--- a/panels/applications/cc-applications-panel.c
+++ b/panels/applications/cc-applications-panel.c
@@ -92,7 +92,7 @@ struct _CcApplicationsPanel
   GtkWidget       *settings_box;
   GtkButton       *install_button;
 
-  GtkWidget       *integration_section;
+  AdwPreferencesGroup *integration_section;
   CcToggleRow     *notification;
   CcToggleRow     *background;
   CcToggleRow     *wallpaper;
@@ -111,6 +111,9 @@ struct _CcApplicationsPanel
   GtkDialog       *builtin_dialog;
   AdwPreferencesGroup *builtin_group;
   GtkListBox      *builtin_list;
+#ifdef HAVE_SNAP
+  GList           *snap_permission_rows;
+#endif
 
   GtkButton       *handler_reset;
   GtkDialog       *handler_dialog;
@@ -650,20 +653,11 @@ location_cb (CcApplicationsPanel *self)
 static void
 remove_snap_permissions (CcApplicationsPanel *self)
 {
-  g_autoptr(GList) rows = NULL;
-  GList *link;
-
-  rows = gtk_container_get_children (GTK_CONTAINER (self->permission_list));
-  for (link = rows; link; link = link->next)
-    {
-      GtkWidget *row = link->data;
-
-      if (row == GTK_WIDGET (self->builtin))
-        break;
+  GList *l;
 
-      if (CC_IS_SNAP_ROW (row))
-        gtk_container_remove (GTK_CONTAINER (self->permission_list), GTK_WIDGET (row));
-    }
+  for (l = self->snap_permission_rows; l; l = l->next)
+    adw_preferences_group_remove (self->integration_section, l->data);
+  g_clear_pointer (&self->snap_permission_rows, g_list_free);
 }
 
 static gboolean
@@ -672,8 +666,6 @@ add_snap_permissions (CcApplicationsPanel *self,
                       const gchar         *app_id)
 {
   const gchar *snap_name;
-  g_autoptr(GList) rows = NULL;
-  gint index;
   g_autoptr(SnapdClient) client = NULL;
   g_autoptr(GPtrArray) interfaces = NULL;
   g_autoptr(GPtrArray) plugs = NULL;
@@ -687,10 +679,6 @@ add_snap_permissions (CcApplicationsPanel *self,
     return FALSE;
   snap_name = app_id + strlen (PORTAL_SNAP_PREFIX);
 
-  rows = gtk_container_get_children (GTK_CONTAINER (self->permission_list));
-  index = g_list_index (rows, self->builtin);
-  g_assert (index >= 0);
-
   client = snapd_client_new ();
 
   interfaces = snapd_client_get_interfaces2_sync (client,
@@ -753,9 +741,8 @@ add_snap_permissions (CcApplicationsPanel *self,
         }
 
       row = cc_snap_row_new (cc_panel_get_cancellable (CC_PANEL (self)), interface, plug, available_slots);
-      gtk_widget_show (GTK_WIDGET (row));
-      gtk_list_box_insert (GTK_LIST_BOX (self->permission_list), GTK_WIDGET (row), index);
-      index++;
+      adw_preferences_group_add (self->integration_section, GTK_WIDGET (row));
+      self->snap_permission_rows = g_list_prepend (self->snap_permission_rows, row);
       added++;
     }
 
@@ -885,6 +872,10 @@ update_integration_section (CcApplicationsPanel *self,
       gtk_widget_hide (GTK_WIDGET (self->shortcuts));
     }
 
+#ifdef HAVE_SNAP
+  remove_snap_permissions (self);
+#endif
+
   if (portal_app_id != NULL)
     {
       g_clear_object (&self->notification_settings);
@@ -931,7 +922,6 @@ update_integration_section (CcApplicationsPanel *self,
       has_any |= set;
 
     #ifdef HAVE_SNAP
-      remove_snap_permissions (self);
       has_any |= add_snap_permissions (self, info, portal_app_id);
     #endif
     }
@@ -955,7 +945,7 @@ update_integration_section (CcApplicationsPanel *self,
       gtk_widget_hide (GTK_WIDGET (self->no_location));
     }
 
-  gtk_widget_set_visible (self->integration_section, has_any);
+  gtk_widget_set_visible (GTK_WIDGET (self->integration_section), has_any);
 }
 
 /* --- handler section --- */
@@ -1610,6 +1600,9 @@ cc_applications_panel_dispose (GObject *object)
   CcApplicationsPanel *self = CC_APPLICATIONS_PANEL (object);
 
   remove_all_handler_rows (self);
+#ifdef HAVE_SNAP
+  remove_snap_permissions (self);
+#endif
   g_clear_object (&self->monitor);
   g_clear_object (&self->perm_store);
 
diff --git a/panels/applications/cc-snap-row.c b/panels/applications/cc-snap-row.c
index 40a7fc407..5928ad3e7 100644
--- a/panels/applications/cc-snap-row.c
+++ b/panels/applications/cc-snap-row.c
@@ -26,9 +26,8 @@
 
 struct _CcSnapRow
 {
-  GtkListBoxRow parent;
+  AdwActionRow parent;
 
-  GtkLabel     *title_label;
   GtkSwitch    *slot_toggle;
   GtkComboBox  *slots_combo;
   GtkListStore *slots_combo_model;
@@ -40,7 +39,7 @@ struct _CcSnapRow
   GPtrArray    *slots;
 };
 
-G_DEFINE_TYPE (CcSnapRow, cc_snap_row, GTK_TYPE_LIST_BOX_ROW)
+G_DEFINE_TYPE (CcSnapRow, cc_snap_row, ADW_TYPE_ACTION_ROW)
 
 typedef struct
 {
@@ -245,7 +244,6 @@ cc_snap_row_class_init (CcSnapRowClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/control-center/applications/cc-snap-row.ui");
 
-  gtk_widget_class_bind_template_child (widget_class, CcSnapRow, title_label);
   gtk_widget_class_bind_template_child (widget_class, CcSnapRow, slot_toggle);
   gtk_widget_class_bind_template_child (widget_class, CcSnapRow, slots_combo);
   gtk_widget_class_bind_template_child (widget_class, CcSnapRow, slots_combo_model);
@@ -295,7 +293,7 @@ cc_snap_row_new (GCancellable *cancellable, SnapdInterface *interface, SnapdPlug
     label = snapd_interface_make_label (interface);
   else
     label = g_strdup (snapd_plug_get_interface (plug));
-  gtk_label_set_label (self->title_label, label);
+  adw_preferences_row_set_title (ADW_PREFERENCES_ROW (self), label);
 
   /* Add option into combo box */
   gtk_list_store_append (self->slots_combo_model, &iter);
diff --git a/panels/applications/cc-snap-row.h b/panels/applications/cc-snap-row.h
index d37bb804f..11214135a 100644
--- a/panels/applications/cc-snap-row.h
+++ b/panels/applications/cc-snap-row.h
@@ -20,13 +20,13 @@
 
 #pragma once
 
-#include <gtk/gtk.h>
+#include <adwaita.h>
 #include <snapd-glib/snapd-glib.h>
 
 G_BEGIN_DECLS
 
 #define CC_TYPE_SNAP_ROW (cc_snap_row_get_type())
-G_DECLARE_FINAL_TYPE (CcSnapRow, cc_snap_row, CC, SNAP_ROW, GtkListBoxRow)
+G_DECLARE_FINAL_TYPE (CcSnapRow, cc_snap_row, CC, SNAP_ROW, AdwActionRow)
 
 CcSnapRow* cc_snap_row_new      (GCancellable   *cancellable,
                                  SnapdInterface *interface,
diff --git a/panels/applications/cc-snap-row.ui b/panels/applications/cc-snap-row.ui
index 2d83f379d..fed545f9e 100644
--- a/panels/applications/cc-snap-row.ui
+++ b/panels/applications/cc-snap-row.ui
@@ -8,45 +8,27 @@
       <column type="gchararray"/>
     </columns>
   </object>
-  <template class="CcSnapRow" parent="GtkListBoxRow">
-    <property name="visible">True</property>
+  <template class="CcSnapRow" parent="AdwActionRow">
     <property name="can-focus">True</property>
     <property name="activatable">False</property>
     <child>
-      <object class="GtkBox">
-        <property name="visible">True</property>
-        <property name="border-width">12</property>
-        <property name="spacing">12</property>
+      <object class="GtkSwitch" id="slot_toggle">
+        <property name="valign">center</property>
+        <signal name="notify::active" handler="switch_changed_cb" swapped="yes"/>
+      </object>
+    </child>
+    <child>
+      <object class="GtkComboBox" id="slots_combo">
+        <property name="valign">center</property>
+        <property name="model">slots_combo_model</property>
+        <signal name="changed" handler="combo_changed_cb" swapped="yes"/>
         <child>
-          <object class="GtkLabel" id="title_label">
-            <property name="visible">True</property>
-            <property name="xalign">0</property>
-            <property name="hexpand">1</property>
+          <object class="GtkCellRendererText">
             <property name="ellipsize">end</property>
           </object>
-        </child>
-        <child>
-          <object class="GtkSwitch" id="slot_toggle">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <signal name="notify::active" handler="switch_changed_cb" swapped="yes"/>
-          </object>
-        </child>
-        <child>
-          <object class="GtkComboBox" id="slots_combo">
-            <property name="visible">True</property>
-            <property name="valign">center</property>
-            <property name="model">slots_combo_model</property>
-            <signal name="changed" handler="combo_changed_cb" swapped="yes"/>
-            <child>
-              <object class="GtkCellRendererText">
-                <property name="ellipsize">end</property>
-              </object>
-              <attributes>
-                <attribute name="text">1</attribute>
-              </attributes>
-            </child>
-          </object>
+          <attributes>
+            <attribute name="text">1</attribute>
+          </attributes>
         </child>
       </object>
     </child>


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