Subversion Repositories public

Rev

Rev 168 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
88 andreas 1
/***************************************************************************
2
 *   Copyright (C) 2008 by Andreas Theofilu                                *
3
 *   andreas@theosys.at                                                    *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation version 3 of the License.                *
8
 *                                                                         *
9
 *   This program is distributed in the hope that it will be useful,       *
10
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12
 *   GNU General Public License for more details.                          *
13
 *                                                                         *
14
 *   You should have received a copy of the GNU General Public License     *
15
 *   along with this program; if not, write to the                         *
16
 *   Free Software Foundation, Inc.,                                       *
17
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
18
 ***************************************************************************/
19
 
20
 
21
#include "settingswidget.h"
22
#include <ksimpleconfig.h>
23
#include <knuminput.h>
24
#include <kcombobox.h>
25
#include <kurlrequester.h>
26
#include <klineedit.h>
27
#include <qdir.h>
149 andreas 28
#include <qcheckbox.h>
230 andreas 29
#include <qradiobutton.h>
88 andreas 30
 
31
settingsWidget::settingsWidget ( QWidget* parent, const char* name, bool modal, WFlags fl )
32
		: settingsWidgetBase ( parent,name, modal,fl )
33
{
34
KComboBox *cb;
35
QDir dir = QDir::home();
36
QString path = dir.absPath();
37
 
38
	// Load the config parameters
39
	cbDevice->setShowLocalProtocol(false);
40
	cb = cbDevice->comboBox();
41
	cb->insertURL(KURL("/dev/ttyUSB0"));
100 andreas 42
	cb->insertURL(KURL("/dev/ttyUSB1"));
88 andreas 43
	cb->insertURL(KURL("/dev/ttyS0"));
44
	cb->insertURL(KURL("/dev/ttyS1"));
45
	KSimpleConfig *cfg = new KSimpleConfig(QString("sportwatcher.rc"), true);
46
	cfg->setGroup(QString("SportWatcher"));
47
	intLower1->setValue(cfg->readNumEntry("lower1"));
48
	intLower2->setValue(cfg->readNumEntry("lower2"));
49
	intLower3->setValue(cfg->readNumEntry("lower3"));
50
	intUpper1->setValue(cfg->readNumEntry("upper1"));
51
	intUpper2->setValue(cfg->readNumEntry("upper2"));
52
	intUpper3->setValue(cfg->readNumEntry("upper3"));
53
	intMaxHr->setValue(cfg->readNumEntry("maxHr"));
54
	intRestHr->setValue(cfg->readNumEntry("restHr"));
55
	intVO2max->setValue(cfg->readNumEntry("vo2max"));
56
	intWeight->setValue(cfg->readNumEntry("weight"));
57
	cbSampleTime->setCurrentItem(cfg->readNumEntry("seconds"));
230 andreas 58
	// If serial device is selected, activate the radio buttons
59
	// to select the type of Forerunner used.
149 andreas 60
	cbSerial->setChecked(cfg->readBoolEntry("Serial", false));
230 andreas 61
 
62
	if (cfg->readBoolEntry("Serial", false))
63
	{
64
	   rbFr50->setEnabled (true);
65
//	   rbFr405->setEnabled (true);
66
	   cbDevice->setEnabled (true);
67
 
68
	   // If "Forerunner" == false, Forerunner 405 is set.
69
	   if (cfg->readBoolEntry("Forerunner", false))
70
	   {
71
	      rbFr50->setChecked(false);
72
	      rbFr405->setChecked(true);
73
	   }
74
	   else
75
	   {
76
	      rbFr50->setChecked(true);
77
	      rbFr405->setChecked(false);
78
	   }
79
	}
80
	else
81
	{
82
	   rbFr50->setEnabled (false);
83
	   rbFr405->setEnabled (false);
84
	   cbDevice->setEnabled (false);
85
	}
86
 
168 andreas 87
	cbContour->setChecked(cfg->readBoolEntry("Contour", false));
149 andreas 88
	cbDevice->setURL(cfg->readEntry("Device"));
88 andreas 89
	lnData->setURL(cfg->readEntry("Data", path + "/.sportwatcher"));
90
	lnHRM->setURL(cfg->readEntry("HRM", path + "/polar"));
151 andreas 91
	lnMapFile->setURL(cfg->readEntry("MAP", cfg->readEntry("Data", path + "/.sportwatcher/track.wms")));
149 andreas 92
	cbUnit->setCurrentItem(cfg->readNumEntry("Units", 0));
158 andreas 93
	cbMapType->setCurrentItem(cfg->readNumEntry("MapType", 7));
88 andreas 94
	delete cfg;
95
}
96
 
97
settingsWidget::~settingsWidget()
98
{
99
}
100
 
101
/*$SPECIALIZATION$*/
230 andreas 102
void settingsWidget::cbSerialSlot (bool state)
103
{
104
	if (state)
105
	{
106
	   rbFr50->setEnabled (true);
107
//	   rbFr405->setEnabled (true);
108
	   cbDevice->setEnabled (true);
109
	}
110
	else
111
	{
112
	   rbFr50->setEnabled (false);
113
	   rbFr405->setEnabled (false);
114
	   cbDevice->setEnabled (false);
115
	}
116
}
117
 
118
void settingsWidget::rbFr50Slot (bool state)
119
{
120
	if (state && rbFr405->isChecked())
121
	   rbFr405->setChecked(false);
122
	else
123
	   rbFr405->setChecked(true);
124
}
125
 
126
void settingsWidget::rbFr405Slot (bool state)
127
{
128
	if (state && rbFr50->isChecked())
129
	   rbFr50->setChecked(false);
130
	else
131
	   rbFr50->setChecked(true);
132
}
133
 
88 andreas 134
void settingsWidget::btCancelSlot()
135
{
136
	done(QDialog::Rejected);
137
}
138
 
139
void settingsWidget::btSaveSlot()
140
{
141
	KSimpleConfig *cfg = new KSimpleConfig(QString("sportwatcher.rc"));
142
	cfg->setGroup(QString("SportWatcher"));
143
	// Put the data into the config file
144
	cfg->writeEntry("lower1", intLower1->value());
145
	cfg->writeEntry("lower2", intLower2->value());
146
	cfg->writeEntry("lower3", intLower3->value());
147
	cfg->writeEntry("upper1", intUpper1->value());
148
	cfg->writeEntry("upper2", intUpper2->value());
149
	cfg->writeEntry("upper3", intUpper3->value());
150
	cfg->writeEntry("maxHr", intMaxHr->value());
151
	cfg->writeEntry("restHr", intRestHr->value());
152
	cfg->writeEntry("vo2max", intVO2max->value());
153
	cfg->writeEntry("weight", intWeight->value());
154
	cfg->writeEntry("seconds", cbSampleTime->currentItem());
149 andreas 155
	cfg->writeEntry("Serial", cbSerial->isChecked());
168 andreas 156
	cfg->writeEntry("Contour", cbContour->isChecked());
149 andreas 157
	cfg->writeEntry("Device", cbDevice->url());
88 andreas 158
	cfg->writeEntry("Data", lnData->lineEdit()->text());
159
	cfg->writeEntry("HRM", lnHRM->lineEdit()->text());
143 andreas 160
	cfg->writeEntry("MAP", lnMapFile->lineEdit()->text());
149 andreas 161
	cfg->writeEntry("Units", cbUnit->currentItem());
158 andreas 162
	cfg->writeEntry("MapType", cbMapType->currentItem());
230 andreas 163
	cfg->writeEntry("Forerunner", rbFr50->isChecked());
88 andreas 164
	cfg->sync();
165
	delete cfg;
166
	done(QDialog::Accepted);
167
}
168
 
169
 
170
 
171
#include "settingswidget.moc"
172