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

tdeprint

  • tdeprint
  • cups
cupsinfos.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 "cupsinfos.h"
21 #include "kmfactory.h"
22 #include "kmtimer.h"
23 #include "messagewindow.h"
24 
25 #include <tdeio/passdlg.h>
26 #include <tdeio/authinfo.h>
27 #include <tdelocale.h>
28 #include <tdeconfig.h>
29 #include <tdeapplication.h>
30 #include <dcopclient.h>
31 #include <kdebug.h>
32 #include <kstringhandler.h>
33 
34 #include <cups/cups.h>
35 #include <cups/ipp.h>
36 
37 const char* cupsGetPasswordCB(const char*)
38 {
39  return CupsInfos::self()->getPasswordCB();
40 }
41 
42 CupsInfos* CupsInfos::unique_ = 0;
43 
44 CupsInfos* CupsInfos::self()
45 {
46  if (!unique_)
47  {
48  unique_ = new CupsInfos();
49  }
50  return unique_;
51 }
52 
53 CupsInfos::CupsInfos()
54 : KPReloadObject(true)
55 {
56  count_ = 0;
57 
58  load();
59 /* host_ = cupsServer();
60  login_ = cupsUser();
61  if (login_.isEmpty()) login_ = TQString();
62  port_ = ippPort();
63  password_ = TQString();*/
64 
65  cupsSetPasswordCB(cupsGetPasswordCB);
66 }
67 
68 CupsInfos::~CupsInfos()
69 {
70 }
71 
72 TQString CupsInfos::hostaddr() const
73 {
74  if (host_[0] != '/')
75  return host_ + ":" + TQString::number(port_);
76  return "localhost";
77 }
78 
79 void CupsInfos::setHost(const TQString& s)
80 {
81  host_ = s;
82  cupsSetServer(s.latin1());
83 }
84 
85 void CupsInfos::setPort(int p)
86 {
87  port_ = p;
88  ippSetPort(p);
89 }
90 
91 void CupsInfos::setLogin(const TQString& s)
92 {
93  login_ = s;
94  cupsSetUser(s.latin1());
95 }
96 
97 void CupsInfos::setPassword(const TQString& s)
98 {
99  password_ = s;
100 }
101 
102 void CupsInfos::setSavePassword( bool on )
103 {
104  savepwd_ = on;
105 }
106 
107 const char* CupsInfos::getPasswordCB()
108 {
109  TQPair<TQString,TQString> pwd = KMFactory::self()->requestPassword( count_, login_, host_, port_ );
110 
111  if ( pwd.first.isEmpty() && pwd.second.isEmpty() )
112  return NULL;
113  setLogin( pwd.first );
114  setPassword( pwd.second );
115  return pwd.second.latin1();
116 }
117 
118 void CupsInfos::load()
119 {
120  TDEConfig *conf_ = KMFactory::self()->printConfig();
121  conf_->setGroup("CUPS");
122  host_ = conf_->readEntry("Host",TQString::fromLatin1(cupsServer()));
123  port_ = conf_->readNumEntry("Port",ippPort());
124  login_ = conf_->readEntry("Login",TQString::fromLatin1(cupsUser()));
125  savepwd_ = conf_->readBoolEntry( "SavePassword", false );
126  if ( savepwd_ )
127  {
128  password_ = KStringHandler::obscure( conf_->readEntry( "Password" ) );
129  KMFactory::self()->initPassword( login_, password_, host_, port_ );
130  }
131  else
132  password_ = TQString();
133  if (login_.isEmpty()) login_ = TQString();
134  reallogin_ = cupsUser();
135 
136  // synchronize with CUPS
137  cupsSetServer(host_.latin1());
138  cupsSetUser(login_.latin1());
139  ippSetPort(port_);
140 }
141 
142 void CupsInfos::save()
143 {
144  TDEConfig *conf_ = KMFactory::self()->printConfig();
145  conf_->setGroup("CUPS");
146  conf_->writeEntry("Host",host_);
147  conf_->writeEntry("Port",port_);
148  conf_->writeEntry("Login",login_);
149  conf_->writeEntry( "SavePassword", savepwd_ );
150  if ( savepwd_ )
151  conf_->writeEntry( "Password", KStringHandler::obscure( password_ ) );
152  else
153  conf_->deleteEntry( "Password" );
154  conf_->sync();
155 }
156 
157 void CupsInfos::reload()
158 {
159  // do nothing, but needs to be implemented
160 }
161 
162 void CupsInfos::configChanged()
163 {
164  // we need to reload settings
165  load();
166 }

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.