androidsettingswidget.cpp 19.5 KB
Newer Older
BogDan Vatra's avatar
BogDan Vatra committed
1
2
/**************************************************************************
**
3
** Copyright (c) 2014 BogDan Vatra <bog_dan_ro@yahoo.com>
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
BogDan Vatra's avatar
BogDan Vatra committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
BogDan Vatra's avatar
BogDan Vatra committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** 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
BogDan Vatra's avatar
BogDan Vatra committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
29
30
31
32
33
34
35

#include "androidsettingswidget.h"

#include "ui_androidsettingswidget.h"

#include "androidconfigurations.h"
#include "androidconstants.h"
Daniel Teske's avatar
Daniel Teske committed
36
#include "androidtoolchain.h"
BogDan Vatra's avatar
BogDan Vatra committed
37

38
#include <utils/environment.h>
39
#include <utils/hostosinfo.h>
40
#include <utils/pathchooser.h>
Daniel Teske's avatar
Daniel Teske committed
41
42
43
44
45
#include <projectexplorer/toolchainmanager.h>
#include <projectexplorer/kitmanager.h>
#include <projectexplorer/kitinformation.h>
#include <qtsupport/qtkitinformation.h>
#include <qtsupport/qtversionmanager.h>
46

47
48
#include <utils/pathchooser.h>

BogDan Vatra's avatar
BogDan Vatra committed
49
50
51
52
#include <QFile>
#include <QTextStream>
#include <QProcess>

53
#include <QDesktopServices>
BogDan Vatra's avatar
BogDan Vatra committed
54
55
56
#include <QFileDialog>
#include <QMessageBox>
#include <QModelIndex>
57
#include <QtCore/QUrl>
58
#include <QtConcurrentRun>
BogDan Vatra's avatar
BogDan Vatra committed
59
60
61
62

namespace Android {
namespace Internal {

hjk's avatar
hjk committed
63
void AvdModel::setAvdList(const QVector<AndroidDeviceInfo> &list)
BogDan Vatra's avatar
BogDan Vatra committed
64
{
65
    beginResetModel();
BogDan Vatra's avatar
BogDan Vatra committed
66
    m_list = list;
67
    endResetModel();
BogDan Vatra's avatar
BogDan Vatra committed
68
69
}

70
71
72
73
74
75
76
77
78
QModelIndex AvdModel::indexForAvdName(const QString &avdName) const
{
    for (int i = 0; i < m_list.size(); ++i) {
        if (m_list.at(i).serialNumber == avdName)
            return index(i, 0);
    }
    return QModelIndex();
}

79
QString AvdModel::avdName(const QModelIndex &index) const
BogDan Vatra's avatar
BogDan Vatra committed
80
{
81
    return m_list.at(index.row()).serialNumber;
BogDan Vatra's avatar
BogDan Vatra committed
82
83
}

hjk's avatar
hjk committed
84
QVariant AvdModel::data(const QModelIndex &index, int role) const
BogDan Vatra's avatar
BogDan Vatra committed
85
86
87
88
89
90
91
92
{
    if (role != Qt::DisplayRole || !index.isValid())
        return QVariant();
    switch (index.column()) {
        case 0:
            return m_list[index.row()].serialNumber;
        case 1:
            return QString::fromLatin1("API %1").arg(m_list[index.row()].sdk);
93
94
95
96
        case 2: {
            QStringList cpuAbis = m_list[index.row()].cpuAbi;
            return cpuAbis.isEmpty() ? QVariant() : QVariant(cpuAbis.first());
        }
BogDan Vatra's avatar
BogDan Vatra committed
97
98
99
100
    }
    return QVariant();
}

hjk's avatar
hjk committed
101
QVariant AvdModel::headerData(int section, Qt::Orientation orientation, int role) const
BogDan Vatra's avatar
BogDan Vatra committed
102
103
104
105
{
    if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
        switch (section) {
            case 0:
Friedemann Kleint's avatar
Friedemann Kleint committed
106
                //: AVD - Android Virtual Device
BogDan Vatra's avatar
BogDan Vatra committed
107
108
109
110
111
112
113
114
115
116
                return tr("AVD Name");
            case 1:
                return tr("AVD Target");
            case 2:
                return tr("CPU/ABI");
        }
    }
    return QAbstractItemModel::headerData(section, orientation, role );
}

hjk's avatar
hjk committed
117
int AvdModel::rowCount(const QModelIndex &/*parent*/) const
BogDan Vatra's avatar
BogDan Vatra committed
118
119
120
121
{
    return m_list.size();
}

