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"
|
232 |
andreas |
22 |
#include <KConfig>
|
88 |
andreas |
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 |
|
232 |
andreas |
31 |
settingsWidget::settingsWidget ( QWidget* parent, Qt::WFlags fl )
|
|
|
32 |
: QDialog(parent, fl), Ui::settingsWidgetBase ()
|
88 |
andreas |
33 |
{
|
|
|
34 |
KComboBox *cb;
|
|
|
35 |
QDir dir = QDir::home();
|
232 |
andreas |
36 |
QString path = dir.absolutePath();
|
88 |
andreas |
37 |
|
232 |
andreas |
38 |
setupUi (this);
|
88 |
andreas |
39 |
// Load the config parameters
|
232 |
andreas |
40 |
cbDevice->setMode(KFile::ExistingOnly | KFile::LocalOnly);
|
88 |
andreas |
41 |
cb = cbDevice->comboBox();
|
232 |
andreas |
42 |
cb->insertUrl(1, KUrl("/dev/ttyUSB0"));
|
|
|
43 |
cb->insertUrl(2, KUrl("/dev/ttyUSB1"));
|
|
|
44 |
cb->insertUrl(3, KUrl("/dev/ttyS0"));
|
|
|
45 |
cb->insertUrl(4, KUrl("/dev/ttyS1"));
|
|
|
46 |
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
|
|
|
47 |
KConfigGroup ic (&cfg, "SportWatcher");
|
|
|
48 |
intLower1->setValue(ic.readEntry("lower1", 0));
|
|
|
49 |
intLower2->setValue(ic.readEntry("lower2", 0));
|
|
|
50 |
intLower3->setValue(ic.readEntry("lower3", 0));
|
|
|
51 |
intUpper1->setValue(ic.readEntry("upper1", 0));
|
|
|
52 |
intUpper2->setValue(ic.readEntry("upper2", 0));
|
|
|
53 |
intUpper3->setValue(ic.readEntry("upper3", 0));
|
|
|
54 |
intMaxHr->setValue(ic.readEntry("maxHr", 0));
|
|
|
55 |
intRestHr->setValue(ic.readEntry("restHr", 0));
|
|
|
56 |
intVO2max->setValue(ic.readEntry("vo2max", 0));
|
|
|
57 |
intWeight->setValue(ic.readEntry("weight", 0));
|
|
|
58 |
cbSampleTime->setCurrentIndex(ic.readEntry("seconds", 1));
|
230 |
andreas |
59 |
// If serial device is selected, activate the radio buttons
|
|
|
60 |
// to select the type of Forerunner used.
|
232 |
andreas |
61 |
cbSerial->setChecked(ic.readEntry("Serial", false));
|
230 |
andreas |
62 |
|
232 |
andreas |
63 |
if (ic.readEntry("Serial", false))
|
230 |
andreas |
64 |
{
|
|
|
65 |
rbFr50->setEnabled (true);
|
|
|
66 |
// rbFr405->setEnabled (true);
|
|
|
67 |
cbDevice->setEnabled (true);
|
|
|
68 |
|
|
|
69 |
// If "Forerunner" == false, Forerunner 405 is set.
|
232 |
andreas |
70 |
if (ic.readEntry("Forerunner", false))
|
230 |
andreas |
71 |
{
|
|
|
72 |
rbFr50->setChecked(false);
|
|
|
73 |
rbFr405->setChecked(true);
|
|
|
74 |
}
|
|
|
75 |
else
|
|
|
76 |
{
|
|
|
77 |
rbFr50->setChecked(true);
|
|
|
78 |
rbFr405->setChecked(false);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
else
|
|
|
82 |
{
|
|
|
83 |
rbFr50->setEnabled (false);
|
|
|
84 |
rbFr405->setEnabled (false);
|
|
|
85 |
cbDevice->setEnabled (false);
|
|
|
86 |
}
|
|
|
87 |
|
232 |
andreas |
88 |
cbContour->setChecked(ic.readEntry("Contour", false));
|
|
|
89 |
cbDevice->setUrl(ic.readEntry("Device", QString("/dev/ttyUSB0")));
|
|
|
90 |
lnData->setUrl(ic.readEntry("Data", path + "/.sportwatcher"));
|
|
|
91 |
lnHRM->setUrl(ic.readEntry("HRM", path + "/polar"));
|
|
|
92 |
lnMapFile->setUrl(ic.readEntry("MAP", ic.readEntry("Data", path + "/.sportwatcher/track.wms")));
|
|
|
93 |
cbUnit->setCurrentIndex(ic.readEntry("Units", 0));
|
|
|
94 |
cbMapType->setCurrentIndex(ic.readEntry("MapType", 7));
|
88 |
andreas |
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 |
{
|
232 |
andreas |
141 |
KConfig cfg (QString("sportwatcher.rc"), KConfig::SimpleConfig);
|
|
|
142 |
KConfigGroup ic (&cfg, "SportWatcher");
|
88 |
andreas |
143 |
// Put the data into the config file
|
232 |
andreas |
144 |
ic.writeEntry("lower1", intLower1->value());
|
|
|
145 |
ic.writeEntry("lower2", intLower2->value());
|
|
|
146 |
ic.writeEntry("lower3", intLower3->value());
|
|
|
147 |
ic.writeEntry("upper1", intUpper1->value());
|
|
|
148 |
ic.writeEntry("upper2", intUpper2->value());
|
|
|
149 |
ic.writeEntry("upper3", intUpper3->value());
|
|
|
150 |
ic.writeEntry("maxHr", intMaxHr->value());
|
|
|
151 |
ic.writeEntry("restHr", intRestHr->value());
|
|
|
152 |
ic.writeEntry("vo2max", intVO2max->value());
|
|
|
153 |
ic.writeEntry("weight", intWeight->value());
|
|
|
154 |
ic.writeEntry("seconds", cbSampleTime->currentIndex());
|
|
|
155 |
ic.writeEntry("Serial", cbSerial->isChecked());
|
|
|
156 |
ic.writeEntry("Contour", cbContour->isChecked());
|
|
|
157 |
ic.writeEntry("Device", cbDevice->url());
|
|
|
158 |
ic.writeEntry("Data", lnData->lineEdit()->text());
|
|
|
159 |
ic.writeEntry("HRM", lnHRM->lineEdit()->text());
|
|
|
160 |
ic.writeEntry("MAP", lnMapFile->lineEdit()->text());
|
|
|
161 |
ic.writeEntry("Units", cbUnit->currentIndex());
|
|
|
162 |
ic.writeEntry("MapType", cbMapType->currentIndex());
|
|
|
163 |
ic.writeEntry("Forerunner", rbFr50->isChecked());
|
|
|
164 |
cfg.sync();
|
88 |
andreas |
165 |
done(QDialog::Accepted);
|
|
|
166 |
}
|
|
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
|
170 |
#include "settingswidget.moc"
|
|
|
171 |
|