2013-04-25 16:02:17 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2017-01-27 11:00:20 +01:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
2016-01-15 14:57:40 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
** 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
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** 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.
|
2013-04-25 16:02:17 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "iossettingswidget.h"
|
|
|
|
|
#include "ui_iossettingswidget.h"
|
|
|
|
|
|
2017-01-27 11:00:20 +01:00
|
|
|
#include "createsimulatordialog.h"
|
2013-04-25 16:02:17 +02:00
|
|
|
#include "iosconfigurations.h"
|
2017-01-27 11:00:20 +01:00
|
|
|
#include "simulatorinfomodel.h"
|
|
|
|
|
#include "simulatoroperationdialog.h"
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2017-01-27 11:00:20 +01:00
|
|
|
#include <utils/algorithm.h>
|
|
|
|
|
#include <utils/runextensions.h>
|
2013-04-25 16:02:17 +02:00
|
|
|
|
2017-01-27 11:00:20 +01:00
|
|
|
#include <QDateTime>
|
|
|
|
|
#include <QInputDialog>
|
2013-04-25 16:02:17 +02:00
|
|
|
#include <QMessageBox>
|
2017-01-27 11:00:20 +01:00
|
|
|
#include <QPointer>
|
2017-07-06 13:20:18 +02:00
|
|
|
#include <QSortFilterProxyModel>
|
2017-01-27 11:00:20 +01:00
|
|
|
|
|
|
|
|
static const int simStartWarnCount = 4;
|
2013-04-25 16:02:17 +02:00
|
|
|
|
|
|
|
|
namespace Ios {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2017-01-27 11:00:20 +01:00
|
|
|
using namespace std::placeholders;
|
|
|
|
|
|
|
|
|
|
static SimulatorInfoList selectedSimulators(const QTreeView *deviceTreeView)
|
|
|
|
|
{
|
|
|
|
|
SimulatorInfoList list;
|
|
|
|
|
QItemSelectionModel *selectionModel = deviceTreeView->selectionModel();
|
|
|
|
|
for (QModelIndex index: selectionModel->selectedRows())
|
|
|
|
|
list << deviceTreeView->model()->data(index, Qt::UserRole).value<SimulatorInfo>();
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void onSimOperation(const SimulatorInfo &simInfo, SimulatorOperationDialog* dlg,
|
|
|
|
|
const QString &contextStr, const SimulatorControl::ResponseData &response)
|
|
|
|
|
{
|
|
|
|
|
dlg->addMessage(simInfo, response, contextStr);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-25 16:02:17 +02:00
|
|
|
IosSettingsWidget::IosSettingsWidget(QWidget *parent)
|
|
|
|
|
: QWidget(parent),
|
2016-11-25 11:11:27 +01:00
|
|
|
m_ui(new Ui::IosSettingsWidget),
|
2017-07-06 13:20:18 +02:00
|
|
|
m_simControl(new SimulatorControl(this))
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2017-01-27 11:00:20 +01:00
|
|
|
m_ui->setupUi(this);
|
2017-07-06 13:20:18 +02:00
|
|
|
auto proxyModel = new QSortFilterProxyModel(this);
|
|
|
|
|
proxyModel->setSourceModel(new SimulatorInfoModel(this));
|
|
|
|
|
m_ui->deviceView->setModel(proxyModel);
|
2017-01-27 11:00:20 +01:00
|
|
|
m_ui->deviceView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
|
|
|
|
|
m_ui->pathWidget->setExpectedKind(Utils::PathChooser::ExistingDirectory);
|
|
|
|
|
m_ui->pathWidget->lineEdit()->setReadOnly(true);
|
|
|
|
|
m_ui->pathWidget->setFileName(IosConfigurations::screenshotDir());
|
|
|
|
|
m_ui->pathWidget->addButton(tr("Screenshot"), this,
|
|
|
|
|
std::bind(&IosSettingsWidget::onScreenshot, this));
|
|
|
|
|
|
|
|
|
|
m_ui->deviceAskCheckBox->setChecked(!IosConfigurations::ignoreAllDevices());
|
|
|
|
|
|
|
|
|
|
connect(m_ui->startButton, &QPushButton::clicked, this, &IosSettingsWidget::onStart);
|
|
|
|
|
connect(m_ui->createButton, &QPushButton::clicked, this, &IosSettingsWidget::onCreate);
|
|
|
|
|
connect(m_ui->renameButton, &QPushButton::clicked, this, &IosSettingsWidget::onRename);
|
|
|
|
|
connect(m_ui->resetButton, &QPushButton::clicked, this, &IosSettingsWidget::onReset);
|
|
|
|
|
connect(m_ui->deleteButton, &QPushButton::clicked, this, &IosSettingsWidget::onDelete);
|
|
|
|
|
|
|
|
|
|
connect(m_ui->deviceView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
|
|
|
|
&IosSettingsWidget::onSelectionChanged);
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IosSettingsWidget::~IosSettingsWidget()
|
|
|
|
|
{
|
|
|
|
|
delete m_ui;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-27 11:00:20 +01:00
|
|
|
/*!
|
|
|
|
|
Called on start button click. Selected simulator devices are started. Multiple devices can be
|
|
|
|
|
started simultaneously provided they in shutdown state.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onStart()
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2017-01-27 11:00:20 +01:00
|
|
|
const SimulatorInfoList simulatorInfoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
if (simulatorInfoList.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (simulatorInfoList.count() > simStartWarnCount) {
|
|
|
|
|
const QString message = tr("You are trying to launch %n simulators simultaneously. This "
|
|
|
|
|
"will take significant system resources. Do you really want to "
|
|
|
|
|
"continue?", "", simulatorInfoList.count());
|
|
|
|
|
const int buttonCode = QMessageBox::warning(this, tr("Simulator Start"), message,
|
|
|
|
|
QMessageBox::Ok | QMessageBox::Abort,
|
|
|
|
|
QMessageBox::Abort);
|
|
|
|
|
|
|
|
|
|
if (buttonCode == QMessageBox::Abort)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
2018-01-09 17:39:06 +01:00
|
|
|
statusDialog->addMessage(tr("Starting %n simulator device(s)...", "", simulatorInfoList.count()),
|
2017-01-27 11:00:20 +01:00
|
|
|
Utils::NormalMessageFormat);
|
|
|
|
|
|
|
|
|
|
QList<QFuture<void>> futureList;
|
|
|
|
|
foreach (const SimulatorInfo &info, simulatorInfoList) {
|
|
|
|
|
if (!info.isShutdown()) {
|
2017-07-28 09:57:18 +02:00
|
|
|
statusDialog->addMessage(tr("Cannot start simulator (%1, %2) in current state: %3")
|
2017-01-27 11:00:20 +01:00
|
|
|
.arg(info.name).arg(info.runtimeName).arg(info.state),
|
|
|
|
|
Utils::StdErrFormat);
|
|
|
|
|
} else {
|
|
|
|
|
futureList << Utils::onResultReady(m_simControl->startSimulator(info.identifier),
|
|
|
|
|
std::bind(onSimOperation, info, statusDialog,
|
|
|
|
|
tr("simulator start"), _1));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusDialog->addFutures(futureList);
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Called on create button click. User is presented with the create simulator dialog and with the
|
|
|
|
|
selected options a new device is created.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onCreate()
|
|
|
|
|
{
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
statusDialog->addMessage(tr("Creating simulator device..."), Utils::NormalMessageFormat);
|
2017-09-07 17:05:47 +02:00
|
|
|
const auto onSimulatorCreate = [statusDialog](const QString &name,
|
2017-01-27 11:00:20 +01:00
|
|
|
const SimulatorControl::ResponseData &response) {
|
|
|
|
|
if (response.success) {
|
2017-07-28 09:57:18 +02:00
|
|
|
statusDialog->addMessage(tr("Simulator device (%1) created.\nUDID: %2")
|
2017-01-27 11:00:20 +01:00
|
|
|
.arg(name).arg(response.simUdid), Utils::StdOutFormat);
|
|
|
|
|
} else {
|
2017-07-28 09:57:18 +02:00
|
|
|
statusDialog->addMessage(tr("Simulator device (%1) creation failed.\nError: %2").
|
2018-05-14 16:46:23 +02:00
|
|
|
arg(name).arg(response.commandOutput),
|
2017-01-27 11:00:20 +01:00
|
|
|
Utils::StdErrFormat);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CreateSimulatorDialog createDialog(this);
|
|
|
|
|
if (createDialog.exec() == QDialog::Accepted) {
|
|
|
|
|
QFuture<void> f = Utils::onResultReady(
|
|
|
|
|
m_simControl->createSimulator(
|
|
|
|
|
createDialog.name(),
|
|
|
|
|
createDialog.deviceType(),
|
|
|
|
|
createDialog.runtime()),
|
|
|
|
|
std::bind(onSimulatorCreate, createDialog.name(), _1));
|
|
|
|
|
statusDialog->addFutures({ f });
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Called on reset button click. Contents and settings of the selected devices are erased. Multiple
|
|
|
|
|
devices can be erased simultaneously provided they in shutdown state.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onReset()
|
|
|
|
|
{
|
|
|
|
|
const SimulatorInfoList simulatorInfoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
if (simulatorInfoList.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int userInput = QMessageBox::question(this, tr("Reset"),
|
|
|
|
|
tr("Do you really want to reset the contents and settings"
|
2018-01-09 17:39:06 +01:00
|
|
|
" of the %n selected device(s)?", "",
|
2017-01-27 11:00:20 +01:00
|
|
|
simulatorInfoList.count()));
|
|
|
|
|
if (userInput == QMessageBox::No)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
statusDialog->addMessage(tr("Resetting contents and settings..."), Utils::NormalMessageFormat);
|
|
|
|
|
|
|
|
|
|
QList<QFuture<void>> futureList;
|
|
|
|
|
foreach (const SimulatorInfo &info, simulatorInfoList) {
|
|
|
|
|
futureList << Utils::onResultReady(m_simControl->resetSimulator(info.identifier),
|
|
|
|
|
std::bind(onSimOperation, info, statusDialog,
|
|
|
|
|
tr("simulator reset"), _1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusDialog->addFutures(futureList);
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Called on rename button click. Selected device is renamed. Only one device can be renamed at a
|
|
|
|
|
time. Rename button is disabled on multi-selection.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onRename()
|
|
|
|
|
{
|
|
|
|
|
const SimulatorInfoList simulatorInfoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
if (simulatorInfoList.isEmpty() || simulatorInfoList.count() > 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const SimulatorInfo &simInfo = simulatorInfoList.at(0);
|
|
|
|
|
const QString newName = QInputDialog::getText(this, tr("Rename %1").arg(simInfo.name),
|
|
|
|
|
tr("Enter new name:"));
|
2017-07-25 12:36:18 +02:00
|
|
|
if (newName.isEmpty())
|
|
|
|
|
return;
|
2017-01-27 11:00:20 +01:00
|
|
|
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
|
|
|
|
statusDialog->addMessage(tr("Renaming simulator device..."), Utils::NormalMessageFormat);
|
|
|
|
|
QFuture<void> f = Utils::onResultReady(m_simControl->renameSimulator(simInfo.identifier, newName),
|
|
|
|
|
std::bind(onSimOperation, simInfo, statusDialog,
|
|
|
|
|
tr("simulator rename"), _1));
|
|
|
|
|
statusDialog->addFutures({f});
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Called on delete button click. Selected devices are deleted. Multiple devices can be deleted
|
|
|
|
|
simultaneously provided they in shutdown state.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onDelete()
|
|
|
|
|
{
|
|
|
|
|
const SimulatorInfoList simulatorInfoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
if (simulatorInfoList.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const int userInput = QMessageBox::question(this, tr("Delete Device"),
|
2018-01-09 17:39:06 +01:00
|
|
|
tr("Do you really want to delete the %n selected "
|
|
|
|
|
"device(s)?", "", simulatorInfoList.count()));
|
2017-01-27 11:00:20 +01:00
|
|
|
if (userInput == QMessageBox::No)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
2018-01-09 17:39:06 +01:00
|
|
|
statusDialog->addMessage(tr("Deleting %n simulator device(s)...", "", simulatorInfoList.count()),
|
2017-01-27 11:00:20 +01:00
|
|
|
Utils::NormalMessageFormat);
|
|
|
|
|
QList<QFuture<void>> futureList;
|
|
|
|
|
foreach (const SimulatorInfo &info, simulatorInfoList) {
|
|
|
|
|
futureList << Utils::onResultReady(m_simControl->deleteSimulator(info.identifier),
|
|
|
|
|
std::bind(onSimOperation, info, statusDialog,
|
|
|
|
|
tr("simulator delete"), _1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusDialog->addFutures(futureList);
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
Called on screenshot button click. Screenshot of the selected devices are saved to the selected
|
|
|
|
|
path. Screenshot from multiple devices can be taken simultaneously provided they in booted state.
|
|
|
|
|
*/
|
|
|
|
|
void IosSettingsWidget::onScreenshot()
|
|
|
|
|
{
|
|
|
|
|
const SimulatorInfoList simulatorInfoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
if (simulatorInfoList.isEmpty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
const auto generatePath = [this](const SimulatorInfo &info) {
|
|
|
|
|
const QString fileName = QString("%1_%2_%3.png").arg(info.name).arg(info.runtimeName)
|
|
|
|
|
.arg(QDateTime::currentDateTime().toString("yyyy-MM-dd_HH-mm-ss-z")).replace(' ', '_');
|
2019-05-15 15:49:19 +02:00
|
|
|
return m_ui->pathWidget->fileName().pathAppended(fileName).toString();
|
2017-01-27 11:00:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QPointer<SimulatorOperationDialog> statusDialog = new SimulatorOperationDialog(this);
|
|
|
|
|
statusDialog->setAttribute(Qt::WA_DeleteOnClose);
|
2018-01-09 17:39:06 +01:00
|
|
|
statusDialog->addMessage(tr("Capturing screenshots from %n device(s)...", "",
|
2017-01-27 11:00:20 +01:00
|
|
|
simulatorInfoList.count()), Utils::NormalMessageFormat);
|
|
|
|
|
QList<QFuture<void>> futureList;
|
|
|
|
|
foreach (const SimulatorInfo &info, simulatorInfoList) {
|
|
|
|
|
futureList << Utils::onResultReady(m_simControl->takeSceenshot(info.identifier,
|
|
|
|
|
generatePath(info)),
|
|
|
|
|
std::bind(onSimOperation, info, statusDialog,
|
|
|
|
|
tr("simulator screenshot"), _1));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
statusDialog->addFutures(futureList);
|
|
|
|
|
statusDialog->exec(); // Modal dialog returns only when all the operations are done or cancelled.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IosSettingsWidget::onSelectionChanged()
|
|
|
|
|
{
|
|
|
|
|
const SimulatorInfoList infoList = selectedSimulators(m_ui->deviceView);
|
|
|
|
|
const bool hasRunning = Utils::anyOf(infoList, [](const SimulatorInfo &info) {
|
|
|
|
|
return info.isBooted();
|
|
|
|
|
});
|
|
|
|
|
const bool hasShutdown = Utils::anyOf(infoList, [](const SimulatorInfo &info) {
|
|
|
|
|
return info.isShutdown();
|
|
|
|
|
});
|
|
|
|
|
m_ui->startButton->setEnabled(hasShutdown);
|
|
|
|
|
m_ui->deleteButton->setEnabled(hasShutdown);
|
|
|
|
|
m_ui->resetButton->setEnabled(hasShutdown);
|
|
|
|
|
m_ui->renameButton->setEnabled(infoList.count() == 1 && hasShutdown);
|
|
|
|
|
m_ui->pathWidget->buttonAtIndex(1)->setEnabled(hasRunning); // Screenshot button
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
2013-10-07 20:14:54 +02:00
|
|
|
void IosSettingsWidget::saveSettings()
|
2013-04-25 16:02:17 +02:00
|
|
|
{
|
2013-10-07 20:14:54 +02:00
|
|
|
IosConfigurations::setIgnoreAllDevices(!m_ui->deviceAskCheckBox->isChecked());
|
2017-01-27 11:00:20 +01:00
|
|
|
IosConfigurations::setScreenshotDir(m_ui->pathWidget->fileName());
|
2013-04-25 16:02:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace Ios
|
2017-01-27 11:00:20 +01:00
|
|
|
|