]> saetta.ns0.it Git - zakaudit/gui/commitdiff
Added progress window when loading table.
authorAndrea Zagli <azagli@libero.it>
Thu, 2 Jun 2011 09:50:02 +0000 (11:50 +0200)
committerAndrea Zagli <azagli@libero.it>
Thu, 2 Jun 2011 09:50:02 +0000 (11:50 +0200)
src/table.c

index 2c5296a4c01e29659844cec79749fb1776a7c4aa..11b061a28ed2ca9264056effbd3e7a02ebaaf41a 100644 (file)
@@ -63,12 +63,16 @@ struct _TablePrivate
        {
                Commons *commons;
 
-               GdaConnection *gdacon;
-
                GtkWidget *w;
                GtkListStore *lstore_fields;
 
                gint id;
+
+               guint update_metastore_datasource_id;
+               gboolean update_metastore_ended;
+               gchar *error_update_metastore;
+
+               GdaConnection *gdacon;
        };
 
 G_DEFINE_TYPE (Table, table, G_TYPE_OBJECT)
@@ -126,7 +130,11 @@ Table
 
        error = NULL;
        gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
-                                          g_strsplit ("lstore_tables|lstore_fields|w_table", "|", -1),
+                                          g_strsplit ("lstore_tables"
+                                                                                      "|lstore_fields"
+                                                      "|w_progress"
+                                                                                                  "|w_table",
+                                                      "|", -1),
                                           &error);
        if (error != NULL)
                {
@@ -206,13 +214,48 @@ table_is_a_system_table (Commons *commons, const gchar *table_name)
 }
 
 /* PRIVATE */
+static gpointer
+table_update_metastore (gpointer data)
+{
+       Table *table;
+       TablePrivate *priv;
+
+       GError *error;
+
+       GdaMetaContext mcontext = {"_tables", 0, NULL, NULL};
+
+       table = (Table *)data;
+       priv = TABLE_GET_PRIVATE (table);
+
+       error = NULL;
+       priv->gdacon = datasources_get_gdaconnection (priv->commons, priv->update_metastore_datasource_id, &error);
+       if (priv->gdacon == NULL || error != NULL)
+               {
+                       priv->error_update_metastore = g_strdup_printf ("Unable to update metastore.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       priv->update_metastore_ended = TRUE;
+                       return NULL;
+               }
+
+       error = NULL;
+       if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
+               {
+                       priv->error_update_metastore = g_strdup_printf ("Unable to update metastore.\n%s",
+                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       priv->update_metastore_ended = TRUE;
+                       return NULL;
+               }
+
+       priv->update_metastore_ended = TRUE;
+}
+
 static void
 table_load_db_tables (Table *table)
 {
        GtkWidget *dialog;
-       GError *error;
 
-       GdaMetaContext mcontext = {"_tables", 0, NULL, NULL};
+       GError *error;
+       GThread *thr;
 
        GdaStatement *stmt;
        GdaDataModel *dm;
@@ -234,36 +277,57 @@ table_load_db_tables (Table *table)
 
        gtk_list_store_clear (GTK_LIST_STORE (model));
 
+       dialog = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, "w_progress"));
+
+       /* updating meta store */
+       priv->update_metastore_datasource_id = strtol (gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8"))), NULL, 10);
+       priv->update_metastore_ended = FALSE;
+       priv->error_update_metastore = NULL;
+
        error = NULL;
-       priv->gdacon = datasources_get_gdaconnection (priv->commons,
-                                                     strtol (gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label8"))), NULL, 10),
-                                                     &error);
-       if (priv->gdacon == NULL || error != NULL)
+       thr = g_thread_create (table_update_metastore,
+                                  (gpointer)table,
+                                  FALSE,
+                                  &error);
+       if (thr == NULL || error != NULL)
                {
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                        GTK_MESSAGE_WARNING,
-                                                        GTK_BUTTONS_OK,
-                                                        "Unable to get tables list.\n%s",
-                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       gtk_widget_hide_all (dialog);
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                    GTK_MESSAGE_WARNING,
+                                                                    GTK_BUTTONS_OK,
+                                                                    "Unable to update the metastore: %s",
+                                                            error != NULL && error->message != NULL ? error->message : "no details");
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                        return;
                }
 
-       error = NULL;
-       if (!gda_connection_update_meta_store (priv->gdacon, &mcontext, &error))
+       gtk_label_set_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label10")),
+                               "Updating meta store");
+       gtk_widget_show_all (dialog);
+       gtk_widget_show_now (dialog);
+
+       while (!priv->update_metastore_ended)
                {
-                       dialog = gtk_message_dialog_new (GTK_WINDOW (priv->w),
-                                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                                        GTK_MESSAGE_WARNING,
-                                                        GTK_BUTTONS_OK,
-                                                        "Unable to get tables list.\n%s",
-                                                        (error != NULL && error->message != NULL ? error->message : "No details."));
+                       while (gtk_events_pending ()) gtk_main_iteration ();
+                       g_usleep (500000);
+                       gtk_progress_bar_pulse (GTK_PROGRESS_BAR (gtk_builder_get_object (priv->commons->gtkbuilder, "progressbar1")));
+               }
+
+       if (priv->error_update_metastore != NULL)
+               {
+                       gtk_widget_hide_all (dialog);
+                       dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main")),
+                                                                    GTK_DIALOG_DESTROY_WITH_PARENT,
+                                                                    GTK_MESSAGE_WARNING,
+                                                                    GTK_BUTTONS_OK,
+                                                                    priv->error_update_metastore);
                        gtk_dialog_run (GTK_DIALOG (dialog));
                        gtk_widget_destroy (dialog);
                        return;
                }
+       gtk_widget_hide_all (dialog);
 
        error = NULL;
        dm = gda_connection_get_meta_store_data (priv->gdacon,