Subversion Repositories public

Rev

Rev 225 | Rev 313 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 225 Rev 232
Line 1... Line 1...
1
/***************************************************************************
1
/***************************************************************************
2
 *   Copyright (C) 2007, 2008 by Andreas Theofilu                          *
2
 *   Copyright (C) 2007 - 2009 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 <qxml.h>
-
 
24
#include <qlistview.h>
23
#include <qlistview.h>
25
#include <qgrid.h>
-
 
26
#include <qdatetime.h>
24
#include <qdatetime.h>
27
#include <qxml.h>
25
#include <QXmlReader>
28
 
26
 
29
#include <klocale.h>
27
#include <klocale.h>
30
 
28
 
31
#include "import.h"
29
#include "import.h"
32
 
30
 
Line 169... Line 167...
169
}
167
}
170
 
168
 
171
gmn_import::gmn_import (const QFile &qfile)
169
gmn_import::gmn_import (const QFile &qfile)
172
{
170
{
173
	Initialize ();
171
	Initialize ();
174
	file.setName (qfile.name ());
172
	file.setFileName (qfile.fileName ());
175
 
173
 
176
	if (file.exists ())
174
	if (file.exists ())
177
	   qfstat = true;
175
	   qfstat = true;
178
}
176
}
179
 
177
 
Line 184... Line 182...
184
	   file.close ();
182
	   file.close ();
185
	   qfopen = false;
183
	   qfopen = false;
186
	}
184
	}
187
 
185
 
188
	qfstat = false;
186
	qfstat = false;
189
	file.setName (qfile.name ());
187
	file.setFileName (qfile.fileName ());
190
 
188
 
191
	if (file.exists ())
189
	if (file.exists ())
192
	   qfstat = true;
190
	   qfstat = true;
193
}
191
}
194
 
192
 
Line 200... Line 198...
200
	   qfopen = false;
198
	   qfopen = false;
201
	   __error = 1;
199
	   __error = 1;
202
	}
200
	}
203
 
201
 
204
	qfstat = false;
202
	qfstat = false;
205
	file.setName (sfile);
203
	file.setFileName (sfile);
206
 
204
 
207
	if (file.exists ())
205
	if (file.exists ())
208
	   qfstat = true;
206
	   qfstat = true;
209
}
207
}
210
 
208
 
Line 234... Line 232...
234
 * This function initializes the XML parser.
232
 * This function initializes the XML parser.
235
 */
233
 */
