Corrected: urpo_id.pub in help file for public key file name
[urpo] / src / printerlistjob.cpp
1 /**************************************************************************
2
3     URPO
4
5     Unix Remote Printing Operation
6     Copyright (c) Arto Hyvättinen 2010
7
8     This file is part of URPO.
9
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.
14
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.
19
20
21 **************************************************************************/
22
23 #include "printerlistjob.h"
24 #include "urpoconnection.h"
25
26 PrinterListJob::PrinterListJob(UrpoConnection* connection) :
27     UrpoJob(connection)
28 {
29     process_=0;
30 }
31
32
33 void PrinterListJob::startJob()
34 {
35     process_= newProcess();
36
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");
42
43     // When finished, call doList
44     connect( process_, SIGNAL(finished(bool)), this, SLOT(doList(bool)));
45     process_->start(command);
46 }
47
48 void PrinterListJob::cancelJob()
49 {
50     if(process_)
51         process_->terminate();
52     finish(Cancelled);
53 }
54
55 void PrinterListJob::doList(bool success)
56 {
57     if( process_ && success )
58     {
59         foreach(QString line, process_->getOutput())
60         {
61             if(!line.section(' ',1,1).isEmpty())
62                 printers_.append( line.section(' ',1,1));
63             // List of printers!
64         }
65         finish(Successed);
66     }
67     else
68     {
69         // Error!
70         // Set error message
71         switch( process_->getError() )
72         {
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;
81         default:
82             fail( tr("Connection failed"));
83         }
84     }
85 }