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 <pulkomandy@gmail.com>
This commit is contained in:
Andrew Lindesay 2021-01-31 22:05:33 +13:00
parent f01bc2121f
commit d75b4d610d
14 changed files with 201 additions and 241 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef LRU_CACHE_H #ifndef LRU_CACHE_H
@ -115,12 +115,11 @@ public:
void Clear() void Clear()
{ {
fMap.Clear(); fMap.Clear();
LRUNode* node = fNewestNode; // this will delete the objects in map which are the nodes in the
while (node != NULL) { // linked list; for this reason don't delete them here as well
LRUNode *next = node->fOlder; // because this will lead to a double-free of the object.
delete node; fNewestNode = NULL;
node = next; fOldestNode = NULL;
}
} }
Value Get(const Key& key) Value Get(const Key& key)

View File

@ -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 { class CategoryFilter : public PackageFilter {
public: public:
CategoryFilter(const BString& category) 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 { class StateFilter : public PackageFilter {
public: public:
StateFilter(PackageState state) StateFilter(PackageState state)
@ -331,9 +262,9 @@ Model::PackageForName(const BString& name)
std::vector<DepotInfoRef>::iterator it; std::vector<DepotInfoRef>::iterator it;
for (it = fDepots.begin(); it != fDepots.end(); it++) { for (it = fDepots.begin(); it != fDepots.end(); it++) {
DepotInfoRef depotInfoRef = *it; DepotInfoRef depotInfoRef = *it;
int32 packageIndex = depotInfoRef->PackageIndexByName(name); PackageInfoRef packageInfoRef = depotInfoRef->PackageByName(name);
if (packageIndex >= 0) if (packageInfoRef.Get() != NULL)
return depotInfoRef->Packages().ItemAtFast(packageIndex); return packageInfoRef;
} }
return PackageInfoRef(); return PackageInfoRef();
} }
@ -353,13 +284,13 @@ Model::MatchesFilter(const PackageInfoRef& package) const
void void
Model::MergeOrAddDepot(const DepotInfoRef depot) Model::MergeOrAddDepot(const DepotInfoRef& depot)
{ {
BString depotName = depot->Name(); BString depotName = depot->Name();
for(uint32 i = 0; i < fDepots.size(); i++) { for(uint32 i = 0; i < fDepots.size(); i++) {
if (fDepots[i]->Name() == depotName) { if (fDepots[i]->Name() == depotName) {
DepotInfoRef ersatzDepot(new DepotInfo(*(fDepots[i].Get())), true); DepotInfoRef ersatzDepot(new DepotInfo(*(fDepots[i].Get())), true);
ersatzDepot->SyncPackages(depot->Packages()); ersatzDepot->SyncPackagesFromDepot(depot);
fDepots[i] = ersatzDepot; fDepots[i] = ersatzDepot;
return; return;
} }
@ -418,41 +349,15 @@ Model::HasAnyProminentPackages()
void void
Model::Clear() Model::Clear()
{ {
GetPackageIconRepository().Clear();
fDepots.clear(); fDepots.clear();
fPopulatedPackageNames.MakeEmpty();
} }
void void
Model::SetPackageState(const PackageInfoRef& package, PackageState state) 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); package->SetState(state);
} }
@ -561,6 +466,28 @@ Model::SetShowDevelopPackages(bool show)
// #pragma mark - information retrieval // #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 /*! Initially only superficial data is loaded from the server into the data
model of the packages. When the package is viewed, additional data needs model of the packages. When the package is viewed, additional data needs
@ -570,6 +497,11 @@ Model::SetShowDevelopPackages(bool show)
void void
Model::PopulatePackage(const PackageInfoRef& package, uint32 flags) 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 // TODO: There should probably also be a way to "unpopulate" the
// package information. Maybe a cache of populated packages, so that // package information. Maybe a cache of populated packages, so that
// packages loose their extra information after a certain amount of // 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. // Especially screen-shots will be a problem eventually.
{ {
BAutolock locker(&fLock); BAutolock locker(&fLock);
bool alreadyPopulated = fPopulatedPackages.Contains(package); bool alreadyPopulated = fPopulatedPackageNames.HasString(
package->Name());
if ((flags & POPULATE_FORCE) == 0 && alreadyPopulated) if ((flags & POPULATE_FORCE) == 0 && alreadyPopulated)
return; return;
if (!alreadyPopulated) if (!alreadyPopulated)
fPopulatedPackages.Add(package); fPopulatedPackageNames.Add(package->Name());
} }
if ((flags & POPULATE_CHANGELOG) != 0 && package->HasChangelog()) { 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]", HDDEBUG("did retrieve %" B_PRIi32 " user ratings for [%s]",
index - 1, packageName.String()); index - 1, packageName.String());
} else { } else {
_MaybeLogJsonRpcError(info, "retrieve user ratings"); BString message;
message.SetToFormat("failure to retrieve user ratings for [%s]",
packageName.String());
_MaybeLogJsonRpcError(info, message.String());
} }
} else } else
HDERROR("unable to retrieve user ratings"); HDERROR("unable to retrieve user ratings");

