diff --git a/cmdline/cmdline.c b/cmdline/cmdline.c index 9bd5d196..ab60ea8a 100644 --- a/cmdline/cmdline.c +++ b/cmdline/cmdline.c @@ -449,6 +449,7 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline) "send \n" "sendimage []\n" "sendfile \n" + "sendpoi \n" "draft []\n" "listmedia\n" "archive \n" @@ -1035,6 +1036,31 @@ char* dc_cmdline(dc_context_t* context, const char* cmdline) ret = dc_strdup("No chat selected."); } } + else if (strcmp(cmd, "sendpoi")==0) + { + if (sel_chat) { + char* arg2 = arg1? strchr(arg1, ' ') : NULL; + if (arg2) { *arg2 = 0; arg2++; } + + char* arg3 = arg2? strchr(arg2, ' ') : NULL; + if (arg3) { *arg3 = 0; arg3++; } + + if (arg1 && arg2 && arg3) { + dc_msg_t* msg = dc_msg_new(context,DC_MSG_TEXT); + dc_msg_set_text(msg, arg3); + dc_msg_set_location(msg, dc_atof(arg1), dc_atof(arg2), 2.0); + dc_send_msg(context, dc_chat_get_id(sel_chat), msg); + dc_msg_unref(msg); + ret = COMMAND_SUCCEEDED; + } + else { + ret = dc_strdup("ERROR: Usage: sendpoi "); + } + } + else { + ret = dc_strdup("No chat selected."); + } + } else if (strcmp(cmd, "listmsgs")==0) { if (arg1) { diff --git a/src/dc_msg.c b/src/dc_msg.c index a7876689..1a4bec00 100644 --- a/src/dc_msg.c +++ b/src/dc_msg.c @@ -1165,6 +1165,37 @@ void dc_msg_set_duration(dc_msg_t* msg, int duration) } +/** + * Set any location that should be bound to the message object. + * The function is useful to add a marker to the map + * at a position different from the self-location. + * You should not call this function + * if you want to bind the current self-location to a message; + * this is done by dc_set_location() and dc_send_locations_to_chat(). + * + * Typically results in the event #DC_EVENT_LOCATION_CHANGED with + * contact_id set to DC_CONTACT_ID_SELF. + * + * @memberof dc_msg_t + * @param context The message object. + * @param latitude North-south position of the location. + * @param longitude East-west position of the location. + * @param accuracy Estimated accuracy of the location, radial, in meters. + * Set to 0.0 if the accuracy is not known. + * @return None. + */ +void dc_msg_set_location(dc_msg_t* msg, double latitude, double longitude, double accuracy) +{ + if (msg==NULL || msg->magic!=DC_MSG_MAGIC || (latitude==0.0 && longitude==0.0)) { + return; + } + + dc_param_set_float(msg->param, DC_PARAM_SET_LATITUDE, latitude); + dc_param_set_float(msg->param, DC_PARAM_SET_LONGITUDE, longitude); + dc_param_set_float(msg->param, DC_PARAM_SET_ACCURACY, accuracy); +} + + /** * Late filing information to a message. * In contrast to the dc_msg_set_*() functions, this function really stores the information in the database. diff --git a/src/dc_param.c b/src/dc_param.c index 23e27f0b..98a90765 100644 --- a/src/dc_param.c +++ b/src/dc_param.c @@ -304,3 +304,27 @@ void dc_param_set_int(dc_param_t* param, int key, int32_t value) dc_param_set(param, key, value_str); free(value_str); } + + +/** + * Set parameter to a float. + * + * @memberof dc_param_t + * @param param Parameter object to modify. + * @param key Key of the parameter to modify, one of the DC_PARAM_* constants. + * @param value Value to store for key. + * @return None. + */ +void dc_param_set_float(dc_param_t* param, int key, double value) +{ + if (param==NULL || key==0) { + return; + } + + char* value_str = dc_ftoa(value); + if (value_str==NULL) { + return; + } + dc_param_set(param, key, value_str); + free(value_str); +} diff --git a/src/dc_param.h b/src/dc_param.h index 1a11efc3..33f55765 100644 --- a/src/dc_param.h +++ b/src/dc_param.h @@ -43,6 +43,9 @@ struct _dc_param #define DC_PARAM_CMD_ARG4 'H' /* for msgs */ #define DC_PARAM_ERROR 'L' /* for msgs */ #define DC_PARAM_PREP_FORWARDS 'P' /* for msgs in PREPARING: space-separated list of message IDs of forwarded copies */ +#define DC_PARAM_SET_LATITUDE 'l' /* for msgs */ +#define DC_PARAM_SET_LONGITUDE 'n' /* for msgs */ +#define DC_PARAM_SET_ACCURACY 'y' /* for msgs */ #define DC_PARAM_SERVER_FOLDER 'Z' /* for jobs */ #define DC_PARAM_SERVER_UID 'z' /* for jobs */ @@ -65,6 +68,7 @@ char* dc_param_get (const dc_param_t*, int key, const char* int32_t dc_param_get_int (const dc_param_t*, int key, int32_t def); void dc_param_set (dc_param_t*, int key, const char* value); void dc_param_set_int (dc_param_t*, int key, int32_t value); +void dc_param_set_float (dc_param_t*, int key, double value); /* library-private */ dc_param_t* dc_param_new (); diff --git a/src/deltachat.h b/src/deltachat.h index c94f11e4..3862ffaf 100644 --- a/src/deltachat.h +++ b/src/deltachat.h @@ -550,6 +550,7 @@ void dc_msg_set_text (dc_msg_t*, const char* text); void dc_msg_set_file (dc_msg_t*, const char* file, const char* filemime); void dc_msg_set_dimension (dc_msg_t*, int width, int height); void dc_msg_set_duration (dc_msg_t*, int duration); +void dc_msg_set_location (dc_msg_t*, double latitude, double longitude, double accuracy); void dc_msg_latefiling_mediasize (dc_msg_t*, int width, int height, int duration);