/** * datasource_gps_get_descriptor: * * Method to get the descriptor from the widget structure * "Everything is a file" * Could actually be normal file or a serial port */ gchar* datasource_gps_get_descriptor ( gpointer user_data ) { gps_user_data_t *w = (gps_user_data_t *)user_data; #if GTK_CHECK_VERSION (2, 24, 0) gchar *descriptor = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(w->ser_b)); #else gchar *descriptor = gtk_combo_box_get_active_text(GTK_COMBO_BOX(w->ser_b)); #endif a_settings_set_string ( VIK_SETTINGS_GPS_PORT, descriptor ); return descriptor; }
/** * datasource_gps_get_protocol: * * Method to get the communication protocol of the GPS device from the widget structure */ gchar* datasource_gps_get_protocol ( gpointer user_data ) { // Uses the list of supported devices gps_user_data_t *w = (gps_user_data_t *)user_data; last_active = gtk_combo_box_get_active(GTK_COMBO_BOX(w->proto_b)); if (a_babel_device_list) { gchar *protocol = ((BabelDevice*)g_list_nth_data(a_babel_device_list, last_active))->name; a_settings_set_string ( VIK_SETTINGS_GPS_PROTOCOL, protocol ); return protocol; } return NULL; }
static void latest_version_thread ( GtkWindow *window ) { // Need to allow a few redirects, as SF file is often served from different server DownloadMapOptions options = { FALSE, FALSE, NULL, 5, NULL, NULL, NULL }; gchar *filename = a_download_uri_to_tmp_file ( "http://sourceforge.net/projects/viking/files/VERSION", &options ); //gchar *filename = g_strdup ( "VERSION" ); if ( !filename ) { return; } GMappedFile *mf = g_mapped_file_new ( filename, FALSE, NULL ); if ( !mf ) return; gchar *text = g_mapped_file_get_contents ( mf ); gint latest_version = viking_version_to_number ( text ); gint my_version = viking_version_to_number ( VIKING_VERSION ); g_debug ( "The lastest version is: %s", text ); if ( my_version < latest_version ) { new_version_thread_data *nvtd = g_malloc ( sizeof(new_version_thread_data) ); nvtd->window = window; nvtd->version = g_strdup ( text ); gdk_threads_add_idle ( (GSourceFunc) new_version_available_message, nvtd ); } else g_debug ( "Running the lastest version: %s", VIKING_VERSION ); g_mapped_file_unref ( mf ); if ( filename ) { g_remove ( filename ); g_free ( filename ); } // Update last checked time GTimeVal time; g_get_current_time ( &time ); a_settings_set_string ( VIK_SETTINGS_VERSION_CHECKED_DATE, g_time_val_to_iso8601(&time) ); }
static gchar *a_prompt_for_goto_string(VikWindow *vw) { GtkWidget *dialog = NULL; dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL ); gtk_window_set_title(GTK_WINDOW(dialog), _("goto")); GtkWidget *tool_label = gtk_label_new(_("goto provider:")); GtkWidget *tool_list = vik_combo_box_text_new (); GList *current = g_list_first (goto_tools_list); while (current != NULL) { char *label = NULL; VikGotoTool *tool = current->data; label = vik_goto_tool_get_label (tool); vik_combo_box_text_append ( tool_list, label ); current = g_list_next (current); } get_provider (); gtk_combo_box_set_active ( GTK_COMBO_BOX( tool_list ), last_goto_tool ); GtkWidget *goto_label = gtk_label_new(_("Enter address or place name:")); GtkWidget *goto_entry = gtk_entry_new(); if (last_goto_str) gtk_entry_set_text(GTK_ENTRY(goto_entry), last_goto_str); // 'ok' when press return in the entry g_signal_connect_swapped (goto_entry, "activate", G_CALLBACK(a_dialog_response_accept), dialog); gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), tool_label, FALSE, FALSE, 5 ); gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), tool_list, FALSE, FALSE, 5 ); gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), goto_label, FALSE, FALSE, 5 ); gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), goto_entry, FALSE, FALSE, 5 ); gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT ); gtk_widget_show_all(dialog); // Ensure the text field has focus so we can start typing straight away gtk_widget_grab_focus ( goto_entry ); if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) != GTK_RESPONSE_ACCEPT ) { gtk_widget_destroy(dialog); return NULL; } // TODO check if list is empty last_goto_tool = gtk_combo_box_get_active ( GTK_COMBO_BOX(tool_list) ); gchar *provider = vik_goto_tool_get_label ( g_list_nth_data (goto_tools_list, last_goto_tool) ); a_settings_set_string ( VIK_SETTINGS_GOTO_PROVIDER, provider ); gchar *goto_str = g_strdup ( gtk_entry_get_text ( GTK_ENTRY(goto_entry) ) ); gtk_widget_destroy(dialog); if (goto_str[0] != '\0') { if (last_goto_str) g_free(last_goto_str); last_goto_str = g_strdup(goto_str); } return(goto_str); /* goto_str needs to be freed by caller */ }
/** * 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 ); }