• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

  • tdeprint
  • lpr
lpqhelper.cpp
1/*
2 * This file is part of the KDE libraries
3 * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License version 2 as published by the Free Software Foundation.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 **/
19
20#include "lpqhelper.h"
21#include "kmjob.h"
22#include "kpipeprocess.h"
23#include "lprsettings.h"
24
25#include <tdestandarddirs.h>
26#include <tdeprocess.h>
27#include <kdebug.h>
28
29LpqHelper::LpqHelper(TQObject *parent, const char *name)
30: TQObject(parent, name)
31{
32 m_exepath = TDEStandardDirs::findExe("lpq");
33}
34
35LpqHelper::~LpqHelper()
36{
37}
38
39KMJob* LpqHelper::parseLineLpr(const TQString& line)
40{
41 TQString rank = line.left(7);
42 if (!rank[0].isDigit() && rank != "active")
43 return NULL;
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);
50 if (p != -1)
51 {
52 job->setSize(line.mid(61, p-61).toInt() / 1000);
53 }
54 return job;
55}
56
57KMJob* LpqHelper::parseLineLPRng(const TQString& line)
58{
59 TQString rank = line.left(7).stripWhiteSpace();
60 if (!rank[0].isDigit() && rank != "active" && rank != "hold")
61 return NULL;
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())
67 q++;
68 q++;
69 while (line[q].isSpace())
70 q++;
71 p = line.find(' ', q);
72 job->setId(line.mid(q, p-q).toInt());
73 while (line[p].isSpace())
74 p++;
75 q = p+25;
76 while (line[q].isDigit())
77 q--;
78 job->setName(line.mid(p, q-p).stripWhiteSpace());
79 job->setSize(line.mid(q+1, p+26-q).toInt() / 1000);
80 return job;
81}
82
83void LpqHelper::listJobs(TQPtrList<KMJob>& jobs, const TQString& prname, int limit)
84{
85 KPipeProcess proc;
86 if (!m_exepath.isEmpty() && proc.open(m_exepath + " -P " + TDEProcess::quote(prname)))
87 {
88 TQTextStream t(&proc);
89 TQString line;
90 bool lprng = (LprSettings::self()->mode() == LprSettings::LPRng);
91 int count = 0;
92
93 while (!t.atEnd())
94 {
95 line = t.readLine().stripWhiteSpace();
96 if (line.startsWith("Rank"))
97 break;
98 }
99 while (!t.atEnd())
100 {
101 line = t.readLine();
102 if ( limit > 0 && count >= limit )
103 continue;
104 KMJob *job = (lprng ? parseLineLPRng(line) : parseLineLpr(line));
105 if (job)
106 {
107 job->setPrinter(prname);
108 job->setUri("lpd://"+prname+"/"+TQString::number(job->id()));
109 jobs.append(job);
110 count++;
111 }
112 else
113 break;
114 }
115 proc.close();
116 }
117}

tdeprint

Skip menu "tdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.9.4
This website is maintained by Timothy Pearson.