[gnome-software] Re-enable the star widgets



commit 0333391db8f975d3015ffdd75feb88a70b7b4c45
Author: Richard Hughes <richard hughsie com>
Date:   Thu Feb 27 12:00:02 2014 +0000

    Re-enable the star widgets
    
    Resolves: https://bugzilla.gnome.org/show_bug.cgi?id=723760

 src/gs-app-widget.c    |   12 +++++++++---
 src/gs-app.c           |   12 ++++++++++++
 src/gs-app.h           |    2 ++
 src/gs-shell-details.c |   12 +++++++++---
 src/gs-star-widget.c   |    3 ---
 5 files changed, 32 insertions(+), 9 deletions(-)
---
diff --git a/src/gs-app-widget.c b/src/gs-app-widget.c
index 4cb74c3..33f7038 100644
--- a/src/gs-app-widget.c
+++ b/src/gs-app-widget.c
@@ -156,9 +156,15 @@ gs_app_widget_refresh (GsAppWidget *app_widget)
                gtk_widget_hide (priv->version_label);
                gtk_widget_show (priv->star);
                gtk_widget_set_sensitive (priv->star, FALSE);
-               gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
-                                          gs_app_get_rating_kind (priv->app),
-                                          gs_app_get_rating (priv->app));
+               if (gs_app_get_rating_kind (priv->app) == GS_APP_RATING_KIND_USER) {
+                       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
+                                                  GS_APP_RATING_KIND_USER,
+                                                  gs_app_get_rating (priv->app));
+               } else {
+                       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
+                                                  GS_APP_RATING_KIND_KUDOS,
+                                                  gs_app_get_kudos_weight (priv->app));
+               }
                gtk_label_set_label (GTK_LABEL (priv->version_label),
                                     gs_app_get_version_ui (priv->app));
        }
diff --git a/src/gs-app.c b/src/gs-app.c
index 9b173d8..5a221ac 100644
--- a/src/gs-app.c
+++ b/src/gs-app.c
@@ -1594,6 +1594,18 @@ gs_app_get_kudos (GsApp *app)
 }
 
 /**
+ * gs_app_get_kudos_weight:
+ */
+guint
+gs_app_get_kudos_weight (GsApp *app)
+{
+       guint32 tmp = app->priv->kudos;
+       tmp = tmp - ((tmp >> 1) & 0x55555555);
+       tmp = (tmp & 0x33333333) + ((tmp >> 2) & 0x33333333);
+       return (((tmp + (tmp >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
+}
+
+/**
  * gs_app_subsume:
  *
  * Imports all the useful data from @other into @app.
diff --git a/src/gs-app.h b/src/gs-app.h
index 755c056..929b9e0 100644
--- a/src/gs-app.h
+++ b/src/gs-app.h
@@ -94,6 +94,7 @@ typedef enum {
        GS_APP_RATING_KIND_UNKNOWN,
        GS_APP_RATING_KIND_USER,
        GS_APP_RATING_KIND_SYSTEM,
+       GS_APP_RATING_KIND_KUDOS,
        GS_APP_RATING_KIND_LAST
 } GsAppRatingKind;
 
@@ -262,6 +263,7 @@ void                 gs_app_set_keywords            (GsApp          *app,
 void            gs_app_add_kudo                (GsApp          *app,
                                                 GsAppKudo       kudo);
 guint64                 gs_app_get_kudos               (GsApp          *app);
+guint           gs_app_get_kudos_weight        (GsApp          *app);
 
 G_END_DECLS
 
diff --git a/src/gs-shell-details.c b/src/gs-shell-details.c
index 5fbb772..2309566 100644
--- a/src/gs-shell-details.c
+++ b/src/gs-shell-details.c
@@ -670,9 +670,15 @@ gs_shell_details_refresh_all (GsShellDetails *shell_details)
                break;
        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));
+               if (gs_app_get_rating_kind (priv->app) == GS_APP_RATING_KIND_USER) {
+                       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
+                                                  GS_APP_RATING_KIND_USER,
+                                                  gs_app_get_rating (priv->app));
+               } else {
+                       gs_star_widget_set_rating (GS_STAR_WIDGET (priv->star),
+                                                  GS_APP_RATING_KIND_KUDOS,
+                                                  gs_app_get_kudos_weight (priv->app));
+               }
                break;
        }
 
diff --git a/src/gs-star-widget.c b/src/gs-star-widget.c
index 0df3028..bfd3c45 100644
--- a/src/gs-star-widget.c
+++ b/src/gs-star-widget.c
@@ -115,9 +115,6 @@ gs_star_widget_refresh (GsStarWidget *star)
 {
        GsStarWidgetPrivate *priv;
        priv = gs_star_widget_get_instance_private (star);
-
-       /* disabled, see https://bugzilla.gnome.org/show_bug.cgi?id=723760 */
-       gtk_widget_set_visible (GTK_WIDGET (star), FALSE);
        gs_star_widget_set_image_rating (GTK_IMAGE (priv->image1),
                                         priv->rating_kind,
                                         priv->rating,


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