/** * vu_check_latest_version: * @window: Somewhere where we may need use the display to inform the user about the version status * * Periodically checks the released latest VERSION file on the website to compare with the running version * */ void vu_check_latest_version ( GtkWindow *window ) { if ( ! a_vik_get_check_version () ) return; gboolean do_check = FALSE; gint check_period; if ( ! a_settings_get_integer ( VIK_SETTINGS_VERSION_CHECK_PERIOD, &check_period ) ) { check_period = 14; } // Get last checked date... GDate *gdate_last = g_date_new(); GDate *gdate_now = g_date_new(); GTimeVal time_last; gchar *last_checked_date = NULL; // When no previous date available - set to do the version check if ( a_settings_get_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, &last_checked_date) ) { if ( g_time_val_from_iso8601 ( last_checked_date, &time_last ) ) { g_date_set_time_val ( gdate_last, &time_last ); } else do_check = TRUE; } else do_check = TRUE; GTimeVal time_now; g_get_current_time ( &time_now ); g_date_set_time_val ( gdate_now, &time_now ); if ( ! do_check ) { // Dates available so do the comparison g_date_add_days ( gdate_last, check_period ); if ( g_date_compare ( gdate_last, gdate_now ) < 0 ) do_check = TRUE; } g_date_free ( gdate_last ); g_date_free ( gdate_now ); if ( do_check ) { #if GLIB_CHECK_VERSION (2, 32, 0) g_thread_try_new ( "latest_version_thread", (GThreadFunc)latest_version_thread, window, NULL ); #else g_thread_create ( (GThreadFunc)latest_version_thread, window, FALSE, NULL ); #endif } }
static void datasource_url_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ) { datasource_url_widgets_t *widgets = (datasource_url_widgets_t *)user_data; GtkWidget *label = gtk_label_new (_("URL:")); widgets->url = ui_entry_new ( NULL, GTK_ENTRY_ICON_SECONDARY ); // 'ok' when press return in the entry g_signal_connect_swapped ( widgets->url, "activate", G_CALLBACK(a_dialog_response_accept), dialog ); GtkWidget *type_label = gtk_label_new (_("File type:")); if ( last_type < 0 ) { find_entry = -1; wanted_entry = -1; gchar *type = NULL; if ( a_settings_get_string ( VIK_SETTINGS_URL_FILE_DL_TYPE, &type ) ) { // Use setting if ( type ) g_list_foreach (a_babel_file_list, find_type, type); } else { // Default to GPX if possible g_list_foreach (a_babel_file_list, find_type, "gpx"); } g_free ( type ); // If not found set it to the first entry, otherwise use the entry last_type = ( wanted_entry < 0 ) ? 0 : wanted_entry; } if ( a_babel_available() ) { widgets->type = vik_combo_box_text_new (); g_list_foreach (a_babel_file_list, fill_combo_box, widgets->type); gtk_combo_box_set_active (GTK_COMBO_BOX (widgets->type), last_type); } else { // Only GPX (not using GPSbabel) widgets->type = gtk_label_new (_("GPX")); } /* Packing all widgets */ GtkBox *box = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))); gtk_box_pack_start ( box, label, FALSE, FALSE, 5 ); gtk_box_pack_start ( box, widgets->url, FALSE, FALSE, 5 ); gtk_box_pack_start ( box, type_label, FALSE, FALSE, 5 ); gtk_box_pack_start ( box, widgets->type, FALSE, FALSE, 5 ); gtk_widget_show_all(dialog); }
/* This should to be called from main() to make sure thread safe */ void curl_download_init() { curl_global_init(CURL_GLOBAL_ALL); curl_download_user_agent = g_strdup_printf ("%s/%s %s", PACKAGE, VERSION, curl_version()); #ifdef CURL_NO_SSL_VERIFYPEER curl_ssl_verifypeer = 0; #endif gboolean tmp; if ( a_settings_get_boolean ( "curl_ssl_verifypeer", &tmp ) ) curl_ssl_verifypeer = tmp; gchar *str = NULL; if ( a_settings_get_string ( "curl_cainfo", &str ) ) { curl_cainfo = g_strdup ( str ); g_free ( str ); } }
/** * Setup last_goto_tool value */ static void get_provider () { // Use setting for the provider if available if ( last_goto_tool < 0 ) { find_entry = -1; wanted_entry = -1; gchar *provider = NULL; if ( a_settings_get_string ( VIK_SETTINGS_GOTO_PROVIDER, &provider ) ) { // Use setting if ( provider ) g_list_foreach (goto_tools_list, find_provider, provider); // If not found set it to the first entry, otherwise use the entry last_goto_tool = ( wanted_entry < 0 ) ? 0 : wanted_entry; } else last_goto_tool = 0; } }
/** * Uploading a VikTrwLayer * * @param vtl VikTrwLayer * @param trk if not null, the track to upload */ void osm_traces_upload_viktrwlayer ( VikTrwLayer *vtl, VikTrack *trk ) { GtkWidget *dia = gtk_dialog_new_with_buttons (_("OSM upload"), VIK_GTK_WINDOW_FROM_LAYER(vtl), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); const gchar *name = NULL; GtkWidget *user_label, *user_entry = NULL; GtkWidget *password_label, *password_entry = NULL; GtkWidget *name_label, *name_entry; GtkWidget *description_label, *description_entry; GtkWidget *tags_label, *tags_entry; GtkWidget *visibility; GtkWidget *anonymize_checkbutton = NULL; const OsmTraceVis_t *vis_t; if ( osm_use_basic_auth() ) { user_label = gtk_label_new(_("Email/username:"******"The email/username used as login\n" "<small>Enter the email/username you use to login into www.openstreetmap.org.</small>")); password_label = gtk_label_new(_("Password:"******"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 = ui_entry_new ( NULL, GTK_ENTRY_ICON_SECONDARY ); if (trk != NULL) name = trk->name; 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_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." "This is not the name of the local file.</small>")); description_label = gtk_label_new(_("Description:")); description_entry = ui_entry_new ( NULL, GTK_ENTRY_ICON_SECONDARY ); const gchar *description = NULL; if (trk != NULL) description = trk->description; else { VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl); description = md ? md->description : NULL; } if (description) gtk_entry_set_text(GTK_ENTRY(description_entry), description); 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")); if (trk != NULL) { GtkWidget *label = gtk_label_new(_("Anonymize Times:")); anonymize_checkbutton = gtk_check_button_new (); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), label, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dia))), anonymize_checkbutton, FALSE, FALSE, 0); gtk_widget_set_tooltip_text(GTK_WIDGET(anonymize_checkbutton), _("Anonymize times of the trace.\n" "<small>You may choose to make the trace identifiable, yet mask the actual real time values</small>")); } tags_label = gtk_label_new(_("Tags:")); tags_entry = ui_entry_new ( NULL, GTK_ENTRY_ICON_SECONDARY ); VikTRWMetadata *md = vik_trw_layer_get_metadata (vtl); if (md->keywords) gtk_entry_set_text(GTK_ENTRY(tags_entry), md->keywords); 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 = vik_combo_box_text_new(); for (vis_t = OsmTraceVis; vis_t->combostr != NULL; vis_t++) 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; } } } g_free ( vis ); // 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 ); gtk_widget_show_all ( dia ); gtk_widget_grab_focus ( description_entry ); if ( gtk_dialog_run ( GTK_DIALOG(dia) ) == GTK_RESPONSE_ACCEPT ) { gchar *title = NULL; if ( osm_use_basic_auth() ) { /* overwrite authentication info */ 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->name = g_strdup(gtk_entry_get_text(GTK_ENTRY(name_entry))); 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(GTK_COMBO_BOX(visibility))]; info->vtl = VIK_TRW_LAYER(g_object_ref(vtl)); info->trk = trk; if (trk != NULL && anonymize_checkbutton != NULL ) info->anonymize_times = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(anonymize_checkbutton)); else info->anonymize_times = FALSE; // 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 a_background_thread( BACKGROUND_POOL_REMOTE, VIK_GTK_WINDOW_FROM_LAYER(vtl), /* parent window */ title, /* description string */ (vik_thr_func) osm_traces_upload_thread, /* function to call within thread */ info, /* pass along data */ (vik_thr_free_func) oti_free, /* function to free pass along data */ (vik_thr_free_func) NULL, 1 ); g_free ( title ); title = NULL; } gtk_widget_destroy ( dia ); }
/* * Upload a file * returns a basic status: * < 0 : curl error * == 0 : OK * > 0 : HTTP error * 1001 : URL signing error */ static gint osm_traces_upload_file(const char *user, const char *password, const char *file, const char *filename, const char *description, const char *tags, const OsmTraceVis_t *vistype) { CURL *curl; CURLcode res; char curl_error_buffer[CURL_ERROR_SIZE]; struct curl_slist *headers = NULL; struct curl_httppost *post=NULL; struct curl_httppost *last=NULL; gchar *trace_url = NULL; if ( !a_settings_get_string ( VIK_SETTINGS_OSM_TRACE_URL, &trace_url ) ) trace_url = g_strdup ( OSM_GPX_UPLOAD_URL ); gchar *user_pass = osm_get_login(); #ifdef HAVE_OAUTH_H char *base_url = osm_oauth_sign_url ( trace_url, "POST" ); if ( !base_url ) { g_free ( trace_url ); return 1001; } #else char *base_url = trace_url; #endif gint result = 0; // Default to it worked! g_debug("%s: %s %s %s %s %s %s %s", __FUNCTION__, base_url, user, password, file, filename, description, tags); /* Init CURL */ curl = curl_easy_init(); /* Filling the form */ curl_formadd(&post, &last, CURLFORM_COPYNAME, "description", CURLFORM_COPYCONTENTS, description, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "tags", CURLFORM_COPYCONTENTS, tags, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "visibility", CURLFORM_COPYCONTENTS, vistype->apistr, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "file", CURLFORM_FILE, file, CURLFORM_FILENAME, filename, CURLFORM_CONTENTTYPE, "text/xml", CURLFORM_END); /* Prepare request */ /* As explained in http://wiki.openstreetmap.org/index.php/User:LA2 */ /* Expect: header seems to produce incompatibilites between curl and httpd */ headers = curl_slist_append(headers, "Expect: "); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPPOST, post); curl_easy_setopt(curl, CURLOPT_URL, base_url); #ifndef HAVE_OAUTH_H curl_easy_setopt(curl, CURLOPT_USERPWD, user_pass); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); #else if ( osm_use_basic_auth() ) { curl_easy_setopt(curl, CURLOPT_USERPWD, user_pass); curl_easy_setopt(curl, CURLOPT_HTTPAUTH, CURLAUTH_ANY); } #endif curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, curl_error_buffer); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 3L); if (vik_verbose) curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 ); /* Execute request */ res = curl_easy_perform(curl); if (res == CURLE_OK) { long code; res = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &code); if (res == CURLE_OK) { g_debug("received valid curl response: %ld", code); if (code != 200) { g_warning(_("failed to upload data: HTTP response is %ld"), code); result = code; } } else { g_critical(_("curl_easy_getinfo failed: %d"), res); result = -1; } } else { g_warning(_("curl request failed: %s"), curl_error_buffer); result = -2; } /* Memory */ g_free(base_url); g_free(user_pass); user_pass = NULL; g_free(base_url); curl_formfree(post); curl_easy_cleanup(curl); return result; }
static void datasource_gps_add_setup_widgets ( GtkWidget *dialog, VikViewport *vvp, gpointer user_data ) { gps_user_data_t *w = (gps_user_data_t *)user_data; GtkTable *box, *data_type_box; w->proto_l = gtk_label_new (_("GPS Protocol:")); w->proto_b = vik_combo_box_text_new (); g_list_foreach (a_babel_device_list, append_element, w->proto_b); if ( last_active < 0 ) { find_entry = -1; wanted_entry = -1; gchar *protocol = NULL; if ( a_settings_get_string ( VIK_SETTINGS_GPS_PROTOCOL, &protocol ) ) { // Use setting if ( protocol ) g_list_foreach (a_babel_device_list, find_protocol, protocol); } else { // Attempt to maintain default to Garmin devices (assumed most popular/numerous device) g_list_foreach (a_babel_device_list, find_protocol, "garmin"); } // If not found set it to the first entry, otherwise use the entry last_active = ( wanted_entry < 0 ) ? 0 : wanted_entry; } gtk_combo_box_set_active (GTK_COMBO_BOX(w->proto_b), last_active); g_object_ref(w->proto_b); w->ser_l = gtk_label_new (_("Serial Port:")); #if GTK_CHECK_VERSION (2, 24, 0) w->ser_b = gtk_combo_box_text_new_with_entry (); #else w->ser_b = gtk_combo_box_entry_new_text (); #endif // Value from the settings is promoted to the top gchar *gps_port = NULL; if ( a_settings_get_string ( VIK_SETTINGS_GPS_PORT, &gps_port ) ) { // Use setting if available if ( gps_port ) { #ifndef WINDOWS if ( !strncmp (gps_port, "/dev/tty", 6) ) { if (g_access (gps_port, R_OK) == 0) { vik_combo_box_text_append (w->ser_b, gps_port); } } else #endif vik_combo_box_text_append (w->ser_b, gps_port); } } // Note avoid appending the port selected from the settings #ifdef WINDOWS if ( gps_port && strcmp (gps_port, "com1") ) vik_combo_box_text_append (w->ser_b, "com1"); #else /* Here just try to see if the device is available which gets passed onto gpsbabel List USB devices first as these will generally only be present if autogenerated by udev or similar User is still able to set their own free text entry */ if ( gps_port && strcmp (gps_port, "/dev/ttyUSB0") ) if (g_access ("/dev/ttyUSB0", R_OK) == 0) vik_combo_box_text_append (w->ser_b, "/dev/ttyUSB0"); if ( gps_port && strcmp (gps_port, "/dev/ttyUSB1") ) if (g_access ("/dev/ttyUSB1", R_OK) == 0) vik_combo_box_text_append (w->ser_b, "/dev/ttyUSB1"); if ( gps_port && strcmp (gps_port, "/dev/ttyS0") ) if (g_access ("/dev/ttyS0", R_OK) == 0) vik_combo_box_text_append (w->ser_b, "/dev/ttyS0"); if ( gps_port && strcmp (gps_port, "/dev/ttyS1") ) if (g_access ("/dev/ttyS1", R_OK) == 0) vik_combo_box_text_append (w->ser_b, "/dev/ttyS1"); #endif if ( gps_port && strcmp (gps_port, "usb:") ) vik_combo_box_text_append (w->ser_b, "usb:"); gtk_combo_box_set_active (GTK_COMBO_BOX(w->ser_b), 0); g_object_ref(w->ser_b); w->off_request_l = gtk_label_new (_("Turn Off After Transfer\n(Garmin/NAViLink Only)")); w->off_request_b = GTK_CHECK_BUTTON ( gtk_check_button_new () ); gboolean power_off; if ( ! a_settings_get_boolean ( VIK_SETTINGS_GPS_POWER_OFF, &power_off ) ) power_off = FALSE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w->off_request_b), power_off); w->get_tracks_l = gtk_label_new (_("Tracks:")); w->get_tracks_b = GTK_CHECK_BUTTON ( gtk_check_button_new () ); gboolean get_tracks; if ( ! a_settings_get_boolean ( VIK_SETTINGS_GPS_GET_TRACKS, &get_tracks ) ) get_tracks = TRUE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w->get_tracks_b), get_tracks); w->get_routes_l = gtk_label_new (_("Routes:")); w->get_routes_b = GTK_CHECK_BUTTON ( gtk_check_button_new () ); gboolean get_routes; if ( ! a_settings_get_boolean ( VIK_SETTINGS_GPS_GET_ROUTES, &get_routes ) ) get_routes = FALSE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w->get_routes_b), get_routes); w->get_waypoints_l = gtk_label_new (_("Waypoints:")); w->get_waypoints_b = GTK_CHECK_BUTTON ( gtk_check_button_new () ); gboolean get_waypoints; if ( ! a_settings_get_boolean ( VIK_SETTINGS_GPS_GET_WAYPOINTS, &get_waypoints ) ) get_waypoints = TRUE; gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(w->get_waypoints_b), get_waypoints); box = GTK_TABLE(gtk_table_new(2, 4, FALSE)); data_type_box = GTK_TABLE(gtk_table_new(4, 1, FALSE)); gtk_table_attach_defaults(box, GTK_WIDGET(w->proto_l), 0, 1, 0, 1); gtk_table_attach_defaults(box, GTK_WIDGET(w->proto_b), 1, 2, 0, 1); gtk_table_attach_defaults(box, GTK_WIDGET(w->ser_l), 0, 1, 1, 2); gtk_table_attach_defaults(box, GTK_WIDGET(w->ser_b), 1, 2, 1, 2); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_tracks_l), 0, 1, 0, 1); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_tracks_b), 1, 2, 0, 1); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_routes_l), 2, 3, 0, 1); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_routes_b), 3, 4, 0, 1); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_waypoints_l), 4, 5, 0, 1); gtk_table_attach_defaults(data_type_box, GTK_WIDGET(w->get_waypoints_b), 5, 6, 0, 1); gtk_table_attach_defaults(box, GTK_WIDGET(data_type_box), 0, 2, 2, 3); gtk_table_attach_defaults(box, GTK_WIDGET(w->off_request_l), 0, 1, 3, 4); gtk_table_attach_defaults(box, GTK_WIDGET(w->off_request_b), 1, 3, 3, 4); gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), GTK_WIDGET(box), FALSE, FALSE, 5 ); gtk_widget_show_all ( dialog ); }