00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#include "cupsinfos.h"
00021
#include "kmfactory.h"
00022
#include "kmtimer.h"
00023
#include "messagewindow.h"
00024
00025
#include <kio/passdlg.h>
00026
#include <kio/authinfo.h>
00027
#include <klocale.h>
00028
#include <kconfig.h>
00029
#include <kapplication.h>
00030
#include <dcopclient.h>
00031
#include <kdebug.h>
00032
#include <kstringhandler.h>
00033
00034
#include <cups/cups.h>
00035
#include <cups/ipp.h>
00036
00037
const char* cupsGetPasswordCB(
const char*)
00038 {
00039
return CupsInfos::self()->getPasswordCB();
00040 }
00041
00042 CupsInfos* CupsInfos::unique_ = 0;
00043
00044 CupsInfos* CupsInfos::self()
00045 {
00046
if (!unique_)
00047 {
00048 unique_ =
new CupsInfos();
00049 }
00050
return unique_;
00051 }
00052
00053 CupsInfos::CupsInfos()
00054 : KPReloadObject(true)
00055 {
00056 count_ = 0;
00057
00058 load();
00059
00060
00061
00062
00063
00064
00065 cupsSetPasswordCB(cupsGetPasswordCB);
00066 }
00067
00068 CupsInfos::~CupsInfos()
00069 {
00070 }
00071
00072
void CupsInfos::setHost(
const QString& s)
00073 {
00074 host_ = s;
00075 cupsSetServer(s.latin1());
00076 }
00077
00078
void CupsInfos::setPort(
int p)
00079 {
00080 port_ = p;
00081 ippSetPort(p);
00082 }
00083
00084
void CupsInfos::setLogin(
const QString& s)
00085 {
00086 login_ = s;
00087 cupsSetUser(s.latin1());
00088 }
00089
00090
void CupsInfos::setPassword(
const QString& s)
00091 {
00092 password_ = s;
00093 }
00094
00095
void CupsInfos::setSavePassword(
bool on )
00096 {
00097 savepwd_ = on;
00098 }
00099
00100
const char* CupsInfos::getPasswordCB()
00101 {
00102
QPair<QString,QString> pwd = KMFactory::self()->requestPassword( count_, login_, host_, port_ );
00103
00104
if ( pwd.first.isEmpty() && pwd.second.isEmpty() )
00105
return NULL;
00106 setLogin( pwd.first );
00107 setPassword( pwd.second );
00108
return pwd.second.latin1();
00109 }
00110
00111
void CupsInfos::load()
00112 {
00113 KConfig *conf_ = KMFactory::self()->printConfig();
00114 conf_->setGroup(
"CUPS");
00115 host_ = conf_->readEntry(
"Host",QString::fromLatin1(cupsServer()));
00116 port_ = conf_->readNumEntry(
"Port",ippPort());
00117 login_ = conf_->readEntry(
"Login",QString::fromLatin1(cupsUser()));
00118 savepwd_ = conf_->readBoolEntry(
"SavePassword",
false );
00119
if ( savepwd_ )
00120 {
00121 password_ = KStringHandler::obscure( conf_->readEntry(
"Password" ) );
00122 KMFactory::self()->initPassword( login_, password_, host_, port_ );
00123 }
00124
else
00125 password_ = QString::null;
00126
if (login_.isEmpty()) login_ = QString::null;
00127 reallogin_ = cupsUser();
00128
00129
00130 cupsSetServer(host_.latin1());
00131 cupsSetUser(login_.latin1());
00132 ippSetPort(port_);
00133 }
00134
00135
void CupsInfos::save()
00136 {
00137 KConfig *conf_ = KMFactory::self()->printConfig();
00138 conf_->setGroup(
"CUPS");
00139 conf_->writeEntry(
"Host",host_);
00140 conf_->writeEntry(
"Port",port_);
00141 conf_->writeEntry(
"Login",login_);
00142 conf_->writeEntry(
"SavePassword", savepwd_ );
00143
if ( savepwd_ )
00144 conf_->writeEntry(
"Password", KStringHandler::obscure( password_ ) );
00145
else
00146 conf_->deleteEntry(
"Password" );
00147 conf_->sync();
00148 }
00149
00150
void CupsInfos::reload()
00151 {
00152
00153 }
00154
00155
void CupsInfos::configChanged()
00156 {
00157
00158 load();
00159 }