HelperProcess.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include "HelperProcess.h"
00042 #include "Vidalia.h"
00043
00044 #include "stringutil.h"
00045
00046 #include <QString>
00047 #include <QFileInfo>
00048
00049
00050
00051 HelperProcess::HelperProcess(QObject *parent)
00052 : QProcess(parent)
00053 {
00054
00055 QObject::connect(this, SIGNAL(error(QProcess::ProcessError)),
00056 this, SLOT(onError(QProcess::ProcessError)));
00057
00058
00059 QObject::connect(this, SIGNAL(readyReadStandardError()),
00060 this, SLOT(onReadyReadStandardError()));
00061 QObject::connect(this, SIGNAL(readyReadStandardOutput()),
00062 this, SLOT(onReadyReadStandardOutput()));
00063 }
00064
00065
00066 void
00067 HelperProcess::onReadyReadStandardError()
00068 {
00069 QString output = QString(readAllStandardError());
00070 foreach (QString line, output.split("\n")) {
00071 vInfo("(%1:stderr): %2").arg(_processName).arg(line);
00072 }
00073 }
00074
00075
00076 void
00077 HelperProcess::onReadyReadStandardOutput()
00078 {
00079 QString output = QString(readAllStandardOutput());
00080 foreach (QString line, output.split("\n")) {
00081 vInfo("(%1:stdout): %2").arg(_processName).arg(line);
00082 }
00083 }
00084
00085 void
00086 HelperProcess::start(const QString &app, const QString &args)
00087 {
00088 QFileInfo fi(app);
00089 _processName = fi.fileName();
00090
00091 QString commandLine = QString("\"%1\" %2").arg(app).arg(args);
00092
00093
00094 vNotice("Launching helper process with command line '%1'")
00095 .arg(commandLine);
00096
00097 QProcess::start(commandLine, QIODevice::ReadOnly | QIODevice::Text);
00098 }
00099
00100
00101 void
00102 HelperProcess::start(const QString &app, const QStringList &args)
00103 {
00104
00105 QFileInfo fi(app);
00106 _processName = fi.fileName();
00107
00108
00109 vNotice("Launching helper process '%1' with arguments '%2'").arg(app)
00110 .arg(string_format_arguments(args));
00111
00112
00113 QProcess::start(app, args, QIODevice::ReadOnly | QIODevice::Text);
00114 }
00115
00116
00117 void
00118 HelperProcess::onError(QProcess::ProcessError error)
00119 {
00120
00121 if (error == QProcess::FailedToStart) {
00122 vWarn("Helper process '%1' failed to start: %2").arg(_processName)
00123 .arg(errorString());
00124 emit startFailed(errorString());
00125 }
00126 }
00127
00128
00129 bool
00130 HelperProcess::isDone() const
00131 {
00132 return state() == NotRunning;
00133 }
00134