[gnome-software] details page: Split up Install and Update buttons in the ui file



commit ad9ea1709486b7cc9462e56a0688819f263520a0
Author: Kalev Lember <klember redhat com>
Date:   Sun Feb 24 19:11:56 2019 +0100

    details page: Split up Install and Update buttons in the ui file
    
    ... and move the Update button to the right side, as per latest mockups.

 src/gs-details-page.c  | 39 +++++++++++++++++++++++++++++----------
 src/gs-details-page.ui | 16 ++++++++++++++++
 2 files changed, 45 insertions(+), 10 deletions(-)
---
diff --git a/src/gs-details-page.c b/src/gs-details-page.c
index a4370b5f..8d9202e3 100644
--- a/src/gs-details-page.c
+++ b/src/gs-details-page.c
@@ -76,6 +76,7 @@ struct _GsDetailsPage
        GtkWidget               *button_details_website;
        GtkWidget               *button_donate;
        GtkWidget               *button_install;
+       GtkWidget               *button_update;
        GtkWidget               *button_remove;
        GtkWidget               *button_cancel;
        GtkWidget               *button_more_reviews;
@@ -789,7 +790,6 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
 {
        AsAppState state;
        GsPrice *price;
-       GtkStyleContext *sc;
        g_autofree gchar *text = NULL;
 
        state = gs_app_get_state (self->app);
@@ -799,7 +799,6 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
        case AS_APP_STATE_AVAILABLE:
        case AS_APP_STATE_AVAILABLE_LOCAL:
                gtk_widget_set_visible (self->button_install, TRUE);
-               gtk_style_context_add_class (gtk_widget_get_style_context (self->button_install), 
"suggested-action");
                /* TRANSLATORS: button text in the header when an application
                 * can be installed */
                gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Install"));
@@ -809,7 +808,6 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
                break;
        case AS_APP_STATE_PURCHASABLE:
                gtk_widget_set_visible (self->button_install, TRUE);
-               gtk_style_context_add_class (gtk_widget_get_style_context (self->button_install), 
"suggested-action");
                price = gs_app_get_price (self->app);
                text = gs_price_to_string (price);
                gtk_button_set_label (GTK_BUTTON (self->button_install), text);
@@ -825,18 +823,13 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
                gtk_widget_set_visible (self->button_install, FALSE);
                break;
        case AS_APP_STATE_UPDATABLE_LIVE:
-               gtk_widget_set_visible (self->button_install, TRUE);
-               sc = gtk_widget_get_style_context (self->button_install);
                if (gs_app_get_kind (self->app) == AS_APP_KIND_FIRMWARE) {
+                       gtk_widget_set_visible (self->button_install, TRUE);
                        /* TRANSLATORS: button text in the header when firmware
                         * can be live-installed */
                        gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Install"));
-                       gtk_style_context_add_class (sc, "suggested-action");
                } else {
-                       /* TRANSLATORS: button text in the header when an application
-                        * can be live-updated */
-                       gtk_button_set_label (GTK_BUTTON (self->button_install), _("_Update"));
-                       gtk_style_context_remove_class (sc, "suggested-action");
+                       gtk_widget_set_visible (self->button_install, FALSE);
                }
                break;
        case AS_APP_STATE_UNAVAILABLE:
@@ -857,6 +850,20 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
                g_assert_not_reached ();
        }
 
+       /* update button */
+       switch (state) {
+       case AS_APP_STATE_UPDATABLE_LIVE:
+               if (gs_app_get_kind (self->app) == AS_APP_KIND_FIRMWARE) {
+                       gtk_widget_set_visible (self->button_update, FALSE);
+               } else {
+                       gtk_widget_set_visible (self->button_update, TRUE);
+               }
+               break;
+       default:
+               gtk_widget_set_visible (self->button_update, FALSE);
+               break;
+       }
+
        /* launch button */
        switch (gs_app_get_state (self->app)) {
        case AS_APP_STATE_INSTALLED:
@@ -930,6 +937,7 @@ gs_details_page_refresh_buttons (GsDetailsPage *self)
 
        if (app_has_pending_action (self->app)) {
                gtk_widget_set_visible (self->button_install, FALSE);
+               gtk_widget_set_visible (self->button_update, FALSE);
                gtk_widget_set_visible (self->button_details_launch, FALSE);
                gtk_widget_set_visible (self->button_remove, FALSE);
        }
@@ -2078,6 +2086,13 @@ gs_details_page_app_install_button_cb (GtkWidget *widget, GsDetailsPage *self)
                             self->app_cancellable);
 }
 
+static void
+gs_details_page_app_update_button_cb (GtkWidget *widget, GsDetailsPage *self)
+{
+       g_set_object (&self->app_cancellable, gs_app_get_cancellable (self->app));
+       gs_page_update_app (GS_PAGE (self), self->app, self->app_cancellable);
+}
+
 static void
 gs_details_page_addon_selected_cb (GsAppAddonRow *row,
                                    GParamSpec *pspec,
@@ -2501,6 +2516,9 @@ gs_details_page_setup (GsPage *page,
        g_signal_connect (self->button_install, "clicked",
                          G_CALLBACK (gs_details_page_app_install_button_cb),
                          self);
+       g_signal_connect (self->button_update, "clicked",
+                         G_CALLBACK (gs_details_page_app_update_button_cb),
+                         self);
        g_signal_connect (self->button_remove, "clicked",
                          G_CALLBACK (gs_details_page_app_remove_button_cb),
                          self);
@@ -2617,6 +2635,7 @@ gs_details_page_class_init (GsDetailsPageClass *klass)
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_details_website);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_donate);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_install);
+       gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_update);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_remove);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_cancel);
        gtk_widget_class_bind_template_child (widget_class, GsDetailsPage, button_more_reviews);
diff --git a/src/gs-details-page.ui b/src/gs-details-page.ui
index a271063a..70975c81 100644
--- a/src/gs-details-page.ui
+++ b/src/gs-details-page.ui
@@ -243,6 +243,21 @@
                                 <property name="receives_default">True</property>
                               </object>
                             </child>
+                            <child>
+                              <object class="GtkButton" id="button_update">
+                                <property name="visible">False</property>
+                                <property name="use_underline">True</property>
+                                <property name="label" translatable="yes">_Update</property>
+                                <property name="width_request">105</property>
+                                <property name="can_focus">True</property>
+                                <property name="receives_default">True</property>
+                                <property name="halign">start</property>
+                                <property name="valign">start</property>
+                              </object>
+                              <packing>
+                                <property name="pack-type">end</property>
+                              </packing>
+                            </child>
                             <child>
                               <object class="GtkLinkButton" id="button_details_add_shortcut">
                                 <property name="visible">False</property>
@@ -1124,6 +1139,7 @@
     <property name="ignore_hidden">True</property>
     <widgets>
       <widget name="button_install"/>
+      <widget name="button_update"/>
       <widget name="button_remove"/>
       <widget name="button_details_launch"/>
     </widgets>


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