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

tdeprint

  • tdeprint
kpfilterpage.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 "kpfilterpage.h"
21 #include "kmfactory.h"
22 #include "kxmlcommand.h"
23 
24 #include <tqtoolbutton.h>
25 #include <tqheader.h>
26 #include <tqtooltip.h>
27 #include <tqlayout.h>
28 #include <tqwhatsthis.h>
29 #include <tdelistview.h>
30 #include <tdelocale.h>
31 #include <kiconloader.h>
32 #include <tdemessagebox.h>
33 #include <kactivelabel.h>
34 #include <kdebug.h>
35 #include <tdeapplication.h>
36 #include <kdialog.h>
37 
38 KPFilterPage::KPFilterPage(TQWidget *parent, const char *name)
39 : KPrintDialogPage(parent,name)
40 {
41  //WhatsThis strings.... (added by pfeifle@kde.org)
42  TQString whatsThisAddFilterButton = i18n( " <qt> <b>Add Filter button</b>"
43  " <p>This button calls a little dialog to let you"
44  " select a filter here. </p>"
45  " <p><b>Note 1:</b> You can chain different filters as long as you make "
46  " sure that the output of one fits as input of the next. (TDEPrint "
47  " checks your filtering chain and will warn you if you fail to do so.</p> "
48  " <p><b>Note 2:</b> The filters you define here are applied to your jobfile "
49  " <em><b>before</b></em> it is handed downstream to your spooler and print "
50  " subsystem (e.g. CUPS, LPRng, LPD).</p>"
51  " </ul>"
52  " </qt>" );
53 
54  TQString whatsThisRemoveFilterButton = i18n(" <qt> <b>Remove Filter button</b>"
55  " <p>This button removes the highlighted filter from the"
56  " list of filters."
57  " </qt>" );
58 
59  TQString whatsThisMoveFilterUpButton = i18n(" <qt> <b>Move Filter Up button</b>"
60  " <p>This button moves the highlighted filter up in the list"
61  " of filters, towards the front of the filtering chain. </p>"
62  " </qt>" );
63 
64  TQString whatsThisMoveFilterDownButton = i18n(" <qt> <b>Move Filter Down button</b>"
65  " <p>This button moves the highlighted filter down in the list"
66  " of filters, towards the end of the filtering chain..</p>"
67  " </qt>" );
68 
69  TQString whatsThisConfigureFilterButton = i18n( " <qt> <b>Configure Filter button</b>"
70  " <p>This button lets you configure the currently highlighted filter."
71  " It opens a separate dialog. "
72  " </p>"
73  " </qt>" );
74 
75  TQString whatsThisFilterInfoPane = i18n( " <qt> <b>Filter Info Pane</b>"
76  " <p>This field shows some general info about the selected filter. "
77  " Amongst them are: "
78  " <ul> "
79  " <li>the <em>filter name</em> (as displayed in the TDEPrint user interface); </li> "
80  " <li>the <em>filter requirements</em> (that is the external program that needs "
81  " to present and executable on this system); </li> "
82  " <li>the <em>filter input format</em> (in the form of one or several <em>MIME types</em>"
83  " accepted by the filter); </li> "
84  " <li>the <em>filter output format</em> (in the form of a <em>MIME type</em> "
85  " generated by the filter); </li> "
86  " <li>a more or less verbose text describing the filter's operation.</li> "
87  " </ul> "
88  " </p>"
89  " </qt>" );
90 
91  TQString whatsThisFilterchainListView = i18n( " <qt> <b>Filtering Chain</b> (if enabled, is run <em>before</em> actual "
92  " job submission to print system)"
93  " <p>This field shows which filters are currently selected to act as 'pre-filters' "
94  " for TDEPrint. Pre-filters are processing the print files <em>before</em> they are "
95  " send downstream to your real print subsystem. </p> "
96  " <p>The list shown in this field may be empty (default). </p> "
97  " <p>The pre-filters act on the printjob in the order they are listed (from top to bottom). "
98  " This is done by acting as a <em>filtering chain</em> where the output of one filter "
99  " acts as input to the next. By putting the filters into the wrong order, you can make "
100  " the filtering chain fail. For example: if your file is ASCII text, and you want the "
101  " output being processed by the 'Multipage per Sheet' filter, the first filter must be "
102  " one that processes ASCII into PostScript. </p> "
103  " <p>TDEPrint can utilize <em>any</em> external filtering program which you may find useful "
104  " through this interface. </p> "
105  " <p>TDEPrint ships preconfigured with support for a selection of common filters. These "
106  " filters however need to be "
107  " installed independently from TDEPrint. These pre-filters work <em>for all</em> print subsystems"
108  " supported by TDEPrint (such as CUPS, LPRng and LPD), because they are not depending on these.</p> "
109  ".<p> Amongst the pre-configured filters shipping with TDEPrint are: </p> "
110  " <ul> "
111  " <li>the <em>Enscript text filter</em> </li> "
112  " <li>a <em>Multiple Pages per Sheet filter</em </li> "
113  " <li>a <em>PostScript to PDF converter</em>.</li> "
114  " <li>a <em>Page Selection/Ordering filter</em>.</li> "
115  " <li>a <em>Poster Printing filter</em>.</li> "
116  " <li>and some more..</li> "
117  " </ul> "
118  " To insert a filter into this list, simply click on the <em>funnel</em> icon (topmost on "
119  " the right icon column group) and proceed. </p>"
120  " <p>Please click on the other elements of this dialog to learn more about the TDEPrint "
121  " pre-filters. "
122  " </p>"
123  " </qt>" );
124 
125  setTitle(i18n("Filters"));
126  m_activefilters.setAutoDelete(true);
127  m_valid = true;
128 
129  m_view = new TDEListView(this);
130  TQWhatsThis::add(m_view, whatsThisFilterchainListView);
131  m_view->addColumn("");
132  m_view->setFrameStyle(TQFrame::WinPanel|TQFrame::Sunken);
133  m_view->setLineWidth(1);
134  m_view->setSorting(-1);
135  m_view->header()->hide();
136  connect(m_view,TQT_SIGNAL(selectionChanged(TQListViewItem*)),TQT_SLOT(slotItemSelected(TQListViewItem*)));
137 
138  m_add = new TQToolButton(this);
139  TQWhatsThis::add(m_add, whatsThisAddFilterButton);
140  m_add->setIconSet(BarIconSet("filter"));
141  TQToolTip::add(m_add, i18n("Add filter"));
142 
143  m_remove = new TQToolButton(this);
144  TQWhatsThis::add(m_remove, whatsThisRemoveFilterButton);
145  m_remove->setIconSet(BarIconSet("remove"));
146  TQToolTip::add(m_remove, i18n("Remove filter"));
147 
148  m_up = new TQToolButton(this);
149  TQWhatsThis::add(m_up, whatsThisMoveFilterUpButton);
150  m_up->setIconSet(BarIconSet("go-up"));
151  TQToolTip::add(m_up, i18n("Move filter up"));
152 
153  m_down = new TQToolButton(this);
154  TQWhatsThis::add(m_down, whatsThisMoveFilterDownButton);
155  m_down->setIconSet(BarIconSet("go-down"));
156  TQToolTip::add(m_down, i18n("Move filter down"));
157 
158  m_configure = new TQToolButton(this);
159  TQWhatsThis::add(m_configure, whatsThisConfigureFilterButton);
160  m_configure->setIconSet(BarIconSet("configure"));
161  TQToolTip::add(m_configure, i18n("Configure filter"));
162 
163  connect(m_add,TQT_SIGNAL(clicked()),TQT_SLOT(slotAddClicked()));
164  connect(m_remove,TQT_SIGNAL(clicked()),TQT_SLOT(slotRemoveClicked()));
165  connect(m_up,TQT_SIGNAL(clicked()),TQT_SLOT(slotUpClicked()));
166  connect(m_down,TQT_SIGNAL(clicked()),TQT_SLOT(slotDownClicked()));
167  connect(m_configure,TQT_SIGNAL(clicked()),TQT_SLOT(slotConfigureClicked()));
168  connect(m_view,TQT_SIGNAL(doubleClicked(TQListViewItem*)),TQT_SLOT(slotConfigureClicked()));
169 
170  m_info = new KActiveLabel(this);
171  TQWhatsThis::add(m_info, whatsThisFilterInfoPane);
172  m_info->setVScrollBarMode( TQScrollView::Auto );
173  m_info->setHScrollBarMode( TQScrollView::Auto );
174  m_info->setFrameStyle( TQFrame::Panel|TQFrame::Sunken );
175  m_info->setMinimumSize( TQSize( 240, 100 ) );
176 
177  TQGridLayout *l1 = new TQGridLayout(this, 2, 2, 0, KDialog::spacingHint());
178  l1->setColStretch(0, 1);
179  TQVBoxLayout *l2 = new TQVBoxLayout(0, 0, 1);
180  l1->addWidget(m_view, 0, 0);
181  l1->addLayout(l2, 0, 1);
182  l2->addWidget(m_add);
183  l2->addWidget(m_remove);
184  l2->addSpacing(5);
185  l2->addWidget(m_up);
186  l2->addWidget(m_down);
187  l2->addSpacing(5);
188  l2->addWidget(m_configure);
189  l2->addStretch(1);
190  l1->addMultiCellWidget(m_info, 1, 1, 0, 1);
191  slotItemSelected(0);
192 
193  resize(100,50);
194 }
195 
196 KPFilterPage::~KPFilterPage()
197 {
198 }
199 
200 void KPFilterPage::updateButton()
201 {
202 /* TQListViewItem *item = m_view->currentItem();
203  bool state=(item!=0);
204  m_remove->setEnabled(state);
205  m_up->setEnabled((state && item->itemAbove() != 0));
206  m_down->setEnabled((state && item->itemBelow() != 0));
207  m_configure->setEnabled(state);*/
208 }
209 
210 void KPFilterPage::slotAddClicked()
211 {
212  bool ok;
213  TQString choice = KXmlCommandManager::self()->selectCommand( this );
214  ok = !choice.isEmpty();
215  if (ok)
216  {
217  KXmlCommand *cmd = KXmlCommandManager::self()->loadCommand(choice);
218  if (!cmd) return; // Error
219  TQStringList filters = activeList();
220  int pos = KXmlCommandManager::self()->insertCommand(filters, cmd->name());
221  TQListViewItem *prev(0);
222  if (pos > 0)
223  {
224  prev = m_view->firstChild();
225  for (int i=1;prev && i<pos;i++)
226  prev = prev->nextSibling();
227  }
228  m_activefilters.insert(cmd->name(), cmd);
229  TQListViewItem *item = new TQListViewItem(m_view, prev, cmd->description(), cmd->name());
230  item->setPixmap(0, SmallIcon("filter"));
231  checkFilterChain();
232  }
233 }
234 
235 void KPFilterPage::slotRemoveClicked()
236 {
237  if (m_view->selectedItem())
238  {
239  TQString idname = m_view->selectedItem()->text(1);
240  delete m_view->selectedItem();
241  m_activefilters.remove(idname);
242  checkFilterChain();
243  if (m_view->currentItem())
244  m_view->setSelected(m_view->currentItem(), true);
245  slotItemSelected(m_view->currentItem());
246  }
247 }
248 
249 void KPFilterPage::slotUpClicked()
250 {
251  TQListViewItem *item = m_view->selectedItem();
252  if (item && item->itemAbove())
253  {
254  TQListViewItem *clone = new TQListViewItem(m_view,item->itemAbove()->itemAbove(),item->text(0),item->text(1));
255  clone->setPixmap(0, SmallIcon("filter"));
256  delete item;
257  m_view->setSelected(clone, true);
258  checkFilterChain();
259  }
260 }
261 
262 void KPFilterPage::slotDownClicked()
263 {
264  TQListViewItem *item = m_view->selectedItem();
265  if (item && item->itemBelow())
266  {
267  TQListViewItem *clone = new TQListViewItem(m_view,item->itemBelow(),item->text(0),item->text(1));
268  clone->setPixmap(0, SmallIcon("filter"));
269  delete item;
270  m_view->setSelected(clone, true);
271  checkFilterChain();
272  }
273 }
274 
275 void KPFilterPage::slotConfigureClicked()
276 {
277  KXmlCommand *filter = currentFilter();
278  if (!filter || !KXmlCommandManager::self()->configure(filter, this))
279  KMessageBox::error(this,i18n("Internal error: unable to load filter."));
280 }
281 
282 void KPFilterPage::slotItemSelected(TQListViewItem *item)
283 {
284  m_remove->setEnabled((item != 0));
285  m_up->setEnabled((item != 0 && item->itemAbove() != 0));
286  m_down->setEnabled((item != 0 && item->itemBelow() != 0));
287  m_configure->setEnabled((item != 0));
288  updateInfo();
289 }
290 
291 void KPFilterPage::setOptions(const TQMap<TQString,TQString>& opts)
292 {
293  TQStringList filters = TQStringList::split(',',opts["_kde-filters"],false);
294  // remove unneeded filters
295  TQDictIterator<KXmlCommand> dit(m_activefilters);
296  for (;dit.current();)
297  {
298  if (filters.find(dit.currentKey()) == filters.end())
299  m_activefilters.remove(dit.currentKey());
300  else
301  {
302  dit.current()->setOptions(opts);
303  ++dit;
304  }
305  }
306  // add needed filters
307  m_view->clear();
308  TQListViewItem *item(0);
309  for (TQStringList::ConstIterator sit=filters.begin(); sit!=filters.end(); ++sit)
310  {
311  KXmlCommand *f(0);
312  if ((f=m_activefilters.find(*sit)) == 0)
313  {
314  f = KXmlCommandManager::self()->loadCommand(*sit);
315  if (f)
316  {
317  m_activefilters.insert(*sit,f);
318  f->setOptions(opts);
319  }
320  }
321  if (f)
322  item = new TQListViewItem(m_view,item,f->description(),f->name());
323  }
324  checkFilterChain();
325 }
326 
327 void KPFilterPage::getOptions(TQMap<TQString,TQString>& opts, bool incldef)
328 {
329  TQStringList filters = activeList();
330  for (TQStringList::ConstIterator it=filters.begin(); it!=filters.end(); ++it)
331  {
332  KXmlCommand *f = m_activefilters.find(*it);
333  if (f)
334  f->getOptions(opts, incldef);
335  }
336  if (filters.count() > 0 || incldef)
337  {
338  opts["_kde-filters"] = filters.join(",");
339  }
340 }
341 
342 TQStringList KPFilterPage::activeList()
343 {
344  TQStringList list;
345  TQListViewItem *item = m_view->firstChild();
346  while (item)
347  {
348  list.append(item->text(1));
349  item = item->nextSibling();
350  }
351  return list;
352 }
353 
354 KXmlCommand* KPFilterPage::currentFilter()
355 {
356  KXmlCommand *filter(0);
357  if (m_view->selectedItem())
358  filter = m_activefilters.find(m_view->selectedItem()->text(1));
359  return filter;
360 }
361 
362 void KPFilterPage::checkFilterChain()
363 {
364  TQListViewItem *item = m_view->firstChild();
365  bool ok(true);
366  m_valid = true;
367  while (item)
368  {
369  item->setPixmap(0, (ok ? SmallIcon("filter") : SmallIcon("filterstop")));
370  KXmlCommand *f1 = m_activefilters.find(item->text(1));
371  if (f1 && item->nextSibling())
372  {
373  KXmlCommand *f2 = m_activefilters.find(item->nextSibling()->text(1));
374  if (f2)
375  {
376  if (!f2->acceptMimeType(f1->mimeType()))
377  {
378  item->setPixmap(0, SmallIcon("filterstop"));
379  ok = false;
380  m_valid = false;
381  }
382  else
383  ok = true;
384  }
385  }
386  item = item->nextSibling();
387  }
388 }
389 
390 bool KPFilterPage::isValid(TQString& msg)
391 {
392  if (!m_valid)
393  {
394  msg = i18n("<p>The filter chain is wrong. The output format of at least one filter is not supported by its follower. See <b>Filters</b> tab for more information.</p>");
395  }
396  return m_valid;
397 }
398 
399 void KPFilterPage::updateInfo()
400 {
401  TQString txt;
402  KXmlCommand *f = currentFilter();
403  if (f)
404  {
405  TQString templ("<b>%1:</b> %2<br>");
406  txt.append(templ.arg(i18n("Name")).arg(f->name()));
407  txt.append(templ.arg(i18n("Requirements")).arg(f->requirements().join(", ")));
408  txt.append(templ.arg(i18n("Input")).arg(f->inputMimeTypes().join(", ")));
409  txt.append(templ.arg(i18n("Output")).arg(f->mimeType()));
410  if ( !f->comment().isEmpty() )
411  txt.append( "<br>" ).append( f->comment() );
412  }
413  m_info->setText(txt);
414 }
415 
416 #include "kpfilterpage.moc"
KPrintDialogPage
This class is intended to be used as base class for customized print dialog page. ...
Definition: kprintdialogpage.h:90

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.