| # kdeprint Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# cupsinfos.cpp

    00001 /*
    00002  *  This file is part of the KDE libraries
    00003  *  Copyright (c) 2001 Michael Goffioul <kdeprint@swing.be>
    00004  *
    00005  *  This library is free software; you can redistribute it and/or
    00006  *  modify it under the terms of the GNU Library General Public
    00007  *  License version 2 as published by the Free Software Foundation.
    00008  *
    00009  *  This library is distributed in the hope that it will be useful,
    00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012  *  Library General Public License for more details.
    00013  *
    00014  *  You should have received a copy of the GNU Library General Public License
    00015  *  along with this library; see the file COPYING.LIB.  If not, write to
    00016  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017  *  Boston, MA 02111-1307, USA.
    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 /*  host_ = cupsServer();
    00060     login_ = cupsUser();
    00061     if (login_.isEmpty()) login_ = QString::null;
    00062     port_ = ippPort();
    00063     password_ = QString::null;*/
    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     // synchronize with CUPS
    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     // do nothing, but needs to be implemented
    00153 }
    00154
    00155 void CupsInfos::configChanged()
    00156 {
    00157     // we need to reload settings
    00158     load();
    00159 }

This file is part of the documentation for kdeprint Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:31:01 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003