summaryrefslogtreecommitdiffstats
path: root/tdeprint/tdeprintfax/confsystem.cpp
blob: bfb2016910cd94d4d480c07dfe84dfe09c469d51 (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/*
 *   tdeprintfax - a small fax utility 
 *   Copyright (C) 2001  Michael Goffioul 
 * 
 *   This program is free software; you can redistribute it and/or modify 
 *   it under the terms of the GNU General Public License as published by 
 *   the Free Software Foundation; either version 2 of the License, or 
 *   (at your option) any later version. 
 * 
 *   This program 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 General Public License for more details. 
 * 
 *   You should have received a copy of the GNU General Public License 
 *   along with this program; if not, write to the Free Software 
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. 
 * 
 */ 
 
#include "confsystem.h" 
#include "defcmds.h" 
 
#include <tqlineedit.h> 
#include <tqlabel.h> 
#include <tqlayout.h> 
#include <tqcombobox.h>
 
#include <tdeglobal.h> 
#include <tdeconfig.h> 
#include <tdelocale.h>
#include <kseparator.h>

#include <stdlib.h>
 
#define	EFAX_ID		0 
#define	HYLAFAX_ID	1
#define	MGETTY_ID	2
#define OTHER_ID    3
 
ConfSystem::ConfSystem(TQWidget *parent, const char *name) 
: TQWidget(parent, name) 
{ 
	m_system = new TQComboBox(this);
	m_system->insertItem("EFax");
	m_system->insertItem("HylaFax");
	m_system->insertItem("Mgetty-sendfax");
	m_system->insertItem( "Other" );
	m_command = new TQLineEdit(this);
	TQLabel	*syslabel = new TQLabel(i18n("F&ax system:"), this);
	TQLabel	*cmdlabel = new TQLabel(i18n("Co&mmand:"), this);
	syslabel->setBuddy(m_system);
	cmdlabel->setBuddy(m_command);
	connect(m_system, TQ_SIGNAL(activated(int)), TQ_SLOT(slotSystemChanged(int)));
	m_current = 0;
	m_system->setCurrentItem(m_current);

	TQWidget	*m_dummy1 = new TQWidget(this), *m_dummy2 = new TQWidget(this);
	m_server = new TQLineEdit(m_dummy1);
	m_device = new TQComboBox(m_dummy2);
	TQLabel	*srvlabel = new TQLabel(i18n("Fax &server (if any):"), m_dummy1);
	TQLabel	*devlabel = new TQLabel(i18n("&Fax/Modem device:"), m_dummy2);
	srvlabel->setBuddy(m_server);
	devlabel->setBuddy(m_device);
	m_device->insertItem(i18n("Standard Modem Port"));
	for (int i=0; i<10; i++)
		m_device->insertItem(TQString(i18n("Serial Port #%1").arg(i)));
	m_device->insertItem( i18n( "Other" ) );
	connect( m_device, TQ_SIGNAL( activated( int ) ), TQ_SLOT( slotDeviceChanged( int ) ) );
	m_device_edit = new TQLineEdit( m_dummy2 );
	slotDeviceChanged( 0 );

	KSeparator	*sep = new KSeparator(this);
	sep->setMinimumHeight(10);
 
	TQVBoxLayout	*l0 = new TQVBoxLayout(this, 10, 10);
	TQGridLayout	*l1 = new TQGridLayout(0, 2, 2, 0, 10);
	l0->addLayout(l1);
	l1->setColStretch(1, 1);
	l1->addWidget(syslabel, 0, 0);
	l1->addWidget(cmdlabel, 1, 0);
	l1->addWidget(m_system, 0, 1);
	l1->addWidget(m_command, 1, 1);
	l0->addWidget(sep);
	l0->addWidget(m_dummy1);
	l0->addWidget(m_dummy2);
	l0->addStretch(1); 
	TQHBoxLayout	*l4 = new TQHBoxLayout(m_dummy1, 0, 10);
	l4->addWidget(srvlabel, 0);
	l4->addWidget(m_server, 1);
	TQGridLayout	*l5 = new TQGridLayout( m_dummy2, 2, 2, 0, 10 );
	l5->setColStretch( 1, 1 );
	l5->addWidget(devlabel, 0, 0);
	l5->addWidget(m_device, 0, 1);
	l5->addWidget( m_device_edit, 1, 1 );
} 
 
void ConfSystem::load() 
{ 
	TDEConfig	*conf = TDEGlobal::config(); 
	conf->setGroup("System");
	m_commands << conf->readPathEntry("EFax", defaultCommand(efax_default_cmd)); 
	m_commands << conf->readPathEntry("HylaFax", defaultCommand(hylafax_default_cmd));
	m_commands << conf->readPathEntry("Mgetty", defaultCommand(mgetty_default_cmd));
	m_commands << conf->readPathEntry( "Other", TQString::null );
	TQString	v = conf->readEntry("System", "efax");
	if (v == "mgetty") m_current = MGETTY_ID;
	else if (v == "hylafax") m_current = HYLAFAX_ID;
	else if ( v == "other" ) m_current = OTHER_ID;
	else m_current = EFAX_ID;
	conf->setGroup("Fax");
	m_server->setText(conf->readEntry("Server", getenv("FAXSERVER")));
	v = conf->readEntry("Device", "modem");
	if (v.startsWith("ttyS"))
		m_device->setCurrentItem(v.right(v.length()-4).toInt()+1);
	else if ( v == "modem" )
		m_device->setCurrentItem(0);
	else
	{
		m_device->setCurrentItem( m_device->count()-1 );
		m_device_edit->setText( "/dev/" + v );
		slotDeviceChanged( m_device->count()-1 );
	}

	m_system->setCurrentItem(m_current);
	m_command->setText(m_commands[m_current]);
	slotSystemChanged(m_current);
}
 
void ConfSystem::save()
{
	m_commands[ m_current ] = m_command->text();
	TDEConfig	*conf = TDEGlobal::config();
	conf->setGroup("System");
	if (m_commands[EFAX_ID] != defaultCommand(efax_default_cmd))
		conf->writePathEntry("EFax", m_commands[EFAX_ID]);
	else
		conf->deleteEntry("EFax");
	if (m_commands[HYLAFAX_ID] != defaultCommand(hylafax_default_cmd))
		conf->writePathEntry("HylaFax", m_commands[HYLAFAX_ID]);
	else
		conf->deleteEntry("HylaFax");
	if (m_commands[MGETTY_ID] != defaultCommand(mgetty_default_cmd))
		conf->writePathEntry("Mgetty", m_commands[MGETTY_ID]);
	else
		conf->deleteEntry("Mgetty");
	if ( !m_commands[ OTHER_ID ].isEmpty() )
		conf->writeEntry( "Other", m_commands[ OTHER_ID ] );
	else
		conf->deleteEntry( "Other" );
	int	ID = m_system->currentItem();
	switch (ID)
	{
		case EFAX_ID: conf->writeEntry("System", "efax"); break;
		case HYLAFAX_ID: conf->writeEntry("System", "hylafax"); break;
		case MGETTY_ID: conf->writeEntry("System", "mgetty"); break;
		case OTHER_ID: conf->writeEntry( "System", "other" ); break;
	}
	conf->setGroup("Fax");
	if ( m_device->currentItem() != ( m_device->count()-1 ) )
		conf->writeEntry("Device", m_device->currentItem() == 0 ? TQString("modem") : TQString(TQString("ttyS%1").arg(m_device->currentItem()-1)));
	else
	{
		TQString dev = m_device_edit->text();
		// strip leading "/dev/"
		if ( dev.startsWith( "/dev/" ) )
			dev = dev.mid( 5 );
		conf->writeEntry( "Device", dev );
	}
	if (m_server->text().isEmpty())
		conf->deleteEntry("Server");
	else
		conf->writeEntry("Server", m_server->text());
}

void ConfSystem::slotSystemChanged(int ID)
{
	m_commands[m_current] = m_command->text();
	m_current = ID;
	if (ID == EFAX_ID)
		m_device->parentWidget()->show();
	else
		m_device->parentWidget()->hide();
	if (ID == HYLAFAX_ID)
		m_server->parentWidget()->show();
	else
		m_server->parentWidget()->hide();
	m_command->setText(m_commands[m_current]);
}

void ConfSystem::slotDeviceChanged( int ID )
{
	if ( ID != ( m_device->count()-1 ) )
		m_device_edit->hide();
	else
		m_device_edit->show();
}

#include "confsystem.moc"