You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
118 lines
3.1 KiB
118 lines
3.1 KiB
15 years ago
|
/*
|
||
|
* This file is part of the KDE libraries
|
||
13 years ago
|
* Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
|
||
15 years ago
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License version 2 as published by the Free Software Foundation.
|
||
|
*
|
||
|
* This library is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
**/
|
||
|
|
||
|
#include "lpqhelper.h"
|
||
|
#include "kmjob.h"
|
||
|
#include "kpipeprocess.h"
|
||
|
#include "lprsettings.h"
|
||
|
|
||
|
#include <kstandarddirs.h>
|
||
|
#include <kprocess.h>
|
||
|
#include <kdebug.h>
|
||
|
|
||
15 years ago
|
LpqHelper::LpqHelper(TQObject *parent, const char *name)
|
||
|
: TQObject(parent, name)
|
||
15 years ago
|
{
|
||
|
m_exepath = KStandardDirs::findExe("lpq");
|
||
|
}
|
||
|
|
||
|
LpqHelper::~LpqHelper()
|
||
|
{
|
||
|
}
|
||
|
|
||
15 years ago
|
KMJob* LpqHelper::parseLineLpr(const TQString& line)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString rank = line.left(7);
|
||
15 years ago
|
if (!rank[0].isDigit() && rank != "active")
|
||
|
return NULL;
|
||
|
KMJob *job = new KMJob;
|
||
|
job->setState((rank[0].isDigit() ? KMJob::Queued : KMJob::Printing));
|
||
|
job->setOwner(line.mid(7, 11).stripWhiteSpace());
|
||
|
job->setId(line.mid(18, 5).toInt());
|
||
|
job->setName(line.mid(23, 38).stripWhiteSpace());
|
||
13 years ago
|
int p = line.find(' ', 61);
|
||
15 years ago
|
if (p != -1)
|
||
|
{
|
||
|
job->setSize(line.mid(61, p-61).toInt() / 1000);
|
||
|
}
|
||
|
return job;
|
||
|
}
|
||
|
|
||
15 years ago
|
KMJob* LpqHelper::parseLineLPRng(const TQString& line)
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString rank = line.left(7).stripWhiteSpace();
|
||
15 years ago
|
if (!rank[0].isDigit() && rank != "active" && rank != "hold")
|
||
|
return NULL;
|
||
|
KMJob *job = new KMJob;
|
||
|
job->setState((rank[0].isDigit() ? KMJob::Queued : (rank == "hold" ? KMJob::Held : KMJob::Printing)));
|
||
13 years ago
|
int p = line.find('@', 7), q = line.find(' ', 7);
|
||
14 years ago
|
job->setOwner(line.mid(7, TQMIN(p,q)-7));
|
||
15 years ago
|
while (line[q].isSpace())
|
||
|
q++;
|
||
|
q++;
|
||
|
while (line[q].isSpace())
|
||
|
q++;
|
||
13 years ago
|
p = line.find(' ', q);
|
||
15 years ago
|
job->setId(line.mid(q, p-q).toInt());
|
||
|
while (line[p].isSpace())
|
||
|
p++;
|
||
|
q = p+25;
|
||
|
while (line[q].isDigit())
|
||
|
q--;
|
||
|
job->setName(line.mid(p, q-p).stripWhiteSpace());
|
||
|
job->setSize(line.mid(q+1, p+26-q).toInt() / 1000);
|
||
|
return job;
|
||
|
}
|
||
|
|
||
15 years ago
|
void LpqHelper::listJobs(TQPtrList<KMJob>& jobs, const TQString& prname, int limit)
|
||
15 years ago
|
{
|
||
|
KPipeProcess proc;
|
||
|
if (!m_exepath.isEmpty() && proc.open(m_exepath + " -P " + KProcess::quote(prname)))
|
||
|
{
|
||
14 years ago
|
TQTextStream t(&proc);
|
||
|
TQString line;
|
||
15 years ago
|
bool lprng = (LprSettings::self()->mode() == LprSettings::LPRng);
|
||
|
int count = 0;
|
||
|
|
||
|
while (!t.atEnd())
|
||
|
{
|
||
|
line = t.readLine().stripWhiteSpace();
|
||
|
if (line.startsWith("Rank"))
|
||
|
break;
|
||
|
}
|
||
|
while (!t.atEnd())
|
||
|
{
|
||
|
line = t.readLine();
|
||
|
if ( limit > 0 && count >= limit )
|
||
|
continue;
|
||
|
KMJob *job = (lprng ? parseLineLPRng(line) : parseLineLpr(line));
|
||
|
if (job)
|
||
|
{
|
||
|
job->setPrinter(prname);
|
||
15 years ago
|
job->setUri("lpd://"+prname+"/"+TQString::number(job->id()));
|
||
15 years ago
|
jobs.append(job);
|
||
|
count++;
|
||
|
}
|
||
|
else
|
||
|
break;
|
||
|
}
|
||
|
proc.close();
|
||
|
}
|
||
|
}
|