From 95e4ca3d0063511f9d76ed36b68df498a277b643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 24 Aug 2014 19:21:50 +0200 Subject: [PATCH] HaikuDepot: Fill some categories and rating summary from web app response. This still uses the request I had prepared earlier, not the new bulk request which can get information for the entire package list in one request. It also has no caching, so it runs for quite a while in the background (dedicated thread, so hopefully no harm done by keeping it enabled). Thanks Augustin, for the parser! --- src/apps/haikudepot/Model.cpp | 38 +++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/src/apps/haikudepot/Model.cpp b/src/apps/haikudepot/Model.cpp index d8d0624435..3f6d2f1ca1 100644 --- a/src/apps/haikudepot/Model.cpp +++ b/src/apps/haikudepot/Model.cpp @@ -609,7 +609,7 @@ Model::_PopulateAllPackagesThread(bool fromCacheOnly) if (package.Get() == NULL) continue; -// _PopulatePackageInfo(package, fromCacheOnly); + _PopulatePackageInfo(package, fromCacheOnly); _PopulatePackageIcon(package, fromCacheOnly); // TODO: Average user rating. It needs to be shown in the // list view, so without the user clicking the package. @@ -629,8 +629,42 @@ Model::_PopulatePackageInfo(const PackageInfoRef& package, bool fromCacheOnly) status_t status = interface.RetrievePackageInfo(package->Title(), info); if (status == B_OK) { - // TODO: Parse message... + // Parse message info.PrintToStream(); + BMessage result; + if (info.FindMessage("result", &result) == B_OK) { + BMessage categories; + if (result.FindMessage("pkgCategoryCodes", &categories) == B_OK) { + int32 index = 0; + while (true) { + BString name; + name << index++; + BString category; + if (categories.FindString(name, &category) != B_OK) + break; + + if (category == "AUDIO") + package->AddCategory(CategoryAudio()); + else if (category == "VIDEO") + package->AddCategory(CategoryVideo()); + else if (category == "DEVELOPMENT") + package->AddCategory(CategoryDevelopment()); + // TODO: ... + } + } + double derivedRating; + double derivedRatingSampleSize; + if (result.FindDouble("derivedRating", &derivedRating) == B_OK + && result.FindDouble("derivedRatingSampleSize", + &derivedRatingSampleSize) == B_OK) { + if (derivedRatingSampleSize > 0) { + RatingSummary summary; + summary.averageRating = derivedRating; + summary.ratingCount = (int)derivedRatingSampleSize; + package->SetRatingSummary(summary); + } + } + } } }