HaikuDepot: Change when featured packages are shown

* Renamed the "Option" menu to "Show", removed the now redundant "Show" from
   the items in that menu.
 * Add an "Only featured packages" item in the Show menu. This item is disabled
   as soon as the user types something in the search terms field. Othetwise,
   this setting is respected, i.e. one can combine the featured setting with
   other settings, i.e. show all featured packages of a certain depot and in a
   certain category.
 * Added PackageInfo::IsProminent() and removed the respective method from
   the MainWindow (which only considered a package prominent if it was not
   yet installed).
 * "Show -> Installed packages" now defaults to on. There have been complaints
   on Trac and I guess rightfully so. The use-cases in which one starts
   HaikuDepot and wants to know about installed packages are just as likely
   as the use-case where one wants to install new software.
This commit is contained in:
Stephan Aßmus 2014-12-26 22:08:08 +01:00
parent 1514783a71
commit 4fade61ff8
6 changed files with 52 additions and 25 deletions

View File

@ -333,8 +333,9 @@ Model::Model()
fDepotFilter(""),
fSearchTermsFilter(PackageFilterRef(new AnyFilter(), true)),
fShowFeaturedPackages(true),
fShowAvailablePackages(true),
fShowInstalledPackages(false),
fShowInstalledPackages(true),
fShowSourcePackages(false),
fShowDevelopPackages(false),
@ -422,6 +423,7 @@ Model::CreatePackageList() const
const PackageInfoRef& package = packages.ItemAtFast(j);
if (fCategoryFilter->AcceptsPackage(package)
&& fSearchTermsFilter->AcceptsPackage(package)
&& (package->IsProminent() || !fShowFeaturedPackages)
&& (fShowAvailablePackages || package->State() != NONE)
&& (fShowInstalledPackages || package->State() != ACTIVATED)
&& (fShowSourcePackages || !is_source_package(package))
@ -551,6 +553,13 @@ Model::SearchTerms() const
}
void
Model::SetShowFeaturedPackages(bool show)
{
fShowFeaturedPackages = show;
}
void
Model::SetShowAvailablePackages(bool show)
{

View File

@ -97,6 +97,9 @@ public:
void SetSearchTerms(const BString& searchTerms);
BString SearchTerms() const;
void SetShowFeaturedPackages(bool show);
bool ShowFeaturedPackages() const
{ return fShowFeaturedPackages; }
void SetShowAvailablePackages(bool show);
bool ShowAvailablePackages() const
{ return fShowAvailablePackages; }
@ -207,6 +210,7 @@ private:
BString fDepotFilter;
PackageFilterRef fSearchTermsFilter;
bool fShowFeaturedPackages;
bool fShowAvailablePackages;
bool fShowInstalledPackages;
bool fShowSourcePackages;

View File

@ -847,6 +847,13 @@ PackageInfo::SetProminence(float prominence)
}
bool
PackageInfo::IsProminent() const
{
return HasProminence() && Prominence() <= 200;
}
void
PackageInfo::ClearScreenshotInfos()
{

View File

@ -322,6 +322,7 @@ public:
{ return fProminence; }
bool HasProminence() const
{ return fProminence != 0.0f; }
bool IsProminent() const;
void ClearScreenshotInfos();
bool AddScreenshotInfo(const ScreenshotInfo& info);

View File

@ -65,6 +65,7 @@ enum {
MSG_AUTHORIZATION_CHANGED = 'athc',
MSG_PACKAGE_CHANGED = 'pchd',
MSG_SHOW_FEATURED_PACKAGES = 'sofp',
MSG_SHOW_AVAILABLE_PACKAGES = 'savl',
MSG_SHOW_INSTALLED_PACKAGES = 'sins',
MSG_SHOW_SOURCE_PACKAGES = 'ssrc',
@ -322,6 +323,15 @@ MainWindow::MessageReceived(BMessage* message)
_UpdateAuthorization();
break;
case MSG_SHOW_FEATURED_PACKAGES:
{
BAutolock locker(fModel.Lock());
fModel.SetShowFeaturedPackages(
!fModel.ShowFeaturedPackages());
}
_AdoptModel();
break;
case MSG_SHOW_AVAILABLE_PACKAGES:
{
BAutolock locker(fModel.Lock());
@ -429,7 +439,7 @@ MainWindow::MessageReceived(BMessage* message)
}
if ((changes & PKG_CHANGED_PROMINENCE) != 0) {
BAutolock locker(fModel.Lock());
if (_IsProminentPackage(ref))
if (ref->IsProminent())
fFeaturedPackagesView->AddPackage(ref);
}
}
@ -517,27 +527,34 @@ MainWindow::_BuildMenu(BMenuBar* menuBar)
menuBar->AddItem(menu);
menu = new BMenu(B_TRANSLATE("Options"));
menu = new BMenu(B_TRANSLATE("Show"));
fShowFeaturedPackagesItem = new BMenuItem(
B_TRANSLATE("Only featured packages"),
new BMessage(MSG_SHOW_FEATURED_PACKAGES));
menu->AddItem(fShowFeaturedPackagesItem);
menu->AddSeparatorItem();
fShowAvailablePackagesItem = new BMenuItem(
B_TRANSLATE("Show available packages"),
B_TRANSLATE("Available packages"),
new BMessage(MSG_SHOW_AVAILABLE_PACKAGES));
menu->AddItem(fShowAvailablePackagesItem);
fShowInstalledPackagesItem = new BMenuItem(
B_TRANSLATE("Show installed packages"),
B_TRANSLATE("Installed packages"),
new BMessage(MSG_SHOW_INSTALLED_PACKAGES));
menu->AddItem(fShowInstalledPackagesItem);
menu->AddSeparatorItem();
fShowDevelopPackagesItem = new BMenuItem(
B_TRANSLATE("Show develop packages"),
B_TRANSLATE("Develop packages"),
new BMessage(MSG_SHOW_DEVELOP_PACKAGES));
menu->AddItem(fShowDevelopPackagesItem);
fShowSourcePackagesItem = new BMenuItem(
B_TRANSLATE("Show source packages"),
B_TRANSLATE("Source packages"),
new BMessage(MSG_SHOW_SOURCE_PACKAGES));
menu->AddItem(fShowSourcePackagesItem);
@ -596,32 +613,22 @@ MainWindow::_AdoptModel()
const PackageInfoRef& package = fVisiblePackages.ItemAtFast(i);
fPackageListView->AddPackage(package);
if (_IsProminentPackage(package))
if (package->IsProminent())
fFeaturedPackagesView->AddPackage(package);
}
BAutolock locker(fModel.Lock());
fShowFeaturedPackagesItem->SetMarked(fModel.ShowFeaturedPackages());
fShowFeaturedPackagesItem->SetEnabled(fModel.SearchTerms() == "");
fShowAvailablePackagesItem->SetMarked(fModel.ShowAvailablePackages());
fShowInstalledPackagesItem->SetMarked(fModel.ShowInstalledPackages());
fShowSourcePackagesItem->SetMarked(fModel.ShowSourcePackages());
fShowDevelopPackagesItem->SetMarked(fModel.ShowDevelopPackages());
if (fModel.Category() != ""
|| fModel.Depot() != ""
|| fModel.SearchTerms() != ""
|| fModel.ShowInstalledPackages()) {
fListLayout->SetVisibleItem((int32)1);
} else {
if (fModel.ShowFeaturedPackages() && fModel.SearchTerms() == "")
fListLayout->SetVisibleItem((int32)0);
}
}
bool
MainWindow::_IsProminentPackage(const PackageInfoRef& package) const
{
return package->HasProminence() && package->Prominence() <= 200
&& package->State() != ACTIVATED;
else
fListLayout->SetVisibleItem((int32)1);
}

View File

@ -65,8 +65,6 @@ private:
void _InitWorkerThreads();
void _AdoptModel();
bool _IsProminentPackage(
const PackageInfoRef& package) const;
void _AdoptPackage(const PackageInfoRef& package);
void _ClearPackage();
@ -102,6 +100,7 @@ private:
BMenuItem* fLogInItem;
BMenuItem* fLogOutItem;
BMenuItem* fShowFeaturedPackagesItem;
BMenuItem* fShowAvailablePackagesItem;
BMenuItem* fShowInstalledPackagesItem;
BMenuItem* fShowDevelopPackagesItem;