22#include "kpipeprocess.h" 
   23#include "lprsettings.h" 
   25#include <tdestandarddirs.h> 
   26#include <tdeprocess.h> 
   29LpqHelper::LpqHelper(TQObject *parent, 
const char *name)
 
   30: TQObject(parent, name)
 
   32    m_exepath = TDEStandardDirs::findExe(
"lpq");
 
   35LpqHelper::~LpqHelper()
 
   39KMJob* LpqHelper::parseLineLpr(
const TQString& line)
 
   41    TQString    rank = line.left(7);
 
   42    if (!rank[0].isDigit() && rank != 
"active")
 
   44    KMJob   *job = 
new KMJob;
 
   45    job->setState((rank[0].isDigit() ? KMJob::Queued : KMJob::Printing));
 
   46    job->setOwner(line.mid(7, 11).stripWhiteSpace());
 
   47    job->setId(line.mid(18, 5).toInt());
 
   48    job->setName(line.mid(23, 38).stripWhiteSpace());
 
   49    int p = line.find(
' ', 61);
 
   52        job->setSize(line.mid(61, p-61).toInt() / 1000);
 
   57KMJob* LpqHelper::parseLineLPRng(
const TQString& line)
 
   59    TQString    rank = line.left(7).stripWhiteSpace();
 
   60    if (!rank[0].isDigit() && rank != 
"active" && rank != 
"hold")
 
   62    KMJob   *job = 
new KMJob;
 
   63    job->setState((rank[0].isDigit() ? KMJob::Queued : (rank == 
"hold" ? KMJob::Held : KMJob::Printing)));
 
   64    int p = line.find(
'@', 7), q = line.find(
' ', 7);
 
   65    job->setOwner(line.mid(7, TQMIN(p,q)-7));
 
   66    while (line[q].isSpace())
 
   69    while (line[q].isSpace())
 
   71    p = line.find(
' ', q);
 
   72    job->setId(line.mid(q, p-q).toInt());
 
   73    while (line[p].isSpace())
 
   76    while (line[q].isDigit())
 
   78    job->setName(line.mid(p, q-p).stripWhiteSpace());
 
   79    job->setSize(line.mid(q+1, p+26-q).toInt() / 1000);
 
   83void LpqHelper::listJobs(TQPtrList<KMJob>& jobs, 
const TQString& prname, 
int limit)
 
   86    if (!m_exepath.isEmpty() && proc.open(m_exepath + 
" -P " + TDEProcess::quote(prname)))
 
   88        TQTextStream    t(&proc);
 
   90        bool    lprng = (LprSettings::self()->mode() == LprSettings::LPRng);
 
   95            line = t.readLine().stripWhiteSpace();
 
   96            if (line.startsWith(
"Rank"))
 
  102            if ( limit > 0 && count >= limit )
 
  104            KMJob   *job = (lprng ? parseLineLPRng(line) : parseLineLpr(line));
 
  107                job->setPrinter(prname);
 
  108                job->setUri(
"lpd://"+prname+
"/"+TQString::number(job->id()));