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

kdeprint

  • kdeprint
  • management
kmconfigfilter.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <kdeprint@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 "kmconfigfilter.h"
21 #include "kmmanager.h"
22 #include "kmfactory.h"
23 
24 #include <tqgroupbox.h>
25 #include <tqlineedit.h>
26 #include <tqtoolbutton.h>
27 #include <tqlayout.h>
28 #include <tqlabel.h>
29 #include <tqapplication.h>
30 
31 #include <klocale.h>
32 #include <kconfig.h>
33 #include <kiconloader.h>
34 #include <klistbox.h>
35 #include <kdialog.h>
36 
37 KMConfigFilter::KMConfigFilter(TQWidget *parent, const char *name)
38 : KMConfigPage(parent, name)
39 {
40  setPageName(i18n("Filter"));
41  setPageHeader(i18n("Printer Filtering Settings"));
42  setPagePixmap("filter");
43 
44  TQGroupBox *box = new TQGroupBox(0, Qt::Vertical, i18n("Printer Filter"), this);
45 
46  m_list1 = new KListBox(box);
47  m_list1->setSelectionMode(KListBox::Extended);
48  m_list2 = new KListBox(box);
49  m_list2->setSelectionMode(KListBox::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);
63 
64  TQVBoxLayout *l0 = new TQVBoxLayout(this, 0, KDialog::spacingHint());
65  l0->addWidget(box, 1);
66  TQVBoxLayout *l1 = new TQVBoxLayout(TQT_TQLAYOUT(box->layout()), KDialog::spacingHint());
67  l1->addWidget(lab);
68  TQGridLayout *l2 = new TQGridLayout(0, 4, 3, 0, KDialog::spacingHint());
69  l1->addLayout(TQT_TQLAYOUT(l2));
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());
79  l1->addLayout(l3, 0);
80  l3->addWidget(lab1, 0);
81  l3->addWidget(m_locationre, 1);
82 
83  connect(m_add, TQT_SIGNAL(clicked()), TQT_SLOT(slotAddClicked()));
84  connect(m_remove, TQT_SIGNAL(clicked()), TQT_SLOT(slotRemoveClicked()));
85  connect(m_list1, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelectionChanged()));
86  connect(m_list2, TQT_SIGNAL(selectionChanged()), TQT_SLOT(slotSelectionChanged()));
87  m_add->setEnabled(false);
88  m_remove->setEnabled(false);
89 }
90 
91 void KMConfigFilter::loadConfig(KConfig *conf)
92 {
93  conf->setGroup("Filter");
94  TQStringList m_plist = conf->readListEntry("Printers");
95  TQPtrListIterator<KMPrinter> it(*(KMManager::self()->printerListComplete(false)));
96  for (; it.current(); ++it)
97  {
98  if (!it.current()->isSpecial() && !it.current()->isVirtual())
99  {
100  KListBox *lb = (m_plist.find(it.current()->printerName()) == m_plist.end() ? m_list1 : m_list2);
101  lb->insertItem(SmallIcon(it.current()->pixmap()), it.current()->printerName());
102  }
103  }
104  m_list1->sort();
105  m_list2->sort();
106  m_locationre->setText(conf->readEntry("LocationRe"));
107 }
108 
109 void KMConfigFilter::saveConfig(KConfig *conf)
110 {
111  conf->setGroup("Filter");
112  TQStringList plist;
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());
117 }
118 
119 void KMConfigFilter::transfer(KListBox *from, KListBox *to)
120 {
121  for (uint i=0; i<from->count();)
122  {
123  if (from->isSelected(i))
124  {
125  to->insertItem(*(from->pixmap(i)), from->text(i));
126  from->removeItem(i);
127  }
128  else
129  i++;
130  }
131  to->sort();
132 }
133 
134 void KMConfigFilter::slotAddClicked()
135 {
136  transfer(m_list1, m_list2);
137 }
138 
139 void KMConfigFilter::slotRemoveClicked()
140 {
141  transfer(m_list2, m_list1);
142 }
143 
144 void KMConfigFilter::slotSelectionChanged()
145 {
146  const KListBox *lb = static_cast<const KListBox*>(sender());
147  if (!lb)
148  return;
149  TQToolButton *pb = (lb == m_list1 ? m_add : m_remove);
150  for (uint i=0; i<lb->count(); i++)
151  if (lb->isSelected(i))
152  {
153  pb->setEnabled(true);
154  return;
155  }
156  pb->setEnabled(false);
157 }
158 
159 #include "kmconfigfilter.moc"

kdeprint

Skip menu "kdeprint"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kdeprint

Skip menu "kdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeprint by doxygen 1.8.11
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |