[gnome-software: 1/2] app-details-page: UI overhaul




commit 4abe3ade1a45f6d3f1fec4f3fe18673cc53c68b8
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri Oct 8 09:11:43 2021 +0200

    app-details-page: UI overhaul
    
    This refreshes the page's style, making it more in line with modern
    GNOME UIs.

 src/gs-app-details-page.c  |  89 ++++++++++++++---------------
 src/gs-app-details-page.ui | 137 ++++++++++++++++-----------------------------
 2 files changed, 91 insertions(+), 135 deletions(-)
---
diff --git a/src/gs-app-details-page.c b/src/gs-app-details-page.c
index 6f34ba819..938ccdd78 100644
--- a/src/gs-app-details-page.c
+++ b/src/gs-app-details-page.c
@@ -47,15 +47,11 @@ struct _GsAppDetailsPage
        GtkBox           parent_instance;
 
        GtkWidget       *back_button;
-       GtkWidget       *box_header;
        GtkWidget       *header_bar;
-       GtkWidget       *image_icon;
        GtkWidget       *label_details;
-       GtkWidget       *label_name;
-       GtkWidget       *label_summary;
-       GtkWidget       *permissions_section_box;
-       GtkWidget       *permissions_section_content;
-       GtkWidget       *scrolledwindow_details;
+       GtkWidget       *permissions_section;
+       GtkWidget       *permissions_section_list;
+       GtkWidget       *status_page;
        AdwWindowTitle  *window_title;
 
        GsApp           *app;  /* (owned) (nullable) */
@@ -86,16 +82,15 @@ static const struct {
 static void
 populate_permissions_section (GsAppDetailsPage *page, GsAppPermissions permissions)
 {
-       gs_widget_remove_all (page->permissions_section_content, (GsRemoveFunc) gtk_box_remove);
+       gs_widget_remove_all (page->permissions_section_list, (GsRemoveFunc) gtk_list_box_remove);
 
        for (gsize i = 0; i < G_N_ELEMENTS (permission_display_data); i++) {
-               GtkWidget *row, *image, *box, *label;
+               GtkWidget *row, *image;
 
                if ((permissions & permission_display_data[i].permission) == 0)
                        continue;
 
-               row = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-               gtk_widget_show (row);
+               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");
                }
@@ -104,25 +99,11 @@ populate_permissions_section (GsAppDetailsPage *page, GsAppPermissions permissio
                if ((permission_display_data[i].permission & ~MEDIUM_PERMISSIONS) == 0)
                        gtk_widget_set_opacity (image, 0);
 
-               gtk_widget_show (image);
-               gtk_box_append (GTK_BOX (row), image);
+               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));
 
-               box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
-               gtk_widget_show (box);
-               gtk_box_append (GTK_BOX (row), box);
-
-               label = gtk_label_new (_(permission_display_data[i].title));
-               gtk_label_set_xalign (GTK_LABEL (label), 0);
-               gtk_widget_show (label);
-               gtk_box_append (GTK_BOX (row), label);
-
-               label = gtk_label_new (_(permission_display_data[i].subtitle));
-               gtk_label_set_xalign (GTK_LABEL (label), 0);
-               gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label");
-               gtk_widget_show (label);
-               gtk_box_append (GTK_BOX (row), label);
-
-               gtk_box_append (GTK_BOX (page->permissions_section_content), row);
+               gtk_list_box_append (GTK_LIST_BOX (page->permissions_section_list), row);
        }
 }
 
@@ -133,6 +114,10 @@ set_updates_description_ui (GsAppDetailsPage *page, GsApp *app)
        g_autoptr(GIcon) icon = NULL;
        guint icon_size;
        const gchar *update_details;
+#if ADW_CHECK_VERSION(1, 0, 1)
+       GdkDisplay *display;
+       g_autoptr (GtkIconPaintable) paintable = NULL;
+#endif
 
        /* FIXME support app == NULL */
 
@@ -163,7 +148,6 @@ set_updates_description_ui (GsAppDetailsPage *page, GsApp *app)
        }
 
        /* set update header */
