androidruncontrol.cpp 3.23 KB
Newer Older
1
/****************************************************************************
BogDan Vatra's avatar
BogDan Vatra committed
2
**
3 4
** Copyright (C) 2016 BogDan Vatra <bog_dan_ro@yahoo.com>
** Contact: https://www.qt.io/licensing/
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
** 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.
BogDan Vatra's avatar
BogDan Vatra committed
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.
BogDan Vatra's avatar
BogDan Vatra committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
BogDan Vatra's avatar
BogDan Vatra committed
25 26 27 28 29 30 31

#include "androidruncontrol.h"

#include "androidglobal.h"
#include "androidrunconfiguration.h"
#include "androidrunner.h"

32 33
#include <coreplugin/coreicons.h>

BogDan Vatra's avatar
BogDan Vatra committed
34 35
#include <projectexplorer/projectexplorerconstants.h>

hjk's avatar
hjk committed
36
using namespace ProjectExplorer;
BogDan Vatra's avatar
BogDan Vatra committed
37 38 39 40 41

namespace Android {
namespace Internal {

AndroidRunControl::AndroidRunControl(AndroidRunConfiguration *rc)
42 43
    : RunControl(rc, ProjectExplorer::Constants::NORMAL_RUN_MODE)
    , m_runner(new AndroidRunner(this, rc, ProjectExplorer::Constants::NORMAL_RUN_MODE))
BogDan Vatra's avatar
BogDan Vatra committed
44 45
    , m_running(false)
{
BogDan Vatra's avatar
BogDan Vatra committed
46
    setRunnable(m_runner->runnable());
47
    setIcon(Core::Icons::RUN_SMALL_TOOLBAR);
BogDan Vatra's avatar
BogDan Vatra committed
48 49 50 51 52 53 54 55 56 57 58 59 60
}

AndroidRunControl::~AndroidRunControl()
{
    stop();
}

void AndroidRunControl::start()
{
    m_running = true;
    emit started();
    disconnect(m_runner, 0, this, 0);

Orgad Shaneh's avatar
Orgad Shaneh committed
61 62 63 64 65 66
    connect(m_runner, &AndroidRunner::remoteErrorOutput,
        this, &AndroidRunControl::handleRemoteErrorOutput);
    connect(m_runner, &AndroidRunner::remoteOutput,
        this, &AndroidRunControl::handleRemoteOutput);
    connect(m_runner, &AndroidRunner::remoteProcessFinished,
        this, &AndroidRunControl::handleRemoteProcessFinished);
67
    appendMessage(tr("Starting remote process."), Utils::NormalMessageFormat);
BogDan Vatra's avatar
BogDan Vatra committed
68
    m_runner->setRunnable(runnable().as<AndroidRunnable>());
BogDan Vatra's avatar
BogDan Vatra committed
69 70 71
    m_runner->start();
}

hjk's avatar
hjk committed
72
RunControl::StopResult AndroidRunControl::stop()
BogDan Vatra's avatar
BogDan Vatra committed
73
{
BogDan Vatra's avatar
BogDan Vatra committed
74
    m_runner->stop();
BogDan Vatra's avatar
BogDan Vatra committed
75 76 77 78 79 80 81 82 83 84 85
    return StoppedSynchronously;
}

void AndroidRunControl::handleRemoteProcessFinished(const QString &error)
{
    appendMessage(error, Utils::ErrorMessageFormat);
    disconnect(m_runner, 0, this, 0);
    m_running = false;
    emit finished();
}

86
void AndroidRunControl::handleRemoteOutput(const QString &output)
BogDan Vatra's avatar
BogDan Vatra committed
87
{
88
    appendMessage(output, Utils::StdOutFormatSameLine);
BogDan Vatra's avatar
BogDan Vatra committed
89 90
}

91
void AndroidRunControl::handleRemoteErrorOutput(const QString &output)
BogDan Vatra's avatar
BogDan Vatra committed
92
{
93
    appendMessage(output, Utils::StdErrFormatSameLine);
BogDan Vatra's avatar
BogDan Vatra committed
94 95 96 97 98 99 100 101 102 103 104 105 106
}

bool AndroidRunControl::isRunning() const
{
    return m_running;
}

QString AndroidRunControl::displayName() const
{
    return m_runner->displayName();
}

} // namespace Internal
107
} // namespace Android