From b7b31be4004fdc9b32ec060451d9686a6fcb2ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Thu, 2 Oct 2014 21:39:55 +0200 Subject: [PATCH] HaikuDepot: Filter ratings by preferred languages Show only those user ratings which are in one of the languages configured in the Locale preflet's preferred languages list. --- src/apps/haikudepot/ui/PackageInfoView.cpp | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/apps/haikudepot/ui/PackageInfoView.cpp b/src/apps/haikudepot/ui/PackageInfoView.cpp index 8c492c543e..1277978e14 100644 --- a/src/apps/haikudepot/ui/PackageInfoView.cpp +++ b/src/apps/haikudepot/ui/PackageInfoView.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -1171,6 +1172,8 @@ public: .Add(scrollView, 1.0f) .SetInsets(B_USE_DEFAULT_SPACING, -1.0f, -1.0f, -1.0f) ; + + _InitPreferredLanguages(); } virtual ~UserRatingsView() @@ -1200,10 +1203,12 @@ public: } // TODO: Sort by age or usefullness rating - // TODO: Optionally hide ratings that are not in the system language - for (int i = count - 1; i >= 0; i--) { const UserRating& rating = userRatings.ItemAtFast(i); + if (fPreferredLanguages.CountItems() > 0 + && !fPreferredLanguages.Contains(rating.Language())) { + continue; + } RatingItemView* view = new RatingItemView(rating, fThumbsUpIcon, fThumbsDownIcon); fRatingContainerLayout->AddView(0, view); @@ -1230,11 +1235,35 @@ public: } } +private: + void _InitPreferredLanguages() + { + fPreferredLanguages.Clear(); + + BLocaleRoster* localeRoster = BLocaleRoster::Default(); + if (localeRoster == NULL) + return; + + BMessage preferredLanguages; + if (localeRoster->GetPreferredLanguages(&preferredLanguages) != B_OK) + return; + + BString language; + int32 index = 0; + while (preferredLanguages.FindString("language", index++, + &language) == B_OK) { + BString languageCode; + language.CopyInto(languageCode, 0, 2); + fPreferredLanguages.Add(languageCode); + } + } + private: BGroupLayout* fRatingContainerLayout; RatingSummaryView* fRatingSummaryView; BitmapRef fThumbsUpIcon; BitmapRef fThumbsDownIcon; + StringList fPreferredLanguages; };