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 | |
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')
50 files changed, 6492 insertions, 0 deletions
diff --git a/kdeprint/cups/cupsdconf2/Makefile.am b/kdeprint/cups/cupsdconf2/Makefile.am new file mode 100644 index 000000000..84c68ae98 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/Makefile.am @@ -0,0 +1,35 @@ +#$Id$ + +INCLUDES= -I$(top_srcdir) -I$(top_srcdir)/kio -I$(top_srcdir)/kfile $(all_includes) + +bin_PROGRAMS = +lib_LTLIBRARIES = +kdeinit_LTLIBRARIES = cupsdconf.la + +# library creation +cupsdconf_la_SOURCES = cupsdconf.cpp cupsddialog.cpp cupsdpage.cpp cupsdcomment.cpp cupsdsplash.cpp \ + cupsdserverpage.cpp cupsdlogpage.cpp cupsdjobspage.cpp cupsdfilterpage.cpp \ + qdirlineedit.cpp cupsddirpage.cpp portdialog.cpp cupsdnetworkpage.cpp \ + editlist.cpp cupsdbrowsingpage.cpp browsedialog.cpp cupsdsecuritypage.cpp \ + locationdialog.cpp addressdialog.cpp cups-util.c \ + qdirmultilineedit.cpp sizewidget.cpp main.cpp +cupsdconf_la_METASOURCES = AUTO +cupsdconf_la_LDFLAGS = -avoid-version -module $(all_libraries) $(KDE_RPATH) +cupsdconf_la_LIBADD = $(LIB_KIO) $(LIB_CUPS) + +noinst_HEADERS = cupsdconf.h cupsdpage.h cupsddialog.h cupsdcomment.h cupsdsplash.h \ + cupsdserverpage.h cupsdlogpage.h cupsdjobspage.h cupsdfilterpage.h \ + qdirlineedit.h cupsddirpage.h portdialog.h cupsdnetworkpage.h \ + editlist.h cupsdbrowsingpage.h browsedialog.h cupsdsecuritypage.h \ + locationdialog.h addressdialog.h cups-util.h qdirmultilineedit.h \ + sizewidget.h + +# Data +cupsdconfdata_DATA = kde_logo.png cups_logo.png cupsd.conf.template +cupsdconfdatadir = $(kde_datadir)/kdeprint + +# Translations +messages: + perl cupsdcomment.pl < cupsd.conf.template > cupsd.conf.template.cpp + $(XGETTEXT) *.cpp -o $(podir)/cupsdconf.pot + rm -f cupsd.conf.template.cpp diff --git a/kdeprint/cups/cupsdconf2/addressdialog.cpp b/kdeprint/cups/cupsdconf2/addressdialog.cpp new file mode 100644 index 000000000..b7472c5a4 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/addressdialog.cpp @@ -0,0 +1,89 @@ +/* + * 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 "addressdialog.h" + +#include <qcombobox.h> +#include <qlineedit.h> +#include <qlabel.h> +#include <qlayout.h> + +#include <klocale.h> + +AddressDialog::AddressDialog(QWidget *parent, const char *name) + : KDialogBase(Swallow, i18n("ACL Address"), Ok|Cancel, Ok, parent, name, true, true) +{ + QWidget *w = new QWidget(this); + type_ = new QComboBox(w); + address_ = new QLineEdit(w); + + type_->insertItem(i18n("Allow")); + type_->insertItem(i18n("Deny")); + + QLabel *l1 = new QLabel(i18n("Type:"), w); + QLabel *l2 = new QLabel(i18n("Address:"), w); + + QGridLayout *m1 = new QGridLayout(w, 2, 2, 0, 5); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(type_, 0, 1); + m1->addWidget(address_, 1, 1); + + setMainWidget(w); + resize(300, 100); +} + +QString AddressDialog::addressString() +{ + QString s; + if (type_->currentItem() == 0) + s.append("Allow "); + else + s.append("Deny "); + if (address_->text().isEmpty()) + s.append("All"); + else + s.append(address_->text()); + return s; +} + +QString AddressDialog::newAddress(QWidget *parent) +{ + AddressDialog dlg(parent); + if (dlg.exec()) + return dlg.addressString(); + else + return QString::null; +} + +QString AddressDialog::editAddress(const QString& addr, QWidget *parent) +{ + AddressDialog dlg(parent); + int p = addr.find(' '); + if (p != -1) + { + dlg.type_->setCurrentItem(addr.left(p).lower() == "deny" ? 1 : 0); + dlg.address_->setText(addr.mid(p+1)); + } + if (dlg.exec()) + return dlg.addressString(); + else + return QString::null; +} diff --git a/kdeprint/cups/cupsdconf2/addressdialog.h b/kdeprint/cups/cupsdconf2/addressdialog.h new file mode 100644 index 000000000..4560dd72b --- /dev/null +++ b/kdeprint/cups/cupsdconf2/addressdialog.h @@ -0,0 +1,42 @@ +/* + * 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. + **/ + +#ifndef ADDRESSDIALOG_H +#define ADDRESSDIALOG_H + +#include <kdialogbase.h> + +class QComboBox; +class QLineEdit; + +class AddressDialog : public KDialogBase +{ +public: + AddressDialog(QWidget *parent = 0, const char *name = 0); + + QString addressString(); + static QString newAddress(QWidget *parent = 0); + static QString editAddress(const QString& s, QWidget *parent = 0); + +private: + QComboBox *type_; + QLineEdit *address_; +}; + +#endif 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" diff --git a/kdeprint/cups/cupsdconf2/browsedialog.h b/kdeprint/cups/cupsdconf2/browsedialog.h new file mode 100644 index 000000000..ac5be55b7 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/browsedialog.h @@ -0,0 +1,49 @@ +/* + * 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. + **/ + +#ifndef BROWSEDIALOG_H +#define BROWSEDIALOG_H + +#include <kdialogbase.h> + +class QLineEdit; +class QComboBox; +struct CupsdConf; + +class BrowseDialog : public KDialogBase +{ + Q_OBJECT + +public: + BrowseDialog(QWidget *parent = 0, const char *name = 0); + + QString addressString(); + void setInfos(CupsdConf*); + static QString newAddress(QWidget *parent = 0, CupsdConf *conf = 0); + static QString editAddress(const QString& s, QWidget *parent = 0, CupsdConf *conf = 0); + +protected slots: + void slotTypeChanged(int); + +private: + QComboBox *type_; + QLineEdit *from_, *to_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cups-util.c b/kdeprint/cups/cupsdconf2/cups-util.c new file mode 100644 index 000000000..cb6ddcf92 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cups-util.c @@ -0,0 +1,556 @@ +#include <cups/ipp.h> +#include <cups/http.h> +#include <cups/cups.h> +#include <stdlib.h> +#include <fcntl.h> +#include <sys/stat.h> +#include <unistd.h> + +#define CUPS_SERVERROOT "/etc/cups" +static http_t *cups_server; +static ipp_status_t last_error; +static char authstring[HTTP_MAX_VALUE]; +static char pwdstring[33]; +static int cups_local_auth(http_t *http); + +const char* cupsGetConf( void ); +int cupsPutConf( const char* ); + +const char * /* O - Filename for PPD file */ +cupsGetConf(void) +{ + int fd; /* PPD file */ + int bytes; /* Number of bytes read */ + char buffer[8192]; /* Buffer for file */ + char resource[HTTP_MAX_URI]; /* Resource name */ + const char *password; /* Password string */ + char realm[HTTP_MAX_VALUE], /* realm="xyz" string */ + nonce[HTTP_MAX_VALUE], /* nonce="xyz" string */ + plain[255], /* Plaintext username:password */ + encode[512]; /* Encoded username:password */ + http_status_t status; /* HTTP status from server */ + char prompt[1024]; /* Prompt string */ + int digest_tries; /* Number of tries with Digest */ + static char filename[HTTP_MAX_URI]; /* Local filename */ +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + const char *fqdn = 0; +#else + char fqdn[ HTTP_MAX_URI ]; /* Server name buffer */ +#endif + + + /* + * Connect to the correct server as needed... + */ + + if ((cups_server = httpConnectEncrypt(cupsServer(), ippPort(), + cupsEncryption())) == NULL) + { + last_error = IPP_SERVICE_UNAVAILABLE; + return (NULL); + } + + /* + * Get a temp file... + */ + + if ((fd = cupsTempFd(filename, sizeof(filename))) < 0) + { + /* + * Can't open file; close the server connection and return NULL... + */ + + httpFlush(cups_server); + httpClose(cups_server); + cups_server = NULL; + return (NULL); + } + + /* + * And send a request to the HTTP server... + */ + + snprintf(resource, sizeof(resource), "/admin/conf/cupsd.conf"); + + digest_tries = 0; + + do + { + httpClearFields(cups_server); + httpSetField(cups_server, HTTP_FIELD_HOST, cupsServer()); + httpSetField(cups_server, HTTP_FIELD_AUTHORIZATION, authstring); + + if (httpGet(cups_server, resource)) + { + if (httpReconnect(cups_server)) + { + status = HTTP_ERROR; + break; + } + else + { + status = HTTP_UNAUTHORIZED; + continue; + } + } + + while ((status = httpUpdate(cups_server)) == HTTP_CONTINUE); + + if (status == HTTP_UNAUTHORIZED) + { + const char *www_authenticate; + fprintf(stderr,"cupsGetConf: unauthorized...\n"); + + /* + * Flush any error message... + */ + + httpFlush(cups_server); + + /* + * See if we can do local authentication... + */ + + if (cups_local_auth(cups_server)) + continue; + + /* + * See if we should retry the current digest password... + */ + +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + www_authenticate = cups_server->fields[HTTP_FIELD_WWW_AUTHENTICATE]; +#else + www_authenticate = httpGetField( cups_server, HTTP_FIELD_WWW_AUTHENTICATE ); +#endif + if (strncmp(www_authenticate, "Basic", 5) == 0 || + digest_tries > 1 || !pwdstring[0]) + { + /* + * Nope - get a password from the user... + */ +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + fqdn = cups_server->hostname; +#else + httpGetHostname( cups_server, fqdn, sizeof( fqdn ) ); +#endif + + snprintf(prompt, sizeof(prompt), "Password for %s on %s? ", cupsUser(), fqdn ); + + if ((password = cupsGetPassword(prompt)) == NULL) + break; + if (!password[0]) + break; + + strncpy(pwdstring, password, sizeof(pwdstring) - 1); + pwdstring[sizeof(pwdstring) - 1] = '\0'; + + digest_tries = 0; + } + else + digest_tries ++; + + /* + * Got a password; encode it for the server... + */ + +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + www_authenticate = cups_server->fields[HTTP_FIELD_WWW_AUTHENTICATE]; +#else + www_authenticate = httpGetField( cups_server, HTTP_FIELD_WWW_AUTHENTICATE ); +#endif + if (strncmp(www_authenticate, "Basic", 5) == 0) + { + /* + * Basic authentication... + */ + + snprintf(plain, sizeof(plain), "%s:%s", cupsUser(), pwdstring); +#if CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2 + httpEncode64_2(encode, sizeof(encode), plain, sizeof(plain)); +#else + httpEncode64(encode, plain); +#endif + snprintf(authstring, sizeof(authstring), "Basic %s", encode); + } + else + { + /* + * Digest authentication... + */ + + httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "realm", realm); + httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce); + + httpMD5(cupsUser(), realm, pwdstring, encode); + httpMD5Final(nonce, "GET", resource, encode); + snprintf(authstring, sizeof(authstring), + "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " + "response=\"%s\"", cupsUser(), realm, nonce, encode); + } + + continue; + } +#ifdef HAVE_LIBSSL + else if (status == HTTP_UPGRADE_REQUIRED) + { + /* + * Flush any error message... + */ + + httpFlush(cups_server); + + /* + * Upgrade with encryption... + */ + + httpEncryption(cups_server, HTTP_ENCRYPT_REQUIRED); + + /* + * Try again, this time with encryption enabled... + */ + + continue; + } +#endif /* HAVE_LIBSSL */ + } + while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED); + + /* + * See if we actually got the file or an error... + */ + + if (status != HTTP_OK) + { + close(fd); + unlink(filename); + httpFlush(cups_server); + httpClose(cups_server); + cups_server = NULL; + return (NULL); + } + + /* + * OK, we need to copy the file... + */ + + while ((bytes = +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + httpRead +#else + httpRead2 +#endif + (cups_server, buffer, sizeof(buffer))) > 0) + { + write(fd, buffer, bytes); + } + + close(fd); + + return (filename); +} + +int /* O - Status of operation */ +cupsPutConf(const char *name) /* I - Name of the config file to send */ +{ + int fd; /* PPD file */ + int bytes; /* Number of bytes read */ + char buffer[8192]; /* Buffer for file */ + char resource[HTTP_MAX_URI]; /* Resource name */ + const char *password; /* Password string */ + char realm[HTTP_MAX_VALUE], /* realm="xyz" string */ + nonce[HTTP_MAX_VALUE], /* nonce="xyz" string */ + plain[255], /* Plaintext username:password */ + encode[512]; /* Encoded username:password */ + http_status_t status; /* HTTP status from server */ + char prompt[1024]; /* Prompt string */ + int digest_tries; /* Number of tries with Digest */ +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + const char *fqdn = 0; +#else + char fqdn[ HTTP_MAX_URI ]; /* Server name buffer */ +#endif + + if (name == NULL) + return 0; + + /* + * Connect to the correct server as needed... + */ + + if ((cups_server = httpConnectEncrypt(cupsServer(), ippPort(), + cupsEncryption())) == NULL) + { + last_error = IPP_SERVICE_UNAVAILABLE; + return 0; + } + + /* + * Open the local config file... + */ + + if ((fd = open(name, O_RDONLY)) < 0) + { + /* + * Can't open file; close the server connection and return NULL... + */ + + httpFlush(cups_server); + httpClose(cups_server); + cups_server = NULL; + return 0; + } + + /* + * And send a request to the HTTP server... + */ + + strncpy(resource, "/admin/conf/cupsd.conf", sizeof(resource)); + + digest_tries = 0; + + do + { + httpClearFields(cups_server); + httpSetField(cups_server, HTTP_FIELD_HOST, cupsServer()); + httpSetField(cups_server, HTTP_FIELD_AUTHORIZATION, authstring); + httpSetField(cups_server, HTTP_FIELD_TRANSFER_ENCODING, "chunked"); + + if (httpPut(cups_server, resource)) + { + if (httpReconnect(cups_server)) + { + status = HTTP_ERROR; + break; + } + else + { + status = HTTP_UNAUTHORIZED; + continue; + } + } + + /* send the file now */ + lseek(fd, 0, SEEK_SET); + status = HTTP_CONTINUE; + while ((bytes = read(fd, buffer, sizeof(buffer))) > 0) + if (httpCheck(cups_server)) + { + if ((status = httpUpdate(cups_server)) != HTTP_CONTINUE) + break; + } + else +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + httpWrite +#else + httpWrite2 +#endif + (cups_server, buffer, bytes); + + if (status == HTTP_CONTINUE) + { +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + httpWrite +#else + httpWrite2 +#endif + (cups_server, buffer, 0); + while ((status = httpUpdate(cups_server)) == HTTP_CONTINUE); + } + + if (status == HTTP_UNAUTHORIZED) + { + const char *www_authenticate; + fprintf(stderr,"cupsPutConf: unauthorized..."); + + /* + * Flush any error message... + */ + + httpFlush(cups_server); + + /* + * See if we can do local authentication... + */ + + if (cups_local_auth(cups_server)) + continue; + + /* + * See if we should retry the current digest password... + */ + +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + www_authenticate = cups_server->fields[HTTP_FIELD_WWW_AUTHENTICATE]; +#else + www_authenticate = httpGetField( cups_server, HTTP_FIELD_WWW_AUTHENTICATE ); +#endif + if (strncmp(www_authenticate, "Basic", 5) == 0 || + digest_tries > 1 || !pwdstring[0]) + { + /* + * Nope - get a password from the user... + */ + + +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + fqdn = cups_server->hostname; +#else + httpGetHostname( cups_server, fqdn, sizeof( fqdn ) ); +#endif + snprintf(prompt, sizeof(prompt), "Password for %s on %s? ", cupsUser(), fqdn ); + + if ((password = cupsGetPassword(prompt)) == NULL) + break; + if (!password[0]) + break; + + strncpy(pwdstring, password, sizeof(pwdstring) - 1); + pwdstring[sizeof(pwdstring) - 1] = '\0'; + + digest_tries = 0; + } + else + digest_tries ++; + + /* + * Got a password; encode it for the server... + */ + +#if CUPS_VERSION_MAJOR - 0 <= 1 && CUPS_VERSION_MINOR - 0 < 2 + www_authenticate = cups_server->fields[HTTP_FIELD_WWW_AUTHENTICATE]; +#else + www_authenticate = httpGetField( cups_server, HTTP_FIELD_WWW_AUTHENTICATE ); +#endif + if (strncmp(www_authenticate, "Basic", 5) == 0) + { + /* + * Basic authentication... + */ + + snprintf(plain, sizeof(plain), "%s:%s", cupsUser(), pwdstring); +#if CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2 + httpEncode64_2(encode, sizeof(encode), plain, sizeof(plain)); +#else + httpEncode64(encode, plain); +#endif + snprintf(authstring, sizeof(authstring), "Basic %s", encode); + } + else + { + /* + * Digest authentication... + */ + + httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "realm", realm); + httpGetSubField(cups_server, HTTP_FIELD_WWW_AUTHENTICATE, "nonce", nonce); + + httpMD5(cupsUser(), realm, pwdstring, encode); + httpMD5Final(nonce, "GET", resource, encode); + snprintf(authstring, sizeof(authstring), + "Digest username=\"%s\", realm=\"%s\", nonce=\"%s\", " + "response=\"%s\"", cupsUser(), realm, nonce, encode); + } + + continue; + } +#ifdef HAVE_LIBSSL + else if (status == HTTP_UPGRADE_REQUIRED) + { + /* + * Flush any error message... + */ + + httpFlush(cups_server); + + /* + * Upgrade with encryption... + */ + + httpEncryption(cups_server, HTTP_ENCRYPT_REQUIRED); + + /* + * Try again, this time with encryption enabled... + */ + + continue; + } +#endif /* HAVE_LIBSSL */ + } + while (status == HTTP_UNAUTHORIZED || status == HTTP_UPGRADE_REQUIRED); + + /* + * See if we actually got the file or an error... + */ + + if (status != HTTP_CREATED) + { + httpFlush(cups_server); + httpClose(cups_server); + cups_server = NULL; + close(fd); + return 0; + } + + close(fd); + + return 1; +} + +static int /* O - 1 if available, 0 if not */ +cups_local_auth(http_t *http) /* I - Connection */ +{ + int pid; /* Current process ID */ + FILE *fp; /* Certificate file */ + char filename[1024], /* Certificate filename */ + certificate[33];/* Certificate string */ + const char *root; /* Server root directory */ + + + /* + * See if we are accessing localhost... + the struct has changed in newer versions - PiggZ (adam@piggz.co.uk) + */ +#if CUPS_VERSION_MAJOR == 1 && CUPS_VERSION_MINOR >= 2 + if (!httpAddrLocalhost(http)) +#else + if (ntohl(*(int*)&http->hostaddr.sin_addr) != 0x7f000001 && + strcasecmp(http->hostname, "localhost") != 0) +#endif + return (0); + + /* + * Try opening a certificate file for this PID. If that fails, + * try the root certificate... + */ + + if ((root = getenv("CUPS_SERVERROOT")) == NULL) + root = CUPS_SERVERROOT; + + pid = getpid(); + snprintf(filename, sizeof(filename), "%s/certs/%d", root, pid); + if ((fp = fopen(filename, "r")) == NULL && pid > 0) + { + snprintf(filename, sizeof(filename), "%s/certs/0", root); + fp = fopen(filename, "r"); + } + + if (fp == NULL) + return (0); + + /* + * Read the certificate from the file... + */ + + fgets(certificate, sizeof(certificate), fp); + fclose(fp); + + /* + * Set the authorization string and return... + */ + + snprintf(authstring, sizeof(authstring), "Local %s", certificate); + + return (1); +} + diff --git a/kdeprint/cups/cupsdconf2/cups-util.h b/kdeprint/cups/cupsdconf2/cups-util.h new file mode 100644 index 000000000..1daf4050e --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cups-util.h @@ -0,0 +1,26 @@ +/* + * 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. + **/ + +#ifndef CUPS_UTIL_H +#define CUPS_UTIL_H + +const char* cupsGetConf(void); +int cupsPutConf(const char *filename); + +#endif diff --git a/kdeprint/cups/cupsdconf2/cups_logo.png b/kdeprint/cups/cupsdconf2/cups_logo.png Binary files differnew file mode 100644 index 000000000..e6f9b5919 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cups_logo.png diff --git a/kdeprint/cups/cupsdconf2/cupsd.conf.template b/kdeprint/cups/cupsdconf2/cupsd.conf.template new file mode 100644 index 000000000..c91f0dfa3 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsd.conf.template @@ -0,0 +1,977 @@ +%%header +# CUPS configuration file, generated by CUPS configuration tool. +# This tool is part of KDEPrint, the printing framework for KDE +# since version 2.2.2 and is used by the CUPS supporting module +# in KDEPrint. The predecessors to KDEPrint in former KDE releases +# were KUPS and QtCUPS; they are deprecated and no longer maintained. +# +# Author: Michael Goffioul <kdeprint@swing.be> +# +# Web site: http://printing.kde.org/ +# +######################################################################## +# # +# This is the CUPS configuration file. If you are familiar with # +# Apache or any of the other popular web servers, we've followed the # +# same format. Any configuration variable used here has the same # +# semantics as the corresponding variable in Apache. If we need # +# different functionality then a different name is used to avoid # +# confusion... # +# # +######################################################################## +@@ + +%%servername +# <b>Server name (ServerName)</b> +# <p> +# The hostname of your server, as advertised to the world. +# By default CUPS will use the hostname of the system.</p> +# <p> +# To set the default server used by clients, see the client.conf file.</p> +# <p> +# <i>ex</i>: myhost.domain.com</p> +$$ +#ServerName myhost.domain.com +@@ + +%%serveradmin +# <b>Server administrator (ServerAdmin)</b> +# <p> +# The email address to send all complaints or problems to. +# By default CUPS will use "root@hostname".</p> +# <p> +# <i>ex</i>: root@myhost.com</p> +$$ +#ServerAdmin root@your.domain.com +@@ + +%%accesslog +# <b>Access log (AccessLog)</b> +# <p> +# The access log file; if this does not start with a leading / +# then it is assumed to be relative to ServerRoot. By default set to +# "/var/log/cups/access_log".</p> +# <p> +# You can also use the special name <b>syslog</b> to send the output to the +# syslog file or daemon.</p> +# <p> +# <i>ex</i>: /var/log/cups/access_log</p> +$$ +#AccessLog /var/log/cups/access_log +@@ + +%%datadir +# <b>Data directory (DataDir)</b> +# <p> +# The root directory for the CUPS data files. +# By default /usr/share/cups.</p> +# <p> +# <i>ex</i>: /usr/share/cups</p> +$$ +#DataDir /usr/share/cups +@@ + +%%defaultcharset +# <b>Default character set (DefaultCharset)</b> +# <p> +# The default character set to use. If not specified, +# defaults to utf-8. Note that this can also be overridden in +# HTML documents...</p> +# <p> +# <i>ex</i>: utf-8</p> +$$ +#DefaultCharset utf-8 +@@ + +%%defaultlanguage +# <b>Default language (DefaultLanguage)</b> +# <p> +# The default language if not specified by the browser. +# If not specified, the current locale is used.</p> +# <p> +# <i>ex</i>: en</p> +$$ +#DefaultLanguage en +@@ + +%%documentroot +# <b>Document directory (DocumentRoot)</b> +# <p> +# The root directory for HTTP documents that are served. +# By default the compiled-in directory.</p> +# <p> +# <i>ex</i>: /usr/share/cups/doc</p> +$$ +#DocumentRoot /usr/share/cups/doc +@@ + +%%errorlog +# <b>Error log (ErrorLog)</b> +# <p> +# The error log file; if this does not start with a leading / +# then it is assumed to be relative to ServerRoot. By default set to +# "/var/log/cups/error_log".</p> +# <p> +# You can also use the special name <b>syslog</b> to send the output to the +# syslog file or daemon.</p> +# <p> +# <i>ex</i>: /var/log/cups/error_log</p> +$$ +#ErrorLog /var/log/cups/error_log +@@ + +%%fontpath +# <b>Font path (FontPath)</b> +# <p> +# The path to locate all font files (currently only for pstoraster). +# By default /usr/share/cups/fonts.</p> +# <p> +# <i>ex</i>: /usr/share/cups/fonts</p> +$$ +#FontPath /usr/share/cups/fonts +@@ + +%%loglevel +# <b>Log level (LogLevel)</b> +# <p> +# Controls the number of messages logged to the ErrorLog +# file and can be one of the following:</p> +# <ul type=circle> +# <li><i>debug2</i>: Log everything.</li> +# <li><i>debug</i>: Log almost everything.</li> +# <li><i>info</i>: Log all requests and state changes.</li> +# <li><i>warn</i>: Log errors and warnings.</li> +# <li><i>error</i>: Log only errors.</li> +# <li><i>none</i>: Log nothing.</li> +# </ul><p> +# <i>ex</i>: info</p> +$$ +#LogLevel info +@@ + +%%maxlogsize +# <b>Max log size (MaxLogSize)</b> +# <p> +# Controls the maximum size of each log file before they are +# rotated. Defaults to 1048576 (1MB). Set to 0 to disable log rotating.</p> +# <p> +# <i>ex</i>: 1048576</p> +$$ +#MaxLogSize 0 +@@ + +%%pagelog +# <b>Page log (PageLog)</b> +# <p> +# The page log file; if this does not start with a leading / +# then it is assumed to be relative to ServerRoot. By default set to +# "/var/log/cups/page_log".</p> +# <p> +# You can also use the special name <b>syslog</b> to send the output to the +# syslog file or daemon.</p> +# <p> +# <i>ex</i>: /var/log/cups/page_log</p> +$$ +#PageLog /var/log/cups/page_log +@@ + +%%preservejobhistory +# <b>Preserve job history (PreserveJobHistory)</b> +# <p> +# Whether or not to preserve the job history after a +# job is completed, canceled, or stopped. Default is Yes.</p> +# <p> +# <i>ex</i>: Yes</p> +$$ +#PreserveJobHistory Yes +@@ + +%%preservejobfiles +# <b>Preserve job files (PreserveJobFiles)</b> +# <p> +# Whether or not to preserve the job files after a +# job is completed, canceled, or stopped. Default is No.</p> +# <p> +# <i>ex</i>: No</p> +$$ +#PreserveJobFiles No +@@ + +%%printcap +# <b>Printcap file (Printcap)</b> +# <p> +# The name of the printcap file. Default is no filename. +# Leave blank to disable printcap file generation.</p> +# <p> +# <i>ex</i>: /etc/printcap</p> +$$ +#Printcap /etc/printcap +@@ + +%%requestroot +# <b>Request directory (RequestRoot)</b> +# <p> +# The directory where request files are stored. +# By default /var/spool/cups.</p> +# <p> +# <i>ex</i>: /var/spool/cups</p> +$$ +#RequestRoot /var/spool/cups +@@ + +%%remoteroot +# <b>Remote root user (RemoteRoot)</b> +# <p> +# The name of the user assigned to unauthenticated accesses +# from remote systems. By default "remroot".</p> +# <p> +# <i>ex</i>: remroot</p> +$$ +#RemoteRoot remroot +@@ + +%%serverbin +# <b>Server binaries (ServerBin)</b> +# <p> +# The root directory for the scheduler executables. +# By default /usr/lib/cups or /usr/lib32/cups (IRIX 6.5).</p> +# <p> +# <i>ex</i>: /usr/lib/cups</p> +$$ +#ServerBin /usr/lib/cups +@@ + +%%serverroot +# <b>Server files (ServerRoot)</b> +# <p> +# The root directory for the scheduler. +# By default /etc/cups.</p> +# <p> +# <i>ex</i>: /etc/cups</p> +$$ +#ServerRoot /etc/cups +@@ + +%%user +# <b>User (User)</b> +# <p> +# The user the server runs under. Normally this +# must be <b>lp</b>, however you can configure things for another user +# as needed.</p> +# <p> +# Note: the server must be run initially as root to support the +# default IPP port of 631. It changes users whenever an external +# program is run...</p> +# <p> +# <i>ex</i>: lp</p> +$$ +#User lp +@@ + +%%group +# <b>Group (Group)</b> +# <p> +# The group the server runs under. Normally this +# must be <b>sys</b>, however you can configure things for another +# group as needed.</p> +# <p> +# <i>ex</i>: sys</p> +$$ +#Group sys +@@ + +%%ripcache +# <b>RIP cache (RIPCache)</b> +# <p> +# The amount of memory that each RIP should use to cache +# bitmaps. The value can be any real number followed by "k" for +# kilobytes, "m" for megabytes, "g" for gigabytes, or "t" for tiles +# (1 tile = 256x256 pixels). Defaults to "8m" (8 megabytes).</p> +# <p> +# <i>ex</i>: 8m</p> +$$ +#RIPCache 8m +@@ + +%%tempdir +# <b>Temporary files (TempDir)</b> +# <p> +# The directory to put temporary files in. This directory must be +# writable by the user defined above! Defaults to "/var/spool/cups/tmp" or +# the value of the TMPDIR environment variable.</p> +# <p> +# <i>ex</i>: /var/spool/cups/tmp</p> +$$ +#TempDir /var/spool/cups/tmp +@@ + +%%filterlimit +# <b>Filter limit (FilterLimit)</b> +# <p> +# Sets the maximum cost of all job filters that can be run +# at the same time. A limit of 0 means no limit. A typical job may need +# a filter limit of at least 200; limits less than the minimum required +# by a job force a single job to be printed at any time.</p> +# <p> +# The default limit is 0 (unlimited).</p> +# <p> +# <i>ex</i>: 200</p> +$$ +#FilterLimit 0 +@@ + +%%listen +# <b>Listen to (Port/Listen)</b> +# <p> +# Ports/addresses that are listened to. The default port 631 is reserved +# for the Internet Printing Protocol (IPP) and is what is used here.</p> +# <p> +# You can have multiple Port/Listen lines to listen to more than one +# port or address, or to restrict access.</p> +# <p> +# Note: Unfortunately, most web browsers don't support TLS or HTTP Upgrades +# for encryption. If you want to support web-based encryption you will +# probably need to listen on port 443 (the "HTTPS" port...).</p> +# <p> +# <i>ex</i>: 631, myhost:80, 1.2.3.4:631</p> +$$ +# Port 80 +# Port 631 +# Listen hostname +# Listen hostname:80 +# Listen hostname:631 +# Listen 1.2.3.4 +# Listen 1.2.3.4:631 +# +#Port 631 +@@ + +%%hostnamelookups +# <b>Hostname lookups (HostNameLookups)</b> +# <p> +# Whether or not to do lookups on IP addresses to get a +# fully-qualified hostname. This defaults to Off for performance reasons...</p> +# <p> +# <i>ex</i>: On</p> +$$ +#HostNameLookups On +@@ + +%%keepalive +# <b>Keep alive (KeepAlive)</b> +# <p> +# Whether or not to support the Keep-Alive connection +# option. Default is on.</p> +# <p> +# <i>ex</i>: On</p> +$$ +#KeepAlive On +@@ + +%%keepalivetimeout +# <b>Keep-alive timeout (KeepAliveTimeout)</b> +# <p> +# The timeout (in seconds) before Keep-Alive connections are +# automatically closed. Default is 60 seconds.</p> +# <p> +# <i>ex</i>: 60</p> +$$ +#KeepAliveTimeout 60 +@@ + +%%maxclients +# <b>Max clients (MaxClients)</b> +# <p> +# Controls the maximum number of simultaneous clients that +# will be handled. Defaults to 100.</p> +# <p> +# <i>ex</i>: 100</p> +$$ +#MaxClients 100 +@@ + +%%maxrequestsize +# <b>Max request size (MaxRequestSize)</b> +# <p> +# Controls the maximum size of HTTP requests and print files. +# Set to 0 to disable this feature (defaults to 0).</p> +# <p> +# <i>ex</i>: 0</p> +$$ +#MaxRequestSize 0 +@@ + +%%timeout +# <b>Client timeout (Timeout)</b> +# <p> +# The timeout (in seconds) before requests time out. Default is 300 seconds.</p> +# <p> +# <i>ex</i>: 300</p> +$$ +#Timeout 300 +@@ + +%%browsing +# <b>Use browsing (Browsing)</b> +# <p> +# Whether or not to <b>listen</b> to printer +# information from other CUPS servers. +# </p> +# <p> +# Enabled by default. +# </p> +# <p> +# Note: to enable the <b>sending</b> of browsing +# information from this CUPS server to the LAN, +# specify a valid <i>BrowseAddress</i>. +# </p> +# <p> +# <i>ex</i>: On</p> +$$ +#Browsing On +@@ + +%%browseshortnames +# <b>Use short names (BrowseShortNames)</b> +# <p> +# Whether or not to use "short" names for remote printers +# when possible (e.g. "printer" instead of "printer@host"). Enabled by +# default.</p> +# <p> +# <i>ex</i>: Yes</p> +$$ +#BrowseShortNames Yes +@@ + +%%browseaddress +# <b>Browse addresses (BrowseAddress)</b> +# <p> +# Specifies a broadcast address to be used. By +# default browsing information is broadcast to all active interfaces.</p> +# <p> +# Note: HP-UX 10.20 and earlier do not properly handle broadcast unless +# you have a Class A, B, C, or D netmask (i.e. no CIDR support).</p> +# <p> +# <i>ex</i>: x.y.z.255, x.y.255.255</p> +$$ +#BrowseAddress x.y.z.255 +#BrowseAddress x.y.255.255 +#BrowseAddress x.255.255.255 +@@ + +%%browseallow +# <b>Browse allow/deny (BrowseAllow/BrowseDeny)</b> +# <p> +# <u>BrowseAllow</u>: specifies an address mask to allow for incoming browser +# packets. The default is to allow packets from all addresses.</p> +# <p> +# <u>BrowseDeny</u>: specifies an address mask to deny for incoming browser +# packets. The default is to deny packets from no addresses.</p> +# <p> +# Both "BrowseAllow" and "BrowseDeny" accept the following notations for +# addresses:</p> +# <pre> +# All +# None +# *.domain.com +# .domain.com +# host.domain.com +# nnn.* +# nnn.nnn.* +# nnn.nnn.nnn.* +# nnn.nnn.nnn.nnn +# nnn.nnn.nnn.nnn/mm +# nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm +# </pre><p> +# The hostname/domainname restrictions only work if you have turned hostname +# lookups on!</p> +$$ +#BrowseAllow address +#BrowseDeny address +@@ + +%%browseinterval +# <b>Browse interval (BrowseInterval)</b> +# <p> +# The time between browsing updates in seconds. Default +# is 30 seconds.</p> +# <p> +# Note that browsing information is sent whenever a printer's state changes +# as well, so this represents the maximum time between updates.</p> +# <p> +# Set this to 0 to disable outgoing broadcasts so your local printers are +# not advertised but you can still see printers on other hosts.</p> +# <p> +# <i>ex</i>: 30</p> +$$ +#BrowseInterval 30 +@@ + +%%browseorder +# <b>Browse order (BrowseOrder)</b> +# <p> +# Specifies the order of BrowseAllow/BrowseDeny comparisons.</p> +# <p> +# <i>ex</i>: allow,deny</p> +$$ +#BrowseOrder allow,deny +#BrowseOrder deny,allow +@@ + +%%browsepoll +# <b>Browse poll (BrowsePoll)</b> +# <p> +# Poll the named server(s) for printers.</p> +# <p> +# <i>ex</i>: myhost:631</p> +$$ +#BrowsePoll address:port +@@ + +%%browseport +# <b>Browse port (BrowsePort)</b> +# <p> +# The port used for UDP broadcasts. By default this is +# the IPP port; if you change this you need to do it on all servers. +# Only one BrowsePort is recognized.</p> +# <p> +# <i>ex</i>: 631</p> +$$ +#BrowsePort 631 +@@ + +%%browserelay +# <b>Browse relay (BrowseRelay)</b> +# <p> +# Relay browser packets from one address/network to another.</p> +# <p> +# <i>ex</i>: src-address dest-address</p> +$$ +#BrowseRelay source-address destination-address +@@ + +%%browsetimeout +# <b>Browse timeout (BrowseTimeout)</b> +# <p> +# The timeout (in seconds) for network printers - if we don't +# get an update within this time the printer will be removed +# from the printer list. This number definitely should not be +# less the BrowseInterval value for obvious reasons. Defaults +# to 300 seconds.</p> +# <p> +# <i>ex</i>: 300</p> +$$ +#BrowseTimeout 300 +@@ + +%%implicitclasses +# <b>Implicit classes (ImplicitClasses)</b> +# <p> +# Whether or not to use implicit classes.</p> +# <p> +# Printer classes can be specified explicitly in the classes.conf +# file, implicitly based upon the printers available on the LAN, or +# both.</p> +# <p> +# When ImplicitClasses is On, printers on the LAN with the same name +# (e.g. Acme-LaserPrint-1000) will be put into a class with the same +# name. This allows you to setup multiple redundant queues on a LAN +# without a lot of administrative difficulties. If a user sends a +# job to Acme-LaserPrint-1000, the job will go to the first available +# queue.</p> +# <p> +# Enabled by default.</p> +$$ +#ImplicitClasses Off +@@ + +%%systemgroup +# <b>System group (SystemGroup)</b> +# <p> +# The group name for "System" (printer administration) +# access. The default varies depending on the operating system, but +# will be <b>sys</b>, <b>system</b>, or <b>root</b> (checked for in that order).</p> +# <p> +# <i>ex</i>: sys</p> +$$ +#SystemGroup sys +@@ + +%%servercertificate +# <b>Encryption certificate (ServerCertificate)</b> +# <p> +# The file to read containing the server's certificate. +# Defaults to "/etc/cups/ssl/server.crt".</p> +# <p> +# <i>ex</i>: /etc/cups/ssl/server.crt</p> +$$ +#ServerCertificate /etc/cups/ssl/server.crt +@@ + +%%serverkey +# <b>Encryption key (ServerKey)</b> +# <p> +# The file to read containing the server's key. +# Defaults to "/etc/cups/ssl/server.key".</p> +# <p> +# <i>ex</i>: /etc/cups/ssl/server.key</p> +$$ +#ServerKey /etc/cups/ssl/server.key +@@ + +%%locations +# Access permissions +# +# Access permissions for each directory served by the scheduler. +# Locations are relative to DocumentRoot... +# +# AuthType: the authorization to use: +# +# None - Perform no authentication +# Basic - Perform authentication using the HTTP Basic method. +# Digest - Perform authentication using the HTTP Digest method. +# +# (Note: local certificate authentication can be substituted by +# the client for Basic or Digest when connecting to the +# localhost interface) +# +# AuthClass: the authorization class; currently only Anonymous, User, +# System (valid user belonging to group SystemGroup), and Group +# (valid user belonging to the specified group) are supported. +# +# AuthGroupName: the group name for "Group" authorization. +# +# Order: the order of Allow/Deny processing. +# +# Allow: allows access from the specified hostname, domain, IP address, or +# network. +# +# Deny: denies access from the specified hostname, domain, IP address, or +# network. +# +# Both "Allow" and "Deny" accept the following notations for addresses: +# +# All +# None +# *.domain.com +# .domain.com +# host.domain.com +# nnn.* +# nnn.nnn.* +# nnn.nnn.nnn.* +# nnn.nnn.nnn.nnn +# nnn.nnn.nnn.nnn/mm +# nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm +# +# The host and domain address require that you enable hostname lookups +# with "HostNameLookups On" above. +# +# Encryption: whether or not to use encryption; this depends on having +# the OpenSSL library linked into the CUPS library and scheduler. +# +# Possible values: +# +# Always - Always use encryption (SSL) +# Never - Never use encryption +# Required - Use TLS encryption upgrade +# IfRequested - Use encryption if the server requests it +# +# The default value is "IfRequested". +$$ +#<Location [resource_name]> +# +# You may wish to limit access to printers and classes, either with Allow +# and Deny lines, or by requiring a username and password. +# +# +## Anonymous access (default) +#AuthType None +# +## Require a username and password (Basic authentication) +#AuthType Basic +#AuthClass User +# +## Require a username and password (Digest/MD5 authentication) +#AuthType Digest +#AuthClass User +# +## Restrict access to local domain +#Order Deny,Allow +#Deny From All +#Allow From .mydomain.com +# +## Use encryption if requested +#Encryption IfRequested +#</Location> +@@ + +%%authtype +# <b>Authentication (AuthType)</b> +# <p> +# The authorization to use:<p> +# <ul type=circle> +# <li><i>None</i> - Perform no authentication.</li> +# <li><i>Basic</i> - Perform authentication using the HTTP Basic method.</li> +# <li><i>Digest</i> - Perform authentication using the HTTP Digest method.</li> +# </ul><p> +# Note: local certificate authentication can be substituted by +# the client for <i>Basic</i> or <i>Digest</i> when connecting to the +# localhost interface.</p> +@@ + +%%authclass +# <b>Class (AuthClass)</b> +# <p> +# The authorization class; currently only <i>Anonymous</i>, <i>User</i>, +# <i>System</i> (valid user belonging to group SystemGroup), and <i>Group</i> +# (valid user belonging to the specified group) are supported.</p> +@@ + +%%authname +# <p>The user/group names allowed to access the resource. The format is a +# comma separated list.</p> +@@ + +%%satisfy +# <b>Satisfy (Satisfy)</b> +# <p> +# This directive controls whether all specified conditions must +# be satisfied to allow access to the resource. If set to "all", +# then all authentication and access control conditions must be +# satisfied to allow access. +# </p> +# <p> +# Setting Satisfy to "any" allows a user to gain access if the +# authentication <i>or</i> access control requirements are satisfied. +# For example, you might require authentication for remote access, +# but allow local access without authentication. +# </p> +# <p> +# The default is "all". +# </p> +@@ + +%%authgroupname +# <b>Authentication group name (AuthGroupName)</b> +# <p> +# The group name for <i>Group</i> authorization.</p> +@@ + +%%order +# <b>ACL order (Order)</b> +# <p> +# The order of Allow/Deny processing.</p> +@@ + +%%allow +# <b>Allow</b> +# <p> +# Allows access from the specified hostname, domain, IP address, or +# network. Possible values are:</p> +# <pre> +# All +# None +# *.domain.com +# .domain.com +# host.domain.com +# nnn.* +# nnn.nnn.* +# nnn.nnn.nnn.* +# nnn.nnn.nnn.nnn +# nnn.nnn.nnn.nnn/mm +# nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm +# </pre><p> +# The host and domain address require that you enable hostname lookups +# with "HostNameLookups On" above.</p> +@@ + +%%allowdeny +# <b>ACL addresses (Allow/Deny)</b> +# <p> +# Allows/Denies access from the specified hostname, domain, IP address, or +# network. Possible values are:</p> +# <pre> +# All +# None +# *.domain.com +# .domain.com +# host.domain.com +# nnn.* +# nnn.nnn.* +# nnn.nnn.nnn.* +# nnn.nnn.nnn.nnn +# nnn.nnn.nnn.nnn/mm +# nnn.nnn.nnn.nnn/mmm.mmm.mmm.mmm +# </pre><p> +# The host and domain address require that you enable hostname lookups +# with "HostNameLookups On" above.</p> +@@ + +%%encryption +# <b>Encryption (Encryption)</b> +# <p> +# Whether or not to use encryption; this depends on having +# the OpenSSL library linked into the CUPS library and scheduler.</p> +# <p> +# Possible values:</p> +# <ul type=circle> +# <li><i>Always</i> - Always use encryption (SSL)</li> +# <li><i>Never</i> - Never use encryption</li> +# <li><i>Required</i> - Use TLS encryption upgrade</li> +# <li><i>IfRequested</i> - Use encryption if the server requests it</li> +# </ul><p> +# The default value is "IfRequested".</p> +@@ + +%%locationsshort +# <b>Access permissions</b> +# <p> +# Access permissions for each directory served by the scheduler. +# Locations are relative to DocumentRoot...</p> +@@ + +%%autopurgejobs +# <b>Auto purge jobs (AutoPurgeJobs)</b> +# <p> +# Automatically purge jobs when not needed for quotas. +# Default is No.</p> +$$ +#AutoPurgeJobs No +@@ + +%%browseprotocols +# <b>Browse protocols (BrowseProtocols)</b> +# <p> +# Which protocols to use for browsing. Can be +# any of the following separated by whitespace and/or commas:</p> +# <ul type=circle> +# <li><i>all</i> - Use all supported protocols.</li> +# <li><i>cups</i> - Use the CUPS browse protocol.</li> +# <li><i>slp</i> - Use the SLPv2 protocol.</li> +# </ul><p> +# The default is <b>cups</b>.</p> +# <p> +# Note: If you choose to use SLPv2, it is <b>strongly</b> recommended that +# you have at least one SLP Directory Agent (DA) on your +# network. Otherwise, browse updates can take several seconds, +# during which the scheduler will not response to client +# requests.</p> +$$ +#BrowseProtocols cups +@@ + +%%classification +# <b>Classification (Classification)</b> +# <p> +# The classification level of the server. If set, this +# classification is displayed on all pages, and raw printing is disabled. +# The default is the empty string.</p> +# <p> +# <i>ex</i>: confidential +$$ +#Classification classified +@@ + +%%classifyoverride +# <b>Allow overrides (ClassifyOverride)</b> +# <p> +# Whether to allow users to override the classification +# on printouts. If enabled, users can limit banner pages to before or +# after the job, and can change the classification of a job, but cannot +# completely eliminate the classification or banners.</p> +# <p> +# The default is off.</p> +$$ +#ClassifyOverride off +@@ + +%%hideimplicitmembers +# <b>Hide implicit members (HideImplicitMembers)</b> +# <p> +# Whether or not to show the members of an +# implicit class.</p> +# <p> +# When HideImplicitMembers is On, any remote printers that are +# part of an implicit class are hidden from the user, who will +# then only see a single queue even though many queues will be +# supporting the implicit class.</p> +# <p> +# Enabled by default.</p> +$$ +#HideImplicitMembers On +@@ + +%%implicitanyclasses +# <b>Use "any" classes (ImplicitAnyClasses)</b> +# <p> +# Whether or not to create <b>AnyPrinter</b> implicit +# classes.</p> +# <p> +# When ImplicitAnyClasses is On and a local queue of the same name +# exists, e.g. "printer", "printer@server1", "printer@server1", then +# an implicit class called "Anyprinter" is created instead.</p> +# <p> +# When ImplicitAnyClasses is Off, implicit classes are not created +# when there is a local queue of the same name.</p> +# <p> +# Disabled by default.</p> +$$ +#ImplicitAnyCLasses Off +@@ + +%%maxjobs +# <b>Max jobs (MaxJobs)</b> +# <p> +# Maximum number of jobs to keep in memory (active and completed). +# Default is 0 (no limit).</p> +$$ +#MaxJobs 0 +@@ + +%%maxjobsperuser +# <b>Max jobs per user (MaxJobsPerUser)</b> +# <p> +# The MaxJobsPerUser directive controls the maximum number of <i>active</i> +# jobs that are allowed for each user. Once a user reaches the limit, new +# jobs will be rejected until one of the active jobs is completed, stopped, +# aborted, or canceled.</p> +# <p> +# Setting the maximum to 0 disables this functionality. +# Default is 0 (no limit). +# </p> +$$ +#MaxJobsPerUser 0 +@@ + +%%maxjobsperprinter +# <b>Max jobs per printer (MaxJobsPerPrinter)</b> +# <p> +# The MaxJobsPerPrinter directive controls the maximum number of <i>active</i> +# jobs that are allowed for each printer or class. Once a printer or class +# reaches the limit, new jobs will be rejected until one of the active jobs +# is completed, stopped, aborted, or canceled.</p> +# <p> +# Setting the maximum to 0 disables this functionality. +# Default is 0 (no limit). +# </p> +$$ +#MaxJobsPerPrinter 0 +@@ + +%%port +# <b>Port</b> +# <p> +# The port value that the CUPS daemon is listening to. Default is 631.</p> +@@ + +%%address +# <b>Address</b> +# <p> +# The address that the CUPS daemon is listening at. Leave it empty or use +# an asterisk (*) to specify a port value on the entire subnetwork.</p> +@@ + +%%usessl +# <p>Check this box if you want to use SSL encryption with this address/port. +# </p> +@@ diff --git a/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.cpp b/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.cpp new file mode 100644 index 000000000..a61742458 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.cpp @@ -0,0 +1,210 @@ +/* + * 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 "cupsdbrowsingpage.h" +#include "cupsdconf.h" +#include "editlist.h" +#include "browsedialog.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <knuminput.h> + +CupsdBrowsingPage::CupsdBrowsingPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Browsing")); + setHeader(i18n("Browsing Settings")); + setPixmap("kdeprint_printer_remote"); + + browseinterval_ = new KIntNumInput(this); + browseport_ = new KIntNumInput(this); + browsetimeout_ = new KIntNumInput(this); + browsing_ = new QCheckBox(i18n("Use browsing"), this); + cups_ = new QCheckBox("CUPS", this); + slp_ = new QCheckBox("SLP", this); + browseaddresses_ = new EditList(this); + browseorder_ = new QComboBox(this); + useimplicitclasses_ = new QCheckBox(i18n("Implicit classes"), this); + hideimplicitmembers_ = new QCheckBox(i18n("Hide implicit members"), this); + useshortnames_ = new QCheckBox(i18n("Use short names"), this); + useanyclasses_ = new QCheckBox(i18n("Use \"any\" classes"), this); + + browseorder_->insertItem(i18n("Allow, Deny")); + browseorder_->insertItem(i18n("Deny, Allow")); + + browseport_->setRange(0, 9999, 1, true); + browseport_->setSteps(1, 5); + browseinterval_->setRange(0, 10000, 1, true); + browseinterval_->setSteps(1, 10); + browseinterval_->setSuffix(i18n(" sec")); + browsetimeout_->setRange(0, 10000, 1, true); + browsetimeout_->setSteps(1, 10); + browsetimeout_->setSuffix(i18n(" sec")); + + QLabel *l1 = new QLabel(i18n("Browse port:"), this); + QLabel *l2 = new QLabel(i18n("Browse interval:"), this); + QLabel *l3 = new QLabel(i18n("Browse timeout:"), this); + QLabel *l4 = new QLabel(i18n("Browse addresses:"), this); + QLabel *l5 = new QLabel(i18n("Browse order:"), this); + QLabel *l6 = new QLabel(i18n("Browse options:"), this); + + QGridLayout *m1 = new QGridLayout(this, 8, 2, 10, 7); + m1->setRowStretch(7, 1); + m1->setColStretch(1, 1); + QHBoxLayout *m2 = new QHBoxLayout(0, 0, 10); + m1->addMultiCellLayout(m2, 0, 0, 0, 1); + m2->addWidget(browsing_); + m2->addWidget(cups_); + m2->addWidget(slp_); + m2->addStretch(1); + m1->addWidget(l1, 1, 0, Qt::AlignRight); + m1->addWidget(l2, 2, 0, Qt::AlignRight); + m1->addWidget(l3, 3, 0, Qt::AlignRight); + m1->addWidget(l4, 4, 0, Qt::AlignRight|Qt::AlignTop); + m1->addWidget(l5, 5, 0, Qt::AlignRight); + m1->addWidget(l6, 6, 0, Qt::AlignRight|Qt::AlignTop); + m1->addWidget(browseport_, 1, 1); + m1->addWidget(browseinterval_, 2, 1); + m1->addWidget(browsetimeout_, 3, 1); + m1->addWidget(browseaddresses_, 4, 1); + m1->addWidget(browseorder_, 5, 1); + QGridLayout *m3 = new QGridLayout(0, 2, 2, 0, 5); + m1->addLayout(m3, 6, 1); + m3->addWidget(useimplicitclasses_, 0, 0); + m3->addWidget(useanyclasses_, 0, 1); + m3->addWidget(hideimplicitmembers_, 1, 0); + m3->addWidget(useshortnames_, 1, 1); + + connect(browsing_, SIGNAL(toggled(bool)), cups_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), slp_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), browseport_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), browseinterval_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), browsetimeout_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), browseaddresses_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), browseorder_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), useimplicitclasses_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), useanyclasses_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), hideimplicitmembers_, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), useshortnames_, SLOT(setEnabled(bool))); + + connect(browsing_, SIGNAL(toggled(bool)), l1, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), l2, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), l3, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), l4, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), l5, SLOT(setEnabled(bool))); + connect(browsing_, SIGNAL(toggled(bool)), l6, SLOT(setEnabled(bool))); + + connect(browseaddresses_, SIGNAL(add()), SLOT(slotAdd())); + connect(browseaddresses_, SIGNAL(edit(int)), SLOT(slotEdit(int))); + connect(browseaddresses_, SIGNAL(defaultList()), SLOT(slotDefaultList())); + connect(browseinterval_, SIGNAL(valueChanged(int)), SLOT(intervalChanged(int))); + browsing_->setChecked(true); +} + +bool CupsdBrowsingPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + browsing_->setChecked(conf_->browsing_); + cups_->setChecked(conf_->browseprotocols_.findIndex("CUPS") != -1); + slp_->setChecked(conf_->browseprotocols_.findIndex("SLP") != -1); + browseport_->setValue(conf_->browseport_); + browseinterval_->setValue(conf_->browseinterval_); + browsetimeout_->setValue(conf_->browsetimeout_); + browseaddresses_->insertItems(conf_->browseaddresses_); + browseorder_->setCurrentItem(conf_->browseorder_); + useimplicitclasses_->setChecked(conf_->useimplicitclasses_); + useanyclasses_->setChecked(conf_->useanyclasses_); + hideimplicitmembers_->setChecked(conf_->hideimplicitmembers_); + useshortnames_->setChecked(conf_->useshortnames_); + + return true; +} + +bool CupsdBrowsingPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->browsing_ = browsing_->isChecked(); + QStringList l; + if (cups_->isChecked()) l << "CUPS"; + if (slp_->isChecked()) l << "SLP"; + conf->browseprotocols_ = l; + conf->browseport_ = browseport_->value(); + conf->browseinterval_ = browseinterval_->value(); + conf->browsetimeout_ = browsetimeout_->value(); + conf->browseaddresses_ = browseaddresses_->items(); + conf->browseorder_ = browseorder_->currentItem(); + conf->useimplicitclasses_ = useimplicitclasses_->isChecked(); + conf->useanyclasses_ = useanyclasses_->isChecked(); + conf->hideimplicitmembers_ = hideimplicitmembers_->isChecked(); + conf->useshortnames_ = useshortnames_->isChecked(); + + return true; +} + +void CupsdBrowsingPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(browsing_, conf->comments_.toolTip("browsing")); + QWhatsThis::add(cups_, conf->comments_.toolTip("browseprotocols")); + QWhatsThis::add(slp_, conf->comments_.toolTip("browseprotocols")); + QWhatsThis::add(browseinterval_, conf->comments_.toolTip("browseinterval")); + QWhatsThis::add(browseport_, conf->comments_.toolTip("browseport")); + QWhatsThis::add(browsetimeout_, conf->comments_.toolTip("browsetimeout")); + QWhatsThis::add(browseaddresses_, conf->comments_.toolTip("browseaddresses")); + QWhatsThis::add(browseorder_, conf->comments_.toolTip("browseorder")); + QWhatsThis::add(useimplicitclasses_, conf->comments_.toolTip("implicitclasses")); + QWhatsThis::add(useanyclasses_, conf->comments_.toolTip("implicitanyclasses")); + QWhatsThis::add(hideimplicitmembers_, conf->comments_.toolTip("hideimplicitmembers")); + QWhatsThis::add(useshortnames_, conf->comments_.toolTip("browseshortnames")); +} + +void CupsdBrowsingPage::slotAdd() +{ + QString s = BrowseDialog::newAddress(this, conf_); + if (!s.isEmpty()) + browseaddresses_->insertItem(s); +} + +void CupsdBrowsingPage::slotEdit(int index) +{ + QString s = browseaddresses_->text(index); + s = BrowseDialog::editAddress(s, this, conf_); + if (!s.isEmpty()) + browseaddresses_->setText(index, s); +} + +void CupsdBrowsingPage::slotDefaultList() +{ + browseaddresses_->clear(); + QStringList l; + l << "Send 255.255.255.255"; + browseaddresses_->insertItems(l); +} + +void CupsdBrowsingPage::intervalChanged(int val) +{ + browsetimeout_->setRange(val, 10000, 1, true); + browsetimeout_->setSteps(1, 10); +} + +#include "cupsdbrowsingpage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.h b/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.h new file mode 100644 index 000000000..655998a5e --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdbrowsingpage.h @@ -0,0 +1,55 @@ +/* + * 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. + **/ + +#ifndef CUPSDBROWSINGPAGE_H +#define CUPSDBROWSINGPAGE_H + +#include "cupsdpage.h" + +class KIntNumInput; +class QCheckBox; +class EditList; +class QComboBox; + +class CupsdBrowsingPage : public CupsdPage +{ + Q_OBJECT + +public: + CupsdBrowsingPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +protected slots: + void slotAdd(); + void slotEdit(int); + void slotDefaultList(); + void intervalChanged(int); + +private: + KIntNumInput *browseport_, *browseinterval_, *browsetimeout_; + EditList *browseaddresses_; + QComboBox *browseorder_; + QCheckBox *browsing_, *cups_, *slp_; + QCheckBox *useimplicitclasses_, *hideimplicitmembers_, *useshortnames_, *useanyclasses_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdcomment.cpp b/kdeprint/cups/cupsdconf2/cupsdcomment.cpp new file mode 100644 index 000000000..d49a104a3 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdcomment.cpp @@ -0,0 +1,136 @@ +/* + * 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 "cupsdcomment.h" + +#include <qfile.h> +#include <qregexp.h> +#include <klocale.h> +#include <kstandarddirs.h> + +QString Comment::comment() +{ + QString str = comment_; + str.replace(QRegExp("<[^>]*>"), ""); + str += ("#\n" + example_); + return str; +} + +QString Comment::toolTip() +{ + QString str = comment_; + str.replace(QRegExp("^#[\\s]*"), "").replace(QRegExp("\n#[\\s]*"), "\n"); + return i18n("Do not translate the keyword between brackets (e.g. ServerName, ServerAdmin, etc.)", str.utf8()); +} + +QString Comment::key() +{ + return key_; +} + +bool Comment::load(QFile *f) +{ + comment_ = ""; + example_ = ""; + key_ = ""; + QString line, *current = &comment_; + while (!f->atEnd()) + { + f->readLine(line, 1024); + if (line.left(2) == "$$") + { + current = &example_; + } + else if (line.left(2) == "%%") + { + key_ = line.mid(2).stripWhiteSpace(); + } + else if (line.left(2) == "@@") + { + return true; + } + else if (line.stripWhiteSpace().isEmpty()) + { + ; // do nothing + } + else + { + if (line[0] != '#') break; + else + { + current->append(line); + } + } + } + return false; +} + +//------------------------------------------------------------------------------------------------------------ + +QString CupsdComment::operator[] (const QString& key) +{ + return comment(key); +} + +QString CupsdComment::comment(const QString& key) +{ + if (comments_.count() != 0 || loadComments()) + { + Comment *comm = comments_.find(key); + if (comm) + return comm->comment(); + } + return QString::null; +} + +QString CupsdComment::toolTip(const QString& key) +{ + if (comments_.count() != 0 || loadComments()) + { + Comment *comm = comments_.find(key); + if (comm) + return comm->toolTip(); + } + return QString::null; +} + +bool CupsdComment::loadComments() +{ + comments_.setAutoDelete(true); + comments_.clear(); + QFile f(locate("data", "kdeprint/cupsd.conf.template")); + if (f.exists() && f.open(IO_ReadOnly)) + { + Comment *comm; + while (!f.atEnd()) + { + comm = new Comment(); + if (!comm->load(&f)) + break; + else + { + if (comm->key().isEmpty()) + delete comm; + else + comments_.insert(comm->key(), comm); + } + } + } + return true; +} diff --git a/kdeprint/cups/cupsdconf2/cupsdcomment.h b/kdeprint/cups/cupsdconf2/cupsdcomment.h new file mode 100644 index 000000000..efe242765 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdcomment.h @@ -0,0 +1,55 @@ +/* + * 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. + **/ + +#ifndef CUPSDCOMMENT_H +#define CUPSDCOMMENT_H + +#include <qstringlist.h> +#include <qdict.h> + +class QFile; + +class Comment +{ +public: + bool load(QFile* f); + QString toolTip(); + QString comment(); + QString key(); +private: + QString comment_; + QString example_; + QString key_; +}; + +class CupsdComment +{ +public: + QString operator[] (const QString& key); + QString comment(const QString& key); + QString toolTip(const QString& key); + +private: + bool loadComments(); + +private: + QDict<Comment> comments_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdcomment.pl b/kdeprint/cups/cupsdconf2/cupsdcomment.pl new file mode 100644 index 000000000..b3da5ee7e --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdcomment.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl -w +# +# Filter to extract comments for translation from cupsd.conf.template +# +# This code should produce strings identical to tooltips in cupsdcomment.cpp +# +my ($comment_, $example_); +$example_ = ""; + +load(); # Skip header + +while ( <STDIN> ) +{ + if(load()) + { + print toolTip(); + } +} + +# Corresponds to Comment::load in cupsdcomment.cpp +sub load +{ + $comment_ = ""; + my($current) = \$comment_; + while ( <STDIN> ) + { + if (/^\$\$/) + { + $current = \$example_; + } + elsif (/^\%\%/) + { + next; # Do nothing + } + elsif (/^\@\@/) + { + return 1; + } + elsif (/^[\s]*$/) + { + next; # Do nothing + } + else + { + last if (!/^\#/); + ${$current} = ${$current} . $_; + } + } + return 0; +} + +# Corresponds to Comment::toolTip in cupsdcomment.cpp +sub toolTip +{ + my($str) = $comment_; + $str =~ s/\"/\\\"/g; + $str =~ s/^\#[\s]*/i18n\(\"Do not translate the keyword between brackets \(e\.g\. ServerName, ServerAdmin, etc\.\)\",\"/; + $str =~ s/\n\#[\s]*/\\n\"\n\"/g; + $str =~ s/\n$/\\n\"\n\)\;\n\n/; + return $str; +} diff --git a/kdeprint/cups/cupsdconf2/cupsdconf.cpp b/kdeprint/cups/cupsdconf2/cupsdconf.cpp new file mode 100644 index 000000000..4018ab2fb --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdconf.cpp @@ -0,0 +1,884 @@ +/* + * 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 <config.h> +#include "cupsdconf.h" + +#include <qfile.h> +#include <qregexp.h> +#include <klocale.h> +#include <kdebug.h> +#include <kconfig.h> + +#include <stdlib.h> +#include <cups/cups.h> +#include <cups/ipp.h> +#include <cups/language.h> + +QString findDir(const QStringList& list) +{ + for (QStringList::ConstIterator it=list.begin(); it!=list.end(); ++it) + if (QFile::exists(*it)) + return *it; + // if nothing found, just use the first as default value + return list[0]; +} + +void splitSizeSpec(const QString& s, int& sz, int& suff) +{ + int p = s.find(QRegExp("\\D")); + sz = s.mid(0, p).toInt(); + if (p != -1) + { + switch (s[p].latin1()) + { + case 'k': suff = UNIT_KB; break; + default: + case 'm': suff = UNIT_MB; break; + case 'g': suff = UNIT_GB; break; + case 't': suff = UNIT_TILE; break; + } + } + else + suff = UNIT_MB; +} + +CupsdConf::CupsdConf() +{ + // start by trying to find CUPS directories (useful later) + datadir_ = findDir(QStringList("/usr/share/cups") + << "/usr/local/share/cups" + << "/opt/share/cups" + << "/opt/local/share/cups"); + documentdir_ = findDir(QStringList(datadir_+"/doc") + << datadir_.left(datadir_.length()-5)+"/doc/cups"); + //fontpath_ << (datadir_+"/fonts"); + requestdir_ = findDir(QStringList("/var/spool/cups") + << "/var/cups"); + serverbin_ = findDir(QStringList("/usr/lib" KDELIBSUFF "/cups") + << "/usr/local/lib" KDELIBSUFF "/cups" + << "/opt/lib" KDELIBSUFF "/cups" + << "/opt/local/lib" KDELIBSUFF "/cups"); + serverfiles_ = findDir(QStringList("/etc/cups") + << "/usr/local/etc/cups"); + tmpfiles_ = requestdir_+"/tmp"; + + // other options + servername_ = QString::null; + serveradmin_ = QString::null; + classification_ = CLASS_NONE; + otherclassname_ = QString::null; + classoverride_ = false; + charset_ = "utf-8"; + language_ = "en"; + printcap_ = "/etc/printcap"; + printcapformat_ = PRINTCAP_BSD; + remoteroot_ = "remroot"; + systemgroup_ = "sys"; + encryptcert_ = serverfiles_+"/ssl/server.crt"; + encryptkey_ = serverfiles_+"/ssl/server.key"; + hostnamelookup_ = HOSTNAME_OFF; + keepalive_ = true; + keepalivetimeout_ = 60; + maxclients_ = 100; + maxrequestsize_ = "0"; + clienttimeout_ = 300; + // listenaddresses_ + QString logdir = findDir(QStringList("/var/log/cups") + << "/var/spool/cups/log" + << "/var/cups/log"); + accesslog_ = logdir+"/access_log"; + errorlog_ = logdir+"/error_log"; + pagelog_ = logdir+"/page_log"; + maxlogsize_ = "1m"; + loglevel_ = LOGLEVEL_INFO; + keepjobhistory_ = true; + keepjobfiles_ = false; + autopurgejobs_ = false; + maxjobs_ = 0; + maxjobsperprinter_ = 0; + maxjobsperuser_ = 0; + user_ = "lp"; + group_ = "sys"; + ripcache_ = "8m"; + filterlimit_ = 0; + browsing_ = true; + browseprotocols_ << "CUPS"; + browseport_ = ippPort(); + browseinterval_ = 30; + browsetimeout_ = 300; + // browseaddresses_ + browseorder_ = ORDER_ALLOW_DENY; + useimplicitclasses_ = true; + hideimplicitmembers_ = true; + useshortnames_ = true; + useanyclasses_ = false; + + loadAvailableResources(); +} + +CupsdConf::~CupsdConf() +{ +} + +bool CupsdConf::loadFromFile(const QString& filename) +{ + QFile f(filename); + if (!f.exists() || !f.open(IO_ReadOnly)) return false; + else + { + QTextStream t(&f); + QString line; + bool done(false), value(true); + while (!done && value) + { + line = t.readLine().simplifyWhiteSpace(); + if (line.isEmpty()) + { + if (t.atEnd()) done = true; + else continue; + } + else if (line[0] == '#') continue; + else if (line.left(9).lower() == "<location") + { + CupsLocation *location = new CupsLocation(); + locations_.append(location); + if (!location->parseResource(line) || !parseLocation(location, t)) + value = false; + // search corresponding resource + for (resources_.first();resources_.current();resources_.next()) + if (resources_.current()->path_ == location->resourcename_) + location->resource_ = resources_.current(); + } + else value = parseOption(line); + } + f.close(); + return value; + } +} + +bool CupsdConf::saveToFile(const QString& filename) +{ + QFile f(filename); + if (!f.open(IO_WriteOnly)) + return false; + else + { + QTextStream t(&f); + t << comments_["header"] << endl; + t << "# Server" << endl << endl; + + t << comments_["servername"] << endl; + if ( !servername_.isEmpty() ) + t << "ServerName " << servername_ << endl; + + t << endl << comments_["serveradmin"] << endl; + if ( !serveradmin_.isEmpty() ) + t << "ServerAdmin " << serveradmin_ << endl; + + t << endl << comments_["classification"] << endl; + t << "Classification "; + switch (classification_) + { + default: + case CLASS_NONE: t << "none"; break; + case CLASS_CLASSIFIED: t << "classified"; break; + case CLASS_CONFIDENTIAL: t << "confidential"; break; + case CLASS_SECRET: t << "secret"; break; + case CLASS_TOPSECRET: t << "topsecret"; break; + case CLASS_UNCLASSIFIED: t << "unclassified"; break; + case CLASS_OTHER: t << otherclassname_; break; + } + t << endl; + + t << endl << comments_["classifyoverride"] << endl; + if (classification_ != CLASS_NONE) t << "ClassifyOverride " << (classoverride_ ? "Yes" : "No") << endl; + + t << endl << comments_["defaultcharset"] << endl; + t << "DefaultCharset " << charset_.upper() << endl; + + t << endl << comments_["defaultlanguage"] << endl; + t << "DefaultLanguage " << language_.lower() << endl; + + t << endl << comments_["printcap"] << endl; + t << "Printcap " << printcap_ << endl; + + t << endl << comments_["printcapformat"] << endl; + t << "PrintcapFormat " << (printcapformat_ == PRINTCAP_SOLARIS ? "Solaris" : "BSD") << endl; + + t << endl << "# Security" << endl; + t << endl << comments_["remoteroot"] << endl; + t << "RemoteRoot " << remoteroot_ << endl; + + t << endl << comments_["systemgroup"] << endl; + t << "SystemGroup " << systemgroup_ << endl; + + t << endl << comments_["servercertificate"] << endl; + t << "ServerCertificate " << encryptcert_ << endl; + + t << endl << comments_["serverkey"] << endl; + t << "ServerKey " << encryptkey_ << endl; + + t << endl << comments_["locations"] << endl; + for (locations_.first(); locations_.current(); locations_.next()) + { + CupsLocation *loc = locations_.current(); + t << "<Location " << loc->resourcename_ << ">" << endl; + if (loc->authtype_ != AUTHTYPE_NONE) + { + t << "AuthType "; + switch (loc->authtype_) + { + case AUTHTYPE_BASIC: t << "Basic"; break; + case AUTHTYPE_DIGEST: t << "Digest"; break; + } + t << endl; + } + if (loc->authclass_ != AUTHCLASS_ANONYMOUS) + { + switch (loc->authclass_) + { + case AUTHCLASS_USER: + if (!loc->authname_.isEmpty()) + t << "Require user " << loc->authname_ << endl; + else + t << "AuthClass User" << endl; + break; + case AUTHCLASS_GROUP: + if (!loc->authname_.isEmpty()) + t << "Require group " << loc->authname_ << endl; + else + t << "AuthClass Group" << endl; + break; + case AUTHCLASS_SYSTEM: + t << "AuthClass System" << endl; + break; + } + } + t << "Encryption "; + switch (loc->encryption_) + { + case ENCRYPT_ALWAYS: t << "Always"; break; + case ENCRYPT_NEVER: t << "Never"; break; + case ENCRYPT_REQUIRED: t << "Required"; break; + default: + case ENCRYPT_IFREQUESTED: t << "IfRequested"; break; + } + t << endl; + t << "Satisfy " << (loc->satisfy_ == SATISFY_ALL ? "All" : "Any") << endl; + t << "Order " << (loc->order_ == ORDER_ALLOW_DENY ? "allow,deny" : "deny,allow") << endl; + for (QStringList::ConstIterator it=loc->addresses_.begin(); it!=loc->addresses_.end(); ++it) + t << *it << endl; + t << "</Location>" << endl; + } + + t << endl << "# Network" << endl; + t << endl << comments_["hostnamelookups"] << endl; + t << "HostnameLookups "; + switch (hostnamelookup_) + { + default: + case HOSTNAME_OFF: t << "Off"; break; + case HOSTNAME_ON: t << "On"; break; + case HOSTNAME_DOUBLE: t << "Double"; break; + } + t << endl; + + t << endl << comments_["keepalive"] << endl; + t << "KeepAlive " << (keepalive_ ? "On" : "Off") << endl; + + t << endl << comments_["keepalivetimeout"] << endl; + t << "KeepAliveTimeout " << keepalivetimeout_ << endl; + + t << endl << comments_["maxclients"] << endl; + t << "MaxClients " << maxclients_ << endl; + + t << endl << comments_["maxrequestsize"] << endl; + t << "MaxRequestSize " << maxrequestsize_ << endl; + + t << endl << comments_["timeout"] << endl; + t << "Timeout " << clienttimeout_ << endl; + + t << endl << comments_["listen"] << endl; + for (QStringList::ConstIterator it=listenaddresses_.begin(); it!=listenaddresses_.end(); ++it) + t << *it << endl; + + t << endl << "# Log" << endl; + t << endl << comments_["accesslog"] << endl; + t << "AccessLog " << accesslog_ << endl; + + t << endl << comments_["errorlog"] << endl; + t << "ErrorLog " << errorlog_ << endl; + + t << endl << comments_["pagelog"] << endl; + t << "PageLog " << pagelog_ << endl; + + t << endl << comments_["maxlogsize"] << endl; + //t << "MaxLogSize " << maxlogsize_ << "m" << endl; + t << "MaxLogSize " << maxlogsize_ << endl; + + t << endl << comments_["loglevel"] << endl; + t << "LogLevel "; + switch (loglevel_) + { + case LOGLEVEL_NONE: t << "none"; break; + default: + case LOGLEVEL_INFO: t << "info"; break; + case LOGLEVEL_ERROR: t << "error"; break; + case LOGLEVEL_WARN: t << "warn"; break; + case LOGLEVEL_DEBUG: t << "debug"; break; + case LOGLEVEL_DEBUG2: t << "debug2"; break; + } + t << endl; + + t << endl << "# Jobs" << endl; + t << endl << comments_["preservejobhistory"] << endl; + t << "PreserveJobHistory " << (keepjobhistory_ ? "On" : "Off") << endl; + + t << endl << comments_["preservejobfiles"] << endl; + if (keepjobhistory_) t << "PreserveJobFiles " << (keepjobfiles_ ? "On" : "Off") << endl; + + t << endl << comments_["autopurgejobs"] << endl; + if (keepjobhistory_) t << "AutoPurgeJobs " << (autopurgejobs_ ? "Yes" : "No") << endl; + + t << endl << comments_["maxjobs"] << endl; + t << "MaxJobs " << maxjobs_ << endl; + + t << endl << comments_["maxjobsperprinter"] << endl; + t << "MaxJobsPerPrinter " << maxjobsperprinter_ << endl; + + t << endl << comments_["maxjobsperuser"] << endl; + t << "MaxJobsPerUser " << maxjobsperuser_ << endl; + + t << endl << "# Filter" << endl; + t << endl << comments_["user"] << endl; + t << "User " << user_ << endl; + + t << endl << comments_["group"] << endl; + t << "Group " << group_ << endl; + + t << endl << comments_["ripcache"] << endl; + t << "RIPCache " << ripcache_ << endl; + + t << endl << comments_["filterlimit"] << endl; + t << "FilterLimit " << filterlimit_ << endl; + + t << endl << "# Directories" << endl; + t << endl << comments_["datadir"] << endl; + t << "DataDir " << datadir_ << endl; + + t << endl << comments_["documentroot"] << endl; + t << "DocumentRoot " << documentdir_ << endl; + + t << endl << comments_["fontpath"] << endl; + for (QStringList::ConstIterator it=fontpath_.begin(); it!=fontpath_.end(); ++it) + t << "FontPath " << *it << endl; + + t << endl << comments_["requestroot"] << endl; + t << "RequestRoot " << requestdir_ << endl; + + t << endl << comments_["serverbin"] << endl; + t << "ServerBin " << serverbin_ << endl; + + t << endl << comments_["serverroot"] << endl; + t << "ServerRoot " << serverfiles_ << endl; + + t << endl << comments_["tempdir"] << endl; + t << "TempDir " << tmpfiles_ << endl; + + t << endl << "# Browsing" << endl; + t << endl << comments_["browsing"] << endl; + t << "Browsing " << (browsing_ ? "On" : "Off") << endl; + + t << endl << comments_["browseprotocols"] << endl; + if (browsing_) + { + t << "BrowseProtocols "; + for (QStringList::ConstIterator it=browseprotocols_.begin(); it!=browseprotocols_.end(); ++it) + t << (*it).upper() << " "; + t << endl; + } + + t << endl << comments_["browseport"] << endl; + if (browsing_) t << "BrowsePort " << browseport_ << endl; + + t << endl << comments_["browseinterval"] << endl; + if (browsing_) t << "BrowseInterval " << browseinterval_ << endl; + + t << endl << comments_["browsetimeout"] << endl; + if (browsing_) t << "BrowseTimeout " << browsetimeout_ << endl; + + t << endl << comments_["browseaddress"] << endl; + if (browsing_) + for (QStringList::ConstIterator it=browseaddresses_.begin(); it!=browseaddresses_.end(); ++it) + if ((*it).startsWith("Send")) + t << "BrowseAddress " << (*it).mid(5) << endl; + else + t << "Browse" << (*it) << endl; + + t << endl << comments_["browseorder"] << endl; + if (browsing_) t << "BrowseOrder " << (browseorder_ == ORDER_ALLOW_DENY ? "allow,deny" : "deny,allow") << endl; + + t << endl << comments_["implicitclasses"] << endl; + if (browsing_) t << "ImplicitClasses " << (useimplicitclasses_ ? "On" : "Off") << endl; + + t << endl << comments_["implicitanyclasses"] << endl; + if (browsing_) t << "ImplicitAnyClasses " << (useanyclasses_ ? "On" : "Off") << endl; + + t << endl << comments_["hideimplicitmembers"] << endl; + if (browsing_) t << "HideImplicitMembers " << (hideimplicitmembers_ ? "Yes" : "No") << endl; + + t << endl << comments_["browseshortnames"] << endl; + if (browsing_) t << "BrowseShortNames " << (useshortnames_ ? "Yes" : "No") << endl; + + t << endl << "# Unknown" << endl; + for (QValueList< QPair<QString,QString> >::ConstIterator it=unknown_.begin(); it!=unknown_.end(); ++it) + t << (*it).first << " " << (*it).second << endl; + + return true; + } +} + +bool CupsdConf::parseLocation(CupsLocation *location, QTextStream& file) +{ + QString line; + bool done(false); + bool value(true); + while (!done && value) + { + line = file.readLine().simplifyWhiteSpace(); + if (line.isEmpty()) + { + if (file.atEnd()) + { + value = false; + done = true; + } + else continue; + } + else if (line[0] == '#') continue; + else if (line.lower() == "</location>") done = true; + else value = location->parseOption(line); + } + return value; +} + +bool CupsdConf::parseOption(const QString& line) +{ + int p(-1); + QString keyword, value, l(line.simplifyWhiteSpace()); + + if ((p=l.find(' ')) != -1) + { + keyword = l.left(p).lower(); + value = l.mid(p+1); + } + else + { + keyword = l.lower(); + } + + //kdDebug() << "cupsd.conf keyword=" << keyword << endl; + if (keyword == "accesslog") accesslog_ = value; + else if (keyword == "autopurgejobs") autopurgejobs_ = (value.lower() == "yes"); + else if (keyword == "browseaddress") browseaddresses_.append("Send "+value); + else if (keyword == "browseallow") browseaddresses_.append("Allow "+value); + else if (keyword == "browsedeny") browseaddresses_.append("Deny "+value); + else if (keyword == "browseinterval") browseinterval_ = value.toInt(); + else if (keyword == "browseorder") browseorder_ = (value.lower() == "deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY); + else if (keyword == "browsepoll") browseaddresses_.append("Poll "+value); + else if (keyword == "browseport") browseport_ = value.toInt(); + else if (keyword == "browseprotocols") + { + browseprotocols_.clear(); + QStringList prots = QStringList::split(QRegExp("\\s"), value, false); + if (prots.find("all") != prots.end()) + browseprotocols_ << "CUPS" << "SLP"; + else + for (QStringList::ConstIterator it=prots.begin(); it!=prots.end(); ++it) + browseprotocols_ << (*it).upper(); + } + else if (keyword == "browserelay") browseaddresses_.append("Relay "+value); + else if (keyword == "browseshortnames") useshortnames_ = (value.lower() != "no"); + else if (keyword == "browsetimeout") browsetimeout_ = value.toInt(); + else if (keyword == "browsing") browsing_ = (value.lower() != "off"); + else if (keyword == "classification") + { + QString cl = value.lower(); + if (cl == "none") classification_ = CLASS_NONE; + else if (cl == "classified") classification_ = CLASS_CLASSIFIED; + else if (cl == "confidential") classification_ = CLASS_CONFIDENTIAL; + else if (cl == "secret") classification_ = CLASS_SECRET; + else if (cl == "topsecret") classification_ = CLASS_TOPSECRET; + else if (cl == "unclassified") classification_ = CLASS_UNCLASSIFIED; + else + { + classification_ = CLASS_OTHER; + otherclassname_ = cl; + } + } + else if (keyword == "classifyoverride") classoverride_ = (value.lower() == "yes"); + else if (keyword == "datadir") datadir_ = value; + else if (keyword == "defaultcharset") charset_ = value; + else if (keyword == "defaultlanguage") language_ = value; + else if (keyword == "documentroot") documentdir_ = value; + else if (keyword == "errorlog") errorlog_ = value; + else if (keyword == "filterlimit") filterlimit_ = value.toInt(); + else if (keyword == "fontpath") fontpath_ += QStringList::split(':', value, false); + else if (keyword == "group") group_ = value; + else if (keyword == "hideimplicitmembers") hideimplicitmembers_ = (value.lower() != "no"); + else if (keyword == "hostnamelookups") + { + QString h = value.lower(); + if (h == "on") hostnamelookup_ = HOSTNAME_ON; + else if (h == "double") hostnamelookup_ = HOSTNAME_DOUBLE; + else hostnamelookup_ = HOSTNAME_OFF; + } + else if (keyword == "implicitclasses") useimplicitclasses_ = (value.lower() != "off"); + else if (keyword == "implicitanyclasses") useanyclasses_ = (value.lower() == "on"); + else if (keyword == "keepalive") keepalive_ = (value.lower() != "off"); + else if (keyword == "keepalivetimeout") keepalivetimeout_ = value.toInt(); + else if (keyword == "listen") listenaddresses_.append("Listen "+value); + else if (keyword == "loglevel") + { + QString ll = value.lower(); + if (ll == "none") loglevel_ = LOGLEVEL_NONE; + else if (ll == "error") loglevel_ = LOGLEVEL_ERROR; + else if (ll == "warn") loglevel_ = LOGLEVEL_WARN; + else if (ll == "info") loglevel_ = LOGLEVEL_INFO; + else if (ll == "debug") loglevel_ = LOGLEVEL_DEBUG; + else if (ll == "debug2") loglevel_ = LOGLEVEL_DEBUG2; + } + else if (keyword == "maxclients") maxclients_ = value.toInt(); + else if (keyword == "maxjobs") maxjobs_ = value.toInt(); + else if (keyword == "maxjobsperprinter") maxjobsperprinter_ = value.toInt(); + else if (keyword == "maxjobsperuser") maxjobsperuser_ = value.toInt(); + else if (keyword == "maxrequestsize") maxrequestsize_ = value; + else if (keyword == "maxlogsize") maxlogsize_ = value; + /*{ + // FIXME: support for suffixes + int suffix; + splitSizeSpec( value, maxlogsize_, suffix ); + }*/ + else if (keyword == "pagelog") pagelog_ = value; + else if (keyword == "port") listenaddresses_.append("Listen *:"+value); + else if (keyword == "preservejobhistory") keepjobhistory_ = (value != "off"); + else if (keyword == "preservejobfiles") keepjobfiles_ = (value == "on"); + else if (keyword == "printcap") printcap_ = value; + else if (keyword == "printcapformat") printcapformat_ = (value.lower() == "solaris" ? PRINTCAP_SOLARIS : PRINTCAP_BSD); + else if (keyword == "requestroot") requestdir_ = value; + else if (keyword == "remoteroot") remoteroot_ = value; + else if (keyword == "ripcache") ripcache_ = value; + else if (keyword == "serveradmin") serveradmin_ = value; + else if (keyword == "serverbin") serverbin_ = value; + else if (keyword == "servercertificate") encryptcert_ = value; + else if (keyword == "serverkey") encryptkey_ = value; + else if (keyword == "servername") servername_ = value; + else if (keyword == "serverroot") serverfiles_ = value; + else if (keyword == "ssllisten") listenaddresses_.append("SSLListen "+value); + else if (keyword == "sslport") listenaddresses_.append("SSLListen *:"+value); + else if (keyword == "systemgroup") systemgroup_ = value; + else if (keyword == "tempdir") tmpfiles_ = value; + else if (keyword == "timeout") clienttimeout_ = value.toInt(); + else if (keyword == "user") user_ = value; + else + { + // unrecognized option + unknown_ << QPair<QString,QString>(keyword, value); + } + return true; +} + +bool CupsdConf::loadAvailableResources() +{ + KConfig conf("kdeprintrc"); + conf.setGroup("CUPS"); + QString host = conf.readEntry("Host",cupsServer()); + int port = conf.readNumEntry("Port",ippPort()); + http_t *http_ = httpConnect(host.local8Bit(),port); + + resources_.clear(); + // standard resources + resources_.append(new CupsResource("/")); + resources_.append(new CupsResource("/admin")); + resources_.append(new CupsResource("/printers")); + resources_.append(new CupsResource("/classes")); + resources_.append(new CupsResource("/jobs")); + + if (!http_) + return false; + + // printer resources + ipp_t *request_ = ippNew(); + cups_lang_t* lang = cupsLangDefault(); + ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(lang)); + ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, lang->language); + request_->request.op.operation_id = CUPS_GET_PRINTERS; + request_ = cupsDoRequest(http_, request_, "/printers/"); + if (request_) + { + QString name; + int type(0); + ipp_attribute_t *attr = request_->attrs; + while (attr) + { + // check new printer (keep only local non-implicit printers) + if (!attr->name) + { + if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty()) + resources_.append(new CupsResource("/printers/"+name)); + name = ""; + type = 0; + } + else if (strcmp(attr->name, "printer-name") == 0) name = attr->values[0].string.text; + else if (strcmp(attr->name, "printer-type") == 0) type = attr->values[0].integer; + attr = attr->next; + } + if (!(type & CUPS_PRINTER_REMOTE) && !(type & CUPS_PRINTER_IMPLICIT) && !name.isEmpty()) + resources_.append(new CupsResource("/printers/"+name)); + ippDelete(request_); + } + // class resources + request_ = ippNew(); + ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_CHARSET, "attributes-charset", NULL, cupsLangEncoding(lang)); + ippAddString(request_, IPP_TAG_OPERATION, IPP_TAG_LANGUAGE, "attributes-natural-language", NULL, lang->language); + request_->request.op.operation_id = CUPS_GET_CLASSES; + request_ = cupsDoRequest(http_, request_, "/classes/"); + if (request_) + { + QString name; + int type(0); + ipp_attribute_t *attr = request_->attrs; + while (attr) + { + // check new class (keep only local classes) + if (!attr->name) + { + if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty()) + resources_.append(new CupsResource("/classes/"+name)); + name = ""; + type = 0; + } + else if (strcmp(attr->name, "printer-name") == 0) name = attr->values[0].string.text; + else if (strcmp(attr->name, "printer-type") == 0) type = attr->values[0].integer; + attr = attr->next; + } + if (!(type & CUPS_PRINTER_REMOTE) && !name.isEmpty()) + resources_.append(new CupsResource("/classes/"+name)); + ippDelete(request_); + } + httpClose(http_); + return true; +} + +//------------------------------------------------------------------------------------------------ + +CupsLocation::CupsLocation() +{ + resource_ = 0; + resourcename_ = ""; + authtype_ = AUTHTYPE_NONE; + authclass_ = AUTHCLASS_ANONYMOUS; + authname_ = QString::null; + encryption_ = ENCRYPT_IFREQUESTED; + satisfy_ = SATISFY_ALL; + order_ = ORDER_ALLOW_DENY; + // addresses_ +} + +CupsLocation::CupsLocation(const CupsLocation& loc) +: resource_(loc.resource_), + resourcename_(loc.resourcename_), + authtype_(loc.authtype_), + authclass_(loc.authclass_), + authname_(loc.authname_), + encryption_(loc.encryption_), + satisfy_(loc.satisfy_), + order_(loc.order_), + addresses_(loc.addresses_) +{ +} + +bool CupsLocation::parseResource(const QString& line) +{ + QString str = line.simplifyWhiteSpace(); + int p1 = line.find(' '), p2 = line.find('>'); + if (p1 != -1 && p2 != -1) + { + resourcename_ = str.mid(p1+1,p2-p1-1); + return true; + } + else return false; +} + +bool CupsLocation::parseOption(const QString& line) +{ + int p(-1); + QString keyword, value, l(line.simplifyWhiteSpace()); + + if ((p=l.find(' ')) != -1) + { + keyword = l.left(p).lower(); + value = l.mid(p+1); + } + else + { + keyword = l.lower(); + } + + if (keyword == "authtype") + { + QString a = value.lower(); + if (a == "basic") authtype_ = AUTHTYPE_BASIC; + else if (a == "digest") authtype_ = AUTHTYPE_DIGEST; + else authtype_ = AUTHTYPE_NONE; + } + else if (keyword == "authclass") + { + QString a = value.lower(); + if (a == "user") authclass_ = AUTHCLASS_USER; + else if (a == "system") authclass_ = AUTHCLASS_SYSTEM; + else if (a == "group") authclass_ = AUTHCLASS_GROUP; + else authclass_ = AUTHCLASS_ANONYMOUS; + } + else if (keyword == "authgroupname") authname_ = value; + else if (keyword == "require") + { + int p = value.find(' '); + if (p != -1) + { + authname_ = value.mid(p+1); + QString cl = value.left(p).lower(); + if (cl == "user") + authclass_ = AUTHCLASS_USER; + else if (cl == "group") + authclass_ = AUTHCLASS_GROUP; + } + } + else if (keyword == "allow") addresses_.append("Allow "+value); + else if (keyword == "deny") addresses_.append("Deny "+value); + else if (keyword == "order") order_ = (value.lower() == "deny,allow" ? ORDER_DENY_ALLOW : ORDER_ALLOW_DENY); + else if (keyword == "encryption") + { + QString e = value.lower(); + if (e == "always") encryption_ = ENCRYPT_ALWAYS; + else if (e == "never") encryption_ = ENCRYPT_NEVER; + else if (e == "required") encryption_ = ENCRYPT_REQUIRED; + else encryption_ = ENCRYPT_IFREQUESTED; + } + else if (keyword == "satisfy") satisfy_ = (value.lower() == "any" ? SATISFY_ANY : SATISFY_ALL); + else return false; + return true; +} + +//------------------------------------------------------------------------------------------------ + +CupsResource::CupsResource() +{ + type_ = RESOURCE_GLOBAL; +} + +CupsResource::CupsResource(const QString& path) +{ + setPath(path); +} + +void CupsResource::setPath(const QString& path) +{ + path_ = path; + type_ = typeFromPath(path_); + text_ = pathToText(path_); +} + +int CupsResource::typeFromText(const QString& text) +{ + if (text == i18n("Base", "Root") || text == i18n("All printers") || text == i18n("All classes") || text == i18n("Print jobs")) return RESOURCE_GLOBAL; + else if (text == i18n("Administration")) return RESOURCE_ADMIN; + else if (text.find(i18n("Class")) == 0) return RESOURCE_CLASS; + else if (text.find(i18n("Printer")) == 0) return RESOURCE_PRINTER; + else return RESOURCE_PRINTER; +} + +int CupsResource::typeFromPath(const QString& path) +{ + if (path == "/admin") return RESOURCE_ADMIN; + else if (path == "/printers" || path == "/classes" || path == "/" || path == "/jobs") return RESOURCE_GLOBAL; + else if (path.left(9) == "/printers") return RESOURCE_PRINTER; + else if (path.left(8) == "/classes") return RESOURCE_CLASS; + else return RESOURCE_GLOBAL; +} + +QString CupsResource::textToPath(const QString& text) +{ + QString path("/"); + if (text == i18n("Administration")) path = "/admin"; + else if (text == i18n("All printers")) path = "/printers"; + else if (text == i18n("All classes")) path = "/classes"; + else if (text == i18n("Print jobs")) path = "/jobs"; + else if (text == i18n("Base", "Root")) path = "/"; + else if (text.find(i18n("Printer")) == 0) + { + path = "/printers/"; + path.append(text.right(text.length()-i18n("Printer").length()-1)); + } + else if (text.find(i18n("Class")) == 0) + { + path = "/classes/"; + path.append(text.right(text.length()-i18n("Class").length()-1)); + } + return path; +} + +QString CupsResource::pathToText(const QString& path) +{ + QString text(i18n("Base", "Root")); + if (path == "/admin") text = i18n("Administration"); + else if (path == "/printers") text = i18n("All printers"); + else if (path == "/classes") text = i18n("All classes"); + else if (path == "/") text = i18n("Root"); + else if (path == "/jobs") text = i18n("Print jobs"); + else if (path.find("/printers/") == 0) + { + text = i18n("Printer"); + text.append(" "); + text.append(path.right(path.length()-10)); + } + else if (path.find("/classes/") == 0) + { + text = i18n("Class"); + text.append(" "); + text.append(path.right(path.length()-9)); + } + return text; +} + +QString CupsResource::typeToIconName(int type) +{ + switch (type) + { + case RESOURCE_ADMIN: + case RESOURCE_GLOBAL: + return QString("folder"); + case RESOURCE_PRINTER: + return QString("kdeprint_printer"); + case RESOURCE_CLASS: + return QString("kdeprint_printer_class"); + } + return QString("folder"); +} diff --git a/kdeprint/cups/cupsdconf2/cupsdconf.h b/kdeprint/cups/cupsdconf2/cupsdconf.h new file mode 100644 index 000000000..3c53c5390 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdconf.h @@ -0,0 +1,181 @@ +/* + * 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. + **/ + +#ifndef CUPSDCONF_H +#define CUPSDCONF_H + +#include <qstring.h> +#include <qstringlist.h> +#include <qptrlist.h> +#include <qtextstream.h> +#include <qpair.h> + +#include "cupsdcomment.h" + +enum LogLevelType { LOGLEVEL_DEBUG2 = 0, LOGLEVEL_DEBUG, LOGLEVEL_INFO, LOGLEVEL_WARN, LOGLEVEL_ERROR, LOGLEVEL_NONE }; +enum OrderType { ORDER_ALLOW_DENY = 0, ORDER_DENY_ALLOW }; +enum AuthTypeType { AUTHTYPE_NONE = 0, AUTHTYPE_BASIC, AUTHTYPE_DIGEST }; +enum AuthClassType { AUTHCLASS_ANONYMOUS = 0, AUTHCLASS_USER, AUTHCLASS_SYSTEM, AUTHCLASS_GROUP }; +enum EncryptionType { ENCRYPT_ALWAYS = 0, ENCRYPT_NEVER, ENCRYPT_REQUIRED, ENCRYPT_IFREQUESTED }; +enum BrowseProtocolType { BROWSE_ALL = 0, BROWSE_CUPS, BROWSE_SLP }; +enum PrintcapFormatType { PRINTCAP_BSD = 0, PRINTCAP_SOLARIS }; +enum HostnameLookupType { HOSTNAME_OFF = 0, HOSTNAME_ON, HOSTNAME_DOUBLE }; +enum ClassificationType { CLASS_NONE = 0, CLASS_CLASSIFIED, CLASS_CONFIDENTIAL, CLASS_SECRET, CLASS_TOPSECRET, CLASS_UNCLASSIFIED, CLASS_OTHER }; +enum SatisfyType { SATISFY_ALL = 0, SATISFY_ANY }; +enum UnitType { UNIT_KB = 0, UNIT_MB, UNIT_GB, UNIT_TILE }; + +struct CupsLocation; +struct CupsResource; +enum ResourceType { RESOURCE_GLOBAL, RESOURCE_PRINTER, RESOURCE_CLASS, RESOURCE_ADMIN }; + +struct CupsdConf +{ +// functions member + CupsdConf(); + ~CupsdConf(); + + bool loadFromFile(const QString& filename); + bool saveToFile(const QString& filename); + bool parseOption(const QString& line); + bool parseLocation(CupsLocation *location, QTextStream& file); + + bool loadAvailableResources(); + + static CupsdConf* get(); + static void release(); + +// data members + static CupsdConf *unique_; + + // Server + QString servername_; + QString serveradmin_; + int classification_; + QString otherclassname_; + bool classoverride_; + QString charset_; + QString language_; + QString printcap_; + int printcapformat_; + + // Security + QString remoteroot_; + QString systemgroup_; + QString encryptcert_; + QString encryptkey_; + QPtrList<CupsLocation> locations_; + QPtrList<CupsResource> resources_; + + // Network + int hostnamelookup_; + bool keepalive_; + int keepalivetimeout_; + int maxclients_; + QString maxrequestsize_; + int clienttimeout_; + QStringList listenaddresses_; + + // Log + QString accesslog_; + QString errorlog_; + QString pagelog_; + QString maxlogsize_; + int loglevel_; + + // Jobs + bool keepjobhistory_; + bool keepjobfiles_; + bool autopurgejobs_; + int maxjobs_; + int maxjobsperprinter_; + int maxjobsperuser_; + + // Filter + QString user_; + QString group_; + QString ripcache_; + int filterlimit_; + + // Directories + QString datadir_; + QString documentdir_; + QStringList fontpath_; + QString requestdir_; + QString serverbin_; + QString serverfiles_; + QString tmpfiles_; + + // Browsing + bool browsing_; + QStringList browseprotocols_; + int browseport_; + int browseinterval_; + int browsetimeout_; + QStringList browseaddresses_; + int browseorder_; + bool useimplicitclasses_; + bool hideimplicitmembers_; + bool useshortnames_; + bool useanyclasses_; + + // cupsd.conf file comments + CupsdComment comments_; + + // unrecognized options + QValueList< QPair<QString,QString> > unknown_; +}; + +struct CupsLocation +{ + CupsLocation(); + CupsLocation(const CupsLocation& loc); + + bool parseOption(const QString& line); + bool parseResource(const QString& line); + + CupsResource *resource_; + QString resourcename_; + int authtype_; + int authclass_; + QString authname_; + int encryption_; + int satisfy_; + int order_; + QStringList addresses_; +}; + +struct CupsResource +{ + CupsResource(); + CupsResource(const QString& path); + + void setPath(const QString& path); + + int type_; + QString path_; + QString text_; + + static QString textToPath(const QString& text); + static QString pathToText(const QString& path); + static int typeFromPath(const QString& path); + static int typeFromText(const QString& text); + static QString typeToIconName(int type); +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsddialog.cpp b/kdeprint/cups/cupsdconf2/cupsddialog.cpp new file mode 100644 index 000000000..a70b5b59e --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsddialog.cpp @@ -0,0 +1,360 @@ +/* + * 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 "cupsddialog.h" + +#include "cupsdpage.h" +#include "cupsdconf.h" +#include "cupsdsplash.h" +#include "cupsdserverpage.h" +#include "cupsdlogpage.h" +#include "cupsdjobspage.h" +#include "cupsdfilterpage.h" +#include "cupsddirpage.h" +#include "cupsdnetworkpage.h" +#include "cupsdbrowsingpage.h" +#include "cupsdsecuritypage.h" + +#include <qdir.h> +#include <qvbox.h> +#include <kmessagebox.h> +#include <klocale.h> +#include <qfile.h> +#include <qfileinfo.h> +#include <kglobal.h> +#include <kiconloader.h> +#include <qstringlist.h> +#include <qwhatsthis.h> +#include <kio/passdlg.h> +#include <kguiitem.h> +#include <kprocess.h> + +#include <signal.h> +#include <cups/cups.h> + +static bool dynamically_loaded = false; +static QString pass_string; + +extern "C" +{ +#include "cups-util.h" + KDEPRINT_EXPORT bool restartServer(QString& msg) + { + return CupsdDialog::restartServer(msg); + } + KDEPRINT_EXPORT bool configureServer(QWidget *parent, QString& msg) + { + dynamically_loaded = true; + bool result = CupsdDialog::configure(QString::null, parent, &msg); + dynamically_loaded = false; + return result; + } +} + +int getServerPid() +{ + QDir dir("/proc",QString::null,QDir::Name,QDir::Dirs); + for (uint i=0;i<dir.count();i++) + { + if (dir[i] == "." || dir[i] == ".." || dir[i] == "self") continue; + QFile f("/proc/" + dir[i] + "/cmdline"); + if (f.exists() && f.open(IO_ReadOnly)) + { + QTextStream t(&f); + QString line; + t >> line; + f.close(); + if (line.right(5) == "cupsd" || + line.right(6).left(5) == "cupsd") // second condition for 2.4.x kernels + // which add a null byte at the end + return dir[i].toInt(); + } + } + return (-1); +} + +const char* getPassword(const char*) +{ + QString user(cupsUser()); + QString pass; + + if (KIO::PasswordDialog::getNameAndPassword(user, pass, NULL) == QDialog::Accepted) + { + cupsSetUser(user.latin1()); + pass_string = pass; + if (pass_string.isEmpty()) + return ""; + else + return pass_string.latin1(); + } + else + return NULL; +} + +//--------------------------------------------------- + +CupsdDialog::CupsdDialog(QWidget *parent, const char *name) + : KDialogBase(IconList, "", Ok|Cancel|User1, Ok, parent, name, true, true, KGuiItem(i18n("Short Help"), "help")) +{ + KGlobal::iconLoader()->addAppDir("kdeprint"); + KGlobal::locale()->insertCatalogue("cupsdconf"); + + setShowIconsInTreeList(true); + setRootIsDecorated(false); + + pagelist_.setAutoDelete(false); + filename_ = ""; + conf_ = 0; + constructDialog(); + + setCaption(i18n("CUPS Server Configuration")); + + //resize(500, 400); +} + +CupsdDialog::~CupsdDialog() +{ + delete conf_; +} + +void CupsdDialog::addConfPage(CupsdPage *page) +{ + QPixmap icon = KGlobal::instance()->iconLoader()->loadIcon( + page->pixmap(), + KIcon::NoGroup, + KIcon::SizeMedium + ); + + QVBox *box = addVBoxPage(page->pageLabel(), page->header(), icon); + page->reparent(box, QPoint(0,0)); + pagelist_.append(page); +} + +void CupsdDialog::constructDialog() +{ + addConfPage(new CupsdSplash(0)); + addConfPage(new CupsdServerPage(0)); + addConfPage(new CupsdNetworkPage(0)); + addConfPage(new CupsdSecurityPage(0)); + addConfPage(new CupsdLogPage(0)); + addConfPage(new CupsdJobsPage(0)); + addConfPage(new CupsdFilterPage(0)); + addConfPage(new CupsdDirPage(0)); + addConfPage(new CupsdBrowsingPage(0)); + + conf_ = new CupsdConf(); + for (pagelist_.first();pagelist_.current();pagelist_.next()) + { + pagelist_.current()->setInfos(conf_); + } +} + +bool CupsdDialog::setConfigFile(const QString& filename) +{ + filename_ = filename; + if (!conf_->loadFromFile(filename_)) + { + KMessageBox::error(this, i18n("Error while loading configuration file!"), i18n("CUPS Configuration Error")); + return false; + } + if (conf_->unknown_.count() > 0) + { + // there were some unknown options, warn the user + QString msg; + for (QValueList< QPair<QString,QString> >::ConstIterator it=conf_->unknown_.begin(); it!=conf_->unknown_.end(); ++it) + msg += ((*it).first + " = " + (*it).second + "<br>"); + msg.prepend("<p>" + i18n("Some options were not recognized by this configuration tool. " + "They will be left untouched and you won't be able to change them.") + "</p>"); + KMessageBox::sorry(this, msg, i18n("Unrecognized Options")); + } + bool ok(true); + QString msg; + for (pagelist_.first();pagelist_.current() && ok;pagelist_.next()) + ok = pagelist_.current()->loadConfig(conf_, msg); + if (!ok) + { + KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"), i18n("CUPS Configuration Error")); + return false; + } + return true; +} + +bool CupsdDialog::restartServer(QString& msg) +{ + int serverPid = getServerPid(); + msg.truncate(0); + if (serverPid <= 0) + { + msg = i18n("Unable to find a running CUPS server"); + } + else + { + bool success = false; + if (getuid() == 0 ) + success = (::kill(serverPid, SIGHUP) == 0); + else + { + KProcess proc; + proc << "kdesu" << "-c" << "kill -SIGHUP " + QString::number( serverPid ); + success = proc.start( KProcess::Block ) && proc.normalExit(); + } + if( !success ) + msg = i18n("Unable to restart CUPS server (pid = %1)").arg(serverPid); + } + return (msg.isEmpty()); +} + +bool CupsdDialog::configure(const QString& filename, QWidget *parent, QString *msg) +{ + bool needUpload(false); + QString errormsg; + bool result = true; + + // init password dialog if needed + if (!dynamically_loaded) + cupsSetPasswordCB(getPassword); + + // load config file from server + QString fn(filename); + if (fn.isEmpty()) + { + fn = cupsGetConf(); + if (fn.isEmpty()) + errormsg = i18n("Unable to retrieve configuration file from the CUPS server. " + "You probably don't have the access permissions to perform this operation."); + else needUpload = true; + } + + // check read state (only if needed) + if (!fn.isEmpty()) + { + QFileInfo fi(fn); + if (!fi.exists() || !fi.isReadable() || !fi.isWritable()) + errormsg = i18n("Internal error: file '%1' not readable/writable!").arg(fn); + // check file size + if (fi.size() == 0) + errormsg = i18n("Internal error: empty file '%1'!").arg(fn); + } + + if (!errormsg.isEmpty()) + { + if ( !dynamically_loaded ) + KMessageBox::error(parent, errormsg.prepend("<qt>").append("</qt>"), i18n("CUPS Configuration Error")); + result = false; + } + else + { + KGlobal::locale()->insertCatalogue("cupsdconf"); // Must be before dialog is created to translate "Short Help" + CupsdDialog dlg(parent); + if (dlg.setConfigFile(fn) && dlg.exec()) + { + QCString encodedFn = QFile::encodeName(fn); + if (!needUpload) + KMessageBox::information(parent, + i18n("The config file has not been uploaded to the " + "CUPS server. The daemon will not be restarted.")); + else if (!cupsPutConf(encodedFn.data())) + { + errormsg = i18n("Unable to upload the configuration file to CUPS server. " + "You probably don't have the access permissions to perform this operation."); + if ( !dynamically_loaded ) + KMessageBox::error(parent, errormsg, i18n("CUPS configuration error")); + result = false; + } + } + + } + if (needUpload) + QFile::remove(fn); + + if ( msg ) + *msg = errormsg; + return result; +} + +void CupsdDialog::slotOk() +{ + if (conf_ && !filename_.isEmpty()) + { // try to save the file + bool ok(true); + QString msg; + CupsdConf newconf_; + for (pagelist_.first();pagelist_.current() && ok;pagelist_.next()) + ok = pagelist_.current()->saveConfig(&newconf_, msg); + // copy unknown options + newconf_.unknown_ = conf_->unknown_; + if (!ok) + { + ; // do nothing + } + else if (!newconf_.saveToFile(filename_)) + { + msg = i18n("Unable to write configuration file %1").arg(filename_); + ok = false; + } + if (!ok) + { + KMessageBox::error(this, msg.prepend("<qt>").append("</qt>"), i18n("CUPS Configuration Error")); + } + else + KDialogBase::slotOk(); + } +} + +void CupsdDialog::slotUser1() +{ + QWhatsThis::enterWhatsThisMode(); +} + +int CupsdDialog::serverPid() +{ + return getServerPid(); +} + +int CupsdDialog::serverOwner() +{ + int pid = getServerPid(); + if (pid > 0) + { + QString str; + str.sprintf("/proc/%d/status",pid); + QFile f(str); + if (f.exists() && f.open(IO_ReadOnly)) + { + QTextStream t(&f); + while (!t.eof()) + { + str = t.readLine(); + if (str.find("Uid:",0,false) == 0) + { + QStringList list = QStringList::split('\t', str, false); + if (list.count() >= 2) + { + bool ok; + int u = list[1].toInt(&ok); + if (ok) return u; + } + } + } + } + } + return (-1); +} + +#include "cupsddialog.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsddialog.h b/kdeprint/cups/cupsdconf2/cupsddialog.h new file mode 100644 index 000000000..4de5cd3dc --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsddialog.h @@ -0,0 +1,58 @@ +/* + * 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. + **/ + +#ifndef CUPSDDIALOG_H +#define CUPSDDIALOG_H + +#include <kdialogbase.h> +#include <qptrlist.h> + +class CupsdPage; +struct CupsdConf; + +class CupsdDialog : public KDialogBase +{ + Q_OBJECT +public: + CupsdDialog(QWidget *parent = 0, const char *name = 0); + ~CupsdDialog(); + + bool setConfigFile(const QString& filename); + + static bool configure(const QString& filename = QString::null, QWidget *parent = 0, QString *errormsg = 0); + static bool restartServer(QString& msg); + static int serverPid(); + static int serverOwner(); + +protected slots: + void slotOk(); + void slotUser1(); + +protected: + void addConfPage(CupsdPage*); + void constructDialog(); + void restartServer(); + +private: + QPtrList<CupsdPage> pagelist_; + CupsdConf *conf_; + QString filename_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsddirpage.cpp b/kdeprint/cups/cupsdconf2/cupsddirpage.cpp new file mode 100644 index 000000000..04a94c30a --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsddirpage.cpp @@ -0,0 +1,109 @@ +/* + * 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 "cupsddirpage.h" +#include "cupsdconf.h" +#include "qdirlineedit.h" +#include "qdirmultilineedit.h" + +#include <qlabel.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> + +CupsdDirPage::CupsdDirPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Folders")); + setHeader(i18n("Folders Settings")); + setPixmap("folder"); + + datadir_ = new QDirLineEdit(false, this); + documentdir_ = new QDirLineEdit(false, this); + fontpath_ = new QDirMultiLineEdit(this); + requestdir_ = new QDirLineEdit(false, this); + serverbin_ = new QDirLineEdit(false, this); + serverfiles_ = new QDirLineEdit(false, this); + tmpfiles_ = new QDirLineEdit(false, this); + + QLabel *l1 = new QLabel(i18n("Data folder:"), this); + QLabel *l2 = new QLabel(i18n("Document folder:"), this); + QLabel *l3 = new QLabel(i18n("Font path:"), this); + QLabel *l4 = new QLabel(i18n("Request folder:"), this); + QLabel *l5 = new QLabel(i18n("Server binaries:"), this); + QLabel *l6 = new QLabel(i18n("Server files:"), this); + QLabel *l7 = new QLabel(i18n("Temporary files:"), this); + + QGridLayout *m1 = new QGridLayout(this, 8, 2, 10, 7); + m1->setRowStretch(7, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight|Qt::AlignTop); + m1->addWidget(l4, 3, 0, Qt::AlignRight); + m1->addWidget(l5, 4, 0, Qt::AlignRight); + m1->addWidget(l6, 5, 0, Qt::AlignRight); + m1->addWidget(l7, 6, 0, Qt::AlignRight); + m1->addWidget(datadir_, 0, 1); + m1->addWidget(documentdir_, 1, 1); + m1->addWidget(fontpath_, 2, 1); + m1->addWidget(requestdir_, 3, 1); + m1->addWidget(serverbin_, 4, 1); + m1->addWidget(serverfiles_, 5, 1); + m1->addWidget(tmpfiles_, 6, 1); +} + +bool CupsdDirPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + datadir_->setURL(conf_->datadir_); + documentdir_->setURL(conf_->documentdir_); + fontpath_->setURLs(conf_->fontpath_); + requestdir_->setURL(conf_->requestdir_); + serverbin_->setURL(conf_->serverbin_); + serverfiles_->setURL(conf_->serverfiles_); + tmpfiles_->setURL(conf_->tmpfiles_); + + return true; +} + +bool CupsdDirPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->datadir_ = datadir_->url(); + conf->documentdir_ = documentdir_->url(); + conf->fontpath_ = fontpath_->urls(); + conf->requestdir_ = requestdir_->url(); + conf->serverbin_ = serverbin_->url(); + conf->serverfiles_ = serverfiles_->url(); + conf->tmpfiles_ = tmpfiles_->url(); + + return true; +} + +void CupsdDirPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(datadir_, conf->comments_.toolTip("datadir")); + QWhatsThis::add(documentdir_, conf->comments_.toolTip("documentroot")); + QWhatsThis::add(fontpath_, conf->comments_.toolTip("fontpath")); + QWhatsThis::add(requestdir_, conf->comments_.toolTip("requestroot")); + QWhatsThis::add(serverbin_, conf->comments_.toolTip("serverbin")); + QWhatsThis::add(serverfiles_, conf->comments_.toolTip("serverroot")); + QWhatsThis::add(tmpfiles_, conf->comments_.toolTip("tempdir")); +} diff --git a/kdeprint/cups/cupsdconf2/cupsddirpage.h b/kdeprint/cups/cupsdconf2/cupsddirpage.h new file mode 100644 index 000000000..ffce797e8 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsddirpage.h @@ -0,0 +1,47 @@ +/* + * 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. + **/ + +#ifndef CUPSDDIRPAGE_H +#define CUPSDDIRPAGE_H + +#include "cupsdpage.h" + +class QDirLineEdit; +class QDirMultiLineEdit; + +class CupsdDirPage : public CupsdPage +{ +public: + CupsdDirPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +private: + QDirLineEdit *datadir_, + *documentdir_, + *requestdir_, + *serverbin_, + *serverfiles_, + *tmpfiles_; + QDirMultiLineEdit *fontpath_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdfilterpage.cpp b/kdeprint/cups/cupsdconf2/cupsdfilterpage.cpp new file mode 100644 index 000000000..12270bc26 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdfilterpage.cpp @@ -0,0 +1,94 @@ +/* + * 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 "cupsdfilterpage.h" +#include "cupsdconf.h" +#include "sizewidget.h" + +#include <qlabel.h> +#include <qlineedit.h> +#include <qlayout.h> +#include <qwhatsthis.h> +#include <qcombobox.h> + +#include <klocale.h> +#include <knuminput.h> + +CupsdFilterPage::CupsdFilterPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Filter")); + setHeader(i18n("Filter Settings")); + setPixmap("filter"); + + user_ = new QLineEdit(this); + group_ = new QLineEdit(this); + ripcache_ = new SizeWidget(this); + filterlimit_ = new KIntNumInput(this); + + filterlimit_->setRange(0, 1000, 1, true); + filterlimit_->setSpecialValueText(i18n("Unlimited")); + filterlimit_->setSteps(1, 10); + + QLabel *l1 = new QLabel(i18n("User:"), this); + QLabel *l2 = new QLabel(i18n("Group:"), this); + QLabel *l3 = new QLabel(i18n("RIP cache:"), this); + QLabel *l4 = new QLabel(i18n("Filter limit:"), this); + + QGridLayout *m1 = new QGridLayout(this, 5, 2, 10, 7); + m1->setRowStretch(4, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(l4, 3, 0, Qt::AlignRight); + m1->addWidget(user_, 0, 1); + m1->addWidget(group_, 1, 1); + m1->addWidget(ripcache_, 2, 1); + m1->addWidget(filterlimit_, 3, 1); +} + +bool CupsdFilterPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + user_->setText(conf_->user_); + group_->setText(conf_->group_); + ripcache_->setSizeString(conf_->ripcache_); + filterlimit_->setValue(conf_->filterlimit_); + + return true; +} + +bool CupsdFilterPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->user_ = user_->text(); + conf->group_ = group_->text(); + conf->ripcache_ = ripcache_->sizeString(); + conf->filterlimit_ = filterlimit_->value(); + + return true; +} + +void CupsdFilterPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(user_, conf->comments_.toolTip("user")); + QWhatsThis::add(group_, conf->comments_.toolTip("group")); + QWhatsThis::add(ripcache_, conf->comments_.toolTip("ripcache")); + QWhatsThis::add(filterlimit_, conf->comments_.toolTip("filterlimit")); +} diff --git a/kdeprint/cups/cupsdconf2/cupsdfilterpage.h b/kdeprint/cups/cupsdconf2/cupsdfilterpage.h new file mode 100644 index 000000000..894777520 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdfilterpage.h @@ -0,0 +1,45 @@ +/* + * 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. + **/ + +#ifndef CUPSDFILTERPAGE_H +#define CUPSDFILTERPAGE_H + +#include "cupsdpage.h" + +class SizeWidget; +class QLineEdit; +class QComboBox; +class KIntNumInput; + +class CupsdFilterPage : public CupsdPage +{ +public: + CupsdFilterPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +private: + QLineEdit *user_, *group_; + KIntNumInput *filterlimit_; + SizeWidget *ripcache_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdjobspage.cpp b/kdeprint/cups/cupsdconf2/cupsdjobspage.cpp new file mode 100644 index 000000000..bfb2832eb --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdjobspage.cpp @@ -0,0 +1,123 @@ +/* + * 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 "cupsdjobspage.h" +#include "cupsdconf.h" + +#include <qlabel.h> +#include <qcheckbox.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <knuminput.h> + +CupsdJobsPage::CupsdJobsPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Jobs")); + setHeader(i18n("Print Jobs Settings")); + setPixmap("fileprint"); + + keepjobhistory_ = new QCheckBox(i18n("Preserve job history"), this); + keepjobfiles_ = new QCheckBox(i18n("Preserve job files"), this); + autopurgejobs_ = new QCheckBox(i18n("Auto purge jobs"), this); + maxjobs_ = new KIntNumInput(this); + maxjobsperprinter_ = new KIntNumInput(this); + maxjobsperuser_ = new KIntNumInput(this); + + maxjobs_->setRange(0, 1000, 1, true); + maxjobs_->setSteps(1, 10); + maxjobs_->setSpecialValueText(i18n("Unlimited")); + maxjobsperprinter_->setRange(0, 1000, 1, true); + maxjobsperprinter_->setSpecialValueText(i18n("Unlimited")); + maxjobsperprinter_->setSteps(1, 10); + maxjobsperuser_->setRange(0, 1000, 1, true); + maxjobsperuser_->setSpecialValueText(i18n("Unlimited")); + maxjobsperuser_->setSteps(1, 10); + + QLabel *l1 = new QLabel(i18n("Max jobs:"), this); + QLabel *l2 = new QLabel(i18n("Max jobs per printer:"), this); + QLabel *l3 = new QLabel(i18n("Max jobs per user:"), this); + + QGridLayout *m1 = new QGridLayout(this, 7, 2, 10, 7); + m1->setRowStretch(6, 1); + m1->setColStretch(1, 1); + m1->addWidget(keepjobhistory_, 0, 1); + m1->addWidget(keepjobfiles_, 1, 1); + m1->addWidget(autopurgejobs_, 2, 1); + m1->addWidget(l1, 3, 0, Qt::AlignRight); + m1->addWidget(l2, 4, 0, Qt::AlignRight); + m1->addWidget(l3, 5, 0, Qt::AlignRight); + m1->addWidget(maxjobs_, 3, 1); + m1->addWidget(maxjobsperprinter_, 4, 1); + m1->addWidget(maxjobsperuser_, 5, 1); + + connect(keepjobhistory_, SIGNAL(toggled(bool)), SLOT(historyChanged(bool))); + keepjobhistory_->setChecked(true); +} + +bool CupsdJobsPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + keepjobhistory_->setChecked(conf_->keepjobhistory_); + if (conf_->keepjobhistory_) + { + keepjobfiles_->setChecked(conf_->keepjobfiles_); + autopurgejobs_->setChecked(conf_->autopurgejobs_); + } + maxjobs_->setValue(conf_->maxjobs_); + maxjobsperprinter_->setValue(conf_->maxjobsperprinter_); + maxjobsperuser_->setValue(conf_->maxjobsperuser_); + + return true; +} + +bool CupsdJobsPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->keepjobhistory_ = keepjobhistory_->isChecked(); + if (conf->keepjobhistory_) + { + conf->keepjobfiles_ = keepjobfiles_->isChecked(); + conf->autopurgejobs_ = autopurgejobs_->isChecked(); + } + conf->maxjobs_ = maxjobs_->value(); + conf->maxjobsperprinter_ = maxjobsperprinter_->value(); + conf->maxjobsperuser_ = maxjobsperuser_->value(); + + return true; +} + +void CupsdJobsPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(keepjobhistory_, conf->comments_.toolTip("preservejobhistory")); + QWhatsThis::add(keepjobfiles_, conf->comments_.toolTip("preservejobfiles")); + QWhatsThis::add(autopurgejobs_, conf->comments_.toolTip("autopurgejobs")); + QWhatsThis::add(maxjobs_, conf->comments_.toolTip("maxjobs")); + QWhatsThis::add(maxjobsperprinter_, conf->comments_.toolTip("maxjobsperprinter")); + QWhatsThis::add(maxjobsperuser_, conf->comments_.toolTip("maxjobsperuser")); +} + +void CupsdJobsPage::historyChanged(bool on) +{ + keepjobfiles_->setEnabled(on); + autopurgejobs_->setEnabled(on); +} + +#include "cupsdjobspage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdjobspage.h b/kdeprint/cups/cupsdconf2/cupsdjobspage.h new file mode 100644 index 000000000..19e76a2aa --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdjobspage.h @@ -0,0 +1,47 @@ +/* + * 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. + **/ + +#ifndef CUPSDJOBSPAGE_H +#define CUPSDJOBSPAGE_H + +#include "cupsdpage.h" + +class KIntNumInput; +class QCheckBox; + +class CupsdJobsPage : public CupsdPage +{ + Q_OBJECT + +public: + CupsdJobsPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +protected slots: + void historyChanged(bool); + +private: + KIntNumInput *maxjobs_, *maxjobsperprinter_, *maxjobsperuser_; + QCheckBox *keepjobhistory_, *keepjobfiles_, *autopurgejobs_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdlogpage.cpp b/kdeprint/cups/cupsdconf2/cupsdlogpage.cpp new file mode 100644 index 000000000..49840050e --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdlogpage.cpp @@ -0,0 +1,111 @@ +/* + * 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 "cupsdlogpage.h" +#include "cupsdconf.h" +#include "qdirlineedit.h" +#include "sizewidget.h" + +#include <qlabel.h> +#include <qcombobox.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <kfiledialog.h> + +CupsdLogPage::CupsdLogPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Log")); + setHeader(i18n("Log Settings")); + setPixmap("contents"); + + accesslog_ = new QDirLineEdit(true, this); + errorlog_ = new QDirLineEdit(true, this); + pagelog_ = new QDirLineEdit(true, this); + maxlogsize_ = new SizeWidget(this); + loglevel_ = new QComboBox(this); + + loglevel_->insertItem(i18n("Detailed Debugging")); + loglevel_->insertItem(i18n("Debug Information")); + loglevel_->insertItem(i18n("General Information")); + loglevel_->insertItem(i18n("Warnings")); + loglevel_->insertItem(i18n("Errors")); + loglevel_->insertItem(i18n("No Logging")); + + /*maxlogsize_->setRange(0, 100, 1, true); + maxlogsize_->setSteps(1, 5); + maxlogsize_->setSpecialValueText(i18n("Unlimited")); + maxlogsize_->setSuffix(i18n("MB"));*/ + + QLabel *l1 = new QLabel(i18n("Access log:"), this); + QLabel *l2 = new QLabel(i18n("Error log:"), this); + QLabel *l3 = new QLabel(i18n("Page log:"), this); + QLabel *l4 = new QLabel(i18n("Max log size:"), this); + QLabel *l5 = new QLabel(i18n("Log level:"), this); + + loglevel_->setCurrentItem(2); + + QGridLayout *m1 = new QGridLayout(this, 6, 2, 10, 7); + m1->setRowStretch(5, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(l4, 3, 0, Qt::AlignRight); + m1->addWidget(l5, 4, 0, Qt::AlignRight); + m1->addWidget(accesslog_, 0, 1); + m1->addWidget(errorlog_, 1, 1); + m1->addWidget(pagelog_, 2, 1); + m1->addWidget(maxlogsize_, 3, 1); + m1->addWidget(loglevel_, 4, 1); +} + +bool CupsdLogPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + accesslog_->setURL(conf_->accesslog_); + errorlog_->setURL(conf_->errorlog_); + pagelog_->setURL(conf_->pagelog_); + maxlogsize_->setSizeString(conf_->maxlogsize_); + loglevel_->setCurrentItem(conf_->loglevel_); + + return true; +} + +bool CupsdLogPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->accesslog_ = accesslog_->url(); + conf->errorlog_ = errorlog_->url(); + conf->pagelog_ = pagelog_->url(); + conf->maxlogsize_ = maxlogsize_->sizeString(); + conf->loglevel_ = loglevel_->currentItem(); + + return true; +} + +void CupsdLogPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(accesslog_, conf->comments_.toolTip("accesslog")); + QWhatsThis::add(errorlog_, conf->comments_.toolTip("errorlog")); + QWhatsThis::add(pagelog_, conf->comments_.toolTip("pagelog")); + QWhatsThis::add(maxlogsize_, conf->comments_.toolTip("maxlogsize")); + QWhatsThis::add(loglevel_, conf->comments_.toolTip("loglevel")); +} diff --git a/kdeprint/cups/cupsdconf2/cupsdlogpage.h b/kdeprint/cups/cupsdconf2/cupsdlogpage.h new file mode 100644 index 000000000..68e15ff45 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdlogpage.h @@ -0,0 +1,44 @@ +/* + * 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. + **/ + +#ifndef CUPSDLOGPAGE_H +#define CUPSDLOGPAGE_H + +#include "cupsdpage.h" + +class QDirLineEdit; +class SizeWidget; +class QComboBox; + +class CupsdLogPage : public CupsdPage +{ +public: + CupsdLogPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +private: + QDirLineEdit *accesslog_, *errorlog_, *pagelog_; + QComboBox *loglevel_; + SizeWidget *maxlogsize_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdnetworkpage.cpp b/kdeprint/cups/cupsdconf2/cupsdnetworkpage.cpp new file mode 100644 index 000000000..6b0f196b5 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdnetworkpage.cpp @@ -0,0 +1,159 @@ +/* + * 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 "cupsdnetworkpage.h" +#include "cupsdconf.h" +#include "editlist.h" +#include "portdialog.h" +#include "sizewidget.h" + +#include <qlabel.h> +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <knuminput.h> + +CupsdNetworkPage::CupsdNetworkPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Network")); + setHeader(i18n("Network Settings")); + setPixmap("network"); + + keepalive_ = new QCheckBox(i18n("Keep alive"), this); + keepalivetimeout_ = new KIntNumInput(this); + maxclients_ = new KIntNumInput(this); + maxrequestsize_ = new SizeWidget(this); + clienttimeout_ = new KIntNumInput(this); + hostnamelookup_ = new QComboBox(this); + listen_ = new EditList(this); + + keepalivetimeout_->setRange(0, 10000, 1, true); + keepalivetimeout_->setSteps(1, 10); + keepalivetimeout_->setSpecialValueText(i18n("Unlimited")); + keepalivetimeout_->setSuffix(i18n(" sec")); + + maxclients_->setRange(1, 1000, 1, true); + maxclients_->setSteps(1, 10); + + clienttimeout_->setRange(0, 10000, 1, true); + clienttimeout_->setSteps(1, 10); + clienttimeout_->setSpecialValueText(i18n("Unlimited")); + clienttimeout_->setSuffix(i18n(" sec")); + + hostnamelookup_->insertItem(i18n("Off")); + hostnamelookup_->insertItem(i18n("On")); + hostnamelookup_->insertItem(i18n("Double")); + + QLabel *l1 = new QLabel(i18n("Hostname lookups:"), this); + QLabel *l2 = new QLabel(i18n("Keep-alive timeout:"), this); + QLabel *l3 = new QLabel(i18n("Max clients:"), this); + QLabel *l4 = new QLabel(i18n("Max request size:"), this); + QLabel *l5 = new QLabel(i18n("Client timeout:"), this); + QLabel *l6 = new QLabel(i18n("Listen to:"), this); + + QGridLayout *m1 = new QGridLayout(this, 8, 2, 10, 7); + m1->setRowStretch(7, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 2, 0, Qt::AlignRight); + m1->addWidget(l3, 3, 0, Qt::AlignRight); + m1->addWidget(l4, 4, 0, Qt::AlignRight); + m1->addWidget(l5, 5, 0, Qt::AlignRight); + m1->addWidget(l6, 6, 0, Qt::AlignTop|Qt::AlignRight); + m1->addWidget(keepalive_, 1, 1); + m1->addWidget(hostnamelookup_, 0, 1); + m1->addWidget(keepalivetimeout_, 2, 1); + m1->addWidget(maxclients_, 3, 1); + m1->addWidget(maxrequestsize_, 4, 1); + m1->addWidget(clienttimeout_, 5, 1); + m1->addWidget(listen_, 6, 1); + + connect(listen_, SIGNAL(add()), SLOT(slotAdd())); + connect(listen_, SIGNAL(edit(int)), SLOT(slotEdit(int))); + connect(listen_, SIGNAL(defaultList()), SLOT(slotDefaultList())); + connect(keepalive_, SIGNAL(toggled(bool)), keepalivetimeout_, SLOT(setEnabled(bool))); + keepalive_->setChecked(true); +} + +bool CupsdNetworkPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + hostnamelookup_->setCurrentItem(conf_->hostnamelookup_); + keepalive_->setChecked(conf_->keepalive_); + keepalivetimeout_->setValue(conf_->keepalivetimeout_); + maxclients_->setValue(conf_->maxclients_); + maxrequestsize_->setSizeString(conf_->maxrequestsize_); + clienttimeout_->setValue(conf_->clienttimeout_); + listen_->insertItems(conf_->listenaddresses_); + + return true; +} + +bool CupsdNetworkPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->hostnamelookup_ = hostnamelookup_->currentItem(); + conf->keepalive_ = keepalive_->isChecked(); + conf->keepalivetimeout_ = keepalivetimeout_->value(); + conf->maxclients_ = maxclients_->value(); + conf->maxrequestsize_ = maxrequestsize_->sizeString(); + conf->clienttimeout_ = clienttimeout_->value(); + conf->listenaddresses_ = listen_->items(); + + return true; +} + +void CupsdNetworkPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(hostnamelookup_, conf->comments_.toolTip("hostnamelookups")); + QWhatsThis::add(keepalive_, conf->comments_.toolTip("keepalive")); + QWhatsThis::add(keepalivetimeout_, conf->comments_.toolTip("keepalivetimeout")); + QWhatsThis::add(maxclients_, conf->comments_.toolTip("maxclients")); + QWhatsThis::add(maxrequestsize_, conf->comments_.toolTip("maxrequestsize")); + QWhatsThis::add(clienttimeout_, conf->comments_.toolTip("timeout")); + QWhatsThis::add(listen_, conf->comments_.toolTip("listen")); +} + +void CupsdNetworkPage::slotAdd() +{ + QString s = PortDialog::newListen(this, conf_); + if (!s.isEmpty()) + listen_->insertItem(s); +} + +void CupsdNetworkPage::slotEdit(int index) +{ + QString s = listen_->text(index); + s = PortDialog::editListen(s, this, conf_); + if (!s.isEmpty()) + listen_->setText(index, s); +} + +void CupsdNetworkPage::slotDefaultList() +{ + listen_->clear(); + QStringList l; + l << "Listen *:631"; + listen_->insertItems(l); +} + +#include "cupsdnetworkpage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdnetworkpage.h b/kdeprint/cups/cupsdconf2/cupsdnetworkpage.h new file mode 100644 index 000000000..c4c8bd450 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdnetworkpage.h @@ -0,0 +1,55 @@ +/* + * 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. + **/ + +#ifndef CUPSDNETWORKPAGE_H +#define CUPSDNETWORKPAGE_H + +#include "cupsdpage.h" + +class KIntNumInput; +class QCheckBox; +class QComboBox; +class EditList; +class SizeWidget; + +class CupsdNetworkPage : public CupsdPage +{ + Q_OBJECT + +public: + CupsdNetworkPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +protected slots: + void slotAdd(); + void slotEdit(int); + void slotDefaultList(); + +private: + KIntNumInput *keepalivetimeout_, *maxclients_, *clienttimeout_; + QComboBox *hostnamelookup_; + QCheckBox *keepalive_; + EditList *listen_; + SizeWidget *maxrequestsize_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdpage.cpp b/kdeprint/cups/cupsdconf2/cupsdpage.cpp new file mode 100644 index 000000000..00798552c --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdpage.cpp @@ -0,0 +1,32 @@ +/* + * 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 "cupsdpage.h" + +CupsdPage::CupsdPage(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + conf_ = 0; +} + +CupsdPage::~CupsdPage() +{ +} + +#include "cupsdpage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdpage.h b/kdeprint/cups/cupsdconf2/cupsdpage.h new file mode 100644 index 000000000..dedd53ade --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdpage.h @@ -0,0 +1,54 @@ +/* + * 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. + **/ + +#ifndef CUPSDPAGE_H +#define CUPSDPAGE_H + +#include <qwidget.h> + +struct CupsdConf; + +class CupsdPage : public QWidget +{ + Q_OBJECT +public: + CupsdPage(QWidget *parent = 0, const char *name = 0); + virtual ~CupsdPage(); + + virtual bool loadConfig(CupsdConf *conf, QString& msg) = 0; + virtual bool saveConfig(CupsdConf *conf, QString& msg) = 0; + virtual void setInfos(CupsdConf*) {} + + QString pageLabel() const { return label_; } + QString header() const { return header_; } + QString pixmap() const { return pixmap_; } + +protected: + void setPageLabel(const QString& s) { label_ = s; } + void setHeader(const QString& s) { header_ = s; } + void setPixmap(const QString& s) { pixmap_ = s; } + +protected: + CupsdConf *conf_; + QString label_; + QString header_; + QString pixmap_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdsecuritypage.cpp b/kdeprint/cups/cupsdconf2/cupsdsecuritypage.cpp new file mode 100644 index 000000000..a77f21708 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdsecuritypage.cpp @@ -0,0 +1,168 @@ +/* + * 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 "cupsdsecuritypage.h" +#include "cupsdconf.h" +#include "qdirlineedit.h" +#include "editlist.h" +#include "locationdialog.h" + +#include <qlabel.h> +#include <qlineedit.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <kiconloader.h> +#include <kmessagebox.h> + +CupsdSecurityPage::CupsdSecurityPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Security")); + setHeader(i18n("Security Settings")); + setPixmap("password"); + locs_.setAutoDelete(true); + + remoteroot_ = new QLineEdit(this); + systemgroup_ = new QLineEdit(this); + encryptcert_ = new QDirLineEdit(true, this); + encryptkey_ = new QDirLineEdit(true, this); + locations_ = new EditList(this); + + QLabel *l1 = new QLabel(i18n("Remote root user:"), this); + QLabel *l2 = new QLabel(i18n("System group:"), this); + QLabel *l3 = new QLabel(i18n("Encryption certificate:"), this); + QLabel *l4 = new QLabel(i18n("Encryption key:"), this); + QLabel *l5 = new QLabel(i18n("Locations:"), this); + + QGridLayout *m1 = new QGridLayout(this, 6, 2, 10, 7); + m1->setRowStretch(5, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(l4, 3, 0, Qt::AlignRight); + m1->addWidget(l5, 4, 0, Qt::AlignRight|Qt::AlignTop); + m1->addWidget(remoteroot_, 0, 1); + m1->addWidget(systemgroup_, 1, 1); + m1->addWidget(encryptcert_, 2, 1); + m1->addWidget(encryptkey_, 3, 1); + m1->addWidget(locations_, 4, 1); + + connect(locations_, SIGNAL(add()), SLOT(slotAdd())); + connect(locations_, SIGNAL(edit(int)), SLOT(slotEdit(int))); + connect(locations_, SIGNAL(defaultList()), SLOT(slotDefaultList())); + connect(locations_, SIGNAL(deleted(int)), SLOT(slotDeleted(int))); +} + +bool CupsdSecurityPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + remoteroot_->setText(conf_->remoteroot_); + systemgroup_->setText(conf_->systemgroup_); + encryptcert_->setURL(conf_->encryptcert_); + encryptkey_->setURL(conf_->encryptkey_); + locs_.clear(); + QPtrListIterator<CupsLocation> it(conf_->locations_); + for (;it.current();++it) + { + locs_.append(new CupsLocation(*(it.current()))); + if (it.current()->resource_) + locations_->insertItem(SmallIcon(CupsResource::typeToIconName(it.current()->resource_->type_)), it.current()->resource_->text_); + else + locations_->insertItem(it.current()->resourcename_); + } + + return true; +} + +bool CupsdSecurityPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->remoteroot_ = remoteroot_->text(); + conf->systemgroup_ = systemgroup_->text(); + conf->encryptcert_ = encryptcert_->url(); + conf->encryptkey_ = encryptkey_->url(); + conf->locations_.clear(); + QPtrListIterator<CupsLocation> it(locs_); + for (;it.current();++it) + conf->locations_.append(new CupsLocation(*(it.current()))); + + return true; +} + +void CupsdSecurityPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(remoteroot_, conf->comments_.toolTip("remoteroot")); + QWhatsThis::add(systemgroup_, conf->comments_.toolTip("systemgroup")); + QWhatsThis::add(encryptcert_, conf->comments_.toolTip("servercertificate")); + QWhatsThis::add(encryptkey_, conf->comments_.toolTip("serverkey")); + QWhatsThis::add(locations_, conf->comments_.toolTip("locationsshort")); +} + +void CupsdSecurityPage::slotAdd() +{ + CupsLocation *loc = new CupsLocation; + if (LocationDialog::newLocation(loc, this, conf_)) + { + int index(-1); + for (locs_.first(); locs_.current(); locs_.next()) + if (locs_.current()->resource_ == loc->resource_) + { + if (KMessageBox::warningContinueCancel(this, i18n("This location is already defined. Do you want to replace the existing one?"),QString::null,i18n("Replace")) == KMessageBox::Continue) + { + index = locs_.at(); + locs_.remove(); + break; + } + else + { + delete loc; + return; + } + } + + if (index == -1) + index = locs_.count(); + locs_.insert(index, loc); + locations_->insertItem(SmallIcon(loc->resource_->typeToIconName(loc->resource_->type_)), loc->resource_->text_); + } + else + delete loc; +} + +void CupsdSecurityPage::slotEdit(int index) +{ + CupsLocation *loc = locs_.at(index); + LocationDialog::editLocation(loc, this, conf_); +} + +void CupsdSecurityPage::slotDefaultList() +{ + locs_.clear(); + locations_->clear(); +} + +void CupsdSecurityPage::slotDeleted(int index) +{ + if (index >= 0 && index < (int)(locs_.count())) + locs_.remove(index); +} + +#include "cupsdsecuritypage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdsecuritypage.h b/kdeprint/cups/cupsdconf2/cupsdsecuritypage.h new file mode 100644 index 000000000..56a9e2e45 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdsecuritypage.h @@ -0,0 +1,56 @@ +/* + * 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. + **/ + +#ifndef CUPSDSECURITYPAGE_H +#define CUPSDSECURITYPAGE_H + +#include "cupsdpage.h" +#include <qptrlist.h> + +class QLineEdit; +class EditList; +class QDirLineEdit; +struct CupsLocation; + +class CupsdSecurityPage : public CupsdPage +{ + Q_OBJECT + +public: + CupsdSecurityPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +protected slots: + void slotAdd(); + void slotEdit(int); + void slotDefaultList(); + void slotDeleted(int); + +private: + QLineEdit *remoteroot_, *systemgroup_; + QDirLineEdit *encryptcert_, *encryptkey_; + EditList *locations_; + + QPtrList<CupsLocation> locs_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdserverpage.cpp b/kdeprint/cups/cupsdconf2/cupsdserverpage.cpp new file mode 100644 index 000000000..861dad9de --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdserverpage.cpp @@ -0,0 +1,181 @@ +/* + * 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 "cupsdserverpage.h" +#include "cupsdconf.h" + +#include <qlineedit.h> +#include <qlabel.h> +#include <qcheckbox.h> +#include <qcombobox.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> + +int findComboItem(QComboBox *cb, const QString& str) +{ + for (int i=0; i<cb->count(); i++) + if (cb->text(i) == str) + return i; + return (-1); +} + +CupsdServerPage::CupsdServerPage(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setPageLabel(i18n("Server")); + setHeader(i18n("Server Settings")); + setPixmap("gear"); + + servername_ = new QLineEdit(this); + serveradmin_ = new QLineEdit(this); + otherclassname_ = new QLineEdit(this); + language_ = new QLineEdit(this); + printcap_ = new QLineEdit(this); + classification_ = new QComboBox(this); + charset_ = new QComboBox(this); + printcapformat_ = new QComboBox(this); + classoverride_ = new QCheckBox(i18n("Allow overrides"), this); + + classification_->insertItem(i18n("None")); + classification_->insertItem(i18n("Classified")); + classification_->insertItem(i18n("Confidential")); + classification_->insertItem(i18n("Secret")); + classification_->insertItem(i18n("Top Secret")); + classification_->insertItem(i18n("Unclassified")); + classification_->insertItem(i18n("Other")); + + charset_->insertItem("UTF-8"); + charset_->insertItem("ISO-8859-1"); + charset_->insertItem("ISO-8859-2"); + charset_->insertItem("ISO-8859-3"); + charset_->insertItem("ISO-8859-4"); + charset_->insertItem("ISO-8859-5"); + charset_->insertItem("ISO-8859-6"); + charset_->insertItem("ISO-8859-7"); + charset_->insertItem("ISO-8859-8"); + charset_->insertItem("ISO-8859-9"); + charset_->insertItem("ISO-8859-10"); + charset_->insertItem("ISO-8859-13"); + charset_->insertItem("ISO-8859-14"); + charset_->insertItem("ISO-8859-15"); + + printcapformat_->insertItem("BSD"); + printcapformat_->insertItem("SOLARIS"); + + QLabel *l1 = new QLabel(i18n("Server name:"), this); + QLabel *l2 = new QLabel(i18n("Server administrator:"), this); + QLabel *l3 = new QLabel(i18n("Classification:"), this); + QLabel *l4 = new QLabel(i18n("Default character set:"), this); + QLabel *l5 = new QLabel(i18n("Default language:"), this); + QLabel *l6 = new QLabel(i18n("Printcap file:"), this); + QLabel *l7 = new QLabel(i18n("Printcap format:"), this); + + connect(classification_, SIGNAL(activated(int)), SLOT(classChanged(int))); + classification_->setCurrentItem(0); + charset_->setCurrentItem(0); + printcapformat_->setCurrentItem(0); + classChanged(0); + + QGridLayout *m1 = new QGridLayout(this, 9, 2, 10, 7); + m1->setRowStretch(8, 1); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(l4, 4, 0, Qt::AlignRight); + m1->addWidget(l5, 5, 0, Qt::AlignRight); + m1->addWidget(l6, 6, 0, Qt::AlignRight); + m1->addWidget(l7, 7, 0, Qt::AlignRight); + m1->addWidget(servername_, 0, 1); + m1->addWidget(serveradmin_, 1, 1); + m1->addWidget(charset_, 4, 1); + m1->addWidget(language_, 5, 1); + m1->addWidget(printcap_, 6, 1); + m1->addWidget(printcapformat_, 7, 1); + QHBoxLayout *m2 = new QHBoxLayout(0, 0, 5); + m1->addLayout(m2, 2, 1); + m2->addWidget(classification_); + m2->addWidget(otherclassname_); + QWidget *w = new QWidget(this); + w->setFixedWidth(20); + QHBoxLayout *m3 = new QHBoxLayout(0, 0, 0); + m1->addLayout(m3, 3, 1); + m3->addWidget(w); + m3->addWidget(classoverride_); +} + +bool CupsdServerPage::loadConfig(CupsdConf *conf, QString&) +{ + conf_ = conf; + servername_->setText(conf_->servername_); + serveradmin_->setText(conf_->serveradmin_); + classification_->setCurrentItem(conf_->classification_); + classChanged(conf_->classification_); + if (conf->classification_ != CLASS_NONE) + classoverride_->setChecked(conf_->classoverride_); + if (conf->classification_ == CLASS_OTHER) + otherclassname_->setText(conf_->otherclassname_); + int index = findComboItem(charset_, conf_->charset_.upper()); + if (index != -1) + charset_->setCurrentItem(index); + language_->setText(conf_->language_); + printcap_->setText(conf_->printcap_); + printcapformat_->setCurrentItem(conf_->printcapformat_); + + return true; +} + +bool CupsdServerPage::saveConfig(CupsdConf *conf, QString&) +{ + conf->servername_ = servername_->text(); + conf->serveradmin_ = serveradmin_->text(); + conf->classification_ = classification_->currentItem(); + if (conf->classification_ != CLASS_NONE) + conf->classoverride_ = classoverride_->isChecked(); + if (conf->classification_ == CLASS_OTHER) + conf->otherclassname_ = otherclassname_->text(); + conf->charset_ = charset_->currentText(); + conf->language_ = language_->text(); + conf->printcap_ = printcap_->text(); + conf->printcapformat_ = printcapformat_->currentItem(); + + return true; +} + +void CupsdServerPage::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(servername_, conf->comments_.toolTip("servername")); + QWhatsThis::add(serveradmin_, conf->comments_.toolTip("serveradmin")); + QWhatsThis::add(classification_, conf->comments_.toolTip("classification")); + QWhatsThis::add(classoverride_, conf->comments_.toolTip("classifyoverride")); + QWhatsThis::add(charset_, conf->comments_.toolTip("defaultcharset")); + QWhatsThis::add(language_, conf->comments_.toolTip("defaultlanguage")); + QWhatsThis::add(printcap_, conf->comments_.toolTip("printcap")); + QWhatsThis::add(printcapformat_, conf->comments_.toolTip("printcapformat")); +} + +void CupsdServerPage::classChanged(int index) +{ + classoverride_->setEnabled(index != 0); + otherclassname_->setEnabled(index == CLASS_OTHER); +} + +#include "cupsdserverpage.moc" diff --git a/kdeprint/cups/cupsdconf2/cupsdserverpage.h b/kdeprint/cups/cupsdconf2/cupsdserverpage.h new file mode 100644 index 000000000..d82367c30 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdserverpage.h @@ -0,0 +1,49 @@ +/* + * 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. + **/ + +#ifndef CUPSDSERVERPAGE_H +#define CUPSDSERVERPAGE_H + +#include "cupsdpage.h" + +class QLineEdit; +class QCheckBox; +class QComboBox; + +class CupsdServerPage : public CupsdPage +{ + Q_OBJECT + +public: + CupsdServerPage(QWidget *parent = 0, const char *name = 0); + + bool loadConfig(CupsdConf*, QString&); + bool saveConfig(CupsdConf*, QString&); + void setInfos(CupsdConf*); + +protected slots: + void classChanged(int); + +private: + QLineEdit *servername_, *serveradmin_, *language_, *printcap_, *otherclassname_; + QComboBox *classification_, *charset_, *printcapformat_; + QCheckBox *classoverride_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/cupsdsplash.cpp b/kdeprint/cups/cupsdconf2/cupsdsplash.cpp new file mode 100644 index 000000000..7a623e972 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdsplash.cpp @@ -0,0 +1,73 @@ +/* + * 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 "cupsdsplash.h" + +#include <qlabel.h> +#include <qpixmap.h> +#include <qlayout.h> +#include <klocale.h> +#include <kstandarddirs.h> + +CupsdSplash::CupsdSplash(QWidget *parent, const char *name) + : CupsdPage(parent, name) +{ + setHeader(i18n("Welcome to the CUPS Server Configuration Tool")); + setPageLabel(i18n("Welcome")); + setPixmap("go"); + + QVBoxLayout *main_ = new QVBoxLayout(this, 10, 10); + QHBoxLayout *sub_ = new QHBoxLayout(0, 0, 10); + main_->addLayout(sub_); + + QLabel *cupslogo_ = new QLabel(this); + QString logopath = locate("data", QString("kdeprint/cups_logo.png")); + cupslogo_->setPixmap(logopath.isEmpty() ? QPixmap() : QPixmap(logopath)); + cupslogo_->setAlignment(Qt::AlignCenter); + QLabel *kupslogo_ = new QLabel(this); + logopath = locate("data", QString("kdeprint/kde_logo.png")); + kupslogo_->setPixmap(logopath.isEmpty() ? QPixmap() : QPixmap(logopath)); + kupslogo_->setAlignment(Qt::AlignCenter); + + QLabel *helptxt_ = new QLabel(this); + helptxt_->setText(i18n( "<p>This tool will help you to configure graphically the server of the CUPS printing system. " + "The available options are grouped into sets of related topics and can be accessed " + "quickly through the icon view located on the left. Each option has a default value that is " + "shown if it has not been previously set. This default value should be OK in most cases.</p><br>" + "<p>You can access a short help message for each option using either the '?' button in the " + "the title bar, or the button at the bottom of this dialog.</p>")); + + sub_->addWidget(cupslogo_); + sub_->addWidget(kupslogo_); + main_->addWidget(helptxt_, 1); +} + +CupsdSplash::~CupsdSplash() +{ +} + +bool CupsdSplash::loadConfig(CupsdConf*, QString&) +{ + return true; +} + +bool CupsdSplash::saveConfig(CupsdConf*, QString&) +{ + return true; +} diff --git a/kdeprint/cups/cupsdconf2/cupsdsplash.h b/kdeprint/cups/cupsdconf2/cupsdsplash.h new file mode 100644 index 000000000..ed548948d --- /dev/null +++ b/kdeprint/cups/cupsdconf2/cupsdsplash.h @@ -0,0 +1,35 @@ +/* + * 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. + **/ + +#ifndef CUPSDSPLASH_H +#define CUPSDSPLASH_H + +#include "cupsdpage.h" + +class CupsdSplash : public CupsdPage +{ +public: + CupsdSplash(QWidget *parent = 0, const char *name = 0); + ~CupsdSplash(); + + bool loadConfig(CupsdConf *conf, QString& msg); + bool saveConfig(CupsdConf *conf, QString& msg); +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/editlist.cpp b/kdeprint/cups/cupsdconf2/editlist.cpp new file mode 100644 index 000000000..4c924dbb4 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/editlist.cpp @@ -0,0 +1,124 @@ +/* + * 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 "editlist.h" + +#include <klistbox.h> +#include <kpushbutton.h> +#include <qlayout.h> +#include <klocale.h> +#include <kiconloader.h> +#include <kguiitem.h> + +EditList::EditList(QWidget *parent, const char *name) + : QWidget(parent, name) +{ + list_ = new KListBox(this); + addbtn_ = new KPushButton(KGuiItem(i18n("Add..."), "filenew"), this); + editbtn_ = new KPushButton(KGuiItem(i18n("Edit..."), "edit"), this); + delbtn_ = new KPushButton(KGuiItem(i18n("Delete"), "editdelete"), this); + defbtn_ = new KPushButton(KGuiItem(i18n("Default List"), "history"), this); + + QGridLayout *m1 = new QGridLayout(this, 4, 2, 0, 0); + m1->setColStretch(0, 1); + m1->addMultiCellWidget(list_, 0, 3, 0, 1); + m1->addWidget(addbtn_, 0, 1); + m1->addWidget(editbtn_, 1, 1); + m1->addWidget(delbtn_, 2, 1); + m1->addWidget(defbtn_, 3, 1); + + connect(addbtn_, SIGNAL(clicked()), SIGNAL(add())); + connect(editbtn_, SIGNAL(clicked()), SLOT(slotEdit())); + connect(delbtn_, SIGNAL(clicked()), SLOT(slotDelete())); + connect(defbtn_, SIGNAL(clicked()), SIGNAL(defaultList())); + connect(list_, SIGNAL(highlighted(int)), SLOT(slotSelected(int))); + slotSelected(-1); +} + +void EditList::slotEdit() +{ + int index = list_->currentItem(); + if (index >= 0) + emit edit(index); +} + +void EditList::slotDelete() +{ + int index = list_->currentItem(); + list_->removeItem(index); + slotSelected((list_->count() > 0 ? list_->currentItem() : -1)); + emit deleted(index); +} + +void EditList::slotSelected(int index) +{ + editbtn_->setEnabled(index >= 0); + delbtn_->setEnabled(index >= 0); +} + +QString EditList::text(int index) +{ + return list_->text(index); +} + +void EditList::setText(int index, const QString& s) +{ + if (list_->text(index) != s) + { + QListBoxItem *it = list_->findItem(s, Qt::ExactMatch); + if (!it) + list_->changeItem(s, index); + else + list_->removeItem(index); + } +} + +void EditList::clear() +{ + list_->clear(); + slotSelected(-1); +} + +void EditList::insertItem(const QString& s) +{ + if (!list_->findItem(s, Qt::ExactMatch)) + list_->insertItem(s); +} + +void EditList::insertItem(const QPixmap& icon, const QString& s) +{ + if (!list_->findItem(s, Qt::ExactMatch)) + list_->insertItem(icon, s); +} + +void EditList::insertItems(const QStringList& l) +{ + for (QStringList::ConstIterator it=l.begin(); it!=l.end(); ++it) + insertItem(*it); +} + +QStringList EditList::items() +{ + QStringList l; + for (uint i=0; i<list_->count(); i++) + l << list_->text(i); + return l; +} + +#include "editlist.moc" diff --git a/kdeprint/cups/cupsdconf2/editlist.h b/kdeprint/cups/cupsdconf2/editlist.h new file mode 100644 index 000000000..773667304 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/editlist.h @@ -0,0 +1,60 @@ +/* + * 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. + **/ + +#ifndef EDITLIST_H +#define EDITLIST_H + +#include <qwidget.h> +#include <qpixmap.h> + +class KListBox; +class QPushButton; + +class EditList : public QWidget +{ + Q_OBJECT + +public: + EditList(QWidget *parent = 0, const char *name = 0); + + QString text(int); + void setText(int, const QString&); + void insertItem(const QString&); + void insertItem(const QPixmap&, const QString&); + void insertItems(const QStringList&); + QStringList items(); + void clear(); + +signals: + void add(); + void edit(int); + void defaultList(); + void deleted(int); + +protected slots: + void slotDelete(); + void slotEdit(); + void slotSelected(int); + +private: + KListBox *list_; + QPushButton *addbtn_, *editbtn_, *delbtn_, *defbtn_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/kde_logo.png b/kdeprint/cups/cupsdconf2/kde_logo.png Binary files differnew file mode 100644 index 000000000..6ba204607 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/kde_logo.png diff --git a/kdeprint/cups/cupsdconf2/locationdialog.cpp b/kdeprint/cups/cupsdconf2/locationdialog.cpp new file mode 100644 index 000000000..fc5c55076 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/locationdialog.cpp @@ -0,0 +1,222 @@ +/* + * 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 "locationdialog.h" +#include "cupsdconf.h" +#include "editlist.h" +#include "addressdialog.h" + +#include <qlineedit.h> +#include <qcombobox.h> +#include <qlayout.h> +#include <qlabel.h> +#include <qpushbutton.h> +#include <qwhatsthis.h> + +#include <klocale.h> +#include <kiconloader.h> + +LocationDialog::LocationDialog(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true) +{ + QWidget *dummy = new QWidget(this); + setMainWidget(dummy); + resource_ = new QComboBox(dummy); + authtype_ = new QComboBox(dummy); + authclass_ = new QComboBox(dummy); + authname_ = new QLineEdit(dummy); + encryption_ = new QComboBox(dummy); + satisfy_ = new QComboBox(dummy); + order_ = new QComboBox(dummy); + addresses_ = new EditList(dummy); + + authtype_->insertItem(i18n("None")); + authtype_->insertItem(i18n("Basic")); + authtype_->insertItem(i18n("Digest")); + + authclass_->insertItem(i18n("None")); + authclass_->insertItem(i18n("User")); + authclass_->insertItem(i18n("System")); + authclass_->insertItem(i18n("Group")); + + encryption_->insertItem(i18n("Always")); + encryption_->insertItem(i18n("Never")); + encryption_->insertItem(i18n("Required")); + encryption_->insertItem(i18n("If Requested")); + + satisfy_->insertItem(i18n("All")); + satisfy_->insertItem(i18n("Any")); + + order_->insertItem(i18n("Allow, Deny")); + order_->insertItem(i18n("Deny, Allow")); + + connect(authclass_, SIGNAL(activated(int)), SLOT(slotClassChanged(int))); + connect(authtype_, SIGNAL(activated(int)), SLOT(slotTypeChanged(int))); + + QLabel *l1 = new QLabel(i18n("Resource:"), dummy); + QLabel *l2 = new QLabel(i18n("Authentication:"), dummy); + QLabel *l3 = new QLabel(i18n("Class:"), dummy); + QLabel *l4 = new QLabel(i18n("Names:"), dummy); + QLabel *l5 = new QLabel(i18n("Encryption:"), dummy); + QLabel *l6 = new QLabel(i18n("Satisfy:"), dummy); + QLabel *l7 = new QLabel(i18n("ACL order:"), dummy); + QLabel *l8 = new QLabel(i18n("ACL addresses:"),dummy); + + QGridLayout *m1 = new QGridLayout(dummy, 8, 2, 0, 5); + m1->setColStretch(1, 1); + m1->addWidget(l1, 0, 0, Qt::AlignRight); + m1->addWidget(l2, 1, 0, Qt::AlignRight); + m1->addWidget(l3, 2, 0, Qt::AlignRight); + m1->addWidget(l4, 3, 0, Qt::AlignRight); + m1->addWidget(l5, 4, 0, Qt::AlignRight); + m1->addWidget(l6, 5, 0, Qt::AlignRight); + m1->addWidget(l7, 6, 0, Qt::AlignRight); + m1->addWidget(l8, 7, 0, Qt::AlignRight|Qt::AlignTop); + m1->addWidget(resource_, 0, 1); + m1->addWidget(authtype_, 1, 1); + m1->addWidget(authclass_, 2, 1); + m1->addWidget(authname_, 3, 1); + m1->addWidget(encryption_, 4, 1); + m1->addWidget(satisfy_, 5, 1); + m1->addWidget(order_, 6, 1); + m1->addWidget(addresses_, 7, 1); + + setCaption(i18n("Location")); + resize(400, 100); + + slotTypeChanged(AUTHTYPE_NONE); + slotClassChanged(AUTHCLASS_ANONYMOUS); + encryption_->setCurrentItem(ENCRYPT_IFREQUESTED); + + connect(addresses_, SIGNAL(add()), SLOT(slotAdd())); + connect(addresses_, SIGNAL(edit(int)), SLOT(slotEdit(int))); + connect(addresses_, SIGNAL(defaultList()), SLOT(slotDefaultList())); +} + +void LocationDialog::setInfos(CupsdConf *conf) +{ + conf_ = conf; + + QPtrListIterator<CupsResource> it(conf->resources_); + for (; it.current(); ++it) + resource_->insertItem(SmallIcon(it.current()->typeToIconName(it.current()->type_)), it.current()->text_); + + QWhatsThis::add(encryption_, conf_->comments_.toolTip("encryption")); + QWhatsThis::add(order_, conf_->comments_.toolTip("order")); + QWhatsThis::add(authclass_, conf_->comments_.toolTip("authclass")); + QWhatsThis::add(authtype_, conf_->comments_.toolTip("authtype")); + QWhatsThis::add(authname_, conf_->comments_.toolTip("authname")); + QWhatsThis::add(satisfy_, conf_->comments_.toolTip("satisfy")); + QWhatsThis::add(addresses_, conf_->comments_.toolTip("allowdeny")); +} + +void LocationDialog::fillLocation(CupsLocation *loc) +{ + loc->resource_ = conf_->resources_.at(resource_->currentItem()); + loc->resourcename_ = loc->resource_->path_; + loc->authtype_ = authtype_->currentItem(); + loc->authclass_ = (loc->authtype_ == AUTHTYPE_NONE ? AUTHCLASS_ANONYMOUS : authclass_->currentItem()); + loc->authname_ = (loc->authclass_ == AUTHCLASS_USER || loc->authclass_ == AUTHCLASS_GROUP ? authname_->text() : QString::null); + loc->encryption_ = encryption_->currentItem(); + loc->satisfy_ = satisfy_->currentItem(); + loc->order_ = order_->currentItem(); + loc->addresses_ = addresses_->items(); +} + +void LocationDialog::setLocation(CupsLocation *loc) +{ + int index = conf_->resources_.findRef(loc->resource_); + resource_->setCurrentItem(index); + authtype_->setCurrentItem(loc->authtype_); + authclass_->setCurrentItem(loc->authclass_); + authname_->setText(loc->authname_); + encryption_->setCurrentItem(loc->encryption_); + satisfy_->setCurrentItem(loc->satisfy_); + order_->setCurrentItem(loc->order_); + addresses_->insertItems(loc->addresses_); + + slotTypeChanged(loc->authtype_); + slotClassChanged(loc->authclass_); +} + +void LocationDialog::slotTypeChanged(int index) +{ + authclass_->setEnabled(index != AUTHTYPE_NONE); + if (index != AUTHTYPE_NONE) + slotClassChanged(authclass_->currentItem()); + else + authname_->setEnabled(false); +} + +void LocationDialog::slotClassChanged(int index) +{ + authname_->setEnabled((index == AUTHCLASS_USER || index == AUTHCLASS_GROUP)); +} + +bool LocationDialog::newLocation(CupsLocation *loc, QWidget *parent, CupsdConf *conf) +{ + LocationDialog dlg(parent); + if (conf) + dlg.setInfos(conf); + if (dlg.exec()) + { + dlg.fillLocation(loc); + return true; + } + else + return false; +} + +bool LocationDialog::editLocation(CupsLocation *loc, QWidget *parent, CupsdConf *conf) +{ + LocationDialog dlg(parent); + if (conf) + dlg.setInfos(conf); + dlg.setLocation(loc); + dlg.resource_->setEnabled(false); + if (dlg.exec()) + { + dlg.fillLocation(loc); + return true; + } + else + return false; +} + +void LocationDialog::slotAdd() +{ + QString addr = AddressDialog::newAddress(this); + if (!addr.isEmpty()) + addresses_->insertItem(addr); +} + +void LocationDialog::slotEdit(int index) +{ + QString addr = addresses_->text(index); + addr = AddressDialog::editAddress(addr, this); + if (!addr.isEmpty()) + addresses_->insertItem(addr); +} + +void LocationDialog::slotDefaultList() +{ + addresses_->clear(); +} + +#include "locationdialog.moc" diff --git a/kdeprint/cups/cupsdconf2/locationdialog.h b/kdeprint/cups/cupsdconf2/locationdialog.h new file mode 100644 index 000000000..5ca8c4d53 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/locationdialog.h @@ -0,0 +1,58 @@ +/* + * 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. + **/ + +#ifndef LOCATIONDIALOG_H +#define LOCATIONDIALOG_H + +#include <kdialogbase.h> + +class QComboBox; +class QLineEdit; +class EditList; +struct CupsdConf; +struct CupsLocation; + +class LocationDialog : public KDialogBase +{ + Q_OBJECT +public: + LocationDialog(QWidget *parent = 0, const char *name = 0); + + void setInfos(CupsdConf*); + void fillLocation(CupsLocation*); + void setLocation(CupsLocation*); + + static bool newLocation(CupsLocation*, QWidget *parent = 0, CupsdConf *conf = 0); + static bool editLocation(CupsLocation*, QWidget *parent = 0, CupsdConf *conf = 0); + +protected slots: + void slotTypeChanged(int); + void slotClassChanged(int); + void slotAdd(); + void slotEdit(int); + void slotDefaultList(); + +private: + QComboBox *resource_, *authtype_, *authclass_, *encryption_, *satisfy_, *order_; + QLineEdit *authname_; + EditList *addresses_; + CupsdConf *conf_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/main.cpp b/kdeprint/cups/cupsdconf2/main.cpp new file mode 100644 index 000000000..e8fd3df6a --- /dev/null +++ b/kdeprint/cups/cupsdconf2/main.cpp @@ -0,0 +1,48 @@ +/* + * 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 "cupsddialog.h" + +#include <qfile.h> +#include <klocale.h> +#include <kcmdlineargs.h> +#include <kapplication.h> + +static KCmdLineOptions options[] = +{ + { "+[file]", I18N_NOOP("Configuration file to load"), 0}, + KCmdLineLastOption +}; + +extern "C" KDE_EXPORT int kdemain(int argc, char *argv[]) +{ + KCmdLineArgs::init(argc,argv,"cupsdconf", + I18N_NOOP("A CUPS configuration tool"), + I18N_NOOP("A CUPS configuration tool"),"0.0.1"); + KCmdLineArgs::addCmdLineOptions(options); + KApplication app; + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + KURL configfile; + if (args->count() > 0) + CupsdDialog::configure(args->url(0).path()); + else + CupsdDialog::configure(); + return (0); +} diff --git a/kdeprint/cups/cupsdconf2/portdialog.cpp b/kdeprint/cups/cupsdconf2/portdialog.cpp new file mode 100644 index 000000000..f866450b8 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/portdialog.cpp @@ -0,0 +1,118 @@ +/* + * 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 "portdialog.h" +#include "cupsdconf.h" + +#include <qlineedit.h> +#include <qspinbox.h> +#include <qcheckbox.h> +#include <qpushbutton.h> +#include <qlabel.h> +#include <qlayout.h> +#include <qwhatsthis.h> + +#include <klocale.h> + +PortDialog::PortDialog(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, QString::null, Ok|Cancel, Ok, true) +{ + QWidget *dummy = new QWidget(this); + setMainWidget(dummy); + address_ = new QLineEdit(dummy); + port_ = new QSpinBox(0, 9999, 1, dummy); + port_->setValue(631); + usessl_ = new QCheckBox(i18n("Use SSL encryption"), dummy); + + QLabel *l1 = new QLabel(i18n("Address:"), dummy); + QLabel *l2 = new QLabel(i18n("Port:"), dummy); + + QVBoxLayout *m1 = new QVBoxLayout(dummy, 0, 10); + QGridLayout *m2 = new QGridLayout(0, 3, 2, 0, 5); + m1->addLayout(m2); + m2->addWidget(l1, 0, 0, Qt::AlignRight); + m2->addWidget(l2, 1, 0, Qt::AlignRight); + m2->addMultiCellWidget(usessl_, 2, 2, 0, 1); + m2->addWidget(address_, 0, 1); + m2->addWidget(port_, 1, 1); + + setCaption(i18n("Listen To")); + resize(250, 100); +} + +QString PortDialog::listenString() +{ + QString s; + if (usessl_->isChecked()) + s.append("SSLListen "); + else + s.append("Listen "); + if (!address_->text().isEmpty()) + s.append(address_->text()); + else + s.append("*"); + s.append(":").append(port_->text()); + return s; +} + +void PortDialog::setInfos(CupsdConf *conf) +{ + QWhatsThis::add(address_, conf->comments_.toolTip("address")); + QWhatsThis::add(port_, conf->comments_.toolTip("port")); + QWhatsThis::add(usessl_, conf->comments_.toolTip("usessl")); +} + +QString PortDialog::newListen(QWidget *parent, CupsdConf *conf) +{ + PortDialog dlg(parent); + dlg.setInfos(conf); + if (dlg.exec()) + { + return dlg.listenString(); + } + return QString::null; +} + +QString PortDialog::editListen(const QString& s, QWidget *parent, CupsdConf *conf) +{ + PortDialog dlg(parent); + dlg.setInfos(conf); + int p = s.find(' '); + if (p != -1) + { + dlg.usessl_->setChecked(s.left(p).startsWith("SSL")); + QString addr = s.mid(p+1).stripWhiteSpace(); + int p1 = addr.find(':'); + if (p1 == -1) + { + dlg.address_->setText(addr); + dlg.port_->setValue(631); + } + else + { + dlg.address_->setText(addr.left(p1)); + dlg.port_->setValue(addr.mid(p1+1).toInt()); + } + } + if (dlg.exec()) + { + return dlg.listenString(); + } + return QString::null; +} diff --git a/kdeprint/cups/cupsdconf2/portdialog.h b/kdeprint/cups/cupsdconf2/portdialog.h new file mode 100644 index 000000000..8f0b9f3e9 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/portdialog.h @@ -0,0 +1,46 @@ +/* + * 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. + **/ + +#ifndef PORTDIALOG_H +#define PORTDIALOG_H + +#include <kdialogbase.h> + +class QLineEdit; +class QSpinBox; +class QCheckBox; +struct CupsdConf; + +class PortDialog : public KDialogBase +{ +public: + PortDialog(QWidget *parent = 0, const char *name = 0); + + QString listenString(); + void setInfos(CupsdConf*); + static QString newListen(QWidget *parent = 0, CupsdConf *conf = 0); + static QString editListen(const QString& s, QWidget *parent = 0, CupsdConf *conf = 0); + +private: + QLineEdit *address_; + QSpinBox *port_; + QCheckBox *usessl_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/qdirlineedit.cpp b/kdeprint/cups/cupsdconf2/qdirlineedit.cpp new file mode 100644 index 000000000..931d6ac4a --- /dev/null +++ b/kdeprint/cups/cupsdconf2/qdirlineedit.cpp @@ -0,0 +1,73 @@ +/* + * 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 "qdirlineedit.h" + +#include <qlineedit.h> +#include <qlayout.h> +#include <kpushbutton.h> +#include <kfiledialog.h> +#include <kiconloader.h> + +QDirLineEdit::QDirLineEdit(bool file, QWidget *parent, const char *name) + : QWidget(parent, name) +{ + edit_ = new QLineEdit(this); + button_ = new KPushButton(this); + button_->setPixmap(SmallIcon("fileopen")); + connect(button_,SIGNAL(clicked()),SLOT(buttonClicked())); + + QHBoxLayout *main_ = new QHBoxLayout(this, 0, 3); + main_->addWidget(edit_); + main_->addWidget(button_); + + fileedit_ = file; +} + +QDirLineEdit::~QDirLineEdit() +{ +} + +void QDirLineEdit::setURL(const QString& txt) +{ + edit_->setText(txt); +} + +QString QDirLineEdit::url() +{ + return edit_->text(); +} + +void QDirLineEdit::buttonClicked() +{ + QString dirname; + if (!fileedit_) + dirname = KFileDialog::getExistingDirectory(edit_->text(), this); + else + dirname = KFileDialog::getOpenFileName(edit_->text(), QString::null, this); + if (!dirname.isEmpty()) + edit_->setText(dirname); +} + +void QDirLineEdit::setFileEdit(bool on) +{ + fileedit_ = on; +} + +#include "qdirlineedit.moc" diff --git a/kdeprint/cups/cupsdconf2/qdirlineedit.h b/kdeprint/cups/cupsdconf2/qdirlineedit.h new file mode 100644 index 000000000..b4b977b75 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/qdirlineedit.h @@ -0,0 +1,49 @@ +/* + * 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. + **/ + +#ifndef QDIRLINEEDIT_H +#define QDIRLINEEDIT_H + +#include <qwidget.h> +#include <qstring.h> + +class QLineEdit; +class QPushButton; + +class QDirLineEdit : public QWidget +{ + Q_OBJECT +public: + QDirLineEdit(bool file, QWidget *parent = 0, const char *name = 0); + ~QDirLineEdit(); + + void setURL(const QString& txt); + QString url(); + void setFileEdit(bool on = true); + +private slots: + void buttonClicked(); + +private: + QLineEdit *edit_; + QPushButton *button_; + bool fileedit_; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/qdirmultilineedit.cpp b/kdeprint/cups/cupsdconf2/qdirmultilineedit.cpp new file mode 100644 index 000000000..31a544e91 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/qdirmultilineedit.cpp @@ -0,0 +1,109 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2001-2002 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 "qdirmultilineedit.h" + +#include <qlayout.h> +#include <qheader.h> +#include <qpushbutton.h> +#include <klistview.h> +#include <klocale.h> +#include <kfiledialog.h> +#include <kiconloader.h> + +QDirMultiLineEdit::QDirMultiLineEdit(QWidget *parent, const char *name) +: QWidget(parent, name) +{ + m_view = new KListView(this); + m_view->header()->hide(); + m_view->addColumn(""); + m_view->setFullWidth(true); + connect(m_view, SIGNAL(selectionChanged(QListViewItem*)), SLOT(slotSelected(QListViewItem*))); + + m_add = new QPushButton(this); + m_add->setPixmap(SmallIcon("folder_new")); + connect(m_add, SIGNAL(clicked()), SLOT(slotAddClicked())); + m_remove = new QPushButton(this); + m_remove->setPixmap(SmallIcon("editdelete")); + connect(m_remove, SIGNAL(clicked()), SLOT(slotRemoveClicked())); + m_remove->setEnabled(false); + + m_view->setFixedHeight(QMAX(m_view->fontMetrics().lineSpacing()*3+m_view->lineWidth()*2, m_add->sizeHint().height()*2)); + + QHBoxLayout *l0 = new QHBoxLayout(this, 0, 3); + QVBoxLayout *l1 = new QVBoxLayout(0, 0, 0); + l0->addWidget(m_view); + l0->addLayout(l1); + l1->addWidget(m_add); + l1->addWidget(m_remove); + l1->addStretch(1); +} + +QDirMultiLineEdit::~QDirMultiLineEdit() +{ +} + +void QDirMultiLineEdit::setURLs(const QStringList& urls) +{ + m_view->clear(); + for (QStringList::ConstIterator it=urls.begin(); it!=urls.end(); ++it) + addURL(*it); +} + +QStringList QDirMultiLineEdit::urls() +{ + QListViewItem *item = m_view->firstChild(); + QStringList l; + while (item) + { + l << item->text(0); + item = item->nextSibling(); + } + return l; +} + +void QDirMultiLineEdit::addURL(const QString& url) +{ + QListViewItem *item = new QListViewItem(m_view, url); + item->setRenameEnabled(0, true); +} + +void QDirMultiLineEdit::slotAddClicked() +{ + QString dirname = KFileDialog::getExistingDirectory(QString::null, this); + if (!dirname.isEmpty()) + addURL(dirname); +} + +void QDirMultiLineEdit::slotRemoveClicked() +{ + QListViewItem *item = m_view->currentItem(); + if (item) + { + delete item; + slotSelected(m_view->currentItem()); + } +} + +void QDirMultiLineEdit::slotSelected(QListViewItem *item) +{ + m_remove->setEnabled((item != NULL)); +} + +#include "qdirmultilineedit.moc" diff --git a/kdeprint/cups/cupsdconf2/qdirmultilineedit.h b/kdeprint/cups/cupsdconf2/qdirmultilineedit.h new file mode 100644 index 000000000..963292985 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/qdirmultilineedit.h @@ -0,0 +1,53 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2001-2002 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. + **/ + +#ifndef QDIRMULTILINEEDIT_H +#define QDIRMULTILINEEDIT_H + +#include <qwidget.h> + +class KListView; +class QListViewItem; +class QPushButton; + +class QDirMultiLineEdit : public QWidget +{ + Q_OBJECT + +public: + QDirMultiLineEdit(QWidget *parent = 0, const char *name = 0); + ~QDirMultiLineEdit(); + + void setURLs(const QStringList&); + QStringList urls(); + +protected: + void addURL(const QString&); + +private slots: + void slotAddClicked(); + void slotRemoveClicked(); + void slotSelected(QListViewItem*); + +private: + KListView *m_view; + QPushButton *m_add, *m_remove; +}; + +#endif diff --git a/kdeprint/cups/cupsdconf2/sizewidget.cpp b/kdeprint/cups/cupsdconf2/sizewidget.cpp new file mode 100644 index 000000000..c61996282 --- /dev/null +++ b/kdeprint/cups/cupsdconf2/sizewidget.cpp @@ -0,0 +1,83 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2002 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 "sizewidget.h" + +#include <qcombobox.h> +#include <qspinbox.h> +#include <qlayout.h> +#include <qregexp.h> +#include <klocale.h> + +SizeWidget::SizeWidget( QWidget *parent, const char *name ) + : QWidget( parent, name ) +{ + m_size = new QSpinBox( 0, 9999, 1, this ); + m_unit = new QComboBox( this ); + + m_unit->insertItem( i18n( "KB" ) ); + m_unit->insertItem( i18n( "MB" ) ); + m_unit->insertItem( i18n( "GB" ) ); + m_unit->insertItem( i18n( "Tiles" ) ); + m_unit->setCurrentItem( 1 ); + m_size->setSpecialValueText( i18n( "Unlimited" ) ); + + QHBoxLayout *l0 = new QHBoxLayout( this, 0, 5 ); + l0->addWidget( m_size, 1 ); + l0->addWidget( m_unit, 0 ); +} + +void SizeWidget::setSizeString( const QString& sz ) +{ + int p = sz.find( QRegExp( "\\D" ) ); + m_size->setValue( sz.left( p ).toInt() ); + switch( sz[ p ].latin1() ) + { + case 'k': p = 0; break; + default: + case 'm': p = 1; break; + case 'g': p = 2; break; + case 't': p = 3; break; + } + m_unit->setCurrentItem( p ); +} + +QString SizeWidget::sizeString() const +{ + QString result = QString::number( m_size->value() ); + switch ( m_unit->currentItem() ) + { + case 0: result.append( "k" ); break; + case 1: result.append( "m" ); break; + case 2: result.append( "g" ); break; + case 3: result.append( "t" ); break; + } + return result; +} + +void SizeWidget::setValue( int value ) +{ + m_size->setValue( value ); + m_unit->setCurrentItem( 1 ); +} + +int SizeWidget::value() const +{ + return m_size->value(); +} diff --git a/kdeprint/cups/cupsdconf2/sizewidget.h b/kdeprint/cups/cupsdconf2/sizewidget.h new file mode 100644 index 000000000..c7f6557df --- /dev/null +++ b/kdeprint/cups/cupsdconf2/sizewidget.h @@ -0,0 +1,43 @@ +/* + * This file is part of the KDE libraries + * Copyright (c) 2002 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. + **/ + +#ifndef SIZEWIDGET_H +#define SIZEWIDGET_H + +#include <qwidget.h> + +class QSpinBox; +class QComboBox; + +class SizeWidget : public QWidget +{ +public: + SizeWidget( QWidget *parent = 0, const char *name = 0 ); + + void setSizeString( const QString& sizeString ); + QString sizeString() const; + void setValue( int sz ); + int value() const; + +private: + QSpinBox *m_size; + QComboBox *m_unit; +}; + +#endif |