androidmanifesteditorwidget.h 5.86 KB
Newer Older
1 2
/****************************************************************************
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5 6 7 8 9 10 11
**
** 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
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 24 25
**
****************************************************************************/

hjk's avatar
hjk committed
26
#pragma once
27

28
#include <texteditor/texteditor.h>
29 30 31 32 33 34

#include <QAbstractListModel>
#include <QStackedWidget>
#include <QTimer>

QT_BEGIN_NAMESPACE
35
class QCheckBox;
36 37 38 39 40 41 42 43 44
class QDomDocument;
class QDomElement;
class QComboBox;
class QPushButton;
class QLabel;
class QLineEdit;
class QListView;
class QSpinBox;
class QToolButton;
45 46
class QXmlStreamReader;
class QXmlStreamWriter;
47 48 49 50 51 52 53
QT_END_NAMESPACE

namespace Core { class IEditor; }

namespace Android {
namespace Internal {
class AndroidManifestEditor;
54
class AndroidManifestEditorWidget;
55 56 57 58 59 60 61 62 63 64


class PermissionsModel: public QAbstractListModel
{
    Q_OBJECT
public:
    PermissionsModel(QObject *parent = 0 );
    void setPermissions(const QStringList &permissions);
    const QStringList &permissions();
    QModelIndex addPermission(const QString &permission);
65
    bool updatePermission(const QModelIndex &index, const QString &permission);
66 67 68 69 70 71 72 73 74 75
    void removePermission(int index);
    QVariant data(const QModelIndex &index, int role) const;

protected:
    int rowCount(const QModelIndex &parent) const;

private:
    QStringList m_permissions;
};

76
class AndroidManifestTextEditorWidget : public TextEditor::TextEditorWidget
77 78
{
public:
79
    explicit AndroidManifestTextEditorWidget(AndroidManifestEditorWidget *parent);
80 81
};

82
class AndroidManifestEditorWidget : public QStackedWidget
83 84 85 86
{
    Q_OBJECT
public:
    enum EditorPage {
87 88
        General = 0,
        Source = 1
89 90
    };

91
    explicit AndroidManifestEditorWidget();
92 93 94 95 96 97 98

    bool isModified() const;

    EditorPage activePage() const;
    bool setActivePage(EditorPage page);

    void preSave();
99
    void postSave();
100

101
    Core::IEditor *editor() const;
102
    TextEditor::TextEditorWidget *textEditorWidget() const;
103

104 105
    void setDirty(bool dirty = true);

106 107 108
signals:
    void guiChanged();

109
protected:
110
    bool eventFilter(QObject *obj, QEvent *event);
Orgad Shaneh's avatar
Orgad Shaneh committed
111 112

private:
113 114 115
    void setLDPIIcon();
    void setMDPIIcon();
    void setHDPIIcon();
116
    void defaultPermissionOrFeatureCheckBoxClicked();
117 118 119 120 121
    void addPermission();
    void removePermission();
    void updateAddRemovePermissionButtons();
    void setPackageName();
    void updateInfoBar();
122
    void updateSdkVersions();
123 124 125 126 127 128
    void startParseCheck();
    void delayedParseCheck();
    void initializePage();
    bool syncToWidgets();
    void syncToWidgets(const QDomDocument &doc);
    void syncToEditor();
129
    void updateAfterFileLoad();
130

131 132
    bool checkDocument(const QDomDocument &doc, QString *errorMessage,
                       int *errorLine, int *errorColumn);
133 134 135 136 137 138 139
    enum IconDPI { LowDPI, MediumDPI, HighDPI };
    QIcon icon(const QString &baseDir, IconDPI dpi);
    QString iconPath(const QString &baseDir, IconDPI dpi);
    void copyIcon(IconDPI dpi, const QString &baseDir, const QString &filePath);

    void updateInfoBar(const QString &errorMessage, int line, int column);
    void hideInfoBar();
Orgad Shaneh's avatar
Orgad Shaneh committed
140
    void updateTargetComboBox();
141

142 143 144 145 146
    void parseManifest(QXmlStreamReader &reader, QXmlStreamWriter &writer);
    void parseApplication(QXmlStreamReader &reader, QXmlStreamWriter &writer);
    void parseActivity(QXmlStreamReader &reader, QXmlStreamWriter &writer);
    bool parseMetaData(QXmlStreamReader &reader, QXmlStreamWriter &writer);
    void parseUsesSdk(QXmlStreamReader &reader, QXmlStreamWriter &writer);
147 148 149
    QString parseUsesPermission(QXmlStreamReader &reader,
                                QXmlStreamWriter &writer,
                                const QSet<QString> &permissions);
150
    QString parseComment(QXmlStreamReader &reader, QXmlStreamWriter &writer);
151 152
    void parseUnknownElement(QXmlStreamReader &reader, QXmlStreamWriter &writer);

153 154 155 156 157 158 159 160 161 162
    bool m_dirty; // indicates that we need to call syncToEditor()
    bool m_stayClean;
    int m_errorLine;
    int m_errorColumn;

    QLineEdit *m_packageNameLineEdit;
    QLabel *m_packageNameWarningIcon;
    QLabel *m_packageNameWarning;
    QSpinBox *m_versionCode;
    QLineEdit *m_versionNameLinedit;
163 164
    QComboBox *m_androidMinSdkVersion;
    QComboBox *m_androidTargetSdkVersion;
165 166 167

    // Application
    QLineEdit *m_appNameLineEdit;
168
    QLineEdit *m_activityNameLineEdit;
169
    QComboBox *m_targetLineEdit;
170 171 172 173 174 175 176 177
    QToolButton *m_lIconButton;
    QToolButton *m_mIconButton;
    QToolButton *m_hIconButton;
    QString m_lIconPath; // only set if the user changed the icon
    QString m_mIconPath;
    QString m_hIconPath;

    // Permissions
178
    QCheckBox *m_defaultPermissonsCheckBox;
179
    QCheckBox *m_defaultFeaturesCheckBox;
180 181 182 183 184 185 186
    PermissionsModel *m_permissionsModel;
    QListView *m_permissionsListView;
    QPushButton *m_addPermissionButton;
    QPushButton *m_removePermissionButton;
    QComboBox *m_permissionsComboBox;

    QTimer m_timerParseCheck;
187
    TextEditor::TextEditorWidget *m_textEditorWidget;
188
    AndroidManifestEditor *m_editor;
189 190 191
};
} // namespace Internal
} // namespace Android