addressdialog.cpp
00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License version 2 as published by the Free Software Foundation. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Library General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Library General Public License 00015 * along with this library; see the file COPYING.LIB. If not, write to 00016 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 * Boston, MA 02110-1301, USA. 00018 **/ 00019 00020 #include "addressdialog.h" 00021 00022 #include <tqcombobox.h> 00023 #include <tqlineedit.h> 00024 #include <tqlabel.h> 00025 #include <tqlayout.h> 00026 00027 #include <klocale.h> 00028 00029 AddressDialog::AddressDialog(TQWidget *parent, const char *name) 00030 : KDialogBase(Swallow, i18n("ACL Address"), Ok|Cancel, Ok, parent, name, true, true) 00031 { 00032 TQWidget *w = new TQWidget(this); 00033 type_ = new TQComboBox(w); 00034 address_ = new TQLineEdit(w); 00035 00036 type_->insertItem(i18n("Allow")); 00037 type_->insertItem(i18n("Deny")); 00038 00039 TQLabel *l1 = new TQLabel(i18n("Type:"), w); 00040 TQLabel *l2 = new TQLabel(i18n("Address:"), w); 00041 00042 TQGridLayout *m1 = new TQGridLayout(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 TQString AddressDialog::addressString() 00054 { 00055 TQString 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 TQString AddressDialog::newAddress(TQWidget *parent) 00068 { 00069 AddressDialog dlg(parent); 00070 if (dlg.exec()) 00071 return dlg.addressString(); 00072 else 00073 return TQString::null; 00074 } 00075 00076 TQString AddressDialog::editAddress(const TQString& addr, TQWidget *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 TQString::null; 00089 }