From 8d68741ee9b2a95646e98b2b9ebc702651f77b14 Mon Sep 17 00:00:00 2001 From: James Turner Date: Sun, 5 Mar 2017 22:01:54 +0200 Subject: [PATCH] On-disk support for multiple primary aircraft. Also add support for customised / per-variant thumbnails in on-disk aircraft; equivalent support for catalog aircraft still to be done. --- src/GUI/AircraftModel.cxx | 26 ++++++++++++++++++++------ src/GUI/AircraftModel.hxx | 2 ++ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/GUI/AircraftModel.cxx b/src/GUI/AircraftModel.cxx index 512d95ebe..bd6b91d0d 100644 --- a/src/GUI/AircraftModel.cxx +++ b/src/GUI/AircraftModel.cxx @@ -42,7 +42,7 @@ const int STANDARD_THUMBNAIL_HEIGHT = 128; const int STANDARD_THUMBNAIL_WIDTH = 172; -static quint32 CACHE_VERSION = 6; +static quint32 CACHE_VERSION = 7; using namespace simgear::pkg; @@ -87,6 +87,12 @@ AircraftItem::AircraftItem(QDir dir, QString filePath) if (sim->hasChild("variant-of")) { variantOf = sim->getStringValue("variant-of"); + } else { + isPrimary = true; + } + + if (sim->hasChild("primary-set")) { + isPrimary = sim->getBoolValue("primary-set"); } if (sim->hasChild("tags")) { @@ -113,6 +119,12 @@ AircraftItem::AircraftItem(QDir dir, QString filePath) previews.append(QUrl::fromLocalFile(previewPath)); } } + + if (sim->hasChild("thumbnail")) { + thumbnailPath = sim->getStringValue("thumbnail"); + } else { + thumbnailPath = "thumbnail.jpg"; + } } QString AircraftItem::baseName() const @@ -129,9 +141,10 @@ void AircraftItem::fromDataStream(QDataStream& ds) return; } - ds >> description >> longDescription >> authors >> variantOf; + ds >> description >> longDescription >> authors >> variantOf >> isPrimary; for (int i=0; i<4; ++i) ds >> ratings[i]; ds >> previews; + ds >> thumbnailPath; } void AircraftItem::toDataStream(QDataStream& ds) const @@ -141,9 +154,10 @@ void AircraftItem::toDataStream(QDataStream& ds) const return; } - ds << description << longDescription << authors << variantOf; + ds << description << longDescription << authors << variantOf << isPrimary; for (int i=0; i<4; ++i) ds << ratings[i]; ds << previews; + ds << thumbnailPath; } QPixmap AircraftItem::thumbnail(bool loadIfRequired) const @@ -151,8 +165,8 @@ QPixmap AircraftItem::thumbnail(bool loadIfRequired) const if (m_thumbnail.isNull() && loadIfRequired) { QFileInfo info(path); QDir dir = info.dir(); - if (dir.exists("thumbnail.jpg")) { - m_thumbnail.load(dir.filePath("thumbnail.jpg")); + if (dir.exists(thumbnailPath)) { + m_thumbnail.load(dir.filePath(thumbnailPath)); // resize to the standard size if (m_thumbnail.height() > STANDARD_THUMBNAIL_HEIGHT) { m_thumbnail = m_thumbnail.scaledToHeight(STANDARD_THUMBNAIL_HEIGHT, Qt::SmoothTransformation); @@ -283,7 +297,7 @@ private: continue; } - if (item->variantOf.isNull()) { + if (item->isPrimary) { baseAircraft.insert(item->baseName(), item); } else { variants.append(item); diff --git a/src/GUI/AircraftModel.hxx b/src/GUI/AircraftModel.hxx index 613cb75e0..3bd4b6162 100644 --- a/src/GUI/AircraftModel.hxx +++ b/src/GUI/AircraftModel.hxx @@ -92,6 +92,8 @@ struct AircraftItem bool usesHeliports = false; bool usesSeaports = false; QList previews; + bool isPrimary = false; + QString thumbnailPath; private: mutable QPixmap m_thumbnail; };