-       gtk_widget_set_visible (page->box_header, kind == AS_COMPONENT_KIND_DESKTOP_APP);
        update_details = gs_app_get_update_details (app);
        if (update_details == NULL) {
                /* TRANSLATORS: this is where the packager did not write
@@ -171,39 +155,56 @@ set_updates_description_ui (GsAppDetailsPage *page, GsApp *app)
                update_details = _("No update description available.");
        }
        gtk_label_set_label (GTK_LABEL (page->label_details), update_details);
-       gtk_label_set_label (GTK_LABEL (page->label_name), gs_app_get_name (app));
-       gtk_label_set_label (GTK_LABEL (page->label_summary), gs_app_get_summary (app));
+       adw_status_page_set_title (ADW_STATUS_PAGE (page->status_page), gs_app_get_name (app));
+       adw_status_page_set_description (ADW_STATUS_PAGE (page->status_page), gs_app_get_summary (app));
 
        /* set the icon; fall back to 64px if 96px isn’t available, which sometimes
         * happens at 2× scale factor (hi-DPI) */
        icon_size = 96;
        icon = gs_app_get_icon_for_size (app,
                                         icon_size,
-                                        gtk_widget_get_scale_factor (page->image_icon),
+                                        gtk_widget_get_scale_factor (GTK_WIDGET (page)),
                                         NULL);
        if (icon == NULL) {
                icon_size = 64;
                icon = gs_app_get_icon_for_size (app,
                                                 icon_size,
-                                                gtk_widget_get_scale_factor (page->image_icon),
+                                                gtk_widget_get_scale_factor (GTK_WIDGET (page)),
                                                 NULL);
        }
        if (icon == NULL) {
                icon_size = 96;
                icon = gs_app_get_icon_for_size (app,
                                                 icon_size,
-                                                gtk_widget_get_scale_factor (page->image_icon),
+                                                gtk_widget_get_scale_factor (GTK_WIDGET (page)),
                                                 "system-component-application");
        }
 
-       gtk_image_set_pixel_size (GTK_IMAGE (page->image_icon), icon_size);
-       gtk_image_set_from_gicon (GTK_IMAGE (page->image_icon), icon);
+#if ADW_CHECK_VERSION(1, 0, 1)
+       display = gdk_display_get_default ();
+       paintable = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_for_display (display),
+                                                   icon,
+                                                   icon_size,
+                                                   gtk_widget_get_scale_factor (GTK_WIDGET (page)),
+                                                   gtk_widget_get_direction (GTK_WIDGET (page)),
+                                                   GTK_ICON_LOOKUP_FORCE_REGULAR);
+       adw_status_page_set_paintable (ADW_STATUS_PAGE (page->status_page), GDK_PAINTABLE (paintable));
+#else
+       if (G_IS_THEMED_ICON (icon)) {
+               const gchar *const *names = g_themed_icon_get_names (G_THEMED_ICON (icon));
+
+               adw_status_page_set_icon_name (ADW_STATUS_PAGE (page->status_page),
+                                              names ? names[0] : NULL);
+       } else {
+               adw_status_page_set_icon_name (ADW_STATUS_PAGE (page->status_page), NULL);
+       }
+#endif
 
        if (gs_app_has_quirk (app, GS_APP_QUIRK_NEW_PERMISSIONS)) {
-               gtk_widget_show (page->permissions_section_box);
+               gtk_widget_show (page->permissions_section);
                populate_permissions_section (page, gs_app_get_update_permissions (app));
        } else {
-               gtk_widget_hide (page->permissions_section_box);
+               gtk_widget_hide (page->permissions_section);
        }
 }
 
@@ -402,15 +403,11 @@ gs_app_details_page_class_init (GsAppDetailsPageClass *klass)
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-app-details-page.ui");
 
        gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, back_button);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, box_header);
        gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, header_bar);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, image_icon);
        gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, label_details);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, label_name);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, label_summary);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, permissions_section_box);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, permissions_section_content);
-       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, scrolledwindow_details);
+       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, permissions_section);
+       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, permissions_section_list);
+       gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, status_page);
        gtk_widget_class_bind_template_child (widget_class, GsAppDetailsPage, window_title);
        gtk_widget_class_bind_template_callback (widget_class, back_clicked_cb);
 }
diff --git a/src/gs-app-details-page.ui b/src/gs-app-details-page.ui
index de11c6745..2edeae3e2 100644
--- a/src/gs-app-details-page.ui
+++ b/src/gs-app-details-page.ui
@@ -29,104 +29,63 @@
       </object>
     </child>
     <child>
-      <object class="GtkBox" id="box7">
-        <property name="margin_start">12</property>
-        <property name="margin_end">12</property>
-        <property name="margin_top">12</property>
-        <property name="margin_bottom">18</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">9</property>
+      <object class="AdwStatusPage" id="status_page">
+        <property name="icon_name">system-component-application</property>
+        <property name="title">Inkscape</property>
+        <property name="description">Vector based drawing program</property>
+        <property name="vexpand">True</property>
+        <style>
+          <class name="compact"/>
+        </style>
         <child>
