[gnome-software: 21/29] gs-details-page: Move origin box widgets out of shell




commit 30a03123889e5e32b920fbd76e674251b66f6990
Author: Philip Withnall <pwithnall endlessos org>
Date:   Thu Jan 21 16:54:54 2021 +0000

    gs-details-page: Move origin box widgets out of shell
    
    Although the origin listbox is shown in the header bar, it really
    belongs to the details page — that’s where all the logic for it lives,
    and no other page needs it.
    
    Move its UI declaration to the details page, so that the page no longer
    needs to access the `GtkBuilder` from `GsShell`.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 src/gnome-software.ui  | 80 --------------------------------------------------
 src/gs-details-page.c  | 47 +++++++++++++++--------------
 src/gs-details-page.ui | 77 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-shell.c         |  2 --
 4 files changed, 102 insertions(+), 104 deletions(-)
---
diff --git a/src/gnome-software.ui b/src/gnome-software.ui
index 542c7b7c1..d12d0b54c 100644
--- a/src/gnome-software.ui
+++ b/src/gnome-software.ui
@@ -250,59 +250,6 @@
                 <property name="pack-type">end</property>
               </packing>
             </child>
-            <child>
-              <object class="GtkBox" id="origin_box">
-                <property name="visible">True</property>
-                <property name="orientation">horizontal</property>
-                <property name="halign">fill</property>
-                <property name="spacing">9</property>
-                <child>
-                  <object class="GtkLabel">
-                    <property name="label" translatable="yes" comments="Translators: This is a label in the 
header bar, followed by a drop down to choose between different source repos">Source</property>
-                    <property name="valign">GTK_ALIGN_CENTER</property>
-                    <property name="visible">1</property>
-                    <style>
-                      <class name="dim-label"/>
-                    </style>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkMenuButton" id="origin_button">
-                    <property name="visible">True</property>
-                    <property name="can_focus">True</property>
-                    <property name="sensitive">True</property>
-                    <property name="popover">origin_popover</property>
-                    <child>
-                      <object class="GtkGrid">
-                        <property name="column-spacing">12</property>
-                        <property name="visible">1</property>
-                        <property name="valign">GTK_ALIGN_CENTER</property>
-                        <child>
-                          <object class="GtkLabel" id="origin_button_label">
-                            <property name="label"></property>
-                            <property name="valign">GTK_ALIGN_CENTER</property>
-                            <property name="visible">1</property>
-                            <property name="xalign">0</property>
-                            <property name="width_chars">10</property>
-                          </object>
-                        </child>
-                        <child>
-                          <object class="GtkImage">
-                            <property name="icon-name">pan-down-symbolic</property>
-                            <property name="pixel-size">16</property>
-                            <property name="valign">GTK_ALIGN_CENTER</property>
-                            <property name="visible">1</property>
-                          </object>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="pack-type">end</property>
-              </packing>
-            </child>
           </object>
         </child>
         <child>
@@ -565,31 +512,4 @@
       </object>
     </child>
   </object>
-  <object class="GtkPopover" id="origin_popover">
-    <property name="visible">False</property>
-    <child>
-      <object class="GtkBox" id="origin_popover_box">
-        <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">12</property>
-        <child>
-          <object class="GtkScrolledWindow">
-            <property name="propagate-natural-height">true</property>
-            <property name="propagate-natural-width">true</property>
-            <property name="max-content-height">600</property>
-            <property name="visible">true</property>
-            <child>
-              <object class="GtkListBox" id="origin_popover_list_box">
-                <property name="selection-mode">none</property>
-                <property name="visible">true</property>
-                <style>
-                  <class name="content"/>
-                </style>
-              </object>
-            </child>
-          </object>
-        </child>
-      </object>
-    </child>
-  </object>
 </interface>
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index b777b6005..467905a80 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -159,6 +159,10 @@ struct _GsDetailsPage
        GtkWidget               *popover_permissions;
        GtkWidget               *box_permissions_details;
        GtkWidget               *star_eventbox;
+       GtkWidget               *origin_popover;
+       GtkWidget               *origin_popover_list_box;
+       GtkWidget               *origin_box;
+       GtkWidget               *origin_button_label;
 };
 
 G_DEFINE_TYPE (GsDetailsPage, gs_details_page, GS_TYPE_PAGE)
@@ -304,6 +308,9 @@ gs_details_page_switch_to (GsPage *page)
                return;
        }
 
+       /* hide the alternates for now until the query is complete */
+       gtk_widget_hide (self->origin_box);
+
        /* not set, perhaps file-to-app */
        if (self->app == NULL)
                return;
