From: Mark Cave-Ayland Date: Thu, 17 Dec 2009 12:54:04 +0000 (+0000) Subject: Implement proper cleanup if an import fails, and also disable the "Import" button... X-Git-Tag: 1.5.0b1~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=50c2ad069002b7dcb485401de1263cf50510129f;p=postgis Implement proper cleanup if an import fails, and also disable the "Import" button during the import to ensure that multiple import threads can't be launched. git-svn-id: http://svn.osgeo.org/postgis/trunk@5020 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/loader/shp2pgsql-gui.c b/loader/shp2pgsql-gui.c index 79938484a..feeb42314 100644 --- a/loader/shp2pgsql-gui.c +++ b/loader/shp2pgsql-gui.c @@ -588,6 +588,13 @@ pgui_action_import(GtkWidget *widget, gpointer data) * Loop through the items in the shapefile */ + /* Disable the button to prevent multiple imports running at the same time */ + gtk_widget_set_sensitive(widget, FALSE); + + /* Allow GTK events to get a look in */ + while (gtk_events_pending()) + gtk_main_iteration(); + /* Create the shapefile state object */ state = ShpLoaderCreate(config); @@ -598,7 +605,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) pgui_logf("%s", state->message); if (ret == SHPLOADERERR) - return; + goto import_cleanup; } /* If reading the whole shapefile, display its type */ @@ -615,7 +622,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) pgui_logf("%s", state->message); if (ret == SHPLOADERERR) - return; + goto import_cleanup; } /* Send the header to the remote server: if we are in COPY mode then the last @@ -624,7 +631,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) free(header); if (!ret) - return; + goto import_cleanup; /* If we are in COPY (dump format) mode, output the COPY statement and enter COPY mode */ if (state->config->dump_format) @@ -635,7 +642,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) pgui_logf("%s", state->message); if (ret == SHPLOADERERR) - return; + goto import_cleanup; } /* Send the result to the remote server: this should put us in COPY mode */ @@ -643,7 +650,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) free(header); if (!ret) - return; + goto import_cleanup; } /* Main loop: iterate through all of the records and send them to stdout */ @@ -707,7 +714,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) if (state->config->dump_format) { if (! pgui_copy_end(0) ) - return; + goto import_cleanup; } /* Get the footer */ @@ -717,7 +724,7 @@ pgui_action_import(GtkWidget *widget, gpointer data) pgui_logf("%s\n", state->message); if (ret == SHPLOADERERR) - return; + goto import_cleanup; } /* Send the footer to the server */ @@ -731,6 +738,18 @@ pgui_action_import(GtkWidget *widget, gpointer data) ShpLoaderDestroy(state); +import_cleanup: + /* Enable the button once again */ + gtk_widget_set_sensitive(widget, TRUE); + + /* Silly GTK bug means we have to hide and show the button for it to work again! */ + gtk_widget_hide(widget); + gtk_widget_show(widget); + + /* Allow GTK events to get a look in */ + while (gtk_events_pending()) + gtk_main_iteration(); + /* Tidy up */ free(connection_string); free(dest_string);