HaikuDepot: Lists & Prominences

Use BStringList instead of bespoke List class for
lists of strings.

Also fix the prominences so that the sort
ordering in the featured packages uses the sorting
algorithm properly.

Relates To #15534

Change-Id: I56e67931aa08e6bfee6d2be21a459152216790e2
Reviewed-on: https://review.haiku-os.org/c/haiku/+/3232
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
Andrew Lindesay 2020-09-18 22:24:52 +12:00
parent 5c32512076
commit 4af3fbf906
6 changed files with 36 additions and 19 deletions

View File

@ -98,9 +98,14 @@ enum UserUsageConditionsSelectionMode {
#define STR_MDASH "\xE2\x80\x94"
#define ALERT_MSG_LOGS_USER_GUIDE "\nInformation about how to view the logs is " \
"available in the HaikuDepot section of the user guide."
#define ALERT_MSG_LOGS_USER_GUIDE "\nInformation about how to view the logs " \
"is available in the HaikuDepot section of the user guide."
#define CACHE_DIRECTORY_APP "HaikuDepot"
#define PROMINANCE_ORDERING_PROMINENT_MAX 200
// any prominence ordering value greater than this is not prominent.
#define PROMINANCE_ORDERING_MAX 1000
// this is the highest prominence value possible.
#endif // HAIKU_DEPOT_CONSTANTS_H

View File

@ -241,8 +241,8 @@ public:
if (package.Get() == NULL)
return false;
// Every search term must be found in one of the package texts
for (int32 i = fSearchTerms.CountItems() - 1; i >= 0; i--) {
const BString& term = fSearchTerms.ItemAtFast(i);
for (int32 i = fSearchTerms.CountStrings() - 1; i >= 0; i--) {
const BString& term = fSearchTerms.StringAt(i);
if (!_TextContains(package->Name(), term)
&& !_TextContains(package->Title(), term)
&& !_TextContains(package->Publisher().Name(), term)
@ -257,8 +257,8 @@ public:
BString SearchTerms() const
{
BString searchTerms;
for (int32 i = 0; i < fSearchTerms.CountItems(); i++) {
const BString& term = fSearchTerms.ItemAtFast(i);
for (int32 i = 0; i < fSearchTerms.CountStrings(); i++) {
const BString& term = fSearchTerms.StringAt(i);
if (term.IsEmpty())
continue;
if (!searchTerms.IsEmpty())
@ -277,7 +277,7 @@ private:
}
private:
StringList fSearchTerms;
BStringList fSearchTerms;
};

View File

@ -883,7 +883,7 @@ PackageInfo::CalculateRatingSummary() const
void
PackageInfo::SetProminence(float prominence)
PackageInfo::SetProminence(int64 prominence)
{
if (fProminence != prominence) {
fProminence = prominence;
@ -895,7 +895,7 @@ PackageInfo::SetProminence(float prominence)
bool
PackageInfo::IsProminent() const
{
return HasProminence() && Prominence() <= 200;
return HasProminence() && Prominence() <= PROMINANCE_ORDERING_PROMINENT_MAX;
}

View File

@ -333,11 +333,11 @@ public:
void SetRatingSummary(const RatingSummary& summary);
RatingSummary CalculateRatingSummary() const;
void SetProminence(float prominence);
float Prominence() const
void SetProminence(int64 prominence);
int64 Prominence() const
{ return fProminence; }
bool HasProminence() const
{ return fProminence != 0.0f; }
{ return fProminence != 0; }
bool IsProminent() const;
void ClearScreenshotInfos();
@ -383,7 +383,7 @@ private:
CategoryList fCategories;
UserRatingList fUserRatings;
RatingSummary fCachedRatingSummary;
float fProminence;
int64 fProminence;
ScreenshotInfoList fScreenshotInfos;
BitmapList fScreenshots;
PackageState fState;
@ -461,7 +461,4 @@ private:
typedef List<DepotInfo, false> DepotList;
typedef List<BString, false> StringList;
#endif // PACKAGE_INFO_H

View File

@ -22,8 +22,6 @@ class BDataIO;
class BMessage;
using BPackageKit::BPackageVersion;
typedef List<BString, false> StringList;
/*! These are error codes that are sent back to the client from the server */

View File

@ -224,6 +224,20 @@ public:
}
static int _CmpProminences(int64 a, int64 b)
{
if (a <= 0)
a = PROMINANCE_ORDERING_MAX;
if (b <= 0)
b = PROMINANCE_ORDERING_MAX;
if (a == b)
return 0;
if (a > b)
return 1;
return -1;
}
/*! This method will return true if the packageA is ordered before
packageB.
*/
@ -233,12 +247,15 @@ public:
{
if (packageA.Get() == NULL || packageB.Get() == NULL)
debugger("unexpected NULL reference in a referencable");
int c = packageA->Title().ICompare(packageB->Title());
int c = _CmpProminences(packageA->Prominence(), packageB->Prominence());
if (c == 0)
c = packageA->Title().ICompare(packageB->Title());
if (c == 0)
c = packageA->Name().Compare(packageB->Name());
return c < 0;
}
void AddPackage(const PackageInfoRef& package)
{
// fPackages is sorted and for this reason it is possible to find the