@@ -849,21 +856,14 @@ gs_details_page_get_alternates_cb (GObject *source_object,
        GsPluginLoader *plugin_loader = GS_PLUGIN_LOADER (source_object);
        g_autoptr(GError) error = NULL;
        g_autoptr(GsAppList) list = NULL;
-       GtkWidget *origin_box;
-       GtkWidget *origin_button_label;
-       GtkWidget *origin_popover_list_box;
        g_autofree gchar *origin_ui = NULL;
        gboolean instance_changed = FALSE;
 
-       origin_box = GTK_WIDGET (gtk_builder_get_object (self->builder, "origin_box"));
-       origin_button_label = GTK_WIDGET (gtk_builder_get_object (self->builder, "origin_button_label"));
-       origin_popover_list_box = GTK_WIDGET (gtk_builder_get_object (self->builder, 
"origin_popover_list_box"));
-
-       gs_container_remove_all (GTK_CONTAINER (origin_popover_list_box));
+       gs_container_remove_all (GTK_CONTAINER (self->origin_popover_list_box));
 
        /* Did we switch away from the page in the meantime? */
        if (!gs_page_is_active (GS_PAGE (self))) {
-               gtk_widget_hide (origin_box);
+               gtk_widget_hide (self->origin_box);
                return;
        }
 
@@ -873,7 +873,7 @@ gs_details_page_get_alternates_cb (GObject *source_object,
        if (list == NULL) {
                if (!g_error_matches (error, GS_PLUGIN_ERROR, GS_PLUGIN_ERROR_CANCELLED))
                        g_warning ("failed to get alternates: %s", error->message);
-               gtk_widget_hide (origin_box);
+               gtk_widget_hide (self->origin_box);
                return;
        }
 
@@ -905,7 +905,7 @@ gs_details_page_get_alternates_cb (GObject *source_object,
 
        /* no alternates to show */
        if (gs_app_list_length (list) < 2) {
-               gtk_widget_hide (origin_box);
+               gtk_widget_hide (self->origin_box);
                return;
        }
 
@@ -929,16 +929,16 @@ gs_details_page_get_alternates_cb (GObject *source_object,
                }
                gs_origin_popover_row_set_size_group (GS_ORIGIN_POPOVER_ROW (row),
                                                      self->size_group_origin_popover);
-               gtk_container_add (GTK_CONTAINER (origin_popover_list_box), row);
+               gtk_container_add (GTK_CONTAINER (self->origin_popover_list_box), row);
        }
 
        origin_ui = gs_app_get_origin_ui (self->app);
        if (origin_ui != NULL)
-               gtk_label_set_text (GTK_LABEL (origin_button_label), origin_ui);
+               gtk_label_set_text (GTK_LABEL (self->origin_button_label), origin_ui);
        else
-               gtk_label_set_text (GTK_LABEL (origin_button_label), "");
+               gtk_label_set_text (GTK_LABEL (self->origin_button_label), "");
 
-       gtk_widget_show (origin_box);
+       gtk_widget_show (self->origin_box);
 
        /* The other parts of the app are the same, only the state/buttons could change */
        if (instance_changed)
@@ -2237,10 +2237,8 @@ origin_popover_row_activated_cb (GtkListBox *list_box,
 {
        GsDetailsPage *self = GS_DETAILS_PAGE (user_data);
        GsApp *app;
-       GtkWidget *popover;
 
-       popover = GTK_WIDGET (gtk_builder_get_object (self->builder, "origin_popover"));
-       gtk_popover_popdown (GTK_POPOVER (popover));
+       gtk_popover_popdown (GTK_POPOVER (self->origin_popover));
 
        app = gs_origin_popover_row_get_app (GS_ORIGIN_POPOVER_ROW (row));
        if (app != self->app) {
@@ -2824,7 +2822,6 @@ gs_details_page_setup (GsPage *page,
 {
        GsDetailsPage *self = GS_DETAILS_PAGE (page);
        GtkAdjustment *adj;
-       GtkWidget *origin_popover_list_box;
 
        g_return_val_if_fail (GS_IS_DETAILS_PAGE (self), TRUE);
 
@@ -2902,11 +2899,11 @@ gs_details_page_setup (GsPage *page,
        g_signal_connect (self->label_license_nonfree_details, "activate-link",
                          G_CALLBACK (gs_details_page_activate_link_cb),
                          self);
-       origin_popover_list_box = GTK_WIDGET (gtk_builder_get_object (self->builder, 
"origin_popover_list_box"));
-       gtk_list_box_set_sort_func (GTK_LIST_BOX (origin_popover_list_box),
+
+       gtk_list_box_set_sort_func (GTK_LIST_BOX (self->origin_popover_list_box),
                                    origin_popover_list_sort_func,
                                    NULL, NULL);
-       g_signal_connect (origin_popover_list_box, "row-activated",
+       g_signal_connect (self->origin_popover_list_box, "row-activated",
                          G_CALLBACK (origin_popover_row_activated_cb),
                          self);
 
@@ -3089,6 +3086,10 @@ gs_details_page_class_init (GsDetailsPageClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, popover_permissions);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, box_permissions_details);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, star_eventbox);
+       gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, origin_popover);
+       gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, origin_popover_list_box);
+       gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, origin_box);
+       gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, origin_button_label);
 }
 
 static void
@@ -3115,6 +3116,8 @@ gs_details_page_init (GsDetailsPage *self)
        g_signal_connect (self->list_box_version_history, "row-activated",
                          G_CALLBACK (version_history_list_row_activated_cb), self);
 
+       gs_page_set_header_end_widget (GS_PAGE (self), self->origin_box);
+
        gtk_style_context_add_class (gtk_widget_get_style_context (self->button_details_permissions_value), 
"content-rating-permissions");
 }
 
diff --git a/src/gs-details-page.ui b/src/gs-details-page.ui
index 2941769ad..31b6f4dba 100644
--- a/src/gs-details-page.ui
+++ b/src/gs-details-page.ui
@@ -1456,4 +1456,81 @@
       </object>
     </child>
   </object>
+
+  <object class="GtkBox" id="origin_box">
+    <property name="visible">True</property>
+    <property name="orientation">horizontal</property>
+    <property name="halign">fill</property>
+    <property name="spacing">9</property>
+    <child>
+      <object class="GtkLabel">
+        <property name="label" translatable="yes" comments="Translators: This is a label in the header bar, 
followed by a drop down to choose between different source repos">Source</property>
+        <property name="valign">GTK_ALIGN_CENTER</property>
+        <property name="visible">1</property>
+        <style>
+          <class name="dim-label"/>
+        </style>
+      </object>
+    </child>
+    <child>
+      <object class="GtkMenuButton" id="origin_button">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="sensitive">True</property>
+        <property name="popover">origin_popover</property>
+        <child>
+          <object class="GtkGrid">
+            <property name="column-spacing">12</property>
+            <property name="visible">1</property>
+            <property name="valign">GTK_ALIGN_CENTER</property>
+            <child>
+              <object class="GtkLabel" id="origin_button_label">
+                <property name="label"></property>
+                <property name="valign">GTK_ALIGN_CENTER</property>
+                <property name="visible">1</property>
+                <property name="xalign">0</property>
+                <property name="width_chars">10</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkImage">
+                <property name="icon-name">pan-down-symbolic</property>
+                <property name="pixel-size">16</property>
+                <property name="valign">GTK_ALIGN_CENTER</property>
+                <property name="visible">1</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+
+  <object class="GtkPopover" id="origin_popover">
+    <property name="visible">False</property>
+    <child>
+      <object class="GtkBox" id="origin_popover_box">
+        <property name="visible">True</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
+        <child>
+          <object class="GtkScrolledWindow">
+            <property name="propagate-natural-height">true</property>
+            <property name="propagate-natural-width">true</property>
+            <property name="max-content-height">600</property>
+            <property name="visible">true</property>
+            <child>
+              <object class="GtkListBox" id="origin_popover_list_box">
+                <property name="selection-mode">none</property>
+                <property name="visible">true</property>
+                <style>
+                  <class name="content"/>
+                </style>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
diff --git a/src/gs-shell.c b/src/gs-shell.c
index 5ea1c9bea..c522d9932 100644
--- a/src/gs-shell.c
+++ b/src/gs-shell.c
@@ -435,8 +435,6 @@ stack_notify_visible_child_cb (GObject    *object,
        gtk_widget_set_visible (widget, buttonbox_visible);
        widget = GTK_WIDGET (gtk_builder_get_object (shell->builder, "header_selection_menu_button"));
        gtk_widget_hide (widget);
-       widget = GTK_WIDGET (gtk_builder_get_object (shell->builder, "origin_box"));
-       gtk_widget_hide (widget);
 
        gtk_widget_set_visible (shell->application_details_header, !buttonbox_visible);
 


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