diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/library/traktor/traktorfeature.cpp | 29 | ||||
-rw-r--r-- | src/util/semanticversion.cpp | 37 | ||||
-rw-r--r-- | src/util/semanticversion.h | 38 |
4 files changed, 83 insertions, 22 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a0d4ad0fb..9f310304e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -815,6 +815,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL src/util/sample.cpp src/util/samplebuffer.cpp src/util/sandbox.cpp + src/util/semanticversion.cpp src/util/screensaver.cpp src/util/sleepableqthread.cpp src/util/stat.cpp diff --git a/src/library/traktor/traktorfeature.cpp b/src/library/traktor/traktorfeature.cpp index 9ab5e2afe7..2b89e6eac4 100644 --- a/src/library/traktor/traktorfeature.cpp +++ b/src/library/traktor/traktorfeature.cpp @@ -8,7 +8,6 @@ #include <QStandardPaths> #include <QXmlStreamReader> #include <QtDebug> -#include <tuple> #include "library/library.h" #include "library/librarytablemodel.h" @@ -19,6 +18,7 @@ #include "library/treeitem.h" #include "moc_traktorfeature.cpp" #include "util/sandbox.h" +#include "util/semanticversion.h" namespace { @@ -27,16 +27,6 @@ QString fromTraktorSeparators(QString path) { return path.replace("/:", "/"); } -struct SemanticVersion { - uint major{0}, - minor{0}, - patch{0}; -}; - -bool operator<(const SemanticVersion& a, const SemanticVersion& b) { - return std::tie(a.major, a.minor, a.patch) < std::tie(b.major, b.minor, b.patch); -} - } // anonymous namespace @@ -584,7 +574,7 @@ QString TraktorFeature::getTraktorMusicDatabase() { //Iterate over the subfolders QFileInfoList list = ni_directory.entryInfoList(); - QMap<SemanticVersion, QString> installed_ts_map; + QMap<mixxx::SemanticVersion, QString> installed_ts_map; for (int i = 0; i < list.size(); ++i) { QFileInfo fileInfo = list.at(i); @@ -592,19 +582,14 @@ QString TraktorFeature::getTraktorMusicDatabase() { if (folder_name == "Traktor") { //We found a Traktor 1 installation - installed_ts_map.insert({1, 0, 0}, fileInfo.absoluteFilePath()); + installed_ts_map.insert(mixxx::SemanticVersion(1, 0, 0), fileInfo.absoluteFilePath()); continue; } if (folder_name.contains("Traktor")) { qDebug() << "Found " << folder_name; - QRegularExpression re("(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)"); - QRegularExpressionMatch match = re.match(folder_name); - if (match.hasMatch()) { - const auto version = SemanticVersion{ - match.captured("major").toUInt(), - match.captured("minor").toUInt(), - match.captured("patch").toUInt()}; - installed_ts_map.insert(version, fileInfo.absoluteFilePath()); + auto semver = mixxx::SemanticVersion(folder_name); + if (semver.isValid()) { + installed_ts_map.insert(semver, fileInfo.absoluteFilePath()); } } } @@ -612,7 +597,7 @@ QString TraktorFeature::getTraktorMusicDatabase() { if (installed_ts_map.isEmpty()) { musicFolder = QDir::homePath() + "/collection.nml"; } else { //Select the folder with the highest version as default Traktor folder - QList<SemanticVersion> versions = installed_ts_map.keys(); + QList<mixxx::SemanticVersion> versions = installed_ts_map.keys(); std::sort(versions.begin(), versions.end()); musicFolder = installed_ts_map.value(versions.last()) + "/collection.nml"; } diff --git a/src/util/semanticversion.cpp b/src/util/semanticversion.cpp new file mode 100644 index 0000000000..3e0053f18f --- /dev/null +++ b/src/util/semanticversion.cpp @@ -0,0 +1,37 @@ +#include "util/semanticversion.h" + +#include <QRegularExpression> + +namespace { + +QRegularExpression regex("(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<patch>\\d+)"); + +} // anonymous namespace + +namespace mixxx { + +SemanticVersion::SemanticVersion(unsigned int majorVersion, + unsigned int minorVersion, + unsigned int patchVersion) + : majorVersion(majorVersion), + minorVersion(minorVersion), + patchVersion(patchVersion) { +} + +SemanticVersion::SemanticVersion(const QString& versionString) + : majorVersion(0), + minorVersion(0), + patchVersion(0) { + QRegularExpressionMatch match = regex.match(versionString); + if (match.hasMatch()) { + majorVersion = match.captured(QStringLiteral("major")).toUInt(); + minorVersion = match.captured(QStringLiteral("minor")).toUInt(); + patchVersion = match.captured(QStringLiteral("patch")).toUInt(); + } +} + +bool SemanticVersion::isValid() const { + return !(majorVersion == 0 && minorVersion == 0 && patchVersion == 0); +} + +} // namespace mixxx diff --git a/src/util/semanticversion.h b/src/util/semanticversion.h new file mode 100644 index 0000000000..9ef99cf2d9 --- /dev/null +++ b/src/util/semanticversion.h @@ -0,0 +1,38 @@ +#pragma once + +#include <QString> +#include <tuple> + +namespace mixxx { + +// "major" and "minor" clash with symbols in glibc, so use more verbose variable names. +class SemanticVersion { + public: + SemanticVersion(unsigned int majorVersion, + unsigned int minorVersion, + unsigned int patchVersion); + SemanticVersion(const QString& versionString); + + bool isValid() const; + + unsigned int majorVersion, minorVersion, patchVersion; +}; + +inline bool operator<(const SemanticVersion& a, const SemanticVersion& b) { + return std::tie(a.majorVersion, a.minorVersion, a.patchVersion) < + std::tie(b.majorVersion, b.minorVersion, b.patchVersion); +} + +inline bool operator>(const SemanticVersion& a, const SemanticVersion& b) { + return b < a; +} + +inline bool operator<=(const SemanticVersion& a, const SemanticVersion& b) { + return !(a > b); +} + +inline bool operator>=(const SemanticVersion& a, const SemanticVersion& b) { + return !(a < b); +} + +} // namespace mixxx |