Quark  0.1
ExternalCommandTask.h++
Go to the documentation of this file.
1 
2 #ifndef __libquark_util_ExternalCommandTask_hxx
3 #define __libquark_util_ExternalCommandTask_hxx
4 
5 #include <QAtomicInt>
6 #include <QProcess>
7 #include <QString>
8 #include <QStringList>
9 
10 #include <quark/Task.h++>
11 
12 namespace quark {
13 namespace util {
14 
22 class ExternalCommandTask : public Task
23 {
24  Q_OBJECT;
25 
26  public:
28  virtual ~ExternalCommandTask();
29 
31  QString executable() const
32  { return(_executable); }
33 
35  QStringList args() const
36  { return(_args); }
37 
39  int exitCode() const
40  { return(_exitCode); }
41 
43  QString toString() const;
44 
46  virtual void execute();
47 
49  virtual bool cancel();
50 
51  protected:
52 
57  ExternalCommandTask(const QString& executable);
58 
62  void setArgs(QStringList args);
63 
71  void setUnbufferedOutput(bool unbufferedOutput)
72  { _unbufferedOutput = unbufferedOutput; }
73 
78  virtual void processStandardOutput(QString text);
79 
84  virtual void processStandardError(QString text);
85 
91  virtual void finish();
92 
93  private slots:
94  void handleProcessFinished(int exitCode, QProcess::ExitStatus status);
95  void handleProcessError(QProcess::ProcessError error);
96  void handleProcessStandardError();
97  void handleProcessStandardOutput();
98 
99  private:
100  void processResults();
101 
102  QString _executable;
103  QStringList _args;
104  bool _unbufferedOutput;
105  QScopedPointer<QProcess> _process;
106  QString _error;
107  QString _standardOutput;
108  QString _errorOutput;
109  int _exitCode;
110 
111  Q_DISABLE_COPY(ExternalCommandTask);
112 };
113 
114 } // namespace util
115 } // namespace quark
116 
117 #endif // __libquark_util_ExternalCommandTask_hxx
int exitCode() const
Returns the exit code from the subprocess.
Definition: ExternalCommandTask.h++:39
virtual ~ExternalCommandTask()
Destructor.
virtual void processStandardError(QString text)
Called to process standard error from the process.
An abstract subclass of Task that runs an external command (a subprocess).
Definition: ExternalCommandTask.h++:22
QString executable() const
Returns the path to the executable that will be run.
Definition: ExternalCommandTask.h++:31
QString toString() const
Returns a string representation of the task.
QStringList args() const
Returns the arguments to the executable.
Definition: ExternalCommandTask.h++:35
Definition: BarChartView.h++:6
void setArgs(QStringList args)
Sets the command line arguments for the executable.
ExternalCommandTask(const QString &executable)
Constructs a new ExternalCommandTask that will run the given executable.
virtual bool cancel()
Specified by Task.
virtual void processStandardOutput(QString text)
Called to process standard output from the process.
An abstract base class for objects that represent tasks to be executed by a TaskProcessor.
Definition: Task.h++:20
void setUnbufferedOutput(bool unbufferedOutput)
Specifies whether the command&#39;s output will be unbuffered.
Definition: ExternalCommandTask.h++:71
QString error() const
Returns the error message reported by this task upon failure, if any.
Definition: Task.h++:56
virtual void finish()
Called when the process has exited and just before the finished() signal is emitted.
virtual void execute()
Specified by Task.