Skip to content

Commit

Permalink
Use QVersionNumber for our own version
Browse files Browse the repository at this point in the history
  • Loading branch information
TheOneRing committed Nov 3, 2021
1 parent 8b74337 commit 3ea52cc
Show file tree
Hide file tree
Showing 18 changed files with 76 additions and 91 deletions.
18 changes: 9 additions & 9 deletions src/common/syncjournaldb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,10 @@ bool SyncJournalDb::checkConnect()
forceRemoteDiscovery = true;

createQuery.prepare("INSERT INTO version VALUES (?1, ?2, ?3, ?4);");
createQuery.bindValue(1, OCC::Version::major());
createQuery.bindValue(2, OCC::Version::minor());
createQuery.bindValue(3, OCC::Version::patch());
createQuery.bindValue(4, OCC::Version::buildNumber());
const auto segments = OCC::Version::versionWithBuildNumber().segments();
for (int i = 0; i < segments.size(); ++i) {
createQuery.bindValue(i + 1, segments[i]);
}
if (!createQuery.exec()) {
return sqlFail(QStringLiteral("Update version"), createQuery);
}
Expand All @@ -544,13 +544,13 @@ bool SyncJournalDb::checkConnect()
}

// Not comparing the BUILD id here, correct?
if (!(major == OCC::Version::major() && minor == OCC::Version::minor() && patch == OCC::Version::patch())) {
if (QVersionNumber(major, minor, patch) != OCC::Version::version()) {
createQuery.prepare("UPDATE version SET major=?1, minor=?2, patch =?3, custom=?4 "
"WHERE major=?5 AND minor=?6 AND patch=?7;");
createQuery.bindValue(1, OCC::Version::major());
createQuery.bindValue(2, OCC::Version::minor());
createQuery.bindValue(3, OCC::Version::patch());
createQuery.bindValue(4, OCC::Version::buildNumber());
const auto segments = OCC::Version::versionWithBuildNumber().segments();
for (int i = 0; i < segments.size(); ++i) {
createQuery.bindValue(i + 1, segments[i]);
}
createQuery.bindValue(5, major);
createQuery.bindValue(6, minor);
createQuery.bindValue(7, patch);
Expand Down
2 changes: 1 addition & 1 deletion src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ QByteArray Utility::userAgentString()
{
return QStringLiteral("Mozilla/5.0 (%1) mirall/%2 (%3, %4-%5 ClientArchitecture: %6 OsArchitecture: %7)")
.arg(platform(),
OCC::Version::string(),
OCC::Version::displayString(),
// accessing the theme to fetch the string is rather difficult
// since this is only needed server-side to identify clients, the app name (as of 2.9, the short name) is good enough
qApp->applicationName(),
Expand Down
28 changes: 6 additions & 22 deletions src/common/version.cpp.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,16 @@

#include "common/version.h"

QString OCC::Version::string()
const QVersionNumber &OCC::Version::version()
{
return QStringLiteral("@MIRALL_VERSION_STRING@");
static const auto v = QVersionNumber({ @MIRALL_VERSION_MAJOR@, @MIRALL_VERSION_MINOR@, @MIRALL_VERSION_PATCH@ });
return v;
}

int OCC::Version::major()
const QVersionNumber &OCC::Version::versionWithBuildNumber()
{
return @MIRALL_VERSION_MAJOR@;
}

int OCC::Version::minor()
{
return @MIRALL_VERSION_MINOR@;
}

int OCC::Version::patch()
{
return @MIRALL_VERSION_PATCH@;
}

int OCC::Version::buildNumber()
{
return @MIRALL_VERSION_BUILD@;
static const auto v = QVersionNumber({ @MIRALL_VERSION_MAJOR@, @MIRALL_VERSION_MINOR@, @MIRALL_VERSION_PATCH@, @MIRALL_VERSION_BUILD@ });
return v;
}

QString OCC::Version::gitSha()
Expand All @@ -52,6 +39,3 @@ QString OCC::Version::suffix()
{
return QStringLiteral("@MIRALL_VERSION_SUFFIX@");
}



36 changes: 20 additions & 16 deletions src/common/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,31 @@
#include "ocsynclib.h"

#include <QString>
#include <QVersionNumber>

namespace OCC {
namespace Version {
/**
* "Major.Minor.Patch"
*/
QString OCSYNC_EXPORT string();
int OCSYNC_EXPORT major();
int OCSYNC_EXPORT minor();
int OCSYNC_EXPORT patch();
int OCSYNC_EXPORT buildNumber();

/**
namespace OCC::Version {
OCSYNC_EXPORT const QVersionNumber &version();

OCSYNC_EXPORT const QVersionNumber &versionWithBuildNumber();

inline int buildNumber()
{
return versionWithBuildNumber().segmentAt(3);
}

/**
* git, rc1, rc2
* Empty in releases
*/
QString OCSYNC_EXPORT suffix();
/**
OCSYNC_EXPORT QString suffix();

/**
* The commit id
*/
QString OCSYNC_EXPORT gitSha();
}
OCSYNC_EXPORT QString gitSha();

inline auto displayString()
{
return QStringLiteral("%1-%2").arg(versionWithBuildNumber().toString(), suffix());
}
}
2 changes: 1 addition & 1 deletion src/common/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ bool OCC::isVfsPluginAvailable(Vfs::Mode mode)
qCWarning(lcPlugin) << "Plugin has wrong type" << loader.fileName() << metadata[QStringLiteral("type")];
return false;
}
if (metadata[QStringLiteral("version")].toString() != OCC::Version::string()) {
if (metadata[QStringLiteral("version")].toString() != OCC::Version::version().toString()) {
qCWarning(lcPlugin) << "Plugin has wrong version" << loader.fileName() << metadata[QStringLiteral("version")];
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <QObject>
#include <QScopedPointer>
#include <QSharedPointer>
#include <QVersionNumber>

#include <memory>

Expand Down Expand Up @@ -62,7 +63,7 @@ struct OCSYNC_EXPORT VfsSetupParams
/// Strings potentially passed on to the platform
QString providerDisplayName;
QString providerName;
QString providerVersion;
QVersionNumber providerVersion;

/** when registering with the system we might use
* a different presentaton to identify the accounts
Expand Down
2 changes: 1 addition & 1 deletion src/common/vfspluginmetadata.json.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"type": "vfs",
"version": "@MIRALL_VERSION_STRING@"
"version": "@MIRALL_VERSION@"
}
6 changes: 3 additions & 3 deletions src/csync/csync_exclude.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const QStringRef &path, bool ex
using namespace OCC;

ExcludedFiles::ExcludedFiles()
: _clientVersion(OCC::Version::major(), OCC::Version::minor(), OCC::Version::patch())
: _clientVersion(OCC::Version::version())
{
// Windows used to use PathMatchSpec which allows *foo to match abc/deffoo.
_wildcardsMatchSlash = Utility::isWindows();
Expand Down Expand Up @@ -277,7 +277,7 @@ void ExcludedFiles::setWildcardsMatchSlash(bool onoff)
prepare();
}

void ExcludedFiles::setClientVersion(ExcludedFiles::Version version)
void ExcludedFiles::setClientVersion(QVersionNumber version)
{
_clientVersion = version;
}
Expand Down Expand Up @@ -321,7 +321,7 @@ bool ExcludedFiles::versionDirectiveKeepNextLine(const QByteArray &directive) co
if (argVersions.size() != 3)
return true;

auto argVersion = std::make_tuple(argVersions[0].toInt(), argVersions[1].toInt(), argVersions[2].toInt());
const auto argVersion = QVersionNumber(argVersions[0].toInt(), argVersions[1].toInt(), argVersions[2].toInt());
if (op == "<=")
return _clientVersion <= argVersion;
if (op == "<")
Expand Down
9 changes: 4 additions & 5 deletions src/csync/csync_exclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
#include "csync.h"

#include <QObject>
#include <QRegularExpression>
#include <QSet>
#include <QString>
#include <QRegularExpression>
#include <QVersionNumber>

#include <functional>

Expand Down Expand Up @@ -65,8 +66,6 @@ class OCSYNC_EXPORT ExcludedFiles : public QObject
{
Q_OBJECT
public:
typedef std::tuple<int, int, int> Version;

ExcludedFiles();
~ExcludedFiles() override;

Expand Down Expand Up @@ -127,7 +126,7 @@ class OCSYNC_EXPORT ExcludedFiles : public QObject
/**
* Sets the client version, only used for testing.
*/
void setClientVersion(Version version);
void setClientVersion(QVersionNumber version);

/**
* @brief Check if the given path should be excluded in a traversal situation.
Expand Down Expand Up @@ -245,7 +244,7 @@ public slots:
* The client version. Used to evaluate version-dependent excludes,
* see versionDirectiveKeepNextLine().
*/
Version _clientVersion;
QVersionNumber _clientVersion;

friend class TestExcludedFiles;
};
Expand Down
6 changes: 3 additions & 3 deletions src/gui/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ bool Application::configVersionMigration()

// Did the client version change?
// (The client version is adjusted further down)
bool versionChanged = configFile.clientVersionString() != OCC::Version::string();
const bool versionChanged = QVersionNumber::fromString(configFile.clientVersionString()) != OCC::Version::version();

// We want to message the user either for destructive changes,
// or if we're ignoring something and the client version changed.
Expand Down Expand Up @@ -196,7 +196,7 @@ bool Application::configVersionMigration()
settings->remove(badKey);
}

configFile.setClientVersionString(OCC::Version::string());
configFile.setClientVersionString(OCC::Version::version().toString());
return true;
}

Expand Down Expand Up @@ -567,7 +567,7 @@ void Application::parseOptions(const QStringList &arguments)
QString descriptionText;
QTextStream descriptionTextStream(&descriptionText);

descriptionTextStream << tr("%1 version %2\r\nFile synchronization desktop utility.").arg(_theme->appName(), _theme->version()) << endl;
descriptionTextStream << tr("%1 version %2\r\nFile synchronization desktop utility.").arg(_theme->appName(), OCC::Version::displayString()) << endl;

if (_theme->appName() == QLatin1String("ownCloud")) {
descriptionTextStream << endl
Expand Down
25 changes: 13 additions & 12 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,25 @@
#include "accountmanager.h"
#include "accountstate.h"
#include "application.h"
#include "clientproxy.h"
#include "common/syncjournalfilerecord.h"
#include "common/version.h"
#include "common/vfs.h"
#include "configfile.h"
#include "creds/abstractcredentials.h"
#include "csync_exclude.h"
#include "filesystem.h"
#include "folder.h"
#include "folderman.h"
#include "localdiscoverytracker.h"
#include "logger.h"
#include "configfile.h"
#include "networkjobs.h"
#include "common/syncjournalfilerecord.h"
#include "syncresult.h"
#include "clientproxy.h"
#include "settingsdialog.h"
#include "socketapi/socketapi.h"
#include "syncengine.h"
#include "syncresult.h"
#include "syncrunfilelog.h"
#include "socketapi/socketapi.h"
#include "theme.h"
#include "filesystem.h"
#include "localdiscoverytracker.h"
#include "csync_exclude.h"
#include "common/vfs.h"
#include "creds/abstractcredentials.h"
#include "settingsdialog.h"

#include <QTimer>
#include <QUrl>
Expand Down Expand Up @@ -534,7 +535,7 @@ void Folder::startVfs()
vfsParams.journal = &_journal;
vfsParams.providerDisplayName = Theme::instance()->appNameGUI();
vfsParams.providerName = Theme::instance()->appName();
vfsParams.providerVersion = Theme::instance()->version();
vfsParams.providerVersion = Version::version();
vfsParams.multipleAccountsRegistered = AccountManager::instance()->accounts().size() > 1;

connect(_vfs.data(), &Vfs::beginHydrating, this, &Folder::slotHydrationStarts);
Expand Down
2 changes: 1 addition & 1 deletion src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ void SocketApi::command_MANAGE_PUBLIC_LINKS(const QString &localFile, SocketList

void SocketApi::command_VERSION(const QString &, SocketListener *listener)
{
listener->sendMessage(QStringLiteral("VERSION:%1:%2").arg(OCC::Version::string(), QStringLiteral(MIRALL_SOCKET_API_VERSION)));
listener->sendMessage(QStringLiteral("VERSION:%1:%2").arg(OCC::Version::versionWithBuildNumber().toString(), QStringLiteral(MIRALL_SOCKET_API_VERSION)));
}

void SocketApi::command_SHARE_MENU_TITLE(const QString &, SocketListener *listener)
Expand Down
7 changes: 4 additions & 3 deletions src/gui/updater/updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,9 @@ qint64 Updater::Helper::versionToInt(qint64 major, qint64 minor, qint64 patch, q

qint64 Updater::Helper::currentVersionToInt()
{
return versionToInt(OCC::Version::major(), OCC::Version::minor(),
OCC::Version::patch(), OCC::Version::buildNumber());
// TODO: directly use QVersionNumber
return versionToInt(OCC::Version::version().majorVersion(), OCC::Version::version().minorVersion(),
OCC::Version::version().microVersion(), OCC::Version::buildNumber());
}

qint64 Updater::Helper::stringVersionToInt(const QString &version)
Expand All @@ -164,7 +165,7 @@ qint64 Updater::Helper::stringVersionToInt(const QString &version)

QString Updater::clientVersion()
{
return QStringLiteral("%1.%2.%3.%4").arg(QString::number(Version::major()), QString::number(Version::minor()), QString::number(Version::patch()), QString::number(Version::buildNumber()));
return Version::versionWithBuildNumber().toString();
}

} // namespace OCC
3 changes: 2 additions & 1 deletion src/libsync/creds/oauth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "creds/oauth.h"

#include "account.h"
#include "common/version.h"
#include "credentialmanager.h"
#include "creds/httpcredentials.h"
#include "networkjobs.h"
Expand Down Expand Up @@ -112,7 +113,7 @@ class RegisterClientJob : public QObject
Q_EMIT errorOccured(error.errorString());
}
});
const QJsonObject json({ { QStringLiteral("client_name"), QStringLiteral("%1 %2").arg(Theme::instance()->appNameGUI(), Theme::instance()->version()) },
const QJsonObject json({ { QStringLiteral("client_name"), QStringLiteral("%1 %2").arg(Theme::instance()->appNameGUI(), OCC::Version::versionWithBuildNumber().toString()) },
{ QStringLiteral("redirect_uris"), QJsonArray { QStringLiteral("http://127.0.0.1") } },
{ QStringLiteral("application_type"), QStringLiteral("native") },
{ QStringLiteral("token_endpoint_auth_method"), QStringLiteral("client_secret_basic") } });
Expand Down
13 changes: 4 additions & 9 deletions src/libsync/theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ QString Theme::appName() const
return QStringLiteral(APPLICATION_SHORTNAME);
}

QString Theme::version() const
{
return OCC::Version::string();
}

QString Theme::configFileName() const
{
return QStringLiteral(APPLICATION_EXECUTABLE ".cfg");
Expand Down Expand Up @@ -301,7 +296,7 @@ QString Theme::defaultServerFolder() const

QString Theme::helpUrl() const
{
return QStringLiteral("https://doc.owncloud.org/desktop/%1.%2/").arg(OCC::Version::major()).arg(OCC::Version::minor());
return QStringLiteral("https://doc.owncloud.org/desktop/%1.%2/").arg(OCC::Version::version().majorVersion()).arg(OCC::Version::version().microVersion());
}

QString Theme::conflictHelpUrl() const
Expand Down Expand Up @@ -425,11 +420,11 @@ QString Theme::aboutVersions(Theme::VersionFormat format) const
}();
const QString qtVersion = QString::fromUtf8(qVersion());
const QString qtVersionString = (QLatin1String(QT_VERSION_STR) == qtVersion ? qtVersion : QCoreApplication::translate("ownCloudTheme::qtVer", "%1 (Built against Qt %1)").arg(qtVersion, QStringLiteral(QT_VERSION_STR)));
QString _version = version();
QString _version = Version::displayString();
QString gitUrl;
#ifdef GIT_SHA1
if (format != Theme::VersionFormat::Url) {
_version = QCoreApplication::translate("ownCloudTheme::versionWithSha", "%1 %2").arg(version(), gitSHA1(format));
_version = QCoreApplication::translate("ownCloudTheme::versionWithSha", "%1 %2").arg(_version, gitSHA1(format));
} else {
gitUrl = gitSHA1(format) + br;
}
Expand Down Expand Up @@ -466,7 +461,7 @@ QString Theme::about() const
"%5 and the %5 logo are registered trademarks of %4 in the "
"United States, other countries, or both.</p>"
"<p><small>%6</small></p>")
.arg(Utility::escape(version()),
.arg(Utility::escape(Version::displayString()),
Utility::escape(QStringLiteral("https://" APPLICATION_DOMAIN)),
Utility::escape(QStringLiteral(APPLICATION_DOMAIN)),
Utility::escape(vendor),
Expand Down
Loading

0 comments on commit 3ea52cc

Please sign in to comment.