Commit 110c31b1 authored by Eike Ziller's avatar Eike Ziller Committed by hjk
Browse files

Resolve demos and examples also relative to qt install paths.



Qt5 has the manifest files in QT_INSTALL_DOCS but the actual examples in
QT_INSTALL_EXAMPLES/DEMOS, which can be completely independent.
The patch tries to resolves files relative to the manifest, and if that
fails, relative to the install paths.

Change-Id: I7d449e1edab01f18680a5ffe6edcb508e7b194f6
Reviewed-by: default avatarhjk <qthjk@ovi.com>
parent fbe6834a
......@@ -101,7 +101,23 @@ static inline QStringList trimStringList(const QStringList &stringlist)
return returnList;
}
QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, const QString& projectsOffset)
static QString relativeOrInstallPath(const QString &path, const QString &manifestPath,
const QString &installPath)
{
const QChar slash = QLatin1Char('/');
const QString relativeResolvedPath = manifestPath + slash + path;
const QString installResolvedPath = installPath + slash + path;
if (QFile::exists(relativeResolvedPath))
return relativeResolvedPath;
else if (QFile::exists(installResolvedPath))
return installResolvedPath;
// doesn't exist, just return relative
return relativeResolvedPath;
}
QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader *reader,
const QString &projectsOffset,
const QString &examplesInstallPath)
{
QList<ExampleItem> examples;
ExampleItem item;
......@@ -116,12 +132,12 @@ QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, co
item.name = attributes.value(QLatin1String("name")).toString();
item.projectPath = attributes.value(QLatin1String("projectPath")).toString();
item.hasSourceCode = !item.projectPath.isEmpty();
item.projectPath.prepend(slash);
item.projectPath.prepend(projectsOffset);
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, examplesInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, examplesInstallPath));
} else if (reader->name() == QLatin1String("description")) {
item.description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("dependency")) {
......@@ -151,7 +167,9 @@ QList<ExampleItem> ExamplesListModel::parseExamples(QXmlStreamReader* reader, co
return examples;
}
QList<ExampleItem> ExamplesListModel::parseDemos(QXmlStreamReader* reader, const QString& projectsOffset)
QList<ExampleItem> ExamplesListModel::parseDemos(QXmlStreamReader *reader,
const QString &projectsOffset,
const QString &demosInstallPath)
{
QList<ExampleItem> demos;
ExampleItem item;
......@@ -166,12 +184,12 @@ QList<ExampleItem> ExamplesListModel::parseDemos(QXmlStreamReader* reader, const
item.name = attributes.value(QLatin1String("name")).toString();
item.projectPath = attributes.value(QLatin1String("projectPath")).toString();
item.hasSourceCode = !item.projectPath.isEmpty();
item.projectPath.prepend(slash);
item.projectPath.prepend(projectsOffset);
item.projectPath = relativeOrInstallPath(item.projectPath, projectsOffset, demosInstallPath);
item.imageUrl = attributes.value(QLatin1String("imageUrl")).toString();
item.docUrl = attributes.value(QLatin1String("docUrl")).toString();
} else if (reader->name() == QLatin1String("fileToOpen")) {
item.filesToOpen.append(projectsOffset + slash + reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
item.filesToOpen.append(relativeOrInstallPath(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement),
projectsOffset, demosInstallPath));
} else if (reader->name() == QLatin1String("description")) {
item.description = fixStringForTags(reader->readElementText(QXmlStreamReader::ErrorOnUnexpectedElement));
} else if (reader->name() == QLatin1String("dependency")) {
......@@ -258,11 +276,14 @@ void ExamplesListModel::handleQtVersionsChanged()
void ExamplesListModel::updateExamples()
{
clear();
QString examplesInstallPath;
QString demosInstallPath;
QString examplesFallback;
QString demosFallback;
QString sourceFallback;
foreach (const QString &exampleSource,
exampleSources(&examplesFallback, &demosFallback, &sourceFallback)) {
exampleSources(&examplesInstallPath, &demosInstallPath,
&examplesFallback, &demosFallback, &sourceFallback)) {
QFile exampleFile(exampleSource);
if (!exampleFile.open(QIODevice::ReadOnly)) {
qDebug() << Q_FUNC_INFO << "Could not open file" << exampleSource;
......@@ -291,9 +312,9 @@ void ExamplesListModel::updateExamples()
switch (reader.readNext()) {
case QXmlStreamReader::StartElement:
if (reader.name() == QLatin1String("examples"))
addItems(parseExamples(&reader, examplesDir.path()));
addItems(parseExamples(&reader, examplesDir.path(), examplesInstallPath));
else if (reader.name() == QLatin1String("demos"))
addItems(parseDemos(&reader, demosDir.path()));
addItems(parseDemos(&reader, demosDir.path(), demosInstallPath));
else if (reader.name() == QLatin1String("tutorials"))
addItems(parseTutorials(&reader, examplesDir.path()));
break;
......@@ -310,7 +331,8 @@ void ExamplesListModel::updateExamples()
emit tagsUpdated();
}
QStringList ExamplesListModel::exampleSources(QString *examplesFallback, QString *demosFallback,
QStringList ExamplesListModel::exampleSources(QString *examplesInstallPath, QString *demosInstallPath,
QString *examplesFallback, QString *demosFallback,
QString *sourceFallback)
{
QTC_CHECK(examplesFallback);
......@@ -379,6 +401,10 @@ QStringList ExamplesListModel::exampleSources(QString *examplesFallback, QString
if (!fis.isEmpty()) {
foreach (const QFileInfo &fi, fis)
sources.append(fi.filePath());
if (examplesInstallPath)
*examplesInstallPath = version->examplesPath();
if (demosInstallPath)
*demosInstallPath = version->demosPath();
return sources;
}
}
......
......@@ -92,11 +92,14 @@ public slots:
private:
void addItems(const QList<ExampleItem> &items);
QList<ExampleItem> parseExamples(QXmlStreamReader* reader, const QString& projectsOffset);
QList<ExampleItem> parseDemos(QXmlStreamReader* reader, const QString& projectsOffset);
QList<ExampleItem> parseTutorials(QXmlStreamReader* reader, const QString& projectsOffset);
QList<ExampleItem> parseExamples(QXmlStreamReader *reader, const QString &projectsOffset,
const QString &examplesInstallPath);
QList<ExampleItem> parseDemos(QXmlStreamReader *reader, const QString &projectsOffset,
const QString &demosInstallPath);
QList<ExampleItem> parseTutorials(QXmlStreamReader *reader, const QString &projectsOffset);
void clear();
QStringList exampleSources(QString *examplesFallback, QString *demosFallback,
QStringList exampleSources(QString *examplesInstallPath, QString *demosInstallPath,
QString *examplesFallback, QString *demosFallback,
QString *sourceFallback);
QList<ExampleItem> exampleItems;
QStringList m_tags;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment