mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-30 11:55:35 +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)
|
||||
{
|
||||
return mode.testFlag(DbDirect) || mode.testFlag(Shared);
|
||||
return mode.testFlag(DbReading) || mode.testFlag(Shared);
|
||||
}
|
||||
|
||||
QString CDbFlags::flagToString(CDbFlags::DataRetrievalModeFlag flag)
|
||||
@@ -29,7 +29,7 @@ namespace BlackMisc
|
||||
case Unspecified: return "Unspecified";
|
||||
case Ignore: return "Ignore";
|
||||
case Canceled: return "Canceled";
|
||||
case DbDirect: return "Direct DB access";
|
||||
case DbReading: return "Direct DB access";
|
||||
case Shared: return "Shared data";
|
||||
case Cached: return "Cached data";
|
||||
default:
|
||||
@@ -45,7 +45,7 @@ namespace BlackMisc
|
||||
if (mode.testFlag(Canceled)) list << "Canceled";
|
||||
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(Cached)) list << "Cached data";
|
||||
return list.join(',');
|
||||
@@ -55,7 +55,7 @@ namespace BlackMisc
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case DbDirect: return Canceled;
|
||||
case DbReading: return Canceled;
|
||||
case CacheThenDb: return Cached;
|
||||
default: return mode;
|
||||
}
|
||||
|
||||
@@ -32,14 +32,16 @@ namespace BlackMisc
|
||||
enum DataRetrievalModeFlag
|
||||
{
|
||||
Unspecified = 0, //!< Unspecified
|
||||
DbDirect = 1 << 0, //!< directly from DB
|
||||
Shared = 1 << 1, //!< shared directory
|
||||
Cached = 1 << 2, //!< from cache
|
||||
Canceled = 1 << 3, //!< canceled DB reading
|
||||
Ignore = 1 << 4, //!< ignore this entity
|
||||
CacheThenDb = DbDirect | Cached, //!< Cache when possible, otherwise DB
|
||||
CacheThenShared = Shared | Cached //!< Cache when possible, otherwise shared
|
||||
|
||||
DbReading = 1 << 0, //!< directly from DB
|
||||
DbWriting = 1 << 1, //!< DB writing
|
||||
Shared = 1 << 2, //!< shared directory
|
||||
SharedHeadersOnly = 1 << 3, //!< shared headers only
|
||||
Cached = 1 << 4, //!< from cache
|
||||
Canceled = 1 << 5, //!< canceled DB reading
|
||||
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)
|
||||
|
||||
|
||||
@@ -39,21 +39,14 @@ namespace BlackMisc
|
||||
|
||||
const QString &CDbInfo::getSharedFileName() const
|
||||
{
|
||||
static const QString empty;
|
||||
CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||
switch (entity)
|
||||
{
|
||||
case CEntityFlags::AircraftIcaoEntity: { return sharedFileNames().at(0); }
|
||||
case CEntityFlags::AirlineIcaoEntity: { return sharedFileNames().at(1); }
|
||||
case CEntityFlags::AirportEntity: { return sharedFileNames().at(2); }
|
||||
case CEntityFlags::CountryEntity: { return sharedFileNames().at(3); }
|
||||
case CEntityFlags::DistributorEntity: { return sharedFileNames().at(4); }
|
||||
case CEntityFlags::LiveryEntity: { return sharedFileNames().at(5); }
|
||||
case CEntityFlags::ModelEntity: { return sharedFileNames().at(6); }
|
||||
default:
|
||||
break;
|
||||
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||
return CDbInfo::entityToSharedName(entity);
|
||||
}
|
||||
return empty;
|
||||
|
||||
const QString &CDbInfo::getServiceName() const
|
||||
{
|
||||
const CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(this->getTableName());
|
||||
return CDbInfo::entityToServiceName(entity);
|
||||
}
|
||||
|
||||
void CDbInfo::setEntity(CEntityFlags::Entity entity)
|
||||
@@ -161,7 +154,13 @@ namespace BlackMisc
|
||||
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;
|
||||
switch (entity)
|
||||
@@ -178,5 +177,23 @@ namespace BlackMisc
|
||||
}
|
||||
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
|
||||
|
||||
@@ -59,6 +59,9 @@ namespace BlackMisc
|
||||
//! The shared file name such as "airports.json"
|
||||
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
|
||||
void setEntity(Network::CEntityFlags::Entity entity);
|
||||
|
||||
@@ -89,8 +92,14 @@ namespace BlackMisc
|
||||
//! The shared file names
|
||||
static const QStringList &sharedFileNames();
|
||||
|
||||
//! Service names
|
||||
static const QStringList &serviceNames();
|
||||
|
||||
//! 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:
|
||||
QString m_tableName; //!< table name
|
||||
|
||||
@@ -155,6 +155,18 @@ namespace BlackMisc
|
||||
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()
|
||||
{
|
||||
// this is no value class and I register enums here,
|
||||
|
||||
@@ -96,7 +96,10 @@ namespace BlackMisc
|
||||
static bool anySwiftDbEntity(Entity entities);
|
||||
|
||||
//! 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
|
||||
static void registerMetadata();
|
||||
|
||||
@@ -124,6 +124,11 @@ namespace BlackMisc
|
||||
setQUrl(QUrl(fullUrl));
|
||||
}
|
||||
|
||||
QString CUrl::getFileName() const
|
||||
{
|
||||
return toQUrl().fileName();
|
||||
}
|
||||
|
||||
QUrl CUrl::toQUrl() const
|
||||
{
|
||||
return QUrl(getFullUrl());
|
||||
|
||||
@@ -115,6 +115,9 @@ namespace BlackMisc
|
||||
//! Set full URL
|
||||
void setFullUrl(const QString &fullUrl);
|
||||
|
||||
//! File name
|
||||
QString getFileName() const;
|
||||
|
||||
//! To QUrl
|
||||
QUrl toQUrl() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user