if ( wi->creating_new_layer ) {
/* Only create the layer if it actually contains anything useful */
// TODO: create function for this operation to hide detail:
- if ( g_hash_table_size (vik_trw_layer_get_tracks(wi->vtl)) ||
- g_hash_table_size (vik_trw_layer_get_waypoints(wi->vtl)) ||
- g_hash_table_size (vik_trw_layer_get_routes(wi->vtl)) ) {
+ if ( ! vik_trw_layer_is_empty ( wi->vtl ) ) {
vik_layer_post_read ( VIK_LAYER(wi->vtl), wi->w->vvp, TRUE );
- vik_aggregate_layer_add_layer( vik_layers_panel_get_top_layer(wi->w->vlp), VIK_LAYER(wi->vtl));
+ vik_aggregate_layer_add_layer ( vik_layers_panel_get_top_layer(wi->w->vlp), VIK_LAYER(wi->vtl), TRUE );
}
else
gtk_label_set_text ( GTK_LABEL(wi->w->status), _("No data.") );
gtk_dialog_response ( GTK_DIALOG(wi->w->dialog), GTK_RESPONSE_ACCEPT );
}
// Main display update
- if ( wi->vtl )
+ if ( wi->vtl ) {
+ vik_layer_post_read ( VIK_LAYER(wi->vtl), wi->w->vvp, TRUE );
vik_layers_panel_emit_update ( wi->w->vlp );
+ }
} else {
/* cancelled */
if ( wi->creating_new_layer )
g_free ( extra );
g_free ( wi->options );
- if (!result) {
+ if (wi->w->running && !result) {
gdk_threads_enter();
gtk_label_set_text ( GTK_LABEL(wi->w->status), _("Error: acquisition failed.") );
if ( wi->creating_new_layer )
if ( wi->w->running ) {
wi->w->running = FALSE;
}
+ else {
+ g_free ( wi->w );
+ g_free ( wi );
+ wi = NULL;
+ }
g_thread_exit ( NULL );
}
* the other can be NULL.
*/
static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface,
- VikTrwLayer *vtl, VikTrack *track )
+ VikTrwLayer *vtl, VikTrack *track, gpointer userdata, VikDataSourceCleanupFunc cleanup_function )
{
/* for manual dialogs */
GtkWidget *dialog = NULL;
gpointer user_data;
gpointer options = NULL;
+ acq_vik_t avt;
+ avt.vlp = vlp;
+ avt.vvp = vvp;
+ avt.vw = vw;
+ avt.userdata = userdata;
+
/* for UI builder */
gpointer pass_along_data;
VikLayerParamData *paramdatas = NULL;
/*** INIT AND CHECK EXISTENCE ***/
if ( source_interface->init_func )
- user_data = source_interface->init_func();
+ user_data = source_interface->init_func(&avt);
else
user_data = NULL;
pass_along_data = user_data;
w->dialog = dialog;
w->running = TRUE;
status = gtk_label_new (_("Working..."));
- gtk_box_pack_start ( GTK_BOX(GTK_DIALOG(dialog)->vbox), status, FALSE, FALSE, 5 );
+ gtk_box_pack_start ( GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))), status, FALSE, FALSE, 5 );
gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT );
// May not want to see the dialog at all
if ( source_interface->is_thread || source_interface->keep_dialog_open )
if ( source_interface->is_thread ) {
if ( cmd ) {
- g_thread_create((GThreadFunc)get_from_anything, wi, FALSE, NULL );
+#if GLIB_CHECK_VERSION (2, 32, 0)
+ g_thread_try_new ( "get_from_anything", (GThreadFunc)get_from_anything, wi, NULL );
+#else
+ g_thread_create ( (GThreadFunc)get_from_anything, wi, FALSE, NULL );
+#endif
gtk_dialog_run ( GTK_DIALOG(dialog) );
if (w->running) {
- w->running = FALSE;
+ // Cancel and mark for thread to finish
+ w->running = FALSE;
+ // NB Thread will free memory
} else {
if ( cmd_off ) {
/* Turn off */
}
if ( extra_off )
g_free ( extra_off );
+
+ // Thread finished by normal completion - free memory
+ g_free ( w );
+ g_free ( wi );
}
}
else {
// This shouldn't happen...
gtk_label_set_text ( GTK_LABEL(w->status), _("Unable to create command\nAcquire method failed.") );
gtk_dialog_run (GTK_DIALOG (dialog));
- goto end;
}
}
else {
// Actually show it if necessary
if ( wi->w->source_interface->keep_dialog_open )
gtk_dialog_run ( GTK_DIALOG(dialog) );
+
+ g_free ( w );
+ g_free ( wi );
}
- end:
gtk_widget_destroy ( dialog );
- g_free ( w );
- g_free ( wi );
+
+ if ( cleanup_function )
+ cleanup_function ( source_interface );
}
/**
* a_acquire:
+ * @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
+ * @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 ) {
- acquire ( vw, vlp, vvp, source_interface, NULL, NULL );
+void a_acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikDataSourceInterface *source_interface,
+ gpointer userdata, VikDataSourceCleanupFunc cleanup_function )
+{
+ acquire ( vw, vlp, vvp, source_interface, NULL, NULL, userdata, cleanup_function );
}
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 );
+ acquire ( vw, vlp, vvp, iface, vtl, tr, NULL, NULL );
}
static GtkWidget *acquire_build_menu ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp,