aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/squish/squishprocessbase.cpp
blob: 744ea506c12130b798966005fc4b236c2b9eb594 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#include "squishprocessbase.h"

namespace Squish::Internal {

SquishProcessBase::SquishProcessBase(QObject *parent)
    : QObject(parent)
{
    connect(&m_process, &Utils::Process::readyReadStandardError,
            this, &SquishProcessBase::onErrorOutput);
    connect(&m_process, &Utils::Process::done,
            this, &SquishProcessBase::onDone);
}

void SquishProcessBase::setState(SquishProcessState state)
{
    if (m_state == state)
        return;
    m_state = state;
    emit stateChanged(state);
}

void SquishProcessBase::start(const Utils::CommandLine &cmdline, const Utils::Environment &env)
{
    QTC_ASSERT(m_process.state() == QProcess::NotRunning, return);
    // avoid crashes on fast re-use
    m_process.close();

    m_process.setCommand(cmdline);
    m_process.setEnvironment(env);

    setState(Starting);
    m_process.start();
    if (!m_process.waitForStarted()) {
        setState(StartFailed);
        qWarning() << "squishprocess did not start within 30s";
    }
    setState(Started);
}

} // namespace Squish::Internal