Commit 89b3d2f2 authored by Daniel Teske's avatar Daniel Teske
Browse files

Android: Add a activity line edit to the AndroidManifest editor



And remove code for handling @strings/app_name. The default template
hasn't used that for a while and it's pretty hard to properly support
that with both a activity and app setting.

Change-Id: I394b78e0a5380232efbc52e1c71d49d9696a9b00
Task-number: QTCREATORBUG-13958
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@theqtcompany.com>
Reviewed-by: default avatarBogDan Vatra <bogdan@kde.org>
parent 5697a935
......@@ -106,9 +106,7 @@ Project *androidProject(const Utils::FileName &fileName)
AndroidManifestEditorWidget::AndroidManifestEditorWidget()
: QStackedWidget(),
m_dirty(false),
m_stayClean(false),
m_setAppName(false),
m_appNameInStringsXml(false)
m_stayClean(false)
{
m_textEditorWidget = new AndroidManifestTextEditorWidget(this);
......@@ -226,6 +224,9 @@ void AndroidManifestEditorWidget::initializePage()
m_appNameLineEdit = new QLineEdit(applicationGroupBox);
formLayout->addRow(tr("Application name:"), m_appNameLineEdit);
m_activityNameLineEdit = new QLineEdit(applicationGroupBox);
formLayout->addRow(tr("Activity name:"), m_activityNameLineEdit);
m_targetLineEdit = new QComboBox(applicationGroupBox);
m_targetLineEdit->setEditable(true);
m_targetLineEdit->setDuplicatesEnabled(true);
......@@ -260,7 +261,9 @@ void AndroidManifestEditorWidget::initializePage()
applicationGroupBox->setLayout(formLayout);
connect(m_appNameLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(setAppName()));
this, SLOT(setDirty()));
connect(m_activityNameLineEdit, SIGNAL(textEdited(QString)),
this, SLOT(setDirty()));
connect(m_targetLineEdit, SIGNAL(currentTextChanged(QString)),
this, SLOT(setDirty()));
......@@ -534,8 +537,7 @@ bool AndroidManifestEditorWidget::isModified() const
return m_dirty
|| !m_hIconPath.isEmpty()
|| !m_mIconPath.isEmpty()
|| !m_lIconPath.isEmpty()
|| m_setAppName;
|| !m_lIconPath.isEmpty();
}
AndroidManifestEditorWidget::EditorPage AndroidManifestEditorWidget::activePage() const
......@@ -573,31 +575,6 @@ void AndroidManifestEditorWidget::preSave()
if (activePage() != Source)
syncToEditor();
if (m_setAppName && m_appNameInStringsXml) {
QString baseDir = m_textEditorWidget->textDocument()->filePath().toFileInfo().absolutePath();
QString fileName = baseDir + QLatin1String("/res/values/strings.xml");
QFile f(fileName);
if (f.open(QIODevice::ReadOnly)) {
QDomDocument doc;
if (doc.setContent(f.readAll())) {
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("string"));
while (!metadataElem.isNull()) {
if (metadataElem.attribute(QLatin1String("name")) == QLatin1String("app_name")) {
metadataElem.removeChild(metadataElem.firstChild());
metadataElem.appendChild(doc.createTextNode(m_appNameLineEdit->text()));
break;
}
metadataElem = metadataElem.nextSiblingElement(QLatin1String("string"));
}
f.close();
f.open(QIODevice::WriteOnly);
f.write(doc.toByteArray((4)));
}
}
m_setAppName = false;
}
QString baseDir = m_textEditorWidget->textDocument()->filePath().toFileInfo().absolutePath();
if (!m_lIconPath.isEmpty()) {
copyIcon(LowDPI, baseDir, m_lIconPath);
......@@ -774,30 +751,15 @@ void AndroidManifestEditorWidget::syncToWidgets(const QDomDocument &doc)
setApiLevel(m_androidTargetSdkVersion, usesSdkElement, QLatin1String("android:targetSdkVersion"));
QString baseDir = m_textEditorWidget->textDocument()->filePath().toFileInfo().absolutePath();
QString fileName = baseDir + QLatin1String("/res/values/strings.xml");
QDomElement applicationElement = manifest.firstChildElement(QLatin1String("application"));
m_appNameLineEdit->setText(applicationElement.attribute(QLatin1String("android:label")));
QFile f(fileName);
if (f.exists() && f.open(QIODevice::ReadOnly)) {
QDomDocument doc;
if (doc.setContent(&f)) {
QDomElement metadataElem = doc.documentElement().firstChildElement(QLatin1String("string"));
while (!metadataElem.isNull()) {
if (metadataElem.attribute(QLatin1String("name")) == QLatin1String("app_name")) {
m_appNameLineEdit->setText(metadataElem.text());
break;
}
metadataElem = metadataElem.nextSiblingElement(QLatin1String("string"));
}
}
m_appNameInStringsXml = true;
} else {
m_appNameLineEdit->setText(applicationElement.attribute(QLatin1String("android:label")));
m_appNameInStringsXml = false;
}
QDomElement activityElem = applicationElement.firstChildElement(QLatin1String("activity"));
m_activityNameLineEdit->setText(activityElem.attribute(QLatin1String("android:label")));
QDomElement metadataElem = activityElem.firstChildElement(QLatin1String("meta-data"));
QDomElement metadataElem = applicationElement.firstChildElement(QLatin1String("activity")).firstChildElement(QLatin1String("meta-data"));
while (!metadataElem.isNull()) {
if (metadataElem.attribute(QLatin1String("android:name")) == QLatin1String("android.app.lib_name")) {
m_targetLineEdit->setEditText(metadataElem.attribute(QLatin1String("android:value")));
......@@ -1011,13 +973,8 @@ void AndroidManifestEditorWidget::parseApplication(QXmlStreamReader &reader, QXm
writer.writeStartElement(reader.name().toString());
QXmlStreamAttributes attributes = reader.attributes();
QStringList keys;
QStringList values;
if (!m_appNameInStringsXml) {
keys << QLatin1String("android:label");
values << m_appNameLineEdit->text();
m_setAppName = false;
}
QStringList keys = { QLatin1String("android:label") };
QStringList values = { m_appNameLineEdit->text() };
bool ensureIconAttribute = !m_lIconPath.isEmpty()
|| !m_mIconPath.isEmpty()
|| !m_hIconPath.isEmpty();
......@@ -1051,7 +1008,14 @@ void AndroidManifestEditorWidget::parseApplication(QXmlStreamReader &reader, QXm
void AndroidManifestEditorWidget::parseActivity(QXmlStreamReader &reader, QXmlStreamWriter &writer)
{
Q_ASSERT(reader.isStartElement());
writer.writeCurrentToken(reader);
writer.writeStartElement(reader.name().toString());
QXmlStreamAttributes attributes = reader.attributes();
QStringList keys = { QLatin1String("android:label") };
QStringList values = { m_activityNameLineEdit->text() };
QXmlStreamAttributes result = modifyXmlStreamAttributes(attributes, keys, values);
writer.writeAttributes(result);
reader.readNext();
bool found = false;
......@@ -1337,12 +1301,6 @@ void AndroidManifestEditorWidget::removePermission()
setDirty(true);
}
void AndroidManifestEditorWidget::setAppName()
{
m_setAppName = true;
setDirty(true);
}
void AndroidManifestEditorWidget::setPackageName()
{
const QString packageName= m_packageNameLineEdit->text();
......
......@@ -125,7 +125,6 @@ private slots:
void addPermission();
void removePermission();
void updateAddRemovePermissionButtons();
void setAppName();
void setPackageName();
void updateInfoBar();
void updateSdkVersions();
......@@ -161,8 +160,6 @@ private:
bool m_dirty; // indicates that we need to call syncToEditor()
bool m_stayClean;
bool m_setAppName;
bool m_appNameInStringsXml;
int m_errorLine;
int m_errorColumn;
......@@ -176,6 +173,7 @@ private:
// Application
QLineEdit *m_appNameLineEdit;
QLineEdit *m_activityNameLineEdit;
QComboBox *m_targetLineEdit;
QToolButton *m_lIconButton;
QToolButton *m_mIconButton;
......
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