From 018d5927d50a8f8af50acf1b77761e8fa3dc9153 Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Thu, 27 Sep 2018 22:08:03 +0200 Subject: [PATCH] HaikuDepot : User-Rating / Star Selection Fix This commit resolves a problem where the user-rating is able to specify a rating (how many stars) or not. The behaviour was not properly honouring the checkbox to specify if the rating was to be used or not. Change-Id: I01067bf899e1d5beab1474a197c5698166b9f582 Reviewed-on: https://review.haiku-os.org/600 Reviewed-by: waddlesplash --- src/apps/haikudepot/server/WebAppInterface.h | 4 ++++ src/apps/haikudepot/ui/RatePackageWindow.cpp | 21 +++++++++++++------- src/apps/haikudepot/ui/RatePackageWindow.h | 1 + 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/apps/haikudepot/server/WebAppInterface.h b/src/apps/haikudepot/server/WebAppInterface.h index 099cf77ab5..543aac1557 100644 --- a/src/apps/haikudepot/server/WebAppInterface.h +++ b/src/apps/haikudepot/server/WebAppInterface.h @@ -33,6 +33,10 @@ typedef List StringList; #define ERROR_CODE_LIMITEXCEEDED -32805 #define ERROR_CODE_AUTHORIZATIONRULECONFLICT -32806 +/*! This constant can be used to indicate the lack of a rating. */ + +#define RATING_NONE -1 + class WebAppInterface { public: diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp b/src/apps/haikudepot/ui/RatePackageWindow.cpp index 13c74c744a..975a82cf3d 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.cpp +++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp @@ -202,7 +202,8 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame, fModel(model), fRatingText(), fTextEditor(new TextEditor(), true), - fRating(-1.0f), + fRating(RATING_NONE), + fRatingDeterminate(false), fCommentLanguage(fModel.PreferredLanguage()), fWorkerThread(-1) { @@ -337,6 +338,7 @@ RatePackageWindow::MessageReceived(BMessage* message) switch (message->what) { case MSG_PACKAGE_RATED: message->FindFloat("rating", &fRating); + fRatingDeterminate = true; fSetRatingView->SetRatingDeterminate(true); fRatingDeterminateCheckBox->SetValue(B_CONTROL_ON); break; @@ -350,8 +352,9 @@ RatePackageWindow::MessageReceived(BMessage* message) break; case MSG_RATING_DETERMINATE_CHANGED: - fSetRatingView->SetRatingDeterminate( - fRatingDeterminateCheckBox->Value() == B_CONTROL_ON); + fRatingDeterminate = fRatingDeterminateCheckBox->Value() + == B_CONTROL_ON; + fSetRatingView->SetRatingDeterminate(fRatingDeterminate); break; case MSG_RATING_ACTIVE_CHANGED: @@ -520,14 +523,15 @@ RatePackageWindow::_RelayServerDataToUI(BMessage& response) double rating; if (response.FindDouble("rating", &rating) == B_OK) { fRating = (float)rating; + fRatingDeterminate = fRating >= 0.0f; fSetRatingView->SetPermanentRating(fRating); - fSetRatingView->SetRatingDeterminate(true); - fRatingDeterminateCheckBox->SetValue(B_CONTROL_ON); } else { - fSetRatingView->SetRatingDeterminate(false); - fRatingDeterminateCheckBox->SetValue(B_CONTROL_OFF); + fRatingDeterminate = false; } + fSetRatingView->SetRatingDeterminate(fRatingDeterminate); + fRatingDeterminateCheckBox->SetValue( + fRatingDeterminate ? B_CONTROL_ON : B_CONTROL_OFF); fRatingActiveCheckBox->SetValue(fRatingActive); fRatingActiveCheckBox->Show(); @@ -649,6 +653,9 @@ RatePackageWindow::_SendRatingThread() BString ratingID = fRatingID; bool active = fRatingActive; + if (!fRatingDeterminate) + rating = RATING_NONE; + const DepotInfo* depot = fModel.DepotForName(fPackage->DepotName()); if (depot != NULL) diff --git a/src/apps/haikudepot/ui/RatePackageWindow.h b/src/apps/haikudepot/ui/RatePackageWindow.h index b5c6889f79..04ca5f0183 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.h +++ b/src/apps/haikudepot/ui/RatePackageWindow.h @@ -53,6 +53,7 @@ private: TextDocumentRef fRatingText; TextEditorRef fTextEditor; float fRating; + bool fRatingDeterminate; BString fStability; StabilityRatingList fStabilityCodes; BString fCommentLanguage;