static void datasource_gc_get_cmd_string ( datasource_gc_widgets_t *widgets, gchar **cmd, gchar **input_file_type ) { //gchar *safe_string = g_shell_quote ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ) ); gchar *safe_user = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "username")->s ); gchar *safe_pass = g_shell_quote ( a_preferences_get ( VIKING_GC_PARAMS_NAMESPACE "password")->s ); gdouble lat, lon; if ( 2 != sscanf ( gtk_entry_get_text ( GTK_ENTRY(widgets->center_entry) ), "%lf,%lf", &lat, &lon ) ) { g_warning (_("Broken input - using some defaults")); lat = a_vik_get_default_lat(); lon = a_vik_get_default_long(); } // Unix specific shell commands // 1. Remove geocache webpages (maybe be from different location) // 2, Gets upto n geocaches as webpages for the specified user in radius r Miles // 3. Converts webpages into a single waypoint file, ignoring zero location waypoints '-z' // Probably as they are premium member only geocaches and user is only a basic member // Final output is piped into GPSbabel - hence removal of *html is done at beginning of the command sequence *cmd = g_strdup_printf( "rm -f ~/.geo/caches/*html ; %s -P -n%d -r%.1fM -u %s -p %s %.4f %.4f ; %s -z ~/.geo/caches/*html ", GC_PROGRAM1, gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(widgets->num_spin) ), gtk_spin_button_get_value_as_float ( GTK_SPIN_BUTTON(widgets->miles_radius_spin) ), safe_user, safe_pass, lat, lon, GC_PROGRAM2 ); *input_file_type = NULL; //g_free ( safe_string ); g_free ( safe_user ); g_free ( safe_pass ); }
/** * Free after use */ gchar* osm_oauth_sign_url ( const gchar* url, const char *method ) { gchar *signed_url = NULL; const gchar *access_token_key_pref = a_preferences_get(OSM_ACCESS_TOKEN_KEY)->s; const gchar *access_token_secret_pref = a_preferences_get(OSM_ACCESS_TOKEN_SECRET)->s; if ( access_token_key_pref && access_token_secret_pref && strlen(access_token_key_pref) > 1 && strlen(access_token_secret_pref) > 1 ) { signed_url = oauth_sign_url2 ( url, NULL, OA_HMAC, method, viking_consumer_key, viking_consumer_secret, access_token_key_pref, access_token_secret_pref ); } return signed_url; }
void a_mapcache_add ( GdkPixbuf *pixbuf, gint x, gint y, gint z, guint8 type, guint zoom, guint8 alpha, gdouble xshrinkfactor, gdouble yshrinkfactor ) { gchar *key = g_strdup_printf ( HASHKEY_FORMAT_STRING, x, y, z, type, zoom, alpha, xshrinkfactor, yshrinkfactor ); static int tmp = 0; g_mutex_lock(mc_mutex); cache_add(key, pixbuf); // TODO: that should be done on preference change only... max_queue_size = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "mapcache_size")->u * 1024 * 1024; if ( queue_size > max_queue_size ) { gchar *oldkey = list_shift_add_entry ( key ); cache_remove(oldkey); while ( queue_size > max_queue_size && (queue_tail->next != queue_tail) ) { /* make sure there's more than one thing to delete */ oldkey = list_shift (); cache_remove(oldkey); } /* chop off 'start' etc */ } else { list_add_entry ( key ); /* business as usual */ } g_mutex_unlock(mc_mutex); if ( (++tmp == 100 )) { g_print("DEBUG: queue count=%d size=%u\n", queue_count, queue_size ); tmp=0; } }
/** * Auto attempt to read the world file associated with the image used for the georef * Based on simple file name conventions * Only attempted if the preference is on. */ static gboolean maybe_read_world_file ( VikFileEntry *vfe, gpointer user_data ) { if ( a_preferences_get (VIKING_PREFERENCES_IO_NAMESPACE "georef_auto_read_world_file")->b ) { const gchar* filename = vik_file_entry_get_filename(VIK_FILE_ENTRY(vfe)); gdouble values[4]; if ( filename && user_data ) { changeable_widgets *cw = user_data; gboolean upper = g_ascii_isupper (filename[strlen(filename)-1]); gchar* filew = g_strconcat ( filename, (upper ? "W" : "w") , NULL ); if ( world_file_read_file ( filew, values ) == 0 ) { set_widget_values ( cw, values ); } else { if ( strlen(filename) > 3 ) { gchar* file0 = g_strndup ( filename, strlen(filename)-2 ); gchar* file1 = g_strdup_printf ( "%s%c%c", file0, filename[strlen(filename)-1], (upper ? 'W' : 'w') ); if ( world_file_read_file ( file1, values ) == 0 ) { set_widget_values ( cw, values ); } g_free ( file1 ); g_free ( file0 ); } } g_free ( filew ); } } return TRUE; }
void a_mapcache_add ( GdkPixbuf *pixbuf, mapcache_extra_t extra, gint x, gint y, gint z, guint16 type, gint zoom, guint8 alpha, gdouble xshrinkfactor, gdouble yshrinkfactor, const gchar* name ) { guint nn = name ? g_str_hash ( name ) : 0; gchar *key = g_strdup_printf ( HASHKEY_FORMAT_STRING, type, x, y, z, zoom, nn, alpha, xshrinkfactor, yshrinkfactor ); g_mutex_lock(mc_mutex); cache_add(key, pixbuf, extra); // TODO: that should be done on preference change only... max_cache_size = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "mapcache_size")->u * 1024 * 1024; if ( cache_size > max_cache_size ) { if ( queue_tail ) { gchar *oldkey = list_shift_add_entry ( key ); cache_remove(oldkey); while ( cache_size > max_cache_size && (queue_tail->next != queue_tail) ) { /* make sure there's more than one thing to delete */ oldkey = list_shift (); cache_remove(oldkey); } } /* chop off 'start' etc */ } else { list_add_entry ( key ); /* business as usual */ } g_mutex_unlock(mc_mutex); static int tmp = 0; if ( (++tmp == 100 )) { g_debug("DEBUG: cache count=%d size=%u list count=%d\n", g_hash_table_size(cache), cache_size, queue_count ); tmp=0; } }
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 (osm_user != NULL && osm_user[0] != '\0') gtk_entry_set_text(GTK_ENTRY(user_entry), osm_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 (osm_password != NULL && osm_password[0] != '\0') gtk_entry_set_text(GTK_ENTRY(password_entry), osm_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); }
void osm_login_widgets (GtkWidget *user_entry, GtkWidget *password_entry) { if (!user_entry || !password_entry) return; const gchar *default_user = get_default_user(); VikLayerParamData *pref_user = a_preferences_get ( OSM_USERNAME ); VikLayerParamData *pref_password = a_preferences_get ( OSM_PASSWORD ); if (osm_user != NULL && osm_user[0] != '\0') gtk_entry_set_text(GTK_ENTRY(user_entry), osm_user); else if (pref_user && pref_user->s && pref_user->s[0] != '\0') gtk_entry_set_text(GTK_ENTRY(user_entry), pref_user->s); else if (default_user != NULL) gtk_entry_set_text(GTK_ENTRY(user_entry), default_user); if (osm_password != NULL && osm_password[0] != '\0') gtk_entry_set_text(GTK_ENTRY(password_entry), osm_password); else if (pref_password && pref_password->s) gtk_entry_set_text(GTK_ENTRY(password_entry), pref_password->s); /* This is a password -> invisible */ gtk_entry_set_visibility(GTK_ENTRY(password_entry), FALSE); }
/** * a_babel_post_init: * * Initialises babel module. * Mainly check existence of gpsbabel progam * and load all features available in that version. */ void a_babel_post_init () { // Read the current preference const gchar *gpsbabel = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpsbabel")->s; // If setting is still the UNIX default then lookup in the path - otherwise attempt to use the specified value directly. if ( g_strcmp0 ( gpsbabel, "gpsbabel" ) == 0 ) { gpsbabel_loc = g_find_program_in_path( "gpsbabel" ); if ( !gpsbabel_loc ) g_warning( "gpsbabel not found in PATH" ); } else gpsbabel_loc = g_strdup ( gpsbabel ); // Unlikely to package unbuffer on Windows so ATM don't even bother trying // Highly unlikely unbuffer is available on a Windows system otherwise #ifndef WINDOWS unbuffer_loc = g_find_program_in_path( "unbuffer" ); if ( !unbuffer_loc ) g_warning( "unbuffer not found in PATH" ); #endif load_feature (); }
gboolean a_vik_get_use_large_waypoint_icons ( ) { gboolean use_large_waypoint_icons; use_large_waypoint_icons = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "use_large_waypoint_icons")->b; return use_large_waypoint_icons; }
static DownloadResult_t download( const char *hostname, const char *uri, const char *fn, DownloadFileOptions *options, gboolean ftp, void *handle) { FILE *f; int ret; gchar *tmpfilename; gboolean failure = FALSE; CurlDownloadOptions cdo = {0, NULL, NULL}; /* Check file */ if ( g_file_test ( fn, G_FILE_TEST_EXISTS ) == TRUE ) { if (options == NULL || (!options->check_file_server_time && !options->use_etag)) { /* Nothing to do as file already exists and we don't want to check server */ return DOWNLOAD_NOT_REQUIRED; } time_t tile_age = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "download_tile_age")->u; /* Get the modified time of this file */ GStatBuf buf; (void)g_stat ( fn, &buf ); time_t file_time = buf.st_mtime; if ( (time(NULL) - file_time) < tile_age ) { /* File cache is too recent, so return */ return DOWNLOAD_NOT_REQUIRED; } if (options != NULL && options->check_file_server_time) { cdo.time_condition = file_time; } if (options != NULL && options->use_etag) { get_etag(fn, &cdo); } } else { gchar *dir = g_path_get_dirname ( fn ); if ( g_mkdir_with_parents ( dir , 0777 ) != 0) g_warning ("%s: Failed to mkdir %s", __FUNCTION__, dir ); g_free ( dir ); } tmpfilename = g_strdup_printf("%s.tmp", fn); if (!lock_file ( tmpfilename ) ) { g_debug("%s: Couldn't take lock on temporary file \"%s\"\n", __FUNCTION__, tmpfilename); g_free ( tmpfilename ); if (options->use_etag) g_free ( cdo.etag ); return DOWNLOAD_FILE_WRITE_ERROR; } f = g_fopen ( tmpfilename, "w+b" ); /* truncate file and open it */ if ( ! f ) { g_warning("Couldn't open temporary file \"%s\": %s", tmpfilename, g_strerror(errno)); g_free ( tmpfilename ); if (options->use_etag) g_free ( cdo.etag ); return DOWNLOAD_FILE_WRITE_ERROR; } /* Call the backend function */ ret = curl_download_get_url ( hostname, uri, f, options, ftp, &cdo, handle ); DownloadResult_t result = DOWNLOAD_SUCCESS; if (ret != CURL_DOWNLOAD_NO_ERROR && ret != CURL_DOWNLOAD_NO_NEWER_FILE) { g_debug("%s: download failed: curl_download_get_url=%d", __FUNCTION__, ret); failure = TRUE; result = DOWNLOAD_HTTP_ERROR; } if (!failure && options != NULL && options->check_file != NULL && ! options->check_file(f)) { g_debug("%s: file content checking failed", __FUNCTION__); failure = TRUE; result = DOWNLOAD_CONTENT_ERROR; } fclose ( f ); f = NULL; if (failure) { g_warning(_("Download error: %s"), fn); if ( g_remove ( tmpfilename ) != 0 ) g_warning( ("Failed to remove: %s"), tmpfilename); unlock_file ( tmpfilename ); g_free ( tmpfilename ); if ( options != NULL && options->use_etag ) { g_free ( cdo.etag ); g_free ( cdo.new_etag ); } return result; } if (ret == CURL_DOWNLOAD_NO_NEWER_FILE) { (void)g_remove ( tmpfilename ); // update mtime of local copy // Not security critical, thus potential Time of Check Time of Use race condition is not bad // coverity[toctou] if ( g_utime ( fn, NULL ) != 0 ) g_warning ( "%s couldn't set time on: %s", __FUNCTION__, fn ); } else { if ( options != NULL && options->convert_file ) options->convert_file ( tmpfilename ); if ( options != NULL && options->use_etag ) { if ( cdo.new_etag ) { /* server returned an etag value */ set_etag(fn, tmpfilename, &cdo); } } /* move completely-downloaded file to permanent location */ if ( g_rename ( tmpfilename, fn ) ) g_warning ("%s: file rename failed [%s] to [%s]", __FUNCTION__, tmpfilename, fn ); } unlock_file ( tmpfilename ); g_free ( tmpfilename ); if ( options != NULL && options->use_etag ) { g_free ( cdo.etag ); g_free ( cdo.new_etag ); } return DOWNLOAD_SUCCESS; }
/** * Start request for New OSM Access Token */ static void new_access_token_cb ( ) { GtkWindow *parent = GTK_WINDOW(a_vik_window_get_a_window()); const gchar *access_token_key_pref = a_preferences_get(OSM_ACCESS_TOKEN_KEY)->s; const gchar *access_token_secret_pref = a_preferences_get(OSM_ACCESS_TOKEN_SECRET)->s; if ( access_token_key_pref && access_token_secret_pref && strlen(access_token_key_pref) > 1 && strlen(access_token_secret_pref) > 1 ) { // Check to really override existing values... if ( !a_dialog_yes_or_no(parent, _("Do you want to overwrite existing values?"), NULL) ) return; } gchar *request_key = NULL; gchar *request_secret = NULL; // Request gint grt = get_request_tokens ( &request_key, &request_secret ); if ( grt != 0 ) g_warning ( "get_request_tokens() returned %d", grt ); if ( !request_key || !request_secret ) { a_dialog_error_msg ( parent, _("Not able to generate OSM request tokens.") ); return; } // JOSM uses some kind of Out of Bound 'OOB' method which doesn't direct the user to the webpage. // However I'm unclear how this works at a low level // it's possible that liboauth doesn't support this 1.0A feature anyway // Auto authorize if possible... // gboolean authorized = liboauth_authorize_url ( request_key ); // if ( !authorized ) { // msg(); // return; // } // So for now just direct user to OSM website (you will have to enter credentials there & grant permissions) gchar *authorize_url = get_authorize_url ( request_key ); g_debug ( "%s:%s", __FUNCTION__, authorize_url ); if ( authorize_url ) { gtk_show_uri ( gdk_screen_get_default(), authorize_url, GDK_CURRENT_TIME, NULL ); } g_free ( authorize_url ); GtkWidget *dialog = gtk_message_dialog_new ( parent, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, GTK_BUTTONS_OK_CANCEL, _("Waiting for authorization approval.\nEnsure you have granted access at the website before continuing here.")); gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT ); if ( gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_OK ) { gtk_widget_destroy ( dialog ); return; } gtk_widget_destroy ( dialog ); gchar *access_token_key = NULL; gchar *access_token_secret = NULL; gint gnat = get_new_access_tokens ( request_key, request_secret, &access_token_key, &access_token_secret ); if ( gnat != 0 ) g_warning ( "get_new_access_tokens() returned %d", gnat ); if ( !access_token_key || !access_token_key ) { a_dialog_error_msg ( parent, _("No Authorization.") ); return; } // Save the values VikLayerParamData vlp_data; VikLayerParam *pref_key = a_preferences_get_param ( OSM_ACCESS_TOKEN_KEY ); VikLayerParam *pref_secret = a_preferences_get_param ( OSM_ACCESS_TOKEN_SECRET ); if ( !pref_key || !pref_secret ) { g_critical ("%s: preference not found", __FUNCTION__); return; } // Unfortunately since the callback mechanism in preferences only allows a function call with no parameters // we have no way of accessing the dialog to effect any updates, other than closing it a_uibuilder_factory_close ( GTK_RESPONSE_REJECT ); // Note since we are in an event handler already, using GTK_RESPONSE_ACCEPT means this signal // is processed after this current function finishes. // This then in turn means it would save the values from the dialog, // overwriting the values set here :( // The current side effect is that any other preferences the user has modified in the dialog are lost // Now apply the new values vlp_data.s = access_token_key; a_preferences_run_setparam ( vlp_data, pref_key ); vlp_data.s = access_token_secret; a_preferences_run_setparam ( vlp_data, pref_secret ); a_preferences_save_to_file (); g_free ( access_token_key ); g_free ( access_token_secret ); // On success mention can remove username/password if they already exist VikLayerParamData *pref_user = a_preferences_get ( OSM_USERNAME ); VikLayerParamData *pref_pwd = a_preferences_get ( OSM_PASSWORD ); if ( pref_user && pref_pwd && pref_user->s && pref_pwd->s && strlen(pref_user->s) > 1 ) { a_dialog_info_msg ( parent, _("OSM Username and Password preferences are not required anymore. You can now remove them.") ); return; } }
const gchar* a_vik_get_image_viewer ( ) { return a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "image_viewer")->s; }
const gchar* a_vik_get_external_gpx_program_2 ( ) { return a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "external_gpx_2")->s; }
vik_kml_export_units_t a_vik_get_kml_export_units ( ) { vik_kml_export_units_t units; units = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "kml_export_units")->u; return units; }
vik_gpx_export_trk_sort_t a_vik_get_gpx_export_trk_sort ( ) { vik_gpx_export_trk_sort_t sort; sort = a_preferences_get(VIKING_PREFERENCES_IO_NAMESPACE "gpx_export_track_sort")->u; return sort; }
vik_degree_format_t a_vik_get_degree_format ( ) { vik_degree_format_t format; format = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "degree_format")->u; return format; }
/** * a_background_post_init: * * Initialize background feature. */ void a_background_post_init() { // initialize thread pools gint max_threads = 10; /* limit maximum number of threads running at one time */ gint maxt; if ( a_settings_get_integer ( VIK_SETTINGS_BACKGROUND_MAX_THREADS, &maxt ) ) max_threads = maxt; thread_pool_remote = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL ); if ( a_settings_get_integer ( VIK_SETTINGS_BACKGROUND_MAX_THREADS_LOCAL, &maxt ) ) max_threads = maxt; else { guint cpus = util_get_number_of_cpus (); max_threads = cpus > 1 ? cpus-1 : 1; // Don't use all available CPUs! } thread_pool_local = g_thread_pool_new ( (GFunc) thread_helper, NULL, max_threads, FALSE, NULL ); #ifdef HAVE_LIBMAPNIK // implicit use of 'MAPNIK_PREFS_NAMESPACE' to avoid dependency issues guint mapnik_threads = a_preferences_get("mapnik.background_max_threads_local_mapnik")->u; thread_pool_local_mapnik = g_thread_pool_new ( (GFunc) thread_helper, NULL, mapnik_threads, FALSE, NULL ); #endif GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkWidget *scrolled_window; g_debug(__FUNCTION__); /* store & treeview */ bgstore = gtk_list_store_new ( N_COLUMNS, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_POINTER ); bgtreeview = gtk_tree_view_new_with_model ( GTK_TREE_MODEL(bgstore) ); gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (bgtreeview), TRUE); gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (bgtreeview)), GTK_SELECTION_SINGLE); /* add columns */ renderer = gtk_cell_renderer_text_new (); column = gtk_tree_view_column_new_with_attributes ( _("Job"), renderer, "text", TITLE_COLUMN, NULL ); gtk_tree_view_append_column ( GTK_TREE_VIEW(bgtreeview), column ); renderer = gtk_cell_renderer_progress_new (); column = gtk_tree_view_column_new_with_attributes ( _("Progress"), renderer, "value", PROGRESS_COLUMN, NULL ); gtk_tree_view_append_column ( GTK_TREE_VIEW(bgtreeview), column ); /* setup window */ scrolled_window = gtk_scrolled_window_new ( NULL, NULL ); gtk_container_add ( GTK_CONTAINER(scrolled_window), bgtreeview ); gtk_scrolled_window_set_policy ( GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC ); bgwindow = gtk_dialog_new_with_buttons ( "", NULL, 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_DELETE, 1, GTK_STOCK_CLEAR, 2, NULL ); gtk_dialog_set_default_response ( GTK_DIALOG(bgwindow), GTK_RESPONSE_ACCEPT ); GtkWidget *response_w = NULL; #if GTK_CHECK_VERSION (2, 20, 0) response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(bgwindow), GTK_RESPONSE_ACCEPT ); #endif gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(bgwindow))), scrolled_window, TRUE, TRUE, 0 ); gtk_window_set_default_size ( GTK_WINDOW(bgwindow), 400, 400 ); gtk_window_set_title ( GTK_WINDOW(bgwindow), _("Viking Background Jobs") ); if ( response_w ) gtk_widget_grab_focus ( response_w ); /* don't destroy win */ g_signal_connect ( G_OBJECT(bgwindow), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL ); g_signal_connect ( G_OBJECT(bgwindow), "response", G_CALLBACK(bgwindow_response), 0 ); }
vik_units_height_t a_vik_get_units_height ( ) { vik_units_height_t units; units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_height")->u; return units; }
vik_units_speed_t a_vik_get_units_speed ( ) { vik_units_speed_t units; units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_speed")->u; return units; }
vik_units_distance_t a_vik_get_units_distance ( ) { vik_units_distance_t units; units = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "units_distance")->u; return units; }
gdouble a_vik_get_default_long ( ) { gdouble data; data = a_preferences_get(VIKING_PREFERENCES_NAMESPACE "default_longitude")->d; return data; }
/** * Uploading a VikTrwLayer * * @param vtl VikTrwLayer * @param track_name if not null, the name of the track to upload */ static void osm_traces_upload_viktrwlayer ( VikTrwLayer *vtl, const gchar *track_name ) { 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 *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; 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_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:"******"The password used to login\n" "<small>Enter the password you use to login into www.openstreetmap.org.</small>")); name_label = gtk_label_new(_("File's name:")); name_entry = gtk_entry_new(); if (track_name != NULL) name = track_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(dia)->vbox), name_label, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dia)->vbox), 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 = 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_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_widget_set_tooltip_text(GTK_WIDGET(tags_entry), _("The tags associated to the trace")); visibility = GTK_COMBO_BOX(gtk_combo_box_new_text ()); 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); /* 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; /* overwrite authentication info */ 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(visibility)]; info->vtl = VIK_TRW_LAYER(g_object_ref(vtl)); info->track_name = (track_name == NULL) ? NULL : g_strdup(track_name); title = g_strdup_printf(_("Uploading %s to OSM"), info->name); /* launch the thread */ a_background_thread(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 ); }