Subversion Repositories public

Rev

Rev 313 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 313 Rev 314
Line 1... Line 1...
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) 2007 - 2009 by Andreas Theofilu                         *
2
 *   Copyright (C) 2007 - 2013 by Andreas Theofilu                         *
3
 *   andreas@theosys.at                                                    *
3
 *   andreas@theosys.at                                                    *
4
 *                                                                         *
4
 *                                                                         *
5
 *   This program is free software; you can redistribute it and/or modify  *
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  *
6
 *   it under the terms of the GNU General Public License as published by  *
7
 *   the Free Software Foundation version 3 of the License.                *
7
 *   the Free Software Foundation version 3 of the License.                *
Line 18... Line 18...
18
 ***************************************************************************/
18
 ***************************************************************************/
19
#include <time.h>
19
#include <time.h>
20
#include <string.h>
20
#include <string.h>
21
#include <math.h>
21
#include <math.h>
22
 
22
 
-
 
23
#include <iostream>
23
#include <qlistview.h>
24
#include <qlistview.h>
24
#include <qdatetime.h>
25
#include <qdatetime.h>
25
#include <QXmlReader>
26
#include <QXmlReader>
26
 
27
 
27
#include <klocale.h>
28
#include <klocale.h>
28
 
29
 
29
#include "import.h"
30
#include "import.h"
30
 
31
 
31
#define FLD_NAME		1
32
#define FLD_NAME					1
32
#define FLD_TOTALTIMESECONDS	2
33
#define FLD_TOTALTIMESECONDS		2
33
#define FLD_DISTANCEMETERS	3
34
#define FLD_DISTANCEMETERS			3
34
#define FLD_LATITUDEDEGREES	4
35
#define FLD_LATITUDEDEGREES			4
35
#define FLD_LONGITUDEDEGREES	5
36
#define FLD_LONGITUDEDEGREES		5
36
#define FLD_VALUE		6
37
#define FLD_VALUE					6
37
#define FLD_INTENSITY		7
38
#define FLD_INTENSITY				7
38
#define FLD_TIME		8
39
#define FLD_TIME					8
39
#define FLD_ALTITUDEMETERS	9
40
#define FLD_ALTITUDEMETERS			9
40
#define FLD_SENSORSTATE		10
41
#define FLD_SENSORSTATE				10
41
#define FLD_STARTTIME		11
42
#define FLD_STARTTIME				11
42
#define FLD_AVERAGECADENCE	12
43
#define FLD_AVERAGECADENCE			12
43
#define FLD_SPORTTYPE		13
44
#define FLD_SPORTTYPE				13
44
#define FLD_VERSIONMAJOR	14
45
#define FLD_VERSIONMAJOR			14
45
#define FLD_VERSIONMINOR	15
46
#define FLD_VERSIONMINOR			15
46
#define FLD_BUILDMAJOR		16
47
#define FLD_BUILDMAJOR				16
47
#define FLD_BUILDMINOR		17
48
#define FLD_BUILDMINOR				17
48
#define FLD_TYPE		18
49
#define FLD_TYPE					18
49
#define FLD_BUILDER		19
50
#define FLD_BUILDER					19
50
#define FLD_LANGID		20
51
#define FLD_LANGID					20
51
#define FLD_PARTNUMBER		21
52
#define FLD_PARTNUMBER				21
52
#define FLD_CADENCE		22
53
#define FLD_CADENCE					22
53
#define FLD_MAXSPEED		23
54
#define FLD_MAXSPEED				23
54
#define FLD_CALORIES		24
55
#define FLD_CALORIES				24
55
#define FLD_ID			25
56
#define FLD_ID						25
56
#define FLD_TRIGGERMETHOD	26
57
#define FLD_TRIGGERMETHOD			26
57
#define FLD_TPX			27
58
#define FLD_TPX						27
58
#define FLD_UNITID		28
59
#define FLD_UNITID					28
59
#define FLD_PRODUCTID		29
60
#define FLD_PRODUCTID				29
60
#define FLD_NOTES		30
61
#define FLD_NOTES					30
61
 
62
 
62
#define CON_COURSES		100
63
#define CON_COURSES					100
63
#define CON_COURSE		101
64
#define CON_COURSE					101
64
#define CON_LAP			102
65
#define CON_LAP						102
65
#define CON_BEGINPOSITION	103
66
#define CON_BEGINPOSITION			103
66
#define CON_ENDPOSITION		104
67
#define CON_ENDPOSITION				104
67
#define CON_AVERAGEHEARTRATEBPM	105
68
#define CON_AVERAGEHEARTRATEBPM		105
68
#define CON_MAXIMUMHEARTRATEBPM	106
69
#define CON_MAXIMUMHEARTRATEBPM		106
69
#define CON_TRACK		107
70
#define CON_TRACK					107
70
#define CON_TRACKPOINT		108
71
#define CON_TRACKPOINT				108
71
#define CON_POSITION		109
72
#define CON_POSITION				109
72
#define CON_HEARTRATEBPM	110
73
#define CON_HEARTRATEBPM			110
73
#define CON_AUTHOR		111
74
#define CON_AUTHOR					111
74
#define CON_VERSION		112
75
#define CON_VERSION					112
75
#define CON_BUILD		113
76
#define CON_BUILD					113
76
#define CON_ACTIVITY		114
77
#define CON_ACTIVITY				114
77
#define CON_EXTENSIONS		115
78
#define CON_EXTENSIONS				115
78
#define CON_CREATOR		116
79
#define CON_CREATOR					116
79
#define CON_MULTISPORTSESSION	117
80
#define CON_MULTISPORTSESSION		117
80
#define CON_FIRSTSPORT		118
81
#define CON_FIRSTSPORT				118
81
#define CON_NEXTSPORT		119
82
#define CON_NEXTSPORT				119
82
#define CON_TRAINING		120
83
#define CON_TRAINING				120
83
#define CON_QUICKWORKOUTRESULTS	121
84
#define CON_QUICKWORKOUTRESULTS		121
84
 
85
 
85
#define ATT_CADENCESENSOR	200
86
#define ATT_CADENCESENSOR			200
86
 
87
 
87
#define STOPSTOP		0
88
#define STOPSTOP					0
88
 
89
 
