1 /***************************************************************************
2  *                                                                         *
3  *   This program is free software; you can redistribute it and/or modify  *
4  *   it under the terms of the GNU General Public License as published by  *
5  *   the Free Software Foundation; either version 3 of the License, or     *
6  *   (at your option) any later version.                                   *
7  *                                                                         *
8  ***************************************************************************/
9 
10 #pragma once
11 
12 /**
13  * @author Edward Sheldrake
14  *
15  * ShellCommandRunner is a QThread which starts a QProcess, waits for it
16  * to finish, gets the output and then emits a sigal.
17  */
18 
19 #include <QThread>
20 #include <QString>
21 #include <QList>
22 #include <QStringList>
23 
24 class ShellCommandRunner : public QThread {
25     Q_OBJECT
26 
27 public:
28     /** constructor */
29     ShellCommandRunner(QString args, QObject * parent = 0);
30     ShellCommandRunner(QString cmd, QStringList args, QObject * parent = 0);
31     /** destructor */
32     virtual ~ShellCommandRunner();
33 
34 public Q_SLOTS:
35     /** the method that runs in the thread */
36     virtual void run();
37     /** Cancel the shell command e.g. if the chat is closed */
38     void cancel();
39     /** Return exit code*/
exitCode()40     int exitCode() const { return _exitCode; }
41 
42 Q_SIGNALS:
43     /** emitted when the command has finished */
44     void finished(bool ok, const QString &output);
45 
46 private:
47     /** used to cancel the thread */
48     bool stop;
49     /** */
50     bool useArgList;
51     /** the program to run and its arguments */
52     QString args;
53     QStringList argList;
54     QString cmd;
55     int _exitCode;
56 };
57