I attached my progress in the HTML exporter, My work was basically adding a detailed dive view that shows more dive info,and added a simple dive profile and dive equipments list to the detailed view.
I am not familiar with the dive profile anyway so I am willing to know your feedback and if you have any recommendations. I need to know what is the most important curves that we need to sketch in the profile. Also fixed the export window, so that the HTML exported with a subdirectory contains the attached scripts. I also fixed a bug in sorting. I would like to mention that the style of the detailed view need enhancements and fixing, I will look into that after I have some correctly working model. -- Regards, Gehad Elrobey
>From ab1b15963692fbc3340beb65a9e22ec8b051acae Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Tue, 10 Jun 2014 18:55:07 +0300 Subject: [PATCH 7/7] HTML: fix the exporting dialog export HTML into the file name choosen and export additional files into a subdirectoy beside the html file, called htmlfilename_files This is to follow the convension and doesn't create additional directories to wrap the exports. Signed-off-by: Gehad elrobey <[email protected]> --- qt-ui/divelogexportdialog.cpp | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/qt-ui/divelogexportdialog.cpp b/qt-ui/divelogexportdialog.cpp index 602d450..7f99042 100644 --- a/qt-ui/divelogexportdialog.cpp +++ b/qt-ui/divelogexportdialog.cpp @@ -68,15 +68,13 @@ void DiveLogExportDialog::showExplanation() void DiveLogExportDialog::exportHtmlInit(QString filename) { - QDir dir(filename); - if (!dir.exists()) { - /* I think this will not work as expected on windows */ - QDir::home().mkpath(filename); - } - - QString json_dive_data = filename + QDir::separator() + "file.json"; - QString json_settings = filename + "/settings.json"; - + QFile file(filename); + QFileInfo info(file); + QDir mainDir = info.absoluteDir(); + mainDir.mkdir(file.fileName()+"_files"); + QString exportFiles = file.fileName()+"_files"; + QString json_dive_data = exportFiles + QDir::separator() + "file.json"; + QString json_settings = exportFiles + QDir::separator() + "settings.json"; exportHTMLsettings(json_settings); export_HTML(json_dive_data.toUtf8().data(), ui->exportSelectedDives->isChecked()); @@ -87,19 +85,19 @@ void DiveLogExportDialog::exportHtmlInit(QString filename) QFile *tmpFile; tmpFile = new QFile(searchPath + "/dive_export.html"); - tmpFile->copy(filename + "/dive_export.html"); + tmpFile->copy(filename); delete tmpFile; tmpFile = new QFile(searchPath + "/list_lib.js"); - tmpFile->copy(filename + "/list_lib.js"); + tmpFile->copy(exportFiles + "/list_lib.js"); delete tmpFile; tmpFile = new QFile(searchPath + "/poster.png"); - tmpFile->copy(filename + "/poster.png"); + tmpFile->copy(exportFiles + "/poster.png"); delete tmpFile; tmpFile = new QFile(searchPath + "/index.html"); - tmpFile->copy(filename + "/index.html"); + tmpFile->copy(exportFiles + "/index.html"); delete tmpFile; if (ui->themeSelection->currentText() == "Light") { @@ -107,7 +105,7 @@ void DiveLogExportDialog::exportHtmlInit(QString filename) } else { tmpFile = new QFile(searchPath + "/sand.css"); } - tmpFile->copy(filename + "/theme.css"); + tmpFile->copy(exportFiles + "/theme.css"); delete tmpFile; } @@ -176,8 +174,8 @@ void DiveLogExportDialog::on_buttonBox_accepted() } break; case 1: - filename = QFileDialog::getSaveFileName(this, tr("Export Subsurface"), lastDir, - tr("Folders"), 0, QFileDialog::ShowDirsOnly); + filename = QFileDialog::getSaveFileName(this, tr("Export HTML files as"), lastDir, + tr("HTML files (*.html)")); if (!filename.isNull() && !filename.isEmpty()) exportHtmlInit(filename); break; -- 1.9.1
>From 2d56603025e49a3f870c19e0487cc28a38c045ee Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Tue, 10 Jun 2014 18:40:56 +0300 Subject: [PATCH 6/7] HTML: Dynamically loading an external JavaScript or CSS file This enable the HTML template from linking JS and CSS files dynamically when starting. This helps to recognize the folder name where js and css where exported dynamically. The HTML template will succesfully find the attached files as long as they exist in a directory named as the HTML file. Signed-off-by: Gehad elrobey <[email protected]> --- theme/dive_export.html | 27 +++++++++++++++++++++++---- theme/light.css | 1 + theme/sand.css | 1 + 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/theme/dive_export.html b/theme/dive_export.html index 4d7efa2..2374c07 100644 --- a/theme/dive_export.html +++ b/theme/dive_export.html @@ -2,13 +2,31 @@ <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>dive log export</title> -<link rel="stylesheet" type="text/css" href="theme.css"> -<script src="file.json"></script> -<script src="settings.json"></script> -<script src="list_lib.js" type="text/javascript"></script> <script> ////////////////////////////////// //advance settings window// +load_scripts(); + +function load_scripts(){ + var fileref=document.createElement("link"); + fileref.setAttribute("rel", "stylesheet"); + fileref.setAttribute("type", "text/css"); + fileref.setAttribute("href", location.pathname+"_files/theme.css"); + document.getElementsByTagName("head")[0].appendChild(fileref); + + fileref=document.createElement('script'); + fileref.setAttribute("src", location.pathname+"_files/file.json"); + document.getElementsByTagName("head")[0].appendChild(fileref); + + fileref=document.createElement('script'); + fileref.setAttribute("src", location.pathname+"_files/settings.json"); + document.getElementsByTagName("head")[0].appendChild(fileref); + + fileref=document.createElement('script'); + fileref.setAttribute("type","text/javascript"); + fileref.setAttribute("src", location.pathname+"_files/list_lib.js"); + document.getElementsByTagName("head")[0].appendChild(fileref); +} var advanced_shown=false; function showdiv(){ @@ -80,6 +98,7 @@ window.onload=function(){ sizeofpage=10; showAllDives(); document.getElementById("divePanel").style.display='none'; + document.body.style.visibility='visible'; } function changeAdvSearch(e){ diff --git a/theme/light.css b/theme/light.css index b2662f4..9184c0d 100644 --- a/theme/light.css +++ b/theme/light.css @@ -3,6 +3,7 @@ body{ background-color:#dfdfdf; font-size:12px; font-family: 'Lobster', helvetica, arial; + visibility: hidden; } h1 { diff --git a/theme/sand.css b/theme/sand.css index 61a918a..a5bbe45 100644 --- a/theme/sand.css +++ b/theme/sand.css @@ -3,6 +3,7 @@ body{ background-color:#F7F4DD; font-size:12px; font-family: 'Lobster', helvetica, arial; + visibility: hidden; } h1 { -- 1.9.1
>From 8fcb005ec2416b7d6e653fd7e8ac7fb7e532c10c Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Tue, 10 Jun 2014 04:45:31 +0300 Subject: [PATCH 5/7] HTML: Show dive profile embedded in HTML5 canvas Plot samples from dive computer (depth,time) with HTML5 canvas. Add very small API for curve drawing and coloring. Add the dive equipment to the detailed dive view. in the dive list when a dive is expanded you can show the dive profile,equipments and dive information by clicking on 'show more details'. Fixing the two themes to work well with the new div added that carry detailed dive information. Signed-off-by: Gehad elrobey <[email protected]> --- theme/dive_export.html | 21 ++++- theme/light.css | 40 +++++++++ theme/list_lib.js | 240 ++++++++++++++++++++++++++++++++++++++++++++++++- theme/sand.css | 40 +++++++++ 4 files changed, 339 insertions(+), 2 deletions(-) diff --git a/theme/dive_export.html b/theme/dive_export.html index edee464..4d7efa2 100644 --- a/theme/dive_export.html +++ b/theme/dive_export.html @@ -79,6 +79,7 @@ window.onload=function(){ sizeofpage=10; showAllDives(); + document.getElementById("divePanel").style.display='none'; } function changeAdvSearch(e){ @@ -95,7 +96,7 @@ function changeAdvSearch(e){ <h1>Subsurface</h1> </div> </center> - <div id="divePanel"> + <div id="diveListPanel"> <div id="controlbox"> <input id="search_input" oninput="SearchModules(this.value)" placeholder="search"/><a id="adv_srch_sp" onClick="showdiv()" >Advanced Search</a> <div id="advanced_search"> @@ -135,5 +136,23 @@ function changeAdvSearch(e){ </div> </center> </div> + <div id="divePanel"> + <div id="diveprofile"> + <h2>Dive profile</h2> + <canvas id="profileCanvas"></canvas> + </div> + <div id="diveinfo"> + <h2>Dive Information</h2> + </div> + <div id="dive_equipments"> + <h2>Dive equipments</h2> + </div> + <div id="bookmarks"> + <h2>Bookmarks</h2> + </div> + <div id="divestats"> + <h2>Dive stats</h2> + </div> + </div> </body> </html> diff --git a/theme/light.css b/theme/light.css index 589bbdd..b2662f4 100644 --- a/theme/light.css +++ b/theme/light.css @@ -192,6 +192,46 @@ ul:hover{ margin-bottom:10px; } +#profileCanvas{ + border:1px solid #d3d3d3; + width:98%; + margin:1%; + height:300px; +} + +#diveListPanel{ + padding:5px; + width:90%; + margin:0% 5% 0% 5%; + margin-bottom:50px; + background-color:rgba(253, 195, 141, 0.43); + box-shadow: 7px 7px 5px rgba(215, 107, 27, 0.43); +} + +.Cyl{ + padding-right:25px; +} + +#diveinfo{ + border-style:solid; +} + +#diveprofile{ + border-style:solid; +} + +#dive_equipments{ + border-style:solid; +} + +#divestats{ + border-style:solid; +} + +#bookmarks{ + border-style:solid; +} + @media (max-width: 768px) { #divePanel{ padding:4px; diff --git a/theme/list_lib.js b/theme/list_lib.js index d7a01c1..ff51e29 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -192,7 +192,8 @@ function getExpanded (dive) { '</td></tr><tr><td class="words"><p>Buddy: </p></td><td>'+dive.buddy + '</td></tr><tr><td class="words">Suit: </td><td>'+dive.suit + '</td></tr><tr><td class="words">Tags: </td><td>'+putTags(dive.tags)+ - '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes +'</div>'; + '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes +'</div>'+ + '<center><a onclick="showDiveDetails('+dive.number+')">show more details</a></center>'; }; function putTags(tags){ @@ -575,3 +576,240 @@ function getItems(){ } } } + +////////////////////////canvas/////////////////// + +/* +Canvas Colors Constants +*/ +var CAMARONE1 = rgb(0,0.4,0); +var LIMENADE1 = rgb(0.4,0.8,0); +var RIOGRANDE1 = rgb (0.8,0.8,0); +var PIRATEGOLD1= rgb(0.8,0.5,0); +var RED1 = rgb(1,0,0); + +/* +Some Global variables that hold the current shown dive data. +*/ +var dive_id;//current shown ID +var points;//reference to the samples array of the shown dive. +var MAX_HEIGHT;//Maximum depth, then its the maximum height for canvas +var MAX_WIDTH;//dive duration, then its the maximum width for canvas + +/** +*Return RGB css color string. +*/ +function rgb(r, g, b){ + r = Math.floor(r*255); + g = Math.floor(g*255); + b = Math.floor(b*255); + return ["rgb(",r,",",g,",",b,")"].join(""); +} + +/** +*This function returns the value scaled to the size of canvas +*new scale = (old scale * height of canvas) / max height in dive +*to ensure that the dive profile is filling the whole area available +*/ +function scaleHeight(vari){ + var height = document.getElementById("profileCanvas").height; + max = MAX_HEIGHT; + return (vari*height)/max; +} + +/** +*This function returns the value scaled to the size of canvas +*new scale = (old scale * width of canvas) / max width in dive +*to ensure that the dive profile is filling the whole area available +*/ +function scaleWidth(vari){ + var width = document.getElementById("profileCanvas").width; + max = MAX_WIDTH; + return (vari*width)/max; +} + +/** +*Show Axis information(Numbers on scale) +*put a Number every 300 second scaled to canvas width. +*/ +function canvas_showAxisInfo(){ + var c=document.getElementById("profileCanvas"); + var ctx=c.getContext("2d"); + ctx.font="27px Georgia";/*This is better be a variable scale*/ + for (var i=0;i<MAX_WIDTH/scaleWidth(5);i++) + ctx.fillText(""+i*5+"",scaleWidth(i*5*60),scaleHeight(MAX_HEIGHT-150)); +} + +/** +*Draw the grid +*with spacing = 5 * 60 = 300 +*draw line every 5 minutes +*/ +function canvas_showGrid() { + var cnv = document.getElementById("profileCanvas"); + var cnvWidth = cnv.width; + var cnvHeight = cnv.height; + var lineOptions= { + separation: scaleWidth(300), + color: '#AAAAAA' + }; + var ctx = cnv.getContext('2d'); + + ctx.strokeStyle = lineOptions.color; + ctx.strokeWidth = 0.5; + ctx.beginPath(); + + var iCount = null; + var i = null; + var x = null; + var y = null; + + //draw horizontal lines + iCount = Math.floor(cnvWidth / lineOptions.separation); + for (i = 1; i <= iCount; i++) { + x = (i * lineOptions.separation); + ctx.moveTo(x, 0); + ctx.lineTo(x, cnvHeight); + ctx.stroke(); + } + + //draw vertical lines + iCount = Math.floor(cnvHeight / lineOptions.separation); + for (i = 1; i <= iCount; i++) { + y = (i * lineOptions.separation); + ctx.moveTo(0, y); + ctx.lineTo(cnvWidth, y); + ctx.stroke(); + } + + ctx.closePath(); +} + +/** +*The Main function used for drawing canvas lines +*it automatically calcualte the slope of the line +*and choose its color. +*This is the function that should be used internally. +*/ +function canvas_drawline(ctx,begin,end){ + drawline(ctx,begin,end,getcolor(begin,end)); +} + +/** +*Draw a line in the canvas with the given +*starting point, ending point, and color. +*/ +function drawline(ctx,begin,end,col){ + ctx.strokeStyle = col; + ctx.beginPath(); + ctx.moveTo(scaleWidth(begin[0]),scaleHeight(begin[1])); + ctx.lineTo(scaleWidth(end[0]),scaleHeight(end[1])); + ctx.stroke(); +} + +/** +*Choose Color for different speeds. +*this need to be fixed to go with subsurface conversion. +*/ +function getcolor(begin,end){ + var slope = (end[1]-begin[1])/(end[0]-begin[0]); + if (Math.abs(slope) > 300 ) return RED1; + if (Math.abs(slope) > 180 ) return PIRATEGOLD1; + if (Math.abs(slope) > 110 ) return RIOGRANDE1; + if (Math.abs(slope) > 70 ) return LIMENADE1; + return CAMARONE1; +} + +/** +*Return the HTML string for a dive cylinder entry in the table. +*/ +function get_cylinder_HTML(cylinder){ + return '<tr><td class="Cyl">'+cylinder.Type+'</td><td class="Cyl">'+cylinder.Size+'</td><td class="Cyl">'+cylinder.WPressure+'</td>'+ + '<td class="Cyl">'+cylinder.SPressure+'</td><td class="Cyl">'+cylinder.EPressure+'</td><td class="Cyl">'+cylinder.O2+'</td></tr>'; +} + +/** +*Return HTML table of cylinders of a dive. +*/ +function get_cylinders_HTML(dive){ + var result=""; + result +='<h2>Dive equipments</h2><table><tr><td class="Cyl">Type</td><td class="Cyl">Size</td><td class="Cyl">Work Pressure</td><td class="Cyl">Start Pressure</td><td class="Cyl">End Pressure</td><td class="Cyl">O2</td></tr>'; + for (var i in dive.Cylinders){ + result+=get_cylinder_HTML(dive.Cylinders[i]); + } + result+='</table>'; + return result; +} + +/** +*Return HTML main data of a dive +*/ +function get_dive_HTML(dive) { + return '<h2>Dive Information</h2><table><tr><td class="words">Date: </td><td>'+dive.date+ + '</td><td class="words">     Time: </td><td>'+dive.time + + '</td><td class="words">     Location: </td><td>'+'<a onclick=\"Search_list_Modules(\''+dive.location+'\')\">'+ + dive.location +'</a>'+ + '</td></tr></table><table><tr><td class="words">Rating:</td><td>'+putRating(dive.rating)+ + '</td><td class="words">   Visibilty:</td><td>'+putRating(dive.visibility)+ + '</td></tr></table>'+ + '<table><tr><td class="words">Air temp: </td><td>'+dive.temperature.air+ + '</td><td class="words">    Water temp: </td><td>'+dive.temperature.water + + '</td></tr></table><table><tr><td class="words">DiveMaster: </td><td>'+dive.divemaster + + '</td></tr><tr><td class="words"><p>Buddy: </p></td><td>'+dive.buddy + + '</td></tr><tr><td class="words">Suit: </td><td>'+dive.suit + + '</td></tr><tr><td class="words">Tags: </td><td>'+putTags(dive.tags)+ + '</td></tr></table><div style="margin:10px;"><p class="words">Notes: </p>' + dive.notes +'</div>'; +}; + +/** +*Main canvas draw function +*this calls the axis and grid initialization functions. +*/ +function canvas_draw(){ + var c=document.getElementById("profileCanvas"); + c.width = window.innerWidth; + c.height = window.innerHeight; + canvas_showGrid(); + canvas_showAxisInfo(); + var ctx=c.getContext("2d"); + ctx.lineWidth=4 //variable width + //draw starting line, draw all samples then draw the final line. + canvas_drawline(ctx,[0,0],points[0]); + for(var i=1;i<points.length;i++){ + canvas_drawline(ctx,points[i-1],points[i]); + } + canvas_drawline(ctx,points[points.length-1],[MAX_WIDTH,0]); +} + +/** +*Initialize the detailed view, +*set the global variables +*Fill the dive data +*Hide the list and show the canvas view. +*this is called to view the dive details. +*/ +function showDiveDetails(dive){ + //set global variables + dive_id = dive; + points = items[dive_id].samples; + MAX_HEIGHT = items[dive_id].maxdepth*1.1; + MAX_WIDTH = items[dive_id].duration; + + //draw the canvas and initialize the view + canvas_draw(); + document.getElementById("diveinfo").innerHTML=get_dive_HTML(items[dive_id]); + document.getElementById("dive_equipments").innerHTML=get_cylinders_HTML(items[dive_id]); + + //hide the list of dives and show the canvas. + document.getElementById("diveListPanel").style.display='none'; + document.getElementById("divePanel").style.display='block'; +} + +/** +*Show the list view and hide the detailed list view. +*this function have to clear any data saved by showDiveDetails +*/ +function unshowDiveDetails(dive){ + document.getElementById("diveListPanel").style.display='block'; + document.getElementById("divePanel").style.display='none'; +} diff --git a/theme/sand.css b/theme/sand.css index 0bfcf66..61a918a 100644 --- a/theme/sand.css +++ b/theme/sand.css @@ -194,6 +194,46 @@ ul:hover{ margin-bottom:10px; } +#profileCanvas{ + border:1px solid #d3d3d3; + width:98%; + margin:1%; + height:300px; +} + +#diveListPanel{ + padding:5px; + width:90%; + margin:0% 5% 0% 5%; + margin-bottom:50px; + background-color:rgba(253, 195, 141, 0.43); + box-shadow: 7px 7px 5px rgba(215, 107, 27, 0.43); +} + +.Cyl{ + padding-right:25px; +} + +#diveinfo{ + border-style:solid; +} + +#diveprofile{ + border-style:solid; +} + +#dive_equipments{ + border-style:solid; +} + +#divestats{ + border-style:solid; +} + +#bookmarks{ + border-style:solid; +} + @media (max-width: 768px) { #divePanel{ padding:4px; -- 1.9.1
>From cc6cf7c2bd982c761d70d7f8cf1302312a4df17d Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Tue, 10 Jun 2014 00:24:18 +0300 Subject: [PATCH 4/7] HTML: define the visited array type to boolean The boolean array must be defined explicitly, to prevent type casting. Signed-off-by: Gehad elrobey <[email protected]> --- theme/list_lib.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/theme/list_lib.js b/theme/list_lib.js index bf1ef59..d7a01c1 100644 --- a/theme/list_lib.js +++ b/theme/list_lib.js @@ -341,7 +341,7 @@ function sort_it(sortOn,function_){ var res = new Array(); var visited = new Array(itemsToShow.length); for(var j=0;j<itemsToShow.length;j++){ - visited[j]=0; + visited[j]=false; } for(var i=0;i< itemsToShow.length ;i++){ for(var j=0;j<itemsToShow.length;j++) -- 1.9.1
>From 01b03ef6f7bf59835cf9d4beb0c5fa771865f6b8 Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Sun, 8 Jun 2014 16:09:24 +0300 Subject: [PATCH 3/7] HTML: Write cylinder data to the JSON files. Iterate the cylinders in each dive and write cylinders data to the exported JSON files. Moving the write attribute function to the top of the file. Signed-off-by: Gehad elrobey <[email protected]> --- save-html.c | 52 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/save-html.c b/save-html.c index 61c453d..e77f79a 100644 --- a/save-html.c +++ b/save-html.c @@ -2,6 +2,48 @@ #include "gettext.h" #include "stdio.h" +void write_attribute(struct membuffer *b, const char *att_name, const char *value) +{ + if (!value) + value = "--"; + put_format(b, "\"%s\":\"", att_name); + put_HTML_quoted(b, value); + put_string(b, "\","); +} + +static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) +{ + int i, nr; + + nr = nr_cylinders(dive); + + put_string(b, "\"Cylinders\":["); + + for (i = 0; i < nr; i++) { + cylinder_t *cylinder = dive->cylinder + i; + put_string(b, "{"); + write_attribute(b, "Type", cylinder->type.description); + if (cylinder->type.size.mliter) { + put_milli(b, "\"Size\":\"", cylinder->type.size.mliter, " l\","); + } else { + write_attribute(b, "Size", "--"); + } + put_pressure(b, cylinder->type.workingpressure, "\"WPressure\":\"", " bar\","); + put_pressure(b, cylinder->start, "\"SPressure\":\"", " bar\","); + put_pressure(b, cylinder->end, "\"EPressure\":\"", " bar\","); + + if (cylinder->gasmix.o2.permille) { + put_format(b, "\"O2\":\"%u.%u%%\",", FRACTION(cylinder->gasmix.o2.permille, 10)); + } else { + write_attribute(b, "O2", "--"); + } + put_string(b, "},"); + } + + put_string(b, "],"); +} + + void put_HTML_samples(struct membuffer *b, struct dive *dive) { int i; @@ -90,15 +132,6 @@ 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\":\"", att_name); - put_HTML_quoted(b, value); - put_string(b, "\","); -} - void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) { put_string(b, "{"); @@ -118,6 +151,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) write_attribute(b, "suit", dive->suit); put_HTML_tags(b, dive, "\"tags\":", ","); put_HTML_notes(b, dive, "\"notes\":\"", "\","); + put_cylinder_HTML(b, dive); put_HTML_samples(b, dive); put_string(b, "},\n"); (*dive_no)++; -- 1.9.1
>From 7b45cb14b647c908227efde6e086019baa8e0e73 Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Sun, 8 Jun 2014 07:56:54 +0300 Subject: [PATCH 2/7] HTML: export DC samples to JSON format. -Export Dive computer samples to JSON format, for dive profile plotting. -Add maxdepth and duration to attributes of the JSON dive object. Signed-off-by: Gehad elrobey <[email protected]> --- save-html.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/save-html.c b/save-html.c index 501bc21..61c453d 100644 --- a/save-html.c +++ b/save-html.c @@ -1,5 +1,20 @@ #include "save-html.h" #include "gettext.h" +#include "stdio.h" + +void put_HTML_samples(struct membuffer *b, struct dive *dive) +{ + int i; + put_format(b, "\"maxdepth\":%d,", dive->dc.maxdepth.mm); + put_format(b, "\"duration\":%d,", dive->dc.duration.seconds); + put_string(b, "\"samples\":\["); + struct sample *s = dive->dc.sample; + for (i = 0; i < dive->dc.samples; i++) { + put_format(b, "[%d,%d],", s->time.seconds, s->depth.mm); + s++; + } + put_string(b, "],"); +} void put_HTML_date(struct membuffer *b, struct dive *dive, const char *pre, const char *post) { @@ -103,6 +118,7 @@ void write_one_dive(struct membuffer *b, struct dive *dive, int *dive_no) write_attribute(b, "suit", dive->suit); put_HTML_tags(b, dive, "\"tags\":", ","); put_HTML_notes(b, dive, "\"notes\":\"", "\","); + put_HTML_samples(b, dive); put_string(b, "},\n"); (*dive_no)++; } -- 1.9.1
>From ffd0ad8d3996f2a0d731cf4714ea555a885ccf4f Mon Sep 17 00:00:00 2001 From: Gehad elrobey <[email protected]> Date: Sun, 8 Jun 2014 07:35:20 +0300 Subject: [PATCH 1/7] HTML: Report saving to file errors. Use subsurface report_error function in save-html and worldmap-save instead of the ridiculous print to standard output. Also use subsurface_fopen for the sake of different platforms. Signed-off-by: Gehad elrobey <[email protected]> --- save-html.c | 4 ++-- worldmap-save.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/save-html.c b/save-html.c index 212cf24..501bc21 100644 --- a/save-html.c +++ b/save-html.c @@ -191,9 +191,9 @@ void export_HTML(const char *file_name, const bool selected_only) struct membuffer buf = { 0 }; export_list(&buf, selected_only); - f = fopen(file_name, "w+"); + f = subsurface_fopen(file_name, "w+"); if (!f) - printf("error"); /*report error*/ + report_error(translate("gettextFromC", "Can't open file %s"), file_name); flush_buffer(&buf, f); /*check for writing errors? */ free_buffer(&buf); diff --git a/worldmap-save.c b/worldmap-save.c index 0dbc479..35a6896 100644 --- a/worldmap-save.c +++ b/worldmap-save.c @@ -90,9 +90,9 @@ void export_worldmap_HTML(const char *file_name, const bool selected_only) struct membuffer buf = { 0 }; export(&buf, selected_only); - f = fopen(file_name, "w+"); + f = subsurface_fopen(file_name, "w+"); if (!f) - printf("error"); /*report error*/ + report_error(translate("gettextFromC", "Can't open file %s"), file_name); flush_buffer(&buf, f); /*check for writing errors? */ free_buffer(&buf); -- 1.9.1
_______________________________________________ subsurface mailing list [email protected] http://lists.hohndel.org/cgi-bin/mailman/listinfo/subsurface
