cupsdbrowsingpage.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #include "cupsdbrowsingpage.h" 00021 #include "cupsdconf.h" 00022 #include "editlist.h" 00023 #include "browsedialog.h" 00024 00025 #include <tqlabel.h> 00026 #include <tqlayout.h> 00027 #include <tqcheckbox.h> 00028 #include <tqcombobox.h> 00029 #include <tqwhatsthis.h> 00030 00031 #include <klocale.h> 00032 #include <knuminput.h> 00033 00034 CupsdBrowsingPage::CupsdBrowsingPage(TQWidget *parent, const char *name) 00035 : CupsdPage(parent, name) 00036 { 00037 setPageLabel(i18n("Browsing")); 00038 setHeader(i18n("Browsing Settings")); 00039 setPixmap("kdeprint_printer_remote"); 00040 00041 browseinterval_ = new KIntNumInput(this); 00042 browseport_ = new KIntNumInput(this); 00043 browsetimeout_ = new KIntNumInput(this); 00044 browsing_ = new TQCheckBox(i18n("Use browsing"), this); 00045 cups_ = new TQCheckBox("CUPS", this); 00046 slp_ = new TQCheckBox("SLP", this); 00047 browseaddresses_ = new EditList(this); 00048 browseorder_ = new TQComboBox(this); 00049 useimplicitclasses_ = new TQCheckBox(i18n("Implicit classes"), this); 00050 hideimplicitmembers_ = new TQCheckBox(i18n("Hide implicit members"), this); 00051 useshortnames_ = new TQCheckBox(i18n("Use short names"), this); 00052 useanyclasses_ = new TQCheckBox(i18n("Use \"any\" classes"), this); 00053 00054 browseorder_->insertItem(i18n("Allow, Deny")); 00055 browseorder_->insertItem(i18n("Deny, Allow")); 00056 00057 browseport_->setRange(0, 9999, 1, true); 00058 browseport_->setSteps(1, 5); 00059 browseinterval_->setRange(0, 10000, 1, true); 00060 browseinterval_->setSteps(1, 10); 00061 browseinterval_->setSuffix(i18n(" sec")); 00062 browsetimeout_->setRange(0, 10000, 1, true); 00063 browsetimeout_->setSteps(1, 10); 00064 browsetimeout_->setSuffix(i18n(" sec")); 00065 00066 TQLabel *l1 = new TQLabel(i18n("Browse port:"), this); 00067 TQLabel *l2 = new TQLabel(i18n("Browse interval:"), this); 00068 TQLabel *l3 = new TQLabel(i18n("Browse timeout:"), this); 00069 TQLabel *l4 = new TQLabel(i18n("Browse addresses:"), this); 00070 TQLabel *l5 = new TQLabel(i18n("Browse order:"), this); 00071 TQLabel *l6 = new TQLabel(i18n("Browse options:"), this); 00072 00073 TQGridLayout *m1 = new TQGridLayout(this, 8, 2, 10, 7); 00074 m1->setRowStretch(7, 1); 00075 m1->setColStretch(1, 1); 00076 TQHBoxLayout *m2 = new TQHBoxLayout(0, 0, 10); 00077 m1->addMultiCellLayout(m2, 0, 0, 0, 1); 00078 m2->addWidget(browsing_); 00079 m2->addWidget(cups_); 00080 m2->addWidget(slp_); 00081 m2->addStretch(1); 00082 m1->addWidget(l1, 1, 0, Qt::AlignRight); 00083 m1->addWidget(l2, 2, 0, Qt::AlignRight); 00084 m1->addWidget(l3, 3, 0, Qt::AlignRight); 00085 m1->addWidget(l4, 4, 0, Qt::AlignRight|Qt::AlignTop); 00086 m1->addWidget(l5, 5, 0, Qt::AlignRight); 00087 m1->addWidget(l6, 6, 0, Qt::AlignRight|Qt::AlignTop); 00088 m1->addWidget(browseport_, 1, 1); 00089 m1->addWidget(browseinterval_, 2, 1); 00090 m1->addWidget(browsetimeout_, 3, 1); 00091 m1->addWidget(browseaddresses_, 4, 1); 00092 m1->addWidget(browseorder_, 5, 1); 00093 TQGridLayout *m3 = new TQGridLayout(0, 2, 2, 0, 5); 00094 m1->addLayout(m3, 6, 1); 00095 m3->addWidget(useimplicitclasses_, 0, 0); 00096 m3->addWidget(useanyclasses_, 0, 1); 00097 m3->addWidget(hideimplicitmembers_, 1, 0); 00098 m3->addWidget(useshortnames_, 1, 1); 00099 00100 connect(browsing_, TQT_SIGNAL(toggled(bool)), cups_, TQT_SLOT(setEnabled(bool))); 00101 connect(browsing_, TQT_SIGNAL(toggled(bool)), slp_, TQT_SLOT(setEnabled(bool))); 00102 connect(browsing_, TQT_SIGNAL(toggled(bool)), browseport_, TQT_SLOT(setEnabled(bool))); 00103 connect(browsing_, TQT_SIGNAL(toggled(bool)), browseinterval_, TQT_SLOT(setEnabled(bool))); 00104 connect(browsing_, TQT_SIGNAL(toggled(bool)), browsetimeout_, TQT_SLOT(setEnabled(bool))); 00105 connect(browsing_, TQT_SIGNAL(toggled(bool)), browseaddresses_, TQT_SLOT(setEnabled(bool))); 00106 connect(browsing_, TQT_SIGNAL(toggled(bool)), browseorder_, TQT_SLOT(setEnabled(bool))); 00107 connect(browsing_, TQT_SIGNAL(toggled(bool)), useimplicitclasses_, TQT_SLOT(setEnabled(bool))); 00108 connect(browsing_, TQT_SIGNAL(toggled(bool)), useanyclasses_, TQT_SLOT(setEnabled(bool))); 00109 connect(browsing_, TQT_SIGNAL(toggled(bool)), hideimplicitmembers_, TQT_SLOT(setEnabled(bool))); 00110 connect(browsing_, TQT_SIGNAL(toggled(bool)), useshortnames_, TQT_SLOT(setEnabled(bool))); 00111 00112 connect(browsing_, TQT_SIGNAL(toggled(bool)), l1, TQT_SLOT(setEnabled(bool))); 00113 connect(browsing_, TQT_SIGNAL(toggled(bool)), l2, TQT_SLOT(setEnabled(bool))); 00114 connect(browsing_, TQT_SIGNAL(toggled(bool)), l3, TQT_SLOT(setEnabled(bool))); 00115 connect(browsing_, TQT_SIGNAL(toggled(bool)), l4, TQT_SLOT(setEnabled(bool))); 00116 connect(browsing_, TQT_SIGNAL(toggled(bool)), l5, TQT_SLOT(setEnabled(bool))); 00117 connect(browsing_, TQT_SIGNAL(toggled(bool)), l6, TQT_SLOT(setEnabled(bool))); 00118 00119 connect(browseaddresses_, TQT_SIGNAL(add()), TQT_SLOT(slotAdd())); 00120 connect(browseaddresses_, TQT_SIGNAL(edit(int)), TQT_SLOT(slotEdit(int))); 00121 connect(browseaddresses_, TQT_SIGNAL(defaultList()), TQT_SLOT(slotDefaultList())); 00122 connect(browseinterval_, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(intervalChanged(int))); 00123 browsing_->setChecked(true); 00124 } 00125 00126 bool CupsdBrowsingPage::loadConfig(CupsdConf *conf, TQString&) 00127 { 00128 conf_ = conf; 00129 browsing_->setChecked(conf_->browsing_); 00130 cups_->setChecked(conf_->browseprotocols_.findIndex("CUPS") != -1); 00131 slp_->setChecked(conf_->browseprotocols_.findIndex("SLP") != -1); 00132 browseport_->setValue(conf_->browseport_); 00133 browseinterval_->setValue(conf_->browseinterval_); 00134 browsetimeout_->setValue(conf_->browsetimeout_); 00135 browseaddresses_->insertItems(conf_->browseaddresses_); 00136 browseorder_->setCurrentItem(conf_->browseorder_); 00137 useimplicitclasses_->setChecked(conf_->useimplicitclasses_); 00138 useanyclasses_->setChecked(conf_->useanyclasses_); 00139 hideimplicitmembers_->setChecked(conf_->hideimplicitmembers_); 00140 useshortnames_->setChecked(conf_->useshortnames_); 00141 00142 return true; 00143 } 00144 00145 bool CupsdBrowsingPage::saveConfig(CupsdConf *conf, TQString&) 00146 { 00147 conf->browsing_ = browsing_->isChecked(); 00148 TQStringList l; 00149 if (cups_->isChecked()) l << "CUPS"; 00150 if (slp_->isChecked()) l << "SLP"; 00151 conf->browseprotocols_ = l; 00152 conf->browseport_ = browseport_->value(); 00153 conf->browseinterval_ = browseinterval_->value(); 00154 conf->browsetimeout_ = browsetimeout_->value(); 00155 conf->browseaddresses_ = browseaddresses_->items(); 00156 conf->browseorder_ = browseorder_->currentItem(); 00157 conf->useimplicitclasses_ = useimplicitclasses_->isChecked(); 00158 conf->useanyclasses_ = useanyclasses_->isChecked(); 00159 conf->hideimplicitmembers_ = hideimplicitmembers_->isChecked(); 00160 conf->useshortnames_ = useshortnames_->isChecked(); 00161 00162 return true; 00163 } 00164 00165 void CupsdBrowsingPage::setInfos(CupsdConf *conf) 00166 { 00167 TQWhatsThis::add(browsing_, conf->comments_.toolTip("browsing")); 00168 TQWhatsThis::add(cups_, conf->comments_.toolTip("browseprotocols")); 00169 TQWhatsThis::add(slp_, conf->comments_.toolTip("browseprotocols")); 00170 TQWhatsThis::add(browseinterval_, conf->comments_.toolTip("browseinterval")); 00171 TQWhatsThis::add(browseport_, conf->comments_.toolTip("browseport")); 00172 TQWhatsThis::add(browsetimeout_, conf->comments_.toolTip("browsetimeout")); 00173 TQWhatsThis::add(browseaddresses_, conf->comments_.toolTip("browseaddresses")); 00174 TQWhatsThis::add(browseorder_, conf->comments_.toolTip("browseorder")); 00175 TQWhatsThis::add(useimplicitclasses_, conf->comments_.toolTip("implicitclasses")); 00176 TQWhatsThis::add(useanyclasses_, conf->comments_.toolTip("implicitanyclasses")); 00177 TQWhatsThis::add(hideimplicitmembers_, conf->comments_.toolTip("hideimplicitmembers")); 00178 TQWhatsThis::add(useshortnames_, conf->comments_.toolTip("browseshortnames")); 00179 } 00180 00181 void CupsdBrowsingPage::slotAdd() 00182 { 00183 TQString s = BrowseDialog::newAddress(this, conf_); 00184 if (!s.isEmpty()) 00185 browseaddresses_->insertItem(s); 00186 } 00187 00188 void CupsdBrowsingPage::slotEdit(int index) 00189 { 00190 TQString s = browseaddresses_->text(index); 00191 s = BrowseDialog::editAddress(s, this, conf_); 00192 if (!s.isEmpty()) 00193 browseaddresses_->setText(index, s); 00194 } 00195 00196 void CupsdBrowsingPage::slotDefaultList() 00197 { 00198 browseaddresses_->clear(); 00199 TQStringList l; 00200 l << "Send 255.255.255.255"; 00201 browseaddresses_->insertItems(l); 00202 } 00203 00204 void CupsdBrowsingPage::intervalChanged(int val) 00205 { 00206 browsetimeout_->setRange(val, 10000, 1, true); 00207 browsetimeout_->setSteps(1, 10); 00208 } 00209 00210 #include "cupsdbrowsingpage.moc"