hrev47930 adds 7 changesets to branch 'master' old head: cec1192ea0f9a4d5be486921e506fadcb9310fb2 new head: 6e80c1ca11a81c8187f4f3edb4adbb62d570fc9d overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=6e80c1c+%5Ecec1192 ---------------------------------------------------------------------------- 0ba9258: HaikuDepot: Use B_USE_WINDOW_INSETS in login window 8ecb43a: HaikuDepot: Display check box to deactivate rating ... if a rating already exists for the given package and version. 965707a: HaikuDepot: Rating and login window have no system names. 24cde1e: HaikuDepot: Added WebAppInterface getter to Model fca4717: HaikuDepot: Implemented creating and updating ratings... ... in WebAppInterface. Both types of requests fail at the moment. Creating a rating failes due to invalid authentication (I thought I am doing it correctly), updating fails with a NullPointerException on the server. e824035: HaikuDepot: Fixed missing space in error alert. 6e80c1c: HaikuDepot: Implemented creating/updating ratings... ... from the RatePackageWindow. It does not work yet, the errors are reported. To be investigated... [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 6 files changed, 212 insertions(+), 18 deletions(-) src/apps/haikudepot/model/Model.h | 4 + src/apps/haikudepot/model/WebAppInterface.cpp | 53 ++++++++ src/apps/haikudepot/model/WebAppInterface.h | 17 +++ src/apps/haikudepot/ui/RatePackageWindow.cpp | 145 +++++++++++++++++++--- src/apps/haikudepot/ui/RatePackageWindow.h | 5 + src/apps/haikudepot/ui/UserLoginWindow.cpp | 6 +- ############################################################################ Commit: 0ba9258d0fae65b60abd93e9bc1b6591254963f9 URL: http://cgit.haiku-os.org/haiku/commit/?id=0ba9258 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 20:22:30 2014 UTC HaikuDepot: Use B_USE_WINDOW_INSETS in login window ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp b/src/apps/haikudepot/ui/UserLoginWindow.cpp index 682d0f5..e89bcff 100644 --- a/src/apps/haikudepot/ui/UserLoginWindow.cpp +++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp @@ -158,7 +158,7 @@ UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model) .Add(fCancelButton) .Add(fSendButton) .End() - .SetInsets(B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) ; SetDefaultButton(fSendButton); ############################################################################ Commit: 8ecb43af281b87c23f3c6418cc065e6ecdc9e696 URL: http://cgit.haiku-os.org/haiku/commit/?id=8ecb43a Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 20:23:15 2014 UTC HaikuDepot: Display check box to deactivate rating ... if a rating already exists for the given package and version. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp b/src/apps/haikudepot/ui/RatePackageWindow.cpp index 0201502..6125917 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.cpp +++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp @@ -12,6 +12,7 @@ #include <Autolock.h> #include <Catalog.h> #include <Button.h> +#include <CheckBox.h> #include <LayoutBuilder.h> #include <MenuField.h> #include <MenuItem.h> @@ -30,10 +31,11 @@ enum { - MSG_SEND = 'send', - MSG_PACKAGE_RATED = 'rpkg', - MSG_STABILITY_SELECTED = 'stbl', - MSG_LANGUAGE_SELECTED = 'lngs' + MSG_SEND = 'send', + MSG_PACKAGE_RATED = 'rpkg', + MSG_STABILITY_SELECTED = 'stbl', + MSG_LANGUAGE_SELECTED = 'lngs', + MSG_RATING_ACTIVE_CHANGED = 'rtac' }; //! Layouts the scrollbar so it looks nice with no border and the document @@ -237,6 +239,13 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame, if (defaultItem != NULL) defaultItem->SetMarked(true); + fRatingActiveCheckBox = new BCheckBox("rating active", + B_TRANSLATE("Other users can see this rating"), + new BMessage(MSG_RATING_ACTIVE_CHANGED)); + // Hide the check mark by default, it will be made visible when + // the user already made a rating and it is loaded + fRatingActiveCheckBox->Hide(); + // Construct buttons fCancelButton = new BButton("cancel", B_TRANSLATE("Cancel"), new BMessage(B_QUIT_REQUESTED)); @@ -254,11 +263,12 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame, .End() .Add(textScrollView) .AddGroup(B_HORIZONTAL) + .Add(fRatingActiveCheckBox) .AddGlue() .Add(fCancelButton) .Add(fSendButton) .End() - .SetInsets(B_USE_DEFAULT_SPACING) + .SetInsets(B_USE_WINDOW_INSETS) ; // NOTE: Do not make Send the default button. The user might want @@ -288,6 +298,14 @@ RatePackageWindow::MessageReceived(BMessage* message) case MSG_LANGUAGE_SELECTED: message->FindString("code", &fCommentLanguage); break; + + case MSG_RATING_ACTIVE_CHANGED: + { + int32 value; + if (message->FindInt32("be:value", &value) == B_OK) + fRatingActive = value == B_CONTROL_ON; + break; + } case MSG_SEND: _SendRating(); @@ -435,6 +453,9 @@ RatePackageWindow::_QueryRatingThread() fRating = (float)rating; fSetRatingView->SetPermanentRating(fRating); } + + fRatingActiveCheckBox->SetValue(fRatingActive); + fRatingActiveCheckBox->Show(); Unlock(); } diff --git a/src/apps/haikudepot/ui/RatePackageWindow.h b/src/apps/haikudepot/ui/RatePackageWindow.h index be9ecc7..f60c538 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.h +++ b/src/apps/haikudepot/ui/RatePackageWindow.h @@ -14,6 +14,7 @@ class BButton; +class BCheckBox; class BMenuField; class SetRatingView; class TextDocumentView; @@ -53,6 +54,7 @@ private: BMenuField* fStabilityField; BMenuField* fCommentLanguageField; TextDocumentView* fTextView; + BCheckBox* fRatingActiveCheckBox; BButton* fCancelButton; BButton* fSendButton; ############################################################################ Commit: 965707a9bbfd077a9bc885c83ddd4bdff50fcd23 URL: http://cgit.haiku-os.org/haiku/commit/?id=965707a Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 20:30:59 2014 UTC HaikuDepot: Rating and login window have no system names. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp b/src/apps/haikudepot/ui/RatePackageWindow.cpp index 6125917..d0e384c 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.cpp +++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp @@ -172,7 +172,7 @@ add_languages_to_menu(const StringList& languages, BMenu* menu) RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame, Model& model) : - BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Your rating"), + BWindow(frame, B_TRANSLATE("Rate package"), B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS), fModel(model), @@ -327,6 +327,10 @@ RatePackageWindow::SetPackage(const PackageInfoRef& package) fPackage = package; + BString windowTitle(B_TRANSLATE("Rate %Package%")); + windowTitle.ReplaceAll("%Package%", package->Title()); + SetTitle(windowTitle); + // See if the user already made a rating for this package, // pre-fill the UI with that rating. (When sending the rating, the // old one will be replaced.) @@ -457,6 +461,8 @@ RatePackageWindow::_QueryRatingThread() fRatingActiveCheckBox->SetValue(fRatingActive); fRatingActiveCheckBox->Show(); + fSendButton->SetLabel(B_TRANSLATE("Update")); + Unlock(); } diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp b/src/apps/haikudepot/ui/UserLoginWindow.cpp index e89bcff..a9159a2 100644 --- a/src/apps/haikudepot/ui/UserLoginWindow.cpp +++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp @@ -77,7 +77,7 @@ add_languages_to_menu(const StringList& languages, BMenu* menu) UserLoginWindow::UserLoginWindow(BWindow* parent, BRect frame, Model& model) : - BWindow(frame, B_TRANSLATE_SYSTEM_NAME("Log in"), + BWindow(frame, B_TRANSLATE("Log in"), B_FLOATING_WINDOW_LOOK, B_FLOATING_SUBSET_WINDOW_FEEL, B_ASYNCHRONOUS_CONTROLS | B_AUTO_UPDATE_SIZE_LIMITS | B_NOT_RESIZABLE | B_NOT_ZOOMABLE), ############################################################################ Commit: 24cde1e4ef8e15853e51429a1ecf925d944a94ab URL: http://cgit.haiku-os.org/haiku/commit/?id=24cde1e Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 21:05:11 2014 UTC HaikuDepot: Added WebAppInterface getter to Model ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h index 4d7b21f..69fbaa4 100644 --- a/src/apps/haikudepot/model/Model.h +++ b/src/apps/haikudepot/model/Model.h @@ -129,6 +129,10 @@ public: const BString& password, bool storePassword); + const WebAppInterface& GetWebAppInterface() const + { return fWebAppInterface; } + + private: static int32 _PopulateAllPackagesEntry(void* cookie); void _PopulateAllPackagesThread(bool fromCacheOnly); ############################################################################ Commit: fca4717406df9010ce3fd46b915dc4bea7242000 URL: http://cgit.haiku-os.org/haiku/commit/?id=fca4717 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 21:05:43 2014 UTC HaikuDepot: Implemented creating and updating ratings... ... in WebAppInterface. Both types of requests fail at the moment. Creating a rating failes due to invalid authentication (I thought I am doing it correctly), updating fails with a NullPointerException on the server. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/model/WebAppInterface.cpp b/src/apps/haikudepot/model/WebAppInterface.cpp index f591d44..2dbc9c8 100644 --- a/src/apps/haikudepot/model/WebAppInterface.cpp +++ b/src/apps/haikudepot/model/WebAppInterface.cpp @@ -439,6 +439,59 @@ WebAppInterface::RetrieveUserRating(const BString& packageName, status_t +WebAppInterface::CreateUserRating(const BString& packageName, + const BString& architecture, const BString& languageCode, + const BString& comment, const BString& stability, int rating, + BMessage& message) +{ + BString jsonString = JsonBuilder() + .AddValue("jsonrpc", "2.0") + .AddValue("id", ++fRequestIndex) + .AddValue("method", "createUserRating") + .AddArray("params") + .AddObject() + .AddValue("pkgName", packageName) + .AddValue("pkgVersionArchitectureCode", architecture) + .AddValue("pkgVersionType", "LATEST") + .AddValue("userNickname", fUsername) + .AddValue("rating", rating) + .AddValue("userRatingStabilityCode", stability) + .AddValue("comment", comment) + .AddValue("naturalLanguageCode", languageCode) + .EndObject() + .EndArray() + .End(); + + return _SendJsonRequest("userrating", jsonString, true, message); +} + + +status_t +WebAppInterface::UpdateUserRating(const BString& ratingID, + const BString& languageCode, const BString& comment, + const BString& stability, int rating, bool active, BMessage& message) +{ + BString jsonString = JsonBuilder() + .AddValue("jsonrpc", "2.0") + .AddValue("id", ++fRequestIndex) + .AddValue("method", "updateUserRating") + .AddArray("params") + .AddObject() + .AddValue("code", ratingID) + .AddValue("rating", rating) + .AddValue("userRatingStabilityCode", stability) + .AddValue("comment", comment) + .AddValue("naturalLanguageCode", languageCode) + .AddValue("active", active) + .EndObject() + .EndArray() + .End(); + + return _SendJsonRequest("userrating", jsonString, true, message); +} + + +status_t WebAppInterface::RetrieveScreenshot(const BString& code, int32 width, int32 height, BDataIO* stream) { diff --git a/src/apps/haikudepot/model/WebAppInterface.h b/src/apps/haikudepot/model/WebAppInterface.h index 95f9034..6d6d35a 100644 --- a/src/apps/haikudepot/model/WebAppInterface.h +++ b/src/apps/haikudepot/model/WebAppInterface.h @@ -63,6 +63,23 @@ public: const BString& username, BMessage& message); + status_t CreateUserRating( + const BString& packageName, + const BString& architecture, + const BString& languageCode, + const BString& comment, + const BString& stability, + int rating, + BMessage& message); + + status_t UpdateUserRating( + const BString& ratingID, + const BString& languageCode, + const BString& comment, + const BString& stability, + int rating, bool active, + BMessage& message); + status_t RetrieveScreenshot( const BString& code, int32 width, int32 height, ############################################################################ Commit: e824035985f60bebe35ffad285bb4fff7b804c62 URL: http://cgit.haiku-os.org/haiku/commit/?id=e824035 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 21:19:25 2014 UTC HaikuDepot: Fixed missing space in error alert. ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/ui/UserLoginWindow.cpp b/src/apps/haikudepot/ui/UserLoginWindow.cpp index a9159a2..7a57a9b 100644 --- a/src/apps/haikudepot/ui/UserLoginWindow.cpp +++ b/src/apps/haikudepot/ui/UserLoginWindow.cpp @@ -514,7 +514,7 @@ UserLoginWindow::_CreateAccountThread() } else if (message == "validationerror") { _CollectValidationFailures(result, error); } else { - error << B_TRANSLATE("The web service responded with: "); + error << B_TRANSLATE(" It responded with: "); error << message; } } ############################################################################ Revision: hrev47930 Commit: 6e80c1ca11a81c8187f4f3edb4adbb62d570fc9d URL: http://cgit.haiku-os.org/haiku/commit/?id=6e80c1c Author: Stephan Aßmus <superstippi@xxxxxx> Date: Mon Sep 29 21:19:55 2014 UTC HaikuDepot: Implemented creating/updating ratings... ... from the RatePackageWindow. It does not work yet, the errors are reported. To be investigated... ---------------------------------------------------------------------------- diff --git a/src/apps/haikudepot/ui/RatePackageWindow.cpp b/src/apps/haikudepot/ui/RatePackageWindow.cpp index d0e384c..6fe5b94 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.cpp +++ b/src/apps/haikudepot/ui/RatePackageWindow.cpp @@ -344,15 +344,10 @@ RatePackageWindow::SetPackage(const PackageInfoRef& package) void RatePackageWindow::_SendRating() { - // TODO: Implement... - BAlert* alert = new BAlert(B_TRANSLATE("Not implemented"), - B_TRANSLATE("Sorry, while the web application would already support " - "storing your rating, HaikuDepot was not yet updated to use " - "this functionality."), - B_TRANSLATE("Thanks for telling me after I typed all this!")); - alert->Go(NULL); - - PostMessage(B_QUIT_REQUESTED); + thread_id thread = spawn_thread(&_SendRatingThreadEntry, + "Send rating", B_NORMAL_PRIORITY, this); + if (thread >= 0) + _SetWorkerThread(thread); } @@ -470,3 +465,96 @@ RatePackageWindow::_QueryRatingThread() } +int32 +RatePackageWindow::_SendRatingThreadEntry(void* data) +{ + RatePackageWindow* window = reinterpret_cast<RatePackageWindow*>(data); + window->_SendRatingThread(); + return 0; +} + + +void +RatePackageWindow::_SendRatingThread() +{ + if (!Lock()) + return; + + BString package = fPackage->Title(); + BString architecture = fPackage->Architecture(); + int rating = (int)fRating; + BString stability = fStability; + BString comment = fRatingText->Text(); + BString languageCode = fCommentLanguage; + BString ratingID = fRatingID; + bool active = fRatingActive; + + WebAppInterface interface = fModel.GetWebAppInterface(); + + Unlock(); + + status_t status; + BMessage info; + if (ratingID.Length() > 0) { + status = interface.UpdateUserRating(ratingID, + languageCode, comment, stability, rating, active, info); + } else { + status = interface.CreateUserRating(package, architecture, + languageCode, comment, stability, rating, info); + } + + info.PrintToStream(); + + BString error = B_TRANSLATE( + "There was a puzzling response from the web service."); + + BMessage result; + if (status == B_OK) { + if (info.FindMessage("result", &result) == B_OK) { + error = ""; + } else if (info.FindMessage("error", &result) == B_OK) { + result.PrintToStream(); + BString message; + if (result.FindString("message", &message) == B_OK) { + error << B_TRANSLATE(" It responded with: "); + error << message; + } + } + } else { + error = B_TRANSLATE( + "It was not possible to contact the web service."); + } + + if (!error.IsEmpty()) { + BString failedTitle; + if (ratingID.Length() > 0) + failedTitle = B_TRANSLATE("Failed to update rating"); + else + failedTitle = B_TRANSLATE("Failed to rate package"); + + BAlert* alert = new(std::nothrow) BAlert( + failedTitle, + error, + B_TRANSLATE("Close")); + + if (alert != NULL) + alert->Go(); + + fprintf(stderr, + B_TRANSLATE("Failed to create account: %s\n"), error.String()); + + _SetWorkerThread(-1); + } else { + _SetWorkerThread(-1); + BMessenger(this).SendMessage(B_QUIT_REQUESTED); + + BAlert* alert = new(std::nothrow) BAlert( + B_TRANSLATE("Success"), + B_TRANSLATE("Your rating was uploaded successfully. " + "You can update it at any time."), + B_TRANSLATE("Close")); + + if (alert != NULL) + alert->Go(); + } +} diff --git a/src/apps/haikudepot/ui/RatePackageWindow.h b/src/apps/haikudepot/ui/RatePackageWindow.h index f60c538..1835df9 100644 --- a/src/apps/haikudepot/ui/RatePackageWindow.h +++ b/src/apps/haikudepot/ui/RatePackageWindow.h @@ -38,6 +38,9 @@ private: static int32 _QueryRatingThreadEntry(void* data); void _QueryRatingThread(); + static int32 _SendRatingThreadEntry(void* data); + void _SendRatingThread(); + private: Model& fModel; TextDocumentRef fRatingText;