#include <QPushButton>
#include <QDebug>
+#include <Main/globals.hxx>
+#include <Network/HTTPClient.hxx>
#include <Include/version.h>
using namespace simgear::pkg;
}
if (m_state == STATE_FINISHED) {
- QString catDesc = QString::fromStdString(m_result->description());
+ QString catDesc = QString::fromStdString(m_result->name());
QString s = tr("Successfully retrieved aircraft information from '%1'. "
"%2 aircraft are included in this hangar.").arg(catDesc).arg(m_result->packages().size());
ui->resultsSummaryLabel->setText(s);
} else if (m_state == STATE_DOWNLOAD_FAILED) {
Delegate::StatusCode code = m_result->status();
- qWarning() << Q_FUNC_INFO << "failed with code" << code;
QString s;
switch (code) {
case Delegate::FAIL_DOWNLOAD:
- s = tr("Failed to download aircraft descriptions from '%1'. "
+ s = tr("Failed to download aircraft descriptions from '%1'. "
"Check the address (URL) and your network connection.").arg(m_catalogUrl.toString());
break;
+ case Delegate::FAIL_NOT_FOUND:
+ s = tr("Failed to download aircraft descriptions at '%1'. "
+ "Check the URL is correct.").arg(m_catalogUrl.toString());
+ break;
+
case Delegate::FAIL_VERSION:
s = tr("The provided hangar is for a different version of FlightGear. "
"(This is version %1)").arg(QString::fromUtf8(FLIGHTGEAR_VERSION));
void AddCatalogDialog::onCatalogStatusChanged(Catalog* cat)
{
Delegate::StatusCode s = cat->status();
- qDebug() << Q_FUNC_INFO << "cat status:" << s;
switch (s) {
case Delegate::STATUS_REFRESHED:
m_state = STATE_FINISHED;
// don't jump to STATE_FINISHED
return;
+ case Delegate::FAIL_NOT_FOUND:
+ {
+ FGHTTPClient* http = globals->get_subsystem<FGHTTPClient>();
+ if (cat->url() == http->getDefaultCatalogUrl()) {
+ cat->setUrl(http->getDefaultCatalogFallbackUrl());
+ cat->refresh(); // and trigger another refresh
+ return;
+ }
+
+ m_state = STATE_DOWNLOAD_FAILED;
+ break;
+ }
+
// all the actual failure codes
default:
m_state = STATE_DOWNLOAD_FAILED;
typedef nasal::Ghost<pkg::CatalogRef> NasalCatalog;
typedef nasal::Ghost<pkg::InstallRef> NasalInstall;
+const char* OFFICIAL_CATALOG_ID = "org.flightgear.official";
-class FGHTTPClient::FGDelegate : public pkg::Delegate
-{
-public:
- virtual void refreshComplete()
- {
- SG_LOG(SG_IO, SG_INFO, "all Catalogs refreshed");
-
- // auto-update; make this controlled by a property
- pkg::Root* r = globals->packageRoot();
-
- pkg::PackageList toBeUpdated(r->packagesNeedingUpdate());
- pkg::PackageList::const_iterator it;
- for (it = toBeUpdated.begin(); it != toBeUpdated.end(); ++it) {
- assert((*it)->isInstalled());
- SG_LOG(SG_IO, SG_INFO, "updating:" << (*it)->id());
- r->scheduleToUpdate((*it)->install());
+// fallback URL is used when looking up a version-specific catalog fails
+const char* FALLBACK_CATALOG_URL = "http://fgfs.goneabitbursar.com/pkg/catalog.xml";
+
+namespace {
+
+ std::string _getDefaultCatalogId()
+ {
+ return fgGetString("/sim/package-system/default-catalog/id",
+ OFFICIAL_CATALOG_ID);
}
- }
-
- virtual void catalogRefreshed(pkg::CatalogRef aCat, StatusCode aReason)
- {
- if (aCat.ptr() == NULL) {
- SG_LOG(SG_IO, SG_INFO, "refresh of all catalogs done");
- return;
- }
-
- switch (aReason) {
- case pkg::Delegate::STATUS_SUCCESS:
- case pkg::Delegate::STATUS_REFRESHED:
- SG_LOG(SG_IO, SG_INFO, "refresh of Catalog done:" << aCat->url());
- break;
-
- case pkg::Delegate::STATUS_IN_PROGRESS:
- SG_LOG(SG_IO, SG_INFO, "refresh of Catalog started:" << aCat->url());
- break;
-
- default:
- SG_LOG(SG_IO, SG_WARN, "refresh of Catalog " << aCat->url() << " failed:" << aReason);
+
+ pkg::CatalogRef getDefaultCatalog()
+ {
+ if (!globals->packageRoot())
+ return pkg::CatalogRef();
+
+ return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
}
- }
-
- virtual void startInstall(pkg::InstallRef aInstall)
- {
- SG_LOG(SG_IO, SG_INFO, "beginning install of:" << aInstall->package()->id()
- << " to local path:" << aInstall->path());
- }
-
- virtual void installProgress(pkg::InstallRef aInstall, unsigned int aBytes, unsigned int aTotal)
- {
- }
-
- virtual void finishInstall(pkg::InstallRef aInstall, StatusCode aReason)
- {
- if (aReason == STATUS_SUCCESS) {
- SG_LOG(SG_IO, SG_INFO, "finished install of:" << aInstall->package()->id()
- << " to local path:" << aInstall->path());
- } else {
- SG_LOG(SG_IO, SG_WARN, "install failed of:" << aInstall->package()->id()
- << " to local path:" << aInstall->path());
- }
+ std::string _getDefaultCatalogUrl()
+ {
+ return fgGetString("/sim/package-system/default-catalog/url",
+ "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");
+ }
+} // of anonymous namespace
- }
-}; // of FGHTTPClient::FGDelegate
FGHTTPClient::FGHTTPClient() :
_inited(false)
if (packageRoot) {
// package system needs access to the HTTP engine too
packageRoot->setHTTPClient(_http.get());
-
- _packageDelegate.reset(new FGDelegate);
- packageRoot->addDelegate(_packageDelegate.get());
-
+
// start a refresh now
// setting 'force' true to work around the problem where a slightly stale
// catalog exists, but aircraft are modified - this causes an MD5 sum
_inited = true;
}
-namespace {
-
-std::string _getDefaultCatalogId()
-{
- return fgGetString("/sim/package-system/default-catalog/id", "org.flightgear.official" );
-}
-
-pkg::CatalogRef getDefaultCatalog()
-{
- if (!globals->packageRoot())
- return pkg::CatalogRef();
-
- return globals->packageRoot()->getCatalogById(_getDefaultCatalogId());
-}
-
-} // of anonymous namespace
-
bool FGHTTPClient::isDefaultCatalogInstalled() const
{
return getDefaultCatalog().valid();
std::string FGHTTPClient::getDefaultCatalogUrl() const
{
- return fgGetString("/sim/package-system/default-catalog/url",
- "http://fgfs.goneabitbursar.com/pkg/" FLIGHTGEAR_VERSION "/catalog.xml");;
+ return _getDefaultCatalogUrl();
+}
+
+std::string FGHTTPClient::getDefaultCatalogFallbackUrl() const
+{
+ return std::string(FALLBACK_CATALOG_URL);
}
static naRef f_package_existingInstall( pkg::Package& pkg,
void FGHTTPClient::shutdown()
{
- pkg::Root* packageRoot = globals->packageRoot();
- if (packageRoot && _packageDelegate.get()) {
- packageRoot->removeDelegate(_packageDelegate.get());
- }
-
- _packageDelegate.reset();
_http.reset();
_inited = false;