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

tdeprint

  • tdeprint
  • cups
kmcupsconfigwidget.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (c) 2001 Michael Goffioul <tdeprint@swing.be>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License version 2 as published by the Free Software Foundation.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this library; see the file COPYING.LIB. If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  **/
19 
20 #include "kmcupsconfigwidget.h"
21 #include "cupsinfos.h"
22 
23 #include <tqlabel.h>
24 #include <tqgroupbox.h>
25 #include <tqlineedit.h>
26 #include <tqcheckbox.h>
27 #include <tqlayout.h>
28 #include <tqpushbutton.h>
29 #include <tqvalidator.h>
30 
31 #include <tdelocale.h>
32 #include <kcursor.h>
33 #include <tdeconfig.h>
34 #include <kstringhandler.h>
35 
36 class PortValidator : public TQIntValidator
37 {
38 public:
39  PortValidator(TQWidget *parent, const char *name = 0);
40  virtual TQValidator::State validate(TQString&, int&) const;
41 };
42 
43 PortValidator::PortValidator(TQWidget *parent, const char *name)
44 : TQIntValidator(1, 65535, TQT_TQOBJECT(parent), name)
45 {
46 }
47 
48 TQValidator::State PortValidator::validate(TQString& txt, int&) const
49 {
50  bool ok(false);
51  int p = txt.toInt(&ok);
52  if (txt.isEmpty())
53  return TQValidator::Intermediate;
54  else if (ok && p >= bottom() && p <= top())
55  return TQValidator::Acceptable;
56  return TQValidator::Invalid;
57 }
58 
59 //******************************************************************************************
60 
61 KMCupsConfigWidget::KMCupsConfigWidget(TQWidget *parent, const char *name)
62 : TQWidget(parent,name)
63 {
64  // widget creation
65  TQGroupBox *m_hostbox = new TQGroupBox(0, Qt::Vertical, i18n("Server Information"), this);
66  TQGroupBox *m_loginbox = new TQGroupBox(0, Qt::Vertical, i18n("Account Information"), this);
67  TQLabel *m_hostlabel = new TQLabel(i18n("&Host:"), m_hostbox);
68  TQLabel *m_portlabel = new TQLabel(i18n("&Port:"), m_hostbox);
69  m_host = new TQLineEdit(m_hostbox);
70  m_port = new TQLineEdit(m_hostbox);
71  m_hostlabel->setBuddy(m_host);
72  m_portlabel->setBuddy(m_port);
73  m_port->setValidator(new PortValidator(m_port));
74  m_login = new TQLineEdit(m_loginbox);
75  TQLabel *m_loginlabel = new TQLabel(i18n("&User:"), m_loginbox);
76  TQLabel *m_passwordlabel = new TQLabel(i18n("Pass&word:"), m_loginbox);
77  m_password = new TQLineEdit(m_loginbox);
78  m_password->setEchoMode(TQLineEdit::Password);
79  m_savepwd = new TQCheckBox( i18n( "&Store password in configuration file" ), m_loginbox );
80  m_savepwd->setCursor( KCursor::handCursor() );
81  m_anonymous = new TQCheckBox(i18n("Use &anonymous access"), m_loginbox);
82  m_anonymous->setCursor(KCursor::handCursor());
83  m_loginlabel->setBuddy(m_login);
84  m_passwordlabel->setBuddy(m_password);
85 
86  // layout creation
87  TQVBoxLayout *lay0 = new TQVBoxLayout(this, 0, 10);
88  lay0->addWidget(m_hostbox,1);
89  lay0->addWidget(m_loginbox,1);
90  TQGridLayout *lay2 = new TQGridLayout(m_hostbox->layout(), 2, 2, 10);
91  lay2->setColStretch(1,1);
92  lay2->addWidget(m_hostlabel,0,0);
93  lay2->addWidget(m_portlabel,1,0);
94  lay2->addWidget(m_host,0,1);
95  lay2->addWidget(m_port,1,1);
96  TQGridLayout *lay3 = new TQGridLayout(m_loginbox->layout(), 4, 2, 10);
97  lay3->setColStretch(1,1);
98  lay3->addWidget(m_loginlabel,0,0);
99  lay3->addWidget(m_passwordlabel,1,0);
100  lay3->addWidget(m_login,0,1);
101  lay3->addWidget(m_password,1,1);
102  lay3->addMultiCellWidget(m_savepwd,2,2,0,1);
103  lay3->addMultiCellWidget(m_anonymous,3,3,0,1);
104 
105  // connections
106  connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_login,TQT_SLOT(setDisabled(bool)));
107  connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_password,TQT_SLOT(setDisabled(bool)));
108  connect(m_anonymous,TQT_SIGNAL(toggled(bool)),m_savepwd,TQT_SLOT(setDisabled(bool)));
109 }
110 
111 void KMCupsConfigWidget::load()
112 {
113  CupsInfos *inf = CupsInfos::self();
114  m_host->setText(inf->host());
115  m_port->setText(TQString::number(inf->port()));
116  if (inf->login().isEmpty())
117  m_anonymous->setChecked(true);
118  else
119  {
120  m_login->setText(inf->login());
121  m_password->setText(inf->password());
122  m_savepwd->setChecked( inf->savePassword() );
123  }
124 }
125 
126 void KMCupsConfigWidget::save(bool sync)
127 {
128  CupsInfos *inf = CupsInfos::self();
129  inf->setHost(m_host->text());
130  inf->setPort(m_port->text().toInt());
131  if (m_anonymous->isChecked())
132  {
133  inf->setLogin(TQString::null);
134  inf->setPassword(TQString::null);
135  inf->setSavePassword( false );
136  }
137  else
138  {
139  inf->setLogin(m_login->text());
140  inf->setPassword(m_password->text());
141  inf->setSavePassword( m_savepwd->isChecked() );
142  }
143  if (sync) inf->save();
144 }
145 
146 void KMCupsConfigWidget::saveConfig(TDEConfig *conf)
147 {
148  conf->setGroup("CUPS");
149  conf->writeEntry("Host",m_host->text());
150  conf->writeEntry("Port",m_port->text().toInt());
151  conf->writeEntry("Login",(m_anonymous->isChecked() ? TQString::null : m_login->text()));
152  conf->writeEntry( "SavePassword", ( m_anonymous->isChecked() ? false : m_savepwd->isChecked() ) );
153  if ( m_savepwd->isChecked() && !m_anonymous->isChecked() )
154  conf->writeEntry( "Password", ( m_anonymous->isChecked() ? TQString::null : KStringHandler::obscure( m_password->text() ) ) );
155  else
156  conf->deleteEntry( "Password" );
157  // synchronize CupsInfos object
158  save(false);
159 }

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
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeprint by doxygen 1.8.8
This website is maintained by Timothy Pearson.