diff options
author | Timothy Pearson <[email protected]> | 2011-11-06 15:56:40 -0600 |
---|---|---|
committer | Timothy Pearson <[email protected]> | 2011-11-06 15:56:40 -0600 |
commit | e16866e072f94410321d70daedbcb855ea878cac (patch) | |
tree | ee3f52eabde7da1a0e6ca845fb9c2813cf1558cf /tdeprint/lpr/lpqhelper.cpp | |
parent | a58c20c1a7593631a1b50213c805507ebc16adaf (diff) | |
download | tdelibs-e16866e072f94410321d70daedbcb855ea878cac.tar.gz tdelibs-e16866e072f94410321d70daedbcb855ea878cac.zip |
Actually move the kde files that were renamed in the last commit
Diffstat (limited to 'tdeprint/lpr/lpqhelper.cpp')
-rw-r--r-- | tdeprint/lpr/lpqhelper.cpp | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/tdeprint/lpr/lpqhelper.cpp b/tdeprint/lpr/lpqhelper.cpp new file mode 100644 index 000000000..30348f591 --- /dev/null +++ b/tdeprint/lpr/lpqhelper.cpp @@ -0,0 +1,117 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2001 Michael Goffioul <[email protected]> + * + * 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> + +LpqHelper::LpqHelper(TQObject *parent, const char *name) +: TQObject(parent, name) +{ + m_exepath = KStandardDirs::findExe("lpq"); +} + +LpqHelper::~LpqHelper() +{ +} + +KMJob* LpqHelper::parseLineLpr(const TQString& line) +{ + TQString rank = line.left(7); + 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()); + int p = line.find(' ', 61); + if (p != -1) + { + job->setSize(line.mid(61, p-61).toInt() / 1000); + } + return job; +} + +KMJob* LpqHelper::parseLineLPRng(const TQString& line) +{ + TQString rank = line.left(7).stripWhiteSpace(); + 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))); + int p = line.find('@', 7), q = line.find(' ', 7); + job->setOwner(line.mid(7, TQMIN(p,q)-7)); + while (line[q].isSpace()) + q++; + q++; + while (line[q].isSpace()) + q++; + p = line.find(' ', q); + 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; +} + +void LpqHelper::listJobs(TQPtrList<KMJob>& jobs, const TQString& prname, int limit) +{ + KPipeProcess proc; + if (!m_exepath.isEmpty() && proc.open(m_exepath + " -P " + KProcess::quote(prname))) + { + TQTextStream t(&proc); + TQString line; + 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); + job->setUri("lpd://"+prname+"/"+TQString::number(job->id())); + jobs.append(job); + count++; + } + else + break; + } + proc.close(); + } +} |