summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-08-13 11:10:11 +0200
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2010-08-13 11:10:11 +0200
commitb44efd097b03a89d1df1fd77b871ff5a238f66c5 (patch)
tree2a4f3c4f4f71298c81028fb299684e82b9430e89
parentae55b43c3782a06d625805e2135f2a0c3b7754b2 (diff)
downloadqt-creator-b44efd097b03a89d1df1fd77b871ff5a238f66c5.tar.gz
Custom wizard: Add boolean 'enabled' attribute to <wizard>.
Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizard.cpp9
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizardparameters.cpp33
-rw-r--r--src/plugins/projectexplorer/customwizard/customwizardparameters.h10
3 files changed, 34 insertions, 18 deletions
diff --git a/src/plugins/projectexplorer/customwizard/customwizard.cpp b/src/plugins/projectexplorer/customwizard/customwizard.cpp
index b9c8e7e18a..81a141e315 100644
--- a/src/plugins/projectexplorer/customwizard/customwizard.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizard.cpp
@@ -331,13 +331,18 @@ QList<CustomWizard*> CustomWizard::createWizards()
if (dir.exists(configFile)) {
CustomWizardParametersPtr parameters(new Internal::CustomWizardParameters);
Core::BaseFileWizardParameters baseFileParameters;
- if (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) {
+ switch (parameters->parse(dir.absoluteFilePath(configFile), &baseFileParameters, &errorMessage)) {
+ case Internal::CustomWizardParameters::ParseOk:
parameters->directory = dir.absolutePath();
if (CustomWizardPrivate::verbose)
verboseLog += parameters->toString();
if (CustomWizard *w = createWizard(parameters, baseFileParameters))
rc.push_back(w);
- } else {
+ case Internal::CustomWizardParameters::ParseDisabled:
+ if (CustomWizardPrivate::verbose)
+ qWarning("Ignoring disabled wizard %s...", qPrintable(dir.absolutePath()));
+ break;
+ case Internal::CustomWizardParameters::ParseFailed:
qWarning("Failed to initialize custom project wizard in %s: %s",
qPrintable(dir.absolutePath()), qPrintable(errorMessage));
}
diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp
index 2f3d902c88..034692039e 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp
+++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.cpp
@@ -48,6 +48,7 @@ static const char customWizardElementC[] = "wizard";
static const char iconElementC[] = "icon";
static const char descriptionElementC[] = "description";
static const char displayNameElementC[] = "displayname";
+static const char wizardEnabledAttributeC[] = "enabled";
static const char idAttributeC[] = "id";
static const char kindAttributeC[] = "kind";
static const char klassAttributeC[] = "class";
@@ -329,9 +330,13 @@ static inline QString msgError(const QXmlStreamReader &reader,
arg(fileName).arg(reader.lineNumber()).arg(reader.columnNumber()).arg(what);
}
-static inline bool booleanAttributeValue(const QXmlStreamReader &r, const char *name)
+static inline bool booleanAttributeValue(const QXmlStreamReader &r, const char *nameC,
+ bool defaultValue)
{
- return r.attributes().value(QLatin1String(name)) == QLatin1String("true");
+ const QStringRef attributeValue = r.attributes().value(QLatin1String(nameC));
+ if (attributeValue.isEmpty())
+ return defaultValue;
+ return attributeValue == QLatin1String("true");
}
static inline int integerAttributeValue(const QXmlStreamReader &r, const char *name, int defaultValue)
@@ -368,7 +373,8 @@ static inline QString localeLanguage()
}
// Main parsing routine
-bool CustomWizardParameters::parse(QIODevice &device,
+CustomWizardParameters::ParseResult
+ CustomWizardParameters::parse(QIODevice &device,
const QString &configFileFullPath,
Core::BaseFileWizardParameters *bp,
QString *errorMessage)
@@ -386,7 +392,7 @@ bool CustomWizardParameters::parse(QIODevice &device,
switch (token) {
case QXmlStreamReader::Invalid:
*errorMessage = msgError(reader, configFileFullPath, reader.errorString());
- return false;
+ return ParseFailed;
case QXmlStreamReader::StartElement:
do {
// Read out subelements applicable to current state
@@ -401,8 +407,10 @@ bool CustomWizardParameters::parse(QIODevice &device,
case ParseError:
*errorMessage = msgError(reader, configFileFullPath,
QString::fromLatin1("Unexpected start element %1").arg(reader.name().toString()));
- return false;
+ return ParseFailed;
case ParseWithinWizard:
+ if (!booleanAttributeValue(reader, wizardEnabledAttributeC, true))
+ return ParseDisabled;
bp->setId(attributeValue(reader, idAttributeC));
bp->setCategory(attributeValue(reader, categoryAttributeC));
bp->setKind(kindAttribute(reader));
@@ -411,14 +419,14 @@ bool CustomWizardParameters::parse(QIODevice &device,
break;
case ParseWithinField: // field attribute
field.name = attributeValue(reader, fieldNameAttributeC);
- field.mandatory = booleanAttributeValue(reader, fieldMandatoryAttributeC);
+ field.mandatory = booleanAttributeValue(reader, fieldMandatoryAttributeC, false);
break;
case ParseWithinFile: { // file attribute
CustomWizardFile file;
file.source = attributeValue(reader, fileNameSourceAttributeC);
file.target = attributeValue(reader, fileNameTargetAttributeC);
- file.openEditor = booleanAttributeValue(reader, fileNameOpenEditorAttributeC);
- file.openProject = booleanAttributeValue(reader, fileNameOpenProjectAttributeC);
+ file.openEditor = booleanAttributeValue(reader, fileNameOpenEditorAttributeC, false);
+ file.openProject = booleanAttributeValue(reader, fileNameOpenProjectAttributeC, false);
if (file.target.isEmpty())
file.target = file.source;
if (file.source.isEmpty()) {
@@ -438,7 +446,7 @@ bool CustomWizardParameters::parse(QIODevice &device,
if (state == ParseError) {
*errorMessage = msgError(reader, configFileFullPath,
QString::fromLatin1("Unexpected end element %1").arg(reader.name().toString()));
- return false;
+ return ParseFailed;
}
if (state == ParseWithinFields) { // Leaving a field element
fields.push_back(field);
@@ -449,17 +457,18 @@ bool CustomWizardParameters::parse(QIODevice &device,
break;
}
} while (token != QXmlStreamReader::EndDocument);
- return true;
+ return ParseOk;
}
-bool CustomWizardParameters::parse(const QString &configFileFullPath,
+CustomWizardParameters::ParseResult
+ CustomWizardParameters::parse(const QString &configFileFullPath,
Core::BaseFileWizardParameters *bp,
QString *errorMessage)
{
QFile configFile(configFileFullPath);
if (!configFile.open(QIODevice::ReadOnly|QIODevice::Text)) {
*errorMessage = QString::fromLatin1("Cannot open %1: %2").arg(configFileFullPath, configFile.errorString());
- return false;
+ return ParseFailed;
}
return parse(configFile, configFileFullPath, bp, errorMessage);
}
diff --git a/src/plugins/projectexplorer/customwizard/customwizardparameters.h b/src/plugins/projectexplorer/customwizard/customwizardparameters.h
index f71de2b612..3d5b223d4c 100644
--- a/src/plugins/projectexplorer/customwizard/customwizardparameters.h
+++ b/src/plugins/projectexplorer/customwizard/customwizardparameters.h
@@ -67,12 +67,14 @@ struct CustomWizardFile {
struct CustomWizardParameters
{
public:
+ enum ParseResult { ParseOk, ParseDisabled, ParseFailed };
+
CustomWizardParameters();
void clear();
- bool parse(QIODevice &device, const QString &configFileFullPath,
- Core::BaseFileWizardParameters *bp, QString *errorMessage);
- bool parse(const QString &configFileFullPath,
- Core::BaseFileWizardParameters *bp, QString *errorMessage);
+ ParseResult parse(QIODevice &device, const QString &configFileFullPath,
+ Core::BaseFileWizardParameters *bp, QString *errorMessage);
+ ParseResult parse(const QString &configFileFullPath,
+ Core::BaseFileWizardParameters *bp, QString *errorMessage);
QString toString() const;
QString directory;