1 /**************************************************************************
5 Unix Remote Printing Operation
6 Copyright (c) Arto Hyvättinen 2010
8 This file is part of URPO.
10 URPO is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
15 URPO is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
21 **************************************************************************/
27 #include <QStringList>
32 /*! Process running ssh/scp command
34 @author Arto Hyvättinen
36 @date 2010-06-11 - 2010-06-12
38 Run ssh/scp etc. command.
40 Read setting using UrpoConnect settings information object.
41 Support debug monitoring using debugMessage-signals, monitor defined in settings object
43 First, connect finished()-signal. Then, run command.
44 Command is run asynchronosly.
48 // Get list of available printers
50 QString command = "ssh ";
51 command.append(getConnection()->getKeyOption());
52 command.append(getConnection()->getHostString());
53 command.append(" env LANG=en lpstat -p");
55 process = new UrpoProcess( connect );
57 connect( process, SIGNAL(finished(bool)), this, SLOT( readOutput(bool) ) );
58 process.start(command);
61 ::readOutput(bool success)
65 foreach(QString line, process->getOutput() )
69 cout << "Error " << process->getError();
76 class UrpoProcess : public QObject
81 @param connection Pointer to connection settings information
83 explicit UrpoProcess(QObject* parent = 0);
87 Ready /*! Ready for connecting */ = 0,
88 Running /*! Command running */ = 1,
89 Successed /*! Command successed */ = 2,
90 Failed /*! Command failed */ = 3,
91 PasswdRunning /*! Running after password sent */ = 11
95 NoError /*! No errors happends */ = 0,
96 ProcessError /*! Error running process */ = 1,
97 ConnectionError /*! Error connecting host */ = 2,
98 AuthError /*! Authentication failed */ = 3,
99 Timeout /*! Timed out */ = 4,
100 Cancelled /*! User cancelled operation */ = 5
103 /*! Get output of command
104 @return Output of command, list of QStrings
106 QStringList getOutput();
110 Start process running command. When process finish
111 (successed/failed), finished() signal will be emitted
113 @param command Command to execute
115 void start(const QString& command);
119 If process failed, get error code
122 UrpoError getError() const { return error_; }
123 /*! Error of process (in string)
125 If process failed, return error string readable by user
130 QString getErrorString() const;
134 @return Status (Ready, Running, Successed, Failed)
136 UrpoStatus getStatus() const { return status_; }
139 /*! Send debug message
141 @param message Message to debug monitor
143 If debug monitor has been connected, send message to debug monitor
146 void sendDebugMessage(QString message) { emit debugMessage(message); }
150 Process time out, if running command last more than timeout
153 @param msecs Timeout in msecs
155 void setTimeout(int msecs) { timeout_=msecs; }
159 @return Timeout in msecs */
160 int getTimeout() { return timeout_; }
163 /*! Process finished (successed of failed)
165 @param success True if process successed, false if failed
167 Emitted when process finished.
168 Output of process can be reader throught getOutput() */
169 void finished(bool success);
170 /** Send debug messages
172 UrpoConnection can set up a debug monitor, a QObject receiving
173 debugMsg signals. Debug messages contains information about
174 process output, errors etc.
176 @param message Message send to debug monitor */
177 void debugMessage(QString message);
182 Terminate process. Emit finished(false) signal and set Cancelled error */
185 /*! SSH client has finished */
186 void processFinished(int exitCode,QProcess::ExitStatus exitStatus);
187 /*! Timeout during connecting */
196 static int const DEFAULTTIMEOUT = 15000;
198 void fail(UrpoError error);
206 int timeout_; /*! Timeout in msecs */
207 QString storedPassword_; /* Password to store */
210 #endif // URPOPROCESS_H