diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 86d612457..53f7a15df 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -36,6 +36,7 @@ #include "simplewidgets.h" #include "diveplanner.h" #include "about.h" +#include "worldmap-save.h" #ifndef NO_PRINTING #include "printdialog.h" #endif @@ -277,6 +278,15 @@ void MainWindow::on_actionExportUDDF_triggered() export_dives_uddf(filename.toUtf8(), false); } +void MainWindow::on_actionExportHTMLworldmap_triggered() +{ + QFileInfo fi(system_default_filename()); + QString filename = QFileDialog::getSaveFileName(this, tr("Export World Map"), fi.absolutePath(), + tr("HTML files (*.html)")); + if (!filename.isNull() && !filename.isEmpty()) + export_worldmap_HTML(filename.toUtf8().data()); +} + void MainWindow::on_actionPrint_triggered() { #ifndef NO_PRINTING diff --git a/qt-ui/mainwindow.h b/qt-ui/mainwindow.h index 51e03c3b8..a0c5be333 100644 --- a/qt-ui/mainwindow.h +++ b/qt-ui/mainwindow.h @@ -90,6 +90,7 @@ slots: void on_actionSaveAs_triggered(); void on_actionClose_triggered(); void on_actionExportUDDF_triggered(); + void on_actionExportHTMLworldmap_triggered(); void on_actionPrint_triggered(); void on_actionPreferences_triggered(); void on_actionQuit_triggered(); diff --git a/qt-ui/mainwindow.ui b/qt-ui/mainwindow.ui index a933a2de9..2bf249683 100644 --- a/qt-ui/mainwindow.ui +++ b/qt-ui/mainwindow.ui @@ -551,6 +551,7 @@ + @@ -680,6 +681,11 @@ Ctrl+U + + + + Export HTML World Map + diff --git a/subsurface.pro b/subsurface.pro index d10f73df4..3944da095 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -28,6 +28,8 @@ HEADERS = \ helpers.h \ libdivecomputer.h \ planner.h \ + worldmap-save.h \ + worldmap-options.h \ pref.h \ profile.h \ qt-gui.h \ @@ -97,6 +99,7 @@ SOURCES = \ parse-xml.c \ planner.c \ profile.c \ + worldmap-save.c \ qt-gui.cpp \ qthelper.cpp \ qt-ui/about.cpp \ diff --git a/worldmap-options.h b/worldmap-options.h new file mode 100644 index 000000000..6e7e8728b --- /dev/null +++ b/worldmap-options.h @@ -0,0 +1,7 @@ +#ifndef WORLDMAP_OPTIONS_H +#define WORLDMAP_OPTIONS_H + +const char* map_options = "center: new google.maps.LatLng(0,0),\n\tzoom: 3,\n\tminZoom: 2,\n\tmapTypeId: google.maps.MapTypeId.SATELLITE\n\t"; +const char* css = "\n\thtml { height: 100% }\n\tbody { height: 100%; margin: 0; padding: 0 }\n\t#map-canvas { height: 100% }\n"; + +#endif// WORLDMAP-OPTIONS_H diff --git a/worldmap-save.c b/worldmap-save.c new file mode 100644 index 000000000..f9a4bf3fe --- /dev/null +++ b/worldmap-save.c @@ -0,0 +1,110 @@ +#include +#include +#include +#include +#include "dive.h" +#include "membuffer.h" +#include "worldmap-save.h" +#include "worldmap-options.h" + +char* getGoogleApi() +{ + /* google maps api auth*/ + 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, "

date=%04u-%02u-%02u

",tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday); + put_format(b, "

time=%02u:%02u:%02u

",tm.tm_hour, tm.tm_min, tm.tm_sec); +} + +void put_HTML_temp(struct membuffer *b,struct dive *dive) +{ + put_temperature(b, dive->airtemp, "

Air Temp: ", " C\\'

"); + put_temperature(b, dive->watertemp, "

Water Temp: ", " C\\'

"); +} + +void put_HTML_notes(struct membuffer *b,struct dive *dive) +{ + if (dive->notes) { + put_format(b,"

Notes : %s

",dive->notes); + } +} + +void writeMarkers(struct membuffer *b) +{ + int i; + struct dive *dive; + + for_each_dive(i, dive) { + /*export selected dives only ?*/ + + if (dive->latitude.udeg==0 && dive->longitude.udeg==0) { + continue; + } + + put_format(b,"temp = new google.maps.Marker({position: new google.maps.LatLng(%f,%f)});\n", + dive->latitude.udeg/1000000.0,dive->longitude.udeg/1000000.0); + put_string(b,"markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '
'+'
'+'
'+'
"); + put_HTML_date(b,dive); + put_duration(b, dive->duration, "

duration=", " min

"); + put_HTML_temp(b,dive); + put_HTML_notes(b,dive); + put_string(b,"

'+'
'+'
'});\ninfowindows.push(tempinfowindow);\n"); + put_format(b,"google.maps.event.addListener(markers[%d], 'mouseover', function() {\ninfowindows[%d].open(map,markers[%d]);}",i,i,i); + put_format(b,");google.maps.event.addListener(markers[%d], 'mouseout', function() {\ninfowindows[%d].close();});\n",i,i); + } +} + +void insert_html_header(struct membuffer *b) +{ + put_string(b,"\n\n\n"); + put_string(b,"\nWorld Map\n"); +} + +void insert_css(struct membuffer *b) +{ + put_format(b,"\n",css); +} + +void insert_javascript(struct membuffer *b) +{ + put_string(b,"\n\n"); +} + +void export(struct membuffer *b) +{ + insert_html_header(b); + insert_css(b); + insert_javascript(b); + put_string(b,"\t\n\n
\n\n"); +} + +void export_worldmap_HTML(const char* file_name) +{ + FILE *f; + + struct membuffer buf = { 0 }; + export(&buf); + + 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/worldmap-save.h b/worldmap-save.h new file mode 100644 index 000000000..72363e482 --- /dev/null +++ b/worldmap-save.h @@ -0,0 +1,15 @@ +#ifndef WORLDMAP_SAVE_H +#define WORLDMAP_SAVE_H + +#ifdef __cplusplus +extern "C" { +#endif + +extern void export_worldmap_HTML(const char* x); + + +#ifdef __cplusplus +} +#endif + +#endif