00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "kmconfigfilter.h"
00021
#include "kmmanager.h"
00022
#include "kmfactory.h"
00023
00024
#include <qgroupbox.h>
00025
#include <qlineedit.h>
00026
#include <qtoolbutton.h>
00027
#include <qlayout.h>
00028
#include <qlabel.h>
00029
#include <qapplication.h>
00030
00031
#include <klocale.h>
00032
#include <kconfig.h>
00033
#include <kiconloader.h>
00034
#include <klistbox.h>
00035
#include <kdialog.h>
00036
00037 KMConfigFilter::KMConfigFilter(
QWidget *parent,
const char *name)
00038 : KMConfigPage(parent, name)
00039 {
00040 setPageName(i18n(
"Filter"));
00041 setPageHeader(i18n(
"Printer Filtering Settings"));
00042 setPagePixmap(
"filter");
00043
00044
QGroupBox *box =
new QGroupBox(0, Qt::Vertical, i18n(
"Printer Filter"),
this);
00045
00046 m_list1 =
new KListBox(box);
00047 m_list1->setSelectionMode(KListBox::Extended);
00048 m_list2 =
new KListBox(box);
00049 m_list2->setSelectionMode(KListBox::Extended);
00050 m_add =
new QToolButton( box );
00051 m_add->setIconSet(QApplication::reverseLayout() ? SmallIconSet(
"back" ) : SmallIconSet(
"forward" ));
00052 m_remove =
new QToolButton( box );
00053 m_remove->setIconSet(QApplication::reverseLayout() ? SmallIconSet(
"forward" ) : SmallIconSet(
"back" ));
00054 m_locationre =
new QLineEdit(box);
00055
QLabel *lab =
new QLabel(box);
00056 lab->
setText(i18n(
"The printer filtering allows you to view only a specific set of "
00057
"printers instead of all of them. This may be useful when there are a "
00058
"lot of printers available but you only use a few ones. Select the "
00059
"printers you want to see from the list on the left or enter a <b>Location</b> "
00060
"filter (ex: Group_1*). Both are cumulative and ignored if empty."));
00061 lab->
setTextFormat(Qt::RichText);
00062 QLabel *lab1 =
new QLabel(i18n(
"Location filter:"), box);
00063
00064
QVBoxLayout *l0 =
new QVBoxLayout(
this, 0, KDialog::spacingHint());
00065 l0->addWidget(box, 1);
00066 QVBoxLayout *l1 =
new QVBoxLayout(box->layout(), KDialog::spacingHint());
00067 l1->addWidget(lab);
00068
QGridLayout *l2 =
new QGridLayout(0, 4, 3, 0, KDialog::spacingHint());
00069 l1->addLayout(l2);
00070 l2->
setRowStretch(0, 1);
00071 l2->
setRowStretch(3, 1);
00072 l2->
setColStretch(0, 1);
00073 l2->
setColStretch(2, 1);
00074 l2->
addMultiCellWidget(m_list1, 0, 3, 0, 0);
00075 l2->
addMultiCellWidget(m_list2, 0, 3, 2, 2);
00076 l2->
addWidget(m_add, 1, 1);
00077 l2->
addWidget(m_remove, 2, 1);
00078
QHBoxLayout *l3 =
new QHBoxLayout(0, 0, KDialog::spacingHint());
00079 l1->addLayout(l3, 0);
00080 l3->addWidget(lab1, 0);
00081 l3->addWidget(m_locationre, 1);
00082
00083 connect(m_add, SIGNAL(clicked()), SLOT(slotAddClicked()));
00084 connect(m_remove, SIGNAL(clicked()), SLOT(slotRemoveClicked()));
00085 connect(m_list1, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
00086 connect(m_list2, SIGNAL(selectionChanged()), SLOT(slotSelectionChanged()));
00087 m_add->setEnabled(
false);
00088 m_remove->setEnabled(
false);
00089 }
00090
00091
void KMConfigFilter::loadConfig(KConfig *conf)
00092 {
00093 conf->setGroup(
"Filter");
00094
QStringList m_plist = conf->readListEntry(
"Printers");
00095
QPtrListIterator<KMPrinter> it(*(KMManager::self()->printerListComplete(
false)));
00096
for (; it.
current(); ++it)
00097 {
00098
if (!it.
current()->isSpecial() && !it.
current()->isVirtual())
00099 {
00100 KListBox *lb = (m_plist.find(it.
current()->printerName()) == m_plist.end() ? m_list1 : m_list2);
00101 lb->insertItem(SmallIcon(it.
current()->pixmap()), it.
current()->printerName());
00102 }
00103 }
00104 m_list1->sort();
00105 m_list2->sort();
00106 m_locationre->setText(conf->readEntry(
"LocationRe"));
00107 }
00108
00109
void KMConfigFilter::saveConfig(KConfig *conf)
00110 {
00111 conf->setGroup(
"Filter");
00112
QStringList plist;
00113
for (uint i=0; i<m_list2->count(); i++)
00114 plist << m_list2->text(i);
00115 conf->writeEntry(
"Printers", plist);
00116 conf->writeEntry(
"LocationRe", m_locationre->text());
00117 }
00118
00119
void KMConfigFilter::transfer(KListBox *from, KListBox *to)
00120 {
00121
for (uint i=0; i<from->count();)
00122 {
00123
if (from->isSelected(i))
00124 {
00125 to->insertItem(*(from->pixmap(i)), from->text(i));
00126 from->removeItem(i);
00127 }
00128
else
00129 i++;
00130 }
00131 to->sort();
00132 }
00133
00134
void KMConfigFilter::slotAddClicked()
00135 {
00136 transfer(m_list1, m_list2);
00137 }
00138
00139
void KMConfigFilter::slotRemoveClicked()
00140 {
00141 transfer(m_list2, m_list1);
00142 }
00143
00144
void KMConfigFilter::slotSelectionChanged()
00145 {
00146
const KListBox *lb = static_cast<const KListBox*>(sender());
00147
if (!lb)
00148
return;
00149 QToolButton *pb = (lb == m_list1 ? m_add : m_remove);
00150
for (uint i=0; i<lb->count(); i++)
00151
if (lb->isSelected(i))
00152 {
00153 pb->setEnabled(
true);
00154
return;
00155 }
00156 pb->setEnabled(
false);
00157 }
00158
00159
#include "kmconfigfilter.moc"