89
KEYS keys[] = {
90
KEYS keys[] =
-
 
91
{
90
	/* Fields */
92
	/* Fields */
91
	{ FLD_NAME,			QString("name") },
93
	{ FLD_NAME,					QString("name") },
92
	{ FLD_TOTALTIMESECONDS,		QString("TotalTimeSeconds") },
94
	{ FLD_TOTALTIMESECONDS,		QString("TotalTimeSeconds") },
93
	{ FLD_DISTANCEMETERS,		QString("DistanceMeters") },
95
	{ FLD_DISTANCEMETERS,		QString("DistanceMeters") },
94
	{ FLD_LATITUDEDEGREES,		QString("LatitudeDegrees") },
96
	{ FLD_LATITUDEDEGREES,		QString("LatitudeDegrees") },
95
	{ FLD_LONGITUDEDEGREES,		QString("LongitudeDegrees") },
97
	{ FLD_LONGITUDEDEGREES,		QString("LongitudeDegrees") },
96
	{ FLD_VALUE,			QString("Value") },
98
	{ FLD_VALUE,				QString("Value") },
97
	{ FLD_INTENSITY,		QString("Intensity") },
99
	{ FLD_INTENSITY,			QString("Intensity") },
98
	{ FLD_TIME,			QString("Time") },
100
	{ FLD_TIME,					QString("Time") },
99
	{ FLD_ALTITUDEMETERS,		QString("AltitudeMeters") },
101
	{ FLD_ALTITUDEMETERS,		QString("AltitudeMeters") },
100
	{ FLD_SENSORSTATE,		QString("SensorState") },
102
	{ FLD_SENSORSTATE,			QString("SensorState") },
101
	{ FLD_STARTTIME,		QString("StartTime") },
103
	{ FLD_STARTTIME,			QString("StartTime") },
102
	{ FLD_AVERAGECADENCE,		QString("AverageCadence") },
104
	{ FLD_AVERAGECADENCE,		QString("AverageCadence") },
103
	{ FLD_SPORTTYPE,		QString("SportType") },
105
	{ FLD_SPORTTYPE,			QString("SportType") },
104
	{ FLD_VERSIONMAJOR,		QString("VersionMajor") },
106
	{ FLD_VERSIONMAJOR,			QString("VersionMajor") },
105
	{ FLD_VERSIONMINOR,		QString("VersionMinor") },
107
	{ FLD_VERSIONMINOR,			QString("VersionMinor") },
106
	{ FLD_BUILDMAJOR,		QString("BuildMajor") },
108
	{ FLD_BUILDMAJOR,			QString("BuildMajor") },
107
	{ FLD_BUILDMINOR,		QString("BuildMinor") },
109
	{ FLD_BUILDMINOR,			QString("BuildMinor") },
108
	{ FLD_TYPE,			QString("Type") },
110
	{ FLD_TYPE,					QString("Type") },
109
	{ FLD_BUILDER,			QString("Builder") },
111
	{ FLD_BUILDER,				QString("Builder") },
110
	{ FLD_LANGID,			QString("LangID") },
112
	{ FLD_LANGID,				QString("LangID") },
111
	{ FLD_PARTNUMBER,		QString("PartNumber") },
113
	{ FLD_PARTNUMBER,			QString("PartNumber") },
112
	{ FLD_CADENCE,			QString("Cadence") },
114
	{ FLD_CADENCE,				QString("Cadence") },
113
	{ FLD_CALORIES,			QString("Calories") },
115
	{ FLD_CALORIES,				QString("Calories") },
114
	{ FLD_MAXSPEED,			QString("MaximumSpeed") },
116
	{ FLD_MAXSPEED,				QString("MaximumSpeed") },
115
	{ FLD_ID,			QString("Id") },
117
	{ FLD_ID,					QString("Id") },
116
	{ FLD_TRIGGERMETHOD,		QString("TriggerMethod") },
118
	{ FLD_TRIGGERMETHOD,		QString("TriggerMethod") },
117
	{ FLD_TPX,			QString("TPX") },
119
	{ FLD_TPX,					QString("TPX") },
118
	{ FLD_UNITID,			QString("UnitId") },
120
	{ FLD_UNITID,				QString("UnitId") },
119
	{ FLD_PRODUCTID,		QString("ProductID") },
121
	{ FLD_PRODUCTID,			QString("ProductID") },
120
	{ FLD_NOTES,			QString("Notes") },
122
	{ FLD_NOTES,				QString("Notes") },
121
	/* Attributes */
123
	/* Attributes */
122
	{ ATT_CADENCESENSOR,		QString("CadenceSensor") },
124
	{ ATT_CADENCESENSOR,		QString("CadenceSensor") },
123
	/* Container */
125
	/* Container */
124
	{ CON_COURSES,			QString("Courses") },
126
	{ CON_COURSES,				QString("Courses") },
125
	{ CON_COURSE,			QString("Course") },
127
	{ CON_COURSE,				QString("Course") },
126
	{ CON_LAP,			QString("Lap") },
128
	{ CON_LAP,					QString("Lap") },
127
	{ CON_BEGINPOSITION,		QString("BeginPosition") },
129
	{ CON_BEGINPOSITION,		QString("BeginPosition") },
128
	{ CON_ENDPOSITION,		QString("EndPosition") },
130
	{ CON_ENDPOSITION,			QString("EndPosition") },
129
	{ CON_AVERAGEHEARTRATEBPM,	QString("AverageHeartRateBpm") },
131
	{ CON_AVERAGEHEARTRATEBPM,	QString("AverageHeartRateBpm") },
130
	{ CON_MAXIMUMHEARTRATEBPM,	QString("MaximumHeartRateBpm") },
132
	{ CON_MAXIMUMHEARTRATEBPM,	QString("MaximumHeartRateBpm") },
131
	{ CON_TRACK,			QString("Track") },
133
	{ CON_TRACK,				QString("Track") },
132
	{ CON_TRACKPOINT,		QString("Trackpoint") },
134
	{ CON_TRACKPOINT,			QString("Trackpoint") },
133
	{ CON_POSITION,			QString("Position") },
135
	{ CON_POSITION,				QString("Position") },
134
	{ CON_HEARTRATEBPM,		QString("HeartRateBpm") },
136
	{ CON_HEARTRATEBPM,			QString("HeartRateBpm") },
135
	{ CON_AUTHOR,			QString("Author") },
137
	{ CON_AUTHOR,				QString("Author") },
136
	{ CON_VERSION,			QString("Version") },
138
	{ CON_VERSION,				QString("Version") },
137
	{ CON_BUILD,			QString("Build") },
139
	{ CON_BUILD,				QString("Build") },
138
	{ CON_ACTIVITY,			QString("Activity") },
140
	{ CON_ACTIVITY,				QString("Activity") },
139
	{ CON_EXTENSIONS,		QString("Extensions") },
141
	{ CON_EXTENSIONS,			QString("Extensions") },
140
	{ CON_CREATOR,			QString("Creator") },
142
	{ CON_CREATOR,				QString("Creator") },
141
	{ CON_MULTISPORTSESSION,	QString("MultiSportSession") },
143
	{ CON_MULTISPORTSESSION,	QString("MultiSportSession") },
142
	{ CON_FIRSTSPORT,		QString("FirstSport") },
144
	{ CON_FIRSTSPORT,			QString("FirstSport") },
143
	{ CON_NEXTSPORT,		QString("NextSport") },
145
	{ CON_NEXTSPORT,			QString("NextSport") },
144
	{ CON_TRAINING,			QString("Training") },
146
	{ CON_TRAINING,				QString("Training") },
145
	{ CON_QUICKWORKOUTRESULTS,	QString("QuickWorkoutResults") },
147
	{ CON_QUICKWORKOUTRESULTS,	QString("QuickWorkoutResults") },
146
	/* Errors */
148
	/* Errors */
147
	{ ERR_OK,			QString("OK") },	// this is no error
149
	{ ERR_OK,					QString("OK") },	// this is no error
148
	{ ERR_NOFILE,			i18n("IMPORT: No file name to parse XML!") },	// but this
150
	{ ERR_NOFILE,				i18n("IMPORT: No file name to parse XML!") },	// but this
149
	{ ERR_TAGS,			i18n("IMPORT: More end tags than open tags! Invalid XML file.") },
151
	{ ERR_TAGS,					i18n("IMPORT: More end tags than open tags! Invalid XML file.") },
150
	{ ERR_ALLOCGMN,			i18n("IMPORT: Error allocating memory for base Garmin structure.") },
152
	{ ERR_ALLOCGMN,				i18n("IMPORT: Error allocating memory for base Garmin structure.") },
151
	{ ERR_ALLOCLAP,			i18n("IMPORT: Error allocating memory for a lap.") },
153
	{ ERR_ALLOCLAP,				i18n("IMPORT: Error allocating memory for a lap.") },
152
	{ ERR_ALLOCPOINT,		i18n("IMPORT: Error allocating memory for a track point.") },
154
	{ ERR_ALLOCPOINT,			i18n("IMPORT: Error allocating memory for a track point.") },
153
	{ ERR_ALLOCRUN,			i18n("IMPORT: Error allocating memory for running information.") },
155
	{ ERR_ALLOCRUN,				i18n("IMPORT: Error allocating memory for running information.") },
154
	{ ERR_ALLOCLIST,		i18n("IMPORT: Error allocating memory for a list node.") },
156
	{ ERR_ALLOCLIST,			i18n("IMPORT: Error allocating memory for a list node.") },
155
	{ STOPSTOP,			QString::null }
157
	{ STOPSTOP,					QString::null }
156
};
158
};
157
 
