PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void pgui_action_export ( GtkWidget *  widget,
gpointer  data 
)
static

Definition at line 1765 of file shp2pgsql-gui.c.

References _, shp_dumper_state::config, shp_dumper_config::conn, conn, connection_test(), dialog_folderchooser, dialog_progress, EXPORT_POINTER_COLUMN, export_table_list_store, FALSE, is_running, label_progress, lw_asprintf(), shp_dumper_state::message, shp_dumper_state::outshptype, shp_dumper_state::pgis_major_version, pgui_logf(), pgui_raise_error_dialogue(), pgui_seterr(), progress, shp_dumper_config::schema, shapetypename(), shp_dumper_config::shp_file, ShpDumperCloseTable(), ShpDumperConnectDatabase(), ShpDumperCreate(), ShpDumperDestroy(), SHPDUMPERERR, ShpDumperGetRecordCount(), SHPDUMPEROK, ShpDumperOpenTable(), ShpLoaderGenerateShapeRow(), shp_dumper_config::table, TRUE, update_conn_ui_from_conn_config(), and window_conn.

Referenced by pgui_create_main_window().

1766 {
1767  SHPDUMPERCONFIG *dumper_table_config;
1768  SHPDUMPERSTATE *state;
1769  gint is_valid;
1770  gpointer gptr;
1771  GtkTreeIter iter;
1772  char *output_shapefile, *orig_shapefile, *progress_text = NULL;
1773  gchar *folder_path;
1774 
1775  int ret, success = FALSE, i = 0;
1776 
1777  /* Get the first row of the import list */
1778  is_valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(export_table_list_store), &iter);
1779  if (!is_valid)
1780  {
1781  pgui_seterr(_("ERROR: You haven't specified any tables to export"));
1783 
1784  return;
1785  }
1786 
1787  /* Firstly make sure that we can connect to the database - if we can't then there isn't much
1788  point doing anything else... */
1789  if (!connection_test())
1790  {
1791  pgui_seterr(_("Unable to connect to the database - please check your connection settings"));
1793 
1794  /* Open the connections UI for the user */
1796 
1797  gtk_widget_show_all(GTK_WIDGET(window_conn));
1798  return;
1799  }
1800 
1801  /* Now open the file selector dialog so the user can specify where they would like the output
1802  files to reside */
1803  if (gtk_dialog_run(GTK_DIALOG(dialog_folderchooser)) != GTK_RESPONSE_ACCEPT)
1804  {
1805  gtk_widget_hide(dialog_folderchooser);
1806 
1807  return;
1808  }
1809 
1810  gtk_widget_hide(dialog_folderchooser);
1811  folder_path = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog_folderchooser));
1812 
1813  /* Now everything is set up, let's extract the tables */
1814  is_valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(export_table_list_store), &iter);
1815  while (is_valid)
1816  {
1817  /* Grab the SHPDUMPERCONFIG for this row */
1818  gtk_tree_model_get(GTK_TREE_MODEL(export_table_list_store), &iter, EXPORT_POINTER_COLUMN, &gptr, -1);
1819  dumper_table_config = (SHPDUMPERCONFIG *)gptr;
1820 
1821  pgui_logf("\n==============================");
1822  pgui_logf("Exporting with configuration: %s, %s, %s", dumper_table_config->table, dumper_table_config->schema, dumper_table_config->shp_file);
1823 
1824  /* Export is running */
1825  is_running = TRUE;
1826  success = FALSE;
1827 
1828  /* Disable the button to prevent multiple imports running at the same time */
1829  gtk_widget_set_sensitive(widget, FALSE);
1830 
1831  /* Allow GTK events to get a look in */
1832  while (gtk_events_pending())
1833  gtk_main_iteration();
1834 
1835  /* Create the state for each configuration */
1836  state = ShpDumperCreate(dumper_table_config);
1837  state->config->conn = conn;
1838 
1839  /* Save the original shapefile name, then create a temporary version containing the full path */
1840  orig_shapefile = dumper_table_config->shp_file;
1841  output_shapefile = malloc(strlen(folder_path) + strlen(dumper_table_config->shp_file) + 2);
1842  strcpy(output_shapefile, folder_path);
1843  strcat(output_shapefile, G_DIR_SEPARATOR_S);
1844  strcat(output_shapefile, dumper_table_config->shp_file);
1845 
1846  dumper_table_config->shp_file = output_shapefile;
1847 
1848  /* Connect to the database */
1849  ret = ShpDumperConnectDatabase(state);
1850  if (ret != SHPDUMPEROK)
1851  {
1852  pgui_seterr("%s", state->message);
1854 
1855  goto export_cleanup;
1856  }
1857 
1858  /* Display the progress dialog */
1859  gtk_label_set_text(GTK_LABEL(label_progress), _("Initialising..."));
1860  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), 0.0);
1861  gtk_widget_show_all(dialog_progress);
1862 
1863  ret = ShpDumperOpenTable(state);
1864  if (ret != SHPDUMPEROK)
1865  {
1866  pgui_logf("%s", state->message);
1867 
1868  if (ret == SHPDUMPERERR)
1869  {
1870  gtk_widget_hide(dialog_progress);
1871 
1872  pgui_seterr("%s", state->message);
1874 
1875  goto export_cleanup;
1876  }
1877  }
1878 
1879  /* Update the text */
1880  lw_asprintf(&progress_text, _("Exporting table %s (%d records)..."), dumper_table_config->table, ShpDumperGetRecordCount(state));
1881  gtk_label_set_text(GTK_LABEL(label_progress), progress_text);
1882 
1883  /* Allow GTK events to get a look in */
1884  while (gtk_events_pending())
1885  gtk_main_iteration();
1886 
1887  pgui_logf(_("Done (postgis major version: %d)"), state->pgis_major_version);
1888  pgui_logf(_("Output shape: %s"), shapetypename(state->outshptype));
1889 
1890  for (i = 0; i < ShpDumperGetRecordCount(state) && is_running == TRUE; i++)
1891  {
1892  ret = ShpLoaderGenerateShapeRow(state);
1893  if (ret != SHPDUMPEROK)
1894  {
1895  pgui_logf("%s", state->message);
1896 
1897  if (ret == SHPDUMPERERR)
1898  {
1899  gtk_widget_hide(dialog_progress);
1900 
1901  pgui_seterr("%s", state->message);
1903 
1904  goto export_cleanup;
1905  }
1906  }
1907 
1908  /* Update the progress bar */
1909  gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress), (float)i / ShpDumperGetRecordCount(state));
1910 
1911  /* Allow GTK events to get a look in */
1912  while (gtk_events_pending())
1913  gtk_main_iteration();
1914  }
1915 
1916  /* Finish the dump */
1917  ret = ShpDumperCloseTable(state);
1918  if (ret != SHPDUMPEROK)
1919  {
1920  pgui_logf("%s", state->message);
1921 
1922  if (ret == SHPDUMPERERR)
1923  {
1924  gtk_widget_hide(dialog_progress);
1925 
1926  pgui_seterr("%s", state->message);
1928  }
1929  }
1930 
1931  /* Indicate success */
1932  if (is_running)
1933  success = TRUE;
1934 
1935 export_cleanup:
1936 
1937  /* Tidy up everything */
1938  ShpDumperDestroy(state);
1939 
1940  /* Reset shapefile back to original form (without full path) */
1941  dumper_table_config->shp_file = orig_shapefile;
1942 
1943  /* Get next entry */
1944  is_valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(export_table_list_store), &iter);
1945  }
1946 
1947  /* Export has definitely finished */
1948  is_running = FALSE;
1949  if (!success)
1950  pgui_logf(_("Table export failed."));
1951  else
1952  pgui_logf(_("Table export completed."));
1953 
1954  /* Enable the button once again */
1955  gtk_widget_set_sensitive(widget, TRUE);
1956 
1957  /* Silly GTK bug means we have to hide and show the button for it to work again! */
1958  gtk_widget_hide(widget);
1959  gtk_widget_show(widget);
1960 
1961  /* Hide the progress dialog */
1962  gtk_widget_hide(dialog_progress);
1963 
1964  /* Allow GTK events to get a look in */
1965  while (gtk_events_pending())
1966  gtk_main_iteration();
1967 
1968  return;
1969 }
static int connection_test(void)
int ShpDumperOpenTable(SHPDUMPERSTATE *state)
#define _(String)
Definition: shpcommon.h:23
static void pgui_logf(const char *fmt,...)
SHPDUMPERCONFIG * config
int ShpLoaderGenerateShapeRow(SHPDUMPERSTATE *state)
SHPDUMPERSTATE * ShpDumperCreate(SHPDUMPERCONFIG *config)
int ShpDumperCloseTable(SHPDUMPERSTATE *state)
static GtkWidget * dialog_folderchooser
static GtkWidget * progress
static SHPCONNECTIONCONFIG * conn
static void pgui_seterr(const char *fmt,...)
#define SHPDUMPERERR
SHPCONNECTIONCONFIG * conn
static volatile int is_running
void ShpDumperDestroy(SHPDUMPERSTATE *state)
int lw_asprintf(result, va_alist)
int ShpDumperGetRecordCount(SHPDUMPERSTATE *state)
#define FALSE
Definition: dbfopen.c:169
static void update_conn_ui_from_conn_config(void)
#define SHPDUMPEROK
static GtkWidget * label_progress
GtkListStore * export_table_list_store
Definition: shp2pgsql-gui.c:82
static GtkWidget * window_conn
static void pgui_raise_error_dialogue(void)
int ShpDumperConnectDatabase(SHPDUMPERSTATE *state)
static GtkWidget * dialog_progress
char message[SHPDUMPERMSGLEN]
char * shapetypename(int num)
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function:

Here is the caller graph for this function: