#define VIKING_OSM_TRACES_PARAMS_GROUP_KEY "osm_traces"
#define VIKING_OSM_TRACES_PARAMS_NAMESPACE "osm_traces."
+#define VIK_SETTINGS_OSM_TRACE_VIS "osm_trace_visibility"
+static gint last_active = -1;
+
/**
* Login to use for OSM uploading.
*/
} OsmTracesInfo;
static VikLayerParam prefs[] = {
- { VIKING_OSM_TRACES_PARAMS_NAMESPACE "username", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM username:"), VIK_LAYER_WIDGET_ENTRY },
- { VIKING_OSM_TRACES_PARAMS_NAMESPACE "password", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM password:"), VIK_LAYER_WIDGET_PASSWORD },
+ { VIK_LAYER_NUM_TYPES, VIKING_OSM_TRACES_PARAMS_NAMESPACE "username", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM username:"), VIK_LAYER_WIDGET_ENTRY, NULL, NULL, NULL },
+ { VIK_LAYER_NUM_TYPES, VIKING_OSM_TRACES_PARAMS_NAMESPACE "password", VIK_LAYER_PARAM_STRING, VIK_LAYER_GROUP_NONE, N_("OSM password:"), VIK_LAYER_WIDGET_PASSWORD, NULL, NULL, NULL },
};
/**
return default_user;
}
-static void set_login(const gchar *user_, const gchar *password_)
+void osm_set_login(const gchar *user_, const gchar *password_)
{
/* Allocate mutex */
if (login_mutex == NULL)
g_mutex_unlock(login_mutex);
}
-static gchar *get_login()
+gchar *osm_get_login()
{
gchar *user_pass = NULL;
g_mutex_lock(login_mutex);
char *base_url = "http://www.openstreetmap.org/api/0.6/gpx/create";
- gchar *user_pass = get_login();
+ gchar *user_pass = osm_get_login();
gint result = 0; // Default to it worked!
{
/* Due to OSM limits, we have to enforce ele and time fields
also don't upload invisible tracks */
- static GpxWritingOptions options = { TRUE, TRUE, FALSE };
+ static GpxWritingOptions options = { TRUE, TRUE, FALSE, FALSE };
FILE *file = NULL;
gchar *filename = NULL;
int fd;
else {
msg = g_strdup_printf ( "%s : %s %d (@%s)", _("FAILED TO UPLOAD DATA TO OSM"), _("HTTP response code"), ans, timestr );
}
- // From the background so should use the signalling method to update display:
- // TODO: This only works with statically assigned strings ATM
- vik_window_signal_statusbar_update ( (VikWindow*)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl), msg, VIK_STATUSBAR_INFO );
- // Thus can't free the memory yet...
- // Luckily OSM traces isn't heavily used so this is not a significant memory leak
- //g_free (msg);
- // But this is better than potentially crashing from multi thread GUI updates
+ vik_window_statusbar_update ( (VikWindow*)VIK_GTK_WINDOW_FROM_LAYER(oti->vtl), msg, VIK_STATUSBAR_INFO );
+ g_free (msg);
}
/* Removing temporary file */
ret = g_unlink(filename);
}
}
+/**
+ *
+ */
+void osm_login_widgets (GtkWidget *user_entry, GtkWidget *password_entry)
+{
+ if (!user_entry || !password_entry)
+ return;
+
+ const gchar *default_user = get_default_user();
+ const gchar *pref_user = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "username")->s;
+ const gchar *pref_password = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "password")->s;
+
+ if (user != NULL && user[0] != '\0')
+ gtk_entry_set_text(GTK_ENTRY(user_entry), user);
+ else if (pref_user != NULL && pref_user[0] != '\0')
+ gtk_entry_set_text(GTK_ENTRY(user_entry), pref_user);
+ else if (default_user != NULL)
+ gtk_entry_set_text(GTK_ENTRY(user_entry), default_user);
+
+ if (password != NULL && password[0] != '\0')
+ gtk_entry_set_text(GTK_ENTRY(password_entry), password);
+ else if (pref_password != NULL)
+ gtk_entry_set_text(GTK_ENTRY(password_entry), pref_password);
+ /* This is a password -> invisible */
+ gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE);
+}
+
/**
* Uploading a VikTrwLayer
*
GTK_RESPONSE_ACCEPT,
NULL);
- const gchar *default_user = get_default_user();
- const gchar *pref_user = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "username")->s;
- const gchar *pref_password = a_preferences_get(VIKING_OSM_TRACES_PARAMS_NAMESPACE "password")->s;
const gchar *name = NULL;
GtkWidget *user_label, *user_entry;
GtkWidget *password_label, *password_entry;
GtkWidget *name_label, *name_entry;
GtkWidget *description_label, *description_entry;
GtkWidget *tags_label, *tags_entry;
- GtkComboBox *visibility;
+ GtkWidget *visibility;
const OsmTraceVis_t *vis_t;
user_label = gtk_label_new(_("Email:"));
user_entry = gtk_entry_new();
- if (user != NULL && user[0] != '\0')
- gtk_entry_set_text(GTK_ENTRY(user_entry), user);
- else if (pref_user != NULL && pref_user[0] != '\0')
- gtk_entry_set_text(GTK_ENTRY(user_entry), pref_user);
- else if (default_user != NULL)
- gtk_entry_set_text(GTK_ENTRY(user_entry), default_user);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), user_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), user_entry, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), user_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), user_entry, FALSE, FALSE, 0);
gtk_widget_set_tooltip_markup(GTK_WIDGET(user_entry),
_("The email used as login\n"
"<small>Enter the email you use to login into www.openstreetmap.org.</small>"));
password_label = gtk_label_new(_("Password:"));
password_entry = gtk_entry_new();
- if (password != NULL && password[0] != '\0')
- gtk_entry_set_text(GTK_ENTRY(password_entry), password);
- else if (pref_password != NULL)
- gtk_entry_set_text(GTK_ENTRY(password_entry), pref_password);
- /* This is a password -> invisible */
- gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), password_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), password_entry, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), password_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), password_entry, FALSE, FALSE, 0);
gtk_widget_set_tooltip_markup(GTK_WIDGET(password_entry),
_("The password used to login\n"
"<small>Enter the password you use to login into www.openstreetmap.org.</small>"));
+ osm_login_widgets ( user_entry, password_entry );
+
name_label = gtk_label_new(_("File's name:"));
name_entry = gtk_entry_new();
if (trk != NULL)
else
name = vik_layer_get_name(VIK_LAYER(vtl));
gtk_entry_set_text(GTK_ENTRY(name_entry), name);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), name_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), name_entry, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), name_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), name_entry, FALSE, FALSE, 0);
gtk_widget_set_tooltip_markup(GTK_WIDGET(name_entry),
_("The name of the file on OSM\n"
"<small>This is the name of the file created on the server."
description_label = gtk_label_new(_("Description:"));
description_entry = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), description_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), description_entry, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), description_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), description_entry, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text(GTK_WIDGET(description_entry),
_("The description of the trace"));
tags_label = gtk_label_new(_("Tags:"));
tags_entry = gtk_entry_new();
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), tags_label, FALSE, FALSE, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), tags_entry, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), tags_label, FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), tags_entry, FALSE, FALSE, 0);
gtk_widget_set_tooltip_text(GTK_WIDGET(tags_entry),
_("The tags associated to the trace"));
- visibility = GTK_COMBO_BOX(gtk_combo_box_new_text ());
+ visibility = vik_combo_box_text_new();
for (vis_t = OsmTraceVis; vis_t->combostr != NULL; vis_t++)
- gtk_combo_box_append_text(visibility, vis_t->combostr);
- /* Set identifiable by default */
- gtk_combo_box_set_active(visibility, 0);
- gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), GTK_WIDGET(visibility), FALSE, FALSE, 0);
+ vik_combo_box_text_append (visibility, vis_t->combostr);
+
+ // Set identifiable by default or use the settings for the value
+ if ( last_active < 0 ) {
+ gint find_entry = -1;
+ gint wanted_entry = -1;
+ gchar *vis = NULL;
+ if ( a_settings_get_string ( VIK_SETTINGS_OSM_TRACE_VIS, &vis ) ) {
+ // Use setting
+ if ( vis ) {
+ for (vis_t = OsmTraceVis; vis_t->apistr != NULL; vis_t++) {
+ find_entry++;
+ if (!strcmp(vis, vis_t->apistr)) {
+ wanted_entry = find_entry;
+ }
+ }
+ }
+ // If not found set it to the first entry, otherwise use the entry
+ last_active = ( wanted_entry < 0 ) ? 0 : wanted_entry;
+ }
+ else
+ last_active = 0;
+ }
+ gtk_combo_box_set_active(GTK_COMBO_BOX(visibility), last_active);
+ gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), GTK_WIDGET(visibility), FALSE, FALSE, 0);
/* User should think about it first... */
gtk_dialog_set_default_response ( GTK_DIALOG(dia), GTK_RESPONSE_REJECT );
gchar *title = NULL;
/* overwrite authentication info */
- set_login(gtk_entry_get_text(GTK_ENTRY(user_entry)),
- gtk_entry_get_text(GTK_ENTRY(password_entry)));
+ osm_set_login(gtk_entry_get_text(GTK_ENTRY(user_entry)),
+ gtk_entry_get_text(GTK_ENTRY(password_entry)));
/* Storing data for the future thread */
OsmTracesInfo *info = g_malloc(sizeof(OsmTracesInfo));
info->description = g_strdup(gtk_entry_get_text(GTK_ENTRY(description_entry)));
/* TODO Normalize tags: they will be used as URL part */
info->tags = g_strdup(gtk_entry_get_text(GTK_ENTRY(tags_entry)));
- info->vistype = &OsmTraceVis[gtk_combo_box_get_active(visibility)];
+ info->vistype = &OsmTraceVis[gtk_combo_box_get_active(GTK_COMBO_BOX(visibility))];
info->vtl = VIK_TRW_LAYER(g_object_ref(vtl));
info->trk = trk;
+ // Save visibility value for default reuse
+ last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(visibility));
+ a_settings_set_string ( VIK_SETTINGS_OSM_TRACE_VIS, OsmTraceVis[last_active].apistr );
+
title = g_strdup_printf(_("Uploading %s to OSM"), info->name);
/* launch the thread */