• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeprint
 

tdeprint

kmcupsconfigwidget.cpp
00001 /*
00002  *  This file is part of the KDE libraries
00003  *  Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
00004  *
00005  *  This library is free software; you can redistribute it and/or
00006  *  modify it under the terms of the GNU Library General Public
00007  *  License version 2 as published by the Free Software Foundation.
00008  *
00009  *  This library is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  *  Library General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU Library General Public License
00015  *  along with this library; see the file COPYING.LIB.  If not, write to
00016  *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "kmcupsconfigwidget.h"
00021 #include "cupsinfos.h"
00022 
00023 #include <tqlabel.h>
00024 #include <tqgroupbox.h>
00025 #include <tqlineedit.h>
00026 #include <tqcheckbox.h>
00027 #include <tqlayout.h>
00028 #include <tqpushbutton.h>
00029 #include <tqvalidator.h>
00030 
00031 #include <tdelocale.h>
00032 #include <kcursor.h>
00033 #include <tdeconfig.h>
00034 #include <kstringhandler.h>
00035 
00036 class PortValidator : public TQIntValidator
00037 {
00038 public:
00039     PortValidator(TQWidget *parent, const char *name = 0);
00040     virtual TQValidator::State validate(TQString&, int&) const;
00041 };
00042 
00043 PortValidator::PortValidator(TQWidget *parent, const char *name)
00044 : TQIntValidator(1, 65535, TQT_TQOBJECT(parent), name)
00045 {
00046 }
00047 
00048 TQValidator::State PortValidator::validate(TQString& txt, int&) const
00049 {
00050     bool    ok(false);
00051     int     p = txt.toInt(&ok);
00052     if (txt.isEmpty())
00053         return TQValidator::Intermediate;
00054     else if (ok && p >= bottom() && p <= top())
00055         return TQValidator::Acceptable;
00056     return TQValidator::Invalid;
00057 }
00058 
00059 //******************************************************************************************
00060 
00061 KMCupsConfigWidget::KMCupsConfigWidget(TQWidget *parent, const char *name)
00062 : TQWidget(parent,name)
00063 {
00064     // widget creation
00065     TQGroupBox  *m_hostbox = new TQGroupBox(0, Qt::Vertical, i18n("Server Information"), this);
00066     TQGroupBox  *m_loginbox = new TQGroupBox(0, Qt::Vertical, i18n("Account Information"), this);
00067     TQLabel *m_hostlabel = new TQLabel(i18n("&Host:"), m_hostbox);
00068     TQLabel *m_portlabel = new TQLabel(i18n("&Port:"), m_hostbox);
00069     m_host = new TQLineEdit(m_hostbox);
00070     m_port = new TQLineEdit(m_hostbox);
00071     m_hostlabel->setBuddy(m_host);
00072     m_portlabel->setBuddy(m_port);
00073     m_port->setValidator(new PortValidator(m_port));
00074     m_login = new TQLineEdit(m_loginbox);
00075     TQLabel *m_loginlabel = new TQLabel(i18n("&User:"), m_loginbox);
00076     TQLabel *m_passwordlabel = new TQLabel(i18n("Pass&word:"), m_loginbox);
00077     m_password = new TQLineEdit(m_loginbox);
00078     m_password->setEchoMode(TQLineEdit::Password);
00079     m_savepwd = new TQCheckBox( i18n( "&Store password in configuration file" ), m_loginbox );
00080     m_savepwd->setCursor( KCursor::handCursor() );
00081     m_anonymous = new TQCheckBox(i18n("Use &anonymous access"), m_loginbox);
00082     m_anonymous->setCursor(KCursor::handCursor());
00083     m_loginlabel->setBuddy(m_login);
00084     m_passwordlabel->setBuddy(m_password);
00085 
00086     // layout creation
00087     TQVBoxLayout    *lay0 = new TQVBoxLayout(this, 0, 10);
00088     lay0->addWidget(m_hostbox,1);
00089     lay0->addWidget(m_loginbox,1);
00090     TQGridLayout    *lay2 = new TQGridLayout(m_hostbox->layout(), 2, 2, 10);
00091     lay2->setColStretch(1,1);
00092     lay2->addWidget(m_hostlabel,0,0);
00093     lay2->addWidget(m_portlabel,1,0);
00094     lay2->addWidget(m_host,0,1);
00095     lay2->addWidget(m_port,1,1);
00096     TQGridLayout    *lay3 = new TQGridLayout(m_loginbox->layout(), 4, 2, 10);
00097     lay3->setColStretch(1,1);
00098     lay3->addWidget(m_loginlabel,0,0);
00099     lay3->addWidget(m_passwordlabel,1,0);
00100     lay3->addWidget(m_login,0,1);
00101     lay3->addWidget(m_password,1,1);
00102     lay3->addMultiCellWidget(m_savepwd,2,2,0,1);
00103     lay3->addMultiCellWidget(m_anonymous,3,3,0,1);
00104 
00105     // connections
00106     connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_login,TQT_SLOT(setDisabled(bool)));
00107     connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_password,TQT_SLOT(setDisabled(bool)));
00108     connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_savepwd,TQT_SLOT(setDisabled(bool)));
00109 }
00110 
00111 void KMCupsConfigWidget::load()
00112 {
00113     CupsInfos   *inf = CupsInfos::self();
00114     m_host->setText(inf->host());
00115     m_port->setText(TQString::number(inf->port()));
00116     if (inf->login().isEmpty())
00117         m_anonymous->setChecked(true);
00118     else
00119     {
00120         m_login->setText(inf->login());
00121         m_password->setText(inf->password());
00122         m_savepwd->setChecked( inf->savePassword() );
00123     }
00124 }
00125 
00126 void KMCupsConfigWidget::save(bool sync)
00127 {
00128     CupsInfos   *inf = CupsInfos::self();
00129     inf->setHost(m_host->text());
00130     inf->setPort(m_port->text().toInt());
00131     if (m_anonymous->isChecked())
00132     {
00133         inf->setLogin(TQString::null);
00134         inf->setPassword(TQString::null);
00135         inf->setSavePassword( false );
00136     }
00137     else
00138     {
00139         inf->setLogin(m_login->text());
00140         inf->setPassword(m_password->text());
00141         inf->setSavePassword( m_savepwd->isChecked() );
00142     }
00143     if (sync) inf->save();
00144 }
00145 
00146 void KMCupsConfigWidget::saveConfig(TDEConfig *conf)
00147 {
00148     conf->setGroup("CUPS");
00149     conf->writeEntry("Host",m_host->text());
00150     conf->writeEntry("Port",m_port->text().toInt());
00151     conf->writeEntry("Login",(m_anonymous->isChecked() ? TQString::null : m_login->text()));
00152     conf->writeEntry( "SavePassword", ( m_anonymous->isChecked() ? false : m_savepwd->isChecked() ) );
00153     if ( m_savepwd->isChecked() && !m_anonymous->isChecked() )
00154         conf->writeEntry( "Password", ( m_anonymous->isChecked() ? TQString::null : KStringHandler::obscure( m_password->text() ) ) );
00155     else
00156         conf->deleteEntry( "Password" );
00157     // synchronize CupsInfos object
00158     save(false);
00159 }

tdeprint

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

tdeprint

Skip menu "tdeprint"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.