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

#include <qlineedit.h>
#include <qspinbox.h>
#include <qcheckbox.h>
#include <qpushbutton.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qwhatsthis.h>

#include <klocale.h>

PortDialog::PortDialog(QWidget *parent, const char *name)
	: KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true)
{
	QWidget	*dummy = new QWidget(this);
	setMainWidget(dummy);
	address_ = new QLineEdit(dummy);
	port_ = new QSpinBox(0, 9999, 1, dummy);
	port_->setValue(631);
	usessl_ = new QCheckBox(i18n("Use SSL encryption"), dummy);

	QLabel	*l1 = new QLabel(i18n("Address:"), dummy);
	QLabel	*l2 = new QLabel(i18n("Port:"), dummy);

	QVBoxLayout	*m1 = new QVBoxLayout(dummy, 0, 10);
	QGridLayout	*m2 = new QGridLayout(0, 3, 2, 0, 5);
	m1->addLayout(m2);
	m2->addWidget(l1, 0, 0, Qt::AlignRight);
	m2->addWidget(l2, 1, 0, Qt::AlignRight);
	m2->addMultiCellWidget(usessl_, 2, 2, 0, 1);
	m2->addWidget(address_, 0, 1);
	m2->addWidget(port_, 1, 1);

	setCaption(i18n("Listen To"));
	resize(250, 100);
}

QString PortDialog::listenString()
{
	QString s;
	if (usessl_->isChecked())
		s.append("SSLListen ");
	else
		s.append("Listen ");
	if (!address_->text().isEmpty())
		s.append(address_->text());
	else
		s.append("*");
	s.append(":").append(port_->text());
	return s;
}

void PortDialog::setInfos(CupsdConf *conf)
{
	QWhatsThis::add(address_, conf->comments_.toolTip("address"));
	QWhatsThis::add(port_, conf->comments_.toolTip("port"));
	QWhatsThis::add(usessl_, conf->comments_.toolTip("usessl"));
}

QString PortDialog::newListen(QWidget *parent, CupsdConf *conf)
{
	PortDialog	dlg(parent);
	dlg.setInfos(conf);
	if (dlg.exec())
	{
		return dlg.listenString();
	}
	return QString::null;
}

QString PortDialog::editListen(const QString& s, QWidget *parent, CupsdConf *conf)
{
	PortDialog	dlg(parent);
	dlg.setInfos(conf);
	int	p = s.find(' ');
	if (p != -1)
	{
		dlg.usessl_->setChecked(s.left(p).startsWith("SSL"));
		QString	addr = s.mid(p+1).stripWhiteSpace();
		int p1 = addr.find(':');
		if (p1 == -1)
		{
			dlg.address_->setText(addr);
			dlg.port_->setValue(631);
		}
		else
		{
			dlg.address_->setText(addr.left(p1));
			dlg.port_->setValue(addr.mid(p1+1).toInt());
		}
	}
	if (dlg.exec())
	{
		return dlg.listenString();
	}
	return QString::null;
}