KDEPrint
addressdialog.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "addressdialog.h"
00021
00022 #include <QtGui/QComboBox>
00023 #include <QtGui/QLineEdit>
00024 #include <QtGui/QLabel>
00025 #include <QtGui/QLayout>
00026
00027 #include <klocale.h>
00028
00029 AddressDialog::AddressDialog(QWidget *parent, const char *name)
00030 : KDialog(parent)
00031 {
00032 setCaption(i18n("ACL Address"));
00033 setButtons(Ok | Cancel);
00034 setDefaultButton(Ok);
00035 setObjectName(name);
00036 setModal(true);
00037 showButtonSeparator(true);
00038
00039 QWidget *w = new QWidget(this);
00040 type_ = new QComboBox(w);
00041 address_ = new QLineEdit(w);
00042
00043 type_->addItem(i18n("Allow"));
00044 type_->addItem(i18n("Deny"));
00045
00046 QLabel *l1 = new QLabel(i18n("Type:"), w);
00047 QLabel *l2 = new QLabel(i18n("Address:"), w);
00048
00049 QGridLayout *m1 = new QGridLayout(w);
00050 m1->setMargin(0);
00051 m1->setSpacing(5);
00052 m1->setColumnStretch(1, 1);
00053 m1->addWidget(l1, 0, 0, Qt::AlignRight);
00054 m1->addWidget(l2, 1, 0, Qt::AlignRight);
00055 m1->addWidget(type_, 0, 1);
00056 m1->addWidget(address_, 1, 1);
00057
00058 setMainWidget(w);
00059 resize(300, 100);
00060 }
00061
00062 QString AddressDialog::addressString()
00063 {
00064 QString s;
00065 if (type_->currentIndex() == 0)
00066 s.append("Allow ");
00067 else
00068 s.append("Deny ");
00069 if (address_->text().isEmpty())
00070 s.append("All");
00071 else
00072 s.append(address_->text());
00073 return s;
00074 }
00075
00076 QString AddressDialog::newAddress(QWidget *parent)
00077 {
00078 AddressDialog dlg(parent);
00079 if (dlg.exec())
00080 return dlg.addressString();
00081 else
00082 return QString();
00083 }
00084
00085 QString AddressDialog::editAddress(const QString& addr, QWidget *parent)
00086 {
00087 AddressDialog dlg(parent);
00088 int p = addr.indexOf(' ');
00089 if (p != -1) {
00090 dlg.type_->setCurrentIndex(addr.left(p).toLower() == "deny" ? 1 : 0);
00091 dlg.address_->setText(addr.mid(p + 1));
00092 }
00093 if (dlg.exec())
00094 return dlg.addressString();
00095 else
00096 return QString();
00097 }