summaryrefslogtreecommitdiffstats
path: root/kdeprint/cups/cupsdconf2/cupsdnetworkpage.cpp
blob: 9edca58685b48fb99ee06de35b06508d5d8582cd (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
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
 *
 *  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 "cupsdnetworkpage.h"
#include "cupsdconf.h"
#include "editlist.h"
#include "portdialog.h"
#include "sizewidget.h"

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

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

CupsdNetworkPage::CupsdNetworkPage(TQWidget *parent, const char *name)
	: CupsdPage(parent, name)
{
	setPageLabel(i18n("Network"));
	setHeader(i18n("Network Settings"));
	setPixmap("network");

	keepalive_ = new TQCheckBox(i18n("Keep alive"), this);
	keepalivetimeout_ = new KIntNumInput(this);
	maxclients_ = new KIntNumInput(this);
	maxrequestsize_ = new SizeWidget(this);
	clienttimeout_ = new KIntNumInput(this);
	hostnamelookup_ = new TQComboBox(this);
	listen_ = new EditList(this);

	keepalivetimeout_->setRange(0, 10000, 1, true);
	keepalivetimeout_->setSteps(1, 10);
	keepalivetimeout_->setSpecialValueText(i18n("Unlimited"));
	keepalivetimeout_->setSuffix(i18n(" sec"));

	maxclients_->setRange(1, 1000, 1, true);
	maxclients_->setSteps(1, 10);

	clienttimeout_->setRange(0, 10000, 1, true);
	clienttimeout_->setSteps(1, 10);
	clienttimeout_->setSpecialValueText(i18n("Unlimited"));
	clienttimeout_->setSuffix(i18n(" sec"));

	hostnamelookup_->insertItem(i18n("Off"));
	hostnamelookup_->insertItem(i18n("On"));
	hostnamelookup_->insertItem(i18n("Double"));

	TQLabel *l1 = new TQLabel(i18n("Hostname lookups:"), this);
	TQLabel *l2 = new TQLabel(i18n("Keep-alive timeout:"), this);
	TQLabel *l3 = new TQLabel(i18n("Max clients:"), this);
	TQLabel *l4 = new TQLabel(i18n("Max request size:"), this);
	TQLabel *l5 = new TQLabel(i18n("Client timeout:"), this);
	TQLabel *l6 = new TQLabel(i18n("Listen to:"), this);

	TQGridLayout	*m1 = new TQGridLayout(this, 8, 2, 10, 7);
	m1->setRowStretch(7, 1);
	m1->setColStretch(1, 1);
	m1->addWidget(l1, 0, 0, Qt::AlignRight);
	m1->addWidget(l2, 2, 0, Qt::AlignRight);
	m1->addWidget(l3, 3, 0, Qt::AlignRight);
	m1->addWidget(l4, 4, 0, Qt::AlignRight);
	m1->addWidget(l5, 5, 0, Qt::AlignRight);
	m1->addWidget(l6, 6, 0, Qt::AlignTop|Qt::AlignRight);
	m1->addWidget(keepalive_, 1, 1);
	m1->addWidget(hostnamelookup_, 0, 1);
	m1->addWidget(keepalivetimeout_, 2, 1);
	m1->addWidget(maxclients_, 3, 1);
	m1->addWidget(maxrequestsize_, 4, 1);
	m1->addWidget(clienttimeout_, 5, 1);
	m1->addWidget(listen_, 6, 1);

	connect(listen_, TQT_SIGNAL(add()), TQT_SLOT(slotAdd()));
	connect(listen_, TQT_SIGNAL(edit(int)), TQT_SLOT(slotEdit(int)));
	connect(listen_, TQT_SIGNAL(defaultList()), TQT_SLOT(slotDefaultList()));
	connect(keepalive_, TQT_SIGNAL(toggled(bool)), keepalivetimeout_, TQT_SLOT(setEnabled(bool)));
	keepalive_->setChecked(true);
}

bool CupsdNetworkPage::loadConfig(CupsdConf *conf, TQString&)
{
	conf_ = conf;
	hostnamelookup_->setCurrentItem(conf_->hostnamelookup_);
	keepalive_->setChecked(conf_->keepalive_);
	keepalivetimeout_->setValue(conf_->keepalivetimeout_);
	maxclients_->setValue(conf_->maxclients_);
	maxrequestsize_->setSizeString(conf_->maxrequestsize_);
	clienttimeout_->setValue(conf_->clienttimeout_);
	listen_->insertItems(conf_->listenaddresses_);

	return true;
}

bool CupsdNetworkPage::saveConfig(CupsdConf *conf, TQString&)
{
	conf->hostnamelookup_ = hostnamelookup_->currentItem();
	conf->keepalive_ = keepalive_->isChecked();
	conf->keepalivetimeout_ = keepalivetimeout_->value();
	conf->maxclients_ = maxclients_->value();
	conf->maxrequestsize_ = maxrequestsize_->sizeString();
	conf->clienttimeout_ = clienttimeout_->value();
	conf->listenaddresses_ = listen_->items();

	return true;
}

void CupsdNetworkPage::setInfos(CupsdConf *conf)
{
	TQWhatsThis::add(hostnamelookup_, conf->comments_.toolTip("hostnamelookups"));
	TQWhatsThis::add(keepalive_, conf->comments_.toolTip("keepalive"));
	TQWhatsThis::add(keepalivetimeout_, conf->comments_.toolTip("keepalivetimeout"));
	TQWhatsThis::add(maxclients_, conf->comments_.toolTip("maxclients"));
	TQWhatsThis::add(maxrequestsize_, conf->comments_.toolTip("maxrequestsize"));
	TQWhatsThis::add(clienttimeout_, conf->comments_.toolTip("timeout"));
	TQWhatsThis::add(listen_, conf->comments_.toolTip("listen"));
}

void CupsdNetworkPage::slotAdd()
{
	TQString	s = PortDialog::newListen(this, conf_);
	if (!s.isEmpty())
		listen_->insertItem(s);
}

void CupsdNetworkPage::slotEdit(int index)
{
	TQString s = listen_->text(index);
	s = PortDialog::editListen(s, this, conf_);
	if (!s.isEmpty())
		listen_->setText(index, s);
}

void CupsdNetworkPage::slotDefaultList()
{
	listen_->clear();
	TQStringList	l;
	l << "Listen *:631";
	listen_->insertItems(l);
}

#include "cupsdnetworkpage.moc"