lprsettings.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00066 if (QFile::exists(LPDCONF))
00067 m_mode = LPRng;
00068 else
00069 m_mode = LPR;
00070 }
00071
00072
00073 m_printcapfile = QString::null;
00074 m_local = true;
00075
00076
00077 m_spooldir = "/var/spool/lpd";
00078 }
00079
00080 QString LprSettings::printcapFile()
00081 {
00082 if (m_printcapfile.isEmpty())
00083 {
00084
00085 m_printcapfile = PRINTCAP;
00086 if (m_mode == LPRng)
00087 {
00088
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
00105
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 }
|