• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDEPrint

browsedialog.cpp

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

KDEPrint

Skip menu "KDEPrint"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  •   KDEPrint
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal