Пример #1
0
static void show_gps(struct membuffer *b, degrees_t latitude, degrees_t longitude)
{
	if (latitude.udeg || longitude.udeg) {
		put_degrees(b, latitude, "gps ", " ");
		put_degrees(b, longitude, "", "\n");
	}
}
Пример #2
0
static void show_location(struct membuffer *b, struct dive *dive)
{
	degrees_t latitude = dive->latitude;
	degrees_t longitude = dive->longitude;

	/* Should we write a location tag at all? */
	if (!(latitude.udeg || longitude.udeg) && !dive->location)
		return;

	put_string(b, "  <location");

	/*
	 * Ok, theoretically I guess you could dive at
	 * exactly 0,0. But we don't support that. So
	 * if you do, just fudge it a bit, and say that
	 * you dove a few meters away.
	 */
	if (latitude.udeg || longitude.udeg) {
		put_degrees(b, latitude, " gps='", " ");
		put_degrees(b, longitude, "", "'");
	}

	/* Do we have a location name or should we write a empty tag? */
	if (dive->location && dive->location[0] != '\0')
		show_utf8(b, dive->location, ">", "</location>\n", 0);
	else
		put_string(b, "/>\n");
}
Пример #3
0
void writeMarkers(struct membuffer *b, const bool selected_only)
{
	int i, dive_no = 0;
	struct dive *dive;
	char pre[1000], post[1000];

	for_each_dive (i, dive) {
		if (selected_only) {
			if (!dive->selected)
				continue;
		}
		struct dive_site *ds = get_dive_site_for_dive(dive);
		if (!ds || !dive_site_has_gps_location(ds))
			continue;
		put_degrees(b, ds->latitude, "temp = new google.maps.Marker({position: new google.maps.LatLng(", "");
		put_degrees(b, ds->longitude, ",", ")});\n");
		put_string(b, "markers.push(temp);\ntempinfowindow = new google.maps.InfoWindow({content: '<div id=\"content\">'+'<div id=\"siteNotice\">'+'</div>'+'<div id=\"bodyContent\">");
		snprintf(pre, sizeof(pre), "<p>%s ", translate("gettextFromC", "Date:"));
		put_HTML_date(b, dive, pre, "</p>");
		snprintf(pre, sizeof(pre), "<p>%s ", translate("gettextFromC", "Time:"));
		put_HTML_time(b, dive, pre, "</p>");
		snprintf(pre, sizeof(pre), "<p>%s ", translate("gettextFromC", "Duration:"));
		snprintf(post, sizeof(post), " %s</p>", translate("gettextFromC", "min"));
		put_duration(b, dive->duration, pre, post);
		put_string(b, "<p> ");
		put_HTML_quoted(b, translate("gettextFromC", "Max. depth:"));
		put_HTML_depth(b, dive, " ", "</p>");
		put_string(b, "<p> ");
		put_HTML_quoted(b, translate("gettextFromC", "Air temp.:"));
		put_HTML_airtemp(b, dive, " ", "</p>");
		put_string(b, "<p> ");
		put_HTML_quoted(b, translate("gettextFromC", "Water temp.:"));
		put_HTML_watertemp(b, dive, " ", "</p>");
		snprintf(pre, sizeof(pre), "<p>%s <b>", translate("gettextFromC", "Location:"));
		put_string(b, pre);
		put_HTML_quoted(b, get_dive_location(dive));
		put_string(b, "</b></p>");
		snprintf(pre, sizeof(pre), "<p> %s ", translate("gettextFromC", "Notes:"));
		put_HTML_notes(b, dive, pre, " </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);
		dive_no++;
	}
}
Пример #4
0
static void save_picture(struct membuffer *b, struct picture *pic)
{
	put_string(b, "  <picture filename='");
	put_quoted(b, pic->filename, true, false);
	put_string(b, "'");
	if (pic->offset.seconds) {
		int offset = pic->offset.seconds;
		char sign = '+';
		if (offset < 0) {
			sign = '-';
			offset = -offset;
		}
		put_format(b, " offset='%c%u:%02u min'", sign, FRACTION(offset, 60));
	}
	if (pic->latitude.udeg || pic->longitude.udeg) {
		put_degrees(b, pic->latitude, " gps='", " ");
		put_degrees(b, pic->longitude, "", "'");
	}
	if (hashstring(pic->filename))
		put_format(b, " hash='%s'", hashstring(pic->filename));

	put_string(b, "/>\n");
}
Пример #5
0
void save_dives_buffer(struct membuffer *b, const bool select_only)
{
	int i;
	struct dive *dive;
	dive_trip_t *trip;

	put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", VERSION);

	if (prefs.save_userid_local)
		put_format(b, "  <userid>%30s</userid>\n", prefs.userid);

	/* save the dive computer nicknames, if any */
	call_for_each_dc(b, save_one_device);
	if (autogroup)
		put_format(b, "  <autogroup state='1' />\n");
	put_format(b, "</settings>\n");

	/* save the dive sites */
	put_format(b, "<divesites>\n");
	for (i = 0; i < dive_site_table.nr; i++) {
		struct dive_site *ds = get_dive_site(i);
		if (dive_site_is_empty(ds)) {
			int j;
			struct dive *d;
			for_each_dive(j, d) {
				if (d->dive_site_uuid == ds->uuid)
					d->dive_site_uuid = 0;
			}
			delete_dive_site(get_dive_site(i)->uuid);
			i--; // since we just deleted that one
			continue;
		}
		put_format(b, "<site uuid='%8x'", ds->uuid);
		show_utf8(b, ds->name, " name='", "'", 1);
		if (ds->latitude.udeg || ds->longitude.udeg) {
			put_degrees(b, ds->latitude, " gps='", " ");
			put_degrees(b, ds->longitude, "", "'");
		}
		show_utf8(b, ds->description, " description='", "'", 1);
		show_utf8(b, ds->notes, " notes='", "'", 1);
		put_format(b, "/>\n");
	}
	put_format(b, "</divesites>\n<dives>\n");
	for (trip = dive_trip_list; trip != NULL; trip = trip->next)
		trip->index = 0;

	/* save the dives */
	for_each_dive(i, dive) {
		if (select_only) {

			if (!dive->selected)
				continue;
			save_one_dive_to_mb(b, dive);

		} else {
			trip = dive->divetrip;

			/* Bare dive without a trip? */
			if (!trip) {
				save_one_dive_to_mb(b, dive);
				continue;
			}

			/* Have we already seen this trip (and thus saved this dive?) */
			if (trip->index)
				continue;

			/* We haven't seen this trip before - save it and all dives */
			trip->index = 1;
			save_trip(b, trip);
		}
	}
	put_format(b, "</dives>\n</divelog>\n");
}
Пример #6
0
// TODO: This looks like should be ported to C code. or a big part of it.
bool DivelogsDeWebServices::prepare_dives_for_divelogs(const QString &tempfile, const bool selected)
{
	static const char errPrefix[] = "divelog.de-upload:";
	if (!amount_selected) {
		report_error(tr("no dives were selected").toUtf8());
		return false;
	}

	xsltStylesheetPtr xslt = NULL;
	struct zip *zip;

	xslt = get_stylesheet("divelogs-export.xslt");
	if (!xslt) {
		qDebug() << errPrefix << "missing stylesheet";
		return false;
	}


	int error_code;
	zip = zip_open(QFile::encodeName(QDir::toNativeSeparators(tempfile)), ZIP_CREATE, &error_code);
	if (!zip) {
		char buffer[1024];
		zip_error_to_str(buffer, sizeof buffer, error_code, errno);
		report_error(tr("failed to create zip file for upload: %s").toUtf8(), buffer);
		return false;
	}

	/* walk the dive list in chronological order */
	int i;
	struct dive *dive;
	for_each_dive (i, dive) {
		FILE *f;
		char filename[PATH_MAX];
		int streamsize;
		const char *membuf;
		xmlDoc *transformed;
		struct zip_source *s;
		struct membuffer mb = { 0 };

		/*
		 * Get the i'th dive in XML format so we can process it.
		 * We need to save to a file before we can reload it back into memory...
		 */
		if (selected && !dive->selected)
			continue;
		/* make sure the buffer is empty and add the dive */
		mb.len = 0;

		struct dive_site *ds = get_dive_site_by_uuid(dive->dive_site_uuid);

		if (ds) {
			put_format(&mb, "<divelog><divesites><site uuid='%8x' name='", dive->dive_site_uuid);
			put_quoted(&mb, ds->name, 1, 0);
			put_format(&mb, "'");
			if (ds->latitude.udeg || ds->longitude.udeg) {
				put_degrees(&mb, ds->latitude, " gps='", " ");
				put_degrees(&mb, ds->longitude, "", "'");
			}
			put_format(&mb, "/>\n</divesites>\n");
		}

		save_one_dive_to_mb(&mb, dive);

		if (ds) {
			put_format(&mb, "</divelog>\n");
		}
		membuf = mb_cstring(&mb);
		streamsize = strlen(membuf);
		/*
		 * Parse the memory buffer into XML document and
		 * transform it to divelogs.de format, finally dumping
		 * the XML into a character buffer.
		 */
		xmlDoc *doc = xmlReadMemory(membuf, streamsize, "divelog", NULL, 0);
		if (!doc) {
			qWarning() << errPrefix << "could not parse back into memory the XML file we've just created!";
			report_error(tr("internal error").toUtf8());
			goto error_close_zip;
		}
		free((void *)membuf);

		transformed = xsltApplyStylesheet(xslt, doc, NULL);
		xmlDocDumpMemory(transformed, (xmlChar **)&membuf, &streamsize);
		xmlFreeDoc(doc);
		xmlFreeDoc(transformed);

		/*
		 * Save the XML document into a zip file.
		 */
		snprintf(filename, PATH_MAX, "%d.xml", i + 1);
		s = zip_source_buffer(zip, membuf, streamsize, 1);
		if (s) {
			int64_t ret = zip_add(zip, filename, s);
			if (ret == -1)
				qDebug() << errPrefix << "failed to include dive:" << i;
		}
	}
Пример #7
0
void save_dives_buffer(struct membuffer *b, const bool select_only)
{
	int i;
	struct dive *dive;
	dive_trip_t *trip;

	put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);

	if (prefs.save_userid_local)
		put_format(b, "  <userid>%30s</userid>\n", prefs.userid);

	/* save the dive computer nicknames, if any */
	call_for_each_dc(b, save_one_device, select_only);
	if (autogroup)
		put_format(b, "  <autogroup state='1' />\n");
	put_format(b, "</settings>\n");

	/* save the dive sites - to make the output consistent let's sort the table, first */
	dive_site_table_sort();
	put_format(b, "<divesites>\n");
	for (i = 0; i < dive_site_table.nr; i++) {
		int j;
		struct dive *d;
		struct dive_site *ds = get_dive_site(i);
		if (dive_site_is_empty(ds)) {
			for_each_dive(j, d) {
				if (d->dive_site_uuid == ds->uuid)
					d->dive_site_uuid = 0;
			}
			delete_dive_site(get_dive_site(i)->uuid);
			i--; // since we just deleted that one
			continue;
		}
		if (select_only && !is_dive_site_used(ds->uuid, true))
				continue;

		put_format(b, "<site uuid='%8x'", ds->uuid);
		show_utf8(b, ds->name, " name='", "'", 1);
		if (ds->latitude.udeg || ds->longitude.udeg) {
			put_degrees(b, ds->latitude, " gps='", " ");
			put_degrees(b, ds->longitude, "", "'");
		}
		show_utf8(b, ds->description, " description='", "'", 1);
		show_utf8(b, ds->notes, " notes='", "'", 1);
		if (ds->taxonomy.nr) {
			put_format(b, ">\n");
			for (int j = 0; j < ds->taxonomy.nr; j++) {
				struct taxonomy *t = &ds->taxonomy.category[j];
				if (t->category != TC_NONE) {
					put_format(b, "<geo cat='%d'", t->category);
					put_format(b, " origin='%d'", t->origin);
					show_utf8(b, t->value, " value='", "'/>\n", 1);
				}
			}
			put_format(b, "</site>\n");
		} else {
			put_format(b, "/>\n");
		}
	}
	put_format(b, "</divesites>\n<dives>\n");
	for (trip = dive_trip_list; trip != NULL; trip = trip->next)
		trip->index = 0;

	/* save the dives */
	for_each_dive(i, dive) {
		if (select_only) {

			if (!dive->selected)
				continue;
			save_one_dive_to_mb(b, dive);

		} else {
			trip = dive->divetrip;

			/* Bare dive without a trip? */
			if (!trip) {
				save_one_dive_to_mb(b, dive);
				continue;
			}

			/* Have we already seen this trip (and thus saved this dive?) */
			if (trip->index)
				continue;

			/* We haven't seen this trip before - save it and all dives */
			trip->index = 1;
			save_trip(b, trip);
		}
	}
	put_format(b, "</dives>\n</divelog>\n");
}
Пример #8
0
void save_dives_buffer(struct membuffer *b, const bool select_only)
{
    int i;
    struct dive *dive;
    dive_trip_t *trip;

    put_format(b, "<divelog program='subsurface' version='%d'>\n<settings>\n", DATAFORMAT_VERSION);

    if (prefs.save_userid_local)
        put_format(b, "  <userid>%30s</userid>\n", prefs.userid);

    /* save the dive computer nicknames, if any */
    call_for_each_dc(b, save_one_device, select_only);
    if (autogroup)
        put_format(b, "  <autogroup state='1' />\n");
    put_format(b, "</settings>\n");

    /* save the dive sites - to make the output consistent let's sort the table, first */
    dive_site_table_sort();
    put_format(b, "<divesites>\n");
    for (i = 0; i < dive_site_table.nr; i++) {
        int j;
        struct dive *d;
        struct dive_site *ds = get_dive_site(i);
        if (dive_site_is_empty(ds)) {
            for_each_dive(j, d) {
                if (d->dive_site_uuid == ds->uuid)
                    d->dive_site_uuid = 0;
            }
            delete_dive_site(ds->uuid);
            i--; // since we just deleted that one
            continue;
        } else if (ds->name &&
                   (strncmp(ds->name, "Auto-created dive", 17) == 0 ||
                    strncmp(ds->name, "New Dive", 8) == 0)) {
            // these are the two default names for sites from
            // the web service; if the site isn't used in any
            // dive (really? you didn't rename it?), delete it
            if (!is_dive_site_used(ds->uuid, false)) {
                if (verbose)
                    fprintf(stderr, "Deleted unused auto-created dive site %s\n", ds->name);
                delete_dive_site(ds->uuid);
                i--; // since we just deleted that one
                continue;
            }
        }
        if (select_only && !is_dive_site_used(ds->uuid, true))
            continue;

        put_format(b, "<site uuid='%8x'", ds->uuid);
        show_utf8(b, ds->name, " name='", "'", 1);
        if (ds->latitude.udeg || ds->longitude.udeg) {
            put_degrees(b, ds->latitude, " gps='", " ");
            put_degrees(b, ds->longitude, "", "'");
        }
        show_utf8(b, ds->description, " description='", "'", 1);
        put_format(b, ">\n");
        show_utf8(b, ds->notes, "  <notes>", " </notes>\n", 0);
        if (ds->taxonomy.nr) {
            for (int j = 0; j < ds->taxonomy.nr; j++) {
                struct taxonomy *t = &ds->taxonomy.category[j];
                if (t->category != TC_NONE && t->value) {
                    put_format(b, "  <geo cat='%d'", t->category);
                    put_format(b, " origin='%d'", t->origin);
                    show_utf8(b, t->value, " value='", "'/>\n", 1);
                }
            }
        }
        put_format(b, "</site>\n");
    }