2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2014-01-07 13:27:11 +01:00
|
|
|
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
2014-10-01 13:21:18 +02:00
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2009-06-29 14:47:04 +02:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
#include "plugingenerator.h"
|
|
|
|
|
#include "pluginoptions.h"
|
|
|
|
|
|
2014-09-30 17:53:20 +02:00
|
|
|
#include <coreplugin/generatedfile.h>
|
|
|
|
|
#include <cpptools/abstracteditorsupport.h>
|
2009-06-29 14:47:04 +02:00
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
#include <utils/fileutils.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QFileInfo>
|
|
|
|
|
#include <QDir>
|
|
|
|
|
#include <QSet>
|
2009-06-29 14:47:04 +02:00
|
|
|
|
|
|
|
|
static QString headerGuard(const QString &header)
|
|
|
|
|
{
|
|
|
|
|
return header.toUpper().replace(QRegExp(QLatin1String("[^A-Z0-9]+")), QLatin1String("_"));
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-16 11:02:37 +02:00
|
|
|
namespace QmakeProjectManager {
|
2009-06-29 14:47:04 +02:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
struct ProjectContents {
|
|
|
|
|
QString tmpl;
|
|
|
|
|
QString library;
|
|
|
|
|
QString headers;
|
|
|
|
|
QString sources;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Create a binary icon file
|
2014-09-30 17:58:56 +02:00
|
|
|
static inline Core::GeneratedFile generateIconFile(const QString &source, const QString &target, QString *errorMessage)
|
2009-06-29 14:47:04 +02:00
|
|
|
{
|
|
|
|
|
// Read out source
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(source, errorMessage))
|
2009-06-29 14:47:04 +02:00
|
|
|
return Core::GeneratedFile();
|
|
|
|
|
Core::GeneratedFile rc(target);
|
2011-03-30 15:15:15 +02:00
|
|
|
rc.setBinaryContents(reader.data());
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.setBinary(true);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
2013-02-12 14:15:31 +01:00
|
|
|
static QString qt4PluginExport(const QString &pluginName, const QString &pluginClassName)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("#if QT_VERSION < 0x050000\nQ_EXPORT_PLUGIN2(")
|
|
|
|
|
+ pluginName + QLatin1String(", ") + pluginClassName
|
|
|
|
|
+ QLatin1String(")\n#endif // QT_VERSION < 0x050000");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static QString qt5PluginMetaData(const QString &interfaceName)
|
|
|
|
|
{
|
|
|
|
|
return QLatin1String("#if QT_VERSION >= 0x050000\n Q_PLUGIN_METADATA(IID \"org.qt-project.Qt.")
|
|
|
|
|
+ interfaceName + QLatin1String("\")\n#endif // QT_VERSION >= 0x050000");
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
QList<Core::GeneratedFile> PluginGenerator::generatePlugin(const GenerationParameters& p, const PluginOptions &options,
|
|
|
|
|
QString *errorMessage)
|
|
|
|
|
{
|
|
|
|
|
const QChar slash = QLatin1Char('/');
|
|
|
|
|
const QChar blank = QLatin1Char(' ');
|
|
|
|
|
QList<Core::GeneratedFile> rc;
|
|
|
|
|
|
|
|
|
|
QString baseDir = p.path;
|
|
|
|
|
baseDir += slash;
|
2010-01-07 18:17:24 +01:00
|
|
|
baseDir += p.fileName;
|
2009-06-29 14:47:04 +02:00
|
|
|
const QString slashLessBaseDir = baseDir;
|
|
|
|
|
baseDir += slash;
|
|
|
|
|
|
|
|
|
|
QSet<QString> widgetLibraries;
|
|
|
|
|
QSet<QString> widgetProjects;
|
|
|
|
|
QMap<QString,ProjectContents> widgetProjectContents;
|
|
|
|
|
QString pluginIncludes;
|
|
|
|
|
QString pluginAdditions;
|
|
|
|
|
QString pluginHeaders;
|
|
|
|
|
QString pluginSources;
|
|
|
|
|
QSet<QString> pluginIcons;
|
|
|
|
|
|
|
|
|
|
SubstitutionMap sm;
|
|
|
|
|
|
|
|
|
|
// First create the widget wrappers (plugins) and - if requested - skeletons
|
|
|
|
|
// for the widgets.
|
2010-04-16 15:55:32 +02:00
|
|
|
const int widgetCount = options.widgetOptions.size();
|
|
|
|
|
for (int i = 0; i < widgetCount; i++) {
|
|
|
|
|
const PluginOptions::WidgetOptions &wo = options.widgetOptions.at(i);
|
2009-06-29 14:47:04 +02:00
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("SINGLE_INCLUDE_GUARD"), headerGuard(wo.pluginHeaderFile));
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_CLASS"), wo.pluginClassName);
|
2013-02-12 14:15:31 +01:00
|
|
|
sm.insert(QLatin1String("SINGLE_PLUGIN_METADATA"),
|
|
|
|
|
options.widgetOptions.count() == 1 ?
|
|
|
|
|
qt5PluginMetaData(QLatin1String("QDesignerCustomWidgetInterface")) : QString());
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString pluginHeaderContents = processTemplate(p.templatePath + QLatin1String("/tpl_single.h"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (pluginHeaderContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile pluginHeader(baseDir + wo.pluginHeaderFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
pluginHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.pluginHeaderFile, wo.pluginClassName)
|
|
|
|
|
+ pluginHeaderContents);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(pluginHeader);
|
|
|
|
|
|
|
|
|
|
sm.remove(QLatin1String("SINGLE_INCLUDE_GUARD"));
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_HEADER"), wo.pluginHeaderFile);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_CLASS"), wo.widgetClassName);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_HEADER"), wo.widgetHeaderFile);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_GROUP"), wo.group);
|
|
|
|
|
QString iconResource;
|
|
|
|
|
if (!wo.iconFile.isEmpty()) {
|
|
|
|
|
iconResource = QLatin1String("QLatin1String(\":/");
|
|
|
|
|
iconResource += QFileInfo(wo.iconFile).fileName();
|
|
|
|
|
iconResource += QLatin1String("\")");
|
|
|
|
|
}
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_ICON"),iconResource);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_TOOLTIP"), cStringQuote(wo.toolTip));
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_WHATSTHIS"), cStringQuote(wo.whatsThis));
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_ISCONTAINER"), wo.isContainer ? QLatin1String("true") : QLatin1String("false"));
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_DOMXML"), cStringQuote(wo.domXml));
|
|
|
|
|
sm.insert(QLatin1String("SINGLE_PLUGIN_EXPORT"),
|
|
|
|
|
options.widgetOptions.count() == 1 ?
|
2013-02-12 14:15:31 +01:00
|
|
|
qt4PluginExport(options.pluginName, wo.pluginClassName) : QString());
|
|
|
|
|
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString pluginSourceContents = processTemplate(p.templatePath + QLatin1String("/tpl_single.cpp"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (pluginSourceContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile pluginSource(baseDir + wo.pluginSourceFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
pluginSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.pluginSourceFile, wo.pluginClassName)
|
|
|
|
|
+ pluginSourceContents);
|
2010-04-16 15:55:32 +02:00
|
|
|
if (i == 0 && widgetCount == 1) // Open first widget unless collection
|
|
|
|
|
pluginSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(pluginSource);
|
|
|
|
|
|
|
|
|
|
if (wo.sourceType == PluginOptions::WidgetOptions::LinkLibrary)
|
|
|
|
|
widgetLibraries.insert(QLatin1String("-l") + wo.widgetLibrary);
|
|
|
|
|
else
|
2014-08-29 14:00:18 +02:00
|
|
|
widgetProjects.insert(QLatin1String("include(") + wo.widgetProjectFile + QLatin1Char(')'));
|
2009-06-29 14:47:04 +02:00
|
|
|
pluginIncludes += QLatin1String("#include \"") + wo.pluginHeaderFile + QLatin1String("\"\n");
|
|
|
|
|
pluginAdditions +=
|
|
|
|
|
QLatin1String(" m_widgets.append(new ") + wo.pluginClassName + QLatin1String("(this));\n");
|
|
|
|
|
pluginHeaders += QLatin1Char(' ') + wo.pluginHeaderFile;
|
|
|
|
|
pluginSources += QLatin1Char(' ') + wo.pluginSourceFile;
|
|
|
|
|
if (!wo.iconFile.isEmpty())
|
|
|
|
|
pluginIcons.insert(wo.iconFile);
|
|
|
|
|
|
|
|
|
|
if (wo.createSkeleton) {
|
|
|
|
|
ProjectContents &pc = widgetProjectContents[wo.widgetProjectFile];
|
|
|
|
|
if (pc.headers.isEmpty()) {
|
|
|
|
|
if (wo.sourceType == PluginOptions::WidgetOptions::LinkLibrary) {
|
|
|
|
|
pc.library = wo.widgetLibrary;
|
2009-06-30 17:11:35 +02:00
|
|
|
pc.tmpl = p.templatePath + QLatin1String("/tpl_widget_lib.pro");
|
2009-06-29 14:47:04 +02:00
|
|
|
} else {
|
2009-06-30 17:11:35 +02:00
|
|
|
pc.tmpl = p.templatePath + QLatin1String("/tpl_widget_include.pri");
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
widgetProjectContents.insert(wo.widgetProjectFile, pc);
|
|
|
|
|
} else {
|
|
|
|
|
if (pc.library != wo.widgetLibrary) {
|
|
|
|
|
*errorMessage = tr("Creating multiple widget libraries (%1, %2) in one project (%3) is not supported.")
|
|
|
|
|
.arg(pc.library, wo.widgetLibrary, wo.widgetProjectFile);
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
pc.headers += blank + wo.widgetHeaderFile;
|
|
|
|
|
pc.sources += blank + wo.widgetSourceFile;
|
|
|
|
|
|
|
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_INCLUDE_GUARD"), headerGuard(wo.widgetHeaderFile));
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_BASE_CLASS"), wo.widgetBaseClassName);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_CLASS"), wo.widgetClassName);
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString widgetHeaderContents = processTemplate(p.templatePath + QLatin1String("/tpl_widget.h"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (widgetHeaderContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile widgetHeader(baseDir + wo.widgetHeaderFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
widgetHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.widgetHeaderFile, wo.widgetClassName)
|
|
|
|
|
+ widgetHeaderContents);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(widgetHeader);
|
|
|
|
|
|
|
|
|
|
sm.remove(QLatin1String("WIDGET_INCLUDE_GUARD"));
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_HEADER"), wo.widgetHeaderFile);
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString widgetSourceContents = processTemplate(p.templatePath + QLatin1String("/tpl_widget.cpp"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (widgetSourceContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile widgetSource(baseDir + wo.widgetSourceFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
widgetSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(wo.widgetSourceFile, wo.widgetClassName)
|
|
|
|
|
+ widgetSourceContents);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(widgetSource);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Then create the project files for the widget skeletons.
|
|
|
|
|
// These might create widgetLibraries or be included into the plugin's project.
|
|
|
|
|
QMap<QString,ProjectContents>::const_iterator it = widgetProjectContents.constBegin();
|
|
|
|
|
const QMap<QString,ProjectContents>::const_iterator end = widgetProjectContents.constEnd();
|
|
|
|
|
for (; it != end; ++it) {
|
|
|
|
|
const ProjectContents &pc = it.value();
|
|
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_HEADERS"), pc.headers);
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_SOURCES"), pc.sources);
|
|
|
|
|
if (!pc.library.isEmpty())
|
|
|
|
|
sm.insert(QLatin1String("WIDGET_LIBRARY"), pc.library);
|
|
|
|
|
const QString widgetPriContents = processTemplate(pc.tmpl, sm, errorMessage);
|
|
|
|
|
if (widgetPriContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile widgetPri(baseDir + it.key());
|
|
|
|
|
widgetPri.setContents(widgetPriContents);
|
|
|
|
|
rc.push_back(widgetPri);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create the sources for the collection if necessary.
|
2010-04-16 15:55:32 +02:00
|
|
|
if (widgetCount > 1) {
|
2009-06-29 14:47:04 +02:00
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("COLLECTION_INCLUDE_GUARD"), headerGuard(options.collectionHeaderFile));
|
|
|
|
|
sm.insert(QLatin1String("COLLECTION_PLUGIN_CLASS"), options.collectionClassName);
|
2013-02-12 14:15:31 +01:00
|
|
|
sm.insert(QLatin1String("COLLECTION_PLUGIN_METADATA"), qt5PluginMetaData(QLatin1String("QDesignerCustomWidgetCollectionInterface")));
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString collectionHeaderContents = processTemplate(p.templatePath + QLatin1String("/tpl_collection.h"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (collectionHeaderContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile collectionHeader(baseDir + options.collectionHeaderFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
collectionHeader.setContents(CppTools::AbstractEditorSupport::licenseTemplate(options.collectionHeaderFile, options.collectionClassName)
|
|
|
|
|
+ collectionHeaderContents);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(collectionHeader);
|
|
|
|
|
|
|
|
|
|
sm.remove(QLatin1String("COLLECTION_INCLUDE_GUARD"));
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_INCLUDES"),
|
|
|
|
|
pluginIncludes +
|
|
|
|
|
QLatin1String("#include \"") +
|
|
|
|
|
options.collectionHeaderFile +
|
|
|
|
|
QLatin1String("\""));
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_ADDITIONS"), pluginAdditions);
|
2013-02-12 14:15:31 +01:00
|
|
|
sm.insert(QLatin1String("COLLECTION_PLUGIN_EXPORT"), qt4PluginExport(options.pluginName, options.collectionClassName));
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString collectionSourceFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_collection.cpp"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (collectionSourceFileContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile collectionSource(baseDir + options.collectionSourceFile);
|
2010-08-09 12:23:21 +02:00
|
|
|
collectionSource.setContents(CppTools::AbstractEditorSupport::licenseTemplate(options.collectionSourceFile, options.collectionClassName)
|
|
|
|
|
+ collectionSourceFileContents);
|
2010-04-16 15:55:32 +02:00
|
|
|
collectionSource.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(collectionSource);
|
|
|
|
|
|
|
|
|
|
pluginHeaders += blank + options.collectionHeaderFile;
|
|
|
|
|
pluginSources += blank + options.collectionSourceFile;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy icons that are not in the plugin source base directory yet (that is,
|
|
|
|
|
// probably all), add them to the resource file
|
|
|
|
|
QString iconFiles;
|
|
|
|
|
foreach (QString icon, pluginIcons) {
|
|
|
|
|
const QFileInfo qfi(icon);
|
|
|
|
|
if (qfi.dir() != slashLessBaseDir) {
|
|
|
|
|
const QString newIcon = baseDir + qfi.fileName();
|
|
|
|
|
const Core::GeneratedFile iconFile = generateIconFile(icon, newIcon, errorMessage);
|
|
|
|
|
if (iconFile.path().isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
rc.push_back(iconFile);
|
|
|
|
|
icon = qfi.fileName();
|
|
|
|
|
}
|
|
|
|
|
iconFiles += QLatin1String(" <file>") + icon + QLatin1String("</file>\n");
|
|
|
|
|
}
|
|
|
|
|
// Create the resource file with the icons.
|
|
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("ICON_FILES"), iconFiles);
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString resourceFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_resources.qrc"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (resourceFileContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
|
|
|
|
Core::GeneratedFile resourceFile(baseDir + options.resourceFile);
|
|
|
|
|
resourceFile.setContents(resourceFileContents);
|
|
|
|
|
rc.push_back(resourceFile);
|
|
|
|
|
|
|
|
|
|
// Finally create the project for the plugin itself.
|
|
|
|
|
sm.clear();
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_NAME"), options.pluginName);
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_HEADERS"), pluginHeaders);
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_SOURCES"), pluginSources);
|
|
|
|
|
sm.insert(QLatin1String("PLUGIN_RESOURCES"), options.resourceFile);
|
2014-08-23 01:19:53 +02:00
|
|
|
sm.insert(QLatin1String("WIDGET_LIBS"), QStringList(widgetLibraries.toList()).join(blank));
|
|
|
|
|
sm.insert(QLatin1String("INCLUSIONS"), QStringList(widgetProjects.toList()).join(QLatin1Char('\n')));
|
2009-06-30 17:11:35 +02:00
|
|
|
const QString proFileContents = processTemplate(p.templatePath + QLatin1String("/tpl_plugin.pro"), sm, errorMessage);
|
2009-06-29 14:47:04 +02:00
|
|
|
if (proFileContents.isEmpty())
|
|
|
|
|
return QList<Core::GeneratedFile>();
|
2010-01-07 18:17:24 +01:00
|
|
|
Core::GeneratedFile proFile(baseDir + p.fileName + QLatin1String(".pro"));
|
2009-06-29 14:47:04 +02:00
|
|
|
proFile.setContents(proFileContents);
|
2010-04-16 15:55:32 +02:00
|
|
|
proFile.setAttributes(Core::GeneratedFile::OpenProjectAttribute);
|
2009-06-29 14:47:04 +02:00
|
|
|
rc.push_back(proFile);
|
|
|
|
|
return rc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PluginGenerator::processTemplate(const QString &tmpl,
|
|
|
|
|
const SubstitutionMap &substMap,
|
|
|
|
|
QString *errorMessage)
|
|
|
|
|
{
|
2011-03-30 15:15:15 +02:00
|
|
|
Utils::FileReader reader;
|
|
|
|
|
if (!reader.fetch(tmpl, errorMessage))
|
2009-06-29 14:47:04 +02:00
|
|
|
return QString();
|
|
|
|
|
|
2011-03-30 15:15:15 +02:00
|
|
|
QString cont = QString::fromUtf8(reader.data());
|
2009-06-29 14:47:04 +02:00
|
|
|
const QChar atChar = QLatin1Char('@');
|
|
|
|
|
int offset = 0;
|
|
|
|
|
for (;;) {
|
|
|
|
|
const int start = cont.indexOf(atChar, offset);
|
|
|
|
|
if (start < 0)
|
|
|
|
|
break;
|
|
|
|
|
const int end = cont.indexOf(atChar, start + 1);
|
|
|
|
|
Q_ASSERT(end);
|
|
|
|
|
const QString keyword = cont.mid(start + 1, end - start - 1);
|
|
|
|
|
const QString replacement = substMap.value(keyword);
|
|
|
|
|
cont.replace(start, end - start + 1, replacement);
|
|
|
|
|
offset = start + replacement.length();
|
|
|
|
|
}
|
|
|
|
|
return cont;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PluginGenerator::cStringQuote(QString s)
|
|
|
|
|
{
|
|
|
|
|
s.replace(QLatin1Char('\\'), QLatin1String("\\\\"));
|
|
|
|
|
s.replace(QLatin1Char('"'), QLatin1String("\\\""));
|
|
|
|
|
s.replace(QLatin1Char('\t'), QLatin1String("\\t"));
|
|
|
|
|
s.replace(QLatin1Char('\n'), QLatin1String("\\n"));
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|