diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | ce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch) | |
tree | 5ac38a06f3dde268dc7927dc155896926aaf7012 /kdeprint/cups/cupsdconf2/browsedialog.cpp | |
download | tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kdeprint/cups/cupsdconf2/browsedialog.cpp')
-rw-r--r-- | kdeprint/cups/cupsdconf2/browsedialog.cpp | 150 |
1 files changed, 150 insertions, 0 deletions
diff --git a/kdeprint/cups/cupsdconf2/browsedialog.cpp b/kdeprint/cups/cupsdconf2/browsedialog.cpp new file mode 100644 index 000000000..846ea41a5 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/browsedialog.cpp @@ -0,0 +1,150 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License version 2 as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + **/ + +#include "browsedialog.h" +#include "cupsdconf.h" + +#include <qlineedit.h> +#include <qpushbutton.h> +#include <qcombobox.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qwhatsthis.h> +#include <qregexp.h> + +#include <klocale.h> + +BrowseDialog::BrowseDialog(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true) +{ + QWidget *dummy = new QWidget(this); + setMainWidget(dummy); + type_ = new QComboBox(dummy); + from_ = new QLineEdit(dummy); + to_ = new QLineEdit(dummy); + type_->insertItem(i18n("Send")); + type_->insertItem(i18n("Allow")); + type_->insertItem(i18n("Deny")); + type_->insertItem(i18n("Relay")); + type_->insertItem(i18n("Poll")); + + QLabel *l1 = new QLabel(i18n("Type:"), dummy); + QLabel *l2 = new QLabel(i18n("From:"), dummy); + QLabel *l3 = new QLabel(i18n("To:"), dummy); + + QGridLayout *m1 = new QGridLayout(dummy, 3, 2, 0, 5); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(type_, 0, 1); + m1->addWidget(from_, 1, 1); + m1->addWidget(to_, 2, 1); + + connect(type_, SIGNAL(activated(int)), SLOT(slotTypeChanged(int))); + slotTypeChanged(type_->currentItem()); + + setCaption(i18n("Browse Address")); + resize(250, 100); +} + +QString BrowseDialog::addressString() +{ + QString s; + switch (type_->currentItem()) + { + case 0: + s.append("Send"); + break; + case 1: + s.append("Allow"); + break; + case 2: + s.append("Deny"); + break; + case 3: + s.append("Relay"); + break; + case 4: + s.append("Poll"); + break; + } + if (from_->isEnabled()) + s.append(" ").append(from_->text()); + if (to_->isEnabled()) + s.append(" ").append(to_->text()); + return s; +} + +void BrowseDialog::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(type_, conf->comments_.toolTip("browsetype")); +} + +QString BrowseDialog::newAddress(QWidget *parent, CupsdConf *conf) +{ + BrowseDialog dlg(parent); + dlg.setInfos(conf); + if (dlg.exec()) + { + return dlg.addressString(); + } + return QString::null; +} + +QString BrowseDialog::editAddress(const QString& s, QWidget *parent, CupsdConf *conf) +{ + BrowseDialog dlg(parent); + dlg.setInfos(conf); + QStringList l = QStringList::split(QRegExp("\\s"), s, false); + if (l.count() > 1) + { + if (l[0] == "Send") dlg.type_->setCurrentItem(0); + else if (l[0] == "Allow") dlg.type_->setCurrentItem(1); + else if (l[0] == "Deny") dlg.type_->setCurrentItem(2); + else if (l[0] == "Relay") dlg.type_->setCurrentItem(3); + else if (l[0] == "Poll") dlg.type_->setCurrentItem(4); + dlg.slotTypeChanged(dlg.type_->currentItem()); + int index(1); + if (dlg.from_->isEnabled()) + dlg.from_->setText(l[index++]); + if (dlg.to_->isEnabled()) + dlg.to_->setText(l[index]); + } + if (dlg.exec()) + { + return dlg.addressString(); + } + return QString::null; +} + +void BrowseDialog::slotTypeChanged(int index) +{ + bool useFrom(true), useTo(true); + switch (index) + { + case 0: useFrom = false; break; + case 1: + case 4: + case 2: useTo = false; break; + } + from_->setEnabled(useFrom); + to_->setEnabled(useTo); +} + +#include "browsedialog.moc" |