From 9cc138481bcf668c773d4f92f145393838af5f21 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Mon, 7 Apr 2014 22:21:44 +0100 Subject: [PATCH] Rationalise acquire mode to have more obvious behaviour. --- help/C/viking.xml | 2 +- src/acquire.c | 34 +++++++++++++++++++++++++--------- src/acquire.h | 14 ++++++++++---- src/datasource_file.c | 2 +- src/datasource_gc.c | 2 +- src/datasource_geotag.c | 2 +- src/datasource_gps.c | 2 +- src/datasource_osm.c | 2 +- src/datasource_routing.c | 2 +- src/datasource_url.c | 2 +- src/datasource_wikipedia.c | 2 +- src/viktrwlayer.c | 29 ++++++++++++----------------- src/vikwebtool_datasource.c | 2 +- src/vikwindow.c | 33 +++++++++++++++++---------------- 14 files changed, 74 insertions(+), 56 deletions(-) diff --git a/help/C/viking.xml b/help/C/viking.xml index 41d1240d..e5fe0450 100644 --- a/help/C/viking.xml +++ b/help/C/viking.xml @@ -469,7 +469,7 @@ GPX and KML files may also be appended, but this is exactly the same as the norm Available on the FileAcquire menu and from the layer menu. -If used from the File menu and a TrackWaypoint layer is not currently selected, these methods place the results in a new TrackWaypoint layer. When a TrackWaypoint layer is selected, then using the FileAcquire will put the results into the selected TrackWaypoint layer. +If used from the File menu these methods place the results in a new TrackWaypoint layer. If used from the layer menu these methods place the results in that TrackWaypoint layer. diff --git a/src/acquire.c b/src/acquire.c index aa1da532..06ababf0 100644 --- a/src/acquire.c +++ b/src/acquire.c @@ -212,8 +212,15 @@ static gchar *write_tmp_track ( VikTrack *track ) /* depending on type of filter, often only vtl or track will be given. * the other can be NULL. */ -static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface, - VikTrwLayer *vtl, VikTrack *track, gpointer userdata, VikDataSourceCleanupFunc cleanup_function ) +static void acquire ( VikWindow *vw, + VikLayersPanel *vlp, + VikViewport *vvp, + vik_datasource_mode_t mode, + VikDataSourceInterface *source_interface, + VikTrwLayer *vtl, + VikTrack *track, + gpointer userdata, + VikDataSourceCleanupFunc cleanup_function ) { /* for manual dialogs */ GtkWidget *dialog = NULL; @@ -341,7 +348,7 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD wi->extra = extra; /* usually input data type (?) */ wi->options = options; wi->vtl = vtl; - wi->creating_new_layer = (!vtl); + wi->creating_new_layer = (!vtl); // Default if Auto Layer Management is passed in dialog = gtk_dialog_new_with_buttons ( "", GTK_WINDOW(vw), 0, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL ); gtk_dialog_set_response_sensitive ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE ); @@ -365,14 +372,17 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD } w->user_data = user_data; - if (source_interface->mode == VIK_DATASOURCE_ADDTOLAYER) { + if ( mode == VIK_DATASOURCE_ADDTOLAYER ) { VikLayer *current_selected = vik_layers_panel_get_selected ( w->vlp ); if ( IS_VIK_TRW_LAYER(current_selected) ) { wi->vtl = VIK_TRW_LAYER(current_selected); wi->creating_new_layer = FALSE; } } - else if ( source_interface->mode == VIK_DATASOURCE_MANUAL_LAYER_MANAGEMENT ) { + else if ( mode == VIK_DATASOURCE_CREATENEWLAYER ) { + wi->creating_new_layer = TRUE; + } + else if ( mode == VIK_DATASOURCE_MANUAL_LAYER_MANAGEMENT ) { // Don't create in acquire - as datasource will perform the necessary actions wi->creating_new_layer = FALSE; VikLayer *current_selected = vik_layers_panel_get_selected ( w->vlp ); @@ -447,16 +457,22 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD * @vw: The #VikWindow to work with * @vlp: The #VikLayersPanel in which a #VikTrwLayer layer may be created/appended * @vvp: The #VikViewport defining the current view + * @mode: How layers should be managed * @source_interface: The #VikDataSourceInterface determining how and what actions to take * @userdata: External data to be passed into the #VikDataSourceInterface * @cleanup_function: The function to dispose the #VikDataSourceInterface if necessary * * Process the given VikDataSourceInterface for sources with no input data. */ -void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface, - gpointer userdata, VikDataSourceCleanupFunc cleanup_function ) +void a_acquire ( VikWindow *vw, + VikLayersPanel *vlp, + VikViewport *vvp, + vik_datasource_mode_t mode, + VikDataSourceInterface *source_interface, + gpointer userdata, + VikDataSourceCleanupFunc cleanup_function ) { - acquire ( vw, vlp, vvp, source_interface, NULL, NULL, userdata, cleanup_function ); + acquire ( vw, vlp, vvp, mode, source_interface, NULL, NULL, userdata, cleanup_function ); } static void acquire_trwlayer_callback ( GObject *menuitem, gpointer *pass_along ) @@ -468,7 +484,7 @@ static void acquire_trwlayer_callback ( GObject *menuitem, gpointer *pass_along VikTrwLayer *vtl = pass_along[3]; VikTrack *tr = pass_along[4]; - acquire ( vw, vlp, vvp, iface, vtl, tr, NULL, NULL ); + acquire ( vw, vlp, vvp, iface->mode, iface, vtl, tr, NULL, NULL ); } static GtkWidget *acquire_build_menu ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, diff --git a/src/acquire.h b/src/acquire.h index 731a7bbe..fb22918f 100644 --- a/src/acquire.h +++ b/src/acquire.h @@ -57,8 +57,9 @@ typedef struct { } acq_dialog_widgets_t; typedef enum { - VIK_DATASOURCE_CREATENEWLAYER, - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_CREATENEWLAYER, // Generally Datasources shouldn't use these and let the HCI decide + VIK_DATASOURCE_ADDTOLAYER, // between the create or add to layer options + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_MANUAL_LAYER_MANAGEMENT, } vik_datasource_mode_t; /* TODO: replace track/layer? */ @@ -179,8 +180,13 @@ struct _VikDataSourceInterface { /**********************************/ -void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface, - gpointer userdata, VikDataSourceCleanupFunc cleanup_function ); +void a_acquire ( VikWindow *vw, + VikLayersPanel *vlp, + VikViewport *vvp, + vik_datasource_mode_t mode, + VikDataSourceInterface *source_interface, + gpointer userdata, + VikDataSourceCleanupFunc cleanup_function ); GtkWidget *a_acquire_trwlayer_menu (VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikTrwLayer *vtl); diff --git a/src/datasource_file.c b/src/datasource_file.c index 8feb0c91..57e6bd08 100644 --- a/src/datasource_file.c +++ b/src/datasource_file.c @@ -59,7 +59,7 @@ static void datasource_file_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_file_interface = { N_("Import file with GPSBabel"), N_("Imported file"), - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, TRUE, diff --git a/src/datasource_gc.c b/src/datasource_gc.c index 110f72bf..d8e20937 100644 --- a/src/datasource_gc.c +++ b/src/datasource_gc.c @@ -65,7 +65,7 @@ static gchar *datasource_gc_check_existence (); VikDataSourceInterface vik_datasource_gc_interface = { N_("Download Geocaches"), N_("Geocaching.com Caches"), - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, // Yes automatically update the display - otherwise we won't see the geocache waypoints! TRUE, diff --git a/src/datasource_geotag.c b/src/datasource_geotag.c index 9ec5d35b..7deee1a3 100644 --- a/src/datasource_geotag.c +++ b/src/datasource_geotag.c @@ -50,7 +50,7 @@ static void datasource_geotag_cleanup ( gpointer user_data ); VikDataSourceInterface vik_datasource_geotag_interface = { N_("Create Waypoints from Geotagged Images"), N_("Geotagged Images"), - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, FALSE, // We should be able to see the data on the screen so no point in keeping the dialog open diff --git a/src/datasource_gps.c b/src/datasource_gps.c index c9933b60..1fd2dd3c 100644 --- a/src/datasource_gps.c +++ b/src/datasource_gps.c @@ -53,7 +53,7 @@ static void datasource_gps_off ( gpointer add_widgets_data_not_used, gchar **bab VikDataSourceInterface vik_datasource_gps_interface = { N_("Acquire from GPS"), N_("Acquired from GPS"), - VIK_DATASOURCE_CREATENEWLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, TRUE, diff --git a/src/datasource_osm.c b/src/datasource_osm.c index 05aa4bf9..105c7859 100644 --- a/src/datasource_osm.c +++ b/src/datasource_osm.c @@ -51,7 +51,7 @@ static void datasource_osm_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_osm_interface = { N_("OSM traces"), N_("OSM traces"), - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, TRUE, diff --git a/src/datasource_routing.c b/src/datasource_routing.c index 4faf8beb..5fb2b9d1 100644 --- a/src/datasource_routing.c +++ b/src/datasource_routing.c @@ -52,7 +52,7 @@ static void datasource_routing_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_routing_interface = { N_("Directions"), N_("Directions"), - VIK_DATASOURCE_ADDTOLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, TRUE, diff --git a/src/datasource_url.c b/src/datasource_url.c index de4d0709..bf82fc89 100644 --- a/src/datasource_url.c +++ b/src/datasource_url.c @@ -46,7 +46,7 @@ static void datasource_url_cleanup ( gpointer data ); VikDataSourceInterface vik_datasource_url_interface = { N_("Acquire from URL"), N_("URL"), - VIK_DATASOURCE_CREATENEWLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, TRUE, TRUE, diff --git a/src/datasource_wikipedia.c b/src/datasource_wikipedia.c index 5644080e..f6d86346 100644 --- a/src/datasource_wikipedia.c +++ b/src/datasource_wikipedia.c @@ -31,7 +31,7 @@ static gboolean datasource_wikipedia_process ( VikTrwLayer *vtl, const gchar *cm VikDataSourceInterface vik_datasource_wikipedia_interface = { N_("Create Waypoints from Wikipedia Articles"), N_("Wikipedia Waypoints"), - VIK_DATASOURCE_CREATENEWLAYER, + VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT, VIK_DATASOURCE_INPUTTYPE_NONE, FALSE, FALSE, // Not even using the dialog diff --git a/src/viktrwlayer.c b/src/viktrwlayer.c index e77464ab..b779ac46 100644 --- a/src/viktrwlayer.c +++ b/src/viktrwlayer.c @@ -3607,7 +3607,10 @@ static void trw_layer_acquire ( menu_array_layer values, VikDataSourceInterface VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)); VikViewport *vvp = vik_window_viewport(vw); - a_acquire ( vw, vlp, vvp, datasource, NULL, NULL ); + vik_datasource_mode_t mode = datasource->mode; + if ( mode == VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT ) + mode = VIK_DATASOURCE_ADDTOLAYER; + a_acquire ( vw, vlp, vvp, mode, datasource, NULL, NULL ); } /* @@ -3615,7 +3618,6 @@ static void trw_layer_acquire ( menu_array_layer values, VikDataSourceInterface */ static void trw_layer_acquire_gps_cb ( menu_array_layer values ) { - vik_datasource_gps_interface.mode = VIK_DATASOURCE_ADDTOLAYER; trw_layer_acquire ( values, &vik_datasource_gps_interface ); } @@ -3632,7 +3634,6 @@ static void trw_layer_acquire_routing_cb ( menu_array_layer values ) */ static void trw_layer_acquire_url_cb ( menu_array_layer values ) { - vik_datasource_url_interface.mode = VIK_DATASOURCE_ADDTOLAYER; trw_layer_acquire ( values, &vik_datasource_url_interface ); } @@ -3672,7 +3673,6 @@ static void trw_layer_acquire_geotagged_cb ( menu_array_layer values ) { VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]); - vik_datasource_geotag_interface.mode = VIK_DATASOURCE_ADDTOLAYER; trw_layer_acquire ( values, &vik_datasource_geotag_interface ); // Reverify thumbnails as they may have changed @@ -3681,6 +3681,14 @@ static void trw_layer_acquire_geotagged_cb ( menu_array_layer values ) } #endif +/* + * Acquire into this TRW Layer from any GPS Babel supported file + */ +static void trw_layer_acquire_file_cb ( menu_array_layer values ) +{ + trw_layer_acquire ( values, &vik_datasource_file_interface ); +} + static void trw_layer_gps_upload ( menu_array_layer values ) { menu_array_sublayer data; @@ -3788,19 +3796,6 @@ static void trw_layer_gps_upload_any ( menu_array_sublayer values ) turn_off ); } -/* - * Acquire into this TRW Layer from any GPS Babel supported file - */ -static void trw_layer_acquire_file_cb ( menu_array_layer values ) -{ - VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]); - VikLayersPanel *vlp = VIK_LAYERS_PANEL(values[MA_VLP]); - VikWindow *vw = (VikWindow *)(VIK_GTK_WINDOW_FROM_LAYER(vtl)); - VikViewport *vvp = vik_window_viewport(vw); - - a_acquire ( vw, vlp, vvp, &vik_datasource_file_interface, NULL, NULL ); -} - static void trw_layer_new_wp ( menu_array_layer values ) { VikTrwLayer *vtl = VIK_TRW_LAYER(values[MA_VTL]); diff --git a/src/vikwebtool_datasource.c b/src/vikwebtool_datasource.c index b962f584..1d330bd4 100644 --- a/src/vikwebtool_datasource.c +++ b/src/vikwebtool_datasource.c @@ -208,7 +208,7 @@ static void webtool_datasource_open ( VikExtTool *self, VikWindow *vw ) }; memcpy ( vik_datasource_interface, &data, sizeof(VikDataSourceInterface) ); - a_acquire ( vw, vik_window_layers_panel(vw), vik_window_viewport (vw), vik_datasource_interface, self, cleanup ); + a_acquire ( vw, vik_window_layers_panel(vw), vik_window_viewport (vw), data.mode, vik_datasource_interface, self, cleanup ); } static void vik_webtool_datasource_class_init ( VikWebtoolDatasourceClass *klass ) diff --git a/src/vikwindow.c b/src/vikwindow.c index 6a9bfdd5..d84fa17e 100644 --- a/src/vikwindow.c +++ b/src/vikwindow.c @@ -3151,64 +3151,65 @@ static void file_properties_cb ( GtkAction *a, VikWindow *vw ) g_free ( message ); } +static void my_acquire ( VikWindow *vw, VikDataSourceInterface *datasource ) +{ + vik_datasource_mode_t mode = datasource->mode; + if ( mode == VIK_DATASOURCE_AUTO_LAYER_MANAGEMENT ) + mode = VIK_DATASOURCE_CREATENEWLAYER; + a_acquire ( vw, vw->viking_vlp, vw->viking_vvp, mode, datasource, NULL, NULL ); +} + static void acquire_from_gps ( GtkAction *a, VikWindow *vw ) { - // Via the file menu, acquiring from a GPS makes a new layer - // this has always been the way (not entirely sure if this was the real intention!) - // thus maintain the behaviour ATM. - // Hence explicit setting here (as the value may be changed elsewhere) - vik_datasource_gps_interface.mode = VIK_DATASOURCE_CREATENEWLAYER; - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gps_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_gps_interface ); } static void acquire_from_file ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_file_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_file_interface ); } static void acquire_from_routing ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_routing_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_routing_interface ); } #ifdef VIK_CONFIG_OPENSTREETMAP static void acquire_from_osm ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_osm_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_osm_interface ); } static void acquire_from_my_osm ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_osm_my_traces_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_osm_my_traces_interface ); } #endif #ifdef VIK_CONFIG_GEOCACHES static void acquire_from_gc ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_gc_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_gc_interface ); } #endif #ifdef VIK_CONFIG_GEOTAG static void acquire_from_geotag ( GtkAction *a, VikWindow *vw ) { - vik_datasource_geotag_interface.mode = VIK_DATASOURCE_CREATENEWLAYER; - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_geotag_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_geotag_interface ); } #endif #ifdef VIK_CONFIG_GEONAMES static void acquire_from_wikipedia ( GtkAction *a, VikWindow *vw ) { - a_acquire(vw, vw->viking_vlp, vw->viking_vvp, &vik_datasource_wikipedia_interface, NULL, NULL ); + my_acquire ( vw, &vik_datasource_wikipedia_interface ); } #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 ); + my_acquire ( vw, &vik_datasource_url_interface ); } static void goto_default_location( GtkAction *a, VikWindow *vw) -- 2.39.5