00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "portdialog.h"
00021 #include "cupsdconf.h"
00022
00023 #include <qlineedit.h>
00024 #include <qspinbox.h>
00025 #include <qcheckbox.h>
00026 #include <qpushbutton.h>
00027 #include <qlabel.h>
00028 #include <qlayout.h>
00029 #include <qwhatsthis.h>
00030
00031 #include <klocale.h>
00032
00033 PortDialog::PortDialog(QWidget *parent, const char *name)
00034 : KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true)
00035 {
00036 QWidget *dummy = new QWidget(this);
00037 setMainWidget(dummy);
00038 address_ = new QLineEdit(dummy);
00039 port_ = new QSpinBox(0, 9999, 1, dummy);
00040 port_->setValue(631);
00041 usessl_ = new QCheckBox(i18n("Use SSL encryption"), dummy);
00042
00043 QLabel *l1 = new QLabel(i18n("Address:"), dummy);
00044 QLabel *l2 = new QLabel(i18n("Port:"), dummy);
00045
00046 QVBoxLayout *m1 = new QVBoxLayout(dummy, 0, 10);
00047 QGridLayout *m2 = new QGridLayout(0, 3, 2, 0, 5);
00048 m1->addLayout(m2);
00049 m2->addWidget(l1, 0, 0, Qt::AlignRight);
00050 m2->addWidget(l2, 1, 0, Qt::AlignRight);
00051 m2->addMultiCellWidget(usessl_, 2, 2, 0, 1);
00052 m2->addWidget(address_, 0, 1);
00053 m2->addWidget(port_, 1, 1);
00054
00055 setCaption(i18n("Listen To"));
00056 resize(250, 100);
00057 }
00058
00059 QString PortDialog::listenString()
00060 {
00061 QString s;
00062 if (usessl_->isChecked())
00063 s.append("SSLListen ");
00064 else
00065 s.append("Listen ");
00066 if (!address_->text().isEmpty())
00067 s.append(address_->text());
00068 else
00069 s.append("*");
00070 s.append(":").append(port_->text());
00071 return s;
00072 }
00073
00074 void PortDialog::setInfos(CupsdConf *conf)
00075 {
00076 QWhatsThis::add(address_, conf->comments_.toolTip("address"));
00077 QWhatsThis::add(port_, conf->comments_.toolTip("port"));
00078 QWhatsThis::add(usessl_, conf->comments_.toolTip("usessl"));
00079 }
00080
00081 QString PortDialog::newListen(QWidget *parent, CupsdConf *conf)
00082 {
00083 PortDialog dlg(parent);
00084 dlg.setInfos(conf);
00085 if (dlg.exec())
00086 {
00087 return dlg.listenString();
00088 }
00089 return QString::null;
00090 }
00091
00092 QString PortDialog::editListen(const QString& s, QWidget *parent, CupsdConf *conf)
00093 {
00094 PortDialog dlg(parent);
00095 dlg.setInfos(conf);
00096 int p = s.find(' ');
00097 if (p != -1)
00098 {
00099 dlg.usessl_->setChecked(s.left(p).startsWith("SSL"));
00100 QString addr = s.mid(p+1).stripWhiteSpace();
00101 int p1 = addr.find(':');
00102 if (p1 == -1)
00103 {
00104 dlg.address_->setText(addr);
00105 dlg.port_->setValue(631);
00106 }
00107 else
00108 {
00109 dlg.address_->setText(addr.left(p1));
00110 dlg.port_->setValue(addr.mid(p1+1).toInt());
00111 }
00112 }
00113 if (dlg.exec())
00114 {
00115 return dlg.listenString();
00116 }
00117 return QString::null;
00118 }