159
 
158
void gmn_import::Initialize()
160
void gmn_import::Initialize()
159
{
161
{
160
	qfstat = false;
162
	qfstat = false;
Line 162... Line 164...
162
	__error = 0;
164
	__error = 0;
163
	gmn = 0;
165
	gmn = 0;
164
	list_lap = list_track = 0;
166
	list_lap = list_track = 0;
165
	ds = 0;
167
	ds = 0;
166
	history = false;
168
	history = false;
-
 
169
	inst = 0;
-
 
170
	m_cb = 0;
-
 
171
	doCallback = FALSE;
167
}
172
}
168
 
173
 
169
gmn_import::gmn_import (const QFile &qfile)
174
gmn_import::gmn_import(const QFile &qfile)
170
{
175
{
171
	Initialize ();
176
	Initialize();
172
	file.setFileName (qfile.fileName ());
177
	file.setFileName(qfile.fileName());
173
 
178
 
174
	if (file.exists ())
179
	if(file.exists())
175
	   qfstat = true;
180
		qfstat = true;
176
}
181
}
177
 
182
 
178
void gmn_import::setFile (const QFile &qfile)
183
void gmn_import::setFile(const QFile &qfile)
179
{
184
{
180
	if (qfopen)
185
	if(qfopen)
181
	{
186
	{
182
	   file.close ();
187
		file.close();
183
	   qfopen = false;
188
		qfopen = false;
184
	}
189
	}
185
 
190
 
186
	qfstat = false;
191
	qfstat = false;
187
	file.setFileName (qfile.fileName ());
192
	file.setFileName(qfile.fileName());
188
 
193
 
189
	if (file.exists ())
194
	if(file.exists())
190
	   qfstat = true;
195
		qfstat = true;
191
}
196
}
192
 
197
 
193
void gmn_import::setFile (const QString &sfile)
198
void gmn_import::setFile(const QString &sfile)
194
{
199
{
195
	if (qfopen)
200
	if(qfopen)
196
	{
201
	{
197
	   file.close ();
202
		file.close();
198
	   qfopen = false;
203
		qfopen = false;
199
	   __error = 1;
204
		__error = 1;
200
	}
205
	}
201
 
206
 
202
	qfstat = false;
207
	qfstat = false;
203
	file.setFileName (sfile);
208
	file.setFileName(sfile);
204
 
209
 
205
	if (file.exists ())
210
	if(file.exists())
206
	   qfstat = true;
211
		qfstat = true;
207
}
212
}
208
 
213
 
209
/*
214
/*
210
 * Convert an ISO8601 formated date into garmin epoch.
215
 * Convert an ISO8601 formated date into garmin epoch.
211
 */
216
 */
212
unsigned int gmn_import::garmin_time (const QString& tstamp)
217
unsigned int gmn_import::garmin_time(const QString& tstamp)
213
{
218
{
214
QDateTime dt;
219
	QDateTime dt;
215
time_t tval;
220
	time_t tval;
216
 
221
 
217
	/*
222
	/*
218
	 * tstamp should contain a valid ISO8601 formated date and time stamp.
223
	 * tstamp should contain a valid ISO8601 formated date and time stamp.
219
	 * We will convert it to a kind of epoch, but with a garmin specific
224
	 * We will convert it to a kind of epoch, but with a garmin specific
220
	 * offset.
225
	 * offset.
221
	 */
226
	 */
222
	dt = dt.fromString(tstamp, Qt::ISODate);
227
	dt = dt.fromString(tstamp, Qt::ISODate);
223
 
228
 
224
	if (!dt.isValid())
229
	if(!dt.isValid())
225
	   return 0;
230
		return 0;
226
 
231
 
227
	tval = dt.toTime_t() - TIME_OFFSET;
232
	tval = dt.toTime_t() - TIME_OFFSET;
228
	return (unsigned int)tval;
233
	return (unsigned int)tval;
229
}
234
}
230
 
235
 
Line 245... Line 250...
245
}
250
}
246
 
251
 
247
/*
252
/*
248
 * This is called every time a new start element was parsed.
253
 * This is called every time a new start element was parsed.
249
 */
254
 */
250
bool gmn_import::startElement( const QString&, const QString&,
255
bool gmn_import::startElement(const QString&, const QString&,
251
                                    const QString& qName,
256
                              const QString& qName,
252
                                    const QXmlAttributes& att)
257
                              const QXmlAttributes& att)
