kdeprint Library API Documentation

lprsettings.cpp

00001 /* 00002 * This file is part of the KDE libraries 00003 * Copyright (c) 2001,2002 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 "lprsettings.h" 00021 #include "kmmanager.h" 00022 #include "kmfactory.h" 00023 00024 #include <kconfig.h> 00025 #include <qfile.h> 00026 #include <qtextstream.h> 00027 00028 #define LPDCONF "/etc/lpd.conf" 00029 #define PRINTCAP "/etc/printcap" 00030 00031 LprSettings* LprSettings::m_self = 0; 00032 00033 LprSettings::LprSettings(QObject *parent, const char *name) 00034 : QObject(parent, name), KPReloadObject(true) 00035 { 00036 init(); 00037 } 00038 00039 LprSettings::~LprSettings() 00040 { 00041 m_self = 0; 00042 } 00043 00044 LprSettings* LprSettings::self() 00045 { 00046 if (!m_self) 00047 { 00048 m_self = new LprSettings(KMManager::self(), "LprSettings"); 00049 } 00050 return m_self; 00051 } 00052 00053 void LprSettings::init() 00054 { 00055 // LPR/LPRng mode 00056 KConfig *conf = KMFactory::self()->printConfig(); 00057 conf->setGroup("LPR"); 00058 QString modestr = conf->readEntry("Mode"); 00059 if (modestr == "LPRng") 00060 m_mode = LPRng; 00061 else if (modestr == "LPR") 00062 m_mode = LPR; 00063 else 00064 { 00065 // try to guess 00066 if (QFile::exists(LPDCONF)) 00067 m_mode = LPRng; 00068 else 00069 m_mode = LPR; 00070 } 00071 00072 // Printcap file 00073 m_printcapfile = QString::null; 00074 m_local = true; 00075 00076 // Spool directory 00077 m_spooldir = "/var/spool/lpd"; 00078 } 00079 00080 QString LprSettings::printcapFile() 00081 { 00082 if (m_printcapfile.isEmpty()) 00083 { 00084 // default value 00085 m_printcapfile = PRINTCAP; 00086 if (m_mode == LPRng) 00087 { 00088 // look into /etc/lpd/conf file 00089 QFile cf(LPDCONF); 00090 if (cf.open(IO_ReadOnly)) 00091 { 00092 QTextStream t(&cf); 00093 QString line; 00094 while (!t.atEnd()) 00095 { 00096 line = t.readLine().stripWhiteSpace(); 00097 if (line.startsWith("printcap_path")) 00098 { 00099 QString filename = line.mid(14).stripWhiteSpace(); 00100 if (filename[0] != '|') 00101 m_printcapfile = filename; 00102 else 00103 { 00104 // should download the printcap file 00105 // and set m_local to false 00106 } 00107 } 00108 } 00109 } 00110 } 00111 } 00112 return m_printcapfile; 00113 } 00114 00115 QString LprSettings::defaultRemoteHost() 00116 { 00117 if (m_defaultremotehost.isEmpty()) 00118 { 00119 m_defaultremotehost = "localhost"; 00120 QFile cf(LPDCONF); 00121 if (cf.open(IO_ReadOnly)) 00122 { 00123 QTextStream t(&cf); 00124 QString line; 00125 while (!t.atEnd()) 00126 { 00127 line = t.readLine().stripWhiteSpace(); 00128 if (line.startsWith("default_remote_host")) 00129 { 00130 QString hostname = line.mid(20).stripWhiteSpace(); 00131 m_defaultremotehost = hostname; 00132 } 00133 } 00134 } 00135 } 00136 return m_defaultremotehost; 00137 } 00138 00139 void LprSettings::reload() 00140 { 00141 } 00142 00143 void LprSettings::configChanged() 00144 { 00145 init(); 00146 }
KDE Logo
This file is part of the documentation for kdeprint Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Sep 29 09:41:52 2004 by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2003