hybridpluginxmlhandler.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include <QDebug>
  2. #include <QRegExp>
  3. #include "hybridpluginxmlhandler.h"
  4. // NOTE: The XML handler has no error case handling whatsoever, so at this point
  5. // the XML files should be pretty much correct.
  6. HybridPluginXmlHandler::HybridPluginXmlHandler(QFile *xmlFile)
  7. : QXmlStreamReader(xmlFile)
  8. {
  9. }
  10. HybridPluginXmlHandler::~HybridPluginXmlHandler()
  11. {
  12. }
  13. QSharedPointer<HybridPlugin> HybridPluginXmlHandler::parse()
  14. {
  15. m_plugin = QSharedPointer<HybridPlugin> (new HybridPlugin);
  16. qDebug() << "Parsing start";
  17. readNextStartElement();
  18. while (!atEnd())
  19. {
  20. qDebug() << "HybridPluginXmlHandler::parse: Element" << name() << "read";
  21. if (name() == QLatin1String("plugin"))
  22. handlePluginTag();
  23. else
  24. readNextStartElement();
  25. }
  26. qDebug() << "Parsing end";
  27. return m_plugin;
  28. }
  29. void HybridPluginXmlHandler::handlePluginTag()
  30. {
  31. while (readNextStartElement())
  32. {
  33. qDebug() << "HybridPluginXmlHandler::handlePluginTag: Element" << name() << "read";
  34. if (name() == QLatin1String("name"))
  35. m_plugin->setName(readElementText());
  36. else if (name() == QLatin1String("version"))
  37. m_plugin->setVersion(readElementText());
  38. else if (name() == QLatin1String("platforms"))
  39. handlePlatformsTag();
  40. }
  41. }
  42. void HybridPluginXmlHandler::handlePlatformsTag()
  43. {
  44. while (readNextStartElement())
  45. {
  46. qDebug() << "HybridPluginXmlHandler::handlePlatformsTag: Element" << name() << "read";
  47. if (name() == QLatin1String("platform"))
  48. handlePlatformTag();
  49. }
  50. }
  51. void HybridPluginXmlHandler::handlePlatformTag()
  52. {
  53. QSharedPointer<HybridPluginPlatform> platform = QSharedPointer<HybridPluginPlatform>(new HybridPluginPlatform(*m_plugin.data()));
  54. m_currentPlatform = platform;
  55. m_plugin->addPlatform(platform);
  56. while (readNextStartElement())
  57. {
  58. qDebug() << "HybridPluginXmlHandler::handlePlatformTag: Element" << name() << "read";
  59. if (name() == QLatin1String("name"))
  60. {
  61. m_currentPlatform->setName(readElementText());
  62. }
  63. else if (name() == QLatin1String("version"))
  64. {
  65. QString tag = readElementText();
  66. bool ok;
  67. int version = tag.toInt(&ok);
  68. if (ok)
  69. {
  70. m_currentPlatform->setVersion(version);
  71. }
  72. }
  73. else if (name() == QLatin1String("qt-version"))
  74. {
  75. QString tag = readElementText();
  76. QRegExp versionRx;
  77. versionRx.setPattern("^([0-9]).([0-9]).([0-9])$");
  78. if (versionRx.indexIn(tag) != -1)
  79. {
  80. bool ok;
  81. int qtVersion = QString(versionRx.cap(1) + versionRx.cap(2) + versionRx.cap(3)).toInt(&ok);
  82. if (ok)
  83. {
  84. m_currentPlatform->setQtVersion(qtVersion);
  85. }
  86. }
  87. }
  88. else if (name() == QLatin1String("format"))
  89. {
  90. QString tag = readElementText();
  91. if (tag.toLower() == "lib")
  92. m_currentPlatform->setFormat(HybridPluginPlatform::Library);
  93. else if (tag.toLower() == "source")
  94. m_currentPlatform->setFormat(HybridPluginPlatform::Source);
  95. }
  96. else if (name() == QLatin1String("configuration"))
  97. {
  98. QString tag = readElementText();
  99. if (tag.toLower() == "debug")
  100. m_currentPlatform->setConfiguration(HybridPluginPlatform::Debug);
  101. else if (tag.toLower() == "release")
  102. m_currentPlatform->setConfiguration(HybridPluginPlatform::Release);
  103. }
  104. else if (name() == QLatin1String("url"))
  105. {
  106. m_currentPlatform->setUrl(readElementText());
  107. }
  108. else if (name() == QLatin1String("depends"))
  109. {
  110. handleDependsTag();
  111. }
  112. }
  113. }
  114. void HybridPluginXmlHandler::handleDependsTag()
  115. {
  116. while (readNextStartElement())
  117. {
  118. qDebug() << "HybridPluginXmlHandler::handleDependsTag: Element" << name() << "read";
  119. if (name() == QLatin1String("item"))
  120. handleItemTag();
  121. }
  122. }
  123. void HybridPluginXmlHandler::handleItemTag()
  124. {
  125. QString itemName, itemVersion;
  126. while (readNextStartElement())
  127. {
  128. qDebug() << "HybridPluginXmlHandler::handleItemTag: Element" << name() << "read";
  129. if (name() == QLatin1String("name"))
  130. itemName = readElementText();
  131. else if (name() == QLatin1String("version"))
  132. itemVersion = readElementText();
  133. }
  134. QSharedPointer<Dependency> dependency = QSharedPointer<Dependency>(new Dependency(itemName, itemVersion));
  135. m_currentPlatform->addDependency(dependency);
  136. }