Here are some patches from Gehad for the HTML export. I fixed typos while reading them through. There is also one patch from me to include some more characters to be encoded with proper HTML encoding.
miika
From 4547cc90156353da37afd40a448979b503ecaaab Mon Sep 17 00:00:00 2001 From: Miika Turkia <miika.tur...@gmail.com> Date: Thu, 29 May 2014 08:30:05 +0300 Subject: [PATCH 5/5] Need to quote some more HTML characters Double quote will break HTML export when it is e.g. within notes. Similarly < and > characters are treated as HTML tags unless quoted properly. Signed-off-by: Miika Turkia <miika.tur...@gmail.com> --- save-html.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/save-html.c b/save-html.c index 7b86ab0..386ce93 100644 --- a/save-html.c +++ b/save-html.c @@ -50,8 +50,14 @@ char *replace_char(char *str, char replace, char *replace_by) char *quote(char *string) { char *new_line_removed = replace_char(string, '\n', "<br>"); - char *single_quotes_removed = replace_char(new_line_removed, '\'', "'"); + char *less_than_removed = replace_char(new_line_removed, '<', "<"); + char *greater_than_removed = replace_char(less_than_removed, '>', ">"); + char *double_quotes_removed = replace_char(greater_than_removed, '"', """); + char *single_quotes_removed = replace_char(double_quotes_removed, '\'', "'"); free(new_line_removed); + free(less_than_removed); + free(greater_than_removed); + free(double_quotes_removed); return single_quotes_removed; } -- 1.9.1
From 1ed637df64294e2cbe4b19d111d28823d952a75c Mon Sep 17 00:00:00 2001 From: Gehad elrobey <gehadelro...@gmail.com> Date: Wed, 28 May 2014 20:52:05 +0300 Subject: [PATCH 4/5] Exporting tags in json array this will help in searching based on tags also some minor coding-style fixes Signed-off-by: Gehad elrobey <gehadelro...@gmail.com> Signed-off-by: Miika Turkia <miika.tur...@gmail.com> --- save-html.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/save-html.c b/save-html.c index 8f16fdf..7b86ab0 100644 --- a/save-html.c +++ b/save-html.c @@ -100,21 +100,23 @@ void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, const char *post) { put_string(b, pre); + put_string(b, "["); struct tag_entry *tag = dive->tag_list; if (!tag) - put_string(b, "--"); + put_string(b, "\"--\","); - while(tag){ - put_format(b, "%s ", tag->tag->name); + while (tag) { + put_format(b, "\"%s\",", tag->tag->name); tag = tag->next; } + put_string(b, "]"); put_string(b, post); } void write_attribute(struct membuffer *b, const char *att_name, const char *value) { - if(!value) + if (!value) value="--"; put_format(b, "\"%s\":\"%s\",", att_name, value); } @@ -136,7 +138,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) write_attribute(b, "buddy", dive->buddy); write_attribute(b, "divemaster", dive->divemaster); write_attribute(b, "suit", dive->suit); - put_HTML_tags(b, dive, "\"tags\":\"", "\","); + put_HTML_tags(b, dive, "\"tags\":", ","); put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); put_string(b, "},\n"); (*dive_no)++; -- 1.9.1
From f8129311ec1418f8a7df4e771a90e1a65c63657b Mon Sep 17 00:00:00 2001 From: Gehad elrobey <gehadelro...@gmail.com> Date: Wed, 28 May 2014 14:43:57 +0300 Subject: [PATCH 3/5] Fixing json exporter output The note is prefixed by a colon Fixing the output of Null values of dive master,dive suit, location and buddy. Signed-off-by: Gehad elrobey <gehadelro...@gmail.com> Signed-off-by: Miika Turkia <miika.tur...@gmail.com> --- save-html.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/save-html.c b/save-html.c index e2222b3..8f16fdf 100644 --- a/save-html.c +++ b/save-html.c @@ -59,7 +59,7 @@ void put_HTML_notes(struct membuffer *b, struct dive *dive, const char *pre, con { if (dive->notes) { char *notes = quote(dive->notes); - put_format(b, "%s: %s %s", pre, notes, post); + put_format(b, "%s%s%s", pre, notes, post); free(notes); } } @@ -101,6 +101,10 @@ void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, cons { put_string(b, pre); struct tag_entry *tag = dive->tag_list; + + if (!tag) + put_string(b, "--"); + while(tag){ put_format(b, "%s ", tag->tag->name); tag = tag->next; @@ -108,6 +112,13 @@ void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, cons put_string(b, post); } +void write_attribute(struct membuffer *b, const char *att_name, const char *value) +{ + if(!value) + value="--"; + put_format(b, "\"%s\":\"%s\",", att_name, value); +} + void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) { put_string(b, "{"); @@ -115,16 +126,16 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) put_format(b, "\"subsurface_number\":%d,", dive->number); put_HTML_date(b, dive, "\"date\":\"", "\","); put_HTML_time(b, dive, "\"time\":\"", "\","); - put_format(b, "\"location\":\"%s\",", dive->location); + write_attribute(b, "location", dive->location); put_format(b, "\"rating\":%d,", dive->rating); put_format(b, "\"visibility\":%d,", dive->visibility); put_string(b, "\"temperature\":{"); put_HTML_airtemp(b, dive, "\"air\":\"", "\","); put_HTML_watertemp(b, dive, "\"water\":\"", "\","); put_string(b, " },"); - put_format(b, "\"buddy\":\"%s\",", dive->buddy); - put_format(b, "\"divemaster\":\"%s\",", dive->divemaster); - put_format(b, "\"suit\":\"%s\",", dive->suit); + write_attribute(b, "buddy", dive->buddy); + write_attribute(b, "divemaster", dive->divemaster); + write_attribute(b, "suit", dive->suit); put_HTML_tags(b, dive, "\"tags\":\"", "\","); put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); put_string(b, "},\n"); -- 1.9.1
From eea36301933d504f62396b5816c50a6f7c3c0e8c Mon Sep 17 00:00:00 2001 From: Gehad elrobey <gehadelro...@gmail.com> Date: Wed, 28 May 2014 00:06:56 +0300 Subject: [PATCH 2/5] Some fixing to the json exporter -checking for zero kelvin degrees temperature -showing dives in group of trips -show the number of dives starting from 1 as in subsurface application. -producing localized output as selected in the user's preferences. -using < and > on the arrow buttons in the HTML file. -Calling the translation functions for text strings Signed-off-by: Gehad elrobey <gehadelro...@gmail.com> Signed-off-by: Miika Turkia <miika.tur...@gmail.com> --- save-html.c | 126 +++++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 99 insertions(+), 27 deletions(-) diff --git a/save-html.c b/save-html.c index a9b48fc..e2222b3 100644 --- a/save-html.c +++ b/save-html.c @@ -76,8 +76,12 @@ void put_HTML_airtemp(struct membuffer *b, struct dive *dive, const char *pre, c const char *unit; double value; + if (!dive->airtemp.mkelvin) { + put_format(b, "%s--%s", pre, post); + return; + } value = get_temp_units(dive->airtemp.mkelvin, &unit); - put_format(b, "%s%.1f %s%s",pre, value, unit, post); + put_format(b, "%s%.1f %s%s", pre, value, unit, post); } void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post) @@ -85,8 +89,12 @@ void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, const char *unit; double value; + if (!dive->watertemp.mkelvin) { + put_format(b, "%s--%s", pre, post); + return; + } value = get_temp_units(dive->watertemp.mkelvin, &unit); - put_format(b, "%s%.1f %s%s",pre, value, unit, post); + put_format(b, "%s%.1f %s%s", pre, value, unit, post); } void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, const char *post) @@ -100,40 +108,104 @@ void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, cons put_string(b, post); } -void write_dives(struct membuffer *b,bool selected_only) +void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) { - int i, dive_no = 0; + put_string(b, "{"); + put_format(b, "\"number\":%d,", *dive_no); + put_format(b, "\"subsurface_number\":%d,", dive->number); + put_HTML_date(b, dive, "\"date\":\"", "\","); + put_HTML_time(b, dive, "\"time\":\"", "\","); + put_format(b, "\"location\":\"%s\",", dive->location); + put_format(b, "\"rating\":%d,", dive->rating); + put_format(b, "\"visibility\":%d,", dive->visibility); + put_string(b, "\"temperature\":{"); + put_HTML_airtemp(b, dive, "\"air\":\"", "\","); + put_HTML_watertemp(b, dive, "\"water\":\"", "\","); + put_string(b, " },"); + put_format(b, "\"buddy\":\"%s\",", dive->buddy); + put_format(b, "\"divemaster\":\"%s\",", dive->divemaster); + put_format(b, "\"suit\":\"%s\",", dive->suit); + put_HTML_tags(b, dive, "\"tags\":\"", "\","); + put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); + put_string(b, "},\n"); + (*dive_no)++; +} + +void write_no_trip (struct membuffer *b, int *dive_no) +{ + int i; struct dive *dive; + put_format(b, "{"); + put_format(b, "\"name\":\"Other\","); + put_format(b, "\"dives\":["); + for_each_dive(i, dive) { - if (selected_only) { + if (!dive->divetrip) + write_one_dive(b, dive, dive_no); + } + put_format(b, "]},\n\n"); +} + +void write_trip (struct membuffer *b, dive_trip_t *trip, int *dive_no) +{ + int i; + struct dive *dive; + + put_format(b, "{"); + put_format(b, "\"name\":\"%s\",",trip->location); + put_format(b, "\"dives\":["); + + for (dive = trip->dives; dive != NULL; dive = dive->next){ + write_one_dive(b, dive, dive_no); + } + + put_format(b, "]},\n\n"); +} + +void write_trips(struct membuffer *b,bool selected_only) +{ + int i, dive_no = 0; + struct dive *dive; + dive_trip_t *trip; + + for (trip = dive_trip_list; trip != NULL; trip = trip->next) + trip->index = 0; + + if (selected_only) { + put_format(b, "{"); + put_format(b, "\"name\":\"Other\","); + put_format(b, "\"dives\":["); + + for_each_dive(i, dive) { if (!dive->selected) continue; + write_one_dive(b, dive, &dive_no); } - put_string(b, "{"); - put_format(b, "\"number\":%d,", dive_no); - put_HTML_date(b, dive, "\"date\":\"", "\","); - put_HTML_time(b, dive, "\"time\":\"", "\","); - put_format(b, "\"location\":\"%s\",", dive->location); - put_format(b, "\"rating\":%d,", dive->rating); - put_format(b, "\"visibility\":%d,", dive->visibility); - put_string(b, "\"temperature\":{"); - put_HTML_airtemp(b, dive, "\"air\":\"", "\","); - put_HTML_watertemp(b, dive, "\"water\":\"", "\","); - put_string(b, " },"); - put_format(b, "\"buddy\":\"%s\",", dive->buddy); - put_format(b, "\"divemaster\":\"%s\",", dive->divemaster); - put_format(b, "\"suit\":\"%s\",", dive->suit); - put_HTML_tags(b, dive, "\"tags\":\"", "\","); - put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); - put_string(b, "},\n"); - dive_no++; + put_format(b, "]},\n\n"); + } else { + + for_each_dive(i, dive) { + + trip = dive->divetrip; + + /*Continue if the dive have no trips or we have seen this trip before*/ + if (!trip || trip->index) + continue; + + /* We haven't seen this trip before - save it and all dives */ + trip->index = 1; + write_trip(b, trip, &dive_no); + } + + /*Save all remaining trips into Others*/ + write_no_trip(b, &dive_no); } } -void export_dives(struct membuffer *b,bool selected_only){ - put_string(b, "items=["); - write_dives(b, selected_only); +void export_list(struct membuffer *b,bool selected_only){ + put_string(b, "trips=["); + write_trips(b, selected_only); put_string(b, "]"); } @@ -142,7 +214,7 @@ void export_HTML(const char *file_name, const bool selected_only) FILE *f; struct membuffer buf = { 0 }; - export_dives(&buf, selected_only); + export_list(&buf, selected_only); f = fopen(file_name, "w+"); if (!f) -- 1.9.1
From ec540a6ecb03b03cef0d39f0479fc20f9f7c06bd Mon Sep 17 00:00:00 2001 From: Gehad elrobey <gehadelro...@gmail.com> Date: Fri, 23 May 2014 21:49:49 +0300 Subject: [PATCH 1/5] HTML list exporter exporting the raw dive list into JSON format for later viewing with html and js files. also some worldmap code organizations. Signed-off-by: Gehad elrobey <gehadelro...@gmail.com> Signed-off-by: Miika Turkia <miika.tur...@gmail.com> --- qt-ui/divelogexportdialog.cpp | 10 ++- qt-ui/divelogexportdialog.ui | 50 +++++++++----- save-html.c | 154 ++++++++++++++++++++++++++++++++++++++++++ save-html.h | 26 +++++++ subsurface.pro | 2 + worldmap-save.c | 88 +++--------------------- 6 files changed, 232 insertions(+), 98 deletions(-) create mode 100644 save-html.c create mode 100644 save-html.h diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 28f3432..a3193d5 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -2,7 +2,6 @@ #include <QString> #include <QShortcut> #include <QAbstractButton> -#include <QDebug> #include <QSettings> #include "mainwindow.h" @@ -10,6 +9,7 @@ #include "ui_divelogexportdialog.h" #include "subsurfacewebservices.h" #include "worldmap-save.h" +#include "save-html.h" DiveLogExportDialog::DiveLogExportDialog(QWidget *parent) : QDialog(parent), ui(new Ui::DiveLogExportDialog) @@ -39,6 +39,8 @@ void DiveLogExportDialog::showExplanation() ui->description->setText("HTML export of the dive locations, visualized on a world map."); } else if (ui->exportSubsurfaceXML->isChecked()) { ui->description->setText("Subsurface native XML format."); + } else if (ui->exportHtml->isChecked()) { + ui->description->setText("Html export of dive list can be viewed in any web browser."); } } @@ -84,7 +86,13 @@ void DiveLogExportDialog::on_buttonBox_accepted() QByteArray bt = QFile::encodeName(filename); save_dives_logic(bt.data(), true); } + } else if (ui->exportHtml->isChecked()) { + filename = QFileDialog::getSaveFileName(this, tr("Export HTML"), lastDir, + tr("HTML files (*.html)")); + if (!filename.isNull() && !filename.isEmpty()) + export_HTML(filename.toUtf8().data(), ui->exportSelected->isChecked()); } + if (!filename.isNull() && !filename.isEmpty()) { // remember the last export path QFileInfo fileInfo(filename); diff --git a/qt-ui/divelogexportdialog.ui b/qt-ui/divelogexportdialog.ui index 72e3731..09143f0 100644 --- a/qt-ui/divelogexportdialog.ui +++ b/qt-ui/divelogexportdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>448</width> - <height>473</height> + <height>522</height> </rect> </property> <property name="windowTitle"> @@ -17,7 +17,7 @@ <property name="geometry"> <rect> <x>20</x> - <y>420</y> + <y>450</y> <width>341</width> <height>32</height> </rect> @@ -62,7 +62,7 @@ <x>20</x> <y>70</y> <width>201</width> - <height>211</height> + <height>241</height> </rect> </property> <property name="title"> @@ -166,6 +166,35 @@ <string notr="true">exportGroup</string> </attribute> </widget> + <widget class="QRadioButton" name="exportHtml"> + <property name="geometry"> + <rect> + <x>10</x> + <y>190</y> + <width>117</width> + <height>22</height> + </rect> + </property> + <property name="text"> + <string>HTML</string> + </property> + <attribute name="buttonGroup"> + <string notr="true">exportGroup</string> + </attribute> + </widget> + <widget class="Line" name="line"> + <property name="geometry"> + <rect> + <x>40</x> + <y>230</y> + <width>231</width> + <height>16</height> + </rect> + </property> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + </widget> </widget> <widget class="QGroupBox" name="exportSelection"> <property name="geometry"> @@ -212,24 +241,11 @@ </property> </widget> </widget> - <widget class="Line" name="line"> - <property name="geometry"> - <rect> - <x>60</x> - <y>280</y> - <width>231</width> - <height>16</height> - </rect> - </property> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - </widget> <widget class="QLabel" name="description"> <property name="geometry"> <rect> <x>30</x> - <y>310</y> + <y>330</y> <width>341</width> <height>91</height> </rect> diff --git a/save-html.c b/save-html.c new file mode 100644 index 0000000..a9b48fc --- /dev/null +++ b/save-html.c @@ -0,0 +1,154 @@ +#include "save-html.h" +#include "gettext.h" + +void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + struct tm tm; + utc_mkdate(dive->when, &tm); + put_format(b, "%s%04u-%02u-%02u%s", pre, tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, post); +} + +char *replace_char(char *str, char replace, char *replace_by) +{ + /* + this function can't replace a character with a substring + where the substring contains the character, infinite loop. + */ + + if (!str) + return 0; + + int i = 0, char_count = 0, new_size; + + while (str[i] != '\0') { + if (str[i] == replace) + char_count++; + i++; + } + + new_size = strlen(str) + char_count * strlen(replace_by) + 1; + char *result = malloc(new_size); + char *temp = strdup(str); + char *p0, *p1; + if (!result || !temp) + return 0; + result[0] = '\0'; + p0 = temp; + p1 = strchr(temp, replace); + while (p1) { + *p1 = '\0'; + strcat(result, p0); + strcat(result, replace_by); + p0 = p1 + 1; + p1 = strchr(p0, replace); + } + strcat(result, p0); /*concat the rest of the string*/ + free(temp); + return result; +} + +char *quote(char *string) +{ + char *new_line_removed = replace_char(string, '\n', "<br>"); + char *single_quotes_removed = replace_char(new_line_removed, '\'', "'"); + free(new_line_removed); + return single_quotes_removed; +} + +void put_HTML_notes(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + if (dive->notes) { + char *notes = quote(dive->notes); + put_format(b, "%s: %s %s", pre, notes, post); + free(notes); + } +} + +void put_HTML_time(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + struct tm tm; + utc_mkdate(dive->when, &tm); + put_format(b, "%s%02u:%02u:%02u%s", pre, tm.tm_hour, tm.tm_min, tm.tm_sec, post); +} + +void put_HTML_airtemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + const char *unit; + double value; + + value = get_temp_units(dive->airtemp.mkelvin, &unit); + put_format(b, "%s%.1f %s%s",pre, value, unit, post); +} + +void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + const char *unit; + double value; + + value = get_temp_units(dive->watertemp.mkelvin, &unit); + put_format(b, "%s%.1f %s%s",pre, value, unit, post); +} + +void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pre, const char *post) +{ + put_string(b, pre); + struct tag_entry *tag = dive->tag_list; + while(tag){ + put_format(b, "%s ", tag->tag->name); + tag = tag->next; + } + put_string(b, post); +} + +void write_dives(struct membuffer *b,bool selected_only) +{ + int i, dive_no = 0; + struct dive *dive; + + for_each_dive(i, dive) { + if (selected_only) { + if (!dive->selected) + continue; + } + put_string(b, "{"); + put_format(b, "\"number\":%d,", dive_no); + put_HTML_date(b, dive, "\"date\":\"", "\","); + put_HTML_time(b, dive, "\"time\":\"", "\","); + put_format(b, "\"location\":\"%s\",", dive->location); + put_format(b, "\"rating\":%d,", dive->rating); + put_format(b, "\"visibility\":%d,", dive->visibility); + put_string(b, "\"temperature\":{"); + put_HTML_airtemp(b, dive, "\"air\":\"", "\","); + put_HTML_watertemp(b, dive, "\"water\":\"", "\","); + put_string(b, " },"); + put_format(b, "\"buddy\":\"%s\",", dive->buddy); + put_format(b, "\"divemaster\":\"%s\",", dive->divemaster); + put_format(b, "\"suit\":\"%s\",", dive->suit); + put_HTML_tags(b, dive, "\"tags\":\"", "\","); + put_HTML_notes(b, dive ,"\"notes\":\"" ,"\","); + put_string(b, "},\n"); + dive_no++; + } +} + +void export_dives(struct membuffer *b,bool selected_only){ + put_string(b, "items=["); + write_dives(b, selected_only); + put_string(b, "]"); +} + +void export_HTML(const char *file_name, const bool selected_only) +{ + FILE *f; + + struct membuffer buf = { 0 }; + export_dives(&buf, selected_only); + + f = fopen(file_name, "w+"); + if (!f) + printf("error"); /*report error*/ + + flush_buffer(&buf, f); /*check for writing errors? */ + free_buffer(&buf); + fclose(f); +} diff --git a/save-html.h b/save-html.h new file mode 100644 index 0000000..47f6d21 --- /dev/null +++ b/save-html.h @@ -0,0 +1,26 @@ +#ifndef HTML_SAVE_H +#define HTML_SAVE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "dive.h" +#include "membuffer.h" + +void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post); +void put_HTML_airtemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post); +void put_HTML_watertemp(struct membuffer *b, struct dive *dive, const char *pre, const char *post); +void put_HTML_time(struct membuffer *b, struct dive *dive, const char *pre, const char *post); +void put_HTML_notes(struct membuffer *b, struct dive *dive, const char *pre, const char *post); + +char *replace_char(char *str, char replace, char *replace_by); +char *quote(char *string); + +void export_HTML(const char *file_name, const bool selected_only); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/subsurface.pro b/subsurface.pro index d718937..6eb2bc8 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -28,6 +28,7 @@ HEADERS = \ helpers.h \ libdivecomputer.h \ planner.h \ + save-html.h \ worldmap-save.h \ worldmap-options.h \ pref.h \ @@ -104,6 +105,7 @@ SOURCES = \ profile.c \ divecomputer.cpp \ worldmap-save.c \ + save-html.c \ qt-gui.cpp \ qthelper.cpp \ qt-ui/about.cpp \ diff --git a/worldmap-save.c b/worldmap-save.c index b82ccd3..3892014 100644 --- a/worldmap-save.c +++ b/worldmap-save.c @@ -2,8 +2,10 @@ #include <stdlib.h> #include <string.h> #include <stdio.h> + #include "dive.h" #include "membuffer.h" +#include "save-html.h" #include "worldmap-save.h" #include "worldmap-options.h" #include "gettext.h" @@ -14,82 +16,6 @@ char *getGoogleApi() return "https://maps.googleapis.com/maps/api/js?key=AIzaSyDzo9PWsqYDDSddVswg_13rpD9oH_dLuoQ"; } -void put_HTML_date(struct membuffer *b, struct dive *dive) -{ - struct tm tm; - utc_mkdate(dive->when, &tm); - put_format(b, "<p>%s: %04u-%02u-%02u</p>", translate("gettextFromC", "Date"), tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); - put_format(b, "<p>%s: %02u:%02u:%02u</p>", translate("gettextFromC", "Time"), tm.tm_hour, tm.tm_min, tm.tm_sec); -} - -void put_HTML_temp(struct membuffer *b, struct dive *dive) -{ - const char *unit; - double value; - - value = get_temp_units(dive->airtemp.mkelvin, &unit); - put_format(b, "<p>%s: %.1f %s</p>", translate("gettextFromC", "Air Temp"), value, unit); - - value = get_temp_units(dive->watertemp.mkelvin, &unit); - put_format(b, "<p>%s: %.1f %s</p>", translate("gettextFromC", "Water Temp"), value, unit); -} - -char *replace_char(char *str, char replace, char *replace_by) -{ - /* - this fumction can't replace a character with a substring - where the substring contains the character, infinte loop. - */ - - if (!str) - return 0; - - int i = 0, char_count = 0, new_size; - - while (str[i] != '\0') { - if (str[i] == replace) - char_count++; - i++; - } - - new_size = strlen(str) + char_count * strlen(replace_by) + 1; - char *result = malloc(new_size); - char *temp = strdup(str); - char *p0, *p1; - if (!result || !temp) - return 0; - result[0] = '\0'; - p0 = temp; - p1 = strchr(temp, replace); - while (p1) { - *p1 = '\0'; - strcat(result, p0); - strcat(result, replace_by); - p0 = p1 + 1; - p1 = strchr(p0, replace); - } - strcat(result, p0); /*concat the rest of the string*/ - free(temp); - return result; -} - -char *quote(char *string) -{ - char *new_line_removed = replace_char(string, '\n', "<br>"); - char *single_quotes_removed = replace_char(new_line_removed, '\'', "'"); - free(new_line_removed); - return single_quotes_removed; -} - -void put_HTML_notes(struct membuffer *b, struct dive *dive) -{ - if (dive->notes) { - char *notes = quote(dive->notes); - put_format(b, "<p>%s: %s </p>", translate("gettextFromC", "Notes"), notes); - free(notes); - } -} - void writeMarkers(struct membuffer *b, const bool selected_only) { int i, dive_no = 0; @@ -106,12 +32,14 @@ void writeMarkers(struct membuffer *b, const bool selected_only) put_degrees(b, dive->latitude, "temp = new google.maps.Marker({position: new google.maps.LatLng(", ""); put_degrees(b, dive->longitude, ",", ")});\n"); put_string(b, "markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '<div id=\"content\">'+'<div id=\"siteNotice\">'+'</div>'+'<div id=\"bodyContent\">"); - put_format(b, "<p><b>%s</b></p>", quote(dive->location)); - put_HTML_date(b, dive); + put_HTML_date(b, dive, translate("gettextFromC", "<p>Date:"), "</p>"); + put_HTML_time(b, dive, translate("gettextFromC", "<p>Time:"), "</p>"); put_duration(b, dive->duration, translate("gettextFromC", "<p>Duration: "), translate("gettextFromC", " min</p>")); put_depth(b, dive->maxdepth, translate("gettextFromC", "<p>Max Depth: "), translate("gettextFromC", " m</p>")); - put_HTML_temp(b, dive); - put_HTML_notes(b, dive); + put_HTML_airtemp(b, dive, translate("gettextFromC", "<p>Air Temp: "), "</p>"); + put_HTML_watertemp(b, dive,translate("gettextFromC", "<p>Water Temp : ") , "</p>"); + put_format(b, "<p>Location : <b>%s</b></p>", quote(dive->location)); + put_HTML_notes(b, dive, translate("gettextFromC", "<p> Notes"), " </p>"); put_string(b, "</p>'+'</div>'+'</div>'});\ninfowindows.push(tempinfowindow);\n"); put_format(b, "google.maps.event.addListener(markers[%d], 'mouseover', function() {\ninfowindows[%d].open(map,markers[%d]);}", dive_no, dive_no, dive_no); put_format(b, ");google.maps.event.addListener(markers[%d], 'mouseout', function() {\ninfowindows[%d].close();});\n", dive_no, dive_no); -- 1.9.1
_______________________________________________ subsurface mailing list subsurface@hohndel.org http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface