• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

KDEPrint

cupsinfos.cpp

Go to the documentation of this file.
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., 51 Franklin Street, Fifth Floor,
00017  *  Boston, MA 02110-1301, USA.
00018  **/
00019 
00020 #include "cupsinfos.h"
00021 #include "kmfactory.h"
00022 #include "kmtimer.h"
00023 #include "messagewindow.h"
00024 
00025 #include <kio/authinfo.h>
00026 #include <klocale.h>
00027 #include <kconfig.h>
00028 #include <kapplication.h>
00029 #include <kdebug.h>
00030 #include <kstringhandler.h>
00031 
00032 #include <cups/cups.h>
00033 #include <cups/ipp.h>
00034 
00035 const char* cupsGetPasswordCB(const char*)
00036 {
00037     return CupsInfos::self()->getPasswordCB();
00038 }
00039 
00040 CupsInfos* CupsInfos::unique_ = 0;
00041 
00042 CupsInfos* CupsInfos::self()
00043 {
00044     if (!unique_) {
00045         unique_ = new CupsInfos();
00046     }
00047     return unique_;
00048 }
00049 
00050 CupsInfos::CupsInfos()
00051         : KPReloadObject(true)
00052 {
00053     count_ = 0;
00054 
00055     load();
00056     /* host_ = cupsServer();
00057      login_ = cupsUser();
00058      if (login_.isEmpty()) login_.clear();
00059      port_ = ippPort();
00060      password_.clear();*/
00061 
00062     cupsSetPasswordCB(cupsGetPasswordCB);
00063 }
00064 
00065 CupsInfos::~CupsInfos()
00066 {
00067 }
00068 
00069 void CupsInfos::setHost(const QString& s)
00070 {
00071     host_ = s;
00072     cupsSetServer(qPrintable(s));
00073 }
00074 
00075 void CupsInfos::setPort(int p)
00076 {
00077     port_ = p;
00078     ippSetPort(p);
00079 }
00080 
00081 void CupsInfos::setLogin(const QString& s)
00082 {
00083     login_ = s;
00084     cupsSetUser(qPrintable(s));
00085 }
00086 
00087 void CupsInfos::setPassword(const QString& s)
00088 {
00089     password_ = s;
00090 }
00091 
00092 void CupsInfos::setSavePassword(bool on)
00093 {
00094     savepwd_ = on;
00095 }
00096 
00097 const char* CupsInfos::getPasswordCB()
00098 {
00099     QPair<QString, QString> pwd = KMFactory::self()->requestPassword(count_, login_, host_, port_);
00100 
00101     if (pwd.first.isEmpty() && pwd.second.isEmpty())
00102         return NULL;
00103     setLogin(pwd.first);
00104     setPassword(pwd.second);
00105     return qPrintable(pwd.second);
00106 }
00107 
00108 void CupsInfos::load()
00109 {
00110     KConfig *cf = KMFactory::self()->printConfig();
00111 
00112     KConfigGroup conf_ = cf->group("CUPS");
00113     host_ = conf_.readEntry("Host", cupsServer());
00114     port_ = conf_.readEntry("Port", ippPort());
00115     login_ = conf_.readEntry("Login", cupsUser());
00116     savepwd_ = conf_.readEntry("SavePassword", false);
00117     if (savepwd_) {
00118         password_ = KStringHandler::obscure(conf_.readEntry("Password"));
00119         KMFactory::self()->initPassword(login_, password_, host_, port_);
00120     } else
00121         password_.clear();
00122     if (login_.isEmpty()) login_.clear();
00123     reallogin_ = cupsUser();
00124 
00125     // synchronize with CUPS
00126     cupsSetServer(qPrintable(host_));
00127     cupsSetUser(qPrintable(login_));
00128     ippSetPort(port_);
00129 }
00130 
00131 void CupsInfos::save()
00132 {
00133     KConfig *cf = KMFactory::self()->printConfig();
00134     KConfigGroup conf_ = cf->group("CUPS");
00135     conf_.writeEntry("Host", host_);
00136     conf_.writeEntry("Port", port_);
00137     conf_.writeEntry("Login", login_);
00138     conf_.writeEntry("SavePassword", savepwd_);
00139     if (savepwd_)
00140         conf_.writeEntry("Password", KStringHandler::obscure(password_));
00141     else
00142         conf_.deleteEntry("Password");
00143     conf_.sync();
00144 }
00145 
00146 void CupsInfos::reload()
00147 {
00148     // do nothing, but needs to be implemented
00149 }
00150 
00151 void CupsInfos::configChanged()
00152 {
00153     // we need to reload settings
00154     load();
00155 }
00156 
00157 const QString CupsInfos::hostaddr() const
00158 {
00159     if (host_[0] != '/')
00160         return QString("%1:%2")
00161                .arg(host_)
00162                .arg(port_);
00163     else
00164         return QString("%1")
00165                .arg(host_);
00166 }
00167 
00168 const QString CupsInfos::ippaddr() const
00169 {
00170     if (host_[0] != '/')
00171         return QString("%1:%2")
00172                .arg(host_)
00173                .arg(port_);
00174     else
00175         return QString("localhost");
00176 }

KDEPrint

Skip menu "KDEPrint"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  •   KDEPrint
Generated for API Reference by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal