[gnome-software] Show the user-set ratings in a different color to system values



commit 062b078d5ebbdaba4e9c042ff1d659c9a522060a
Author: Richard Hughes <richard hughsie com>
Date:   Fri Nov 29 17:10:00 2013 +0000

    Show the user-set ratings in a different color to system values

 src/gs-app.c                          |   26 ++++++++++++++++++++++++++
 src/gs-app.h                          |   10 ++++++++++
 src/gs-shell-details.c                |    2 ++
 src/gs-star-widget.c                  |   22 +++++++++++++++++++---
 src/gs-star-widget.h                  |    3 +++
 src/gtk-style.css                     |    4 ++++
 src/plugins/gs-plugin-fedora-tagger.c |    1 +
 src/plugins/gs-plugin-local-ratings.c |    4 +++-
 8 files changed, 68 insertions(+), 4 deletions(-)
---
diff --git a/src/gs-app.c b/src/gs-app.c
index f2e26b4..2e6adac 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -78,6 +78,7 @@ struct GsAppPrivate
        gchar                   *update_details;
        gchar                   *management_plugin;
        gint                     rating;
+       GsAppRatingKind          rating_kind;
        guint64                  size;
        GsAppKind                kind;
        GsAppIdKind              id_kind;
@@ -260,6 +261,10 @@ gs_app_to_string (GsApp *app)
                g_string_append_printf (str, "\tmenu-path:\t%s\n", priv->menu_path);
        if (priv->rating != -1)
                g_string_append_printf (str, "\trating:\t%i\n", priv->rating);
+       if (priv->rating_kind != GS_APP_RATING_KIND_UNKNOWN)
+               g_string_append_printf (str, "\trating-kind:\t%s\n",
+                                       priv->rating_kind == GS_APP_RATING_KIND_USER ?
+                                               "user" : "system");
        if (priv->pixbuf != NULL)
                g_string_append_printf (str, "\tpixbuf:\t%p\n", priv->pixbuf);
        if (priv->featured_pixbuf != NULL)
@@ -1253,6 +1258,26 @@ gs_app_set_rating (GsApp *app, gint rating)
 }
 
 /**
+ * gs_app_get_rating_kind:
+ */
+GsAppRatingKind
+gs_app_get_rating_kind (GsApp *app)
+{
+       g_return_val_if_fail (GS_IS_APP (app), -1);
+       return app->priv->rating_kind;
+}
+
+/**
+ * gs_app_set_rating_kind:
+ */
+void
+gs_app_set_rating_kind (GsApp *app, GsAppRatingKind rating_kind)
+{
+       g_return_if_fail (GS_IS_APP (app));
+       app->priv->rating_kind = rating_kind;
+}
+
+/**
  * gs_app_get_size:
  */
 guint64
@@ -1597,6 +1622,7 @@ gs_app_init (GsApp *app)
 {
        app->priv = GS_APP_GET_PRIVATE (app);
        app->priv->rating = -1;
+       app->priv->rating_kind = GS_APP_RATING_KIND_UNKNOWN;
        app->priv->sources = g_ptr_array_new_with_free_func (g_free);
        app->priv->source_ids = g_ptr_array_new_with_free_func (g_free);
        app->priv->related = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref);
diff --git a/src/gs-app.h b/src/gs-app.h
index d779ed9..9254d37 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -87,6 +87,13 @@ typedef enum {
        GS_APP_ID_KIND_LAST
 } GsAppIdKind;
 
+typedef enum {
+       GS_APP_RATING_KIND_UNKNOWN,
+       GS_APP_RATING_KIND_USER,
+       GS_APP_RATING_KIND_SYSTEM,
+       GS_APP_RATING_KIND_LAST
+} GsAppRatingKind;
+
 #define        GS_APP_INSTALL_DATE_UNSET               0
 #define        GS_APP_INSTALL_DATE_UNKNOWN             1 /* 1s past the epoch */
 #define        GS_APP_SIZE_UNKNOWN                     0
@@ -194,6 +201,9 @@ void                 gs_app_set_metadata            (GsApp          *app,
 gint            gs_app_get_rating              (GsApp          *app);
 void            gs_app_set_rating              (GsApp          *app,
                                                 gint            rating);
+GsAppRatingKind         gs_app_get_rating_kind         (GsApp          *app);
+void            gs_app_set_rating_kind         (GsApp          *app,
+                                                GsAppRatingKind rating_kind);
 guint64                 gs_app_get_size                (GsApp          *app);
 void            gs_app_set_size                (GsApp          *app,
                                                 guint64         size);
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index df2ad01..6502397 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -597,6 +597,7 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
        default:
                gtk_widget_set_visible (priv->star, TRUE);
                gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
+                                          gs_app_get_rating_kind (priv->app),
                                           gs_app_get_rating (priv->app));
                break;
        }
@@ -1109,6 +1110,7 @@ gs_shell_details_rating_changed_cb (GsStarWidget *star,
 
        /* call into the plugins to set the new value */
        gs_app_set_rating (priv->app, rating);
+       gs_app_set_rating_kind (priv->app, GS_APP_RATING_KIND_USER);
        gs_plugin_loader_app_action_async (priv->plugin_loader, priv->app,
                                           GS_PLUGIN_LOADER_ACTION_SET_RATING,
                                           priv->cancellable,
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index a99fa8f..82e5e91 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -28,6 +28,7 @@
 
 struct _GsStarWidgetPrivate
 {
+       GsAppRatingKind  rating_kind;
        gint             rating;
        GtkWidget       *button1;
        GtkWidget       *button2;
@@ -68,18 +69,25 @@ gs_star_widget_get_rating (GsStarWidget *star)
  * gs_star_widget_set_image_rating:
  **/
 static void
-gs_star_widget_set_image_rating (GtkImage *image,
+gs_star_widget_set_image_rating (GtkImage *image, GsAppRatingKind rating_kind,
                                 gint value, gint lower, gint higher)
 {
        GtkStyleContext *context;
        const gchar *icon_name = "semi-starred-symbolic";
+
        if (value <= lower)
                icon_name = "non-starred-symbolic";
        if (value >= higher)
                icon_name = "starred-symbolic";
 
        context = gtk_widget_get_style_context (GTK_WIDGET (image));
-       gtk_style_context_add_class (context, "star");
+       if (rating_kind == GS_APP_RATING_KIND_USER) {
+               gtk_style_context_add_class (context, "star-user");
+               gtk_style_context_remove_class (context, "star");
+       } else {
+               gtk_style_context_add_class (context, "star");
+               gtk_style_context_remove_class (context, "star-user");
+       }
        gtk_image_set_from_icon_name (image, icon_name, GTK_ICON_SIZE_MENU);
 }
 
@@ -93,18 +101,23 @@ gs_star_widget_refresh (GsStarWidget *star)
        priv = gs_star_widget_get_instance_private (star);
 
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image1),
+                                        priv->rating_kind,
                                         priv->rating,
                                         0, rate_to_star[0]);
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image2),
+                                        priv->rating_kind,
                                         priv->rating,
                                         rate_to_star[0], rate_to_star[1]);
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image3),
+                                        priv->rating_kind,
                                         priv->rating,
                                         rate_to_star[1], rate_to_star[2]);
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image4),
+                                        priv->rating_kind,
                                         priv->rating,
                                         rate_to_star[2], rate_to_star[3]);
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image5),
+                                        priv->rating_kind,
                                         priv->rating,
                                         rate_to_star[3], rate_to_star[4]);
 }
@@ -113,12 +126,15 @@ gs_star_widget_refresh (GsStarWidget *star)
  * gs_star_widget_set_rating:
  **/
 void
-gs_star_widget_set_rating (GsStarWidget *star, gint rating)
+gs_star_widget_set_rating (GsStarWidget *star,
+                          GsAppRatingKind rating_kind,
+                          gint rating)
 {
        GsStarWidgetPrivate *priv;
        g_return_if_fail (GS_IS_STAR_WIDGET (star));
        priv = gs_star_widget_get_instance_private (star);
        priv->rating = rating;
+       priv->rating_kind = rating_kind;
        gs_star_widget_refresh (star);
 }
 
diff --git a/src/gs-star-widget.h b/src/gs-star-widget.h
index 24fe418..e3118ba 100644
--- a/src/gs-star-widget.h
+++ b/src/gs-star-widget.h
@@ -24,6 +24,8 @@
 
 #include <gtk/gtk.h>
 
+#include "gs-app.h"
+
 #define GS_TYPE_STAR_WIDGET            (gs_star_widget_get_type())
 #define GS_STAR_WIDGET(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GS_TYPE_STAR_WIDGET, GsStarWidget))
 #define GS_STAR_WIDGET_CLASS(cls)      (G_TYPE_CHECK_CLASS_CAST((cls), GS_TYPE_STAR_WIDGET, 
GsStarWidgetClass))
@@ -54,6 +56,7 @@ GType          gs_star_widget_get_type                (void);
 GtkWidget      *gs_star_widget_new                     (void);
 gint            gs_star_widget_get_rating              (GsStarWidget   *star);
 void            gs_star_widget_set_rating              (GsStarWidget   *star,
+                                                        GsAppRatingKind rating_kind,
                                                         gint            rating);
 
 G_END_DECLS
diff --git a/src/gtk-style.css b/src/gtk-style.css
index eb980b3..3033e28 100644
--- a/src/gtk-style.css
+++ b/src/gtk-style.css
@@ -94,6 +94,10 @@ GtkNotebook.main-notebook-software > GtkScrolledWindow {
        color: #888a85;
 }
 
+.star-user {
+       color: #edd400;
+}
+
 .counter-label {
     color: @theme_selected_fg_color;
     background-color: mix(@theme_selected_bg_color, @theme_selected_fg_color, 0.3);
diff --git a/src/plugins/gs-plugin-fedora-tagger.c b/src/plugins/gs-plugin-fedora-tagger.c
index 7071dfa..7cb88d9 100644
--- a/src/plugins/gs-plugin-fedora-tagger.c
+++ b/src/plugins/gs-plugin-fedora-tagger.c
@@ -584,6 +584,7 @@ gs_plugin_refine (GsPlugin *plugin,
                                g_debug ("fedora-tagger setting rating on %s to %i",
                                         pkgname, rating);
                                gs_app_set_rating (app, rating);
+                               gs_app_set_rating_kind (app, GS_APP_RATING_KIND_SYSTEM);
                        }
                }
        }
diff --git a/src/plugins/gs-plugin-local-ratings.c b/src/plugins/gs-plugin-local-ratings.c
index be398fb..0edb465 100644
--- a/src/plugins/gs-plugin-local-ratings.c
+++ b/src/plugins/gs-plugin-local-ratings.c
@@ -231,8 +231,10 @@ gs_plugin_refine (GsPlugin *plugin,
                if (gs_app_get_rating (app) != -1)
                        continue;
                rating = gs_plugin_local_find_app (plugin, gs_app_get_id (app));
-               if (rating != -1)
+               if (rating != -1) {
                        gs_app_set_rating (app, rating);
+                       gs_app_set_rating_kind (app, GS_APP_RATING_KIND_USER);
+               }
        }
 out:
        return ret;


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