20 #include "cupsinfos.h"
21 #include "kmfactory.h"
23 #include "messagewindow.h"
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>
32 #include <kstringhandler.h>
34 #include <cups/cups.h>
37 const char* cupsGetPasswordCB(
const char*)
39 return CupsInfos::self()->getPasswordCB();
42 CupsInfos* CupsInfos::unique_ = 0;
44 CupsInfos* CupsInfos::self()
48 unique_ =
new CupsInfos();
53 CupsInfos::CupsInfos()
54 : KPReloadObject(true)
65 cupsSetPasswordCB(cupsGetPasswordCB);
68 CupsInfos::~CupsInfos()
72 TQString CupsInfos::hostaddr()
const
75 return host_ +
":" + TQString::number(port_);
79 void CupsInfos::setHost(
const TQString& s)
82 cupsSetServer(s.latin1());
85 void CupsInfos::setPort(
int p)
91 void CupsInfos::setLogin(
const TQString& s)
94 cupsSetUser(s.latin1());
97 void CupsInfos::setPassword(
const TQString& s)
102 void CupsInfos::setSavePassword(
bool on )
107 const char* CupsInfos::getPasswordCB()
109 TQPair<TQString,TQString> pwd = KMFactory::self()->requestPassword( count_, login_, host_, port_ );
111 if ( pwd.first.isEmpty() && pwd.second.isEmpty() )
113 setLogin( pwd.first );
114 setPassword( pwd.second );
115 return pwd.second.latin1();
118 void CupsInfos::load()
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 );
128 password_ = KStringHandler::obscure( conf_->readEntry(
"Password" ) );
129 KMFactory::self()->initPassword( login_, password_, host_, port_ );
132 password_ = TQString();
133 if (login_.isEmpty()) login_ = TQString();
134 reallogin_ = cupsUser();
137 cupsSetServer(host_.latin1());
138 cupsSetUser(login_.latin1());
142 void CupsInfos::save()
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_ );
151 conf_->writeEntry(
"Password", KStringHandler::obscure( password_ ) );
153 conf_->deleteEntry(
"Password" );
157 void CupsInfos::reload()
162 void CupsInfos::configChanged()