Commit 60b1aaea authored by Daniel Teske's avatar Daniel Teske

Android: Implement a "editor" for android manifest files

Change-Id: I18c00ab452db21e5aa1ae3ad2eff465cfeff54b6
Reviewed-by: default avatarEskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
parent 5fc56515
......@@ -36,7 +36,11 @@ HEADERS += \
androiddevice.h \
androidgdbserverkitinformation.h \
androidanalyzesupport.h \
androidrunsupport.h
androidrunsupport.h \
androidmanifesteditorfactory.h \
androidmanifesteditor.h \
androidmanifesteditorwidget.h \
androidmanifestdocument.h
SOURCES += \
androidconfigurations.cpp \
......@@ -67,7 +71,11 @@ SOURCES += \
androiddevice.cpp \
androidgdbserverkitinformation.cpp \
androidanalyzesupport.cpp \
androidrunsupport.cpp
androidrunsupport.cpp \
androidmanifesteditorfactory.cpp \
androidmanifesteditor.cpp \
androidmanifesteditorwidget.cpp \
androidmanifestdocument.cpp
FORMS += \
androidsettingswidget.ui \
......
......@@ -62,6 +62,9 @@ const char ANDROIDQT[] = "Qt4ProjectManager.QtVersion.Android";
const char ANDROID_DEVICE_TYPE[] = "Android.Device.Type";
const char ANDROID_DEVICE_ID[] = "Android Device";
const char ANDROID_MANIFEST_MIME_TYPE[] = "application/vnd.google.android.android_manifest";
const char ANDROID_MANIFEST_EDITOR_ID[] = "Android.AndroidManifestEditor.Id";
const char ANDROID_MANIFEST_EDITOR_CONTEXT[] = "Android.AndroidManifestEditor.Id";
} // namespace Constants;
} // namespace Android
......
......@@ -182,41 +182,6 @@ bool AndroidManager::setApplicationName(ProjectExplorer::Target *target, const Q
return saveXmlFile(target, doc, path);
}
QStringList AndroidManager::permissions(ProjectExplorer::Target *target)
{
QStringList per;
QDomDocument doc;
if (!openManifest(target, doc))
return per;
QDomElement permissionElem = doc.documentElement().firstChildElement(QLatin1String("uses-permission"));
while (!permissionElem.isNull()) {
per << permissionElem.attribute(QLatin1String("android:name"));
permissionElem = permissionElem.nextSiblingElement(QLatin1String("uses-permission"));
}
return per;
}
bool AndroidManager::setPermissions(ProjectExplorer::Target *target, const QStringList &permissions)
{
QDomDocument doc;
if (!openManifest(target, doc))
return false;
QDomElement docElement = doc.documentElement();
QDomElement permissionElem = docElement.firstChildElement(QLatin1String("uses-permission"));
while (!permissionElem.isNull()) {
docElement.removeChild(permissionElem);
permissionElem = docElement.firstChildElement(QLatin1String("uses-permission"));
}
foreach (const QString &permission, permissions ) {
permissionElem = doc.createElement(QLatin1String("uses-permission"));
permissionElem.setAttribute(QLatin1String("android:name"), permission);
docElement.appendChild(permissionElem);
}
return saveManifest(target, doc);
}
QString AndroidManager::intentName(ProjectExplorer::Target *target)
{
return packageName(target) + QLatin1Char('/') + activityName(target);
......@@ -231,54 +196,6 @@ QString AndroidManager::activityName(ProjectExplorer::Target *target)
return activityElem.attribute(QLatin1String("android:name"));
}
int AndroidManager::versionCode(ProjectExplorer::Target *target)
{
QDomDocument doc;
if (!openManifest(target, doc))
return 0;
QDomElement manifestElem = doc.documentElement();
return manifestElem.attribute(QLatin1String("android:versionCode")).toInt();
}
bool AndroidManager::setVersionCode(ProjectExplorer::Target *target, int version)
{
QDomDocument doc;
if (!openManifest(target, doc))
return false;
QDomElement manifestElem = doc.documentElement();
manifestElem.setAttribute(QLatin1String("android:versionCode"), version);
return saveManifest(target, doc);
}
QString AndroidManager::versionName(ProjectExplorer::Target *target)
{
QDomDocument doc;
if (!openManifest(target, doc))
return QString();
QDomElement manifestElem = doc.documentElement();
return manifestElem.attribute(QLatin1String("android:versionName"));
}
bool AndroidManager::setVersionName(ProjectExplorer::Target *target, const QString &version)
{
QDomDocument doc;
if (!openManifest(target, doc))
return false;
QDomElement manifestElem = doc.documentElement();
manifestElem.setAttribute(QLatin1String("android:versionName"), version);
return saveManifest(target, doc);
}
bool AndroidManager::ensureIconAttribute(ProjectExplorer::Target *target)
{
QDomDocument doc;
if (!openManifest(target, doc))
return false;
QDomElement applicationElem = doc.documentElement().firstChildElement(QLatin1String("application"));
applicationElem.setAttribute(QLatin1String("android:icon"), QLatin1String("@drawable/icon"));
return saveManifest(target, doc);
}
QString AndroidManager::targetSDK(ProjectExplorer::Target *target)
{
QVariant v = target->namedSettings(QLatin1String("AndroidManager.TargetSdk"));
......@@ -322,39 +239,6 @@ QString AndroidManager::targetArch(ProjectExplorer::Target *target)
return node->singleVariableValue(Qt4ProjectManager::AndroidArchVar);
}
QIcon AndroidManager::highDpiIcon(ProjectExplorer::Target *target)
{
return icon(target, HighDPI);
}
bool AndroidManager::setHighDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
{
return ensureIconAttribute(target) &&
setIcon(target, HighDPI, iconFilePath);
}
QIcon AndroidManager::mediumDpiIcon(ProjectExplorer::Target *target)
{
return icon(target, MediumDPI);
}
bool AndroidManager::setMediumDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
{
return ensureIconAttribute(target) &&
setIcon(target, MediumDPI, iconFilePath);
}
QIcon AndroidManager::lowDpiIcon(ProjectExplorer::Target *target)
{
return icon(target, LowDPI);
}
bool AndroidManager::setLowDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath)
{
return ensureIconAttribute(target) &&
setIcon(target, LowDPI, iconFilePath);
}
Utils::FileName AndroidManager::dirPath(ProjectExplorer::Target *target)
{
return Utils::FileName::fromString(target->project()->projectDirectory()).appendPath(AndroidDirName);
......@@ -1029,20 +913,6 @@ bool AndroidManager::saveManifest(ProjectExplorer::Target *target, QDomDocument
return saveXmlFile(target, doc, manifestPath(target));
}
QString AndroidManager::iconPath(ProjectExplorer::Target *target, AndroidManager::IconType type)
{
switch (type) {
case HighDPI:
return dirPath(target).appendPath(QLatin1String("res/drawable-hdpi/icon.png")).toString();
case MediumDPI:
return dirPath(target).appendPath(QLatin1String("res/drawable-mdpi/icon.png")).toString();
case LowDPI:
return dirPath(target).appendPath(QLatin1String("res/drawable-ldpi/icon.png")).toString();
default:
return QString();
}
}
QStringList AndroidManager::libsXml(ProjectExplorer::Target *target, const QString &tag)
{
QStringList libs;
......@@ -1089,23 +959,6 @@ bool AndroidManager::setLibsXml(ProjectExplorer::Target *target, const QStringLi
}
QIcon AndroidManager::icon(ProjectExplorer::Target *target, IconType type)
{
return QIcon(iconPath(target, type));
}
bool AndroidManager::setIcon(ProjectExplorer::Target *target, IconType type, const QString &iconFileName)
{
if (!QFileInfo(iconFileName).exists())
return false;
const QString path = iconPath(target, type);
QFile::remove(path);
QDir dir;
dir.mkpath(QFileInfo(path).absolutePath());
return QFile::copy(iconFileName, path);
}
QStringList AndroidManager::dependencies(const Utils::FileName &readelfPath, const QString &lib)
{
QStringList libs;
......
......@@ -61,25 +61,9 @@ public:
static QString applicationName(ProjectExplorer::Target *target);
static bool setApplicationName(ProjectExplorer::Target *target, const QString &name);
static QStringList permissions(ProjectExplorer::Target *target);
static bool setPermissions(ProjectExplorer::Target *target, const QStringList &permissions);
static QString intentName(ProjectExplorer::Target *target);
static QString activityName(ProjectExplorer::Target *target);
static int versionCode(ProjectExplorer::Target *target);
static bool setVersionCode(ProjectExplorer::Target *target, int version);
static QString versionName(ProjectExplorer::Target *target);
static bool setVersionName(ProjectExplorer::Target *target, const QString &version);
static QIcon highDpiIcon(ProjectExplorer::Target *target);
static bool setHighDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath);
static QIcon mediumDpiIcon(ProjectExplorer::Target *target);
static bool setMediumDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath);
static QIcon lowDpiIcon(ProjectExplorer::Target *target);
static bool setLowDpiIcon(ProjectExplorer::Target *target, const QString &iconFilePath);
static bool ensureIconAttribute(ProjectExplorer::Target *target);
static QStringList availableTargetApplications(ProjectExplorer::Target *target);
static QString targetApplication(ProjectExplorer::Target *target);
static bool setTargetApplication(ProjectExplorer::Target *target, const QString &name);
......@@ -159,16 +143,6 @@ private:
};
static QString loadLocal(ProjectExplorer::Target *target, int apiLevel, ItemType item, const QString &attribute=QLatin1String("file"));
enum IconType
{
HighDPI,
MediumDPI,
LowDPI
};
static QString iconPath(ProjectExplorer::Target *target, IconType type);
static QIcon icon(ProjectExplorer::Target *target, IconType type);
static bool setIcon(ProjectExplorer::Target *target, IconType type, const QString &iconFileName);
static QStringList dependencies(const Utils::FileName &readelfPath, const QString &lib);
static int setLibraryLevel(const QString &library, LibrariesMap &mapLibs);
static bool qtLibrariesLessThan(const Library &a, const Library &b);
......
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "androidmanifestdocument.h"
#include "androidmanifesteditorwidget.h"
#include "androidconstants.h"
#include <coreplugin/editormanager/ieditor.h>
#include <QDir>
#include <QDomDocument>
using namespace Android;
using namespace Android::Internal;
AndroidManifestDocument::AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget)
: TextEditor::BaseTextDocument(),
m_editorWidget(editorWidget)
{
}
bool AndroidManifestDocument::save(QString *errorString, const QString &fileName, bool autoSave)
{
m_editorWidget->preSave();
return BaseTextDocument::save(errorString, fileName, autoSave);
}
QString AndroidManifestDocument::defaultPath() const
{
QFileInfo fi(fileName());
return fi.absolutePath();
}
QString AndroidManifestDocument::suggestedFileName() const
{
QFileInfo fi(fileName());
return fi.fileName();
}
bool AndroidManifestDocument::isModified() const
{
return BaseTextDocument::isModified() || m_editorWidget->isModified();
}
bool AndroidManifestDocument::isSaveAsAllowed() const
{
return false;
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef ANDROIDMANIFESTDOCUMENT_H
#define ANDROIDMANIFESTDOCUMENT_H
#include <coreplugin/textdocument.h>
#include <texteditor/basetextdocument.h>
namespace Android {
namespace Internal {
class AndroidManifestEditorWidget;
class AndroidManifestDocument : public TextEditor::BaseTextDocument
{
public:
explicit AndroidManifestDocument(AndroidManifestEditorWidget *editorWidget);
bool save(QString *errorString, const QString &fileName = QString(), bool autoSave = false);
QString defaultPath() const;
QString suggestedFileName() const;
bool isModified() const;
bool isSaveAsAllowed() const;
private:
AndroidManifestEditorWidget *m_editorWidget;
};
} // namespace Internal
} // namespace Android
#endif // ANDROIDMANIFESTDOCUMENT_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "androidmanifesteditor.h"
#include "androidmanifestdocument.h"
#include "androidmanifesteditorwidget.h"
#include "androidconstants.h"
#include <texteditor/texteditorconstants.h>
#include <QActionGroup>
#include <QToolBar>
using namespace Android;
using namespace Internal;
Android::Internal::AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget)
: BaseTextEditor(editorWidget),
m_document(new AndroidManifestDocument(editorWidget))
{
QToolBar *toolBar = new QToolBar;
m_actionGroup = new QActionGroup(this);
connect(m_actionGroup, SIGNAL(triggered(QAction*)), this, SLOT(changeEditorPage(QAction*)));
QAction *generalAction = toolBar->addAction(tr("General"));
generalAction->setData(AndroidManifestEditorWidget::General);
generalAction->setCheckable(true);
m_actionGroup->addAction(generalAction);
QAction *sourceAction = toolBar->addAction(tr("XML Source"));
sourceAction->setData(AndroidManifestEditorWidget::Source);
sourceAction->setCheckable(true);
m_actionGroup->addAction(sourceAction);
generalAction->setChecked(true);
insertExtraToolBarWidget(BaseTextEditor::Left, toolBar);
setContext(Core::Context(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT,
TextEditor::Constants::C_TEXTEDITOR));
}
Core::Id AndroidManifestEditor::id() const
{
return Constants::ANDROID_MANIFEST_EDITOR_ID;
}
bool AndroidManifestEditor::duplicateSupported() const
{
return false;
}
Core::IEditor *AndroidManifestEditor::duplicate(QWidget *parent)
{
Q_UNUSED(parent);
return 0;
}
bool AndroidManifestEditor::isTemporary() const
{
return false;
}
void AndroidManifestEditor::changeEditorPage(QAction *action)
{
AndroidManifestEditorWidget *editorWidget = static_cast<AndroidManifestEditorWidget *>(widget());
if (!editorWidget->setActivePage(static_cast<AndroidManifestEditorWidget::EditorPage>(action->data().toInt()))) {
foreach (QAction *action, m_actionGroup->actions()) {
if (action->data().toInt() == editorWidget->activePage()) {
action->setChecked(true);
break;
}
}
}
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef ANDROIDMANIFESTEDITOR_H
#define ANDROIDMANIFESTEDITOR_H
#include "androidmanifestdocument.h"
#include <coreplugin/editormanager/ieditor.h>
#include <texteditor/basetexteditor.h>
QT_BEGIN_NAMESPACE
class QToolBar;
QT_END_NAMESPACE
namespace Android {
namespace Internal {
class AndroidManifestEditorWidget;
class AndroidManifestEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
explicit AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget);
Core::Id id() const;
bool duplicateSupported() const;
Core::IEditor *duplicate(QWidget *parent);
bool isTemporary() const;
private slots:
void changeEditorPage(QAction *action);
private:
AndroidManifestDocument *m_document;
QString m_displayName;
QActionGroup *m_actionGroup;
};
} // namespace Internal
} // namespace Android
#endif // ANDROIDMANIFESTEDITOR_H
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "androidmanifesteditorfactory.h"
#include "androidconstants.h"
#include "androidmanifesteditorwidget.h"
#include "androidmanifesteditor.h"
#include <coreplugin/id.h>
#include <texteditor/texteditoractionhandler.h>
#include <texteditor/texteditorsettings.h>
using namespace Android;
using namespace Android::Internal;
AndroidManifestEditorFactory::AndroidManifestEditorFactory(QObject *parent)
: Core::IEditorFactory(parent),
m_actionHandler(new TextEditor::TextEditorActionHandler(Constants::ANDROID_MANIFEST_EDITOR_CONTEXT))
{
}
QStringList AndroidManifestEditorFactory::mimeTypes() const
{
return QStringList() << QLatin1String(Constants::ANDROID_MANIFEST_MIME_TYPE);
}
Core::Id AndroidManifestEditorFactory::id() const
{
return Constants::ANDROID_MANIFEST_EDITOR_ID;
}
QString AndroidManifestEditorFactory::displayName() const
{
return tr("Android Manifest editor");
}
Core::IEditor *AndroidManifestEditorFactory::createEditor(QWidget *parent)
{
AndroidManifestEditorWidget *editor = new AndroidManifestEditorWidget(parent, m_actionHandler);
TextEditor::TextEditorSettings::instance()->initializeEditor(editor);
return editor->editor();
}
/****************************************************************************
**
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights a