diff options
author | Kimmo Ollila <kimmo.ollila@theqtcompany.com> | 2016-01-27 08:53:06 +0200 |
---|---|---|
committer | Kimmo Ollila <kimmo.ollila@theqtcompany.com> | 2016-01-27 09:37:09 +0000 |
commit | 8dac8f162f60f7f7359d6a7c6fbd091f2b8656c1 (patch) | |
tree | 4f17b820a2b7e57e2821cc33d50cb643cd113d39 /src | |
parent | 4aa55de37d14fa1c4cceb639db5649372318015b (diff) |
Use one unified xml to read metadatas for demos.
This change also needs commit 5c60949719acb84bfaea8c0e49b96c7041c38235
from tqtc-boot2qt/demos.git for demos to show up.
Change-Id: Id909258de0f64675ef754bba33906c4d2ab1e163
Task-Id: QTRD-3762
Reviewed-by: Teemu Holappa <teemu.holappa@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/applicationsmodel.cpp | 78 | ||||
-rw-r--r-- | src/applicationsmodel.h | 4 |
2 files changed, 75 insertions, 7 deletions
diff --git a/src/applicationsmodel.cpp b/src/applicationsmodel.cpp index b78b275..38b6dec 100644 --- a/src/applicationsmodel.cpp +++ b/src/applicationsmodel.cpp @@ -25,6 +25,7 @@ #include <QRegExp> #include <QJsonDocument> #include <QJsonObject> +#include <QXmlStreamReader> const QEvent::Type RESULT_EVENT = (QEvent::Type) (QEvent::User + 1); class ResultEvent : public QEvent @@ -40,7 +41,10 @@ public: static bool appOrder(const AppData& a, const AppData& b) { - return a.name < b.name; + if (a.priority != b.priority) + return a.priority > b.priority; + else + return a.name < b.name; } class IndexingThread : public QThread @@ -53,8 +57,69 @@ public: QList<QString> roots = root.split(":"); target = qgetenv("B2QT_BASE") + "-" + qgetenv("B2QT_PLATFORM"); foreach (const QString &root, roots) { - results += indexDirectory(root); + if (QFile::exists(root + "/demos.xml")) { + + QFile file(root + "/demos.xml"); + + if (!file.open(QIODevice::ReadOnly)) + break; + + QXmlStreamReader xml(&file); + + AppData data; + bool exclude = false; + + while (!xml.atEnd()) { + switch (xml.readNext()) { + + case QXmlStreamReader::StartElement: + if (xml.name().toString().toLower() == "application") { + + const QStringList excludeList = xml.attributes().value("exclude").toString().split(QRegExp(":|\\s+")); + + exclude = excludeList.contains(target) || excludeList.contains(QStringLiteral("all")); + + if (exclude) + break; + + data.name = xml.attributes().value("title").toString().trimmed(); + + QString path = xml.attributes().value("location").toString(); + data.location = QUrl::fromLocalFile(path); + + data.main = QString("/%1").arg(xml.attributes().value("main").toString()); + + QString imageName = xml.attributes().value("icon").toString(); + + data.icon = QFile::exists(imageName) + ? QUrl::fromLocalFile(imageName) + : QUrl("qrc:///qml/images/codeless.png"); + + + data.priority = xml.attributes().value("priority").toInt(); + + } else if (xml.name().toString().toLower() == "description") { + data.description = xml.readElementText().trimmed(); + } + break; + + case QXmlStreamReader::EndElement: + if (xml.name().toString().toLower() == "application" && !exclude) + results << data; + break; + + default: + break; + } + } + + if (xml.error() != QXmlStreamReader::NoError) + qWarning("XML Parser error: %s", qPrintable(xml.errorString())); + } } + + std::sort(results.begin(), results.end(), appOrder); + qDebug() << "Indexer: all done... total:" << results.size(); QCoreApplication::postEvent(model, new ResultEvent(results)); } @@ -129,11 +194,10 @@ QHash<int, QByteArray> ApplicationsModel::roleNames() const names[MainFileRole] = "mainFile"; names[LocationRole] = "location"; names[IconRole] = "icon"; + names[PriorityRole] = "priority"; return names; } - - void ApplicationsModel::initialize(const QString &appsRoot) { IndexingThread *thread = new IndexingThread; @@ -168,6 +232,7 @@ QVariant ApplicationsModel::data(const QModelIndex &index, int role) const case LocationRole: return ad.location; case MainFileRole: return ad.main; case IconRole: return ad.icon; + case PriorityRole: return ad.priority; default: qDebug() << "ApplicationsModel::data: unhandled role" << role; } @@ -202,8 +267,9 @@ QVariant ApplicationsModel::query(int i, const QString &name) const else if (name == QStringLiteral("location")) return ad.location; else if (name == QStringLiteral("mainFile")) return ad.main; else if (name == QStringLiteral("icon")) return ad.icon; - - return QVariant(); + else if (name == QStringLiteral("priority")) return ad.priority; qWarning("ApplicationsModel::query: Asking for bad name %s", qPrintable(name)); + + return QVariant(); } diff --git a/src/applicationsmodel.h b/src/applicationsmodel.h index 6c791c2..0f15b84 100644 --- a/src/applicationsmodel.h +++ b/src/applicationsmodel.h @@ -28,6 +28,7 @@ struct AppData { QString main; QUrl location; QUrl icon; + int priority; }; @@ -41,7 +42,8 @@ public: MainFileRole, LocationRole, IconRole, - LargeIconNameRole + LargeIconNameRole, + PriorityRole }; explicit ApplicationsModel(QObject *parent = 0); |