|
8 | 8 |
|
9 | 9 | Q_LOGGING_CATEGORY(kLogger, "controllers.mappinginfo") |
10 | 10 |
|
| 11 | +namespace { |
| 12 | +// Sanitize a string to a version number, often extracted from the XML property, |
| 13 | +// which aims to contain a Mixxx version, from which a given mapping is |
| 14 | +// supported. In the current official mapping included in the code base, we have |
| 15 | +// a variety of format such as "1.0.0" (correct semver), "2.4" (partial semver), |
| 16 | +// "1.7.0+", "1.10.0-beta1+" or "" (invalid semver) |
| 17 | +QVersionNumber sanitizeVersion(QString rawVersion) { |
| 18 | + return !rawVersion.isEmpty() |
| 19 | + ? QVersionNumber::fromString(rawVersion.remove(QChar('+'))) |
| 20 | + : QVersionNumber(); |
| 21 | +} |
| 22 | +} // namespace |
| 23 | + |
| 24 | +bool operator==(const ProductInfo& a, const ProductInfo& b) { |
| 25 | + return a.protocol == b.protocol && |
| 26 | + a.vendor_id == b.vendor_id && |
| 27 | + a.product_id == b.product_id && |
| 28 | + a.interface_number == b.interface_number && |
| 29 | + a.usage_page == b.usage_page && |
| 30 | + a.usage == b.usage && |
| 31 | + a.in_epaddr == b.in_epaddr && |
| 32 | + a.out_epaddr == b.out_epaddr; |
| 33 | +} |
| 34 | + |
| 35 | +size_t qHash(const ProductInfo& product) { |
| 36 | + return qHash(product.protocol) + |
| 37 | + qHash(product.vendor_id) + |
| 38 | + qHash(product.product_id) + |
| 39 | + qHash(product.interface_number) + |
| 40 | + qHash(product.usage_page) + |
| 41 | + qHash(product.usage) + |
| 42 | + qHash(product.in_epaddr) + |
| 43 | + qHash(product.out_epaddr); |
| 44 | +} |
| 45 | + |
| 46 | +QDebug operator<<(QDebug dbg, const ProductInfo& product) { |
| 47 | + dbg << QStringLiteral( |
| 48 | + "ProductInfo<protocol=%1, friendlyName=%2, vendor_id=%3, " |
| 49 | + "product_id=%4, interface_number=%5>") |
| 50 | + .arg(product.protocol, |
| 51 | + product.friendlyName, |
| 52 | + product.vendor_id, |
| 53 | + product.product_id, |
| 54 | + product.interface_number); |
| 55 | + return dbg; |
| 56 | +} |
| 57 | + |
11 | 58 | MappingInfo::MappingInfo(const QFileInfo& fileInfo) { |
12 | 59 | // Parse only the <info> header section from a controller description XML file |
13 | 60 | // using a streaming parser to avoid loading/parsing the entire (potentially |
14 | 61 | // very large) XML file. |
15 | 62 | // Contents parsed by xml path: |
16 | | - // info.name Mapping name, used for drop down menus in dialogs |
17 | | - // info.author Mapping author |
18 | | - // info.description Mapping description |
19 | | - // info.forums Link to mixxx forum discussion for the mapping |
20 | | - // info.wiki Link to mixxx wiki for the mapping |
21 | | - // info.devices.product List of device matches, specific to device type |
| 63 | + // MixxxControllerPreset The minimum supported Mixxx version |
| 64 | + // info.name Mapping name, used for drop down menus in dialogs |
| 65 | + // info.author Mapping author |
| 66 | + // info.description Mapping description |
| 67 | + // info.forums Link to mixxx forum discussion for the mapping |
| 68 | + // info.wiki Link to mixxx wiki for the mapping |
| 69 | + // info.devices.product List of device matches, specific to device type |
22 | 70 | m_path = fileInfo.absoluteFilePath(); |
23 | 71 | m_dirPath = fileInfo.dir().absolutePath(); |
24 | 72 |
|
@@ -94,6 +142,16 @@ MappingInfo::MappingInfo(const QFileInfo& fileInfo) { |
94 | 142 | } |
95 | 143 | } |
96 | 144 |
|
| 145 | + if (xmlElementName == QStringLiteral("MixxxControllerPreset") && |
| 146 | + xmlHierachyDepth == 1) { |
| 147 | + QXmlStreamAttributes xmlElementAttributes = xml.attributes(); |
| 148 | + auto mixxxVersion = |
| 149 | + xmlElementAttributes |
| 150 | + .value(QStringLiteral("mixxxVersion")) |
| 151 | + .toString(); |
| 152 | + m_mixxxVersion = sanitizeVersion(mixxxVersion); |
| 153 | + } |
| 154 | + |
97 | 155 | } else if (token == QXmlStreamReader::EndElement) { |
98 | 156 | const QString name = xml.name().toString(); |
99 | 157 |
|
@@ -145,6 +203,9 @@ ProductInfo MappingInfo::parseBulkProduct(const QXmlStreamAttributes& xmlElement |
145 | 203 | productInfo.interface_number = |
146 | 204 | xmlElementAttributes.value(QStringLiteral("interface_number")) |
147 | 205 | .toString(); |
| 206 | + productInfo.friendlyName = xmlElementAttributes.value("friendly_name").toString(); |
| 207 | + |
| 208 | + productInfo.visualUrl = QUrl(xmlElementAttributes.value("image").toString()); |
148 | 209 | return productInfo; |
149 | 210 | } |
150 | 211 |
|
|
0 commit comments