hjk's avatar
hjk committed
122
int AvdModel::columnCount(const QModelIndex &/*parent*/) const
BogDan Vatra's avatar
BogDan Vatra committed
123
124
125
126
127
128
{
    return 3;
}

AndroidSettingsWidget::AndroidSettingsWidget(QWidget *parent)
    : QWidget(parent),
Daniel Teske's avatar
Daniel Teske committed
129
130
131
      m_sdkState(NotSet),
      m_ndkState(NotSet),
      m_javaState(NotSet),
BogDan Vatra's avatar
BogDan Vatra committed
132
      m_ui(new Ui_AndroidSettingsWidget),
Daniel Teske's avatar
Daniel Teske committed
133
      m_androidConfig(AndroidConfigurations::currentConfig())
BogDan Vatra's avatar
BogDan Vatra committed
134
{
Daniel Teske's avatar
Daniel Teske committed
135
    m_ui->setupUi(this);
BogDan Vatra's avatar
BogDan Vatra committed
136

137
138
139
140
    m_ui->SDKLocationPathChooser->setFileName(m_androidConfig.sdkLocation());
    m_ui->SDKLocationPathChooser->setPromptDialogTitle(tr("Select Android SDK folder"));
    m_ui->NDKLocationPathChooser->setFileName(m_androidConfig.ndkLocation());
    m_ui->NDKLocationPathChooser->setPromptDialogTitle(tr("Select Android NDK folder"));
BogDan Vatra's avatar
BogDan Vatra committed
141

142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
    QString dir;
    QString filter;
    if (Utils::HostOsInfo::isWindowsHost()) {
        dir = QDir::homePath() + QLatin1String("/ant.bat");
        filter = QLatin1String("ant (ant.bat)");
    } else if (Utils::HostOsInfo::isMacHost()) {
        // work around QTBUG-7739 that prohibits filters that don't start with *
        dir = QLatin1String("/usr/bin/ant");
        filter = QLatin1String("ant (*ant)");
    } else {
        dir = QLatin1String("/usr/bin/ant");
        filter = QLatin1String("ant (ant)");
    }
    m_ui->AntLocationPathChooser->setFileName(m_androidConfig.antLocation());
    m_ui->AntLocationPathChooser->setExpectedKind(Utils::PathChooser::Command);
    m_ui->AntLocationPathChooser->setPromptDialogTitle(tr("Select ant Script"));
    m_ui->AntLocationPathChooser->setInitialBrowsePathBackup(dir);
    m_ui->AntLocationPathChooser->setPromptDialogFilter(filter);

    m_ui->OpenJDKLocationPathChooser->setFileName(m_androidConfig.openJDKLocation());
    m_ui->OpenJDKLocationPathChooser->setPromptDialogTitle(tr("Select JDK Path"));
Daniel Teske's avatar
Daniel Teske committed
163
164
    m_ui->DataPartitionSizeSpinBox->setValue(m_androidConfig.partitionSize());
    m_ui->CreateKitCheckBox->setChecked(m_androidConfig.automaticKitCreation());
BogDan Vatra's avatar
BogDan Vatra committed
165
    m_ui->AVDTableView->setModel(&m_AVDModel);
Daniel Teske's avatar
Daniel Teske committed
166
    m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
BogDan Vatra's avatar
BogDan Vatra committed
167
168
    m_ui->AVDTableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
    m_ui->AVDTableView->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
Daniel Teske's avatar
Daniel Teske committed
169

170
171
    m_ui->downloadAntToolButton->setVisible(!Utils::HostOsInfo::isLinuxHost());
    m_ui->downloadOpenJDKToolButton->setVisible(!Utils::HostOsInfo::isLinuxHost());
Daniel Teske's avatar
Daniel Teske committed
172
173
174

    check(All);
    applyToUi(All);
175
176
177

    connect(&m_futureWatcher, SIGNAL(finished()),
            this, SLOT(avdAdded()));
BogDan Vatra's avatar
BogDan Vatra committed
178
179
}

