mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +08:00
refs #787, utility functions for shared files
* get file name from URL * service and file names in CDbInfo * adjusted DB flags, allow to load headers only * set of entity flags
This commit is contained in:
@@ -19,7 +19,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
bool CDbFlags::readsFromWeb(CDbFlags::DataRetrievalMode mode)
|
bool CDbFlags::readsFromWeb(CDbFlags::DataRetrievalMode mode)
|
||||||
{
|
{
|
||||||
return mode.testFlag(DbDirect) || mode.testFlag(Shared);
|
return mode.testFlag(DbReading) || mode.testFlag(Shared);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CDbFlags::flagToString(CDbFlags::DataRetrievalModeFlag flag)
|
QString CDbFlags::flagToString(CDbFlags::DataRetrievalModeFlag flag)
|
||||||
@@ -29,7 +29,7 @@ namespace BlackMisc
|
|||||||
case Unspecified: return "Unspecified";
|
case Unspecified: return "Unspecified";
|
||||||
case Ignore: return "Ignore";
|
case Ignore: return "Ignore";
|
||||||
case Canceled: return "Canceled";
|
case Canceled: return "Canceled";
|
||||||
case DbDirect: return "Direct DB access";
|
case DbReading: return "Direct DB access";
|
||||||
case Shared: return "Shared data";
|
case Shared: return "Shared data";
|
||||||
case Cached: return "Cached data";
|
case Cached: return "Cached data";
|
||||||
default:
|
default:
|
||||||
@@ -45,7 +45,7 @@ namespace BlackMisc
|
|||||||
if (mode.testFlag(Canceled)) list << "Canceled";
|
if (mode.testFlag(Canceled)) list << "Canceled";
|
||||||
if (mode.testFlag(Ignore)) list << "Ignore";
|
if (mode.testFlag(Ignore)) list << "Ignore";
|
||||||
|
|
||||||
if (mode.testFlag(DbDirect)) list << "Direct DB access";
|
if (mode.testFlag(DbReading)) list << "Direct DB access";
|
||||||
if (mode.testFlag(Shared)) list << "Shared data";
|
if (mode.testFlag(Shared)) list << "Shared data";
|
||||||
if (mode.testFlag(Cached)) list << "Cached data";
|
if (mode.testFlag(Cached)) list << "Cached data";
|
||||||
return list.join(',');
|
return list.join(',');
|
||||||
@@ -55,7 +55,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
switch (mode)
|
switch (mode)
|
||||||
{
|
{
|
||||||
case DbDirect: return Canceled;
|
case DbReading: return Canceled;
|
||||||
case CacheThenDb: return Cached;
|
case CacheThenDb: return Cached;
|
||||||
default: return mode;
|
default: return mode;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,15 +31,17 @@ namespace BlackMisc
|
|||||||
//! Which data to read, requires corresponding readers
|
//! Which data to read, requires corresponding readers
|
||||||
enum DataRetrievalModeFlag
|
enum DataRetrievalModeFlag
|
||||||
{
|
{
|
||||||
Unspecified = 0, //!< Unspecified
|
Unspecified = 0, //!< Unspecified
|
||||||
DbDirect = 1 << 0, //!< directly from DB
|
DbReading = 1 << 0, //!< directly from DB
|
||||||
Shared = 1 << 1, //!< shared directory
|
DbWriting = 1 << 1, //!< DB writing
|
||||||
Cached = 1 << 2, //!< from cache
|
Shared = 1 << 2, //!< shared directory
|
||||||
Canceled = 1 << 3, //!< canceled DB reading
|
SharedHeadersOnly = 1 << 3, //!< shared headers only
|
||||||
Ignore = 1 << 4, //!< ignore this entity
|
Cached = 1 << 4, //!< from cache
|
||||||
CacheThenDb = DbDirect | Cached, //!< Cache when possible, otherwise DB
|
Canceled = 1 << 5, //!< canceled DB reading
|
||||||
CacheThenShared = Shared | Cached //!< Cache when possible, otherwise shared
|
Ignore = 1 << 6, //!< ignore this entity
|
||||||
|
CacheThenDb = DbReading | Cached, //!< Cache where possible, otherwise DB
|
||||||
|
CacheThenShared = Shared | Cached, //!< Cache where possible, otherwise shared
|
||||||
|
CacheAndSharedHeaders = SharedHeadersOnly | Cached
|
||||||
};
|
};
|
||||||
Q_DECLARE_FLAGS(DataRetrievalMode, DataRetrievalModeFlag)
|
Q_DECLARE_FLAGS(DataRetrievalMode, DataRetrievalModeFlag)
|
||||||
|
|
||||||
|
|||||||
@@ -39,21 +39,14 @@ namespace BlackMisc
|
|||||||
|
|
||||||
const QString &CDbInfo::getSharedFileName() const
|
const QString &CDbInfo::getSharedFileName() const
|
||||||
{
|
{
|
||||||
static const QString empty;
|
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||||
CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
return CDbInfo::entityToSharedName(entity);
|
||||||
switch (entity)
|
}
|
||||||
{
|
|
||||||
case CEntityFlags::AircraftIcaoEntity: { return sharedFileNames().at(0); }
|
const QString &CDbInfo::getServiceName() const
|
||||||
case CEntityFlags::AirlineIcaoEntity: { return sharedFileNames().at(1); }
|
{
|
||||||
case CEntityFlags::AirportEntity: { return sharedFileNames().at(2); }
|
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||||
case CEntityFlags::CountryEntity: { return sharedFileNames().at(3); }
|
return CDbInfo::entityToServiceName(entity);
|
||||||
case CEntityFlags::DistributorEntity: { return sharedFileNames().at(4); }
|
|
||||||
case CEntityFlags::LiveryEntity: { return sharedFileNames().at(5); }
|
|
||||||
case CEntityFlags::ModelEntity: { return sharedFileNames().at(6); }
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDbInfo::setEntity(CEntityFlags::Entity entity)
|
void CDbInfo::setEntity(CEntityFlags::Entity entity)
|
||||||
@@ -161,7 +154,13 @@ namespace BlackMisc
|
|||||||
return names;
|
return names;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString &CDbInfo::entityToSharedFileName(CEntityFlags::Entity entity)
|
const QStringList &CDbInfo::serviceNames()
|
||||||
|
{
|
||||||
|
static const QStringList names({"jsonaircrafticao.php", "jsonairlineicao.php", "jsonairport.php", "jsoncountry.php", "jsondistributor.php", "jsonlivery.php", "jsonaircraftmodel.php" });
|
||||||
|
return names;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &CDbInfo::entityToSharedName(CEntityFlags::Entity entity)
|
||||||
{
|
{
|
||||||
static const QString empty;
|
static const QString empty;
|
||||||
switch (entity)
|
switch (entity)
|
||||||
@@ -178,5 +177,23 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
return empty;
|
return empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QString &CDbInfo::entityToServiceName(CEntityFlags::Entity entity)
|
||||||
|
{
|
||||||
|
static const QString empty;
|
||||||
|
switch (entity)
|
||||||
|
{
|
||||||
|
case CEntityFlags::AircraftIcaoEntity: return serviceNames().at(0);
|
||||||
|
case CEntityFlags::AirlineIcaoEntity: return serviceNames().at(1);
|
||||||
|
case CEntityFlags::AirportEntity: return serviceNames().at(2);
|
||||||
|
case CEntityFlags::CountryEntity: return serviceNames().at(3);
|
||||||
|
case CEntityFlags::DistributorEntity: return serviceNames().at(4);
|
||||||
|
case CEntityFlags::LiveryEntity: return serviceNames().at(5);
|
||||||
|
case CEntityFlags::ModelEntity: return serviceNames().at(6);
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return empty;
|
||||||
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -59,6 +59,9 @@ namespace BlackMisc
|
|||||||
//! The shared file name such as "airports.json"
|
//! The shared file name such as "airports.json"
|
||||||
const QString &getSharedFileName() const;
|
const QString &getSharedFileName() const;
|
||||||
|
|
||||||
|
//! Service name such as "jsonairport.php"
|
||||||
|
const QString &getServiceName() const;
|
||||||
|
|
||||||
//! Set entity, should be in sync with a corresponding table name
|
//! Set entity, should be in sync with a corresponding table name
|
||||||
void setEntity(Network::CEntityFlags::Entity entity);
|
void setEntity(Network::CEntityFlags::Entity entity);
|
||||||
|
|
||||||
@@ -89,8 +92,14 @@ namespace BlackMisc
|
|||||||
//! The shared file names
|
//! The shared file names
|
||||||
static const QStringList &sharedFileNames();
|
static const QStringList &sharedFileNames();
|
||||||
|
|
||||||
|
//! Service names
|
||||||
|
static const QStringList &serviceNames();
|
||||||
|
|
||||||
//! Get shared file name
|
//! Get shared file name
|
||||||
static const QString &entityToSharedFileName(Network::CEntityFlags::Entity entity);
|
static const QString &entityToSharedName(Network::CEntityFlags::Entity entity);
|
||||||
|
|
||||||
|
//! Get service file name
|
||||||
|
static const QString &entityToServiceName(Network::CEntityFlags::Entity entity);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_tableName; //!< table name
|
QString m_tableName; //!< table name
|
||||||
|
|||||||
@@ -155,6 +155,18 @@ namespace BlackMisc
|
|||||||
return NoEntity;
|
return NoEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QSet<CEntityFlags::Entity> CEntityFlags::asSingleEntities(Entity entities)
|
||||||
|
{
|
||||||
|
QSet<CEntityFlags::Entity> s;
|
||||||
|
CEntityFlags::Entity currentEntity = iterateDbEntities(entities);
|
||||||
|
while (currentEntity != NoEntity)
|
||||||
|
{
|
||||||
|
s.insert(currentEntity);
|
||||||
|
currentEntity = iterateDbEntities(entities);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
void CEntityFlags::registerMetadata()
|
void CEntityFlags::registerMetadata()
|
||||||
{
|
{
|
||||||
// this is no value class and I register enums here,
|
// this is no value class and I register enums here,
|
||||||
|
|||||||
@@ -96,7 +96,10 @@ namespace BlackMisc
|
|||||||
static bool anySwiftDbEntity(Entity entities);
|
static bool anySwiftDbEntity(Entity entities);
|
||||||
|
|
||||||
//! Get by name
|
//! Get by name
|
||||||
static CEntityFlags::Entity singleEntityByName(const QString &name);
|
static Entity singleEntityByName(const QString &name);
|
||||||
|
|
||||||
|
//! As set of single entities
|
||||||
|
static QSet<Entity> asSingleEntities(Entity entities);
|
||||||
|
|
||||||
//! Register metadata
|
//! Register metadata
|
||||||
static void registerMetadata();
|
static void registerMetadata();
|
||||||
|
|||||||
@@ -124,6 +124,11 @@ namespace BlackMisc
|
|||||||
setQUrl(QUrl(fullUrl));
|
setQUrl(QUrl(fullUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CUrl::getFileName() const
|
||||||
|
{
|
||||||
|
return toQUrl().fileName();
|
||||||
|
}
|
||||||
|
|
||||||
QUrl CUrl::toQUrl() const
|
QUrl CUrl::toQUrl() const
|
||||||
{
|
{
|
||||||
return QUrl(getFullUrl());
|
return QUrl(getFullUrl());
|
||||||
|
|||||||
@@ -115,6 +115,9 @@ namespace BlackMisc
|
|||||||
//! Set full URL
|
//! Set full URL
|
||||||
void setFullUrl(const QString &fullUrl);
|
void setFullUrl(const QString &fullUrl);
|
||||||
|
|
||||||
|
//! File name
|
||||||
|
QString getFileName() const;
|
||||||
|
|
||||||
//! To QUrl
|
//! To QUrl
|
||||||
QUrl toQUrl() const;
|
QUrl toQUrl() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user