From 4fade61ff862bff75a0e5d13fe949b7b4234a91d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Fri, 26 Dec 2014 22:08:08 +0100 Subject: [PATCH] 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. --- src/apps/haikudepot/model/Model.cpp | 11 ++++- src/apps/haikudepot/model/Model.h | 4 ++ src/apps/haikudepot/model/PackageInfo.cpp | 7 ++++ src/apps/haikudepot/model/PackageInfo.h | 1 + src/apps/haikudepot/ui/MainWindow.cpp | 51 +++++++++++++---------- src/apps/haikudepot/ui/MainWindow.h | 3 +- 6 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index ae399f8b17..3737388d9b 100644 --- a/src/apps/haikudepot/model/Model.cpp +++ b/src/apps/haikudepot/model/Model.cpp @@ -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) { diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h index e8dd1d6388..6d08833adb 100644 --- a/src/apps/haikudepot/model/Model.h +++ b/src/apps/haikudepot/model/Model.h @@ -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; diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index 7abf257cc3..8eb496aee4 100644 --- a/src/apps/haikudepot/model/PackageInfo.cpp +++ b/src/apps/haikudepot/model/PackageInfo.cpp @@ -847,6 +847,13 @@ PackageInfo::SetProminence(float prominence) } +bool +PackageInfo::IsProminent() const +{ + return HasProminence() && Prominence() <= 200; +} + + void PackageInfo::ClearScreenshotInfos() { diff --git a/src/apps/haikudepot/model/PackageInfo.h b/src/apps/haikudepot/model/PackageInfo.h index c4f53892d3..dba6288f73 100644 --- a/src/apps/haikudepot/model/PackageInfo.h +++ b/src/apps/haikudepot/model/PackageInfo.h @@ -322,6 +322,7 @@ public: { return fProminence; } bool HasProminence() const { return fProminence != 0.0f; } + bool IsProminent() const; void ClearScreenshotInfos(); bool AddScreenshotInfo(const ScreenshotInfo& info); diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index b161b36d1d..48cf785b20 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -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); } diff --git a/src/apps/haikudepot/ui/MainWindow.h b/src/apps/haikudepot/ui/MainWindow.h index 8fcc09a6bd..11e5fb2414 100644 --- a/src/apps/haikudepot/ui/MainWindow.h +++ b/src/apps/haikudepot/ui/MainWindow.h @@ -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;