cupsinfos.cpp00001
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 QString CupsInfos::hostaddr() const
00073 {
00074 if (host_[0] != '/')
00075 return host_ + ":" + QString::number(port_);
00076 return "localhost";
00077 }
00078
00079 void CupsInfos::setHost(const QString& s)
00080 {
00081 host_ = s;
00082 cupsSetServer(s.latin1());
00083 }
00084
00085 void CupsInfos::setPort(int p)
00086 {
00087 port_ = p;
00088 ippSetPort(p);
00089 }
00090
00091 void CupsInfos::setLogin(const QString& s)
00092 {
00093 login_ = s;
00094 cupsSetUser(s.latin1());
00095 }
00096
00097 void CupsInfos::setPassword(const QString& s)
00098 {
00099 password_ = s;
00100 }
00101
00102 void CupsInfos::setSavePassword( bool on )
00103 {
00104 savepwd_ = on;
00105 }
00106
00107 const char* CupsInfos::getPasswordCB()
00108 {
00109 QPair<QString,QString> pwd = KMFactory::self()->requestPassword( count_, login_, host_, port_ );
00110
00111 if ( pwd.first.isEmpty() && pwd.second.isEmpty() )
00112 return NULL;
00113 setLogin( pwd.first );
00114 setPassword( pwd.second );
00115 return pwd.second.latin1();
00116 }
00117
00118 void CupsInfos::load()
00119 {
00120 KConfig *conf_ = KMFactory::self()->printConfig();
00121 conf_->setGroup("CUPS");
00122 host_ = conf_->readEntry("Host",QString::fromLatin1(cupsServer()));
00123 port_ = conf_->readNumEntry("Port",ippPort());
00124 login_ = conf_->readEntry("Login",QString::fromLatin1(cupsUser()));
00125 savepwd_ = conf_->readBoolEntry( "SavePassword", false );
00126 if ( savepwd_ )
00127 {
00128 password_ = KStringHandler::obscure( conf_->readEntry( "Password" ) );
00129 KMFactory::self()->initPassword( login_, password_, host_, port_ );
00130 }
00131 else
00132 password_ = QString::null;
00133 if (login_.isEmpty()) login_ = QString::null;
00134 reallogin_ = cupsUser();
00135
00136
00137 cupsSetServer(host_.latin1());
00138 cupsSetUser(login_.latin1());
00139 ippSetPort(port_);
00140 }
00141
00142 void CupsInfos::save()
00143 {
00144 KConfig *conf_ = KMFactory::self()->printConfig();
00145 conf_->setGroup("CUPS");
00146 conf_->writeEntry("Host",host_);
00147 conf_->writeEntry("Port",port_);
00148 conf_->writeEntry("Login",login_);
00149 conf_->writeEntry( "SavePassword", savepwd_ );
00150 if ( savepwd_ )
00151 conf_->writeEntry( "Password", KStringHandler::obscure( password_ ) );
00152 else
00153 conf_->deleteEntry( "Password" );
00154 conf_->sync();
00155 }
00156
00157 void CupsInfos::reload()
00158 {
00159
00160 }
00161
00162 void CupsInfos::configChanged()
00163 {
00164
00165 load();
00166 }
|