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

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.