[gnome-software/1690-button-to-go-back-is-missing-in-os-updates-page-opened-from-installed-updates-window] gs-os-update-page: Add a Back button to the page title



commit 0c42c86098515ccaee3b3333fe7a514fd98e2c4a
Author: Milan Crha <mcrha redhat com>
Date:   Mon Mar 28 16:48:29 2022 +0200

    gs-os-update-page: Add a Back button to the page title
    
    It can be used to move to the previous page, if needed.
    It's hidden by default.

 src/gs-os-update-page.c  | 87 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gs-os-update-page.h  |  5 +++
 src/gs-os-update-page.ui | 15 +++++++++
 3 files changed, 107 insertions(+)
---
diff --git a/src/gs-os-update-page.c b/src/gs-os-update-page.c
index d20f15e7d..5439dddad 100644
--- a/src/gs-os-update-page.c
+++ b/src/gs-os-update-page.c
@@ -36,11 +36,13 @@ typedef enum {
 
 typedef enum {
        PROP_APP = 1,
+       PROP_SHOW_BACK_BUTTON,
        PROP_TITLE,
 } GsOsUpdatePageProperty;
 
 enum {
        SIGNAL_APP_ACTIVATED,
+       SIGNAL_BACK_CLICKED,
        SIGNAL_LAST
 };
 
@@ -52,6 +54,7 @@ struct _GsOsUpdatePage
 {
        GtkBox           parent_instance;
 
+       GtkWidget       *back_button;
        GtkWidget       *box;
        GtkWidget       *group;
        GtkWidget       *header_bar;
@@ -406,6 +409,55 @@ gs_os_update_page_set_app (GsOsUpdatePage *page, GsApp *app)
        g_object_notify_by_pspec (G_OBJECT (page), obj_props[PROP_TITLE]);
 }
 
+/**
+ * gs_os_update_page_get_show_back_button:
+ * @page: a #GsOsUpdatePage
+ *
+ * Get the value of #GsOsUpdatePage:show-back-button.
+ *
+ * Returns: whether to show the back button
+ *
+ * Since: 42.1
+ */
+gboolean
+gs_os_update_page_get_show_back_button (GsOsUpdatePage *page)
+{
+       g_return_val_if_fail (GS_IS_OS_UPDATE_PAGE (page), FALSE);
+       return gtk_widget_get_visible (page->back_button);
+}
+
+/**
+ * gs_os_update_page_set_show_back_button:
+ * @page: a #GsOsUpdatePage
+ * @show_back_button: whether to show the back button
+ *
+ * Set the value of #GsOsUpdatePage:show-back-button.
+ *
+ * Since: 42.1
+ */
+void
+gs_os_update_page_set_show_back_button (GsOsUpdatePage *page,
+                                       gboolean show_back_button)
+{
+       g_return_if_fail (GS_IS_OS_UPDATE_PAGE (page));
+
+       show_back_button = !!show_back_button;
+
+       if (gtk_widget_get_visible (page->back_button) == show_back_button)
+               return;
+
+       gtk_widget_set_visible (page->back_button, show_back_button);
+
+       g_object_notify_by_pspec (G_OBJECT (page), obj_props[PROP_SHOW_BACK_BUTTON]);
+}
+
+static void
+back_clicked_cb (GtkWidget *widget,
+                GsOsUpdatePage *page)
+{
+       g_signal_emit (page, signals[SIGNAL_BACK_CLICKED], 0);
+}
+
 static void
 gs_os_update_page_dispose (GObject *object)
 {
@@ -425,6 +477,9 @@ gs_os_update_page_get_property (GObject *object, guint prop_id, GValue *value, G
        case PROP_APP:
                g_value_set_object (value, gs_os_update_page_get_app (page));
                break;
+       case PROP_SHOW_BACK_BUTTON:
+               g_value_set_boolean (value, gs_os_update_page_get_show_back_button (page));
+               break;
        case PROP_TITLE:
                g_value_set_string (value, adw_window_title_get_title (page->window_title));
                break;
@@ -443,6 +498,9 @@ gs_os_update_page_set_property (GObject *object, guint prop_id, const GValue *va
        case PROP_APP:
                gs_os_update_page_set_app (page, g_value_get_object (value));
                break;
+       case PROP_SHOW_BACK_BUTTON:
+               gs_os_update_page_set_show_back_button (page, g_value_get_boolean (value));
+               break;
        default:
                G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
                break;
@@ -477,6 +535,18 @@ gs_os_update_page_class_init (GsOsUpdatePageClass *klass)
                                     GS_TYPE_APP,
                                     G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
 
+       /**
+        * GsOsUpdatePage:show-back-button
+        *
+        * Whether to show the back button.
+        *
+        * Since: 42.1
+        */
+       obj_props[PROP_SHOW_BACK_BUTTON] =
+               g_param_spec_boolean ("show-back-button", NULL, NULL,
+                                    FALSE,
+                                    G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY);
+
        /**
         * GsOsUpdatePage:title
         *
@@ -507,12 +577,29 @@ gs_os_update_page_class_init (GsOsUpdatePageClass *klass)
                              0, NULL, NULL, g_cclosure_marshal_generic,
                              G_TYPE_NONE, 1, GS_TYPE_APP);
 
+       /**
+        * GsOsUpdatePage:back-clicked:
+        * @self: a #GsOsUpdatePage
+        *
+        * Emitted when the back button got activated and the #GsUpdateDialog
+        * containing this page is expected to go back.
+        *
+        * Since: 42.1
+        */
+       signals[SIGNAL_BACK_CLICKED] =
+               g_signal_new ("back-clicked",
+                             G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST,
+                             0, NULL, NULL, g_cclosure_marshal_generic,
+                             G_TYPE_NONE, 0);
+
        gtk_widget_class_set_template_from_resource (widget_class, 
"/org/gnome/Software/gs-os-update-page.ui");
 
+       gtk_widget_class_bind_template_child (widget_class, GsOsUpdatePage, back_button);
        gtk_widget_class_bind_template_child (widget_class, GsOsUpdatePage, box);
        gtk_widget_class_bind_template_child (widget_class, GsOsUpdatePage, group);
        gtk_widget_class_bind_template_child (widget_class, GsOsUpdatePage, header_bar);
        gtk_widget_class_bind_template_child (widget_class, GsOsUpdatePage, window_title);
+       gtk_widget_class_bind_template_callback (widget_class, back_clicked_cb);
 }
 
 /**
diff --git a/src/gs-os-update-page.h b/src/gs-os-update-page.h
index 8d973c12a..dbe4ce301 100644
--- a/src/gs-os-update-page.h
+++ b/src/gs-os-update-page.h
@@ -22,5 +22,10 @@ GtkWidget    *gs_os_update_page_new          (void);
 GsApp          *gs_os_update_page_get_app      (GsOsUpdatePage *page);
 void            gs_os_update_page_set_app      (GsOsUpdatePage *page,
                                                 GsApp          *app);
+gboolean        gs_os_update_page_get_show_back_button
+                                               (GsOsUpdatePage *page);
+void            gs_os_update_page_set_show_back_button
+                                               (GsOsUpdatePage *page,
+                                                gboolean show_back_button);
 
 G_END_DECLS
diff --git a/src/gs-os-update-page.ui b/src/gs-os-update-page.ui
index 9d38fd8e9..a0ec36ef0 100644
--- a/src/gs-os-update-page.ui
+++ b/src/gs-os-update-page.ui
@@ -11,6 +11,21 @@
         <property name="title-widget">
           <object class="AdwWindowTitle" id="window_title" />
         </property>
+        <child type="start">
+          <object class="GtkButton" id="back_button">
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="icon_name">go-previous-symbolic</property>
+            <property name="visible">False</property>
+            <signal name="clicked" handler="back_clicked_cb"/>
+            <style>
+              <class name="image-button"/>
+            </style>
+            <accessibility>
+              <property name="label" translatable="yes">Go back</property>
+            </accessibility>
+          </object>
+        </child>
       </object>
     </child>
     <child>


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