253
{
258
{
254
int i = CON_FIRST;
259
	int i = CON_FIRST;
255
int index;
260
	int index;
256
 
261
 
257
	while (i <= CON_LAST)
262
	while(i <= CON_LAST)
258
	{
263
	{
259
	   if (qName.toLower() == getKey(i).toLower())
264
		if(qName.toLower() == getKey(i).toLower())
260
	   {
265
		{
-
 
266
			if(i == CON_MULTISPORTSESSION)
-
 
267
				doCallback = TRUE;
-
 
268
 
261
	      if (qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
269
			if(qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
262
	      {
270
			{
263
		 memset (&run, 0, sizeof (D1009));
271
				memset(&run, 0, sizeof(D1009));
264
 
272
 
265
		 if (i == CON_ACTIVITY)
273
				if(i == CON_ACTIVITY)
266
		 {
274
				{
267
		    con = "activity";
275
					con = "activity";
268
		    history = true;
276
					history = true;
269
		 }
277
				}
270
		 else
278
				else
271
		    con = "course";
279
					con = "course";
272
 
280
 
273
		 run.track_index = 0;
281
				run.track_index = 0;
274
		 run.first_lap_index = 0;
282
				run.first_lap_index = 0;
-
 
283
 
275
		 // Find sport type, if there is one
284
				// Find sport type, if there is one
276
		 if ((index = att.index(QString("Sport"))) != -1)
285
				if((index = att.index(QString("Sport"))) != -1)
277
		 {
286
				{
278
		    if (att.value(index).toAscii().toLower() == QString("Running").toLower())
287
					if(att.value(index).toAscii().toLower() == QString("Running").toLower())
279
				run.sport_type = D1000_running;
288
						run.sport_type = D1000_running;
280
			else if (att.value(index).toAscii().toLower() == QString("Biking").toLower())
289
					else if(att.value(index).toAscii().toLower() == QString("Biking").toLower())
281
				run.sport_type = D1000_biking;
290
						run.sport_type = D1000_biking;
282
			else if (att.value(index).toAscii().toLower() == QString("Other").toLower())
291
					else if(att.value(index).toAscii().toLower() == QString("Other").toLower())
283
				run.sport_type = D1000_other;
292
						run.sport_type = D1000_other;
284
			else
293
					else
285
				run.sport_type = D1000_other;
294
						run.sport_type = D1000_other;
286
		 }
295
				}
287
		 else
296
				else
288
			run.sport_type = D1000_other;		// Other
297
					run.sport_type = D1000_other;		// Other
289
 
298
 
290
		 tk = i;
299
				tk = i;
291
	      }
300
			}
292
 
301
 
293
	      if (qName.toLower() == QString("lap"))
302
			if(qName.toLower() == QString("lap"))
294
	      {
303
			{
295
		 memset (&lap, 0, sizeof (D1015));
304
				memset(&lap, 0, sizeof(D1015));
296
		 lap.index = lpos;
305
				lap.index = lpos;
297
		 lap.begin.lat = 0x7fffffff;
306
				lap.begin.lat = 0x7fffffff;
298
		 lap.begin.lon = 0x7fffffff;
307
				lap.begin.lon = 0x7fffffff;
299
		 lap.end.lat = 0x7fffffff;
308
				lap.end.lat = 0x7fffffff;
300
		 lap.end.lon = 0x7fffffff;
309
				lap.end.lon = 0x7fffffff;
301
		 con = "lap";
310
				con = "lap";
302
		 lpos++;
311
				lpos++;
303
		 tk = i;
312
				tk = i;
304
	      }
313
			}
305
 
314
 
306
	      if (con == QString("lap") && qName.toLower() == QString("BeginPosition").toLower())
315
			if(con == QString("lap") && qName.toLower() == QString("BeginPosition").toLower())
307
		 subCon = qName.toLower();
316
				subCon = qName.toLower();
308
	      else if (con == QString("lap") && qName.toLower() == QString("EndPosition").toLower())
317
			else if(con == QString("lap") && qName.toLower() == QString("EndPosition").toLower())
309
		 subCon = qName.toLower();
318
				subCon = qName.toLower();
310
	      else if (con == QString("lap") && qName.toLower() == QString("AverageHeartRateBpm").toLower())
319
			else if(con == QString("lap") && qName.toLower() == QString("AverageHeartRateBpm").toLower())
311
		 subCon = qName.toLower();
320
				subCon = qName.toLower();
312
	      else if (con == QString("lap") && qName.toLower() == QString("MaximumHeartRateBpm").toLower())
321
			else if(con == QString("lap") && qName.toLower() == QString("MaximumHeartRateBpm").toLower())
313
		 subCon = qName.toLower();
322
				subCon = qName.toLower();
314
 
323
 
315
	      if (history && qName.toLower() == QString("track") && con.toLower() == QString("lap"))
324
			if(history && qName.toLower() == QString("track") && con.toLower() == QString("lap"))
316
	      {
325
			{
317
		 first_tpos = tpos + 1;
326
				first_tpos = tpos + 1;
318
		 endElement (QString::null, QString::null, QString("Lap"));
327
				endElement(QString::null, QString::null, QString("Lap"));
319
		 indent++;
328
				indent++;
320
		 con = "lap";
329
				con = "lap";
321
		 fakeLap = true;
330
				fakeLap = true;
322
	      }
331
			}
323
 
332
 
324
	      if (qName.toLower() == QString("trackpoint"))
333
			if(qName.toLower() == QString("trackpoint"))
325
	      {
334
			{
326
		 memset (&point, 0, sizeof (D304));
335
				memset(&point, 0, sizeof(D304));
327
		 point.alt = 1.0e24;
336
				point.alt = 1.0e24;
328
		 point.posn.lat = 0x7fffffff;
337
				point.posn.lat = 0x7fffffff;
329
		 point.posn.lon = 0x7fffffff;
338
				point.posn.lon = 0x7fffffff;
330
		 con = "trackpoint";
339
				con = "trackpoint";
331
		 tpos++;
340
				tpos++;
332
		 tk = i;
341
				tk = i;
333
	      }
342
			}
334
 
343
 
335
	      if (con == QString("trackpoint") && qName.toLower() == QString("position"))
344
			if(con == QString("trackpoint") && qName.toLower() == QString("position"))
336
		 subCon = qName.toLower();
345
				subCon = qName.toLower();
337
	      else if (con == QString("trackpoint") && qName.toLower() == QString("heartratebpm"))
346
			else if(con == QString("trackpoint") && qName.toLower() == QString("heartratebpm"))
338
		 subCon = qName.toLower();
347
				subCon = qName.toLower();
339
	   }
348
		}
340
 
349
 
341
	   i++;
350
		i++;
342
	}
351
	}
343
 
352
 
344
	i = FLD_FIRST;
353
	i = FLD_FIRST;
345
 
354
 
346
	while (i <= FLD_LAST)
355
	while(i <= FLD_LAST)
347
	{
356
	{
348
	   if (qName.toLower() == getKey(i).toLower())
357
		if(qName.toLower() == getKey(i).toLower())
349
	      tk = i;
358
			tk = i;
350
 
359
 
351
	   i++;
360
		i++;
352
	}
361
	}
353
 
362
 
354
	indent++;
363
	indent++;
355
	return TRUE;
364
	return TRUE;
356
}
365
}
357
 
366
 
358
/*
367
/*
359
 * This is called every time an element is closed.
368
 * This is called every time an element is closed.
360
 */
369
 */
361
bool gmn_import::endElement( const QString&, const QString&, const QString& qName)
370
bool gmn_import::endElement(const QString&, const QString&, const QString& qName)
362
{
371
{
363
	if (!fakeLap)
372
	if(!fakeLap)
364
	   indent--;
373
		indent--;
365
 
374
 
366
	if (qName.toLower() == QString("lap"))
375
	if(qName.toLower() == QString("lap"))
367
	{
376
	{
368
	   garmin_data *gdt;
377
		garmin_data *gdt;
369
	   garmin_list *l;
378
		garmin_list *l;
370
 
379
 
371
	   if (!fakeLap)
380
		if(!fakeLap)
372
	      con.clear();
381
			con.clear();
373
 
382
 
374
	   if (history && fakeLap)
383
		if(history && fakeLap)
375
	   {
384
		{
376
	      fakeLap = false;
385
			fakeLap = false;
377
	      return TRUE;
386
			return TRUE;
378
	   }
387
		}
379
 
388
 
380
	   if (!gmn)		/* allocating space for first structure */
389
		if(!gmn)		/* allocating space for first structure */
381
	   {
390
		{
382
	      if ((gmn = garmin_alloc_data (data_Dlist)) == NULL)
391
			if((gmn = garmin_alloc_data(data_Dlist)) == NULL)
383
	      {
392
			{
384
		 __error = 3;
393
				__error = 3;
385
		 return FALSE;
394
				return FALSE;
386
	      }
395
			}
387
 
396
 
388
	      list = (garmin_list *)gmn->data;
397
			list = (garmin_list *)gmn->data;
389
	      /*
398
 
390
	       * This is the first data structure. It contains the total
399
			/*
391
	       * number of laps and the name of the course, if it was
400
			 * This is the first data structure. It contains the total
392
	       * named.
401
			 * number of laps and the name of the course, if it was
393
	       */
402
			 * named.
394
	      if ((gdt = garmin_alloc_data (data_D1009)) == NULL)
403
			 */
395
	      {
404
			if((gdt = garmin_alloc_data(data_D1009)) == NULL)
396
		 __error = 6;
405
			{
397
		 return FALSE;
406
				__error = 6;
398
	      }
407
				return FALSE;
399
 
408
			}
400
	      memmove (gdt->data, &run, sizeof (D1009));
409
 
401
	      prun = (D1009 *)gdt->data;
410
			memmove(gdt->data, &run, sizeof(D1009));
402
 
411
			prun = (D1009 *)gdt->data;
403
	      if (ds)
412
 
404
		 ds->garmin_print_data (gdt);
413
			if(ds)
405
 
414
				ds->garmin_print_data(gdt);
406
	      if ((l = garmin_list_append (list, gdt)) == NULL)
415
 
407
	      {
416
			if((l = garmin_list_append(list, gdt)) == NULL)
408
		 __error = 7;
417
			{
409
		 return FALSE;
418
				__error = 7;
410
	      }
419
				return FALSE;
411
 
420
			}
412
	      list = l;
421
 
413
	   }
422
			list = l;
414
 
423
		}
415
	   if (!list_lap)
424
 
416
	   {
425
		if(!list_lap)
417
	      if ((gmn_lap = garmin_alloc_data (data_Dlist)) == NULL)
426
		{
418
	      {
427
			if((gmn_lap = garmin_alloc_data(data_Dlist)) == NULL)
419
		 __error = 3;
428
			{
420
		 return FALSE;
429
				__error = 3;
421
	      }
430
				return FALSE;
422
 
431
			}
423
	      list_lap = (garmin_list *)gmn_lap->data;
432
 
424
 
433
			list_lap = (garmin_list *)gmn_lap->data;
425
	      if (garmin_list_append (list, gmn_lap) == NULL)
434
 
426
	      {
435
			if(garmin_list_append(list, gmn_lap) == NULL)
427
		 __error = 7;
436
			{
428
		 return FALSE;
437
				__error = 7;
429
	      }
438
				return FALSE;
430
 
439
			}
431
	      list = list_lap;
440
 
432
	   }
441
			list = list_lap;
433
	   else
442
		}
434
	      list = list_lap;
443
		else
435
 
444
			list = list_lap;
436
	   if ((gdt = garmin_alloc_data (data_D1015)) == NULL)
445
 
437
	   {
446
		if((gdt = garmin_alloc_data(data_D1015)) == NULL)
438
	      __error = 4;
447
		{
439
	      return FALSE;
448
			__error = 4;
440
	   }
449
			return FALSE;
441
 
450
		}
442
	   memmove (gdt->data, &lap, sizeof (D1015));
451
 
443
	   plap = (D1015 *)gdt->data;
452
		memmove(gdt->data, &lap, sizeof(D1015));
444
 
453
		plap = (D1015 *)gdt->data;
445
	   if (ds)
454
 
446
	      ds->garmin_print_data (gdt);
455
		if(ds)
447
 
456
			ds->garmin_print_data(gdt);
448
	   if ((l = garmin_list_append (list, gdt)) == NULL)
457
 
449
	   {
458
		if((l = garmin_list_append(list, gdt)) == NULL)
450
	      __error = 7;
459
		{
451
	      return FALSE;
460
			__error = 7;
452
	   }
461
			return FALSE;
453
 
462
		}
454
	   list = l;
463
 
455
	}
464
		list = l;
456
 
465
	}
457
	if (history && qName.toLower() == QString("track"))
466
 
458
	   first_tpos = 0;
467
	if(history && qName.toLower() == QString("track"))
459
 
468
		first_tpos = 0;
460
	if (qName.toLower() == QString("trackpoint"))
469
 
461
	{
470
	if(qName.toLower() == QString("trackpoint"))
462
	   garmin_data *gdt;
471
	{
463
	   garmin_list *l;
472
		garmin_data *gdt;
464
 
473
		garmin_list *l;
465
	   con.clear();
474
 
466
 
475
		con.clear();
467
	   if (!gmn)		/* allocating space for first structure */
476
 
468
	   {
477
		if(!gmn)		/* allocating space for first structure */
469
	      if ((gmn = garmin_alloc_data (data_Dlist)) == NULL)
478
		{
470
	      {
479
			if((gmn = garmin_alloc_data(data_Dlist)) == NULL)
471
		 __error = 3;
480
			{
472
		 return FALSE;
481
				__error = 3;
473
	      }
482
				return FALSE;
474
 
483
			}
475
	      list = (garmin_list *)gmn->data;
484
 
476
	      /*
485
			list = (garmin_list *)gmn->data;
477
	       * This is the first data structure. It contains the total
486
 
478
	       * number of laps and the name of the course, if it was
487
			/*
479
	       * named.
488
			 * This is the first data structure. It contains the total
480
	       */
489
			 * number of laps and the name of the course, if it was
481
	      if ((gdt = garmin_alloc_data (data_D1009)) == NULL)
490
			 * named.
482
	      {
491
			 */
483
		 __error = 6;
492
			if((gdt = garmin_alloc_data(data_D1009)) == NULL)
484
		 return FALSE;
493
			{
485
	      }
494
				__error = 6;
486
 
495
				return FALSE;
487
	      memmove (gdt->data, &run, sizeof (D1009));
496
			}
488
	      prun = (D1009 *)gdt->data;
497
 
489
 
498
			memmove(gdt->data, &run, sizeof(D1009));
490
	      if (ds)
499
			prun = (D1009 *)gdt->data;
491
		 ds->garmin_print_data (gdt);
500
 
492
 
501
			if(ds)
493
	      if ((l = garmin_list_append (list, gdt)) == NULL)
502
				ds->garmin_print_data(gdt);
494
	      {
503
 
495
		 __error = 7;
504
			if((l = garmin_list_append(list, gdt)) == NULL)
496
		 return FALSE;
505
			{
497
	      }
506
				__error = 7;
498
 
507
				return FALSE;
499
	      list = l;
508
			}
500
	   }
509
 
501
 
510
			list = l;
502
	   if (!list_track)
511
		}
503
	   {
512
 
504
	      if ((gmn_track = garmin_alloc_data (data_Dlist)) == NULL)
513
		if(!list_track)
505
	      {
514
		{
506
		 __error = 3;
515
			if((gmn_track = garmin_alloc_data(data_Dlist)) == NULL)
507
		 return FALSE;
516
			{
508
	      }
517
				__error = 3;
509
 
518
				return FALSE;
510
	      list_track = (garmin_list *)gmn_track->data;
519
			}
511
 
520
 
512
	      if (garmin_list_append (list, gmn_track) == NULL)
521
			list_track = (garmin_list *)gmn_track->data;
513
	      {
522
 
514
		 __error = 7;
523
			if(garmin_list_append(list, gmn_track) == NULL)
515
		 return FALSE;
524
			{
516
	      }
525
				__error = 7;
517
 
526
				return FALSE;
518
	      list = list_track;
527
			}
519
	   }
528
 
520
	   else
529
			list = list_track;
521
	      list = list_track;
530
		}
522
 
531
		else
523
	   if ((gdt = garmin_alloc_data (data_D304)) == NULL)
532
			list = list_track;
524
	   {
533
 
525
	      __error = 5;
534
		if((gdt = garmin_alloc_data(data_D304)) == NULL)
526
	      return FALSE;
535
		{
527
	   }
536
			__error = 5;
528
 
537
			return FALSE;
529
	   memmove (gdt->data, &point, sizeof (D304));
538
		}
530
 
539
 
531
	   if (ds)
540
		memmove(gdt->data, &point, sizeof(D304));
532
	      ds->garmin_print_data (gdt);
541
 
533
 
542
		if(ds)
534
	   if ((l = garmin_list_append (list, gdt)) == NULL)
543
			ds->garmin_print_data(gdt);
535
	   {
544
 
536
	      __error = 7;
545
		if((l = garmin_list_append(list, gdt)) == NULL)
537
	      return FALSE;
546
		{
538
	   }
547
			__error = 7;
539
 
548
			return FALSE;
540
	   list = l;
549
		}
541
	}
550
 
542
 
551
		list = l;
543
	if (qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
552
	}
544
	{
553
 
545
	   con.clear();
554
	if(qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
546
	   run.track_index = tpos - 1;
555
	{
547
	   run.last_lap_index = lpos - 1;
556
		con.clear();
548
	   memmove (prun, &run, sizeof (D1009));
557
		run.track_index = tpos - 1;
549
	   history = false;
558
		run.last_lap_index = lpos - 1;
550
	}
559
		memmove(prun, &run, sizeof(D1009));
551
 
560
 
552
	if (qName.toLower() == QString("beginposition") || qName.toLower() == QString("endposition") ||
561
		if (doCallback && m_cb)
553
	    qName.toLower() == QString("averageheartratebpm") || qName.toLower() == QString("maximumheartratebpm"))
562
		{
554
	   subCon.clear();
563
			m_cb->cbiCallbackFunction((void *)gmn);
-
 
564
			subCon.clear();
-
 
565
			lpos = tpos = oldLPos = 0;
-
 
566
			fakeLap = false;
-
 
567
			first_tpos = 0;
-
 
568
			garmin_free_data(gmn);
-
 
569
			gmn = 0;
-
 
570
		}
-
 
571
		else if (doCallback)
-
 
572
			std::cerr << "No callback function was defined! Can't save single track!" << std::endl;
-
 
573
	}
-
 
574
 
-
 
575
	if (qName.toLower() == QString("activities"))
-
 
576
	{
-
 
577
		con.clear();
-
 
578
		subCon.clear();
-
 
579
		history = false;
-
 
580
	}
-
 
581
 
-
 
582
	if(qName.toLower() == QString("beginposition") || qName.toLower() == QString("endposition") ||
-
 
583
	                  qName.toLower() == QString("averageheartratebpm") || qName.toLower() == QString("maximumheartratebpm"))
-
 
584
		subCon.clear();
555
 
585
 
556
	if (qName.toLower() == QString("heartratebpm") || qName.toLower() == QString("position"))
586
	if(qName.toLower() == QString("heartratebpm") || qName.toLower() == QString("position"))
557
	   subCon.clear();
587
		subCon.clear();
558
 
588
 
559
	if (indent < 0)
589
	if(indent < 0)
560
	{
590
	{
561
	   __error = 2;
591
		__error = 2;
562
	   return FALSE;
592
		return FALSE;
563
	}
593
	}
564
 
594
 
565
	return TRUE;
595
	return TRUE;
566
}
596
}
567
 
597
 
568
/*
598
/*
569
 * The reader calls this function when it has parsed a chunk of character data
599
 * The reader calls this function when it has parsed a chunk of character data
570
 * - either normal character data or character data inside a CDATA section.
600
 * - either normal character data or character data inside a CDATA section.
571
 */
601
 */
572
bool gmn_import::characters (const QString& ch)
602
bool gmn_import::characters(const QString& ch)
573
{
603
{
574
	if (con == QString("course"))
604
	if(con == QString("course"))
575
	{
605
	{
576
	   if (tk == FLD_NAME)
606
		if(tk == FLD_NAME)
577
	   {
607
		{
578
	      strncpy (run.workout.name, ch.toAscii(), 15);
608
			strncpy(run.workout.name, ch.toAscii(), 15);
579
	      run.workout.name[15] = 0;
609
			run.workout.name[15] = 0;
580
	      tk = 0;
610
			tk = 0;
581
	   }
611
		}
582
	}
612
	}
583
 
613
 
584
	if (history && con == QString("activity"))
614
	if(history && con == QString("activity"))
585
	{
615
	{
586
	   if (tk == FLD_ID)
616
		if(tk == FLD_ID)
587
	   {
617
		{
588
	      strncpy (run.workout.name, ch.toAscii(), 15);
618
			strncpy(run.workout.name, ch.toAscii(), 15);
589
	      run.workout.name[15] = 0;
619
			run.workout.name[15] = 0;
590
	      tk = 0;
620
			tk = 0;
591
	   }
621
		}
592
	}
622
	}
593
 
623
 
594
	if (con == QString("lap"))
624
	if(con == QString("lap"))
595
	{
625
	{
596
	   if (tk == FLD_DISTANCEMETERS)
626
		if(tk == FLD_DISTANCEMETERS)
597
	   {
627
		{
598
	      lap.total_dist = (float32)ch.toFloat();
628
			lap.total_dist = (float32)ch.toFloat();
599
	      tk = 0;
629
			tk = 0;
600
	   }
630
		}
601
 
631
 
602
	   if (tk == FLD_INTENSITY)
632
		if(tk == FLD_INTENSITY)
603
	   {
633
		{
604
	      lap.intensity = (ch.toLower() == QString("activ")) ? 0 : 1;
634
			lap.intensity = (ch.toLower() == QString("activ")) ? 0 : 1;
605
	      tk = 0;
635
			tk = 0;
606
	   }
636
		}
607
 
637
 
608
	   if (tk == FLD_STARTTIME)
638
		if(tk == FLD_STARTTIME)
609
	   {
639
		{
610
	      lap.start_time = garmin_time (ch);
640
			lap.start_time = garmin_time(ch);
611
	      tk = 0;
641
			tk = 0;
612
	   }
642
		}
613
 
643
 
614
	   if (tk == FLD_TOTALTIMESECONDS)
644
		if(tk == FLD_TOTALTIMESECONDS)
615
	   {
645
		{
616
	      lap.total_time = (uint32)(ch.toDouble() * 100.0);
646
			lap.total_time = (uint32)(ch.toDouble() * 100.0);
617
	      tk = 0;
647
			tk = 0;
618
	   }
648
		}
619
 
649
 
620
	   if (tk == FLD_CADENCE)
650
		if(tk == FLD_CADENCE)
621
	   {
651
		{
622
	      lap.avg_cadence = (uint8)ch.toUInt();
652
			lap.avg_cadence = (uint8)ch.toUInt();
623
	      tk = 0;
653
			tk = 0;
624
	   }
654
		}
625
 
655
 
626
	   if (tk == FLD_CALORIES)
656
		if(tk == FLD_CALORIES)
627
	   {
657
		{
628
	      lap.calories = (uint16)ch.toUInt();
658
			lap.calories = (uint16)ch.toUInt();
629
	      tk = 0;
659
			tk = 0;
630
	   }
660
		}
631
 
661
 
632
	   if (tk == FLD_MAXSPEED)
662
		if(tk == FLD_MAXSPEED)
633
	   {
663
		{
634
	      lap.max_speed = (float32)ch.toFloat();
664
			lap.max_speed = (float32)ch.toFloat();
635
	      tk = 0;
665
			tk = 0;
636
	   }
666
		}
637
 
667
 
638
	   if (tk == FLD_TRIGGERMETHOD)
668
		if(tk == FLD_TRIGGERMETHOD)
639
	   {
669
		{
640
	      if (ch.toLower() == QString("manual"))
670
			if(ch.toLower() == QString("manual"))
641
		 lap.trigger_method = D1011_manual;
671
				lap.trigger_method = D1011_manual;
642
	      else if (ch.toLower() == QString("distance"))
672
			else if(ch.toLower() == QString("distance"))
643
		 lap.trigger_method = D1011_distance;
673
				lap.trigger_method = D1011_distance;
644
	      else if (ch.toLower() == QString("location"))
674
			else if(ch.toLower() == QString("location"))
645
		 lap.trigger_method = D1011_location;
675
				lap.trigger_method = D1011_location;
646
	      else if (ch.toLower() == QString("time"))
676
			else if(ch.toLower() == QString("time"))
647
		 lap.trigger_method = D1011_time;
677
				lap.trigger_method = D1011_time;
648
	      else if (ch.toLower() == QString("HeartRate"))
678
			else if(ch.toLower() == QString("HeartRate"))
649
		 lap.trigger_method = D1011_heart_rate;
679
				lap.trigger_method = D1011_heart_rate;
650
	   }
680
		}
651
 
681
 
652
	   if (subCon.toLower() == QString("BeginPosition").toLower())
682
		if(subCon.toLower() == QString("BeginPosition").toLower())
653
	   {
683
		{
654
	      if (tk == FLD_LATITUDEDEGREES)
684
			if(tk == FLD_LATITUDEDEGREES)
655
	      {
685
			{
656
		 lap.begin.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
686
				lap.begin.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
657
		 tk = 0;
687
				tk = 0;
658
	      }
688
			}
659
 
689
 
660
	      if (tk == FLD_LONGITUDEDEGREES)
690
			if(tk == FLD_LONGITUDEDEGREES)
661
	      {
691
			{
662
		 lap.begin.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
692
				lap.begin.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
663
		 tk = 0;
693
				tk = 0;
664
	      }
694
			}
665
	   }
695
		}
666
	   else if (subCon.toLower() == QString("EndPosition").toLower())
696
		else if(subCon.toLower() == QString("EndPosition").toLower())
667
	   {
697
		{
668
	      if (tk == FLD_LATITUDEDEGREES)
698
			if(tk == FLD_LATITUDEDEGREES)
669
	      {
699
			{
670
		 lap.end.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
700
				lap.end.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
671
		 tk = 0;
701
				tk = 0;
672
	      }
702
			}
673
 
703
 
674
	      if (tk == FLD_LONGITUDEDEGREES)
704
			if(tk == FLD_LONGITUDEDEGREES)
675
	      {
705
			{
676
		 lap.end.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
706
				lap.end.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
677
		 tk = 0;
707
				tk = 0;
678
	      }
708
			}
679
	   }
709
		}
680
	   else if (subCon.toLower() == QString("AverageHeartRateBpm").toLower())
710
		else if(subCon.toLower() == QString("AverageHeartRateBpm").toLower())
681
	   {
711
		{
682
	      if (tk == FLD_VALUE)
712
			if(tk == FLD_VALUE)
683
	      {
713
			{
684
		 lap.avg_heart_rate = (uint8)ch.toInt();
714
				lap.avg_heart_rate = (uint8)ch.toInt();
685
		 tk = 0;
715
				tk = 0;
686
	      }
716
			}
687
	   }
717
		}
688
	   else if (subCon.toLower() == QString("MaximumHeartRateBpm").toLower())
718
		else if(subCon.toLower() == QString("MaximumHeartRateBpm").toLower())
689
	   {
719
		{
690
	      if (tk == FLD_VALUE)
720
			if(tk == FLD_VALUE)
691
	      {
721
			{
692
		 lap.max_heart_rate = (uint8)ch.toInt();
722
				lap.max_heart_rate = (uint8)ch.toInt();
693
		 tk = 0;
723
				tk = 0;
694
	      }
724
			}
695
	   }
725
		}
696
	}
726
	}
697
 
727
 
698
	if (con == QString("trackpoint"))
728
	if(con == QString("trackpoint"))
699
	{
729
	{
700
	   if (tk == FLD_TIME)
730
		if(tk == FLD_TIME)
701
	   {
731
		{
702
	      point.time = garmin_time (ch);
732
			point.time = garmin_time(ch);
703
 
733
 
704
	      if (history && first_tpos == tpos && plap)
734
			if(history && first_tpos == tpos && plap)
705
		 plap->start_time = point.time;
735
				plap->start_time = point.time;
706
 
736
 
707
	      tk = 0;
737
			tk = 0;
708
	   }
738
		}
709
 
739
 
710
	   if (tk == FLD_ALTITUDEMETERS)
740
		if(tk == FLD_ALTITUDEMETERS)
711
	   {
741
		{
712
	      point.alt = (ch.toFloat() >= 1.0e24) ? 1.0e24 : (float32)ch.toFloat();
742
			point.alt = (ch.toFloat() >= 1.0e24) ? 1.0e24 : (float32)ch.toFloat();
713
	      tk = 0;
743
			tk = 0;
714
	   }
744
		}
715
 
745
 
716
	   if (tk == FLD_DISTANCEMETERS)
746
		if(tk == FLD_DISTANCEMETERS)
717
	   {
747
		{
718
	      point.distance = (ch.toFloat() >= 1.0e24) ? 1.0e24 : (float32)ch.toFloat();
748
			point.distance = (ch.toFloat() >= 1.0e24) ? 1.0e24 : (float32)ch.toFloat();
719
	      tk = 0;
749
			tk = 0;
720
	   }
750
		}
721
 
751
 
722
	   if (tk == FLD_SENSORSTATE)
752
		if(tk == FLD_SENSORSTATE)
723
	   {
753
		{
724
	      point.sensor = (ch.toLower() == QString("absent")) ? false : true;
754
			point.sensor = (ch.toLower() == QString("absent")) ? false : true;
725
	      tk = 0;
755
			tk = 0;
726
	   }
756
		}
727
 
757
 
728
	   if (subCon.toLower() == QString("position"))
758
		if(subCon.toLower() == QString("position"))
729
	   {
759
		{
730
	      if (tk == FLD_LATITUDEDEGREES)
760
			if(tk == FLD_LATITUDEDEGREES)
731
	      {
761
			{
732
		 point.posn.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
762
				point.posn.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
733
 
763
 
734
		 if (history && tpos == first_tpos && plap)	// Add mising information to first lap
764
				if(history && tpos == first_tpos && plap)	// Add mising information to first lap
735
		    plap->begin.lat = point.posn.lat;
765
					plap->begin.lat = point.posn.lat;
736
		 else if (history && point.posn.lat != 0x7fffffff && plap)
766
				else if(history && point.posn.lat != 0x7fffffff && plap)
737
		    plap->end.lat = point.posn.lat;
767
					plap->end.lat = point.posn.lat;
738
 
768
 
739
		 tk = 0;
769
				tk = 0;
740
	      }
770
			}
741
 
771
 
742
	      if (tk == FLD_LONGITUDEDEGREES)
772
			if(tk == FLD_LONGITUDEDEGREES)
743
	      {
773
			{
744
		 point.posn.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
774
				point.posn.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
745
 
775
 
746
		 if (history && tpos == first_tpos && plap)	// Add mising information to first lap
776
				if(history && tpos == first_tpos && plap)	// Add mising information to first lap
747
		    plap->begin.lon = point.posn.lon;
777
					plap->begin.lon = point.posn.lon;
748
		 else if (history && point.posn.lon != 0x7fffffff && plap)
778
				else if(history && point.posn.lon != 0x7fffffff && plap)
749
		    plap->end.lat = point.posn.lon;
779
					plap->end.lat = point.posn.lon;
750
 
780
 
751
		 tk = 0;
781
				tk = 0;
752
	      }
782
			}
753
	   }
783
		}
754
	   else if (subCon.toLower() == QString("heartratebpm"))
784
		else if(subCon.toLower() == QString("heartratebpm"))
755
	   {
785
		{
756
	      if (tk == FLD_VALUE)
786
			if(tk == FLD_VALUE)
757
	      {
787
			{
758
		 point.heart_rate = (unsigned char)ch.toInt();
788
				point.heart_rate = (unsigned char)ch.toInt();
759
		 tk = 0;
789
				tk = 0;
760
	      }
790
			}
761
	   }
791
		}
762
	}
792
	}
763
 
793
 
764
	return TRUE;
794
	return TRUE;
765
}
795
}
766
 
796
 
767
/*
797
/*
768
 * The following function reads a Garmin HST file, parses the XML
798
 * The following function reads a Garmin HST file, parses the XML
769
 * content and creates the gmn files. If there already exists a file,
799
 * content and creates the gmn files. If there already exists a file,
770
 * it's not overwritten.
800
 * it's not overwritten.
771
 */
801
 */
772
int gmn_import::import ()
802
int gmn_import::import()
773
{
803
{
774
QXmlSimpleReader reader;
804
	QXmlSimpleReader reader;
775
 
805
 
776
	if (!qfstat)
806
	if(!qfstat)
777
	   return 1;
807
		return 1;
778
 
808
 
779
	QXmlInputSource source (&file);
809
	QXmlInputSource source(&file);
780
	reader.setContentHandler (this);
810
	reader.setContentHandler(this);
781
	reader.parse (source);
811
	reader.parse(source);
782
	return 0;
812
	return 0;
783
}
813
}
784
 
814
 
785
QString gmn_import::getKey (int pos)
815
QString gmn_import::getKey(int pos)
786
{
816
{
787
int i = 0;
817
	int i = 0;
788
 
818
 
789
	while (keys[i].id > 0)
819
	while(keys[i].id > 0)
790
	{
820
	{
791
	   if (keys[i].id == pos)
821
		if(keys[i].id == pos)
792
	      return keys[i].name;
822
			return keys[i].name;
793
 
823
 
794
	   i++;
824
		i++;
795
	}
825
	}
796
 
826
 
797
	return QString::null;
827
	return QString::null;
798
}
828
}
799
 
829
 
800
QString gmn_import::getError (int err)
830
QString gmn_import::getError(int err)
801
{
831
{
802
	if (err > eMax || err < 1)
832
	if(err > eMax || err < 1)
803
	   return 0;
833
		return 0;
804
 
834
 
805
	return getKey (ERR_FIRST + err);
835
	return getKey(ERR_FIRST + err);
806
}
836
}
807
 
837
 
808
QString gmn_import::getError ()
838
QString gmn_import::getError()
809
{
839
{
810
	return getKey (ERR_FIRST + __error);
840
	return getKey(ERR_FIRST + __error);
811
}
841
}
812
 
842