236
bool gmn_import::startDocument()
234
bool gmn_import::startDocument()
237
{
235
{
238
	indent = 0;
236
	indent = 0;
239
	con.setAscii("");
237
	con.clear();
240
	subCon.setAscii("");
238
	subCon.clear();
241
	lpos = tpos = oldLPos = 0;
239
	lpos = tpos = oldLPos = 0;
242
	history = fakeLap = false;
240
	history = fakeLap = false;
243
	first_tpos = 0;
241
	first_tpos = 0;
244
	prun = 0;
242
	prun = 0;
245
	plap = 0;
243
	plap = 0;
Line 255... Line 253...
255
{
253
{
256
int i = CON_FIRST;
254
int i = CON_FIRST;
257
 
255
 
258
	while (i <= CON_LAST)
256
	while (i <= CON_LAST)
259
	{
257
	{
260
	   if (qName.lower() == getKey(i).lower())
258
	   if (qName.toLower() == getKey(i).toLower())
261
	   {
259
	   {
262
	      if (qName.lower() == QString("course") || qName.lower() == QString("activity"))
260
	      if (qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
263
	      {
261
	      {
264
		 memset (&run, 0, sizeof (D1009));
262
		 memset (&run, 0, sizeof (D1009));
265
 
263
 
266
		 if (i == CON_ACTIVITY)
264
		 if (i == CON_ACTIVITY)
267
		 {
265
		 {
268
		    con.setAscii("activity");
266
		    con = "activity";
269
		    history = true;
267
		    history = true;
270
		 }
268
		 }
271
		 else
269
		 else
272
		    con.setAscii("course");
270
		    con = "course";
273
 
271
 
274
		 run.track_index = 0;
272
		 run.track_index = 0;
275
		 run.first_lap_index = 0;
273
		 run.first_lap_index = 0;
276
		 run.sport_type = 0;		// Running
274
		 run.sport_type = 0;		// Running
277
		 tk = i;
275
		 tk = i;
278
	      }
276
	      }
279
 
277
 
280
	      if (qName.lower() == QString("lap"))
278
	      if (qName.toLower() == QString("lap"))
281
	      {
279
	      {
282
		 memset (&lap, 0, sizeof (D1015));
280
		 memset (&lap, 0, sizeof (D1015));
283
		 lap.index = lpos;
281
		 lap.index = lpos;
284
		 lap.begin.lat = 0x7fffffff;
282
		 lap.begin.lat = 0x7fffffff;
285
		 lap.begin.lon = 0x7fffffff;
283
		 lap.begin.lon = 0x7fffffff;
286
		 lap.end.lat = 0x7fffffff;
284
		 lap.end.lat = 0x7fffffff;
287
		 lap.end.lon = 0x7fffffff;
285
		 lap.end.lon = 0x7fffffff;
288
		 con.setAscii("lap");
286
		 con = "lap";
289
		 lpos++;
287
		 lpos++;
290
		 tk = i;
288
		 tk = i;
291
	      }
289
	      }
292
 
290
 
293
	      if (con == QString("lap") && qName.lower() == QString("BeginPosition").lower())
291
	      if (con == QString("lap") && qName.toLower() == QString("BeginPosition").toLower())
294
		 subCon = qName.lower();
292
		 subCon = qName.toLower();
295
	      else if (con == QString("lap") && qName.lower() == QString("EndPosition").lower())
293
	      else if (con == QString("lap") && qName.toLower() == QString("EndPosition").toLower())
296
		 subCon = qName.lower();
294
		 subCon = qName.toLower();
297
	      else if (con == QString("lap") && qName.lower() == QString("AverageHeartRateBpm").lower())
295
	      else if (con == QString("lap") && qName.toLower() == QString("AverageHeartRateBpm").toLower())
298
		 subCon = qName.lower();
296
		 subCon = qName.toLower();
299
	      else if (con == QString("lap") && qName.lower() == QString("MaximumHeartRateBpm").lower())
297
	      else if (con == QString("lap") && qName.toLower() == QString("MaximumHeartRateBpm").toLower())
300
		 subCon = qName.lower();
298
		 subCon = qName.toLower();
301
 
299
 
302
	      if (history && qName.lower() == QString("track") && con.lower() == QString("lap"))
300
	      if (history && qName.toLower() == QString("track") && con.toLower() == QString("lap"))
303
	      {
301
	      {
304
		 first_tpos = tpos + 1;
302
		 first_tpos = tpos + 1;
305
		 endElement (QString::null, QString::null, QString("Lap"));
303
		 endElement (QString::null, QString::null, QString("Lap"));
306
		 indent++;
304
		 indent++;
307
		 con.setAscii("lap");
305
		 con = "lap";
308
		 fakeLap = true;
306
		 fakeLap = true;
309
	      }
307
	      }
310
 
308
 
311
	      if (qName.lower() == QString("trackpoint"))
309
	      if (qName.toLower() == QString("trackpoint"))
312
	      {
310
	      {
313
		 memset (&point, 0, sizeof (D304));
311
		 memset (&point, 0, sizeof (D304));
314
		 point.alt = 1.0e24;
312
		 point.alt = 1.0e24;
315
		 point.posn.lat = 0x7fffffff;
313
		 point.posn.lat = 0x7fffffff;
316
		 point.posn.lon = 0x7fffffff;
314
		 point.posn.lon = 0x7fffffff;
317
		 con.setAscii("trackpoint");
315
		 con = "trackpoint";
318
		 tpos++;
316
		 tpos++;
319
		 tk = i;
317
		 tk = i;
320
	      }
318
	      }
321
 
319
 
322
	      if (con == QString("trackpoint") && qName.lower() == QString("position"))
320
	      if (con == QString("trackpoint") && qName.toLower() == QString("position"))
323
		 subCon = qName.lower();
321
		 subCon = qName.toLower();
324
	      else if (con == QString("trackpoint") && qName.lower() == QString("heartratebpm"))
322
	      else if (con == QString("trackpoint") && qName.toLower() == QString("heartratebpm"))
325
		 subCon = qName.lower();
323
		 subCon = qName.toLower();
326
	   }
324
	   }
327
 
325
 
328
	   i++;
326
	   i++;
329
	}
327
	}
330
 
328
 
331
	i = FLD_FIRST;
329
	i = FLD_FIRST;
332
 
330
 
333
	while (i <= FLD_LAST)
331
	while (i <= FLD_LAST)
334
	{
332
	{
335
	   if (qName.lower() == getKey(i).lower())
333
	   if (qName.toLower() == getKey(i).toLower())
336
	      tk = i;
334
	      tk = i;
337
 
335
 
338
	   i++;
336
	   i++;
339
	}
337
	}
340
 
338
 
Line 348... Line 346...
348
bool gmn_import::endElement( const QString&, const QString&, const QString& qName)
346
bool gmn_import::endElement( const QString&, const QString&, const QString& qName)
349
{
347
{
350
	if (!fakeLap)
348
	if (!fakeLap)
351
	   indent--;
349
	   indent--;
352
 
350
 
353
	if (qName.lower() == QString("lap"))
351
	if (qName.toLower() == QString("lap"))
354
	{
352
	{
355
	   garmin_data *gdt;
353
	   garmin_data *gdt;
356
	   garmin_list *l;
354
	   garmin_list *l;
357
 
355
 
358
	   if (!fakeLap)
356
	   if (!fakeLap)
359
	      con.setAscii("");
357
	      con.clear();
360
 
358
 
361
	   if (history && fakeLap)
359
	   if (history && fakeLap)
362
	   {
360
	   {
363
	      fakeLap = false;
361
	      fakeLap = false;
364
	      return TRUE;
362
	      return TRUE;
Line 439... Line 437...
439
	   }
437
	   }
440
 
438
 
441
	   list = l;
439
	   list = l;
442
	}
440
	}
443
 
441
 
444
	if (history && qName.lower() == QString("track"))
442
	if (history && qName.toLower() == QString("track"))
445
	   first_tpos = 0;
443
	   first_tpos = 0;
446
 
444
 
447
	if (qName.lower() == QString("trackpoint"))
445
	if (qName.toLower() == QString("trackpoint"))
448
	{
446
	{
449
	   garmin_data *gdt;
447
	   garmin_data *gdt;
450
	   garmin_list *l;
448
	   garmin_list *l;
451
 
449
 
452
	   con.setAscii("");
450
	   con.clear();
453
 
451
 
454
	   if (!gmn)		/* allocating space for first structure */
452
	   if (!gmn)		/* allocating space for first structure */
455
	   {
453
	   {
456
	      if ((gmn = garmin_alloc_data (data_Dlist)) == NULL)
454
	      if ((gmn = garmin_alloc_data (data_Dlist)) == NULL)
457
	      {
455
	      {
Line 525... Line 523...
525
	   }
523
	   }
526
 
524
 
527
	   list = l;
525
	   list = l;
528
	}
526
	}
529
 
527
 
530
	if (qName.lower() == QString("course") || qName.lower() == QString("activity"))
528
	if (qName.toLower() == QString("course") || qName.toLower() == QString("activity"))
531
	{
529
	{
532
	   con.setAscii("");
530
	   con.clear();
533
	   run.track_index = tpos - 1;
531
	   run.track_index = tpos - 1;
534
	   run.last_lap_index = lpos - 1;
532
	   run.last_lap_index = lpos - 1;
535
	   memmove (prun, &run, sizeof (D1009));
533
	   memmove (prun, &run, sizeof (D1009));
536
	   history = false;
534
	   history = false;
537
	}
535
	}
538
 
536
 
539
	if (qName.lower() == QString("beginposition") || qName.lower() == QString("endposition") ||
537
	if (qName.toLower() == QString("beginposition") || qName.toLower() == QString("endposition") ||
540
	    qName.lower() == QString("averageheartratebpm") || qName.lower() == QString("maximumheartratebpm"))
538
	    qName.toLower() == QString("averageheartratebpm") || qName.toLower() == QString("maximumheartratebpm"))
541
	   subCon.setAscii("");
539
	   subCon.clear();
542
 
540
 
543
	if (qName.lower() == QString("heartratebpm") || qName.lower() == QString("position"))
541
	if (qName.toLower() == QString("heartratebpm") || qName.toLower() == QString("position"))
544
	   subCon.setAscii("");
542
	   subCon.clear();
545
 
543
 
546
	if (indent < 0)
544
	if (indent < 0)
547
	{
545
	{
548
	   __error = 2;
546
	   __error = 2;
549
	   return FALSE;
547
	   return FALSE;
Line 556... Line 554...
556
 * The reader calls this function when it has parsed a chunk of character data
554
 * The reader calls this function when it has parsed a chunk of character data
557
 * - either normal character data or character data inside a CDATA section.
555
 * - either normal character data or character data inside a CDATA section.
558
 */
556
 */
559
bool gmn_import::characters (const QString& ch)
557
bool gmn_import::characters (const QString& ch)
560
{
558
{
561
int j = FLD_FIRST;
-
 
562
 
-
 
563
	if (con == QString("course"))
559
	if (con == QString("course"))
564
	{
560
	{
565
	   if (tk == FLD_NAME)
561
	   if (tk == FLD_NAME)
566
	   {
562
	   {
567
	      strncpy (run.workout.name, ch.ascii(), 15);
563
	      strncpy (run.workout.name, ch.toAscii(), 15);
568
	      run.workout.name[15] = 0;
564
	      run.workout.name[15] = 0;
569
	      tk = 0;
565
	      tk = 0;
570
	   }
566
	   }
571
	}
567
	}
572
 
568
 
573
	if (history && con == QString("activity"))
569
	if (history && con == QString("activity"))
574
	{
570
	{
575
	   if (tk == FLD_ID)
571
	   if (tk == FLD_ID)
576
	   {
572
	   {
577
	      strncpy (run.workout.name, ch.ascii(), 15);
573
	      strncpy (run.workout.name, ch.toAscii(), 15);
578
	      run.workout.name[15] = 0;
574
	      run.workout.name[15] = 0;
579
	      tk = 0;
575
	      tk = 0;
580
	   }
576
	   }
581
	}
577
	}
582
 
578
 
Line 588... Line 584...
588
	      tk = 0;
584
	      tk = 0;
589
	   }
585
	   }
590
 
586
 
591
	   if (tk == FLD_INTENSITY)
587
	   if (tk == FLD_INTENSITY)
592
	   {
588
	   {
593
	      lap.intensity = (ch.lower() == QString("activ")) ? 0 : 1;
589
	      lap.intensity = (ch.toLower() == QString("activ")) ? 0 : 1;
594
	      tk = 0;
590
	      tk = 0;
595
	   }
591
	   }
596
 
592
 
597
	   if (tk == FLD_STARTTIME)
593
	   if (tk == FLD_STARTTIME)
598
	   {
594
	   {
Line 624... Line 620...
624
	      tk = 0;
620
	      tk = 0;
625
	   }
621
	   }
626
 
622
 
627
	   if (tk == FLD_TRIGGERMETHOD)
623
	   if (tk == FLD_TRIGGERMETHOD)
628
	   {
624
	   {
629
	      if (ch.lower() == QString("manual"))
625
	      if (ch.toLower() == QString("manual"))
630
		 lap.trigger_method = D1011_manual;
626
		 lap.trigger_method = D1011_manual;
631
	      else if (ch.lower() == QString("distance"))
627
	      else if (ch.toLower() == QString("distance"))
632
		 lap.trigger_method = D1011_distance;
628
		 lap.trigger_method = D1011_distance;
633
	      else if (ch.lower() == QString("location"))
629
	      else if (ch.toLower() == QString("location"))
634
		 lap.trigger_method = D1011_location;
630
		 lap.trigger_method = D1011_location;
635
	      else if (ch.lower() == QString("time"))
631
	      else if (ch.toLower() == QString("time"))
636
		 lap.trigger_method = D1011_time;
632
		 lap.trigger_method = D1011_time;
637
	      else if (ch.lower() == QString("HeartRate"))
633
	      else if (ch.toLower() == QString("HeartRate"))
638
		 lap.trigger_method = D1011_heart_rate;
634
		 lap.trigger_method = D1011_heart_rate;
639
	   }
635
	   }
640
 
636
 
641
	   if (subCon.lower() == QString("BeginPosition").lower())
637
	   if (subCon.toLower() == QString("BeginPosition").toLower())
642
	   {
638
	   {
643
	      if (tk == FLD_LATITUDEDEGREES)
639
	      if (tk == FLD_LATITUDEDEGREES)
644
	      {
640
	      {
645
		 lap.begin.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
641
		 lap.begin.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
646
		 tk = 0;
642
		 tk = 0;
Line 650... Line 646...
650
	      {
646
	      {
651
		 lap.begin.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
647
		 lap.begin.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
652
		 tk = 0;
648
		 tk = 0;
653
	      }
649
	      }
654
	   }
650
	   }
655
	   else if (subCon.lower() == QString("EndPosition").lower())
651
	   else if (subCon.toLower() == QString("EndPosition").toLower())
656
	   {
652
	   {
657
	      if (tk == FLD_LATITUDEDEGREES)
653
	      if (tk == FLD_LATITUDEDEGREES)
658
	      {
654
	      {
659
		 lap.end.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
655
		 lap.end.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
660
		 tk = 0;
656
		 tk = 0;
Line 664... Line 660...
664
	      {
660
	      {
665
		 lap.end.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
661
		 lap.end.lon = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
666
		 tk = 0;
662
		 tk = 0;
667
	      }
663
	      }
668
	   }
664
	   }
669
	   else if (subCon.lower() == QString("AverageHeartRateBpm").lower())
665
	   else if (subCon.toLower() == QString("AverageHeartRateBpm").toLower())
670
	   {
666
	   {
671
	      if (tk == FLD_VALUE)
667
	      if (tk == FLD_VALUE)
672
	      {
668
	      {
673
		 lap.avg_heart_rate = (uint8)ch.toInt();
669
		 lap.avg_heart_rate = (uint8)ch.toInt();
674
		 tk = 0;
670
		 tk = 0;
675
	      }
671
	      }
676
	   }
672
	   }
677
	   else if (subCon.lower() == QString("MaximumHeartRateBpm").lower())
673
	   else if (subCon.toLower() == QString("MaximumHeartRateBpm").toLower())
678
	   {
674
	   {
679
	      if (tk == FLD_VALUE)
675
	      if (tk == FLD_VALUE)
680
	      {
676
	      {
681
		 lap.max_heart_rate = (uint8)ch.toInt();
677
		 lap.max_heart_rate = (uint8)ch.toInt();
682
		 tk = 0;
678
		 tk = 0;
Line 708... Line 704...
708
	      tk = 0;
704
	      tk = 0;
709
	   }
705
	   }
710
 
706
 
711
	   if (tk == FLD_SENSORSTATE)
707
	   if (tk == FLD_SENSORSTATE)
712
	   {
708
	   {
713
	      point.sensor = (ch.lower() == QString("absent")) ? false : true;
709
	      point.sensor = (ch.toLower() == QString("absent")) ? false : true;
714
	      tk = 0;
710
	      tk = 0;
715
	   }
711
	   }
716
 
712
 
717
	   if (subCon.lower() == QString("position"))
713
	   if (subCon.toLower() == QString("position"))
718
	   {
714
	   {
719
	      if (tk == FLD_LATITUDEDEGREES)
715
	      if (tk == FLD_LATITUDEDEGREES)
720
	      {
716
	      {
721
		 point.posn.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
717
		 point.posn.lat = (ch.toDouble() == 180.0) ? 0x7fffffff : (sint32)DEG2SEMI(ch.toDouble());
722
 
718
 
Line 738... Line 734...
738
		    plap->end.lat = point.posn.lon;
734
		    plap->end.lat = point.posn.lon;
739
 
735
 
740
		 tk = 0;
736
		 tk = 0;
741
	      }
737
	      }
742
	   }
738
	   }
743
	   else if (subCon.lower() == QString("heartratebpm"))
739
	   else if (subCon.toLower() == QString("heartratebpm"))
744
	   {
740
	   {
745
	      if (tk == FLD_VALUE)
741
	      if (tk == FLD_VALUE)
746
	      {
742
	      {
747
		 point.heart_rate = (unsigned char)ch.toInt();
743
		 point.heart_rate = (unsigned char)ch.toInt();
748
		 tk = 0;
744
		 tk = 0;