20 #include "kmconfigfilter.h"
21 #include "kmmanager.h"
22 #include "kmfactory.h"
24 #include <tqgroupbox.h>
25 #include <tqlineedit.h>
26 #include <tqtoolbutton.h>
29 #include <tqapplication.h>
31 #include <tdelocale.h>
32 #include <tdeconfig.h>
33 #include <kiconloader.h>
34 #include <tdelistbox.h>
37 KMConfigFilter::KMConfigFilter(TQWidget *parent,
const char *name)
38 : KMConfigPage(parent, name)
40 setPageName(i18n(
"Filter"));
41 setPageHeader(i18n(
"Printer Filtering Settings"));
42 setPagePixmap(
"filter");
44 TQGroupBox *box =
new TQGroupBox(0, TQt::Vertical, i18n(
"Printer Filter"),
this);
46 m_list1 =
new TDEListBox(box);
47 m_list1->setSelectionMode(TDEListBox::Extended);
48 m_list2 =
new TDEListBox(box);
49 m_list2->setSelectionMode(TDEListBox::Extended);
50 m_add =
new TQToolButton( box );
51 m_add->setIconSet(TQApplication::reverseLayout() ? SmallIconSet(
"back" ) : SmallIconSet(
"forward" ));
52 m_remove =
new TQToolButton( box );
53 m_remove->setIconSet(TQApplication::reverseLayout() ? SmallIconSet(
"forward" ) : SmallIconSet(
"back" ));
54 m_locationre =
new TQLineEdit(box);
55 TQLabel *lab =
new TQLabel(box);
56 lab->setText(i18n(
"The printer filtering allows you to view only a specific set of "
57 "printers instead of all of them. This may be useful when there are a "
58 "lot of printers available but you only use a few ones. Select the "
59 "printers you want to see from the list on the left or enter a <b>Location</b> "
60 "filter (ex: Group_1*). Both are cumulative and ignored if empty."));
61 lab->setTextFormat(TQt::RichText);
62 TQLabel *lab1 =
new TQLabel(i18n(
"Location filter:"), box);
64 TQVBoxLayout *l0 =
new TQVBoxLayout(
this, 0, KDialog::spacingHint());
65 l0->addWidget(box, 1);
66 TQVBoxLayout *l1 =
new TQVBoxLayout(box->layout(), KDialog::spacingHint());
68 TQGridLayout *l2 =
new TQGridLayout(0, 4, 3, 0, KDialog::spacingHint());
70 l2->setRowStretch(0, 1);
71 l2->setRowStretch(3, 1);
72 l2->setColStretch(0, 1);
73 l2->setColStretch(2, 1);
74 l2->addMultiCellWidget(m_list1, 0, 3, 0, 0);
75 l2->addMultiCellWidget(m_list2, 0, 3, 2, 2);
76 l2->addWidget(m_add, 1, 1);
77 l2->addWidget(m_remove, 2, 1);
78 TQHBoxLayout *l3 =
new TQHBoxLayout(0, 0, KDialog::spacingHint());
80 l3->addWidget(lab1, 0);
81 l3->addWidget(m_locationre, 1);
83 connect(m_add, TQ_SIGNAL(clicked()), TQ_SLOT(slotAddClicked()));
84 connect(m_remove, TQ_SIGNAL(clicked()), TQ_SLOT(slotRemoveClicked()));
85 connect(m_list1, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
86 connect(m_list2, TQ_SIGNAL(selectionChanged()), TQ_SLOT(slotSelectionChanged()));
87 m_add->setEnabled(
false);
88 m_remove->setEnabled(
false);
91 void KMConfigFilter::loadConfig(TDEConfig *conf)
93 conf->setGroup(
"Filter");
94 TQStringList m_plist = conf->readListEntry(
"Printers");
95 TQPtrListIterator<KMPrinter> it(*(KMManager::self()->printerListComplete(
false)));
96 for (; it.current(); ++it)
98 if (!it.current()->isSpecial() && !it.current()->isVirtual())
100 TDEListBox *lb = (m_plist.find(it.current()->printerName()) == m_plist.end() ? m_list1 : m_list2);
101 lb->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName());
106 m_locationre->setText(conf->readEntry(
"LocationRe"));
109 void KMConfigFilter::saveConfig(TDEConfig *conf)
111 conf->setGroup(
"Filter");
113 for (uint i=0; i<m_list2->count(); i++)
114 plist << m_list2->text(i);
115 conf->writeEntry(
"Printers", plist);
116 conf->writeEntry(
"LocationRe", m_locationre->text());
119 void KMConfigFilter::transfer(TDEListBox *from, TDEListBox *to)
121 for (uint i=0; i<from->count();)
123 if (from->isSelected(i))
125 to->insertItem(*(from->pixmap(i)), from->text(i));
134 void KMConfigFilter::slotAddClicked()
136 transfer(m_list1, m_list2);
139 void KMConfigFilter::slotRemoveClicked()
141 transfer(m_list2, m_list1);
144 void KMConfigFilter::slotSelectionChanged()
146 const TDEListBox *lb =
static_cast<const TDEListBox*
>(sender());
149 TQToolButton *pb = (lb == m_list1 ? m_add : m_remove);
150 for (uint i=0; i<lb->count(); i++)
151 if (lb->isSelected(i))
153 pb->setEnabled(
true);
156 pb->setEnabled(
false);
159 #include "kmconfigfilter.moc"