AusweisApp2/src/global/VersionNumber.cpp

96 lines
1.9 KiB
C++
Raw Normal View History

2017-07-03 09:30:10 +02:00
/*
2017-12-20 14:54:05 +01:00
* \copyright Copyright (c) 2016-2017 Governikus GmbH & Co. KG, Germany
2017-07-03 09:30:10 +02:00
*/
#include "VersionNumber.h"
#include <QCoreApplication>
#include <QGlobalStatic>
using namespace governikus;
Q_GLOBAL_STATIC_WITH_ARGS(VersionNumber, AppVersionNumber, (QCoreApplication::applicationVersion()))
VersionNumber::VersionNumber(const QString& pVersion)
2017-09-15 10:23:30 +02:00
: mVersionNumber()
, mSuffix()
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
int idx = 0;
2017-09-15 10:23:30 +02:00
mVersionNumber = QVersionNumber::fromString(pVersion, &idx);
2017-12-20 14:54:05 +01:00
#ifdef Q_CC_GNU
__sync_synchronize(); // a gcc bug: https://bugs.alpinelinux.org/issues/7584
#endif
2017-09-15 10:23:30 +02:00
mSuffix = pVersion.mid(idx).trimmed();
2017-07-03 09:30:10 +02:00
}
2017-12-20 14:54:05 +01:00
const VersionNumber& VersionNumber::getApplicationVersion()
{
return *AppVersionNumber;
}
2017-07-03 09:30:10 +02:00
const QVersionNumber& VersionNumber::getVersionNumber() const
{
return mVersionNumber;
}
bool VersionNumber::isDeveloperVersion() const
{
2017-09-15 10:23:30 +02:00
return mVersionNumber.isNull() || (mVersionNumber.minorVersion() & 1) || !mSuffix.isEmpty();
2017-07-03 09:30:10 +02:00
}
int VersionNumber::getDistance() const
{
2017-12-20 14:54:05 +01:00
const int indexStart = mSuffix.indexOf(QLatin1Char('+')) + 1;
const int indexEnd = mSuffix.indexOf(QLatin1Char('-'), indexStart);
2017-07-03 09:30:10 +02:00
if (indexStart && indexEnd)
{
bool ok;
int value = mSuffix.mid(indexStart, indexEnd - indexStart).toInt(&ok);
if (ok)
{
return value;
}
}
return -1;
}
QString VersionNumber::getBranch() const
{
2017-12-20 14:54:05 +01:00
const int indexStart = mSuffix.indexOf(QLatin1Char('-')) + 1;
const int indexEnd = mSuffix.indexOf(QLatin1Char('-'), indexStart);
2017-07-03 09:30:10 +02:00
if (indexStart && indexEnd)
{
return mSuffix.mid(indexStart, indexEnd - indexStart);
}
return QString();
}
QString VersionNumber::getRevision() const
{
2017-12-20 14:54:05 +01:00
if (mSuffix.count(QLatin1Char('-')) > 1)
2017-07-03 09:30:10 +02:00
{
2017-12-20 14:54:05 +01:00
const int index = mSuffix.lastIndexOf(QLatin1Char('-')) + 1;
2017-07-03 09:30:10 +02:00
if (index)
{
return mSuffix.mid(index);
}
}
return QString();
}
bool VersionNumber::isDraft() const
{
return mSuffix.contains(QStringLiteral("-draft")) || mSuffix.contains(QStringLiteral("-secret"));
}