summaryrefslogtreecommitdiffstats
path: root/tdeprint/cups/cupsdconf2/cupsdbrowsingpage.cpp
blob: 4b056cdb0c993838bedaa2110ebd3ed06e69042d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <[email protected]>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "cupsdbrowsingpage.h"
#include "cupsdconf.h"
#include "editlist.h"
#include "browsedialog.h"

#include <tqlabel.h>
#include <tqlayout.h>
#include <tqcheckbox.h>
#include <tqcombobox.h>
#include <tqwhatsthis.h>

#include <klocale.h>
#include <knuminput.h>

CupsdBrowsingPage::CupsdBrowsingPage(TQWidget *parent, const char *name)
	: CupsdPage(parent, name)
{
	setPageLabel(i18n("Browsing"));
	setHeader(i18n("Browsing Settings"));
	setPixmap("tdeprint_printer_remote");

	browseinterval_ = new KIntNumInput(this);
	browseport_ = new KIntNumInput(this);
	browsetimeout_ = new KIntNumInput(this);
	browsing_ = new TQCheckBox(i18n("Use browsing"), this);
	cups_ = new TQCheckBox("CUPS", this);
	slp_ = new TQCheckBox("SLP", this);
	browseaddresses_ = new EditList(this);
	browseorder_ = new TQComboBox(this);
	useimplicitclasses_ = new TQCheckBox(i18n("Implicit classes"), this);
	hideimplicitmembers_ = new TQCheckBox(i18n("Hide implicit members"), this);
	useshortnames_ = new TQCheckBox(i18n("Use short names"), this);
	useanyclasses_ = new TQCheckBox(i18n("Use \"any\" classes"), this);

	browseorder_->insertItem(i18n("Allow, Deny"));
	browseorder_->insertItem(i18n("Deny, Allow"));

	browseport_->setRange(0, 9999, 1, true);
	browseport_->setSteps(1, 5);
	browseinterval_->setRange(0, 10000, 1, true);
	browseinterval_->setSteps(1, 10);
	browseinterval_->setSuffix(i18n(" sec"));
	browsetimeout_->setRange(0, 10000, 1, true);
	browsetimeout_->setSteps(1, 10);
	browsetimeout_->setSuffix(i18n(" sec"));

	TQLabel *l1 = new TQLabel(i18n("Browse port:"), this);
	TQLabel *l2 = new TQLabel(i18n("Browse interval:"), this);
	TQLabel *l3 = new TQLabel(i18n("Browse timeout:"), this);
	TQLabel *l4 = new TQLabel(i18n("Browse addresses:"), this);
	TQLabel *l5 = new TQLabel(i18n("Browse order:"), this);
	TQLabel *l6 = new TQLabel(i18n("Browse options:"), this);

	TQGridLayout	*m1 = new TQGridLayout(this, 8, 2, 10, 7);
	m1->setRowStretch(7, 1);
	m1->setColStretch(1, 1);
	TQHBoxLayout	*m2 = new TQHBoxLayout(0, 0, 10);
	m1->addMultiCellLayout(m2, 0, 0, 0, 1);
	m2->addWidget(browsing_);
	m2->addWidget(cups_);
	m2->addWidget(slp_);
	m2->addStretch(1);
	m1->addWidget(l1, 1, 0, Qt::AlignRight);
	m1->addWidget(l2, 2, 0, Qt::AlignRight);
	m1->addWidget(l3, 3, 0, Qt::AlignRight);
	m1->addWidget(l4, 4, 0, Qt::AlignRight|Qt::AlignTop);
	m1->addWidget(l5, 5, 0, Qt::AlignRight);
	m1->addWidget(l6, 6, 0, Qt::AlignRight|Qt::AlignTop);	
	m1->addWidget(browseport_, 1, 1);
	m1->addWidget(browseinterval_, 2, 1);
	m1->addWidget(browsetimeout_, 3, 1);
	m1->addWidget(browseaddresses_, 4, 1);
	m1->addWidget(browseorder_, 5, 1);
	TQGridLayout	*m3 = new TQGridLayout(0, 2, 2, 0, 5);
	m1->addLayout(m3, 6, 1);
	m3->addWidget(useimplicitclasses_, 0, 0);
	m3->addWidget(useanyclasses_, 0, 1);
	m3->addWidget(hideimplicitmembers_, 1, 0);
	m3->addWidget(useshortnames_, 1, 1);

	connect(browsing_, TQT_SIGNAL(toggled(bool)), cups_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), slp_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), browseport_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), browseinterval_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), browsetimeout_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), browseaddresses_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), browseorder_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), useimplicitclasses_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), useanyclasses_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), hideimplicitmembers_, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), useshortnames_, TQT_SLOT(setEnabled(bool)));

	connect(browsing_, TQT_SIGNAL(toggled(bool)), l1, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), l2, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), l3, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), l4, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), l5, TQT_SLOT(setEnabled(bool)));
	connect(browsing_, TQT_SIGNAL(toggled(bool)), l6, TQT_SLOT(setEnabled(bool)));

	connect(browseaddresses_, TQT_SIGNAL(add()), TQT_SLOT(slotAdd()));
	connect(browseaddresses_, TQT_SIGNAL(edit(int)), TQT_SLOT(slotEdit(int)));
	connect(browseaddresses_, TQT_SIGNAL(defaultList()), TQT_SLOT(slotDefaultList()));
	connect(browseinterval_, TQT_SIGNAL(valueChanged(int)), TQT_SLOT(intervalChanged(int)));
	browsing_->setChecked(true);
}

