Utils: Use std::function instead of signal SynchronousProcess callback

Simpler interface and use.

Change-Id: I8db448b7ccd12927b8f8fd347b0a92c3f76f7114
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-05-06 08:56:42 +02:00
parent 3229903e8a
commit d825805c39
6 changed files with 31 additions and 85 deletions

View File

@@ -174,18 +174,15 @@ static void sdkManagerCommand(const AndroidConfig &config, const QStringList &ar
SynchronousProcess proc;
proc.setEnvironment(AndroidConfigurations::toolsEnvironment(config));
bool assertionFound = false;
proc.setStdErrBufferedSignalsEnabled(true);
proc.setStdOutBufferedSignalsEnabled(true);
proc.setTimeoutS(timeout);
QObject::connect(&proc, &SynchronousProcess::stdOutBuffered,
[offset, progressQuota, &proc, &assertionFound, &fi](const QString &out) {
proc.setStdOutCallback([offset, progressQuota, &proc, &assertionFound, &fi](const QString &out) {
int progressPercent = parseProgress(out, assertionFound);
if (assertionFound)
proc.terminate();
if (progressPercent != -1)
fi.setProgressValue(offset + qRound((progressPercent / 100.0) * progressQuota));
});
QObject::connect(&proc, &SynchronousProcess::stdErrBuffered, [&output](const QString &err) {
proc.setStdErrCallback([&output](const QString &err) {
output.stdError = err;
});
if (interruptible) {

View File

@@ -1249,7 +1249,6 @@ PerforceResponse PerforcePluginPrivate::synchronousProcess(const QString &workin
{
QTC_ASSERT(stdInput.isEmpty(), return PerforceResponse()); // Not supported here
VcsOutputWindow *outputWindow = VcsOutputWindow::instance();
// Run, connect stderr to the output window
SynchronousProcess process;
const int timeOutS = (flags & LongTimeOut) ? m_settings.longTimeOutS() : m_settings.timeOutS.value();
@@ -1262,26 +1261,15 @@ PerforceResponse PerforcePluginPrivate::synchronousProcess(const QString &workin
process.setWorkingDirectory(workingDir);
// connect stderr to the output window if desired
if (flags & StdErrToWindow) {
process.setStdErrBufferedSignalsEnabled(true);
connect(&process, &SynchronousProcess::stdErrBuffered,
outputWindow, [](const QString &lines) {
VcsOutputWindow::append(lines);
});
}
if (flags & StdErrToWindow)
process.setStdErrCallback([](const QString &lines) { VcsOutputWindow::append(lines); });
// connect stdout to the output window if desired
if (flags & StdOutToWindow) {
process.setStdOutBufferedSignalsEnabled(true);
if (flags & SilentStdOut) {
connect(&process, &SynchronousProcess::stdOutBuffered,
outputWindow, &VcsOutputWindow::appendSilently);
} else {
connect(&process, &SynchronousProcess::stdOutBuffered,
outputWindow, [](const QString &lines) {
VcsOutputWindow::append(lines);
});
}
if (flags & SilentStdOut)
process.setStdOutCallback(&VcsOutputWindow::appendSilently);
else
process.setStdOutCallback([](const QString &lines) { VcsOutputWindow::append(lines); });
}
process.setTimeOutMessageBoxEnabled(true);
const SynchronousProcessResponse sp_resp = process.run({m_settings.p4BinaryPath.value(), args});