From: James Turner Date: Mon, 23 Nov 2015 17:57:36 +0000 (+0000) Subject: Fix for catalog adding/removing bugs X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=3f20a3d2c694172214c84222b54e56e4cddb957b;p=simgear.git Fix for catalog adding/removing bugs --- diff --git a/simgear/package/Delegate.hxx b/simgear/package/Delegate.hxx index 8de67aa5..df82f58e 100644 --- a/simgear/package/Delegate.hxx +++ b/simgear/package/Delegate.hxx @@ -68,9 +68,13 @@ public: virtual void installProgress(InstallRef aInstall, unsigned int aBytes, unsigned int aTotal) = 0; virtual void finishInstall(InstallRef aInstall, StatusCode aReason) = 0; + /** + * Notification when catalogs/packages are added or removed + */ + virtual void availablePackagesChanged() {} + virtual void dataForThumbnail(const std::string& aThumbnailUrl, - size_t lenth, const uint8_t* bytes) - {} + size_t lenth, const uint8_t* bytes) {} }; } // of namespace pkg diff --git a/simgear/package/Root.cxx b/simgear/package/Root.cxx index 8d3b52a8..192db3dc 100644 --- a/simgear/package/Root.cxx +++ b/simgear/package/Root.cxx @@ -105,8 +105,15 @@ public: (*it)->catalogRefreshed(catalog, status); } } - - + + void firePackagesChanged() + { + DelegateVec::const_iterator it; + for (it = delegates.begin(); it != delegates.end(); ++it) { + (*it)->availablePackagesChanged(); + } + } + void thumbnailDownloadComplete(HTTP::Request_ptr request, Delegate::StatusCode status, const std::string& bytes) { @@ -475,15 +482,10 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason) if (aReason == Delegate::STATUS_IN_PROGRESS) { d->refreshing.insert(aCat); - - if (catIt == d->catalogs.end()) { - // first fresh, add to our storage now - d->catalogs.insert(catIt, CatalogDict::value_type(aCat->id(), aCat)); - } } else { d->refreshing.erase(aCat); } - + if ((aReason != Delegate::STATUS_REFRESHED) && (aReason != Delegate::STATUS_IN_PROGRESS)) { // if the failure is permanent, delete the catalog from our // list (don't touch it on disk) @@ -495,9 +497,15 @@ void Root::catalogRefreshStatus(CatalogRef aCat, Delegate::StatusCode aReason) } } } - + + if ((aReason == Delegate::STATUS_REFRESHED) && (catIt == d->catalogs.end())) { + assert(!aCat->id().empty()); + d->catalogs.insert(catIt, CatalogDict::value_type(aCat->id(), aCat)); + } + if (d->refreshing.empty()) { d->fireRefreshStatus(CatalogRef(), Delegate::STATUS_REFRESHED); + d->firePackagesChanged(); } } @@ -508,21 +516,24 @@ bool Root::removeCatalogById(const std::string& aId) SG_LOG(SG_GENERAL, SG_WARN, "removeCatalogById: unknown ID:" << aId); return false; } - + CatalogRef cat = catIt->second; - + // drop the reference d->catalogs.erase(catIt); - + bool ok = cat->uninstall(); if (!ok) { SG_LOG(SG_GENERAL, SG_WARN, "removeCatalogById: catalog :" << aId << "failed to uninstall"); } - + + // notify that a catalog is being removed + d->firePackagesChanged(); + return ok; } - + void Root::requestThumbnailData(const std::string& aUrl) { MemThumbnailCache::iterator it = d->thumbnailCache.find(aUrl);