From d75b4d610d3e19d90240ae6d6dce02c77db8519f Mon Sep 17 00:00:00 2001 From: Andrew Lindesay Date: Sun, 31 Jan 2021 22:05:33 +1300 Subject: [PATCH] HaikuDepot: Remove Custom List Further removal of the use of custom list class; this time with the package lists. Relates To #15534 Change-Id: I1f01ed9d5ddbd7754097ce0adbf505d6ba17fd2f Reviewed-on: https://review.haiku-os.org/c/haiku/+/3732 Reviewed-by: Adrien Destugues --- headers/private/shared/LRUCache.h | 13 +- src/apps/haikudepot/model/Model.cpp | 146 +++++------------ src/apps/haikudepot/model/Model.h | 11 +- src/apps/haikudepot/model/PackageAction.cpp | 14 +- .../haikudepot/model/PackageIconRepository.h | 3 +- .../model/PackageIconTarRepository.cpp | 11 +- .../model/PackageIconTarRepository.h | 3 +- src/apps/haikudepot/model/PackageInfo.cpp | 147 +++++++++++------- src/apps/haikudepot/model/PackageInfo.h | 21 ++- src/apps/haikudepot/model/PackageManager.cpp | 14 +- .../server/ServerIconExportUpdateProcess.cpp | 11 +- .../server/ServerPkgDataUpdateProcess.cpp | 21 +-- .../haikudepot/ui/FeaturedPackagesView.cpp | 16 +- src/apps/haikudepot/ui/MainWindow.cpp | 11 +- 14 files changed, 201 insertions(+), 241 deletions(-) diff --git a/headers/private/shared/LRUCache.h b/headers/private/shared/LRUCache.h index 3df0d9f897..0450e840e2 100644 --- a/headers/private/shared/LRUCache.h +++ b/headers/private/shared/LRUCache.h @@ -1,5 +1,5 @@ /* - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef LRU_CACHE_H @@ -115,12 +115,11 @@ public: void Clear() { fMap.Clear(); - LRUNode* node = fNewestNode; - while (node != NULL) { - LRUNode *next = node->fOlder; - delete node; - node = next; - } + // this will delete the objects in map which are the nodes in the + // linked list; for this reason don't delete them here as well + // because this will lead to a double-free of the object. + fNewestNode = NULL; + fOldestNode = NULL; } Value Get(const Key& key) diff --git a/src/apps/haikudepot/model/Model.cpp b/src/apps/haikudepot/model/Model.cpp index d51081d567..fa2fd66f54 100644 --- a/src/apps/haikudepot/model/Model.cpp +++ b/src/apps/haikudepot/model/Model.cpp @@ -65,35 +65,6 @@ public: }; -class DepotFilter : public PackageFilter { -public: - DepotFilter(const DepotInfo& depot) - : - fDepot(depot) - { - } - - virtual bool AcceptsPackage(const PackageInfoRef& package) const - { - // TODO: Maybe a PackageInfo ought to know the Depot it came from? - // But right now the same package could theoretically be provided - // from different depots and the filter would work correctly. - // Also the PackageList could actually contain references to packages - // instead of the packages as objects. The equal operator is quite - // expensive as is. - return fDepot.Packages().Contains(package); - } - - const BString& Depot() const - { - return fDepot.Name(); - } - -private: - DepotInfo fDepot; -}; - - class CategoryFilter : public PackageFilter { public: CategoryFilter(const BString& category) @@ -127,46 +98,6 @@ private: }; -class ContainedInFilter : public PackageFilter { -public: - ContainedInFilter(const PackageList& packageList) - : - fPackageList(packageList) - { - } - - virtual bool AcceptsPackage(const PackageInfoRef& package) const - { - return fPackageList.Contains(package); - } - -private: - const PackageList& fPackageList; -}; - - -class ContainedInEitherFilter : public PackageFilter { -public: - ContainedInEitherFilter(const PackageList& packageListA, - const PackageList& packageListB) - : - fPackageListA(packageListA), - fPackageListB(packageListB) - { - } - - virtual bool AcceptsPackage(const PackageInfoRef& package) const - { - return fPackageListA.Contains(package) - || fPackageListB.Contains(package); - } - -private: - const PackageList& fPackageListA; - const PackageList& fPackageListB; -}; - - class StateFilter : public PackageFilter { public: StateFilter(PackageState state) @@ -331,9 +262,9 @@ Model::PackageForName(const BString& name) std::vector::iterator it; for (it = fDepots.begin(); it != fDepots.end(); it++) { DepotInfoRef depotInfoRef = *it; - int32 packageIndex = depotInfoRef->PackageIndexByName(name); - if (packageIndex >= 0) - return depotInfoRef->Packages().ItemAtFast(packageIndex); + PackageInfoRef packageInfoRef = depotInfoRef->PackageByName(name); + if (packageInfoRef.Get() != NULL) + return packageInfoRef; } return PackageInfoRef(); } @@ -353,13 +284,13 @@ Model::MatchesFilter(const PackageInfoRef& package) const void -Model::MergeOrAddDepot(const DepotInfoRef depot) +Model::MergeOrAddDepot(const DepotInfoRef& depot) { BString depotName = depot->Name(); for(uint32 i = 0; i < fDepots.size(); i++) { if (fDepots[i]->Name() == depotName) { DepotInfoRef ersatzDepot(new DepotInfo(*(fDepots[i].Get())), true); - ersatzDepot->SyncPackages(depot->Packages()); + ersatzDepot->SyncPackagesFromDepot(depot); fDepots[i] = ersatzDepot; return; } @@ -418,41 +349,15 @@ Model::HasAnyProminentPackages() void Model::Clear() { + GetPackageIconRepository().Clear(); fDepots.clear(); + fPopulatedPackageNames.MakeEmpty(); } void Model::SetPackageState(const PackageInfoRef& package, PackageState state) { - switch (state) { - default: - case NONE: - fInstalledPackages.Remove(package); - fActivatedPackages.Remove(package); - fUninstalledPackages.Remove(package); - break; - case INSTALLED: - if (!fInstalledPackages.Contains(package)) - fInstalledPackages.Add(package); - fActivatedPackages.Remove(package); - fUninstalledPackages.Remove(package); - break; - case ACTIVATED: - if (!fInstalledPackages.Contains(package)) - fInstalledPackages.Add(package); - if (!fActivatedPackages.Contains(package)) - fActivatedPackages.Add(package); - fUninstalledPackages.Remove(package); - break; - case UNINSTALLED: - fInstalledPackages.Remove(package); - fActivatedPackages.Remove(package); - if (!fUninstalledPackages.Contains(package)) - fUninstalledPackages.Add(package); - break; - } - package->SetState(state); } @@ -561,6 +466,28 @@ Model::SetShowDevelopPackages(bool show) // #pragma mark - information retrieval +/*! It may transpire that the package has no corresponding record on the + server side because the repository is not represented in the server. + In such a case, there is little point in communicating with the server + only to hear back that the package does not exist. +*/ + +bool +Model::CanPopulatePackage(const PackageInfoRef& package) +{ + const BString& depotName = package->DepotName(); + + if (depotName.IsEmpty()) + return false; + + const DepotInfoRef& depot = DepotForName(depotName); + + if (depot.Get() == NULL) + return false; + + return !depot->WebAppRepositoryCode().IsEmpty(); +} + /*! Initially only superficial data is loaded from the server into the data model of the packages. When the package is viewed, additional data needs @@ -570,6 +497,11 @@ Model::SetShowDevelopPackages(bool show) void Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) { + if (!CanPopulatePackage(package)) { + HDINFO("unable to populate package [%s]", package->Name().String()); + return; + } + // TODO: There should probably also be a way to "unpopulate" the // package information. Maybe a cache of populated packages, so that // packages loose their extra information after a certain amount of @@ -578,11 +510,12 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) // Especially screen-shots will be a problem eventually. { BAutolock locker(&fLock); - bool alreadyPopulated = fPopulatedPackages.Contains(package); + bool alreadyPopulated = fPopulatedPackageNames.HasString( + package->Name()); if ((flags & POPULATE_FORCE) == 0 && alreadyPopulated) return; if (!alreadyPopulated) - fPopulatedPackages.Add(package); + fPopulatedPackageNames.Add(package->Name()); } if ((flags & POPULATE_CHANGELOG) != 0 && package->HasChangelog()) { @@ -703,7 +636,10 @@ Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) HDDEBUG("did retrieve %" B_PRIi32 " user ratings for [%s]", index - 1, packageName.String()); } else { - _MaybeLogJsonRpcError(info, "retrieve user ratings"); + BString message; + message.SetToFormat("failure to retrieve user ratings for [%s]", + packageName.String()); + _MaybeLogJsonRpcError(info, message.String()); } } else HDERROR("unable to retrieve user ratings"); diff --git a/src/apps/haikudepot/model/Model.h b/src/apps/haikudepot/model/Model.h index 47bdae8c2e..268efaf012 100644 --- a/src/apps/haikudepot/model/Model.h +++ b/src/apps/haikudepot/model/Model.h @@ -79,7 +79,7 @@ public: bool MatchesFilter( const PackageInfoRef& package) const; - void MergeOrAddDepot(const DepotInfoRef depot); + void MergeOrAddDepot(const DepotInfoRef& depot); bool HasDepot(const BString& name) const; int32 CountDepots() const; DepotInfoRef DepotAtIndex(int32 index) const; @@ -139,6 +139,8 @@ public: static const uint32 POPULATE_CATEGORIES = 1 << 5; static const uint32 POPULATE_FORCE = 1 << 6; + bool CanPopulatePackage( + const PackageInfoRef& package); void PopulatePackage(const PackageInfoRef& package, uint32 flags); @@ -191,12 +193,7 @@ private: std::vector fRatingStabilities; - PackageList fInstalledPackages; - PackageList fActivatedPackages; - PackageList fUninstalledPackages; - PackageList fDownloadingPackages; - PackageList fUpdateablePackages; - PackageList fPopulatedPackages; + BStringList fPopulatedPackageNames; PackageFilterRef fCategoryFilter; BString fDepotFilter; diff --git a/src/apps/haikudepot/model/PackageAction.cpp b/src/apps/haikudepot/model/PackageAction.cpp index 345791ca1c..8f8b93896c 100644 --- a/src/apps/haikudepot/model/PackageAction.cpp +++ b/src/apps/haikudepot/model/PackageAction.cpp @@ -42,19 +42,7 @@ PackageAction::~PackageAction() PackageInfoRef PackageAction::FindPackageByName(const BString& name) { - Model* model = GetModel(); - // TODO: optimize! - for (int32 i = 0; i < model->CountDepots(); i++) { - const DepotInfoRef depotInfoRef = model->DepotAtIndex(i); - const PackageList& packages = depotInfoRef->Packages(); - for (int32 j = 0; j < packages.CountItems(); j++) { - PackageInfoRef info = packages.ItemAtFast(j); - if (info->Name() == name) - return info; - } - } - - return PackageInfoRef(); + return GetModel()->PackageForName(name); } diff --git a/src/apps/haikudepot/model/PackageIconRepository.h b/src/apps/haikudepot/model/PackageIconRepository.h index 3c0850012d..0875ce2eaa 100644 --- a/src/apps/haikudepot/model/PackageIconRepository.h +++ b/src/apps/haikudepot/model/PackageIconRepository.h @@ -1,5 +1,5 @@ /* - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_ICON_REPOSITORY_H @@ -16,6 +16,7 @@ public: virtual bool HasAnyIcon(const BString& pkgName) = 0; virtual status_t GetIcon(const BString& pkgName, BitmapSize size, BitmapRef& bitmap) = 0; + virtual void Clear() = 0; }; diff --git a/src/apps/haikudepot/model/PackageIconTarRepository.cpp b/src/apps/haikudepot/model/PackageIconTarRepository.cpp index e75d6088ea..c0a50da689 100644 --- a/src/apps/haikudepot/model/PackageIconTarRepository.cpp +++ b/src/apps/haikudepot/model/PackageIconTarRepository.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -139,6 +139,13 @@ PackageIconTarRepository::~PackageIconTarRepository() } +void +PackageIconTarRepository::Clear() { + BAutolock locker(&fLock); + fIconCache.Clear(); +} + + /*! This method will reconfigure itself using the data in the tar file supplied. Any existing data will be flushed and the new tar will be scanned for offsets to usable files. @@ -195,10 +202,10 @@ PackageIconTarRepository::Init(BPath& tarPath) void PackageIconTarRepository::_Close() { + fIconCache.Clear(); delete fTarIo; fTarIo = NULL; fIconTarPtrs.Clear(); - fIconCache.Clear(); } diff --git a/src/apps/haikudepot/model/PackageIconTarRepository.h b/src/apps/haikudepot/model/PackageIconTarRepository.h index ea0db5e982..f47e6df42f 100644 --- a/src/apps/haikudepot/model/PackageIconTarRepository.h +++ b/src/apps/haikudepot/model/PackageIconTarRepository.h @@ -1,5 +1,5 @@ /* - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #ifndef PACKAGE_ICON_TAR_REPOSITORY_H @@ -32,6 +32,7 @@ public: virtual status_t GetIcon(const BString& pkgName, BitmapSize size, BitmapRef& bitmap); virtual bool HasAnyIcon(const BString& pkgName); + virtual void Clear(); static void CleanupDefaultIcon(); diff --git a/src/apps/haikudepot/model/PackageInfo.cpp b/src/apps/haikudepot/model/PackageInfo.cpp index c9dbd445a7..8af55349b7 100644 --- a/src/apps/haikudepot/model/PackageInfo.cpp +++ b/src/apps/haikudepot/model/PackageInfo.cpp @@ -441,7 +441,7 @@ PackageInfo::PackageInfo() fChangelog(), fUserRatings(), fCachedRatingSummary(), - fProminence(0.0f), + fProminence(0), fScreenshotInfos(), fScreenshots(), fState(NONE), @@ -471,7 +471,7 @@ PackageInfo::PackageInfo(const BPackageInfo& info) fChangelog(), fUserRatings(), fCachedRatingSummary(), - fProminence(0.0f), + fProminence(0), fScreenshotInfos(), fScreenshots(), fState(NONE), @@ -485,7 +485,6 @@ PackageInfo::PackageInfo(const BPackageInfo& info) fDepotName(""), fIsCollatingChanges(false), fCollatedChanges(0) - { BString publisherURL; if (info.URLList().CountStrings() > 0) @@ -518,7 +517,7 @@ PackageInfo::PackageInfo(const BString& name, fCategories(), fUserRatings(), fCachedRatingSummary(), - fProminence(0.0f), + fProminence(0), fScreenshotInfos(), fScreenshots(), fState(NONE), @@ -1051,18 +1050,12 @@ PackageInfo::_NotifyListeners(uint32 changes) void PackageInfo::_NotifyListenersImmediate(uint32 changes) { - int count = fListeners.size(); - if (count == 0) + if (fListeners.empty()) return; // Clone list to avoid listeners detaching themselves in notifications // to screw up the list while iterating it. std::vector listeners(fListeners); - - // Check if it worked: - if (listeners.size() != count) - return; - PackageInfoEvent event(PackageInfoRef(this), changes); std::vector::iterator it; @@ -1077,27 +1070,21 @@ PackageInfo::_NotifyListenersImmediate(uint32 changes) // #pragma mark - Sorting Functions -/*! This function is used with the List class in order to facilitate fast - ordered inserting of packages. - */ - -static int32 -PackageCompare(const PackageInfoRef& p1, const PackageInfoRef& p2) +static bool +_IsPackageBeforeByName(const PackageInfoRef& p1, const BString& packageName) { - return p1->Name().Compare(p2->Name()); + return p1->Name().Compare(packageName) < 0; } -/*! This function is used with the List class in order to facilitate fast - searching of packages. +/*! This function is used in order to provide an ordering on the packages + that are stored on a Depot. */ -static int32 -PackageFixedNameCompare(const void* context, - const PackageInfoRef& package) +static bool +_IsPackageBefore(const PackageInfoRef& p1, const PackageInfoRef& p2) { - const BString* packageName = static_cast(context); - return packageName->Compare(package->Name()); + return _IsPackageBeforeByName(p1, p2->Name()); } @@ -1107,7 +1094,6 @@ PackageFixedNameCompare(const void* context, DepotInfo::DepotInfo() : fName(), - fPackages(&PackageCompare, &PackageFixedNameCompare), fWebAppRepositoryCode() { } @@ -1116,7 +1102,6 @@ DepotInfo::DepotInfo() DepotInfo::DepotInfo(const BString& name) : fName(name), - fPackages(&PackageCompare, &PackageFixedNameCompare), fWebAppRepositoryCode(), fWebAppRepositorySourceCode() { @@ -1161,56 +1146,100 @@ DepotInfo::operator!=(const DepotInfo& other) const } +int32 +DepotInfo::CountPackages() const +{ + return fPackages.size(); +} + + +PackageInfoRef +DepotInfo::PackageAtIndex(int32 index) +{ + return fPackages[index]; +} + + /*! This method will insert the package into the list of packages in order so that the list of packages remains in order. */ -bool -DepotInfo::AddPackage(const PackageInfoRef& package) +void +DepotInfo::AddPackage(PackageInfoRef& package) { - return fPackages.Add(package); + std::vector::iterator itInsertionPt + = std::lower_bound( + fPackages.begin(), + fPackages.end(), + package, + &_IsPackageBefore); + fPackages.insert(itInsertionPt, package); } -int32 -DepotInfo::PackageIndexByName(const BString& packageName) const +bool +DepotInfo::HasPackage(const BString& packageName) { - return fPackages.Search(&packageName); + std::vector::const_iterator it + = std::lower_bound( + fPackages.begin(), + fPackages.end(), + packageName, + &_IsPackageBeforeByName); + if (it != fPackages.end()) { + PackageInfoRef candidate = *it; + return (candidate.Get() != NULL + && candidate.Get()->Name() == packageName); + } + return false; +} + + +PackageInfoRef +DepotInfo::PackageByName(const BString& packageName) +{ + std::vector::const_iterator it + = std::lower_bound( + fPackages.begin(), + fPackages.end(), + packageName, + &_IsPackageBeforeByName); + + if (it != fPackages.end()) { + PackageInfoRef candidate = *it; + if (candidate.Get() != NULL && candidate.Get()->Name() == packageName) + return candidate; + } + return PackageInfoRef(); } void -DepotInfo::SyncPackages(const PackageList& otherPackages) +DepotInfo::SyncPackagesFromDepot(const DepotInfoRef& other) { - PackageList packages(fPackages); + for (int32 i = other->CountPackages() - 1; i >= 0; i--) { + PackageInfoRef otherPackage = other->PackageAtIndex(i); + PackageInfoRef myPackage = PackageByName(otherPackage->Name()); - for (int32 i = otherPackages.CountItems() - 1; i >= 0; i--) { - const PackageInfoRef& otherPackage = otherPackages.ItemAtFast(i); - bool found = false; - for (int32 j = packages.CountItems() - 1; j >= 0; j--) { - const PackageInfoRef& package = packages.ItemAtFast(j); - if (package->Name() == otherPackage->Name()) { - package->SetState(otherPackage->State()); - package->SetLocalFilePath(otherPackage->LocalFilePath()); - package->SetSystemDependency( - otherPackage->IsSystemDependency()); - found = true; - packages.Remove(j); - break; - } + if (myPackage.Get() != NULL) { + myPackage->SetState(otherPackage->State()); + myPackage->SetLocalFilePath(otherPackage->LocalFilePath()); + myPackage->SetSystemDependency(otherPackage->IsSystemDependency()); } - if (!found) { + else { HDINFO("%s: new package: '%s'", fName.String(), otherPackage->Name().String()); - fPackages.Add(otherPackage); + AddPackage(otherPackage); } } - for (int32 i = packages.CountItems() - 1; i >= 0; i--) { - const PackageInfoRef& package = packages.ItemAtFast(i); - HDINFO("%s: removing package: '%s'", fName.String(), - package->Name().String()); - fPackages.Remove(package); + for (int32 i = CountPackages() - 1; i >= 0; i--) { + PackageInfoRef myPackage = PackageAtIndex(i); + if (!other->HasPackage(myPackage->Name())) { + HDINFO("%s: removing package: '%s'", fName.String(), + myPackage->Name().String()); + fPackages.erase(fPackages.begin() + i); + } } } @@ -1218,9 +1247,9 @@ 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); + std::vector::const_iterator it; + for (it = fPackages.begin(); it != fPackages.end(); it++) { + const PackageInfoRef& package = *it; if (package->IsProminent()) return true; } diff --git a/src/apps/haikudepot/model/PackageInfo.h b/src/apps/haikudepot/model/PackageInfo.h index 77945c964d..6895479db1 100644 --- a/src/apps/haikudepot/model/PackageInfo.h +++ b/src/apps/haikudepot/model/PackageInfo.h @@ -396,9 +396,6 @@ private: typedef BReference PackageInfoRef; -typedef List PackageList; - - class DepotInfo : public BReferenceable { public: DepotInfo(); @@ -412,15 +409,14 @@ public: const BString& Name() const { return fName; } - const PackageList& Packages() const - { return fPackages; } + int32 CountPackages() const; + PackageInfoRef PackageAtIndex(int32 index); + void AddPackage(PackageInfoRef& package); + PackageInfoRef PackageByName(const BString& packageName); + bool HasPackage(const BString& packageName); - bool AddPackage(const PackageInfoRef& package); - - int32 PackageIndexByName(const BString& packageName) - const; - - void SyncPackages(const PackageList& packages); + void SyncPackagesFromDepot( + const BReference& other); bool HasAnyProminentPackages() const; @@ -439,7 +435,8 @@ public: private: BString fName; - PackageList fPackages; + std::vector + fPackages; BString fWebAppRepositoryCode; BString fWebAppRepositorySourceCode; BString fURL; diff --git a/src/apps/haikudepot/model/PackageManager.cpp b/src/apps/haikudepot/model/PackageManager.cpp index 0ba08f9921..69390d0d9a 100644 --- a/src/apps/haikudepot/model/PackageManager.cpp +++ b/src/apps/haikudepot/model/PackageManager.cpp @@ -312,19 +312,25 @@ public: PackageInfoRef ref(FindPackageByName(packages.ItemAt(i) ->Name())); if (ref.IsSet()) - fRemovedPackages.Add(ref); + fRemovedPackages.push_back(ref); } } void ApplyingChangesDone( BPackageManager::InstalledRepository& repository) { - for (int32 i = 0; i < fRemovedPackages.CountItems(); i++) - fRemovedPackages.ItemAt(i)->SetState(NONE); + std::vector::iterator it; + for ( + it = fRemovedPackages.begin(); + it != fRemovedPackages.end(); + it++) { + PackageInfoRef packageInfoRef = *it; + packageInfoRef->SetState(NONE); + } } private: - PackageList fRemovedPackages; + std::vector fRemovedPackages; }; diff --git a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp index ac8ef4a2e7..969eec8b76 100644 --- a/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp +++ b/src/apps/haikudepot/server/ServerIconExportUpdateProcess.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020, Andrew Lindesay . + * Copyright 2017-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ #include "ServerIconExportUpdateProcess.h" @@ -248,11 +248,10 @@ ServerIconExportUpdateProcess::_NotifyPackagesWithIconsInDepot( { PackageIconRepository& packageIconRepository = fModel->GetPackageIconRepository(); - const PackageList& packages = depot->Packages(); - for (int32 p = 0; p < packages.CountItems(); p++) { + for (int32 p = 0; p < depot->CountPackages(); p++) { AutoLocker locker(fModel->Lock()); - const PackageInfoRef& packageInfoRef = packages.ItemAtFast(p); + const PackageInfoRef& packageInfoRef = depot->PackageAtIndex(p); if (packageIconRepository.HasAnyIcon(packageInfoRef->Name())) - packages.ItemAtFast(p)->NotifyChangedIcon(); + packageInfoRef->NotifyChangedIcon(); } -} \ No newline at end of file +} diff --git a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp index 19dee090c5..4c3e471d28 100644 --- a/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp +++ b/src/apps/haikudepot/server/ServerPkgDataUpdateProcess.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2017-2020, Andrew Lindesay . + * Copyright 2017-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -172,20 +172,15 @@ PackageFillingPkgListener::Count() bool PackageFillingPkgListener::Handle(DumpExportPkg* pkg) { - const DepotInfo* depotInfo = fModel->DepotForName(fDepotName); + AutoLocker locker(fModel->Lock()); + DepotInfoRef depot = fModel->DepotForName(fDepotName); - if (depotInfo != NULL) { + if (depot.Get() != NULL) { const BString packageName = *(pkg->Name()); - int32 packageIndex = depotInfo->PackageIndexByName(packageName); - - if (-1 != packageIndex) { - const PackageList& packages = depotInfo->Packages(); - const PackageInfoRef& packageInfoRef = - packages.ItemAtFast(packageIndex); - - AutoLocker locker(fModel->Lock()); - ConsumePackage(packageInfoRef, pkg); - } else { + PackageInfoRef package = depot->PackageByName(packageName); + if (package.Get() != NULL) + ConsumePackage(package, pkg); + else { HDINFO("[PackageFillingPkgListener] unable to find the pkg [%s]", packageName.String()); } diff --git a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp index af04bde19b..5b8ad08492 100644 --- a/src/apps/haikudepot/ui/FeaturedPackagesView.cpp +++ b/src/apps/haikudepot/ui/FeaturedPackagesView.cpp @@ -1,7 +1,7 @@ /* * Copyright 2013-214, Stephan Aßmus . * Copyright 2017, Julian Harnath . - * Copyright 2020, Andrew Lindesay . + * Copyright 2020-2021, Andrew Lindesay . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -124,11 +124,14 @@ public: switch (key) { case B_RIGHT_ARROW: case B_DOWN_ARROW: + { + int32 lastIndex = static_cast(fPackages.size()) - 1; if (!IsEmpty() && fSelectedIndex != -1 - && fSelectedIndex < fPackages.size() - 1) { + && fSelectedIndex < lastIndex) { _MessageSelectIndex(fSelectedIndex + 1); } break; + } case B_LEFT_ARROW: case B_UP_ARROW: if (fSelectedIndex > 0) @@ -165,7 +168,8 @@ public: { if (index != -1) { BMessage message(MSG_PACKAGE_SELECTED); - message.AddString("name", fPackages[index]->Name()); + BString packageName = fPackages[index]->Name(); + message.AddString("name", packageName); Window()->PostMessage(&message); } } @@ -589,8 +593,8 @@ public: { if (fPackages.empty()) return -1; - int32 i = y / HEIGHT_PACKAGE; - if (i < 0 || i >= fPackages.size()) + int32 i = static_cast(y / HEIGHT_PACKAGE); + if (i < 0 || i >= static_cast(fPackages.size())) return -1; return i; } @@ -606,7 +610,7 @@ public: { if (fPackages.empty()) return -1; - int32 i = y / HEIGHT_PACKAGE; + int32 i = static_cast(y / HEIGHT_PACKAGE); if (i < 0) return 0; return std::min(i, (int32) (fPackages.size() - 1)); diff --git a/src/apps/haikudepot/ui/MainWindow.cpp b/src/apps/haikudepot/ui/MainWindow.cpp index 8017384c74..72de375fdd 100644 --- a/src/apps/haikudepot/ui/MainWindow.cpp +++ b/src/apps/haikudepot/ui/MainWindow.cpp @@ -3,7 +3,7 @@ * Copyright 2013-2014, Stephan Aßmus . * Copyright 2013, Rene Gollent, rene@gollent.com. * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. - * Copyright 2016-2020, Andrew Lindesay . + * Copyright 2016-2021, Andrew Lindesay . * Copyright 2017, Julian Harnath . * All rights reserved. Distributed under the terms of the MIT License. */ @@ -429,7 +429,7 @@ MainWindow::MessageReceived(BMessage* message) BAutolock locker(fModel.Lock()); package = fModel.PackageForName(name); } - if (!package.IsSet()) + if (package.IsSet() || name != package->Name()) debugger("unable to find the named package"); else _AdoptPackage(package); @@ -830,9 +830,10 @@ MainWindow::_AdoptModel() std::vector::iterator it; for (it = depots.begin(); it != depots.end(); it++) { DepotInfoRef depotInfoRef = *it; - const PackageList& packages = depotInfoRef->Packages(); - for (int32 p = 0; p < packages.CountItems(); p++) - _AddRemovePackageFromLists(packages.ItemAtFast(p)); + for (int i = 0; i < depotInfoRef->CountPackages(); i++) { + PackageInfoRef package = depotInfoRef->PackageAtIndex(i); + _AddRemovePackageFromLists(package); + } } _AdoptModelControls();