1
0
Fork 0
mirror of https://github.com/deltachat/deltachat-core.git synced 2025-10-05 10:39:27 +02:00

send locations as kml-files

This commit is contained in:
B. Petersen 2019-03-07 15:53:00 +01:00
parent bfbfb7f33f
commit b72e22a1ba
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
3 changed files with 46 additions and 15 deletions

View file

@ -121,7 +121,7 @@ int dc_is_inbox (dc_context_t*, const char* folder);
int dc_is_sentbox (dc_context_t*, const char* folder);
int dc_is_mvbox (dc_context_t*, const char* folder);
char* dc_get_location_str (dc_context_t*);
char* dc_get_location_kml (dc_context_t*, uint32_t chat_id);
#define DC_BAK_PREFIX "delta-chat"
#define DC_BAK_SUFFIX "bak"

View file

@ -144,17 +144,25 @@ cleanup:
char* dc_get_location_str(dc_context_t* context)
char* dc_get_location_kml(dc_context_t* context, uint32_t chat_id)
{
sqlite3_stmt* stmt = NULL;
double latitude = 0.0;
double longitude = 0.0;
double accuracy = 0.0;
sqlite3_stmt* stmt = NULL;
double latitude = 0.0;
double longitude = 0.0;
double accuracy = 0.0;
time_t timestamp = 0;
dc_strbuilder_t ret;
dc_strbuilder_init(&ret, 1000);
if (context==NULL || context->magic!=DC_CONTEXT_MAGIC) {
goto cleanup;
}
dc_strbuilder_cat(&ret,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<kml xmlns=\"http://www.opengis.net/kml/2.2\">\n"
"<Document>\n");
stmt = dc_sqlite3_prepare(context->sql,
"SELECT latitude, longitude, accuracy, timestamp "
" FROM locations "
@ -162,20 +170,36 @@ char* dc_get_location_str(dc_context_t* context)
" AND timestamp=(SELECT MAX(timestamp) FROM locations WHERE from_id=?) ");
sqlite3_bind_int (stmt, 1, DC_CONTACT_ID_SELF);
sqlite3_bind_int (stmt, 2, DC_CONTACT_ID_SELF);
if (sqlite3_step(stmt)==SQLITE_ROW) {
while (sqlite3_step(stmt)==SQLITE_ROW)
{
latitude = sqlite3_column_double(stmt, 0);
longitude = sqlite3_column_double(stmt, 1);
accuracy = sqlite3_column_double(stmt, 2);
timestamp = sqlite3_column_int64 (stmt, 3);
dc_strbuilder_catf(&ret,
"<Placemark>"
"<Timestamp><when>%i</when></Timestamp>" // TODO: timestamp must be formatted as 2005-08-21T09:01:00Z
"<Point><coordinates accuracy=\"%f\">%f,%f,0</coordinates></Point>"
"</Placemark>\n",
(int)timestamp,
accuracy,
latitude,
longitude);
}
dc_strbuilder_cat(&ret,
"</Document>\n"
"</kml>");
cleanup:
sqlite3_finalize(stmt);
return dc_mprintf("%f %f %f", latitude, longitude, accuracy);
return ret.buf;
}
/**
* Get last location for a contact in a given chat.
* Get last locations for a contact in a given chat.
* The number of returned locations can be retrieved using dc_array_get_cnt(),
* to get information for each location,
* use dc_array_get_latitude(), dc_array_get_longitude(),

View file

@ -612,12 +612,6 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
}
}
if (dc_is_sending_locations_to_chat(msg->context, msg->chat_id)) {
mailimf_fields_add(imf_fields, mailimf_field_new_custom(
strdup("Chat-Location"),
dc_get_location_str(msg->context)));
}
if (grpimage)
{
dc_msg_t* meta = dc_msg_new_untyped(factory->context);
@ -699,6 +693,19 @@ int dc_mimefactory_render(dc_mimefactory_t* factory)
mailmime_smart_add_part(message, meta_part); /* meta parts are only added if there are other parts */
parts++;
}
if (dc_is_sending_locations_to_chat(msg->context, msg->chat_id)) {
char* kml_file = dc_get_location_kml(msg->context, msg->chat_id);
struct mailmime_content* content_type = mailmime_content_new_with_str("application/vnd.google-earth.kml+xml");
struct mailmime_fields* mime_fields = mailmime_fields_new_filename(MAILMIME_DISPOSITION_TYPE_ATTACHMENT,
dc_strdup("location.kml"), MAILMIME_MECHANISM_8BIT);
struct mailmime* kml_mime_part = mailmime_new_empty(content_type, mime_fields);
mailmime_set_body_text(kml_mime_part, kml_file, strlen(kml_file));
mailmime_smart_add_part(message, kml_mime_part);
parts++;
}
}
else if (factory->loaded==DC_MF_MDN_LOADED)
{