kdeprint Library API Documentation

cupsdnetworkclientspage.cpp

00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017  *  Boston, MA 02111-1307, USA.
00018  **/
00019 
00020 #include "cupsdnetworkclientspage.h"
00021 
00022 #include <qlineedit.h>
00023 #include <klocale.h>
00024 #include <qlayout.h>
00025 #include <qlabel.h>
00026 #include <qcheckbox.h>
00027 #include <qframe.h>
00028 #include <qwhatsthis.h>
00029 
00030 #include "cupsdconf.h"
00031 #include "cupsdoption.h"
00032 
00033 CupsdNetworkClientsPage::CupsdNetworkClientsPage(QWidget *parent, const char *name)
00034     : CupsdPage(parent, name)
00035 {
00036     path_.append(i18n("Network"));
00037     path_.append(i18n("Clients"));
00038     header_ = i18n("Network Clients Configuration");
00039 
00040     for (int i=0;i<3;i++)
00041         opt_[i] = new CupsdOption(this);
00042 
00043     keepalive_ = new QCheckBox(i18n("Accept \"Keep Alive\" requests"), opt_[0]);
00044     keepalivetimeout_ = new QLineEdit(opt_[1]);
00045     maxclients_ = new QLineEdit(opt_[2]);
00046 
00047     QLabel  *l1 = new QLabel(i18n("Keep alive timeout:"), this);
00048     QLabel  *l2 = new QLabel(i18n("Max number of clients:"), this);
00049 
00050     QGridLayout *main_ = new QGridLayout(this, 6, 2, 10, 10);
00051     main_->addWidget(deflabel_, 0, 1, Qt::AlignRight|Qt::AlignVCenter);
00052     main_->addMultiCellWidget(opt_[0], 1, 1, 0, 1);
00053     main_->addWidget(opt_[1], 2, 1);
00054     main_->addWidget(opt_[2], 4, 1);
00055     main_->addWidget(l1, 2, 0);
00056     main_->addWidget(l2, 4, 0);
00057     main_->setRowStretch(5, 1);
00058     main_->addRowSpacing(3, 20);
00059 }
00060 
00061 CupsdNetworkClientsPage::~CupsdNetworkClientsPage()
00062 {
00063 }
00064 
00065 bool CupsdNetworkClientsPage::loadConfig(CupsdConf *conf, QString&)
00066 {
00067     conf_ = conf;
00068     if (conf->keepalive_ != -1)
00069     {
00070         opt_[0]->setDefault(false);
00071         keepalive_->setChecked(conf->keepalive_ == 1);
00072     }
00073     if (conf->keepalivetimeout_ != -1)
00074     {
00075         opt_[1]->setDefault(false);
00076         keepalivetimeout_->setText(QString::number(conf->keepalivetimeout_));
00077     }
00078     if (conf->maxclients_ != -1)
00079     {
00080         opt_[2]->setDefault(false);
00081         maxclients_->setText(QString::number(conf->maxclients_));
00082     }
00083     return true;
00084 }
00085 
00086 bool CupsdNetworkClientsPage::saveConfig(CupsdConf *conf, QString& msg)
00087 {
00088     bool    ok;
00089     int v;
00090     if (!opt_[0]->isDefault()) conf->keepalive_ = (keepalive_->isChecked() ? 1 : 0);
00091     if (!opt_[1]->isDefault() && !keepalivetimeout_->text().isNull())
00092     {
00093         v = keepalivetimeout_->text().toInt(&ok);
00094         if (ok) conf->keepalivetimeout_ = v;
00095         else
00096         {
00097             msg = i18n("%1 wrong argument").arg(i18n("Keep alive timeout:"));
00098             return false;
00099         }
00100     }
00101     if (!opt_[2]->isDefault() && !maxclients_->text().isNull())
00102     {
00103         v = maxclients_->text().toInt(&ok);
00104         if (ok) conf->maxclients_ = v;
00105         else
00106         {
00107             msg = i18n("%1 wrong argument").arg(i18n("Max number of clients:"));
00108             return false;
00109         }
00110     }
00111     return true;
00112 }
00113 
00114 void CupsdNetworkClientsPage::setDefaults()
00115 {
00116     keepalive_->setChecked(true);
00117     keepalivetimeout_->setText("60");
00118     maxclients_->setText("100");
00119 }
00120 
00121 void CupsdNetworkClientsPage::setInfos(CupsdConf *conf)
00122 {
00123         QWhatsThis::add(keepalive_, conf->comments_.toolTip(KEEPALIVE_COMM));
00124         QWhatsThis::add(keepalivetimeout_, conf->comments_.toolTip(KEEPALIVETIMEOUT_COMM));
00125         QWhatsThis::add(maxclients_, conf->comments_.toolTip(MAXCLIENTS_COMM));
00126 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Mar 3 19:24:20 2005 by doxygen 1.3.6 written by Dimitri van Heesch, © 1997-2003