[gnome-software] Do not use the application state to modify how widgets are drawn



commit 6a943ad62fd4f88bdf22ec4d565ac1cbf3c839aa
Author: Richard Hughes <richard hughsie com>
Date:   Thu Sep 26 16:18:57 2013 +0100

    Do not use the application state to modify how widgets are drawn
    
    It's not nice to change the way the widget works using a special state value.
    Instead of this, provide a method that only the updates panel will use and make
    things less magic.

 src/gs-app-widget.c    |   28 +++++++++++++++++++++++-----
 src/gs-app-widget.h    |    2 ++
 src/gs-shell-updates.c |    1 +
 3 files changed, 26 insertions(+), 5 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 860fef5..b52b448 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -40,6 +40,7 @@ struct _GsAppWidgetPrivate
        GtkWidget       *button;
        GtkWidget       *spinner;
        gboolean         colorful;
+       gboolean         show_update;
 };
 
 G_DEFINE_TYPE_WITH_PRIVATE (GsAppWidget, gs_app_widget, GTK_TYPE_BIN)
@@ -66,7 +67,8 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
                return;
 
        /* get the main body text */
-       if (gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE)
+       if (priv->show_update &&
+           gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE)
                tmp = gs_app_get_update_details (priv->app);
        if (tmp == NULL)
                tmp = gs_app_get_description (priv->app);
@@ -84,7 +86,8 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
 
        gtk_label_set_label (GTK_LABEL (priv->name_label),
                             gs_app_get_name (priv->app));
-       if (gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE) {
+       if (priv->show_update &&
+           gs_app_get_state (priv->app) == GS_APP_STATE_UPDATABLE) {
                gtk_label_set_label (GTK_LABEL (priv->version_label),
                                     gs_app_get_update_version (priv->app));
        } else {
@@ -121,9 +124,13 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
        case GS_APP_STATE_UPDATABLE:
                gtk_widget_set_visible (priv->spinner, FALSE);
                gtk_widget_set_visible (priv->button, FALSE);
-               /* TRANSLATORS: this is a button next to the search results that
-                * allows the application to be updated. not normally shown */
-               gtk_button_set_label (GTK_BUTTON (priv->button), _("Update"));
+               if (priv->show_update) {
+                       /* TRANSLATORS: this is a button next to the search results that
+                        * allows the application to be updated. not normally shown */
+                       gtk_button_set_label (GTK_BUTTON (priv->button), _("Update"));
+               } else {
+                       gtk_button_set_label (GTK_BUTTON (priv->button), _("Remove"));
+               }
                break;
        case GS_APP_STATE_INSTALLING:
                gtk_spinner_start (GTK_SPINNER (priv->spinner));
@@ -253,6 +260,17 @@ gs_app_widget_set_colorful (GsAppWidget *app_widget,
        app_widget->priv->colorful = colorful;
 }
 
+/**
+ * gs_app_widget_set_show_update:
+ *
+ * Only really useful for the update panel to call
+ **/
+void
+gs_app_widget_set_show_update (GsAppWidget *app_widget, gboolean show_update)
+{
+       app_widget->priv->show_update = show_update;
+}
+
 GtkWidget *
 gs_app_widget_new (void)
 {
diff --git a/src/gs-app-widget.h b/src/gs-app-widget.h
index a01d1c6..5c0324d 100644
--- a/src/gs-app-widget.h
+++ b/src/gs-app-widget.h
@@ -57,6 +57,8 @@ GType          gs_app_widget_get_type                 (void);
 GtkWidget      *gs_app_widget_new                      (void);
 void            gs_app_widget_set_colorful             (GsAppWidget    *app_widget,
                                                         gboolean        colorful);
+void            gs_app_widget_set_show_update          (GsAppWidget    *app_widget,
+                                                        gboolean        show_update);
 GsApp          *gs_app_widget_get_app                  (GsAppWidget    *app_widget);
 void            gs_app_widget_set_app                  (GsAppWidget    *app_widget,
                                                         GsApp          *app);
diff --git a/src/gs-shell-updates.c b/src/gs-shell-updates.c
index 09e5445..17f34b8 100644
--- a/src/gs-shell-updates.c
+++ b/src/gs-shell-updates.c
@@ -132,6 +132,7 @@ gs_shell_updates_get_updates_cb (GsPluginLoader *plugin_loader,
                app = GS_APP (l->data);
                g_debug ("adding update %s, kind %d state %d", gs_app_get_id (app), gs_app_get_kind (app), 
gs_app_get_state (app));
                widget = gs_app_widget_new ();
+               gs_app_widget_set_show_update (GS_APP_WIDGET (widget), TRUE);
                gs_app_widget_set_app (GS_APP_WIDGET (widget), app);
                gtk_container_add (GTK_CONTAINER (priv->list_box_updates), widget);
                gtk_widget_show (widget);


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