browsedialog.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 "browsedialog.h"
00021 #include "cupsdconf.h"
00022 
00023 #include <qlineedit.h>
00024 #include <qpushbutton.h>
00025 #include <qcombobox.h>
00026 #include <qlabel.h>
00027 #include <qlayout.h>
00028 #include <qwhatsthis.h>
00029 #include <qregexp.h>
00030 
00031 #include <klocale.h>
00032 
00033 BrowseDialog::BrowseDialog(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     type_ = new QComboBox(dummy);
00039     from_ = new QLineEdit(dummy);
00040     to_ = new QLineEdit(dummy);
00041     type_->insertItem(i18n("Send"));
00042     type_->insertItem(i18n("Allow"));
00043     type_->insertItem(i18n("Deny"));
00044     type_->insertItem(i18n("Relay"));
00045     type_->insertItem(i18n("Poll"));
00046 
00047     QLabel  *l1 = new QLabel(i18n("Type:"), dummy);
00048     QLabel  *l2 = new QLabel(i18n("From:"), dummy);
00049     QLabel  *l3 = new QLabel(i18n("To:"), dummy);
00050 
00051     QGridLayout *m1 = new QGridLayout(dummy, 3, 2, 0, 5);
00052     m1->addWidget(l1, 0, 0, Qt::AlignRight);
00053     m1->addWidget(l2, 1, 0, Qt::AlignRight);
00054     m1->addWidget(l3, 2, 0, Qt::AlignRight);
00055     m1->addWidget(type_, 0, 1);
00056     m1->addWidget(from_, 1, 1);
00057     m1->addWidget(to_, 2, 1);
00058 
00059     connect(type_, SIGNAL(activated(int)), SLOT(slotTypeChanged(int)));
00060     slotTypeChanged(type_->currentItem());
00061 
00062     setCaption(i18n("Browse Address"));
00063     resize(250, 100);
00064 }
00065 
00066 QString BrowseDialog::addressString()
00067 {
00068     QString s;
00069     switch (type_->currentItem())
00070     {
00071         case 0:
00072             s.append("Send");
00073             break;
00074         case 1:
00075             s.append("Allow");
00076             break;
00077         case 2:
00078             s.append("Deny");
00079             break;
00080         case 3:
00081             s.append("Relay");
00082             break;
00083         case 4:
00084             s.append("Poll");
00085             break;
00086     }
00087     if (from_->isEnabled())
00088         s.append(" ").append(from_->text());
00089     if (to_->isEnabled())
00090         s.append(" ").append(to_->text());
00091     return s;
00092 }
00093 
00094 void BrowseDialog::setInfos(CupsdConf *conf)
00095 {
00096     QWhatsThis::add(type_, conf->comments_.toolTip("browsetype"));
00097 }
00098 
00099 QString BrowseDialog::newAddress(QWidget *parent, CupsdConf *conf)
00100 {
00101     BrowseDialog    dlg(parent);
00102     dlg.setInfos(conf);
00103     if (dlg.exec())
00104     {
00105         return dlg.addressString();
00106     }
00107     return QString::null;
00108 }
00109 
00110 QString BrowseDialog::editAddress(const QString& s, QWidget *parent, CupsdConf *conf)
00111 {
00112     BrowseDialog    dlg(parent);
00113     dlg.setInfos(conf);
00114     QStringList l = QStringList::split(QRegExp("\\s"), s, false);
00115     if (l.count() > 1)
00116     {
00117         if (l[0] == "Send") dlg.type_->setCurrentItem(0);
00118         else if (l[0] == "Allow") dlg.type_->setCurrentItem(1);
00119         else if (l[0] == "Deny") dlg.type_->setCurrentItem(2);
00120         else if (l[0] == "Relay") dlg.type_->setCurrentItem(3);
00121         else if (l[0] == "Poll") dlg.type_->setCurrentItem(4);
00122         dlg.slotTypeChanged(dlg.type_->currentItem());
00123         int index(1);
00124         if (dlg.from_->isEnabled())
00125             dlg.from_->setText(l[index++]);
00126         if (dlg.to_->isEnabled())
00127             dlg.to_->setText(l[index]);
00128     }
00129     if (dlg.exec())
00130     {
00131         return dlg.addressString();
00132     }
00133     return QString::null;
00134 }
00135 
00136 void BrowseDialog::slotTypeChanged(int index)
00137 {
00138     bool    useFrom(true), useTo(true);
00139     switch (index)
00140     {
00141         case 0: useFrom = false; break;
00142         case 1:
00143         case 4:
00144         case 2: useTo = false; break;
00145     }
00146     from_->setEnabled(useFrom);
00147     to_->setEnabled(useTo);
00148 }
00149 
00150 #include "browsedialog.moc"
KDE Home | KDE Accessibility Home | Description of Access Keys