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 "printerlistjob.h"
24 #include "urpoconnection.h"
26 PrinterListJob::PrinterListJob(UrpoConnection* connection) :
33 void PrinterListJob::startJob()
35 process_= newProcess();
37 // ssh command getting printers of cups
38 QString command = "ssh ";
39 command.append(getConnection()->getKeyOption());
40 command.append(getConnection()->getHostString());
41 command.append(" env LANG=en lpstat -p");
43 // When finished, call doList
44 connect( process_, SIGNAL(finished(bool)), this, SLOT(doList(bool)));
45 process_->start(command);
48 void PrinterListJob::cancelJob()
51 process_->terminate();
55 void PrinterListJob::doList(bool success)
57 if( process_ && success )
59 foreach(QString line, process_->getOutput())
61 if(!line.section(' ',1,1).isEmpty())
62 printers_.append( line.section(' ',1,1));
71 switch( process_->getError() )
73 case UrpoProcess::ProcessError :
74 fail( tr("Failed to run ssh client.")); break;
75 case UrpoProcess::ConnectionError:
76 fail( tr("Failed to connect host")); break;
77 case UrpoProcess::Timeout:
78 fail( tr("Time out or authentication error")); break;
79 case UrpoProcess::Cancelled:
80 fail( tr("User cancelled")); break;
82 fail( tr("Connection failed"));