diff options
author | be_ <be.0@gmx.com> | 2015-07-18 17:36:44 -0500 |
---|---|---|
committer | be_ <be.0@gmx.com> | 2015-07-18 17:36:44 -0500 |
commit | bc99329b3f2cbb82eee132318fd4371007edfa8e (patch) | |
tree | 5854c267abefdf743a8b7d1979b8298d2882219a /src/controllers/controllerpresetinfo.cpp | |
parent | ca6b4e51ac8ff3dc3c8712d1cb9496929b981ec2 (diff) |
split controller PresetInfoEnumerator class into its own cpp/h files
also rename member variables of PresetInfo and PresetInfoEnumerator classes to use m_ prefix
Diffstat (limited to 'src/controllers/controllerpresetinfo.cpp')
-rw-r--r-- | src/controllers/controllerpresetinfo.cpp | 170 |
1 files changed, 21 insertions, 149 deletions
diff --git a/src/controllers/controllerpresetinfo.cpp b/src/controllers/controllerpresetinfo.cpp index 267094e85c..c8850f4d6e 100644 --- a/src/controllers/controllerpresetinfo.cpp +++ b/src/controllers/controllerpresetinfo.cpp @@ -4,14 +4,13 @@ * @date Wed May 15 2012 * @brief Implement handling enumeration and parsing of preset info headers * -* This class handles enumeration and parsing of controller XML description file +* This class handles parsing of controller XML description file * <info> header tags. It can be used to match controllers automatically or to * show details for a mapping. */ -#include <QDirIterator> - #include "controllers/controllerpresetinfo.h" +#include "controllers/controllerpresetinfoenumerator.h" #include "controllers/defs_controllers.h" #include "util/xml.h" @@ -30,40 +29,40 @@ PresetInfo::PresetInfo(const QString preset_path) // info.forums Link to mixxx forum discussion for the preset // info.wiki Link to mixxx wiki for the preset // info.devices.product List of device matches, specific to device type - path = QFileInfo(preset_path).absoluteFilePath(); - name = ""; - author = ""; - description = ""; - forumlink = ""; - wikilink = ""; - - QDomElement root = XmlParse::openXMLFile(path, "controller"); + m_path = QFileInfo(preset_path).absoluteFilePath(); + m_name = ""; + m_author = ""; + m_description = ""; + m_forumlink = ""; + m_wikilink = ""; + + QDomElement root = XmlParse::openXMLFile(m_path, "controller"); if (root.isNull()) { - qDebug() << "ERROR parsing" << path; + qDebug() << "ERROR parsing" << m_path; return; } QDomElement info = root.firstChildElement("info"); if (info.isNull()) { - qDebug() << "MISSING <info> ELEMENT: " << path; + qDebug() << "MISSING <info> ELEMENT: " << m_path; return; } m_valid = true; QDomElement dom_name = info.firstChildElement("name"); - if (!dom_name.isNull()) name = dom_name.text(); + if (!dom_name.isNull()) m_name = dom_name.text(); QDomElement dom_author = info.firstChildElement("author"); - if (!dom_author.isNull()) author = dom_author.text(); + if (!dom_author.isNull()) m_author = dom_author.text(); QDomElement dom_description = info.firstChildElement("description"); - if (!dom_description.isNull()) description = dom_description.text(); + if (!dom_description.isNull()) m_description = dom_description.text(); QDomElement dom_forums = info.firstChildElement("forums"); - if (!dom_forums.isNull()) forumlink = dom_forums.text(); + if (!dom_forums.isNull()) m_forumlink = dom_forums.text(); QDomElement dom_wiki = info.firstChildElement("wiki"); - if (!dom_wiki.isNull()) wikilink = dom_wiki.text(); + if (!dom_wiki.isNull()) m_wikilink = dom_wiki.text(); QDomElement devices = info.firstChildElement("devices"); if (!devices.isNull()) { @@ -71,15 +70,15 @@ PresetInfo::PresetInfo(const QString preset_path) while (!product.isNull()) { QString protocol = product.attribute("protocol",""); if (protocol=="hid") { - products.append(parseHIDProduct(product)); + m_products.append(parseHIDProduct(product)); } else if (protocol=="bulk") { - products.append(parseBulkProduct(product)); + m_products.append(parseBulkProduct(product)); } else if (protocol=="midi") { qDebug("MIDI product info parsing not yet implemented"); - //products.append(parseMIDIProduct(product); + //m_products.append(parseMIDIProduct(product); } else if (protocol=="osc") { qDebug("OSC product info parsing not yet implemented"); - //products.append(parseOSCProduct(product); + //m_products.append(parseOSCProduct(product); } else { qDebug("Product specification missing protocol attribute"); } @@ -133,130 +132,3 @@ QHash<QString,QString> PresetInfo::parseOSCProduct(const QDomElement& element) c product.insert("procotol",element.attribute("protocol","")); return product; } - -PresetInfoEnumerator::PresetInfoEnumerator(ConfigObject<ConfigValue>* pConfig) { - controllerDirPaths.append(userPresetsPath(pConfig)); - controllerDirPaths.append(resourcePresetsPath(pConfig)); - - // Static list of supported default extensions, sorted by popularity - fileExtensions.append(QString(MIDI_PRESET_EXTENSION)); - fileExtensions.append(QString(HID_PRESET_EXTENSION)); - fileExtensions.append(QString(BULK_PRESET_EXTENSION)); - - loadSupportedPresets(); -} - -PresetInfoEnumerator::~PresetInfoEnumerator() { - for (QMap<QString, ControllerPresetFileHandler*>::iterator it = - m_presetFileHandlersByExtension.begin(); - it != m_presetFileHandlersByExtension.end(); ++it) { - delete it.value(); - it = m_presetFileHandlersByExtension.erase(it); - } -} - -bool PresetInfoEnumerator::isValidExtension(const QString extension) { - if (presetsByExtension.contains(extension)) - return true; - return false; -} - -bool PresetInfoEnumerator::hasPresetInfo(const QString extension, const QString name) { - // Check if preset info matching extension and preset name can be found - if (!isValidExtension(extension)) - return false; - - for (QMap<QString, QMap<QString, PresetInfo> >::const_iterator it = - presetsByExtension.begin(); - it != presetsByExtension.end(); ++it) { - for (QMap<QString, PresetInfo>::const_iterator it2 = it.value().begin(); - it2 != it.value().end(); ++it2) { - if (name == it2.value().getName()) { - return true; - } - } - } - return false; -} - -bool PresetInfoEnumerator::hasPresetInfo(const QString path) { - foreach (QString extension, presetsByExtension.keys()) { - QMap<QString, PresetInfo> presets = presetsByExtension[extension]; - if (presets.contains(path)) - return true; - } - return false; -} - -PresetInfo PresetInfoEnumerator::getPresetInfo(const QString path) { - // Lookup and return controller script preset info by script path - // Return NULL if path is not found. - foreach (QString extension, presetsByExtension.keys()) { - QMap<QString, PresetInfo> presets = presetsByExtension[extension]; - if (presets.contains(path)) - return presets[path]; - } - return PresetInfo(); -} - -QList<PresetInfo> PresetInfoEnumerator::getPresets(const QString extension) { - // Return list of PresetInfo items matching extension - // Returns empty list if no matching extension presets can be found - QList<PresetInfo> presets; - if (presetsByExtension.contains(extension)) { - presets = presetsByExtension[extension].values(); - return presetsByExtension[extension].values(); - } - qDebug() << "Extension not registered to presetinfo" << extension; - return presets; -} - -void PresetInfoEnumerator::addExtension(const QString extension) { - if (presetsByExtension.contains(extension)) - return; - QMap<QString,PresetInfo> presets; - presetsByExtension[extension] = presets; -} - -void PresetInfoEnumerator::loadSupportedPresets() { - foreach (QString dirPath, controllerDirPaths) { - QDirIterator it(dirPath); - while (it.hasNext()) { - it.next(); - const QString path = it.filePath(); - foreach (QString extension, fileExtensions) { - if (!path.endsWith(extension)) - continue; - if (!presetsByExtension.contains(extension)) { - addExtension(extension); - } - presetsByExtension[extension][path] = PresetInfo(path); - } - } - } - - foreach (QString extension, presetsByExtension.keys()) { - QMap<QString,PresetInfo> presets = presetsByExtension[extension]; - qDebug() << "Extension" << extension << "total" << presets.keys().length() << "presets"; - } -} - -void PresetInfoEnumerator::updatePresets(const QString extension) { - QMap<QString,PresetInfo> presets; - - if (presetsByExtension.contains(extension)) - presetsByExtension.remove(extension); - - foreach (QString dirPath, controllerDirPaths) { - QDirIterator it(dirPath); - while (it.hasNext()) { - it.next(); - const QString path = it.filePath(); - if (!path.endsWith(extension)) - continue; - presets[path] = PresetInfo(path); - } - } - - presetsByExtension[extension] = presets; -} |