Daniel Teske's avatar
Daniel Teske committed
180
AndroidSettingsWidget::~AndroidSettingsWidget()
BogDan Vatra's avatar
BogDan Vatra committed
181
{
Daniel Teske's avatar
Daniel Teske committed
182
    delete m_ui;
183
    m_futureWatcher.waitForFinished();
BogDan Vatra's avatar
BogDan Vatra committed
184
185
}

Daniel Teske's avatar
Daniel Teske committed
186
void AndroidSettingsWidget::check(AndroidSettingsWidget::Mode mode)
BogDan Vatra's avatar
BogDan Vatra committed
187
{
Daniel Teske's avatar
Daniel Teske committed
188
189
    if (mode & Sdk) {
        m_sdkState = Okay;
190
        if (m_androidConfig.sdkLocation().isEmpty())
Daniel Teske's avatar
Daniel Teske committed
191
            m_sdkState = NotSet;
192
193
        else if (!(sdkLocationIsValid() && sdkPlatformToolsInstalled()))
            m_sdkState = Error;
194
    }
Daniel Teske's avatar
Daniel Teske committed
195
196
197
198
199
200
201
202
203
204
205
206

    if (mode & Ndk) {
        m_ndkState = Okay;
        Utils::FileName platformPath = m_androidConfig.ndkLocation();
        Utils::FileName toolChainPath = m_androidConfig.ndkLocation();
        Utils::FileName sourcesPath = m_androidConfig.ndkLocation();
        if (m_androidConfig.ndkLocation().isEmpty()) {
            m_ndkState = NotSet;
        } else if (!platformPath.appendPath(QLatin1String("platforms")).toFileInfo().exists()
                || !toolChainPath.appendPath(QLatin1String("toolchains")).toFileInfo().exists()
                || !sourcesPath.appendPath(QLatin1String("sources/cxx-stl")).toFileInfo().exists()) {
            m_ndkState = Error;
207
208
209
210
211
            m_ndkErrorMessage = tr("\"%1\" does not seem to be an Android NDK top folder.")
                    .arg(m_androidConfig.ndkLocation().toUserOutput());
        } else if (platformPath.toString().contains(QLatin1String(" "))) {
            m_ndkState = Error;
            m_ndkErrorMessage = tr("The Android NDK cannot be installed into a path with spaces.");
Daniel Teske's avatar
Daniel Teske committed
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
        } else {
            QList<AndroidToolChainFactory::AndroidToolChainInformation> compilerPaths
                    = AndroidToolChainFactory::toolchainPathsForNdk(m_androidConfig.ndkLocation());
            m_ndkCompilerCount = compilerPaths.count();


            // See if we have qt versions for those toolchains
            QSet<ProjectExplorer::Abi::Architecture> toolchainsForArch;
            foreach (const AndroidToolChainFactory::AndroidToolChainInformation &ati, compilerPaths)
                toolchainsForArch.insert(ati.architecture);

            QSet<ProjectExplorer::Abi::Architecture> qtVersionsForArch;
            foreach (QtSupport::BaseQtVersion *qtVersion, QtSupport::QtVersionManager::versions()) {
                if (qtVersion->type() != QLatin1String(Constants::ANDROIDQT) || qtVersion->qtAbis().isEmpty())
                    continue;
                qtVersionsForArch.insert(qtVersion->qtAbis().first().architecture());
            }

            QSet<ProjectExplorer::Abi::Architecture> missingQtArchs = toolchainsForArch.subtract(qtVersionsForArch);
            if (missingQtArchs.isEmpty()) {
                m_ndkMissingQtArchs.clear();
            } else {
                if (missingQtArchs.count() == 1) {
                    m_ndkMissingQtArchs = tr("Qt version for architecture %1 is missing.\n"
                                             "To add the Qt version, select Options > Build & Run > Qt Versions.")
                            .arg(ProjectExplorer::Abi::toString((*missingQtArchs.constBegin())));
                } else {
                    QStringList missingArchs;
                    foreach (ProjectExplorer::Abi::Architecture arch, missingQtArchs)
                        missingArchs.append(ProjectExplorer::Abi::toString(arch));
                    m_ndkMissingQtArchs = tr("Qt versions for architectures %1 are missing.\n"
                                             "To add the Qt versions, select Options > Build & Run > Qt Versions.")
                            .arg(missingArchs.join(QLatin1String(", ")));
                }
            }
        }
BogDan Vatra's avatar
BogDan Vatra committed
248
249
    }

Daniel Teske's avatar
Daniel Teske committed
250
251
252
253
254
255
    if (mode & Java) {
        m_javaState = Okay;
        if (m_androidConfig.openJDKLocation().isEmpty()) {
            m_javaState = NotSet;
        } else {
            Utils::FileName bin = m_androidConfig.openJDKLocation();
256
            bin.appendPath(QLatin1String("bin/javac" QTC_HOST_EXE_SUFFIX));
Daniel Teske's avatar
Daniel Teske committed
257
258
259
260
            if (!m_androidConfig.openJDKLocation().toFileInfo().exists()
                    || !bin.toFileInfo().exists())
                m_javaState = Error;
        }
Daniel Teske's avatar
Daniel Teske committed
261
262
263
    }
}

