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"
26 #include <QInputDialog>
30 int const UrpoProcess::DEFAULTTIMEOUT;
32 UrpoProcess::UrpoProcess(QObject* parent) :
37 setTimeout( DEFAULTTIMEOUT );
40 void UrpoProcess::terminate()
45 QStringList UrpoProcess::getOutput()
50 void UrpoProcess::fail(UrpoError error)
54 qprocess_.terminate();
56 sendDebugMessage( getErrorString() );
60 void UrpoProcess::timeout()
62 // If process is still running, it means timeout!
63 if( status_ == Running)
64 fail(Timeout); // FAILS !!!
67 void UrpoProcess::start(const QString &command)
69 sendDebugMessage(QString("[Running command %1 ]").arg(command));
71 // Process finished handling
72 connect( &qprocess_, SIGNAL(finished(int,QProcess::ExitStatus)), this, SLOT(processFinished(int,QProcess::ExitStatus)));
75 // use UrpoConnection's default timeout settings
76 QTimer::singleShot( getTimeout(), this, SLOT(timeout()) );
81 qprocess_.start(command);
85 void UrpoProcess::processFinished(int exitCode,QProcess::ExitStatus exitStatus)
89 sendDebugMessage( QString( tr("Process exited with code %1") ).arg(exitCode));
90 // Get data from ssh server
91 QByteArray newData = qprocess_.readAllStandardError();
92 sendDebugMessage( QString(newData) );
94 fail(ConnectionError);
96 else if( exitStatus == QProcess::CrashExit)
102 QByteArray bytes = qprocess_.readAllStandardOutput();
103 QString string(bytes);
104 sendDebugMessage(string);
105 // Split to lines and store to output_
106 output_=string.split("\n");
114 QString UrpoProcess::getErrorString() const
121 return tr("External program calling error");
122 case ConnectionError:
123 return tr("Connection error");
125 return tr("Authentication error");
127 return tr("Time out");
129 return tr("User cancelled");