00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "printerlistjob.h"
00024 #include "urpoconnection.h"
00025
00026 PrinterListJob::PrinterListJob(UrpoConnection* connection) :
00027 UrpoJob(connection)
00028 {
00029 process_=0;
00030 }
00031
00032
00033 void PrinterListJob::startJob()
00034 {
00035 process_= newProcess();
00036
00037
00038 QString command = "ssh ";
00039 command.append(getConnection()->getKeyOption());
00040 command.append(getConnection()->getHostString());
00041 command.append(" env LANG=en lpstat -p");
00042
00043
00044 connect( process_, SIGNAL(finished(bool)), this, SLOT(doList(bool)));
00045 process_->start(command);
00046 }
00047
00048 void PrinterListJob::cancelJob()
00049 {
00050 if(process_)
00051 process_->terminate();
00052 finish(Cancelled);
00053 }
00054
00055 void PrinterListJob::doList(bool success)
00056 {
00057 if( process_ && success )
00058 {
00059 foreach(QString line, process_->getOutput())
00060 {
00061 if(!line.section(' ',1,1).isEmpty())
00062 printers_.append( line.section(' ',1,1));
00063
00064 }
00065 finish(Successed);
00066 }
00067 else
00068 {
00069
00070
00071 switch( process_->getError() )
00072 {
00073 case UrpoProcess::ProcessError :
00074 fail( tr("Failed to run ssh client.")); break;
00075 case UrpoProcess::ConnectionError:
00076 fail( tr("Failed to connect host")); break;
00077 case UrpoProcess::Timeout:
00078 fail( tr("Time out or authentication error")); break;
00079 case UrpoProcess::Cancelled:
00080 fail( tr("User cancelled")); break;
00081 default:
00082 fail( tr("Connection failed"));
00083 }
00084 }
00085 }