Daniel Teske's avatar
Daniel Teske committed
264
void AndroidSettingsWidget::applyToUi(AndroidSettingsWidget::Mode mode)
BogDan Vatra's avatar
BogDan Vatra committed
265
{
Daniel Teske's avatar
Daniel Teske committed
266
267
268
269
    if (mode & Sdk) {
        if (m_sdkState == Error) {
            m_ui->sdkWarningIconLabel->setVisible(true);
            m_ui->sdkWarningLabel->setVisible(true);
270
            Utils::FileName location = Utils::FileName::fromUserInput(m_ui->SDKLocationPathChooser->rawPath());
271
272
273
274
            if (sdkLocationIsValid())
                m_ui->sdkWarningLabel->setText(tr("The Platform tools are missing. Please use the Android SDK Manager to install them."));
            else
                m_ui->sdkWarningLabel->setText(tr("\"%1\" does not seem to be an Android SDK top folder.").arg(location.toUserOutput()));
Daniel Teske's avatar
Daniel Teske committed
275
276
277
278
        } else {
            m_ui->sdkWarningIconLabel->setVisible(false);
            m_ui->sdkWarningLabel->setVisible(false);
        }
BogDan Vatra's avatar
BogDan Vatra committed
279
    }
Daniel Teske's avatar
Daniel Teske committed
280

Daniel Teske's avatar
Daniel Teske committed
281
282
283
284
285
286
287
    if (mode & Ndk) {
        if (m_ndkState == NotSet) {
            m_ui->ndkWarningIconLabel->setVisible(false);
            m_ui->toolchainFoundLabel->setVisible(false);
            m_ui->kitWarningIconLabel->setVisible(false);
            m_ui->kitWarningLabel->setVisible(false);
        } else if (m_ndkState == Error) {
288
            m_ui->toolchainFoundLabel->setText(m_ndkErrorMessage);
Daniel Teske's avatar
Daniel Teske committed
289
290
            m_ui->toolchainFoundLabel->setVisible(true);
            m_ui->ndkWarningIconLabel->setVisible(true);
291
292
            m_ui->kitWarningIconLabel->setVisible(false);
            m_ui->kitWarningLabel->setVisible(false);
Daniel Teske's avatar
Daniel Teske committed
293
294
295
296
297
298
299
300
301
        } else {
            if (m_ndkCompilerCount > 0) {
                m_ui->ndkWarningIconLabel->setVisible(false);
                m_ui->toolchainFoundLabel->setText(tr("Found %n toolchains for this NDK.", 0, m_ndkCompilerCount));
                m_ui->toolchainFoundLabel->setVisible(true);
            } else {
                m_ui->ndkWarningIconLabel->setVisible(false);
                m_ui->toolchainFoundLabel->setVisible(false);
            }
Daniel Teske's avatar
Daniel Teske committed
302

Daniel Teske's avatar
Daniel Teske committed
303
304
305
306
307
308
309
310
311
312
            if (m_ndkMissingQtArchs.isEmpty()) {
                m_ui->kitWarningIconLabel->setVisible(false);
                m_ui->kitWarningLabel->setVisible(false);
            } else {
                m_ui->kitWarningIconLabel->setVisible(true);
                m_ui->kitWarningLabel->setVisible(true);
                m_ui->kitWarningLabel->setText(m_ndkMissingQtArchs);
            }
        }
    }
Daniel Teske's avatar
Daniel Teske committed
313

Daniel Teske's avatar
Daniel Teske committed
314
315
316
317
318
319
320
    if (mode & Java) {
        Utils::FileName location = m_androidConfig.openJDKLocation();
        bool error = m_javaState == Error;
        m_ui->jdkWarningIconLabel->setVisible(error);
        m_ui->jdkWarningLabel->setVisible(error);
        if (error)
            m_ui->jdkWarningLabel->setText(tr("\"%1\" does not seem to be a JDK folder.").arg(location.toUserOutput()));
Daniel Teske's avatar
Daniel Teske committed
321
322
    }

Daniel Teske's avatar
Daniel Teske committed
323
324
325
    if (mode & Sdk || mode & Java) {
        if (m_sdkState == Okay && m_javaState == Okay) {
            m_ui->AVDManagerFrame->setEnabled(true);
Daniel Teske's avatar
Daniel Teske committed
326
        } else {
Daniel Teske's avatar
Daniel Teske committed
327
            m_ui->AVDManagerFrame->setEnabled(false);
Daniel Teske's avatar
Daniel Teske committed
328
        }
Daniel Teske's avatar
Daniel Teske committed
329
330

        m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
Daniel Teske's avatar
Daniel Teske committed
331
    }
Daniel Teske's avatar
Daniel Teske committed
332
}
Daniel Teske's avatar
Daniel Teske committed
333