bool CupsdBrowsingPage::loadConfig(CupsdConf *conf, TQString&)
{
	conf_ = conf;
	browsing_->setChecked(conf_->browsing_);
	cups_->setChecked(conf_->browseprotocols_.findIndex("CUPS") != -1);
	slp_->setChecked(conf_->browseprotocols_.findIndex("SLP") != -1);
	browseport_->setValue(conf_->browseport_);
	browseinterval_->setValue(conf_->browseinterval_);
	browsetimeout_->setValue(conf_->browsetimeout_);
	browseaddresses_->insertItems(conf_->browseaddresses_);
	browseorder_->setCurrentItem(conf_->browseorder_);
	useimplicitclasses_->setChecked(conf_->useimplicitclasses_);
	useanyclasses_->setChecked(conf_->useanyclasses_);
	hideimplicitmembers_->setChecked(conf_->hideimplicitmembers_);
	useshortnames_->setChecked(conf_->useshortnames_);

	return true;
}

bool CupsdBrowsingPage::saveConfig(CupsdConf *conf, TQString&)
{
	conf->browsing_ = browsing_->isChecked();
	TQStringList	l;
	if (cups_->isChecked()) l << "CUPS";
	if (slp_->isChecked()) l << "SLP";
	conf->browseprotocols_ = l;
	conf->browseport_ = browseport_->value();
	conf->browseinterval_ = browseinterval_->value();
	conf->browsetimeout_ = browsetimeout_->value();
	conf->browseaddresses_ = browseaddresses_->items();
	conf->browseorder_ = browseorder_->currentItem();
	conf->useimplicitclasses_ = useimplicitclasses_->isChecked();
	conf->useanyclasses_ = useanyclasses_->isChecked();
	conf->hideimplicitmembers_ = hideimplicitmembers_->isChecked();
	conf->useshortnames_ = useshortnames_->isChecked();

	return true;
}

void CupsdBrowsingPage::setInfos(CupsdConf *conf)
{
	TQWhatsThis::add(browsing_, conf->comments_.toolTip("browsing"));
	TQWhatsThis::add(cups_, conf->comments_.toolTip("browseprotocols"));
	TQWhatsThis::add(slp_, conf->comments_.toolTip("browseprotocols"));
	TQWhatsThis::add(browseinterval_, conf->comments_.toolTip("browseinterval"));
	TQWhatsThis::add(browseport_, conf->comments_.toolTip("browseport"));
	TQWhatsThis::add(browsetimeout_, conf->comments_.toolTip("browsetimeout"));
	TQWhatsThis::add(browseaddresses_, conf->comments_.toolTip("browseaddresses"));
	TQWhatsThis::add(browseorder_, conf->comments_.toolTip("browseorder"));
	TQWhatsThis::add(useimplicitclasses_, conf->comments_.toolTip("implicitclasses"));
	TQWhatsThis::add(useanyclasses_, conf->comments_.toolTip("implicitanyclasses"));
	TQWhatsThis::add(hideimplicitmembers_, conf->comments_.toolTip("hideimplicitmembers"));
	TQWhatsThis::add(useshortnames_, conf->comments_.toolTip("browseshortnames"));
}

void CupsdBrowsingPage::slotAdd()
{
	TQString s = BrowseDialog::newAddress(this, conf_);
	if (!s.isEmpty())
		browseaddresses_->insertItem(s);
}

void CupsdBrowsingPage::slotEdit(int index)
{
	TQString s = browseaddresses_->text(index);
	s = BrowseDialog::editAddress(s, this, conf_);
	if (!s.isEmpty())
		browseaddresses_->setText(index, s);
}

void CupsdBrowsingPage::slotDefaultList()
{
	browseaddresses_->clear();
	TQStringList	l;
	l << "Send 255.255.255.255";
	browseaddresses_->insertItems(l);
}

void CupsdBrowsingPage::intervalChanged(int val)
{
	browsetimeout_->setRange(val, 10000, 1, true);
	browsetimeout_->setSteps(1, 10);
}

#include "cupsdbrowsingpage.moc"