X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/7f95fd54bf0c86359545ec8c955e67fa442d7c7e..d6c110f19fddb9e2ba1cab304a0fafd4a7c3fe46:/src/vikwindow.c diff --git a/src/vikwindow.c b/src/vikwindow.c index d480ef9c..324d0bbd 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -430,7 +430,6 @@ void vik_window_new_window_finish ( VikWindow *vw ) // Maybe add a default map layer if ( a_vik_get_add_default_map_layer () ) { VikMapsLayer *vml = VIK_MAPS_LAYER ( vik_layer_create(VIK_LAYER_MAPS, vw->viking_vvp, NULL, FALSE) ); - vik_maps_layer_pretend_licence_shown ( vml ); vik_layer_rename ( VIK_LAYER(vml), _("Default Map") ); vik_aggregate_layer_add_layer ( vik_layers_panel_get_top_layer(vw->viking_vlp), VIK_LAYER(vml), TRUE ); @@ -461,7 +460,7 @@ static void open_window ( VikWindow *vw, GSList *files ) while ( cur_file ) { // Only open a new window if a viking file gchar *file_name = cur_file->data; - if (vw != NULL && check_file_magic_vik ( file_name ) ) { + if (vw != NULL && vw->filename && check_file_magic_vik ( file_name ) ) { VikWindow *newvw = vik_window_new_window (); if (newvw) vik_window_open_file ( newvw, file_name, TRUE ); @@ -506,6 +505,12 @@ static void window_finalize ( GObject *gob ) window_list = g_slist_remove ( window_list, vw ); gdk_cursor_unref ( vw->busy_cursor ); + int tt; + for (tt = 0; tt < vw->vt->n_tools; tt++ ) + if ( vw->vt->tools[tt].ti.destroy ) + vw->vt->tools[tt].ti.destroy ( vw->vt->tools[tt].state ); + g_free ( vw->vt->tools ); + g_free ( vw->vt ); G_OBJECT_CLASS(parent_class)->finalize(gob); } @@ -644,8 +649,13 @@ static void drag_data_received_cb ( GtkWidget *widget, gint entry_runner = 0; gchar *entry = entries[entry_runner]; while (entry) { - if ( g_strcmp0 ( entry, "" ) ) - filenames = g_slist_append ( filenames, entry ); + if ( g_strcmp0 ( entry, "" ) ) { + // Drag+Drop gives URIs. And so in particular, %20 in place of spaces in filenames + // thus need to convert the text into a plain string + gchar *filename = g_filename_from_uri ( entry, NULL, NULL ); + if ( filename ) + filenames = g_slist_append ( filenames, filename ); + } entry_runner++; entry = entries[entry_runner]; } @@ -2511,7 +2521,7 @@ void vik_window_set_busy_cursor ( VikWindow *vw ) { gdk_window_set_cursor ( gtk_widget_get_window(GTK_WIDGET(vw)), vw->busy_cursor ); // Viewport has a separate cursor - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw->busy_cursor ); + gdk_window_set_cursor ( gtk_widget_get_window(GTK_WIDGET(vw->viking_vvp)), vw->busy_cursor ); // Ensure cursor updated before doing stuff while( gtk_events_pending() ) gtk_main_iteration(); @@ -2521,7 +2531,7 @@ void vik_window_clear_busy_cursor ( VikWindow *vw ) { gdk_window_set_cursor ( gtk_widget_get_window(GTK_WIDGET(vw)), NULL ); // Restore viewport cursor - gdk_window_set_cursor ( GTK_WIDGET(vw->viking_vvp)->window, vw->viewport_cursor ); + gdk_window_set_cursor ( gtk_widget_get_window(GTK_WIDGET(vw->viking_vvp)), vw->viewport_cursor ); } void vik_window_open_file ( VikWindow *vw, const gchar *filename, gboolean change_filename ) @@ -2832,7 +2842,7 @@ static gboolean export_to ( VikWindow *vw, GList *gl, VikFileType_t vft, const g // Show some progress if ( this_success ) { export_count++; - gchar *message = g_strconcat ( _("Exporting to file: "), fn, NULL ); + gchar *message = g_strdup_printf ( _("Exporting to file: %s"), fn ); vik_statusbar_set_message ( vw->viking_vs, VIK_STATUSBAR_INFO, message ); while ( gtk_events_pending() ) gtk_main_iteration (); @@ -2865,25 +2875,22 @@ static void export_to_common ( VikWindow *vw, VikFileType_t vft, const gchar *ex return; } - GtkWidget *dialog = gtk_dialog_new_with_buttons ( _("Export to directory"), + GtkWidget *dialog = gtk_file_chooser_dialog_new ( _("Export to directory"), GTK_WINDOW(vw), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL ); - - GtkWidget *gw = gtk_file_chooser_widget_new ( GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ); - gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), gw, TRUE, TRUE, 0 ); - - // try to make it a nice size - otherwise seems to default to something impractically small - gtk_window_set_default_size ( GTK_WINDOW(dialog), 600, 300 ); + gtk_window_set_transient_for ( GTK_WINDOW(dialog), GTK_WINDOW(vw) ); + gtk_window_set_destroy_with_parent ( GTK_WINDOW(dialog), TRUE ); + gtk_window_set_modal ( GTK_WINDOW(dialog), TRUE ); gtk_widget_show_all ( dialog ); if ( gtk_dialog_run ( GTK_DIALOG(dialog) ) == GTK_RESPONSE_ACCEPT ) { - gchar *dir = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(gw) ); + gchar *dir = gtk_file_chooser_get_filename ( GTK_FILE_CHOOSER(dialog) ); gtk_widget_destroy ( dialog ); if ( dir ) { if ( !export_to ( vw, gl, vft, dir, extension ) ) @@ -2907,6 +2914,10 @@ static void export_to_kml ( GtkAction *a, VikWindow *vw ) export_to_common ( vw, FILE_TYPE_KML, ".kml" ); } +#if !GLIB_CHECK_VERSION(2,26,0) +typedef struct stat GStatBuf; +#endif + static void file_properties_cb ( GtkAction *a, VikWindow *vw ) { gchar *message = NULL; @@ -2997,6 +3008,12 @@ static void acquire_from_wikipedia ( GtkAction *a, VikWindow *vw ) } #endif +static void acquire_from_url ( GtkAction *a, VikWindow *vw ) +{ + vik_datasource_url_interface.mode = VIK_DATASOURCE_CREATENEWLAYER; + a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_url_interface, NULL, NULL ); +} + static void goto_default_location( GtkAction *a, VikWindow *vw) { struct LatLon ll; @@ -3037,12 +3054,14 @@ static void preferences_change_update ( VikWindow *vw, gpointer data ) // Want to update all TrackWaypoint layers GList *layers = vik_layers_panel_get_all_layers_of_type ( vw->viking_vlp, VIK_LAYER_TRW, TRUE ); - GList *iter = g_list_first ( layers ); - while ( iter ) { + if ( !layers ) + return; + + while ( layers ) { // Reset the individual waypoints themselves due to the preferences change - VikTrwLayer *vtl = VIK_TRW_LAYER(VIK_LAYER(layers->data)); + VikTrwLayer *vtl = VIK_TRW_LAYER(layers->data); vik_trw_layer_reset_waypoints ( vtl ); - iter = g_list_next ( iter ); + layers = g_list_next ( layers ); } g_list_free ( layers ); @@ -3079,7 +3098,10 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw ) VIK_LAYER_WIDGET_SPINBUTTON, NULL, NULL, - NULL }, + NULL, + NULL, + NULL, + }, }; VikLayerParam pref_lon[] = { { VIK_LAYER_NUM_TYPES, @@ -3090,7 +3112,10 @@ static void default_location_cb ( GtkAction *a, VikWindow *vw ) VIK_LAYER_WIDGET_SPINBUTTON, NULL, NULL, - NULL }, + NULL, + NULL, + NULL, + }, }; /* Get current center */ @@ -3478,6 +3503,9 @@ static void draw_to_image_file ( VikWindow *vw, gboolean one_image_only ) png_radio = gtk_radio_button_new_with_label ( NULL, _("Save as PNG") ); jpeg_radio = gtk_radio_button_new_with_label_from_widget ( GTK_RADIO_BUTTON(png_radio), _("Save as JPEG") ); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), png_radio, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), jpeg_radio, FALSE, FALSE, 0); + if ( ! vw->draw_image_save_as_png ) gtk_toggle_button_set_active ( GTK_TOGGLE_BUTTON(jpeg_radio), TRUE ); @@ -3489,8 +3517,6 @@ static void draw_to_image_file ( VikWindow *vw, gboolean one_image_only ) gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), win_warning_label, FALSE, FALSE, 0); #endif gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), current_window_button, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), png_radio, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), jpeg_radio, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zoom_label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), zoom_combo, FALSE, FALSE, 0); @@ -3707,6 +3733,7 @@ static GtkActionEntry entries[] = { #ifdef VIK_CONFIG_GEOTAG { "AcquireGeotag", NULL, N_("From Geotagged _Images..."), NULL, N_("Create waypoints from geotagged images"), (GCallback)acquire_from_geotag }, #endif + { "AcquireURL", NULL, N_("From _URL..."), NULL, N_("Get a file from a URL"), (GCallback)acquire_from_url }, #ifdef VIK_CONFIG_GEONAMES { "AcquireWikipedia", NULL, N_("From _Wikipedia Waypoints"), NULL, N_("Create waypoints from Wikipedia items in the current view"), (GCallback)acquire_from_wikipedia }, #endif @@ -3851,6 +3878,8 @@ static void window_create_ui( VikWindow *window ) action.callback = (GCallback)menu_addlayer_cb; gtk_action_group_add_actions(action_group, &action, 1, window); + g_free ( (gchar*)action.label ); + if ( vik_layer_get_interface(i)->tools_count ) { gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Tools/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); gtk_ui_manager_add_ui(uim, mid, "/ui/MainToolbar/ToolItems/", vik_layer_get_interface(i)->name, NULL, GTK_UI_MANAGER_SEPARATOR, FALSE); @@ -3879,10 +3908,12 @@ static void window_create_ui( VikWindow *window ) } GtkActionEntry action_dl; + gchar *layername = g_strdup_printf ( "Layer%s", vik_layer_get_interface(i)->fixed_layer_name ); gtk_ui_manager_add_ui(uim, mid, "/ui/MainMenu/Edit/LayerDefaults", vik_layer_get_interface(i)->name, - g_strdup_printf("Layer%s", vik_layer_get_interface(i)->fixed_layer_name), + layername, GTK_UI_MANAGER_MENUITEM, FALSE); + g_free (layername); // For default layers use action names of the form 'Layer' // This is to avoid clashing with just the layer name used above for the tool actions @@ -3893,6 +3924,8 @@ static void window_create_ui( VikWindow *window ) action_dl.tooltip = NULL; action_dl.callback = (GCallback)layer_defaults_cb; gtk_action_group_add_actions(action_group, &action_dl, 1, window); + g_free ( (gchar*)action_dl.name ); + g_free ( (gchar*)action_dl.label ); } g_object_unref (icon_factory);