summaryrefslogtreecommitdiffstats
path: root/kdeprint/lpr/lprsettings.cpp
blob: a1a632a0f78fcb26c9300d6fe73a6df002ddd929 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 *  This file is part of the KDE libraries
 *  Copyright (c) 2001,2002 Michael Goffioul <kdeprint@swing.be>
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library General Public
 *  License version 2 as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public License
 *  along with this library; see the file COPYING.LIB.  If not, write to
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 *  Boston, MA 02110-1301, USA.
 **/

#include "lprsettings.h"
#include "kmmanager.h"
#include "kmfactory.h"

#include <kconfig.h>
#include <tqfile.h>
#include <tqtextstream.h>

#define LPDCONF "/etc/lpd.conf"
#define PRINTCAP "/etc/printcap"

LprSettings* LprSettings::m_self = 0;

LprSettings::LprSettings(TQObject *parent, const char *name)
: TQObject(parent, name), KPReloadObject(true)
{
	init();
}

LprSettings::~LprSettings()
{
	m_self = 0;
}

LprSettings* LprSettings::self()
{
	if (!m_self)
	{
		m_self = new LprSettings(KMManager::self(), "LprSettings");
	}
	return m_self;
}

void LprSettings::init()
{
	// LPR/LPRng mode
	KConfig	*conf = KMFactory::self()->printConfig();
	conf->setGroup("LPR");
	TQString	modestr = conf->readEntry("Mode");
	if (modestr == "LPRng")
		m_mode = LPRng;
	else if (modestr == "LPR")
		m_mode = LPR;
	else
	{
		// try to guess
		if (TQFile::exists(LPDCONF))
			m_mode = LPRng;
		else
			m_mode = LPR;
	}

	// Printcap file
	m_printcapfile = TQString();
	m_local = true;

	// Spool directory
	m_spooldir = "/var/spool/lpd";
}

TQString LprSettings::printcapFile()
{
	if (m_printcapfile.isEmpty())
	{
		// default value
		m_printcapfile = PRINTCAP;
		if (m_mode == LPRng)
		{
			// look into /etc/lpd/conf file
			TQFile cf(LPDCONF);
			if (cf.open(IO_ReadOnly))
			{
				TQTextStream	t(&cf);
				TQString	line;
				while (!t.atEnd())
				{
					line = t.readLine().stripWhiteSpace();
					if (line.startsWith("printcap_path"))
					{
						TQString	filename = line.mid(14).stripWhiteSpace();
						if (filename[0] != '|')
							m_printcapfile = filename;
						else
						{
							// should download the printcap file
							// and set m_local to false
						}
					}
				}
			}
		}
	}
	return m_printcapfile;
}

TQString LprSettings::defaultRemoteHost()
{
	if (m_defaultremotehost.isEmpty())
	{
		m_defaultremotehost = "localhost";
		TQFile cf(LPDCONF);
		if (cf.open(IO_ReadOnly))
		{
			TQTextStream	t(&cf);
			TQString	line;
			while (!t.atEnd())
			{
				line = t.readLine().stripWhiteSpace();
				if (line.startsWith("default_remote_host"))
				{
					TQString	hostname = line.mid(20).stripWhiteSpace();
					m_defaultremotehost = hostname;
				}
			}
		}		
	}
	return m_defaultremotehost;
}

void LprSettings::reload()
{
}

void LprSettings::configChanged()
{
	init();
}