|
Canorus
0.7
|
00001 00008 #ifndef _EXTERN_PROGRAM_H_ 00009 #define _EXTERN_PROGRAM_H_ 00010 00011 // Includes 00012 #include <QObject> 00013 #include <QProcess> 00014 #include <QStringList> 00015 00016 // Forward declarations 00017 00018 // This class is used to run a program in the background 00019 // and to get it's input/output via signals 00020 00021 // Class definition 00022 class CAExternProgram : public QObject 00023 { 00024 Q_OBJECT 00025 00026 public: 00027 CAExternProgram( bool bRcvStdErr = true, bool bRcvStdOut = true ); 00028 ~CAExternProgram(); 00029 00030 void setProgramName( const QString &roProgram ); 00031 void setProgramPath( const QString &roPath ); 00032 // Warning: Setting all parameters overwrites all 00033 // parameters added via addParameter method! 00034 void setParameters( const QStringList &roParams ); 00035 void inline setParamDelimiter( QString oDelimiter = " " ) 00036 { _oParamDelimiter = oDelimiter; } 00037 00038 inline const QStringList &getParameters() { return _oParameters; } 00039 inline bool getRunning() 00040 { return _poExternProgram->state() == QProcess::Running; } 00041 inline const QString &getParamDelimiter() { return _oParamDelimiter; } 00042 int getExitState(); 00043 00044 void addParameter( const QString &roParam, bool bAddDelimiter = true ); 00045 inline void clearParameters() { _oParameters.clear(); } 00046 bool execProgram( const QString &roCwd = "." ); 00047 inline bool waitForFinished ( int iMSecs ) { _poExternProgram->waitForFinished( iMSecs ); } 00048 00049 signals: 00050 void nextOutput( const QByteArray &roData ); 00051 void programExited( int iExitCode ); 00052 00053 protected slots: 00054 void rcvProgramStdOut() { rcvProgramOutput( _poExternProgram->readAllStandardOutput() ); } 00055 void rcvProgramStdErr() { rcvProgramOutput( _poExternProgram->readAllStandardError() ); } 00056 void programError( QProcess::ProcessError ) { programExited(); } 00057 void programFinished( int, QProcess::ExitStatus ) { programExited(); } 00058 00059 protected: 00060 void rcvProgramOutput( const QByteArray &roData ); 00061 void programExited(); 00062 00063 // References to the real objects(!) 00064 QProcess *_poExternProgram; // Process object running the watched program 00065 QString _oProgramName; // Program name to be run 00066 QString _oProgramPath; // Program path being added to the program name 00067 QStringList _oParameters; // List of program parameters 00068 QString _oParamDelimiter; // delimiter between the single parameters 00069 bool _bRcvStdErr; // 'true': Receive program output from stderr 00070 }; 00071 00072 #endif // _EXTERN_PROGRAM_ 00073
1.8.0