20 #include "kpfilterpage.h"
21 #include "kmfactory.h"
22 #include "kxmlcommand.h"
24 #include <tqtoolbutton.h>
26 #include <tqtooltip.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>
35 #include <tdeapplication.h>
38 KPFilterPage::KPFilterPage(TQWidget *parent,
const char *name)
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>"
54 TQString whatsThisRemoveFilterButton = i18n(
" <qt> <b>Remove Filter button</b>"
55 " <p>This button removes the highlighted filter from the"
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>"
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>"
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. "
75 TQString whatsThisFilterInfoPane = i18n(
" <qt> <b>Filter Info Pane</b>"
76 " <p>This field shows some general info about the selected filter. "
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> "
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> "
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> "
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 "
125 setTitle(i18n(
"Filters"));
126 m_activefilters.setAutoDelete(
true);
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,TQ_SIGNAL(selectionChanged(TQListViewItem*)),TQ_SLOT(slotItemSelected(TQListViewItem*)));
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"));
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"));
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"));
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"));
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"));
163 connect(m_add,TQ_SIGNAL(clicked()),TQ_SLOT(slotAddClicked()));
164 connect(m_remove,TQ_SIGNAL(clicked()),TQ_SLOT(slotRemoveClicked()));
165 connect(m_up,TQ_SIGNAL(clicked()),TQ_SLOT(slotUpClicked()));
166 connect(m_down,TQ_SIGNAL(clicked()),TQ_SLOT(slotDownClicked()));
167 connect(m_configure,TQ_SIGNAL(clicked()),TQ_SLOT(slotConfigureClicked()));
168 connect(m_view,TQ_SIGNAL(doubleClicked(TQListViewItem*)),TQ_SLOT(slotConfigureClicked()));
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 ) );
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);
186 l2->addWidget(m_down);
188 l2->addWidget(m_configure);
190 l1->addMultiCellWidget(m_info, 1, 1, 0, 1);
196 KPFilterPage::~KPFilterPage()
200 void KPFilterPage::updateButton()
210 void KPFilterPage::slotAddClicked()
213 TQString choice = KXmlCommandManager::self()->selectCommand(
this );
214 ok = !choice.isEmpty();
217 KXmlCommand *cmd = KXmlCommandManager::self()->loadCommand(choice);
219 TQStringList filters = activeList();
220 int pos = KXmlCommandManager::self()->insertCommand(filters, cmd->name());
221 TQListViewItem *prev(0);
224 prev = m_view->firstChild();
225 for (
int i=1;prev && i<pos;i++)
226 prev = prev->nextSibling();
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"));
235 void KPFilterPage::slotRemoveClicked()
237 if (m_view->selectedItem())
239 TQString idname = m_view->selectedItem()->text(1);
240 delete m_view->selectedItem();
241 m_activefilters.remove(idname);
243 if (m_view->currentItem())
244 m_view->setSelected(m_view->currentItem(),
true);
245 slotItemSelected(m_view->currentItem());
249 void KPFilterPage::slotUpClicked()
251 TQListViewItem *item = m_view->selectedItem();
252 if (item && item->itemAbove())
254 TQListViewItem *clone =
new TQListViewItem(m_view,item->itemAbove()->itemAbove(),item->text(0),item->text(1));
255 clone->setPixmap(0, SmallIcon(
"filter"));
257 m_view->setSelected(clone,
true);
262 void KPFilterPage::slotDownClicked()
264 TQListViewItem *item = m_view->selectedItem();
265 if (item && item->itemBelow())
267 TQListViewItem *clone =
new TQListViewItem(m_view,item->itemBelow(),item->text(0),item->text(1));
268 clone->setPixmap(0, SmallIcon(
"filter"));
270 m_view->setSelected(clone,
true);
275 void KPFilterPage::slotConfigureClicked()
277 KXmlCommand *filter = currentFilter();
278 if (!filter || !KXmlCommandManager::self()->configure(filter,
this))
279 KMessageBox::error(
this,i18n(
"Internal error: unable to load filter."));
282 void KPFilterPage::slotItemSelected(TQListViewItem *item)
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));
291 void KPFilterPage::setOptions(
const TQMap<TQString,TQString>& opts)
293 TQStringList filters = TQStringList::split(
',',opts[
"_kde-filters"],
false);
295 TQDictIterator<KXmlCommand> dit(m_activefilters);
296 for (;dit.current();)
298 if (filters.find(dit.currentKey()) == filters.end())
299 m_activefilters.remove(dit.currentKey());
302 dit.current()->setOptions(opts);
308 TQListViewItem *item(0);
309 for (TQStringList::ConstIterator sit=filters.begin(); sit!=filters.end(); ++sit)
312 if ((f=m_activefilters.find(*sit)) == 0)
314 f = KXmlCommandManager::self()->loadCommand(*sit);
317 m_activefilters.insert(*sit,f);
322 item =
new TQListViewItem(m_view,item,f->description(),f->name());
327 void KPFilterPage::getOptions(TQMap<TQString,TQString>& opts,
bool incldef)
329 TQStringList filters = activeList();
330 for (TQStringList::ConstIterator it=filters.begin(); it!=filters.end(); ++it)
332 KXmlCommand *f = m_activefilters.find(*it);
334 f->getOptions(opts, incldef);
336 if (filters.count() > 0 || incldef)
338 opts[
"_kde-filters"] = filters.join(
",");
342 TQStringList KPFilterPage::activeList()
345 TQListViewItem *item = m_view->firstChild();
348 list.append(item->text(1));
349 item = item->nextSibling();
354 KXmlCommand* KPFilterPage::currentFilter()
356 KXmlCommand *filter(0);
357 if (m_view->selectedItem())
358 filter = m_activefilters.find(m_view->selectedItem()->text(1));
362 void KPFilterPage::checkFilterChain()
364 TQListViewItem *item = m_view->firstChild();
369 item->setPixmap(0, (ok ? SmallIcon(
"filter") : SmallIcon(
"filterstop")));
370 KXmlCommand *f1 = m_activefilters.find(item->text(1));
371 if (f1 && item->nextSibling())
373 KXmlCommand *f2 = m_activefilters.find(item->nextSibling()->text(1));
376 if (!f2->acceptMimeType(f1->mimeType()))
378 item->setPixmap(0, SmallIcon(
"filterstop"));
386 item = item->nextSibling();
390 bool KPFilterPage::isValid(TQString& msg)
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>");
399 void KPFilterPage::updateInfo()
402 KXmlCommand *f = currentFilter();
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() );
413 m_info->setText(txt);
416 #include "kpfilterpage.moc"
This class is intended to be used as base class for customized print dialog page.