HaikuDepot: Fixes for Tabs
Cleans up the code around tab-switching and also improves some logic around inserting packages into the list of 'prominent' packages by using a binary search. If Haiku is installed into an environment with no networking then it won't be able to talk to HDS and so won't know which packages are promoted. In this case switch the user to the "all packages" tab so they are not shown a blank panel by default. Relates to #14675, #14927 Change-Id: I14dd3be4af09a98245ddd0a9704bd8d53ed64a53 Reviewed-on: https://review.haiku-os.org/c/haiku/+/2478 Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
committed by
waddlesplash
parent
10cd325cfa
commit
ccf707d0bb
@@ -21,9 +21,10 @@ Captcha::Captcha(BMessage* from)
|
|||||||
fToken(""),
|
fToken(""),
|
||||||
fPngImageData(NULL)
|
fPngImageData(NULL)
|
||||||
{
|
{
|
||||||
if (from->FindString(KEY_TOKEN, &fToken) != B_OK)
|
if (from->FindString(KEY_TOKEN, &fToken) != B_OK) {
|
||||||
printf("expected key [%s] in the message data when creating a "
|
printf("expected key [%s] in the message data when creating a "
|
||||||
"Captcha\n", KEY_TOKEN);
|
"Captcha\n", KEY_TOKEN);
|
||||||
|
}
|
||||||
|
|
||||||
const void* data;
|
const void* data;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
@@ -45,8 +46,7 @@ Captcha::Captcha()
|
|||||||
|
|
||||||
Captcha::~Captcha()
|
Captcha::~Captcha()
|
||||||
{
|
{
|
||||||
if (fPngImageData != NULL)
|
delete fPngImageData;
|
||||||
delete fPngImageData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -286,19 +286,6 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class IsFeaturedFilter : public PackageFilter {
|
|
||||||
public:
|
|
||||||
IsFeaturedFilter()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual bool AcceptsPackage(const PackageInfoRef& package) const
|
|
||||||
{
|
|
||||||
return package.Get() != NULL && package->IsProminent();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static inline bool
|
static inline bool
|
||||||
is_source_package(const PackageInfoRef& package)
|
is_source_package(const PackageInfoRef& package)
|
||||||
{
|
{
|
||||||
@@ -338,14 +325,12 @@ Model::Model()
|
|||||||
fCategoryFilter(PackageFilterRef(new AnyFilter(), true)),
|
fCategoryFilter(PackageFilterRef(new AnyFilter(), true)),
|
||||||
fDepotFilter(""),
|
fDepotFilter(""),
|
||||||
fSearchTermsFilter(PackageFilterRef(new AnyFilter(), true)),
|
fSearchTermsFilter(PackageFilterRef(new AnyFilter(), true)),
|
||||||
fIsFeaturedFilter(),
|
fPackageListViewMode(PROMINENT),
|
||||||
fShowFeaturedPackages(true),
|
|
||||||
fShowAvailablePackages(true),
|
fShowAvailablePackages(true),
|
||||||
fShowInstalledPackages(true),
|
fShowInstalledPackages(true),
|
||||||
fShowSourcePackages(false),
|
fShowSourcePackages(false),
|
||||||
fShowDevelopPackages(false)
|
fShowDevelopPackages(false)
|
||||||
{
|
{
|
||||||
_UpdateIsFeaturedFilter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -399,7 +384,6 @@ Model::MatchesFilter(const PackageInfoRef& package) const
|
|||||||
{
|
{
|
||||||
return fCategoryFilter->AcceptsPackage(package)
|
return fCategoryFilter->AcceptsPackage(package)
|
||||||
&& fSearchTermsFilter->AcceptsPackage(package)
|
&& fSearchTermsFilter->AcceptsPackage(package)
|
||||||
&& fIsFeaturedFilter->AcceptsPackage(package)
|
|
||||||
&& (fShowAvailablePackages || package->State() != NONE)
|
&& (fShowAvailablePackages || package->State() != NONE)
|
||||||
&& (fShowInstalledPackages || package->State() != ACTIVATED)
|
&& (fShowInstalledPackages || package->State() != ACTIVATED)
|
||||||
&& (fShowSourcePackages || !is_source_package(package))
|
&& (fShowSourcePackages || !is_source_package(package))
|
||||||
@@ -448,6 +432,18 @@ Model::SyncDepot(const DepotInfo& depot)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
Model::HasAnyProminentPackages()
|
||||||
|
{
|
||||||
|
for (int32 i = fDepots.CountItems() - 1; i >= 0; i--) {
|
||||||
|
const DepotInfo& existingDepot = fDepots.ItemAtFast(i);
|
||||||
|
if (existingDepot.HasAnyProminentPackages())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Model::Clear()
|
Model::Clear()
|
||||||
{
|
{
|
||||||
@@ -543,7 +539,6 @@ Model::SetSearchTerms(const BString& searchTerms)
|
|||||||
filter = new SearchTermsFilter(searchTerms);
|
filter = new SearchTermsFilter(searchTerms);
|
||||||
|
|
||||||
fSearchTermsFilter.SetTo(filter, true);
|
fSearchTermsFilter.SetTo(filter, true);
|
||||||
_UpdateIsFeaturedFilter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -559,10 +554,9 @@ Model::SearchTerms() const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Model::SetShowFeaturedPackages(bool show)
|
Model::SetPackageListViewMode(package_list_view_mode mode)
|
||||||
{
|
{
|
||||||
fShowFeaturedPackages = show;
|
fPackageListViewMode = mode;
|
||||||
_UpdateIsFeaturedFilter();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -959,16 +953,6 @@ Model::DumpExportPkgDataPath(BPath& path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
Model::_UpdateIsFeaturedFilter()
|
|
||||||
{
|
|
||||||
if (fShowFeaturedPackages && SearchTerms().IsEmpty())
|
|
||||||
fIsFeaturedFilter = PackageFilterRef(new IsFeaturedFilter(), true);
|
|
||||||
else
|
|
||||||
fIsFeaturedFilter = PackageFilterRef(new AnyFilter(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
Model::_PopulatePackageScreenshot(const PackageInfoRef& package,
|
Model::_PopulatePackageScreenshot(const PackageInfoRef& package,
|
||||||
const ScreenshotInfo& info, int32 scaledWidth, bool fromCacheOnly)
|
const ScreenshotInfo& info, int32 scaledWidth, bool fromCacheOnly)
|
||||||
|
|||||||
@@ -20,6 +20,12 @@ class BMessage;
|
|||||||
class BPath;
|
class BPath;
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum package_list_view_mode {
|
||||||
|
PROMINENT,
|
||||||
|
ALL
|
||||||
|
} package_list_view_mode;
|
||||||
|
|
||||||
|
|
||||||
class PackageFilter : public BReferenceable {
|
class PackageFilter : public BReferenceable {
|
||||||
public:
|
public:
|
||||||
virtual ~PackageFilter();
|
virtual ~PackageFilter();
|
||||||
@@ -83,6 +89,7 @@ public:
|
|||||||
{ return fDepots; }
|
{ return fDepots; }
|
||||||
const DepotInfo* DepotForName(const BString& name) const;
|
const DepotInfo* DepotForName(const BString& name) const;
|
||||||
bool SyncDepot(const DepotInfo& depot);
|
bool SyncDepot(const DepotInfo& depot);
|
||||||
|
bool HasAnyProminentPackages();
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
|
|
||||||
@@ -102,9 +109,11 @@ public:
|
|||||||
void SetSearchTerms(const BString& searchTerms);
|
void SetSearchTerms(const BString& searchTerms);
|
||||||
BString SearchTerms() const;
|
BString SearchTerms() const;
|
||||||
|
|
||||||
void SetShowFeaturedPackages(bool show);
|
void SetPackageListViewMode(
|
||||||
bool ShowFeaturedPackages() const
|
package_list_view_mode mode);
|
||||||
{ return fShowFeaturedPackages; }
|
package_list_view_mode
|
||||||
|
PackageListViewMode() const
|
||||||
|
{ return fPackageListViewMode; }
|
||||||
void SetShowAvailablePackages(bool show);
|
void SetShowAvailablePackages(bool show);
|
||||||
bool ShowAvailablePackages() const
|
bool ShowAvailablePackages() const
|
||||||
{ return fShowAvailablePackages; }
|
{ return fShowAvailablePackages; }
|
||||||
@@ -136,7 +145,8 @@ public:
|
|||||||
const BString& passwordClear,
|
const BString& passwordClear,
|
||||||
bool storePassword);
|
bool storePassword);
|
||||||
|
|
||||||
const WebAppInterface& GetWebAppInterface() const
|
const WebAppInterface&
|
||||||
|
GetWebAppInterface() const
|
||||||
{ return fWebAppInterface; }
|
{ return fWebAppInterface; }
|
||||||
|
|
||||||
void ReplaceDepotByUrl(
|
void ReplaceDepotByUrl(
|
||||||
@@ -159,8 +169,6 @@ private:
|
|||||||
const BMessage &responsePayload,
|
const BMessage &responsePayload,
|
||||||
const char *sourceDescription) const;
|
const char *sourceDescription) const;
|
||||||
|
|
||||||
void _UpdateIsFeaturedFilter();
|
|
||||||
|
|
||||||
static int32 _PopulateAllPackagesEntry(void* cookie);
|
static int32 _PopulateAllPackagesEntry(void* cookie);
|
||||||
|
|
||||||
void _PopulatePackageChangelog(
|
void _PopulatePackageChangelog(
|
||||||
@@ -191,9 +199,9 @@ private:
|
|||||||
PackageFilterRef fCategoryFilter;
|
PackageFilterRef fCategoryFilter;
|
||||||
BString fDepotFilter;
|
BString fDepotFilter;
|
||||||
PackageFilterRef fSearchTermsFilter;
|
PackageFilterRef fSearchTermsFilter;
|
||||||
PackageFilterRef fIsFeaturedFilter;
|
|
||||||
|
|
||||||
bool fShowFeaturedPackages;
|
package_list_view_mode
|
||||||
|
fPackageListViewMode;
|
||||||
bool fShowAvailablePackages;
|
bool fShowAvailablePackages;
|
||||||
bool fShowInstalledPackages;
|
bool fShowInstalledPackages;
|
||||||
bool fShowSourcePackages;
|
bool fShowSourcePackages;
|
||||||
|
|||||||
@@ -1178,6 +1178,19 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
DepotInfo::HasAnyProminentPackages() const
|
||||||
|
{
|
||||||
|
int32 count = fPackages.CountItems();
|
||||||
|
for (int32 i = 0; i < count; i++) {
|
||||||
|
const PackageInfoRef& package = fPackages.ItemAtFast(i);
|
||||||
|
if (package->IsProminent())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
DepotInfo::SetURL(const BString& URL)
|
DepotInfo::SetURL(const BString& URL)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -436,6 +436,8 @@ public:
|
|||||||
|
|
||||||
void SyncPackages(const PackageList& packages);
|
void SyncPackages(const PackageList& packages);
|
||||||
|
|
||||||
|
bool HasAnyProminentPackages() const;
|
||||||
|
|
||||||
void SetURL(const BString& URL);
|
void SetURL(const BString& URL);
|
||||||
const BString& URL() const
|
const BString& URL() const
|
||||||
{ return fURL; }
|
{ return fURL; }
|
||||||
|
|||||||
@@ -380,31 +380,89 @@ FeaturedPackagesView::~FeaturedPackagesView()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*! This method will add the package into the list to be displayed. The
|
||||||
|
insertion will occur in alphabetical order.
|
||||||
|
*/
|
||||||
|
|
||||||
void
|
void
|
||||||
FeaturedPackagesView::AddPackage(const PackageInfoRef& package)
|
FeaturedPackagesView::AddPackage(const PackageInfoRef& package)
|
||||||
{
|
{
|
||||||
// Find insertion index (alphabetical)
|
int32 index = _InsertionIndex(package->Name());
|
||||||
int32 index = 0;
|
if (index != -1) {
|
||||||
for (int32 i = 0; BLayoutItem* item = fPackageListLayout->ItemAt(i); i++) {
|
PackageView* view = new PackageView();
|
||||||
PackageView* view = dynamic_cast<PackageView*>(item->View());
|
view->SetPackage(package);
|
||||||
if (view == NULL)
|
fPackageListLayout->AddView(index, view);
|
||||||
break;
|
|
||||||
|
|
||||||
BString name = view->PackageName();
|
|
||||||
if (name == package->Name()) {
|
|
||||||
// Don't add packages more than once
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BString title = view->PackageTitle();
|
|
||||||
if (title.Compare(package->Title()) < 0)
|
|
||||||
index++;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
PackageView* view = new PackageView();
|
|
||||||
view->SetPackage(package);
|
|
||||||
|
|
||||||
fPackageListLayout->AddView(index, view);
|
const char*
|
||||||
|
FeaturedPackagesView::_PackageNameAtIndex(int32 index) const
|
||||||
|
{
|
||||||
|
BLayoutItem* item = fPackageListLayout->ItemAt(index);
|
||||||
|
PackageView* view = dynamic_cast<PackageView*>(item->View());
|
||||||
|
return (view != NULL ? view->PackageName() : NULL);
|
||||||
|
// some of the items in the GroupLayout instance are not of type
|
||||||
|
// PackageView* and it is not immediately clear where they are
|
||||||
|
// coming from.
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int32
|
||||||
|
FeaturedPackagesView::_InsertionIndex(const BString& packageName) const
|
||||||
|
{
|
||||||
|
int32 count = fPackageListLayout->CountItems();
|
||||||
|
return _InsertionIndexBinary(packageName, 0, count - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32
|
||||||
|
FeaturedPackagesView::_InsertionIndexLinear(const BString& packageName,
|
||||||
|
int32 startIndex, int32 endIndex) const
|
||||||
|
{
|
||||||
|
for (int32 i = startIndex; i <= endIndex; i++) {
|
||||||
|
const char* iPackageName = _PackageNameAtIndex(i);
|
||||||
|
if (NULL != iPackageName) {
|
||||||
|
int compare = packageName.Compare(iPackageName);
|
||||||
|
if (compare == 0)
|
||||||
|
return -1;
|
||||||
|
if (compare < 0)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*! This performs a binary search to find the location at which to insert
|
||||||
|
the item.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int32
|
||||||
|
FeaturedPackagesView::_InsertionIndexBinary(const BString& packageName,
|
||||||
|
int32 startIndex, int32 endIndex) const
|
||||||
|
{
|
||||||
|
if (startIndex == endIndex)
|
||||||
|
return startIndex;
|
||||||
|
|
||||||
|
int32 endStartSpan = endIndex - startIndex;
|
||||||
|
|
||||||
|
if (endStartSpan < 5)
|
||||||
|
return _InsertionIndexLinear(packageName, startIndex, endIndex);
|
||||||
|
|
||||||
|
int midIndex = startIndex + (endStartSpan / 2);
|
||||||
|
const char *midPackageName = _PackageNameAtIndex(midIndex);
|
||||||
|
|
||||||
|
if (midPackageName == NULL)
|
||||||
|
return _InsertionIndexLinear(packageName, startIndex, endIndex);
|
||||||
|
|
||||||
|
int compare = packageName.Compare(midPackageName);
|
||||||
|
|
||||||
|
if (compare == 0)
|
||||||
|
return -1;
|
||||||
|
// don't want to insert the same package twice.
|
||||||
|
if (compare < 0)
|
||||||
|
return _InsertionIndexBinary(packageName, startIndex, midIndex);
|
||||||
|
return _InsertionIndexBinary(packageName, midIndex, endIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,15 @@ public:
|
|||||||
|
|
||||||
static void CleanupIcons();
|
static void CleanupIcons();
|
||||||
|
|
||||||
|
private:
|
||||||
|
const char* _PackageNameAtIndex(int32 index) const;
|
||||||
|
int32 _InsertionIndex(
|
||||||
|
const BString& packageName) const;
|
||||||
|
int32 _InsertionIndexBinary(const BString& packageName,
|
||||||
|
int32 startIndex, int32 endIndex) const;
|
||||||
|
int32 _InsertionIndexLinear(const BString& packageName,
|
||||||
|
int32 startIndex, int32 endIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BGroupLayout* fPackageListLayout;
|
BGroupLayout* fPackageListLayout;
|
||||||
ScrollableGroupView* fContainerView;
|
ScrollableGroupView* fContainerView;
|
||||||
|
|||||||
@@ -68,14 +68,18 @@ enum {
|
|||||||
MSG_WORK_STATUS_CHANGE = 'wsch',
|
MSG_WORK_STATUS_CHANGE = 'wsch',
|
||||||
MSG_WORK_STATUS_CLEAR = 'wscl',
|
MSG_WORK_STATUS_CLEAR = 'wscl',
|
||||||
|
|
||||||
MSG_SHOW_FEATURED_PACKAGES = 'sofp',
|
MSG_CHANGE_PACKAGE_LIST_VIEW_MODE = 'cplm',
|
||||||
MSG_SHOW_AVAILABLE_PACKAGES = 'savl',
|
MSG_SHOW_AVAILABLE_PACKAGES = 'savl',
|
||||||
MSG_SHOW_INSTALLED_PACKAGES = 'sins',
|
MSG_SHOW_INSTALLED_PACKAGES = 'sins',
|
||||||
MSG_SHOW_SOURCE_PACKAGES = 'ssrc',
|
MSG_SHOW_SOURCE_PACKAGES = 'ssrc',
|
||||||
MSG_SHOW_DEVELOP_PACKAGES = 'sdvl'
|
MSG_SHOW_DEVELOP_PACKAGES = 'sdvl'
|
||||||
};
|
};
|
||||||
|
|
||||||
#define KEY_ERROR_STATUS "errorStatus"
|
#define KEY_ERROR_STATUS "errorStatus"
|
||||||
|
#define KEY_PACKAGE_LIST_VIEW_MODE "packageListViewMode"
|
||||||
|
|
||||||
|
#define TAB_PROMINENT_PACKAGES 0
|
||||||
|
#define TAB_ALL_PACKAGES 1
|
||||||
|
|
||||||
using namespace BPackageKit;
|
using namespace BPackageKit;
|
||||||
using namespace BPackageKit::BManager::BPrivate;
|
using namespace BPackageKit::BManager::BPrivate;
|
||||||
@@ -159,7 +163,7 @@ MainWindow::MainWindow(const BMessage& settings)
|
|||||||
fPackageListView->AttachWorkStatusView(fWorkStatusView);
|
fPackageListView->AttachWorkStatusView(fWorkStatusView);
|
||||||
|
|
||||||
fListTabs = new TabView(BMessenger(this),
|
fListTabs = new TabView(BMessenger(this),
|
||||||
BMessage(MSG_SHOW_FEATURED_PACKAGES), "list tabs");
|
BMessage(MSG_CHANGE_PACKAGE_LIST_VIEW_MODE), "list tabs");
|
||||||
fListTabs->AddTab(fFeaturedPackagesView);
|
fListTabs->AddTab(fFeaturedPackagesView);
|
||||||
fListTabs->AddTab(fPackageListView);
|
fListTabs->AddTab(fPackageListView);
|
||||||
|
|
||||||
@@ -186,27 +190,16 @@ MainWindow::MainWindow(const BMessage& settings)
|
|||||||
|
|
||||||
fModel.AddListener(fModelListener);
|
fModel.AddListener(fModelListener);
|
||||||
|
|
||||||
// Restore settings
|
|
||||||
BMessage columnSettings;
|
BMessage columnSettings;
|
||||||
if (settings.FindMessage("column settings", &columnSettings) == B_OK)
|
if (settings.FindMessage("column settings", &columnSettings) == B_OK)
|
||||||
fPackageListView->LoadState(&columnSettings);
|
fPackageListView->LoadState(&columnSettings);
|
||||||
|
|
||||||
bool showOption;
|
_RestoreModelSettings(settings);
|
||||||
if (settings.FindBool("show featured packages", &showOption) == B_OK)
|
|
||||||
fModel.SetShowFeaturedPackages(showOption);
|
|
||||||
if (settings.FindBool("show available packages", &showOption) == B_OK)
|
|
||||||
fModel.SetShowAvailablePackages(showOption);
|
|
||||||
if (settings.FindBool("show installed packages", &showOption) == B_OK)
|
|
||||||
fModel.SetShowInstalledPackages(showOption);
|
|
||||||
if (settings.FindBool("show develop packages", &showOption) == B_OK)
|
|
||||||
fModel.SetShowDevelopPackages(showOption);
|
|
||||||
if (settings.FindBool("show source packages", &showOption) == B_OK)
|
|
||||||
fModel.SetShowSourcePackages(showOption);
|
|
||||||
|
|
||||||
if (fModel.ShowFeaturedPackages())
|
if (fModel.PackageListViewMode() == PROMINENT)
|
||||||
fListTabs->Select(0);
|
fListTabs->Select(TAB_PROMINENT_PACKAGES);
|
||||||
else
|
else
|
||||||
fListTabs->Select(1);
|
fListTabs->Select(TAB_ALL_PACKAGES);
|
||||||
|
|
||||||
_RestoreNickname(settings);
|
_RestoreNickname(settings);
|
||||||
_UpdateAuthorization();
|
_UpdateAuthorization();
|
||||||
@@ -255,6 +248,7 @@ MainWindow::MainWindow(const BMessage& settings, const PackageInfoRef& package)
|
|||||||
|
|
||||||
// Restore settings
|
// Restore settings
|
||||||
_RestoreNickname(settings);
|
_RestoreNickname(settings);
|
||||||
|
_UpdateAuthorization();
|
||||||
_RestoreWindowFrame(settings);
|
_RestoreWindowFrame(settings);
|
||||||
|
|
||||||
fPackageInfoView->SetPackage(package);
|
fPackageInfoView->SetPackage(package);
|
||||||
@@ -375,17 +369,8 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
fFilterView->AdoptModel(fModel);
|
fFilterView->AdoptModel(fModel);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_SHOW_FEATURED_PACKAGES:
|
case MSG_CHANGE_PACKAGE_LIST_VIEW_MODE:
|
||||||
// check to see if we aren't already on the current tab
|
_HandleChangePackageListViewMode();
|
||||||
if (fListTabs->Selection() ==
|
|
||||||
(fModel.ShowFeaturedPackages() ? 0 : 1))
|
|
||||||
break;
|
|
||||||
{
|
|
||||||
BAutolock locker(fModel.Lock());
|
|
||||||
fModel.SetShowFeaturedPackages(
|
|
||||||
fListTabs->Selection() == 0);
|
|
||||||
}
|
|
||||||
_AdoptModel();
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_SHOW_AVAILABLE_PACKAGES:
|
case MSG_SHOW_AVAILABLE_PACKAGES:
|
||||||
@@ -661,6 +646,24 @@ MainWindow::MessageReceived(BMessage* message)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static const char*
|
||||||
|
main_window_package_list_view_mode_str(package_list_view_mode mode)
|
||||||
|
{
|
||||||
|
if (mode == PROMINENT)
|
||||||
|
return "PROMINENT";
|
||||||
|
return "ALL";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static package_list_view_mode
|
||||||
|
main_window_str_to_package_list_view_mode(const BString& str)
|
||||||
|
{
|
||||||
|
if (str == "PROMINENT")
|
||||||
|
return PROMINENT;
|
||||||
|
return ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::StoreSettings(BMessage& settings) const
|
MainWindow::StoreSettings(BMessage& settings) const
|
||||||
{
|
{
|
||||||
@@ -673,8 +676,9 @@ MainWindow::StoreSettings(BMessage& settings) const
|
|||||||
|
|
||||||
settings.AddMessage("column settings", &columnSettings);
|
settings.AddMessage("column settings", &columnSettings);
|
||||||
|
|
||||||
settings.AddBool("show featured packages",
|
settings.AddString(KEY_PACKAGE_LIST_VIEW_MODE,
|
||||||
fModel.ShowFeaturedPackages());
|
main_window_package_list_view_mode_str(
|
||||||
|
fModel.PackageListViewMode()));
|
||||||
settings.AddBool("show available packages",
|
settings.AddBool("show available packages",
|
||||||
fModel.ShowAvailablePackages());
|
fModel.ShowAvailablePackages());
|
||||||
settings.AddBool("show installed packages",
|
settings.AddBool("show installed packages",
|
||||||
@@ -851,6 +855,28 @@ MainWindow::_RestoreWindowFrame(const BMessage& settings)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::_RestoreModelSettings(const BMessage& settings)
|
||||||
|
{
|
||||||
|
BString packageListViewMode;
|
||||||
|
if (settings.FindString(KEY_PACKAGE_LIST_VIEW_MODE,
|
||||||
|
&packageListViewMode) == B_OK) {
|
||||||
|
fModel.SetPackageListViewMode(
|
||||||
|
main_window_str_to_package_list_view_mode(packageListViewMode));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool showOption;
|
||||||
|
if (settings.FindBool("show available packages", &showOption) == B_OK)
|
||||||
|
fModel.SetShowAvailablePackages(showOption);
|
||||||
|
if (settings.FindBool("show installed packages", &showOption) == B_OK)
|
||||||
|
fModel.SetShowInstalledPackages(showOption);
|
||||||
|
if (settings.FindBool("show develop packages", &showOption) == B_OK)
|
||||||
|
fModel.SetShowDevelopPackages(showOption);
|
||||||
|
if (settings.FindBool("show source packages", &showOption) == B_OK)
|
||||||
|
fModel.SetShowSourcePackages(showOption);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
MainWindow::_InitWorkerThreads()
|
MainWindow::_InitWorkerThreads()
|
||||||
{
|
{
|
||||||
@@ -887,6 +913,9 @@ MainWindow::_InitWorkerThreads()
|
|||||||
void
|
void
|
||||||
MainWindow::_AdoptModel()
|
MainWindow::_AdoptModel()
|
||||||
{
|
{
|
||||||
|
if (Logger::IsTraceEnabled())
|
||||||
|
printf("adopting model to main window ui");
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoLocker<BLocker> modelLocker(fModel.Lock());
|
AutoLocker<BLocker> modelLocker(fModel.Lock());
|
||||||
fVisiblePackages = fModel.CreatePackageList();
|
fVisiblePackages = fModel.CreatePackageList();
|
||||||
@@ -906,10 +935,10 @@ MainWindow::_AdoptModel()
|
|||||||
fShowSourcePackagesItem->SetMarked(fModel.ShowSourcePackages());
|
fShowSourcePackagesItem->SetMarked(fModel.ShowSourcePackages());
|
||||||
fShowDevelopPackagesItem->SetMarked(fModel.ShowDevelopPackages());
|
fShowDevelopPackagesItem->SetMarked(fModel.ShowDevelopPackages());
|
||||||
|
|
||||||
if (fModel.ShowFeaturedPackages())
|
if (fModel.PackageListViewMode() == PROMINENT)
|
||||||
fListTabs->Select(0);
|
fListTabs->Select(TAB_PROMINENT_PACKAGES);
|
||||||
else
|
else
|
||||||
fListTabs->Select(1);
|
fListTabs->Select(TAB_ALL_PACKAGES);
|
||||||
|
|
||||||
fFilterView->AdoptModel(fModel);
|
fFilterView->AdoptModel(fModel);
|
||||||
}
|
}
|
||||||
@@ -971,6 +1000,19 @@ MainWindow::_BulkLoadCompleteReceived(status_t errorStatus)
|
|||||||
fRefreshRepositoriesItem->SetEnabled(true);
|
fRefreshRepositoriesItem->SetEnabled(true);
|
||||||
_AdoptModel();
|
_AdoptModel();
|
||||||
_UpdateAvailableRepositories();
|
_UpdateAvailableRepositories();
|
||||||
|
|
||||||
|
// if after loading everything in, it transpires that there are no
|
||||||
|
// featured packages then the featured packages should be disabled
|
||||||
|
// and the user should be switched to the "all packages" view so
|
||||||
|
// that they are not presented with a blank window!
|
||||||
|
|
||||||
|
bool hasProminentPackages = fModel.HasAnyProminentPackages();
|
||||||
|
fListTabs->TabAt(TAB_PROMINENT_PACKAGES)->SetEnabled(hasProminentPackages);
|
||||||
|
if (!hasProminentPackages
|
||||||
|
&& fListTabs->Selection() == TAB_PROMINENT_PACKAGES) {
|
||||||
|
fModel.SetPackageListViewMode(ALL);
|
||||||
|
fListTabs->Select(TAB_ALL_PACKAGES);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1562,4 +1604,27 @@ MainWindow::CoordinatorChanged(ProcessCoordinatorState& coordinatorState)
|
|||||||
if (Logger::IsInfoEnabled())
|
if (Logger::IsInfoEnabled())
|
||||||
printf("! unknown process coordinator changed\n");
|
printf("! unknown process coordinator changed\n");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static package_list_view_mode
|
||||||
|
main_window_tab_to_package_list_view_mode(int32 tab)
|
||||||
|
{
|
||||||
|
if (tab == TAB_PROMINENT_PACKAGES)
|
||||||
|
return PROMINENT;
|
||||||
|
return ALL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
MainWindow::_HandleChangePackageListViewMode()
|
||||||
|
{
|
||||||
|
package_list_view_mode tabMode = main_window_tab_to_package_list_view_mode(
|
||||||
|
fListTabs->Selection());
|
||||||
|
package_list_view_mode modelMode = fModel.PackageListViewMode();
|
||||||
|
|
||||||
|
if (tabMode != modelMode) {
|
||||||
|
BAutolock locker(fModel.Lock());
|
||||||
|
fModel.SetPackageListViewMode(tabMode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -81,9 +81,10 @@ private:
|
|||||||
void _BuildMenu(BMenuBar* menuBar);
|
void _BuildMenu(BMenuBar* menuBar);
|
||||||
void _BuildUserMenu(BMenuBar* menuBar);
|
void _BuildUserMenu(BMenuBar* menuBar);
|
||||||
|
|
||||||
void _RestoreNickname(const BMessage& settings);
|
|
||||||
const char* _WindowFrameName() const;
|
const char* _WindowFrameName() const;
|
||||||
|
void _RestoreNickname(const BMessage& settings);
|
||||||
void _RestoreWindowFrame(const BMessage& settings);
|
void _RestoreWindowFrame(const BMessage& settings);
|
||||||
|
void _RestoreModelSettings(const BMessage& settings);
|
||||||
|
|
||||||
void _InitWorkerThreads();
|
void _InitWorkerThreads();
|
||||||
void _AdoptModel();
|
void _AdoptModel();
|
||||||
@@ -103,6 +104,8 @@ private:
|
|||||||
void _HandleWorkStatusChangeMessageReceived(
|
void _HandleWorkStatusChangeMessageReceived(
|
||||||
const BMessage* message);
|
const BMessage* message);
|
||||||
|
|
||||||
|
void _HandleChangePackageListViewMode();
|
||||||
|
|
||||||
static status_t _RefreshModelThreadWorker(void* arg);
|
static status_t _RefreshModelThreadWorker(void* arg);
|
||||||
static status_t _PackageActionWorker(void* arg);
|
static status_t _PackageActionWorker(void* arg);
|
||||||
static status_t _PopulatePackageWorker(void* arg);
|
static status_t _PopulatePackageWorker(void* arg);
|
||||||
|
|||||||
Reference in New Issue
Block a user