View File

@ -79,7 +79,7 @@ public:
bool MatchesFilter( bool MatchesFilter(
const PackageInfoRef& package) const; const PackageInfoRef& package) const;
void MergeOrAddDepot(const DepotInfoRef depot); void MergeOrAddDepot(const DepotInfoRef& depot);
bool HasDepot(const BString& name) const; bool HasDepot(const BString& name) const;
int32 CountDepots() const; int32 CountDepots() const;
DepotInfoRef DepotAtIndex(int32 index) const; DepotInfoRef DepotAtIndex(int32 index) const;
@ -139,6 +139,8 @@ public:
static const uint32 POPULATE_CATEGORIES = 1 << 5; static const uint32 POPULATE_CATEGORIES = 1 << 5;
static const uint32 POPULATE_FORCE = 1 << 6; static const uint32 POPULATE_FORCE = 1 << 6;
bool CanPopulatePackage(
const PackageInfoRef& package);
void PopulatePackage(const PackageInfoRef& package, void PopulatePackage(const PackageInfoRef& package,
uint32 flags); uint32 flags);
@ -191,12 +193,7 @@ private:
std::vector<RatingStabilityRef> std::vector<RatingStabilityRef>
fRatingStabilities; fRatingStabilities;
PackageList fInstalledPackages; BStringList fPopulatedPackageNames;
PackageList fActivatedPackages;
PackageList fUninstalledPackages;
PackageList fDownloadingPackages;
PackageList fUpdateablePackages;
PackageList fPopulatedPackages;
PackageFilterRef fCategoryFilter; PackageFilterRef fCategoryFilter;
BString fDepotFilter; BString fDepotFilter;

View File

