]>
Commit | Line | Data |
---|---|---|
3e7553ae GB |
1 | /* |
2 | * viking -- GPS Data and Topo Analyzer, Explorer, and Manager | |
3 | * | |
4 | * Copyright (C) 2007, Guilhem Bonnefille <guilhem.bonnefille@gmail.com> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 | * | |
20 | */ | |
4c77d5e0 GB |
21 | #ifdef HAVE_CONFIG_H |
22 | #include "config.h" | |
23 | #endif | |
3e7553ae GB |
24 | |
25 | #include <stdio.h> | |
26 | #include <string.h> | |
3e7553ae | 27 | #include <errno.h> |
36420b5f | 28 | #include <time.h> |
3e7553ae GB |
29 | |
30 | #include <curl/curl.h> | |
3e7553ae GB |
31 | #include <curl/easy.h> |
32 | ||
33 | #include <glib.h> | |
34 | #include <glib/gstdio.h> | |
4c77d5e0 | 35 | #include <glib/gi18n.h> |
3e7553ae GB |
36 | |
37 | #include "viking.h" | |
38 | #include "viktrwlayer.h" | |
39 | #include "osm-traces.h" | |
40 | #include "gpx.h" | |
41 | #include "background.h" | |
843b99df GB |
42 | #include "preferences.h" |
43 | ||
9de6196a | 44 | /* params will be osm_traces.username, osm_traces.password */ |
843b99df GB |
45 | /* we have to make sure these don't collide. */ |
46 | #define VIKING_OSM_TRACES_PARAMS_GROUP_KEY "osm_traces" | |
47 | #define VIKING_OSM_TRACES_PARAMS_NAMESPACE "osm_traces." | |
3e7553ae GB |
48 | |
49 | /** | |
50 | * Login to use for OSM uploading. | |
51 | */ | |
52 | static gchar *user = NULL; | |
53 | ||
54 | /** | |
55 | * Password to use for OSM uploading. | |
56 | */ | |
57 | static gchar *password = NULL; | |
58 | ||
59 | /** | |
60 | * Mutex to protect auth. token | |
61 | */ | |
62 | static GMutex *login_mutex = NULL; | |
63 | ||
8b589250 GS |
64 | /** |
65 | * Different type of trace visibility. | |
66 | */ | |
67 | typedef struct _OsmTraceVis_t { | |
68 | const gchar *combostr; | |
69 | const gchar *apistr; | |
70 | } OsmTraceVis_t; | |
71 | ||
72 | static const OsmTraceVis_t OsmTraceVis[] = { | |
502d25de GB |
73 | { N_("Identifiable (public w/ timestamps)"), "identifiable" }, |
74 | { N_("Trackable (private w/ timestamps)"), "trackable" }, | |
75 | { N_("Public"), "public" }, | |
76 | { N_("Private"), "private" }, | |
8b589250 GS |
77 | { NULL, NULL }, |
78 | }; | |
79 | ||
3e7553ae GB |
80 | /** |
81 | * Struct hosting needed info. | |
82 | */ | |
83 | typedef struct _OsmTracesInfo { | |
84 | gchar *name; | |
85 | gchar *description; | |
86 | gchar *tags; | |
8b589250 | 87 | const OsmTraceVis_t *vistype; |
3e7553ae | 88 | VikTrwLayer *vtl; |
ce4bd1cf | 89 | VikTrack *trk; |
3e7553ae GB |
90 | } OsmTracesInfo; |
91 | ||
843b99df GB |
92 | static VikLayerParam prefs[] = { |
93 | { VIKING_OSM_TRACES_PARAMS_NAMESPACE "username", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM username:"), VIK_LAYER_WIDGET_ENTRY }, | |
dd8bde3a | 94 | { VIKING_OSM_TRACES_PARAMS_NAMESPACE "password", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM password:"), VIK_LAYER_WIDGET_PASSWORD }, |
843b99df GB |
95 | }; |
96 | ||
3e7553ae GB |
97 | /** |
98 | * Free an OsmTracesInfo struct. | |
99 | */ | |
100 | static void oti_free(OsmTracesInfo *oti) | |
101 | { | |
102 | if (oti) { | |
103 | /* Fields have been g_strdup'ed */ | |
104 | g_free(oti->name); oti->name = NULL; | |
105 | g_free(oti->description); oti->description = NULL; | |
106 | g_free(oti->tags); oti->tags = NULL; | |
107 | ||
108 | g_object_unref(oti->vtl); oti->vtl = NULL; | |
109 | } | |
110 | /* Main struct has been g_malloc'ed */ | |
111 | g_free(oti); | |
112 | } | |
113 | ||
624318ca | 114 | static const gchar *get_default_user() |
51c15f41 GB |
115 | { |
116 | const gchar *default_user = NULL; | |
117 | ||
118 | /* Retrieve "standard" EMAIL varenv */ | |
119 | default_user = g_getenv("EMAIL"); | |
120 | ||
121 | return default_user; | |
122 | } | |
123 | ||
3e7553ae GB |
124 | static void set_login(const gchar *user_, const gchar *password_) |
125 | { | |
126 | /* Allocate mutex */ | |
127 | if (login_mutex == NULL) | |
128 | { | |
129 | login_mutex = g_mutex_new(); | |
130 | } | |
131 | g_mutex_lock(login_mutex); | |
132 | g_free(user); user = NULL; | |
133 | g_free(password); password = NULL; | |
134 | user = g_strdup(user_); | |
135 | password = g_strdup(password_); | |
136 | g_mutex_unlock(login_mutex); | |
137 | } | |
138 | ||
139 | static gchar *get_login() | |
140 | { | |
141 | gchar *user_pass = NULL; | |
142 | g_mutex_lock(login_mutex); | |
143 | user_pass = g_strdup_printf("%s:%s", user, password); | |
144 | g_mutex_unlock(login_mutex); | |
145 | return user_pass; | |
146 | } | |
147 | ||
843b99df GB |
148 | /* initialisation */ |
149 | void osm_traces_init () { | |
150 | /* Preferences */ | |
d11de0ca | 151 | a_preferences_register_group ( VIKING_OSM_TRACES_PARAMS_GROUP_KEY, _("OpenStreetMap Traces") ); |
843b99df GB |
152 | |
153 | VikLayerParamData tmp; | |
154 | tmp.s = ""; | |
155 | a_preferences_register(prefs, tmp, VIKING_OSM_TRACES_PARAMS_GROUP_KEY); | |
156 | tmp.s = ""; | |
157 | a_preferences_register(prefs+1, tmp, VIKING_OSM_TRACES_PARAMS_GROUP_KEY); | |
158 | ||
159 | } | |
160 | ||
3e7553ae GB |
161 | /* |
162 | * Upload a file | |
36420b5f RN |
163 | * returns a basic status: |
164 | * < 0 : curl error | |
165 | * == 0 : OK | |
166 | * > 0 : HTTP error | |
167 | */ | |
168 | static gint osm_traces_upload_file(const char *user, | |
169 | const char *password, | |
170 | const char *file, | |
171 | const char *filename, | |
172 | const char *description, | |
173 | const char *tags, | |
174 | const OsmTraceVis_t *vistype) | |
3e7553ae GB |
175 | { |
176 | CURL *curl; | |
177 | CURLcode res; | |
178 | char curl_error_buffer[CURL_ERROR_SIZE]; | |
179 | struct curl_slist *headers = NULL; | |
180 | struct curl_httppost *post=NULL; | |
181 | struct curl_httppost *last=NULL; | |
3e7553ae | 182 | |
ffb5a285 | 183 | char *base_url = "http://www.openstreetmap.org/api/0.6/gpx/create"; |
3e7553ae GB |
184 | |
185 | gchar *user_pass = get_login(); | |
186 | ||
36420b5f RN |
187 | gint result = 0; // Default to it worked! |
188 | ||
3e7553ae GB |
189 | g_debug("%s: %s %s %s %s %s %s", __FUNCTION__, |
190 | user, password, file, filename, description, tags); | |
191 | ||
192 | /* Init CURL */ | |
193 | curl = curl_easy_init(); | |
194 | ||
195 | /* Filling the form */ | |
196 | curl_formadd(&post, &last, | |
197 | CURLFORM_COPYNAME, "description", | |
198 | CURLFORM_COPYCONTENTS, description, CURLFORM_END); | |
199 | curl_formadd(&post, &last, | |
200 | CURLFORM_COPYNAME, "tags", | |
201 | CURLFORM_COPYCONTENTS, tags, CURLFORM_END); | |
3e7553ae | 202 | curl_formadd(&post, &last, |
8b589250 GS |
203 | CURLFORM_COPYNAME, "visibility", |
204 | CURLFORM_COPYCONTENTS, vistype->apistr, CURLFORM_END); | |
3e7553ae GB |
205 | curl_formadd(&post, &last, |
206 | CURLFORM_COPYNAME, "file", | |
207 | CURLFORM_FILE, file, | |
208 | CURLFORM_FILENAME, filename, | |
209 | CURLFORM_CONTENTTYPE, "text/xml", CURLFORM_END); | |
210 | ||
211 | /* Prepare request */ | |
212 | /* As explained in http://wiki.openstreetmap.org/index.php/User:LA2 */ | |
213 | /* Expect: header seems to produce incompatibilites between curl and httpd */ | |
214 | headers = curl_slist_append(headers, "Expect: "); | |
215 | curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); | |
216 | curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); | |
217 | curl_easy_setopt(curl, CURLOPT_URL, base_url); | |
218 | curl_easy_setopt(curl, CURLOPT_USERPWD, user_pass); | |
219 | curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | |
5a7d2873 | 220 | curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer); |
2936913d GB |
221 | if (vik_verbose) |
222 | curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 ); | |
3e7553ae GB |
223 | |
224 | /* Execute request */ | |
225 | res = curl_easy_perform(curl); | |
226 | if (res == CURLE_OK) | |
227 | { | |
228 | long code; | |
229 | res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); | |
230 | if (res == CURLE_OK) | |
231 | { | |
232 | g_debug("received valid curl response: %ld", code); | |
36420b5f | 233 | if (code != 200) { |
4c77d5e0 | 234 | g_warning(_("failed to upload data: HTTP response is %ld"), code); |
36420b5f RN |
235 | result = code; |
236 | } | |
3e7553ae | 237 | } |
36420b5f | 238 | else { |
24ff9c7b | 239 | g_critical(_("curl_easy_getinfo failed: %d"), res); |
36420b5f | 240 | result = -1; |
3e7553ae | 241 | } |
36420b5f RN |
242 | } |
243 | else { | |
244 | g_warning(_("curl request failed: %s"), curl_error_buffer); | |
245 | result = -2; | |
246 | } | |
3e7553ae GB |
247 | |
248 | /* Memory */ | |
249 | g_free(user_pass); user_pass = NULL; | |
250 | ||
251 | curl_formfree(post); | |
36420b5f RN |
252 | curl_easy_cleanup(curl); |
253 | return result; | |
3e7553ae GB |
254 | } |
255 | ||
256 | /** | |
257 | * uploading function executed by the background" thread | |
258 | */ | |
259 | static void osm_traces_upload_thread ( OsmTracesInfo *oti, gpointer threaddata ) | |
260 | { | |
208d2084 RN |
261 | /* Due to OSM limits, we have to enforce ele and time fields |
262 | also don't upload invisible tracks */ | |
0d2b891f | 263 | static GpxWritingOptions options = { TRUE, TRUE, FALSE, FALSE }; |
3e7553ae GB |
264 | FILE *file = NULL; |
265 | gchar *filename = NULL; | |
266 | int fd; | |
267 | GError *error = NULL; | |
268 | int ret; | |
269 | ||
270 | g_assert(oti != NULL); | |
271 | ||
272 | /* Opening temporary file */ | |
273 | fd = g_file_open_tmp("viking_osm_upload_XXXXXX.gpx", &filename, &error); | |
274 | if (fd < 0) { | |
4c77d5e0 | 275 | g_error(_("failed to open temporary file: %s"), strerror(errno)); |
3e7553ae GB |
276 | return; |
277 | } | |
278 | g_clear_error(&error); | |
279 | g_debug("%s: temporary file = %s", __FUNCTION__, filename); | |
280 | ||
281 | /* Creating FILE* */ | |
282 | file = fdopen(fd, "w"); | |
283 | ||
284 | /* writing gpx file */ | |
ce4bd1cf | 285 | if (oti->trk != NULL) |
5092de80 GB |
286 | { |
287 | /* Upload only the selected track */ | |
208d2084 | 288 | a_gpx_write_track_file(oti->trk, file, &options); |
5092de80 GB |
289 | } |
290 | else | |
0b72c435 | 291 | { |
5092de80 | 292 | /* Upload the whole VikTrwLayer */ |
208d2084 | 293 | a_gpx_write_file(oti->vtl, file, &options); |
0b72c435 | 294 | } |
3e7553ae GB |
295 | |
296 | /* We can close the file */ | |
297 | /* This also close the associated fd */ | |
298 | fclose(file); | |
8c060406 | 299 | file = NULL; |
3e7553ae GB |
300 | |
301 | /* finally, upload it */ | |
36420b5f RN |
302 | gint ans = osm_traces_upload_file(user, password, filename, |
303 | oti->name, oti->description, oti->tags, oti->vistype); | |
304 | ||
305 | // | |
306 | // Show result in statusbar or failure in dialog for user feedback | |
307 | // | |
308 | ||
309 | // Get current time to put into message to show when result was generated | |
310 | // since need to show difference between operations (when displayed on statusbar) | |
311 | // NB If on dialog then don't need time. | |
312 | time_t timenow; | |
313 | struct tm* timeinfo; | |
314 | time ( &timenow ); | |
315 | timeinfo = localtime ( &timenow ); | |
316 | gchar timestr[80]; | |
317 | // Compact time only - as days/date isn't very useful here | |
318 | strftime ( timestr, sizeof(timestr), "%X)", timeinfo ); | |
319 | ||
320 | // | |
321 | // Test to see if window it was invoked on is still valid | |
322 | // Not sure if this test really works! (i.e. if the window was closed in the mean time) | |
323 | // | |
324 | if ( IS_VIK_WINDOW ((VikWindow *)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl)) ) { | |
325 | gchar* msg; | |
326 | if ( ans == 0 ) { | |
327 | // Success | |
328 | msg = g_strdup_printf ( "%s (@%s)", _("Uploaded to OSM"), timestr ); | |
36420b5f RN |
329 | } |
330 | // Use UPPER CASE for bad news :( | |
331 | else if ( ans < 0 ) { | |
332 | msg = g_strdup_printf ( "%s (@%s)", _("FAILED TO UPLOAD DATA TO OSM - CURL PROBLEM"), timestr ); | |
36420b5f RN |
333 | } |
334 | else { | |
335 | msg = g_strdup_printf ( "%s : %s %d (@%s)", _("FAILED TO UPLOAD DATA TO OSM"), _("HTTP response code"), ans, timestr ); | |
36420b5f | 336 | } |
7e5bb4eb RN |
337 | // From the background so should use the signalling method to update display: |
338 | // TODO: This only works with statically assigned strings ATM | |
339 | vik_window_signal_statusbar_update ( (VikWindow*)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl), msg, VIK_STATUSBAR_INFO ); | |
340 | // Thus can't free the memory yet... | |
341 | // Luckily OSM traces isn't heavily used so this is not a significant memory leak | |
342 | //g_free (msg); | |
343 | // But this is better than potentially crashing from multi thread GUI updates | |
36420b5f | 344 | } |
3e7553ae GB |
345 | /* Removing temporary file */ |
346 | ret = g_unlink(filename); | |
347 | if (ret != 0) { | |
24ff9c7b | 348 | g_critical(_("failed to unlink temporary file: %s"), strerror(errno)); |
3e7553ae GB |
349 | } |
350 | } | |
351 | ||
352 | /** | |
353 | * Uploading a VikTrwLayer | |
5092de80 GB |
354 | * |
355 | * @param vtl VikTrwLayer | |
ce4bd1cf | 356 | * @param trk if not null, the track to upload |
3e7553ae | 357 | */ |
ce4bd1cf | 358 | static void osm_traces_upload_viktrwlayer ( VikTrwLayer *vtl, VikTrack *trk ) |
3e7553ae | 359 | { |
4c77d5e0 | 360 | GtkWidget *dia = gtk_dialog_new_with_buttons (_("OSM upload"), |
3e7553ae GB |
361 | VIK_GTK_WINDOW_FROM_LAYER(vtl), |
362 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
363 | GTK_STOCK_CANCEL, | |
364 | GTK_RESPONSE_REJECT, | |
365 | GTK_STOCK_OK, | |
366 | GTK_RESPONSE_ACCEPT, | |
367 | NULL); | |
368 | ||
843b99df GB |
369 | const gchar *default_user = get_default_user(); |
370 | const gchar *pref_user = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "username")->s; | |
371 | const gchar *pref_password = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "password")->s; | |
3e7553ae GB |
372 | const gchar *name = NULL; |
373 | GtkWidget *user_label, *user_entry; | |
374 | GtkWidget *password_label, *password_entry; | |
375 | GtkWidget *name_label, *name_entry; | |
376 | GtkWidget *description_label, *description_entry; | |
377 | GtkWidget *tags_label, *tags_entry; | |
8b589250 GS |
378 | GtkComboBox *visibility; |
379 | const OsmTraceVis_t *vis_t; | |
3e7553ae | 380 | |
4c77d5e0 | 381 | user_label = gtk_label_new(_("Email:")); |
3e7553ae | 382 | user_entry = gtk_entry_new(); |
843b99df | 383 | if (user != NULL && user[0] != '\0') |
3e7553ae | 384 | gtk_entry_set_text(GTK_ENTRY(user_entry), user); |
843b99df GB |
385 | else if (pref_user != NULL && pref_user[0] != '\0') |
386 | gtk_entry_set_text(GTK_ENTRY(user_entry), pref_user); | |
387 | else if (default_user != NULL) | |
388 | gtk_entry_set_text(GTK_ENTRY(user_entry), default_user); | |
3e7553ae GB |
389 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), user_label, FALSE, FALSE, 0); |
390 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), user_entry, FALSE, FALSE, 0); | |
064a4ce9 SB |
391 | gtk_widget_set_tooltip_markup(GTK_WIDGET(user_entry), |
392 | _("The email used as login\n" | |
393 | "<small>Enter the email you use to login into www.openstreetmap.org.</small>")); | |
3e7553ae | 394 | |
4c77d5e0 | 395 | password_label = gtk_label_new(_("Password:")); |
3e7553ae | 396 | password_entry = gtk_entry_new(); |
843b99df | 397 | if (password != NULL && password[0] != '\0') |
3e7553ae | 398 | gtk_entry_set_text(GTK_ENTRY(password_entry), password); |
843b99df GB |
399 | else if (pref_password != NULL) |
400 | gtk_entry_set_text(GTK_ENTRY(password_entry), pref_password); | |
3e7553ae GB |
401 | /* This is a password -> invisible */ |
402 | gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE); | |
403 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), password_label, FALSE, FALSE, 0); | |
404 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), password_entry, FALSE, FALSE, 0); | |
064a4ce9 SB |
405 | gtk_widget_set_tooltip_markup(GTK_WIDGET(password_entry), |
406 | _("The password used to login\n" | |
407 | "<small>Enter the password you use to login into www.openstreetmap.org.</small>")); | |
3e7553ae | 408 | |
4c77d5e0 | 409 | name_label = gtk_label_new(_("File's name:")); |
3e7553ae | 410 | name_entry = gtk_entry_new(); |
ce4bd1cf RN |
411 | if (trk != NULL) |
412 | name = trk->name; | |
5092de80 GB |
413 | else |
414 | name = vik_layer_get_name(VIK_LAYER(vtl)); | |
3e7553ae GB |
415 | gtk_entry_set_text(GTK_ENTRY(name_entry), name); |
416 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), name_label, FALSE, FALSE, 0); | |
417 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), name_entry, FALSE, FALSE, 0); | |
064a4ce9 SB |
418 | gtk_widget_set_tooltip_markup(GTK_WIDGET(name_entry), |
419 | _("The name of the file on OSM\n" | |
420 | "<small>This is the name of the file created on the server." | |
421 | "This is not the name of the local file.</small>")); | |
3e7553ae | 422 | |
4c77d5e0 | 423 | description_label = gtk_label_new(_("Description:")); |
3e7553ae GB |
424 | description_entry = gtk_entry_new(); |
425 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), description_label, FALSE, FALSE, 0); | |
426 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), description_entry, FALSE, FALSE, 0); | |
064a4ce9 SB |
427 | gtk_widget_set_tooltip_text(GTK_WIDGET(description_entry), |
428 | _("The description of the trace")); | |
3e7553ae | 429 | |
4c77d5e0 | 430 | tags_label = gtk_label_new(_("Tags:")); |
3e7553ae GB |
431 | tags_entry = gtk_entry_new(); |
432 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), tags_label, FALSE, FALSE, 0); | |
433 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), tags_entry, FALSE, FALSE, 0); | |
064a4ce9 SB |
434 | gtk_widget_set_tooltip_text(GTK_WIDGET(tags_entry), |
435 | _("The tags associated to the trace")); | |
3e7553ae | 436 | |
8b589250 GS |
437 | visibility = GTK_COMBO_BOX(gtk_combo_box_new_text ()); |
438 | for (vis_t = OsmTraceVis; vis_t->combostr != NULL; vis_t++) | |
439 | gtk_combo_box_append_text(visibility, vis_t->combostr); | |
440 | /* Set identifiable by default */ | |
441 | gtk_combo_box_set_active(visibility, 0); | |
442 | gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), GTK_WIDGET(visibility), FALSE, FALSE, 0); | |
443 | ||
76e2179a RN |
444 | /* User should think about it first... */ |
445 | gtk_dialog_set_default_response ( GTK_DIALOG(dia), GTK_RESPONSE_REJECT ); | |
446 | ||
8b589250 GS |
447 | gtk_widget_show_all ( dia ); |
448 | gtk_widget_grab_focus ( description_entry ); | |
3e7553ae GB |
449 | |
450 | if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_ACCEPT ) | |
451 | { | |
452 | gchar *title = NULL; | |
453 | ||
454 | /* overwrite authentication info */ | |
455 | set_login(gtk_entry_get_text(GTK_ENTRY(user_entry)), | |
456 | gtk_entry_get_text(GTK_ENTRY(password_entry))); | |
457 | ||
458 | /* Storing data for the future thread */ | |
459 | OsmTracesInfo *info = g_malloc(sizeof(OsmTracesInfo)); | |
460 | info->name = g_strdup(gtk_entry_get_text(GTK_ENTRY(name_entry))); | |
461 | info->description = g_strdup(gtk_entry_get_text(GTK_ENTRY(description_entry))); | |
462 | /* TODO Normalize tags: they will be used as URL part */ | |
463 | info->tags = g_strdup(gtk_entry_get_text(GTK_ENTRY(tags_entry))); | |
8b589250 | 464 | info->vistype = &OsmTraceVis[gtk_combo_box_get_active(visibility)]; |
3e7553ae | 465 | info->vtl = VIK_TRW_LAYER(g_object_ref(vtl)); |
ce4bd1cf | 466 | info->trk = trk; |
3e7553ae | 467 | |
4c77d5e0 | 468 | title = g_strdup_printf(_("Uploading %s to OSM"), info->name); |
3e7553ae GB |
469 | |
470 | /* launch the thread */ | |
471 | a_background_thread(VIK_GTK_WINDOW_FROM_LAYER(vtl), /* parent window */ | |
472 | title, /* description string */ | |
473 | (vik_thr_func) osm_traces_upload_thread, /* function to call within thread */ | |
474 | info, /* pass along data */ | |
475 | (vik_thr_free_func) oti_free, /* function to free pass along data */ | |
476 | (vik_thr_free_func) NULL, | |
477 | 1 ); | |
478 | g_free ( title ); title = NULL; | |
479 | } | |
480 | gtk_widget_destroy ( dia ); | |
481 | } | |
482 | ||
483 | /** | |
5092de80 | 484 | * Function called by the entry menu of a TrwLayer |
3e7553ae GB |
485 | */ |
486 | void osm_traces_upload_cb ( gpointer layer_and_vlp[2], guint file_type ) | |
487 | { | |
5092de80 GB |
488 | osm_traces_upload_viktrwlayer(VIK_TRW_LAYER(layer_and_vlp[0]), NULL); |
489 | } | |
490 | ||
491 | /** | |
492 | * Function called by the entry menu of a single track | |
493 | */ | |
ce4bd1cf RN |
494 | // TODO: Fix this dodgy usage of magic 8 ball array sized numbering |
495 | // At least have some common definition somewhere... | |
496 | void osm_traces_upload_track_cb ( gpointer pass_along[8] ) | |
5092de80 | 497 | { |
ce4bd1cf RN |
498 | if ( pass_along[7] ) { |
499 | VikTrack *trk = VIK_TRACK(pass_along[7]); | |
500 | osm_traces_upload_viktrwlayer(VIK_TRW_LAYER(pass_along[0]), trk); | |
501 | } | |
3e7553ae | 502 | } |