[gnome-software] trivial: Hide the review action buttons after voting



commit 37cde672e032a89f62f4247ecee6ba6de936c280
Author: Richard Hughes <richard hughsie com>
Date:   Tue Feb 9 21:34:26 2016 +0000

    trivial: Hide the review action buttons after voting
    
    This ensures that we don't try to vote on the same review twice.

 src/gs-review-row.c           |   38 +++++++++++++++++++++++---------------
 src/gs-review.h               |    5 +++--
 src/plugins/gs-plugin-dummy.c |    3 +++
 3 files changed, 29 insertions(+), 17 deletions(-)
---
diff --git a/src/gs-review-row.c b/src/gs-review-row.c
index f6941f5..1143f6f 100644
--- a/src/gs-review-row.c
+++ b/src/gs-review-row.c
@@ -32,6 +32,7 @@ typedef struct
        GtkListBoxRow    parent_instance;
 
        GsReview        *review;
+       guint64          actions;
        GtkWidget       *stars;
        GtkWidget       *summary_label;
        GtkWidget       *author_label;
@@ -75,6 +76,26 @@ gs_review_row_refresh (GsReviewRow *row)
                            gs_review_get_summary (priv->review));
        gtk_label_set_text (GTK_LABEL (priv->text_label),
                            gs_review_get_text (priv->review));
+
+       /* if we voted, we can't do any actions */
+       if (gs_review_get_state (priv->review) & GS_REVIEW_STATE_VOTED)
+               priv->actions = 0;
+
+       /* set actions up */
+       if ((priv->actions & (1 << GS_REVIEW_ACTION_UPVOTE |
+                             1 << GS_REVIEW_ACTION_DOWNVOTE)) == 0) {
+               gtk_widget_set_visible (priv->box_vote_buttons, FALSE);
+       } else {
+               gtk_widget_set_visible (priv->box_vote_buttons, TRUE);
+               gtk_widget_set_visible (priv->button_yes,
+                                       priv->actions & 1 << GS_REVIEW_ACTION_UPVOTE);
+               gtk_widget_set_visible (priv->button_no,
+                                       priv->actions & 1 << GS_REVIEW_ACTION_DOWNVOTE);
+       }
+       gtk_widget_set_visible (priv->button_remove,
+                               priv->actions & 1 << GS_REVIEW_ACTION_REMOVE);
+       gtk_widget_set_visible (priv->button_report,
+                               priv->actions & 1 << GS_REVIEW_ACTION_REPORT);
 }
 
 static gboolean
@@ -182,21 +203,8 @@ void
 gs_review_row_set_actions (GsReviewRow *review_row, guint64 actions)
 {
        GsReviewRowPrivate *priv = gs_review_row_get_instance_private (review_row);
-
-       if ((actions & (1 << GS_REVIEW_ACTION_UPVOTE |
-                       1 << GS_REVIEW_ACTION_DOWNVOTE)) == 0) {
-               gtk_widget_set_visible (priv->box_vote_buttons, FALSE);
-       } else {
-               gtk_widget_set_visible (priv->box_vote_buttons, TRUE);
-               gtk_widget_set_visible (priv->button_yes,
-                                       actions & 1 << GS_REVIEW_ACTION_UPVOTE);
-               gtk_widget_set_visible (priv->button_no,
-                                       actions & 1 << GS_REVIEW_ACTION_DOWNVOTE);
-       }
-       gtk_widget_set_visible (priv->button_remove,
-                               actions & 1 << GS_REVIEW_ACTION_REMOVE);
-       gtk_widget_set_visible (priv->button_report,
-                               actions & 1 << GS_REVIEW_ACTION_REPORT);
+       priv->actions = actions;
+       gs_review_row_refresh (review_row);
 }
 
 /**
diff --git a/src/gs-review.h b/src/gs-review.h
index 21aac5e..73662d0 100644
--- a/src/gs-review.h
+++ b/src/gs-review.h
@@ -40,8 +40,9 @@ typedef enum {
 } GsReviewAction;
 
 typedef enum {
-       GS_REVIEW_STATE_NONE = 0,
-       GS_REVIEW_STATE_SELF = 1 << 0,  /* user wrote the review themselves */
+       GS_REVIEW_STATE_NONE    = 0,
+       GS_REVIEW_STATE_SELF    = 1 << 0,       /* user wrote the review themselves */
+       GS_REVIEW_STATE_VOTED   = 1 << 1,       /* user voted on the review */
        GS_REVIEW_STATE_LAST
 } GsReviewState;
 
diff --git a/src/plugins/gs-plugin-dummy.c b/src/plugins/gs-plugin-dummy.c
index 020e532..00324d8 100644
--- a/src/plugins/gs-plugin-dummy.c
+++ b/src/plugins/gs-plugin-dummy.c
@@ -283,6 +283,7 @@ gs_plugin_review_report (GsPlugin *plugin,
                         GError **error)
 {
        g_debug ("Reporting dummy review");
+       gs_review_set_state (review, GS_REVIEW_STATE_VOTED);
        return TRUE;
 }
 
@@ -297,6 +298,7 @@ gs_plugin_review_upvote (GsPlugin *plugin,
                         GError **error)
 {
        g_debug ("Upvoting dummy review");
+       gs_review_set_state (review, GS_REVIEW_STATE_VOTED);
        return TRUE;
 }
 
@@ -311,6 +313,7 @@ gs_plugin_review_downvote (GsPlugin *plugin,
                           GError **error)
 {
        g_debug ("Downvoting dummy review");
+       gs_review_set_state (review, GS_REVIEW_STATE_VOTED);
        return TRUE;
 }
 


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