@ -42,19 +42,7 @@ PackageAction::~PackageAction()
PackageInfoRef PackageInfoRef
PackageAction::FindPackageByName(const BString& name) PackageAction::FindPackageByName(const BString& name)
{ {
Model* model = GetModel(); return GetModel()->PackageForName(name);
// 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();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef PACKAGE_ICON_REPOSITORY_H #ifndef PACKAGE_ICON_REPOSITORY_H
@ -16,6 +16,7 @@ public:
virtual bool HasAnyIcon(const BString& pkgName) = 0; virtual bool HasAnyIcon(const BString& pkgName) = 0;
virtual status_t GetIcon(const BString& pkgName, BitmapSize size, virtual status_t GetIcon(const BString& pkgName, BitmapSize size,
BitmapRef& bitmap) = 0; BitmapRef& bitmap) = 0;
virtual void Clear() = 0;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * 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. /*! 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 Any existing data will be flushed and the new tar will be scanned for
offsets to usable files. offsets to usable files.
@ -195,10 +202,10 @@ PackageIconTarRepository::Init(BPath& tarPath)
void void
PackageIconTarRepository::_Close() PackageIconTarRepository::_Close()
{ {
fIconCache.Clear();
delete fTarIo; delete fTarIo;
fTarIo = NULL; fTarIo = NULL;
fIconTarPtrs.Clear(); fIconTarPtrs.Clear();
fIconCache.Clear();
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#ifndef PACKAGE_ICON_TAR_REPOSITORY_H #ifndef PACKAGE_ICON_TAR_REPOSITORY_H
@ -32,6 +32,7 @@ public:
virtual status_t GetIcon(const BString& pkgName, BitmapSize size, virtual status_t GetIcon(const BString& pkgName, BitmapSize size,
BitmapRef& bitmap); BitmapRef& bitmap);
virtual bool HasAnyIcon(const BString& pkgName); virtual bool HasAnyIcon(const BString& pkgName);
virtual void Clear();
static void CleanupDefaultIcon(); static void CleanupDefaultIcon();

View File

@ -441,7 +441,7 @@ PackageInfo::PackageInfo()
fChangelog(), fChangelog(),
fUserRatings(), fUserRatings(),
fCachedRatingSummary(), fCachedRatingSummary(),
fProminence(0.0f), fProminence(0),
fScreenshotInfos(), fScreenshotInfos(),
fScreenshots(), fScreenshots(),
fState(NONE), fState(NONE),
@ -471,7 +471,7 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
fChangelog(), fChangelog(),
fUserRatings(), fUserRatings(),
fCachedRatingSummary(), fCachedRatingSummary(),
fProminence(0.0f), fProminence(0),
fScreenshotInfos(), fScreenshotInfos(),
fScreenshots(), fScreenshots(),
fState(NONE), fState(NONE),
@ -485,7 +485,6 @@ PackageInfo::PackageInfo(const BPackageInfo& info)
fDepotName(""), fDepotName(""),
fIsCollatingChanges(false), fIsCollatingChanges(false),
fCollatedChanges(0) fCollatedChanges(0)
{ {
BString publisherURL; BString publisherURL;
if (info.URLList().CountStrings() > 0) if (info.URLList().CountStrings() > 0)
@ -518,7 +517,7 @@ PackageInfo::PackageInfo(const BString& name,
fCategories(), fCategories(),
fUserRatings(), fUserRatings(),
fCachedRatingSummary(), fCachedRatingSummary(),
fProminence(0.0f), fProminence(0),
fScreenshotInfos(), fScreenshotInfos(),
fScreenshots(), fScreenshots(),
fState(NONE), fState(NONE),
@ -1051,18 +1050,12 @@ PackageInfo::_NotifyListeners(uint32 changes)
void void
PackageInfo::_NotifyListenersImmediate(uint32 changes) PackageInfo::_NotifyListenersImmediate(uint32 changes)
{ {
int count = fListeners.size(); if (fListeners.empty())
if (count == 0)
return; return;
// Clone list to avoid listeners detaching themselves in notifications // Clone list to avoid listeners detaching themselves in notifications
// to screw up the list while iterating it. // to screw up the list while iterating it.
std::vector<PackageInfoListenerRef> listeners(fListeners); std::vector<PackageInfoListenerRef> listeners(fListeners);
// Check if it worked:
if (listeners.size() != count)
return;
PackageInfoEvent event(PackageInfoRef(this), changes); PackageInfoEvent event(PackageInfoRef(this), changes);
std::vector<PackageInfoListenerRef>::iterator it; std::vector<PackageInfoListenerRef>::iterator it;
@ -1077,27 +1070,21 @@ PackageInfo::_NotifyListenersImmediate(uint32 changes)
// #pragma mark - Sorting Functions // #pragma mark - Sorting Functions
/*! This function is used with the List class in order to facilitate fast static bool
ordered inserting of packages. _IsPackageBeforeByName(const PackageInfoRef& p1, const BString& packageName)
*/
static int32
PackageCompare(const PackageInfoRef& p1, const PackageInfoRef& p2)
{ {
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 /*! This function is used in order to provide an ordering on the packages
searching of packages. that are stored on a Depot.
*/ */
static int32 static bool
PackageFixedNameCompare(const void* context, _IsPackageBefore(const PackageInfoRef& p1, const PackageInfoRef& p2)
const PackageInfoRef& package)
{ {
const BString* packageName = static_cast<const BString*>(context); return _IsPackageBeforeByName(p1, p2->Name());
return packageName->Compare(package->Name());
} }
@ -1107,7 +1094,6 @@ PackageFixedNameCompare(const void* context,
DepotInfo::DepotInfo() DepotInfo::DepotInfo()
: :
fName(), fName(),
fPackages(&PackageCompare, &PackageFixedNameCompare),
fWebAppRepositoryCode() fWebAppRepositoryCode()
{ {
} }
@ -1116,7 +1102,6 @@ DepotInfo::DepotInfo()
DepotInfo::DepotInfo(const BString& name) DepotInfo::DepotInfo(const BString& name)
: :
fName(name), fName(name),
fPackages(&PackageCompare, &PackageFixedNameCompare),
fWebAppRepositoryCode(), fWebAppRepositoryCode(),
fWebAppRepositorySourceCode() 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 /*! This method will insert the package into the list of packages
in order so that the list of packages remains in order. in order so that the list of packages remains in order.
*/ */
bool void
DepotInfo::AddPackage(const PackageInfoRef& package) DepotInfo::AddPackage(PackageInfoRef& package)
{ {
return fPackages.Add(package); std::vector<PackageInfoRef>::iterator itInsertionPt
= std::lower_bound(
fPackages.begin(),
fPackages.end(),
package,
&_IsPackageBefore);
fPackages.insert(itInsertionPt, package);
} }
int32 bool
DepotInfo::PackageIndexByName(const BString& packageName) const DepotInfo::HasPackage(const BString& packageName)
{ {
return fPackages.Search(&packageName); std::vector<PackageInfoRef>::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<PackageInfoRef>::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 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--) { if (myPackage.Get() != NULL) {
const PackageInfoRef& otherPackage = otherPackages.ItemAtFast(i); myPackage->SetState(otherPackage->State());
bool found = false; myPackage->SetLocalFilePath(otherPackage->LocalFilePath());
for (int32 j = packages.CountItems() - 1; j >= 0; j--) { myPackage->SetSystemDependency(otherPackage->IsSystemDependency());
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 (!found) { else {
HDINFO("%s: new package: '%s'", fName.String(), HDINFO("%s: new package: '%s'", fName.String(),
otherPackage->Name().String()); otherPackage->Name().String());
fPackages.Add(otherPackage); AddPackage(otherPackage);
} }
} }
for (int32 i = packages.CountItems() - 1; i >= 0; i--) { for (int32 i = CountPackages() - 1; i >= 0; i--) {
const PackageInfoRef& package = packages.ItemAtFast(i); PackageInfoRef myPackage = PackageAtIndex(i);
HDINFO("%s: removing package: '%s'", fName.String(), if (!other->HasPackage(myPackage->Name())) {
package->Name().String()); HDINFO("%s: removing package: '%s'", fName.String(),
fPackages.Remove(package); myPackage->Name().String());
fPackages.erase(fPackages.begin() + i);
}
} }
} }
@ -1218,9 +1247,9 @@ DepotInfo::SyncPackages(const PackageList& otherPackages)
bool bool
DepotInfo::HasAnyProminentPackages() const DepotInfo::HasAnyProminentPackages() const
{ {
int32 count = fPackages.CountItems(); std::vector<PackageInfoRef>::const_iterator it;
for (int32 i = 0; i < count; i++) { for (it = fPackages.begin(); it != fPackages.end(); it++) {
const PackageInfoRef& package = fPackages.ItemAtFast(i); const PackageInfoRef& package = *it;
if (package->IsProminent()) if (package->IsProminent())
return true; return true;
} }

View File

@ -396,9 +396,6 @@ private:
typedef BReference<PackageInfo> PackageInfoRef; typedef BReference<PackageInfo> PackageInfoRef;
typedef List<PackageInfoRef, false> PackageList;
class DepotInfo : public BReferenceable { class DepotInfo : public BReferenceable {
public: public:
DepotInfo(); DepotInfo();
@ -412,15 +409,14 @@ public:
const BString& Name() const const BString& Name() const
{ return fName; } { return fName; }
const PackageList& Packages() const int32 CountPackages() const;
{ return fPackages; } PackageInfoRef PackageAtIndex(int32 index);
void AddPackage(PackageInfoRef& package);
PackageInfoRef PackageByName(const BString& packageName);
bool HasPackage(const BString& packageName);
bool AddPackage(const PackageInfoRef& package); void SyncPackagesFromDepot(
const BReference<DepotInfo>& other);
int32 PackageIndexByName(const BString& packageName)
const;
void SyncPackages(const PackageList& packages);
bool HasAnyProminentPackages() const; bool HasAnyProminentPackages() const;
@ -439,7 +435,8 @@ public:
private: private:
BString fName; BString fName;
PackageList fPackages; std::vector<PackageInfoRef>
fPackages;
BString fWebAppRepositoryCode; BString fWebAppRepositoryCode;
BString fWebAppRepositorySourceCode; BString fWebAppRepositorySourceCode;
BString fURL; BString fURL;

View File

@ -312,19 +312,25 @@ public:
PackageInfoRef ref(FindPackageByName(packages.ItemAt(i) PackageInfoRef ref(FindPackageByName(packages.ItemAt(i)
->Name())); ->Name()));
if (ref.IsSet()) if (ref.IsSet())
fRemovedPackages.Add(ref); fRemovedPackages.push_back(ref);
} }
} }
void ApplyingChangesDone( void ApplyingChangesDone(
BPackageManager::InstalledRepository& repository) BPackageManager::InstalledRepository& repository)
{ {
for (int32 i = 0; i < fRemovedPackages.CountItems(); i++) std::vector<PackageInfoRef>::iterator it;
fRemovedPackages.ItemAt(i)->SetState(NONE); for (
it = fRemovedPackages.begin();
it != fRemovedPackages.end();
it++) {
PackageInfoRef packageInfoRef = *it;
packageInfoRef->SetState(NONE);
}
} }
private: private:
PackageList fRemovedPackages; std::vector<PackageInfoRef> fRemovedPackages;
}; };

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2017-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
#include "ServerIconExportUpdateProcess.h" #include "ServerIconExportUpdateProcess.h"
@ -248,11 +248,10 @@ ServerIconExportUpdateProcess::_NotifyPackagesWithIconsInDepot(
{ {
PackageIconRepository& packageIconRepository PackageIconRepository& packageIconRepository
= fModel->GetPackageIconRepository(); = fModel->GetPackageIconRepository();
const PackageList& packages = depot->Packages(); for (int32 p = 0; p < depot->CountPackages(); p++) {
for (int32 p = 0; p < packages.CountItems(); p++) {
AutoLocker<BLocker> locker(fModel->Lock()); AutoLocker<BLocker> locker(fModel->Lock());
const PackageInfoRef& packageInfoRef = packages.ItemAtFast(p); const PackageInfoRef& packageInfoRef = depot->PackageAtIndex(p);
if (packageIconRepository.HasAnyIcon(packageInfoRef->Name())) if (packageIconRepository.HasAnyIcon(packageInfoRef->Name()))
packages.ItemAtFast(p)->NotifyChangedIcon(); packageInfoRef->NotifyChangedIcon();
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2017-2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2017-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@ -172,20 +172,15 @@ PackageFillingPkgListener::Count()
bool bool
PackageFillingPkgListener::Handle(DumpExportPkg* pkg) PackageFillingPkgListener::Handle(DumpExportPkg* pkg)
{ {
const DepotInfo* depotInfo = fModel->DepotForName(fDepotName); AutoLocker<BLocker> locker(fModel->Lock());
DepotInfoRef depot = fModel->DepotForName(fDepotName);
if (depotInfo != NULL) { if (depot.Get() != NULL) {
const BString packageName = *(pkg->Name()); const BString packageName = *(pkg->Name());
int32 packageIndex = depotInfo->PackageIndexByName(packageName); PackageInfoRef package = depot->PackageByName(packageName);
if (package.Get() != NULL)
if (-1 != packageIndex) { ConsumePackage(package, pkg);
const PackageList& packages = depotInfo->Packages(); else {
const PackageInfoRef& packageInfoRef =
packages.ItemAtFast(packageIndex);
AutoLocker<BLocker> locker(fModel->Lock());
ConsumePackage(packageInfoRef, pkg);
} else {
HDINFO("[PackageFillingPkgListener] unable to find the pkg [%s]", HDINFO("[PackageFillingPkgListener] unable to find the pkg [%s]",
packageName.String()); packageName.String());
} }

View File

@ -1,7 +1,7 @@
/* /*
* Copyright 2013-214, Stephan Aßmus <superstippi@gmx.de>. * Copyright 2013-214, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>. * Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
* Copyright 2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2020-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@ -124,11 +124,14 @@ public:
switch (key) { switch (key) {
case B_RIGHT_ARROW: case B_RIGHT_ARROW:
case B_DOWN_ARROW: case B_DOWN_ARROW:
{
int32 lastIndex = static_cast<int32>(fPackages.size()) - 1;
if (!IsEmpty() && fSelectedIndex != -1 if (!IsEmpty() && fSelectedIndex != -1
&& fSelectedIndex < fPackages.size() - 1) { && fSelectedIndex < lastIndex) {
_MessageSelectIndex(fSelectedIndex + 1); _MessageSelectIndex(fSelectedIndex + 1);
} }
break; break;
}
case B_LEFT_ARROW: case B_LEFT_ARROW:
case B_UP_ARROW: case B_UP_ARROW:
if (fSelectedIndex > 0) if (fSelectedIndex > 0)
@ -165,7 +168,8 @@ public:
{ {
if (index != -1) { if (index != -1) {
BMessage message(MSG_PACKAGE_SELECTED); BMessage message(MSG_PACKAGE_SELECTED);
message.AddString("name", fPackages[index]->Name()); BString packageName = fPackages[index]->Name();
message.AddString("name", packageName);
Window()->PostMessage(&message); Window()->PostMessage(&message);
} }
} }
@ -589,8 +593,8 @@ public:
{ {
if (fPackages.empty()) if (fPackages.empty())
return -1; return -1;
int32 i = y / HEIGHT_PACKAGE; int32 i = static_cast<int32>(y / HEIGHT_PACKAGE);
if (i < 0 || i >= fPackages.size()) if (i < 0 || i >= static_cast<int32>(fPackages.size()))
return -1; return -1;
return i; return i;
} }
@ -606,7 +610,7 @@ public:
{ {
if (fPackages.empty()) if (fPackages.empty())
return -1; return -1;
int32 i = y / HEIGHT_PACKAGE; int32 i = static_cast<int32>(y / HEIGHT_PACKAGE);
if (i < 0) if (i < 0)
return 0; return 0;
return std::min(i, (int32) (fPackages.size() - 1)); return std::min(i, (int32) (fPackages.size() - 1));

View File

@ -3,7 +3,7 @@
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>. * Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2013, Rene Gollent, rene@gollent.com. * Copyright 2013, Rene Gollent, rene@gollent.com.
* Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2013, Ingo Weinhold, ingo_weinhold@gmx.de.
* Copyright 2016-2020, Andrew Lindesay <apl@lindesay.co.nz>. * Copyright 2016-2021, Andrew Lindesay <apl@lindesay.co.nz>.
* Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>. * Copyright 2017, Julian Harnath <julian.harnath@rwth-aachen.de>.
* All rights reserved. Distributed under the terms of the MIT License. * All rights reserved. Distributed under the terms of the MIT License.
*/ */
@ -429,7 +429,7 @@ MainWindow::MessageReceived(BMessage* message)
BAutolock locker(fModel.Lock()); BAutolock locker(fModel.Lock());
package = fModel.PackageForName(name); package = fModel.PackageForName(name);
} }
if (!package.IsSet()) if (package.IsSet() || name != package->Name())
debugger("unable to find the named package"); debugger("unable to find the named package");
else else
_AdoptPackage(package); _AdoptPackage(package);
@ -830,9 +830,10 @@ MainWindow::_AdoptModel()
std::vector<DepotInfoRef>::iterator it; std::vector<DepotInfoRef>::iterator it;
for (it = depots.begin(); it != depots.end(); it++) { for (it = depots.begin(); it != depots.end(); it++) {
DepotInfoRef depotInfoRef = *it; DepotInfoRef depotInfoRef = *it;
const PackageList& packages = depotInfoRef->Packages(); for (int i = 0; i < depotInfoRef->CountPackages(); i++) {
for (int32 p = 0; p < packages.CountItems(); p++) PackageInfoRef package = depotInfoRef->PackageAtIndex(i);
_AddRemovePackageFromLists(packages.ItemAtFast(p)); _AddRemovePackageFromLists(package);
}
} }
_AdoptModelControls(); _AdoptModelControls();