27 #include <QMessageBox>
29 #if QT_CONFIG(process)
30 QgsRunProcess::QgsRunProcess(
const QString &action,
bool capture )
39 mProcess =
new QProcess;
43 connect( mProcess, &QProcess::errorOccurred,
this, &QgsRunProcess::processError );
44 connect( mProcess, &QProcess::readyReadStandardOutput,
this, &QgsRunProcess::stdoutAvailable );
45 connect( mProcess, &QProcess::readyReadStandardError,
this, &QgsRunProcess::stderrAvailable );
49 connect( mProcess,
static_cast < void ( QProcess::* )(
int, QProcess::ExitStatus )
>( &QProcess::finished ),
this, &QgsRunProcess::processExit );
54 mOutput->setTitle( action );
56 mOutput->showMessage(
false );
59 QObject *mOutputObj =
dynamic_cast<QObject *
>( mOutput );
62 connect( mOutputObj, &QObject::destroyed,
this, &QgsRunProcess::dialogGone );
66 mProcess->start( action );
70 if ( ! mProcess->startDetached( action ) )
72 QMessageBox::critical(
nullptr, tr(
"Action" ),
73 tr(
"Unable to run command\n%1" ).arg( action ),
74 QMessageBox::Ok, Qt::NoButton );
82 QgsRunProcess::~QgsRunProcess()
87 void QgsRunProcess::die()
93 void QgsRunProcess::stdoutAvailable()
95 QByteArray bytes( mProcess->readAllStandardOutput() );
96 QTextCodec *codec = QTextCodec::codecForLocale();
97 QString line( codec->toUnicode( bytes ) );
100 mOutput->appendMessage( line );
103 void QgsRunProcess::stderrAvailable()
105 QByteArray bytes( mProcess->readAllStandardOutput() );
106 QTextCodec *codec = QTextCodec::codecForLocale();
107 QString line( codec->toUnicode( bytes ) );
110 mOutput->appendMessage(
"<font color=red>" + line +
"</font>" );
113 void QgsRunProcess::processExit(
int, QProcess::ExitStatus )
124 mOutput->appendMessage(
"<b>" + tr(
"Done" ) +
"</b>" );
133 void QgsRunProcess::dialogGone()
144 disconnect( mProcess, &QProcess::errorOccurred,
this, &QgsRunProcess::processError );
145 disconnect( mProcess, &QProcess::readyReadStandardOutput,
this, &QgsRunProcess::stdoutAvailable );
146 disconnect( mProcess, &QProcess::readyReadStandardError,
this, &QgsRunProcess::stderrAvailable );
147 disconnect( mProcess,
static_cast < void ( QProcess::* )(
int, QProcess::ExitStatus )
>( &QProcess::finished ),
this, &QgsRunProcess::processExit );
152 void QgsRunProcess::processError( QProcess::ProcessError err )
154 if ( err == QProcess::FailedToStart )
163 QgsDebugMsg(
"Got error: " + QString(
"%d" ).arg( err ) );
167 QgsRunProcess::QgsRunProcess(
const QString &action,
bool )
173 QgsRunProcess::~QgsRunProcess()