]> git.mxchange.org Git - simgear.git/commitdiff
Fix for catalog adding/removing bugs
authorJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 17:57:36 +0000 (17:57 +0000)
committerJames Turner <zakalawe@mac.com>
Mon, 23 Nov 2015 17:57:36 +0000 (17:57 +0000)
simgear/package/Delegate.hxx
simgear/package/Root.cxx

index 8de67aa53c75fcbbbbca1309cfd7b50178a2ee94..df82f58e4cb7681d909896ef08b5b56a280971f0 100644 (file)
@@ -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
index 8d3b52a86a8b8ec9f8f26234597b2ccfa66787f1..192db3dcbb9dd30dea0746267d4e82f7e7ab2106 100644 (file)
@@ -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);