2017-10-09 20:53:26 +00:00
|
|
|
// Written by James Turner, started October 2017
|
|
|
|
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 James Turner <zakalawe@mac.com>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
#ifndef LOCALAIRCRAFTCACHE_HXX
|
|
|
|
#define LOCALAIRCRAFTCACHE_HXX
|
|
|
|
|
2018-01-07 14:19:28 +00:00
|
|
|
#include <memory>
|
2017-10-09 20:53:26 +00:00
|
|
|
#include <QObject>
|
|
|
|
#include <QPixmap>
|
|
|
|
#include <QDateTime>
|
|
|
|
#include <QUrl>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QDir>
|
|
|
|
#include <QVariant>
|
|
|
|
|
2020-06-19 09:45:47 +00:00
|
|
|
#include <simgear/props/props.hxx>
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
class QDataStream;
|
|
|
|
struct AircraftItem;
|
2018-10-08 11:31:27 +00:00
|
|
|
class SGPropertyNode;
|
2017-10-09 20:53:26 +00:00
|
|
|
|
|
|
|
typedef QSharedPointer<AircraftItem> AircraftItemPtr;
|
|
|
|
|
|
|
|
struct AircraftItem
|
|
|
|
{
|
2020-06-19 09:45:47 +00:00
|
|
|
AircraftItem() = default;
|
2017-10-09 20:53:26 +00:00
|
|
|
|
|
|
|
AircraftItem(QDir dir, QString filePath);
|
|
|
|
|
|
|
|
// the file-name without -set.xml suffix
|
|
|
|
QString baseName() const;
|
|
|
|
|
2020-06-19 09:45:47 +00:00
|
|
|
QString name() const;
|
|
|
|
|
|
|
|
QString description() const;
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
void fromDataStream(QDataStream& ds);
|
|
|
|
|
|
|
|
void toDataStream(QDataStream& ds) const;
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
int indexOfVariant(QUrl uri) const;
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
bool excluded = false;
|
|
|
|
QString path;
|
2020-06-19 09:45:47 +00:00
|
|
|
|
2018-07-26 11:03:21 +00:00
|
|
|
QString authors; // legacy authors data only
|
2017-10-09 20:53:26 +00:00
|
|
|
int ratings[4] = {0, 0, 0, 0};
|
|
|
|
QString variantOf;
|
|
|
|
QDateTime pathModTime;
|
|
|
|
QList<AircraftItemPtr> variants;
|
|
|
|
bool usesHeliports = false;
|
|
|
|
bool usesSeaports = false;
|
|
|
|
QList<QUrl> previews;
|
|
|
|
bool isPrimary = false;
|
|
|
|
QString thumbnailPath;
|
|
|
|
QString minFGVersion;
|
2018-10-09 09:25:50 +00:00
|
|
|
QStringList tags;
|
2017-10-09 20:53:26 +00:00
|
|
|
bool needsMaintenance = false;
|
2018-07-26 11:03:21 +00:00
|
|
|
QUrl homepageUrl;
|
|
|
|
QUrl wikipediaUrl;
|
|
|
|
QUrl supportUrl;
|
2017-10-09 20:53:26 +00:00
|
|
|
QVariant status(int variant);
|
2020-06-19 09:45:47 +00:00
|
|
|
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
private:
|
2020-06-19 09:45:47 +00:00
|
|
|
struct LocalizedStrings {
|
|
|
|
QString locale;
|
|
|
|
QMap<QByteArray, QString> strings;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend QDataStream& operator<<(QDataStream&, const LocalizedStrings&);
|
|
|
|
friend QDataStream& operator>>(QDataStream&, LocalizedStrings&);
|
|
|
|
|
|
|
|
using LocalizedStringsVec = QVector<LocalizedStrings>;
|
|
|
|
|
|
|
|
// store all localized strings. We need this to avoid rebuilding
|
|
|
|
// the cache when switching languages.
|
|
|
|
LocalizedStringsVec _localized;
|
|
|
|
|
|
|
|
// the resolved values for our strings, based on QLocale
|
|
|
|
// if we support dynamic switching of language, this would need to
|
|
|
|
// be flushed and re-computed
|
|
|
|
QMap<QByteArray, QString> _currentStrings;
|
|
|
|
|
|
|
|
void doLocalizeStrings();
|
|
|
|
|
|
|
|
void readLocalizedStrings(SGPropertyNode_ptr simNode);
|
2017-10-09 20:53:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class LocalAircraftCache : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
~LocalAircraftCache();
|
|
|
|
|
|
|
|
static LocalAircraftCache* instance();
|
|
|
|
|
|
|
|
|
|
|
|
void setPaths(QStringList paths);
|
2020-10-06 10:39:21 +00:00
|
|
|
QStringList paths() const;
|
2017-10-09 20:53:26 +00:00
|
|
|
|
|
|
|
void scanDirs();
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @helper to determine if a particular path is likely to contain
|
|
|
|
* aircraft or not. Checks for -set.xml files one level down in the tree.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
static bool isCandidateAircraftPath(QString path);
|
|
|
|
|
|
|
|
int itemCount() const;
|
|
|
|
|
2018-01-07 14:19:28 +00:00
|
|
|
QVector<AircraftItemPtr> allItems() const;
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
AircraftItemPtr itemAt(int index) const;
|
|
|
|
|
|
|
|
AircraftItemPtr findItemWithUri(QUrl aircraftUri) const;
|
|
|
|
int findIndexWithUri(QUrl aircraftUri) const;
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
AircraftItemPtr primaryItemFor(AircraftItemPtr item) const;
|
|
|
|
|
2017-10-09 20:53:26 +00:00
|
|
|
QVariant aircraftStatus(AircraftItemPtr item) const;
|
|
|
|
|
|
|
|
enum AircraftStatus
|
|
|
|
{
|
|
|
|
AircraftOk = 0,
|
|
|
|
AircraftUnmaintained,
|
|
|
|
AircraftNeedsNewerSimulator,
|
|
|
|
AircraftNeedsOlderSimulator // won't ever occur for the moment
|
|
|
|
};
|
|
|
|
|
2017-10-13 15:48:24 +00:00
|
|
|
enum PackageStatus {
|
|
|
|
PackageNotInstalled = 0,
|
|
|
|
PackageInstalled,
|
|
|
|
PackageUpdateAvailable,
|
|
|
|
PackageQueued,
|
2017-12-09 09:46:14 +00:00
|
|
|
PackageDownloading,
|
2020-02-24 11:32:43 +00:00
|
|
|
NotPackaged,
|
|
|
|
PackageInstallFailed
|
2017-10-13 15:48:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
Q_ENUMS(PackageStatus)
|
|
|
|
Q_ENUMS(AircraftStatus)
|
2018-10-08 11:31:27 +00:00
|
|
|
|
|
|
|
// rating order is FDM, Systems, Cockpit, External model
|
|
|
|
static int ratingFromProperties(SGPropertyNode* node, int ratingIndex);
|
2020-10-06 10:39:21 +00:00
|
|
|
|
|
|
|
enum class ParseSetXMLResult {
|
|
|
|
Ok,
|
|
|
|
Failed,
|
|
|
|
Retry ///< aircraft scan in progress, try again later
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @brief readAircraftProperties - helper to parse a -set.xml, but with the correct
|
|
|
|
* path setup (root, aircradft dirs, current aircraft dir)
|
|
|
|
* @param path : full path to the -set.xml file
|
|
|
|
* @param props : property node to be populated
|
|
|
|
* @return status indication
|
|
|
|
*/
|
|
|
|
ParseSetXMLResult readAircraftProperties(const SGPath& path, SGPropertyNode_ptr props);
|
2017-10-09 20:53:26 +00:00
|
|
|
signals:
|
|
|
|
|
|
|
|
void scanStarted();
|
|
|
|
void scanCompleted();
|
|
|
|
|
2017-12-15 15:42:36 +00:00
|
|
|
void cleared();
|
2017-10-09 20:53:26 +00:00
|
|
|
void addedItems(int count);
|
|
|
|
public slots:
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void onScanResults();
|
|
|
|
|
|
|
|
void onScanFinished();
|
|
|
|
|
|
|
|
private:
|
|
|
|
explicit LocalAircraftCache();
|
|
|
|
|
|
|
|
void abandonCurrentScan();
|
|
|
|
|
2020-10-06 10:39:21 +00:00
|
|
|
class AircraftCachePrivate;
|
|
|
|
std::unique_ptr<AircraftCachePrivate> d;
|
2017-10-09 20:53:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LOCALAIRCRAFTCACHE_HXX
|