diff --git a/src/plugins/android/androidmanifesteditorwidget.cpp b/src/plugins/android/androidmanifesteditorwidget.cpp index 9c6a616abe3..cb7de5307e5 100644 --- a/src/plugins/android/androidmanifesteditorwidget.cpp +++ b/src/plugins/android/androidmanifesteditorwidget.cpp @@ -488,21 +488,40 @@ void AndroidManifestEditorWidget::focusInEvent(QFocusEvent *event) } } +static bool checkDocument(const QDomDocument &doc, QDomDocument::ParseResult *result) +{ + QDomElement manifest = doc.documentElement(); + if (manifest.tagName() != QLatin1String("manifest")) { + result->errorMessage = ::Android::Tr::tr("The structure of the Android manifest file " + "is corrupted. Expected a top level 'manifest' node."); + result->errorLine = -1; + result->errorColumn = -1; + return false; + } + if (manifest.firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity")).isNull()) { + // missing either application or activity element + result->errorMessage = ::Android::Tr::tr("The structure of the Android manifest file " + "is corrupted. Expected an 'application' and 'activity' sub node."); + result->errorLine = -1; + result->errorColumn = -1; + return false; + } + return true; +} + void AndroidManifestEditorWidget::updateAfterFileLoad() { - QString error; - int errorLine; - int errorColumn; QDomDocument doc; - if (doc.setContent(m_textEditorWidget->toPlainText(), &error, &errorLine, &errorColumn)) { - if (checkDocument(doc, &error, &errorLine, &errorColumn)) { + QDomDocument::ParseResult result = doc.setContent(m_textEditorWidget->toPlainText()); + if (result) { + if (checkDocument(doc, &result)) { if (activePage() != Source) syncToWidgets(doc); return; } } // some error occurred - updateInfoBar(error, errorLine, errorColumn); + updateInfoBar(result.errorMessage, result.errorLine, result.errorColumn); setActivePage(Source); } @@ -591,39 +610,19 @@ TextEditor::TextEditorWidget *AndroidManifestEditorWidget::textEditorWidget() co bool AndroidManifestEditorWidget::syncToWidgets() { QDomDocument doc; - QString errorMessage; - int errorLine, errorColumn; - if (doc.setContent(m_textEditorWidget->toPlainText(), &errorMessage, &errorLine, &errorColumn)) { - if (checkDocument(doc, &errorMessage, &errorLine, &errorColumn)) { + QDomDocument::ParseResult result = doc.setContent(m_textEditorWidget->toPlainText()); + if (result) { + if (checkDocument(doc, &result)) { hideInfoBar(); syncToWidgets(doc); return true; } } - updateInfoBar(errorMessage, errorLine, errorColumn); + updateInfoBar(result.errorMessage, result.errorLine, result.errorColumn); return false; } -bool AndroidManifestEditorWidget::checkDocument(const QDomDocument &doc, QString *errorMessage, - int *errorLine, int *errorColumn) -{ - QDomElement manifest = doc.documentElement(); - if (manifest.tagName() != QLatin1String("manifest")) { - *errorMessage = ::Android::Tr::tr("The structure of the Android manifest file is corrupted. Expected a top level 'manifest' node."); - *errorLine = -1; - *errorColumn = -1; - return false; - } else if (manifest.firstChildElement(QLatin1String("application")).firstChildElement(QLatin1String("activity")).isNull()) { - // missing either application or activity element - *errorMessage = ::Android::Tr::tr("The structure of the Android manifest file is corrupted. Expected an 'application' and 'activity' sub node."); - *errorLine = -1; - *errorColumn = -1; - return false; - } - return true; -} - void AndroidManifestEditorWidget::startParseCheck() { m_timerParseCheck.start(); @@ -641,16 +640,15 @@ void AndroidManifestEditorWidget::updateInfoBar() return; } QDomDocument doc; - int errorLine, errorColumn; - QString errorMessage; - if (doc.setContent(m_textEditorWidget->toPlainText(), &errorMessage, &errorLine, &errorColumn)) { - if (checkDocument(doc, &errorMessage, &errorLine, &errorColumn)) { + QDomDocument::ParseResult result = doc.setContent(m_textEditorWidget->toPlainText()); + if (result) { + if (checkDocument(doc, &result)) { hideInfoBar(); return; } } - updateInfoBar(errorMessage, errorLine, errorColumn); + updateInfoBar(result.errorMessage, result.errorLine, result.errorColumn); } void AndroidManifestEditorWidget::updateSdkVersions() @@ -888,9 +886,9 @@ void AndroidManifestEditorWidget::syncToEditor() m_dirty = false; } -namespace { -QXmlStreamAttributes modifyXmlStreamAttributes(const QXmlStreamAttributes &input, const QStringList &keys, - const QStringList &values, const QStringList &remove = QStringList()) +static QXmlStreamAttributes modifyXmlStreamAttributes( + const QXmlStreamAttributes &input, const QStringList &keys, + const QStringList &values, const QStringList &remove = {}) { Q_ASSERT(keys.size() == values.size()); QXmlStreamAttributes result; @@ -903,8 +901,7 @@ QXmlStreamAttributes modifyXmlStreamAttributes(const QXmlStreamAttributes &input if (index == -1) result.push_back(attribute); else - result.push_back(QXmlStreamAttribute(name, - values.at(index))); + result.push_back(QXmlStreamAttribute(name, values.at(index))); } for (int i = 0; i < keys.size(); ++i) { @@ -913,7 +910,6 @@ QXmlStreamAttributes modifyXmlStreamAttributes(const QXmlStreamAttributes &input } return result; } -} // end namespace void AndroidManifestEditorWidget::parseManifest(QXmlStreamReader &reader, QXmlStreamWriter &writer) { diff --git a/src/plugins/android/androidmanifesteditorwidget.h b/src/plugins/android/androidmanifesteditorwidget.h index 1cce7157e44..28c193f15fc 100644 --- a/src/plugins/android/androidmanifesteditorwidget.h +++ b/src/plugins/android/androidmanifesteditorwidget.h @@ -14,14 +14,11 @@ QT_BEGIN_NAMESPACE class QCheckBox; class QDomDocument; -class QDomElement; class QComboBox; class QPushButton; class QLabel; class QLineEdit; class QListView; -class QSpinBox; -class QToolButton; class QXmlStreamReader; class QXmlStreamWriter; QT_END_NAMESPACE @@ -108,9 +105,6 @@ private: void syncToEditor(); void updateAfterFileLoad(); - bool checkDocument(const QDomDocument &doc, QString *errorMessage, - int *errorLine, int *errorColumn); - void updateInfoBar(const QString &errorMessage, int line, int column); void hideInfoBar();