You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

glogbook.cc 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. Access Garmin Logbook (Forerunner/Foretracker) data files.
  3. Copyright (C) 2004, 2005, 2006, 2007 Robert Lipe, robertlipe+source@gpsbabel.org
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
  15. */
  16. #include "defs.h"
  17. #include "xmlgeneric.h"
  18. #include "src/core/file.h"
  19. #include <QtCore/QXmlStreamAttributes>
  20. #include <QtCore/QXmlStreamWriter>
  21. static gbfile* ofd;
  22. static QString ostring;
  23. static QXmlStreamWriter writer(&ostring);
  24. static Waypoint* wpt_tmp;
  25. static route_head* trk_head;
  26. #define MYNAME "glogbook"
  27. static
  28. arglist_t glogbook_args[] = {
  29. ARG_TERMINATOR
  30. };
  31. /* Tracks */
  32. static xg_callback gl_trk_s;
  33. // static xg_callback gl_trk_ident;
  34. static xg_callback gl_trk_pnt_s, gl_trk_pnt_e;
  35. static xg_callback gl_trk_utc;
  36. static xg_callback gl_trk_lat;
  37. static xg_callback gl_trk_long;
  38. static xg_callback gl_trk_alt;
  39. static xg_tag_mapping gl_map[] = {
  40. { gl_trk_s, cb_start, "/History/Run/Track" },
  41. { gl_trk_pnt_s,cb_start, "/History/Run/Track/Trackpoint/Position" },
  42. { gl_trk_pnt_e,cb_end, "/History/Run/Track/Trackpoint/Position" },
  43. { gl_trk_lat, cb_cdata, "/History/Run/Track/Trackpoint/Position/Latitude" },
  44. { gl_trk_long, cb_cdata, "/History/Run/Track/Trackpoint/Position/Longitude" },
  45. { gl_trk_alt, cb_cdata, "/History/Run/Track/Trackpoint/Position/Altitude" },
  46. { gl_trk_utc, cb_cdata, "/History/Run/Track/Trackpoint/Time" },
  47. { NULL, (xg_cb_type)0, NULL}
  48. };
  49. static void
  50. glogbook_rd_init(const QString& fname)
  51. {
  52. xml_init(fname, gl_map, NULL);
  53. }
  54. static void
  55. glogbook_read(void)
  56. {
  57. xml_read();
  58. }
  59. static void
  60. glogbook_rd_deinit(void)
  61. {
  62. xml_deinit();
  63. }
  64. static void
  65. glogbook_wr_init(const QString& fname)
  66. {
  67. ofd = gbfopen(fname, "w", MYNAME);
  68. writer.setAutoFormatting(true);
  69. writer.setAutoFormattingIndent(4);
  70. writer.writeStartDocument();
  71. }
  72. static void
  73. glogbook_wr_deinit(void)
  74. {
  75. writer.writeEndDocument();
  76. gbfputs(ostring,ofd);
  77. gbfclose(ofd);
  78. ofd = NULL;
  79. }
  80. static void
  81. glogbook_waypt_pr(const Waypoint* wpt)
  82. {
  83. writer.writeStartElement("Trackpoint");
  84. writer.writeStartElement("Position");
  85. writer.writeTextElement("Latitude", QString::number(wpt->latitude,'f', 5));
  86. writer.writeTextElement("Longitude", QString::number(wpt->longitude,'f', 5));
  87. writer.writeTextElement("Altitude", QString::number(wpt->altitude,'f', 3));
  88. writer.writeEndElement(); // Position
  89. writer.writeTextElement("Time", wpt->GetCreationTime().toPrettyString());
  90. writer.writeEndElement(); // Trackpoint
  91. }
  92. static void
  93. glogbook_hdr(const route_head* rte)
  94. {
  95. writer.writeStartElement("Track");
  96. }
  97. static void
  98. glogbook_ftr(const route_head* rte)
  99. {
  100. writer.writeEndElement();
  101. }
  102. static void
  103. glogbook_write(void)
  104. {
  105. #if 0
  106. gbfprintf(ofd, "<?xml version=\"1.0\" ?>\n");
  107. gbfprintf(ofd, "<History xmlns=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.garmin.com/xmlschemas/ForerunnerLogbook http://www.garmin.com/xmlschemas/ForerunnerLogbookv1.xsd\" version=\"1\">\n");
  108. gbfprintf(ofd, " <Run>\n");
  109. #else
  110. writer.writeStartElement("History");
  111. writer.writeStartElement("Run");
  112. #endif
  113. track_disp_all(glogbook_hdr, glogbook_ftr, glogbook_waypt_pr);
  114. writer.writeEndElement(); // Run
  115. writer.writeEndElement(); // History
  116. }
  117. void gl_trk_s(xg_string args, const QXmlStreamAttributes*)
  118. {
  119. trk_head = route_head_alloc();
  120. track_add_head(trk_head);
  121. }
  122. void gl_trk_pnt_s(xg_string args, const QXmlStreamAttributes*)
  123. {
  124. wpt_tmp = new Waypoint;
  125. }
  126. void gl_trk_pnt_e(xg_string args, const QXmlStreamAttributes*)
  127. {
  128. track_add_wpt(trk_head, wpt_tmp);
  129. }
  130. void gl_trk_utc(xg_string args, const QXmlStreamAttributes*)
  131. {
  132. wpt_tmp->SetCreationTime(xml_parse_time(args));
  133. }
  134. void gl_trk_lat(xg_string args, const QXmlStreamAttributes*)
  135. {
  136. wpt_tmp->latitude = args.toDouble();
  137. }
  138. void gl_trk_long(xg_string args, const QXmlStreamAttributes*)
  139. {
  140. wpt_tmp->longitude = args.toDouble();
  141. }
  142. void gl_trk_alt(xg_string args, const QXmlStreamAttributes*)
  143. {
  144. wpt_tmp->altitude = args.toDouble();
  145. }
  146. ff_vecs_t glogbook_vecs = {
  147. ff_type_file,
  148. { ff_cap_none, (ff_cap)(ff_cap_read | ff_cap_write), ff_cap_none},
  149. glogbook_rd_init,
  150. glogbook_wr_init,
  151. glogbook_rd_deinit,
  152. glogbook_wr_deinit,
  153. glogbook_read,
  154. glogbook_write,
  155. NULL,
  156. glogbook_args,
  157. CET_CHARSET_ASCII, 0 /* CET-REVIEW */
  158. };