[gnome-software/1722-flatpak-handle-more-well-known-filesystem-permissions: 7/10] gs-app-details-page: Extract permission row addition into a function




commit 27b854e4f7df615cd1ccc4093d2f84661bb186c5
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jun 17 10:32:00 2022 +0200

    gs-app-details-page: Extract permission row addition into a function
    
    It will be reused in the following commit.

 src/gs-app-details-page.c | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-app-details-page.c b/src/gs-app-details-page.c
index ee902793f..b210a9703 100644
--- a/src/gs-app-details-page.c
+++ b/src/gs-app-details-page.c
@@ -82,30 +82,42 @@ static const struct {
 };
 
 static void
-populate_permissions_section (GsAppDetailsPage *page, GsAppPermissionsFlags permissions)
+add_permissions_row (GsAppDetailsPage *page,
+                    const gchar *title,
+                    const gchar *subtitle,
+                    gboolean is_warning_row)
 {
-       gs_widget_remove_all (page->permissions_section_list, (GsRemoveFunc) gtk_list_box_remove);
+       GtkWidget *row, *image;
 
-       for (gsize i = 0; i < G_N_ELEMENTS (permission_display_data); i++) {
-               GtkWidget *row, *image;
+       row = adw_action_row_new ();
+       if (is_warning_row)
+               gtk_style_context_add_class (gtk_widget_get_style_context (row), "permission-row-warning");
 
-               if ((permissions & permission_display_data[i].permission) == 0)
-                       continue;
+       image = gtk_image_new_from_icon_name ("dialog-warning-symbolic");
+       if (!is_warning_row)
+               gtk_widget_set_opacity (image, 0);
+
+       adw_action_row_add_prefix (ADW_ACTION_ROW (row), image);
+       adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), title);
+       adw_action_row_set_subtitle (ADW_ACTION_ROW (row), subtitle);
 
-               row = adw_action_row_new ();
-               if ((permission_display_data[i].permission & ~MEDIUM_PERMISSIONS) != 0) {
-                       gtk_style_context_add_class (gtk_widget_get_style_context (row), 
"permission-row-warning");
-               }
+       gtk_list_box_append (GTK_LIST_BOX (page->permissions_section_list), row);
+}
 
-               image = gtk_image_new_from_icon_name ("dialog-warning-symbolic");
-               if ((permission_display_data[i].permission & ~MEDIUM_PERMISSIONS) == 0)
-                       gtk_widget_set_opacity (image, 0);
+static void
+populate_permissions_section (GsAppDetailsPage *page,
+                             GsAppPermissionsFlags permissions)
+{
+       gs_widget_remove_all (page->permissions_section_list, (GsRemoveFunc) gtk_list_box_remove);
 
-               adw_action_row_add_prefix (ADW_ACTION_ROW (row), image);
-               adw_preferences_row_set_title (ADW_PREFERENCES_ROW (row), 
_(permission_display_data[i].title));
-               adw_action_row_set_subtitle (ADW_ACTION_ROW (row), _(permission_display_data[i].subtitle));
+       for (gsize i = 0; i < G_N_ELEMENTS (permission_display_data); i++) {
+               if ((permissions & permission_display_data[i].permission) == 0)
+                       continue;
 
-               gtk_list_box_append (GTK_LIST_BOX (page->permissions_section_list), row);
+               add_permissions_row (page,
+                       _(permission_display_data[i].title),
+                       _(permission_display_data[i].subtitle),
+                       (permission_display_data[i].permission & ~MEDIUM_PERMISSIONS) != 0);
        }
 }
 


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