forked from qt-creator/qt-creator
Boot2Qt: Simplify DeviceApplicationObserver interface
The ability to run more than one command is never used, drop it. Change-Id: Id42c8922e1290bbb4a7a2e517dc7759dcfb0b189 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -51,29 +51,18 @@ DeviceApplicationObserver::DeviceApplicationObserver(QObject *parent)
|
||||
}
|
||||
|
||||
void DeviceApplicationObserver::start(const IDevice::ConstPtr &device,
|
||||
const QList<Command> &commands)
|
||||
const Command &command)
|
||||
{
|
||||
QTC_ASSERT(device, return);
|
||||
m_device = device;
|
||||
m_commandsToRun = commands;
|
||||
runNext();
|
||||
}
|
||||
m_command = command;
|
||||
|
||||
void DeviceApplicationObserver::runNext()
|
||||
{
|
||||
if (m_commandsToRun.isEmpty()) {
|
||||
showMessage(tr("Commands on device '%1' finished successfully.")
|
||||
.arg(m_device->displayName()));
|
||||
deleteLater();
|
||||
return;
|
||||
}
|
||||
const Command c = m_commandsToRun.takeFirst();
|
||||
m_stdout.clear();
|
||||
m_stderr.clear();
|
||||
|
||||
Runnable r;
|
||||
r.executable = c.binary;
|
||||
r.commandLineArguments = Utils::QtcProcess::joinArgs(c.arguments);
|
||||
r.executable = m_command.binary;
|
||||
r.commandLineArguments = Utils::QtcProcess::joinArgs(m_command.arguments);
|
||||
m_appRunner->start(r, m_device);
|
||||
showMessage(tr("Starting command '%1 %2' on device '%3'.")
|
||||
.arg(r.executable, r.commandLineArguments, m_device->displayName()));
|
||||
@@ -113,10 +102,11 @@ void DeviceApplicationObserver::handleFinished(bool success)
|
||||
showMessage(tr("stdout was: '%1'").arg(m_stdout));
|
||||
if (!m_stderr.isEmpty())
|
||||
showMessage(tr("stderr was: '%1'").arg(m_stderr));
|
||||
deleteLater();
|
||||
return;
|
||||
} else {
|
||||
showMessage(tr("Commands on device '%1' finished successfully.")
|
||||
.arg(m_device->displayName()));
|
||||
}
|
||||
runNext();
|
||||
deleteLater();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -36,9 +36,6 @@ namespace Internal {
|
||||
|
||||
class Command {
|
||||
public:
|
||||
Command(const QString &bin, const QStringList &args = QStringList())
|
||||
: binary(bin), arguments(args) {}
|
||||
|
||||
QString binary;
|
||||
QStringList arguments;
|
||||
};
|
||||
@@ -50,18 +47,17 @@ public:
|
||||
explicit DeviceApplicationObserver(QObject *parent = 0);
|
||||
|
||||
// Once all commands have finished, this object will delete itself.
|
||||
void start(const ProjectExplorer::IDevice::ConstPtr &device, const QList<Command> &commands);
|
||||
void start(const ProjectExplorer::IDevice::ConstPtr &device, const Command &command);
|
||||
|
||||
private:
|
||||
void handleStdout(const QString &data);
|
||||
void handleStderr(const QString &data);
|
||||
void handleError(const QString &message);
|
||||
void handleFinished(bool success);
|
||||
void runNext();
|
||||
|
||||
QString m_stdout;
|
||||
QString m_stderr;
|
||||
QList<Command> m_commandsToRun;
|
||||
Command m_command;
|
||||
ProjectExplorer::ApplicationLauncher * const m_appRunner;
|
||||
ProjectExplorer::IDevice::ConstPtr m_device;
|
||||
QString m_error;
|
||||
|
@@ -45,13 +45,13 @@ namespace Internal {
|
||||
QdbDevice::QdbDevice()
|
||||
{
|
||||
addDeviceAction({tr("Reboot Device"), [](const IDevice::Ptr &device, QWidget *) {
|
||||
QList<Command> commands{Command("reboot")};
|
||||
(new DeviceApplicationObserver)->start(device, commands);
|
||||
Command cmd{"reboot", {}};
|
||||
(new DeviceApplicationObserver)->start(device, cmd);
|
||||
}});
|
||||
|
||||
addDeviceAction({tr("Restore Default App"), [](const IDevice::Ptr &device, QWidget *) {
|
||||
QList<Command> commands{Command(appControllerFilePath(), QStringList{"--remove-default"})};
|
||||
(new DeviceApplicationObserver)->start(device, commands);
|
||||
Command cmd{appControllerFilePath(), {"--remove-default"}};
|
||||
(new DeviceApplicationObserver)->start(device, cmd);
|
||||
}});
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user