334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
bool AndroidSettingsWidget::sdkLocationIsValid() const
{
    Utils::FileName androidExe = m_androidConfig.sdkLocation();
    Utils::FileName androidBat = m_androidConfig.sdkLocation();
    Utils::FileName emulator = m_androidConfig.sdkLocation();
    return (androidExe.appendPath(QLatin1String("/tools/android" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists()
            || androidBat.appendPath(QLatin1String("/tools/android" ANDROID_BAT_SUFFIX)).toFileInfo().exists())
            && emulator.appendPath(QLatin1String("/tools/emulator" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
}

bool AndroidSettingsWidget::sdkPlatformToolsInstalled() const
{
    Utils::FileName adb = m_androidConfig.sdkLocation();
    return adb.appendPath(QLatin1String("platform-tools/adb" QTC_HOST_EXE_SUFFIX)).toFileInfo().exists();
}

Daniel Teske's avatar
Daniel Teske committed
350
351
352
353
354
355
356
357
358
void AndroidSettingsWidget::saveSettings()
{
    sdkLocationEditingFinished();
    ndkLocationEditingFinished();
    antLocationEditingFinished();
    openJDKLocationEditingFinished();
    dataPartitionSizeEditingFinished();
    AndroidConfigurations::setConfig(m_androidConfig);
}
BogDan Vatra's avatar
BogDan Vatra committed
359

Daniel Teske's avatar
Daniel Teske committed
360
361
362
363
364
365
366
367
int indexOf(const QList<AndroidToolChainFactory::AndroidToolChainInformation> &list, const Utils::FileName &f)
{
    int end = list.count();
    for (int i = 0; i < end; ++i) {
        if (list.at(i).compilerCommand == f)
            return i;
    }
    return -1;
BogDan Vatra's avatar
BogDan Vatra committed
368
369
370
371
}

void AndroidSettingsWidget::sdkLocationEditingFinished()
{
372
    m_androidConfig.setSdkLocation(Utils::FileName::fromUserInput(m_ui->SDKLocationPathChooser->rawPath()));
Daniel Teske's avatar
Daniel Teske committed
373
374
375
376
377
378
379

    check(Sdk);

    if (m_sdkState == Okay)
        searchForAnt(m_androidConfig.sdkLocation());

    applyToUi(Sdk);
BogDan Vatra's avatar
BogDan Vatra committed
380
381
382
383
}

void AndroidSettingsWidget::ndkLocationEditingFinished()
{
384
    m_androidConfig.setNdkLocation(Utils::FileName::fromUserInput(m_ui->NDKLocationPathChooser->rawPath()));
Daniel Teske's avatar
Daniel Teske committed
385
386
387
388
389
390
391

    check(Ndk);

    if (m_ndkState == Okay)
        searchForAnt(m_androidConfig.ndkLocation());

    applyToUi(Ndk);
BogDan Vatra's avatar
BogDan Vatra committed
392
393
}

Daniel Teske's avatar
Daniel Teske committed
394
void AndroidSettingsWidget::searchForAnt(const Utils::FileName &location)
Daniel Teske's avatar
Daniel Teske committed
395
{
Daniel Teske's avatar
Daniel Teske committed
396
    if (!m_androidConfig.antLocation().isEmpty())
Daniel Teske's avatar
Daniel Teske committed
397
398
399
            return;
    if (location.isEmpty())
        return;
Daniel Teske's avatar
Daniel Teske committed
400
    QDir parentFolder = location.toFileInfo().absoluteDir();
Daniel Teske's avatar
Daniel Teske committed
401
402
    foreach (const QString &file, parentFolder.entryList()) {
        if (file.startsWith(QLatin1String("apache-ant"))) {
403
            Utils::FileName ant = Utils::FileName::fromString(parentFolder.absolutePath());
404
405
406
407
408
            ant.appendPath(file).appendPath(QLatin1String("bin"));
            if (Utils::HostOsInfo::isWindowsHost())
                ant.appendPath(QLatin1String("ant.bat"));
            else
                ant.appendPath(QLatin1String("ant"));
409
            if (ant.toFileInfo().exists()) {
Daniel Teske's avatar
Daniel Teske committed
410
                m_androidConfig.setAntLocation(ant);
411
                m_ui->AntLocationPathChooser->setFileName(ant);
Daniel Teske's avatar
Daniel Teske committed
412
413
414
415
416
            }
        }
    }
}

BogDan Vatra's avatar
BogDan Vatra committed
417
418
void AndroidSettingsWidget::antLocationEditingFinished()
{
419
    m_androidConfig.setAntLocation(Utils::FileName::fromUserInput(m_ui->AntLocationPathChooser->rawPath()));
BogDan Vatra's avatar
BogDan Vatra committed
420
421
422
423
}

void AndroidSettingsWidget::openJDKLocationEditingFinished()
{
424
    m_androidConfig.setOpenJDKLocation(Utils::FileName::fromUserInput(m_ui->OpenJDKLocationPathChooser->rawPath()));
Daniel Teske's avatar
Daniel Teske committed
425
426
427

    check(Java);
    applyToUi(Java);
BogDan Vatra's avatar
BogDan Vatra committed
428
429
}

430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
void AndroidSettingsWidget::openSDKDownloadUrl()
{
    QDesktopServices::openUrl(QUrl::fromUserInput(QLatin1String("http://developer.android.com/sdk")));
}

void AndroidSettingsWidget::openNDKDownloadUrl()
{
    QDesktopServices::openUrl(QUrl::fromUserInput(QLatin1String("http://developer.android.com/tools/sdk/ndk/index.html#Downloads")));
}

void AndroidSettingsWidget::openAntDownloadUrl()
{
    QDesktopServices::openUrl(QUrl::fromUserInput(QLatin1String("http://ant.apache.org/bindownload.cgi")));
}

void AndroidSettingsWidget::openOpenJDKDownloadUrl()
{
    QDesktopServices::openUrl(QUrl::fromUserInput(QLatin1String("http://www.oracle.com/technetwork/java/javase/downloads")));
}

BogDan Vatra's avatar
BogDan Vatra committed
450
451
void AndroidSettingsWidget::addAVD()
{
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
    m_ui->AVDAddPushButton->setEnabled(false);
    AndroidConfig::CreateAvdInfo info = m_androidConfig.gatherCreateAVDInfo(this);

    if (info.target.isEmpty()) {
        m_ui->AVDAddPushButton->setEnabled(true);
        return;
    }

    m_futureWatcher.setFuture(m_androidConfig.createAVD(info));
}

void AndroidSettingsWidget::avdAdded()
{
    m_ui->AVDAddPushButton->setEnabled(true);
    AndroidConfig::CreateAvdInfo info = m_futureWatcher.result();
    if (!info.error.isEmpty()) {
        QMessageBox::critical(this, QApplication::translate("AndroidConfig", "Error Creating AVD"), info.error);
        return;
    }

Daniel Teske's avatar
Daniel Teske committed
472
    m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
473
    m_ui->AVDTableView->setCurrentIndex(m_AVDModel.indexForAvdName(info.name));
BogDan Vatra's avatar
BogDan Vatra committed
474
475
476
477
}

void AndroidSettingsWidget::removeAVD()
{
478
479
480
481
482
483
484
485
    QString avdName = m_AVDModel.avdName(m_ui->AVDTableView->currentIndex());
    if (QMessageBox::question(this, tr("Remove Android Virtual Device"),
                              tr("Remove device \"%1\"? This cannot be undone.").arg(avdName),
                              QMessageBox::Yes | QMessageBox::No)
            == QMessageBox::No)
        return;

    m_androidConfig.removeAVD(avdName);
Daniel Teske's avatar
Daniel Teske committed
486
    m_AVDModel.setAvdList(m_androidConfig.androidVirtualDevices());
487
    avdActivated(m_ui->AVDTableView->currentIndex());
BogDan Vatra's avatar
BogDan Vatra committed
488
489
490
491
}

void AndroidSettingsWidget::startAVD()
{
Daniel Teske's avatar
Daniel Teske committed
492
    m_androidConfig.startAVDAsync(m_AVDModel.avdName(m_ui->AVDTableView->currentIndex()));
BogDan Vatra's avatar
BogDan Vatra committed
493
494
495
496
497
498
499
500
501
502
}

void AndroidSettingsWidget::avdActivated(QModelIndex index)
{
    m_ui->AVDRemovePushButton->setEnabled(index.isValid());
    m_ui->AVDStartPushButton->setEnabled(index.isValid());
}

void AndroidSettingsWidget::dataPartitionSizeEditingFinished()
{
Daniel Teske's avatar
Daniel Teske committed
503
    m_androidConfig.setPartitionSize(m_ui->DataPartitionSizeSpinBox->value());
BogDan Vatra's avatar
BogDan Vatra committed
504
505
}

Daniel Teske's avatar
Daniel Teske committed
506
507
void AndroidSettingsWidget::createKitToggled()
{
Daniel Teske's avatar
Daniel Teske committed
508
    m_androidConfig.setAutomaticKitCreation(m_ui->CreateKitCheckBox->isChecked());
Daniel Teske's avatar
Daniel Teske committed
509
510
}

BogDan Vatra's avatar
BogDan Vatra committed
511
512
513
514
515
void AndroidSettingsWidget::manageAVD()
{
    QProcess *avdProcess = new QProcess();
    connect(this, SIGNAL(destroyed()), avdProcess, SLOT(deleteLater()));
    connect(avdProcess, SIGNAL(finished(int)), avdProcess, SLOT(deleteLater()));
516

Daniel Teske's avatar
Daniel Teske committed
517
518
    avdProcess->setProcessEnvironment(m_androidConfig.androidToolEnvironment().toProcessEnvironment());
    QString executable = m_androidConfig.androidToolPath().toString();
519
520
521
    QStringList arguments = QStringList() << QLatin1String("avd");

    avdProcess->start(executable, arguments);
BogDan Vatra's avatar
BogDan Vatra committed
522
523
524
525
526
}


} // namespace Internal
} // namespace Android