00001 /************************************************************************** 00002 00003 URPO 00004 00005 Unix Remote Printing Operation 00006 Copyright (c) Arto Hyvättinen 2010 00007 00008 This file is part of URPO. 00009 00010 URPO is free software: you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation, either version 3 of the License, or 00013 (at your option) any later version. 00014 00015 URPO is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 00021 **************************************************************************/ 00022 00023 #ifndef URPOPROCESS_H 00024 #define URPOPROCESS_H 00025 00026 #include <QObject> 00027 #include <QStringList> 00028 #include <QProcess> 00029 class UrpoConnection; 00030 00075 class UrpoProcess : public QObject 00076 { 00077 Q_OBJECT 00078 public: 00082 explicit UrpoProcess(QObject* parent = 0); 00083 00084 00085 enum UrpoStatus { 00086 Ready = 0, 00087 Running = 1, 00088 Successed = 2, 00089 Failed = 3 00090 }; 00091 00092 enum UrpoError { 00093 NoError = 0, 00094 ProcessError = 1, 00095 ConnectionError = 2, 00096 AuthError = 3, 00097 Timeout = 4, 00098 Cancelled = 5 00099 }; 00100 00104 QStringList getOutput(); 00105 00113 void start(const QString& command); 00114 00120 UrpoError getError() const { return error_; } 00128 QString getErrorString() const; 00129 00134 UrpoStatus getStatus() const { return status_; } 00135 00136 00144 void sendDebugMessage(QString message) { emit debugMessage(message); } 00145 00153 void setTimeout(int msecs) { timeout_=msecs; } 00154 00158 int getTimeout() { return timeout_; } 00159 00160 signals: 00167 void finished(bool success); 00175 void debugMessage(QString message); 00176 00177 public slots: 00181 void terminate(); 00182 00184 void processFinished(int exitCode,QProcess::ExitStatus exitStatus); 00186 void timeout(); 00187 00188 00189 protected: 00190 00191 00192 private: 00193 00194 static int const DEFAULTTIMEOUT = 15000; 00195 00196 void fail(UrpoError error); 00197 00198 QStringList output_; 00199 00200 QProcess qprocess_; 00201 00202 UrpoStatus status_; 00203 UrpoError error_; 00204 int timeout_; 00205 }; 00206 00207 #endif // URPOPROCESS_H