6#include <QRegularExpression>
7#include <QStringBuilder>
12using namespace swift::config;
13using namespace swift::misc::network;
17namespace swift::misc::db
20 int size,
bool existing,
const CPlatform &platform)
21 : m_name(name.trimmed()), m_md5(md5), m_type(static_cast<int>(type)), m_size(size), m_existing(existing),
27 m_version = versionNumberFromFilename(name);
57 if (distribution.
isEmpty() || !this->hasDistributions())
63 return dist == distribution || (acceptMoreStableDistributions && dist.
isStabilityBetter(distribution));
125 case IndexPlatform:
return m_platform.propertyByIndex(index.
copyFrontRemoved());
153 case IndexMd5: m_md5 = variant.
toString();
break;
154 case IndexPlatform: m_platform.setPropertyByIndex(index.
copyFrontRemoved(), variant);
break;
155 case IndexType: m_type = variant.
toInt();
break;
156 case IndexSize: m_size = variant.
toInt();
break;
167 const QString name = json.value(
"name").toString();
168 const QString md5 = json.value(
"md5").toString();
169 const QString version = json.value(
"version").toString();
172 const int size = json.value(
"size").toInt(-1);
173 const bool existing = json.value(
"existing").toBool();
175 CArtifact artifact(name, version, md5, type, size, existing, platform);
177 if (json.contains(
"distributions"))
192 static const QString xswb(
"xswiftbus");
193 static const QString installer(
"pilot client installer");
194 static const QString symbols(
"symbols");
195 static const QString unknown(
"unknown");
200 case PilotClientInstaller:
return installer;
201 case Symbols:
return symbols;
202 case UnknownArtifact:
244 QString CArtifact::versionNumberFromFilename(
const QString &filename)
260 if (s.contains(
"installer"))
return CArtifact::PilotClientInstaller;
261 if (s.contains(
"client"))
return CArtifact::PilotClientInstaller;
262 if (s.contains(
"symb"))
return CArtifact::Symbols;
263 if (s.contains(
"bus"))
return CArtifact::XSwiftBus;
264 return CArtifact::UnknownArtifact;
267 QString CArtifact::trimVersionString(
const QString &version)
269 if (version.
count(
'.') != 3)
return version;
270 QStringList parts = version.
split(
'.');
271 const QString p4 = trim4thSegment(parts[3]);
277 const QString v = parts.
join(
'.');
281 QString CArtifact::trim4thSegment(
const QString &seg)
286 return QStringLiteral(
"0");
static const QVersionNumber & getVersion()
Version as QVersionNumber.
static QString humanReadableFileSize(qint64 size)
Human readable (GB, MB, ..) file size.
Non-owning reference to a CPropertyIndex with a subset of its features.
Q_REQUIRED_RESULT CPropertyIndexRef copyFrontRemoved() const
Copy with first element removed.
CastType frontCasted() const
First element casted to given type, usually the PropertIndex enum.
bool isMyself() const
Myself index, used with nesting.
QString getFormattedUtcTimestampYmdhms() const
As yyyy MM dd HH mm ss.
QDateTime getUtcTimestamp() const
Get timestamp.
void setUtcTimestamp(const QDateTime ×tamp)
Set timestamp.
ColumnIndex
Properties by index.
bool hasUnrestrictedDistribution() const
Has unrestricted distribution.
bool isWithDistribution(const CDistribution &distribution, bool acceptMoreStableDistributions) const
Is distributed with given distribution?
bool hasDistributions() const
Has distributions?
void setName(const QString &name)
Set the name.
bool matchesAnyPlatform(const CPlatform &platform) const
Matches any platform.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QString getFileSizeHumanReadable() const
Human readable (GB, MB, ..) file size.
network::CRemoteFile asRemoteFile() const
Turn into remote file.
const CPlatform & getPlatform() const
OS.
const QString & getName() const
Name (i.e. installer name, symbol name).
bool isUnknown() const
Unknown.
int getFileSize() const
File size.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
CArtifact()=default
Default constructor.
static CPlatform artifactNameToPlatform(const QString &name)
Name to platform.
bool isNewerThanCurrentBuild() const
Newer than the current build.
void setDistributions(const CDistributionList &distributions)
Related distributions.
const CDistributionList & getDistributions() const
Related distributions.
static const QString & typeToString(ArtifactType type)
Type as string.
static CArtifact fromDatabaseJson(const QJsonObject &json, const QString &prefix={})
Object from database JSON format.
bool matchesName(const QString &name, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Matching name?
CDistribution getMostStableDistribution() const
Most stable distribution if any.
QString convertToQString(bool i18n=false) const
Cast as QString.
Distributions for channel.
bool isStabilityBetter(const CDistribution &otherDistribution) const
"this" having better stability than other distribution?
const QString & getChannel() const
Version channel (Alpha, Beta, Stable ..).
const network::CUrl & getDownloadUrl() const
Download URL, i.e. here one can download installer.
bool isEmpty() const
Empty?
Multiple distributions for different channels:
static CDistributionList fromDatabaseJson(const QJsonArray &array)
From database JSON by array.
QVersionNumber getQVersion() const
Version as QVersion.
QString m_version
version info
bool hasVersion() const
Having a version?s.
void setVersion(const QString &version)
Version info.
QVariant propertyByIndex(swift::misc::CPropertyIndexRef index) const
Property by index.
static bool canHandleIndex(swift::misc::CPropertyIndexRef index)
Can given index be handled?
void setKeyVersionTimestampFromDatabaseJson(const QJsonObject &json, const QString &prefix=QString())
Set key and timestamp values.
void setPropertyByIndex(swift::misc::CPropertyIndexRef index, const QVariant &variant)
Set property by index.
void setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
Set property by index.
QVariant propertyByIndex(CPropertyIndexRef index) const
Property by index.
QString toQString(bool i18n=false) const
void setDescription(const QString &description)
Description.
void setUrl(const CUrl &url)
Set URL.
Value object encapsulating information of a location, kind of simplified CValueObject compliant versi...
bool isEmpty() const
Empty.
Plugin loaded by X-Plane which publishes a DBus service.
SWIFT_MISC_EXPORT bool caseInsensitiveStringCompare(const QString &c1, const QString &c2)
Case insensitive string compare.
bool contains(QLatin1StringView key) const const
bool isEmpty() const const
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
QJsonObject toObject() const const
QRegularExpressionMatch match(QStringView subjectView, qsizetype offset, QRegularExpression::MatchType matchType, QRegularExpression::MatchOptions matchOptions) const const
QString captured(QAnyStringView name) const const
qsizetype count() const const
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
bool endsWith(QChar c, Qt::CaseSensitivity cs) const const
bool isEmpty() const const
qsizetype length() const const
QStringList split(QChar sep, Qt::SplitBehavior behavior, Qt::CaseSensitivity cs) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QString toLower() const const
QString trimmed() const const
QString join(QChar separator) const const
QVariant fromValue(T &&value)
int toInt(bool *ok) const const
QString toString() const const
#define SWIFT_DEFINE_VALUEOBJECT_MIXINS(Namespace, Class)
Explicit template definition of mixins for a CValueObject subclass.