-          <object class="GtkBox" id="box_header">
-            <property name="spacing">9</property>
+          <object class="AdwClamp">
             <child>
-              <object class="GtkImage" id="image_icon">
-                <property name="pixel_size">96</property>
-                <property name="icon_name">system-component-application</property>
-                <property name="icon-size">normal</property>
-                <style>
-                  <class name="icon-dropshadow"/>
-                </style>
-              </object>
-            </child>
-            <child>
-              <object class="GtkBox" id="box9">
+              <object class="GtkBox">
                 <property name="orientation">vertical</property>
-                <property name="spacing">3</property>
                 <child>
-                  <object class="GtkLabel" id="label_name">
-                    <property name="xalign">0</property>
-                    <property name="label">Inkscape</property>
-                    <property name="selectable">True</property>
-                    <property name="wrap">True</property>
-                    <property name="max_width_chars">50</property>
-                    <property name="width_chars">50</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                      <attribute name="scale" value="1.3999999999999999"/>
-                    </attributes>
+                  <object class="AdwPreferencesGroup" id="permissions_section">
+                    <property name="title" translatable="yes">Requires additional permissions</property>
+                    <!-- We can't remove children from a AdwPreferencesGroup
+                         without knowing them beforehand, so let's simply
+                         include a GtkListBox and remove its children. -->
+                    <child>
+                      <object class="GtkListBox" id="permissions_section_list">
+                        <property name="selection-mode">none</property>
+                        <style>
+                          <class name="content"/>
+                        </style>
+                      </object>
+                    </child>
                   </object>
                 </child>
                 <child>
-                  <object class="GtkLabel" id="label_summary">
-                    <property name="xalign">0</property>
-                    <property name="label">Vector based drawing program</property>
-                    <property name="selectable">True</property>
-                    <property name="wrap">True</property>
-                    <property name="max_width_chars">50</property>
-                    <property name="width_chars">50</property>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkBox" id="permissions_section_box">
-            <property name="orientation">vertical</property>
-            <property name="spacing">6</property>
-            <property name="margin_top">12</property>
-            <property name="margin_bottom">18</property>
-            <child>
-              <object class="GtkLabel" id="permissions_section_title">
-                <property name="xalign">0</property>
-                <property name="halign">start</property>
-                <property name="margin_bottom">6</property>
-                <property name="label" translatable="yes">Requires additional permissions</property>
-                <attributes>
-                  <attribute name="weight" value="bold"/>
-                </attributes>
-              </object>
-            </child>
-            <child>
-              <object class="GtkBox" id="permissions_section_content">
-                <property name="orientation">vertical</property>
-                <property name="spacing">12</property>
-                <property name="margin-start">18</property>
-                <property name="margin-end">18</property>
-              </object>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkScrolledWindow" id="scrolledwindow_details">
-            <property name="can_focus">True</property>
-            <property name="vexpand">True</property>
-            <property name="hscrollbar_policy">never</property>
-            <property name="vscrollbar_policy">automatic</property>
-            <child>
-              <object class="GtkLabel" id="label_details">
-                <property name="xalign">0</property>
-                <property name="yalign">0</property>
-                <property name="margin-top">6</property>
-                <property name="margin-bottom">6</property>
-                <property name="margin-start">6</property>
-                <property name="margin-end">6</property>
-                <property name="label">New in kmod 14-1
+                  <object class="GtkListBox">
+                    <property name="selection-mode">none</property>
+                    <style>
+                      <class name="content"/>
+                    </style>
+                    <child>
+                      <object class="GtkListBoxRow">
+                        <property name="activatable">False</property>
+                        <child>
+                          <object class="GtkLabel" id="label_details">
+                            <property name="xalign">0</property>
+                            <property name="yalign">0</property>
+                            <property name="margin-top">18</property>
+                            <property name="margin-bottom">18</property>
+                            <property name="margin-start">18</property>
+                            <property name="margin-end">18</property>
+                            <property name="label">New in kmod 14-1
 * Moo
 * bar</property>
-                <property name="wrap">True</property>
-                <property name="selectable">True</property>
+                            <property name="wrap">True</property>
+                            <property name="selectable">True</property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                  </object>
+                </child>
               </object>
             </child>
           </object>


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