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 <qcombobox.h>
00023
#include <qlineedit.h>
00024
#include <qlabel.h>
00025
#include <qlayout.h>
00026
00027
#include <klocale.h>
00028
00029 AddressDialog::AddressDialog(
QWidget *parent,
const char *name)
00030 : KDialogBase(Swallow, i18n(
"ACL Address"), Ok|Cancel, Ok, parent, name, true, true)
00031 {
00032
QWidget *w =
new QWidget(
this);
00033 type_ =
new QComboBox(w);
00034 address_ =
new QLineEdit(w);
00035
00036 type_->insertItem(i18n(
"Allow"));
00037 type_->insertItem(i18n(
"Deny"));
00038
00039
QLabel *l1 =
new QLabel(i18n(
"Type:"), w);
00040
QLabel *l2 =
new QLabel(i18n(
"Address:"), w);
00041
00042
QGridLayout *m1 =
new QGridLayout(w, 2, 2, 0, 5);
00043 m1->
setColStretch(1, 1);
00044 m1->
addWidget(l1, 0, 0, Qt::AlignRight);
00045 m1->
addWidget(l2, 1, 0, Qt::AlignRight);
00046 m1->
addWidget(type_, 0, 1);
00047 m1->
addWidget(address_, 1, 1);
00048
00049 setMainWidget(w);
00050 resize(300, 100);
00051 }
00052
00053
QString AddressDialog::addressString()
00054 {
00055
QString s;
00056
if (type_->currentItem() == 0)
00057 s.
append(
"Allow ");
00058
else
00059 s.
append(
"Deny ");
00060
if (address_->text().isEmpty())
00061 s.
append(
"All");
00062
else
00063 s.
append(address_->text());
00064
return s;
00065 }
00066
00067
QString AddressDialog::newAddress(
QWidget *parent)
00068 {
00069 AddressDialog dlg(parent);
00070
if (dlg.exec())
00071
return dlg.addressString();
00072
else
00073
return QString::null;
00074 }
00075
00076
QString AddressDialog::editAddress(
const QString& addr,
QWidget *parent)
00077 {
00078 AddressDialog dlg(parent);
00079
int p = addr.
find(
' ');
00080
if (p != -1)
00081 {
00082 dlg.type_->setCurrentItem(addr.
left(p).lower() ==
"deny" ? 1 : 0);
00083 dlg.address_->setText(addr.
mid(p+1));
00084 }
00085
if (dlg.exec())
00086
return dlg.addressString();
00087
else
00088
return QString::null;
00089 }