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

tdeprint

  • tdeprint
  • cups
kcupsprinterimpl.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 "kcupsprinterimpl.h"
21#include "kprinter.h"
22#include "driver.h"
23#include "kmfactory.h"
24#include "kmmanager.h"
25#include "cupsinfos.h"
26
27#include <tqfile.h>
28#include <cups/cups.h>
29#include <stdlib.h>
30#include <kprocess.h>
31#include <kstandarddirs.h>
32#include <tdelocale.h>
33
34static void mapToCupsOptions(const TQMap<TQString,TQString>& opts, TQString& cmd);
35
36TQSize rangeToSize(const TQString& s)
37{
38 TQString range = s;
39 int p(-1);
40 int from, to;
41
42 if ((p=range.find(',')) != -1)
43 range.truncate(p);
44 if ((p=range.find('-')) != -1)
45 {
46 from = range.left(p).toInt();
47 to = range.right(range.length()-p-1).toInt();
48 }
49 else if (!range.isEmpty())
50 from = to = range.toInt();
51 else
52 from = to = 0;
53
54 return TQSize(from,to);
55}
56//******************************************************************************************************
57
58KCupsPrinterImpl::KCupsPrinterImpl(TQObject *parent, const char *name, const TQStringList & /*args*/)
59: KPrinterImpl(parent,name)
60{
61}
62
63KCupsPrinterImpl::~KCupsPrinterImpl()
64{
65}
66
67bool KCupsPrinterImpl::setupCommand(TQString& cmd, KPrinter *printer)
68{
69 // check printer object
70 if (!printer) return false;
71
72 TQString exe = TDEStandardDirs::findExe("cupsdoprint");
73 if (exe.isEmpty())
74 {
75 printer->setErrorMessage(i18n("Unable to locate the CUPS print helper <b>cupsdoprint</b>."));
76 return false;
77 }
78
79 TQString hoststr = TQString::fromLatin1("%1:%2").arg(CupsInfos::self()->host()).arg(CupsInfos::self()->port());
80 cmd = TQString::fromLatin1("%1 -P %2 -J %4 -H %3").arg(quote(exe)).arg(quote(printer->printerName())).arg(quote(hoststr)).arg(quote(printer->docName()));
81 if (!CupsInfos::self()->login().isEmpty())
82 {
83 TQString userstr(CupsInfos::self()->login());
84 //if (!CupsInfos::self()->password().isEmpty())
85 // userstr += (":" + CupsInfos::self()->password());
86 cmd.append(" -U ").append(quote(userstr));
87 }
88 mapToCupsOptions(printer->options(),cmd);
89 return true;
90}
91
92void KCupsPrinterImpl::preparePrinting(KPrinter *printer)
93{
94 // process orientation
95 TQString o = printer->option("orientation-requested");
96 printer->setOption("kde-orientation",(o == "4" || o == "5" ? "Landscape" : "Portrait"));
97 // if it's a TQt application, then convert orientation as it will be handled by TQt directly
98 if (printer->applicationType() == KPrinter::Dialog)
99 printer->setOption("orientation-requested",(o == "5" || o == "6" ? "6" : "3"));
100
101 // translate copies number
102 if (!printer->option("kde-copies").isEmpty()) printer->setOption("copies",printer->option("kde-copies"));
103
104 // page ranges are handled by CUPS, so application should print all pages
105 if (printer->pageSelection() == KPrinter::SystemSide)
106 { // TQt => CUPS
107 // translations
108 if (!printer->option("kde-range").isEmpty())
109 printer->setOption("page-ranges",printer->option("kde-range"));
110 if (printer->option("kde-pageorder") == "Reverse")
111 printer->setOption("OutputOrder",printer->option("kde-pageorder"));
112 o = printer->option("kde-pageset");
113 if (!o.isEmpty() && o != "0")
114 printer->setOption("page-set",(o == "1" ? "odd" : "even"));
115 printer->setOption("multiple-document-handling",(printer->option("kde-collate") == "Collate" ? "separate-documents-collated-copies" : "separate-documents-uncollated-copies"));
116 }
117 else
118 { // No translation needed (but range => (from,to))
119 TQString range = printer->option("kde-range");
120 if (!range.isEmpty())
121 {
122 TQSize s = rangeToSize(range);
123 printer->setOption("kde-from",TQString::number(s.width()));
124 printer->setOption("kde-to",TQString::number(s.height()));
125 }
126 }
127
128 // needed for page size and margins
129 KPrinterImpl::preparePrinting(printer);
130}
131
132void KCupsPrinterImpl::broadcastOption(const TQString& key, const TQString& value)
133{
134 KPrinterImpl::broadcastOption(key,value);
135 if (key == "kde-orientation")
136 KPrinterImpl::broadcastOption("orientation-requested",(value == "Landscape" ? "4" : "3"));
137 else if (key == "kde-pagesize")
138 {
139 TQString pagename = TQString::fromLatin1(pageSizeToPageName((KPrinter::PageSize)value.toInt()));
140 KPrinterImpl::broadcastOption("PageSize",pagename);
141 // simple hack for classes
142 KPrinterImpl::broadcastOption("media",pagename);
143 }
144}
145
146//******************************************************************************************************
147
148static void mapToCupsOptions(const TQMap<TQString,TQString>& opts, TQString& cmd)
149{
150 TQString optstr;
151 for (TQMap<TQString,TQString>::ConstIterator it=opts.begin(); it!=opts.end(); ++it)
152 {
153 // only encode those options that doesn't start with "kde-" or "app-".
154 if (!it.key().startsWith("kde-") && !it.key().startsWith("app-") && !it.key().startsWith("_kde"))
155 {
156 TQString key = it.key();
157 if (key.startsWith("KDEPrint-"))
158 /* Those are keys added by the "Additional Tags" page. *
159 * Strip the prefix to build valid a CUPS option. */
160 key = key.mid(9);
161 optstr.append(" ").append(key);
162 if (!it.data().isEmpty())
163 optstr.append("=").append(it.data());
164 }
165 }
166 if (!optstr.isEmpty())
167 cmd.append(" -o ").append( TDEProcess::quote( optstr ) );
168}
KPrinter
This class is the main interface to access the TDE print framework.
Definition kprinter.h:89
KPrinter::docName
TQString docName() const
See TQPrinter::docName().
Definition kprinter.cpp:797
KPrinter::PageSize
PageSize
Defines the paper size to use.
Definition kprinter.h:168
KPrinter::option
const TQString & option(const TQString &key) const
Starts the add printer wizard.
Definition kprinter.cpp:791
KPrinter::setErrorMessage
void setErrorMessage(const TQString &msg)
Sets the last error message.
Definition kprinter.cpp:1016
KPrinter::printerName
TQString printerName() const
See TQPrinter::printerName().
Definition kprinter.cpp:870
KPrinter::setOption
void setOption(const TQString &key, const TQString &value)
Adds or modifies an option in the KPrinter object.
Definition kprinter.cpp:794
KPrinter::options
const TQMap< TQString, TQString > & options() const
Returns the complete set of print options from the KPrinter object.
Definition kprinter.cpp:903
KPrinter::pageSelection
static PageSelectionType pageSelection()
Returns the page selection mode of the current application.
Definition kprinter.cpp:260
KPrinter::applicationType
static ApplicationType applicationType()
Returns the application type concerning the print dialog.
Definition kprinter.cpp:270

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.15.0
This website is maintained by Timothy Pearson.