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 **************************************************************************/
23 #include "urpoprocess.h"
24 #include "urpoconnection.h"
28 int const UrpoProcess::DEFAULTTIMEOUT;
30 UrpoProcess::UrpoProcess(QObject* parent) :
35 setTimeout( DEFAULTTIMEOUT );
38 void UrpoProcess::terminate()
43 QStringList UrpoProcess::getOutput()
48 void UrpoProcess::fail(UrpoError error)
52 qprocess_.terminate();
54 sendDebugMessage( getErrorString() );
58 void UrpoProcess::timeout()
60 // If process is still running, it means timeout!
61 if( status_ == Running)
65 void UrpoProcess::start(const QString &command)
67 sendDebugMessage(QString("[Running command %1 ]").arg(command));
69 // Process finished handling
70 connect( &qprocess_, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
73 // use UrpoConnection's default timeout settings
74 QTimer::singleShot( getTimeout(), this, SLOT(timeout()) );
79 qprocess_.start(command);
83 void UrpoProcess::processFinished(int exitCode,QProcess::ExitStatus exitStatus)
87 sendDebugMessage( QString( tr("Process exited with code %1") ).arg(exitCode));
88 // Get data from ssh server
89 QByteArray newData = qprocess_.readAllStandardError();
90 sendDebugMessage( QString(newData) );
92 fail(ConnectionError);
94 else if( exitStatus == QProcess::CrashExit)
100 QByteArray bytes = qprocess_.readAllStandardOutput();
101 QString string(bytes);
102 sendDebugMessage(string);
103 // Split to lines and store to output_
104 output_=string.split("\n");
110 QString UrpoProcess::getErrorString() const
117 return tr("External program calling error");
118 case ConnectionError:
119 return tr("Connection error");
121 return tr("Authentication error");
123 return tr("Time out");
125 return tr("User cancelled");