[libgda/LIBGDA_4.2] GdaBrowser: allow easy data refresh
- From: Vivien Malerba <vivien src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgda/LIBGDA_4.2] GdaBrowser: allow easy data refresh
- Date: Wed, 31 Aug 2011 19:59:11 +0000 (UTC)
commit 8a4c2b9ca50f26cb082461b55220e463bebe8c5f
Author: Vivien Malerba <malerba gnome-db org>
Date: Wed Aug 31 16:51:27 2011 +0200
GdaBrowser: allow easy data refresh
tools/browser/data-manager/data-source.c | 32 +++++-
tools/browser/query-exec/marshal.list | 2 +
tools/browser/query-exec/query-console-page.c | 170 +++++++++++++++----------
tools/browser/query-exec/query-editor.c | 13 ++-
tools/browser/query-exec/query-editor.h | 3 +-
tools/browser/query-exec/query-result.c | 58 +++++++-
tools/browser/query-exec/query-result.h | 4 +
7 files changed, 199 insertions(+), 83 deletions(-)
---
diff --git a/tools/browser/data-manager/data-source.c b/tools/browser/data-manager/data-source.c
index e7d2cc9..4a8df34 100644
--- a/tools/browser/data-manager/data-source.c
+++ b/tools/browser/data-manager/data-source.c
@@ -988,6 +988,13 @@ data_source_execute (DataSource *source, GError **error)
source->priv->executing = FALSE;
}
+static void
+action_refresh_cb (GtkAction *action, DataSource *source)
+{
+ source->priv->need_rerun = TRUE;
+ data_source_execute (source, NULL);
+}
+
/**
* data_source_create_grid
*
@@ -1002,7 +1009,30 @@ data_source_create_grid (DataSource *source)
return NULL;
GtkWidget *fg;
- fg = ui_formgrid_new (source->priv->model, FALSE, 0);
+ fg = ui_formgrid_new (source->priv->model, FALSE, GDAUI_DATA_PROXY_INFO_ROW_MODIFY_BUTTONS);
+
+ /* add a refresh action */
+ GtkUIManager *uimanager;
+ GtkActionGroup *agroup;
+ GtkAction *action;
+ guint mid;
+
+ agroup = gtk_action_group_new ("DSGroup");
+ gtk_action_group_set_translation_domain (agroup, GETTEXT_PACKAGE);
+ action = gtk_action_new ("Refresh", "Refresh",
+ _("Refresh data"), GTK_STOCK_EXECUTE);
+ gtk_action_group_add_action (agroup, action);
+ g_signal_connect (G_OBJECT (action), "activate",
+ G_CALLBACK (action_refresh_cb), source);
+ g_object_unref (action);
+ uimanager = ui_formgrid_get_ui_manager (UI_FORMGRID (fg));
+ gtk_ui_manager_insert_action_group (uimanager, agroup, 0);
+ g_object_unref (agroup);
+
+ mid = gtk_ui_manager_new_merge_id (uimanager);
+ gtk_ui_manager_add_ui (uimanager, mid, "/ToolBar/RowModifExtension", "Refresh", "Refresh",
+ GTK_UI_MANAGER_AUTO, TRUE);
+ gtk_ui_manager_ensure_update (uimanager);
return fg;
}
diff --git a/tools/browser/query-exec/marshal.list b/tools/browser/query-exec/marshal.list
index d9ba6de..0d39eb3 100644
--- a/tools/browser/query-exec/marshal.list
+++ b/tools/browser/query-exec/marshal.list
@@ -24,3 +24,5 @@
VOID:ENUM,STRING
VOID:INT,ENUM,STRING
+VOID:POINTER,POINTER
+
diff --git a/tools/browser/query-exec/query-console-page.c b/tools/browser/query-exec/query-console-page.c
index 4ac1265..c117782 100644
--- a/tools/browser/query-exec/query-console-page.c
+++ b/tools/browser/query-exec/query-console-page.c
@@ -265,6 +265,9 @@ static void sql_favorite_clicked_cb (GtkButton *button, QueryConsolePage *tconso
static void history_copy_clicked_cb (GtkButton *button, QueryConsolePage *tconsole);
static void history_clear_clicked_cb (GtkButton *button, QueryConsolePage *tconsole);
static void history_changed_cb (QueryEditor *history, QueryConsolePage *tconsole);
+
+static void rerun_requested_cb (QueryResult *qres, QueryEditorHistoryBatch *batch,
+ QueryEditorHistoryItem *item, QueryConsolePage *tconsole);
/**
* query_console_page_new
*
@@ -448,6 +451,8 @@ query_console_page_new (BrowserConnection *bcnc)
wid = query_result_new (tconsole->priv->history);
tconsole->priv->query_result = wid;
gtk_box_pack_start (GTK_BOX (vbox), wid, TRUE, TRUE, 0);
+ g_signal_connect (wid, "rerun-requested",
+ G_CALLBACK (rerun_requested_cb), tconsole);
/* show everything */
gtk_widget_show_all (vpaned);
@@ -485,9 +490,9 @@ history_changed_cb (G_GNUC_UNUSED QueryEditor *history, QueryConsolePage *tconso
QueryEditor *qe;
qe = tconsole->priv->history;
- if (query_editor_get_current_history_item (qe)) {
+ if (query_editor_get_current_history_item (qe, NULL)) {
query_result_show_history_item (QUERY_RESULT (tconsole->priv->query_result),
- query_editor_get_current_history_item (qe));
+ query_editor_get_current_history_item (qe, NULL));
act = TRUE;
}
else if (query_editor_get_current_history_batch (qe)) {
@@ -517,7 +522,7 @@ history_copy_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcon
string = g_string_new ("");
qe = tconsole->priv->history;
- qih = query_editor_get_current_history_item (qe);
+ qih = query_editor_get_current_history_item (qe, NULL);
if (qih)
g_string_append (string, qih->sql);
else {
@@ -875,14 +880,12 @@ params_form_changed_cb (GdauiBasicForm *form, G_GNUC_UNUSED GdaHolder *param,
}
static gboolean query_exec_fetch_cb (QueryConsolePage *tconsole);
-
+static void actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
+ gboolean add_editor_history);
static void
sql_execute_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
gchar *sql;
- const gchar *remain;
- GdaBatch *batch;
- GError *error = NULL;
/* compute parameters if necessary */
if (tconsole->priv->params_compute_id > 0) {
@@ -954,71 +957,9 @@ sql_execute_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tcons
}
}
- if (!tconsole->priv->parser)
- tconsole->priv->parser = browser_connection_create_parser (tconsole->priv->bcnc);
-
sql = query_editor_get_all_text (tconsole->priv->editor);
- batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, &remain, &error);
- if (!batch) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("Error while parsing code: %s"),
- error && error->message ? error->message : _("No detail"));
- g_clear_error (&error);
- g_free (sql);
- return;
- }
+ actually_execute (tconsole, sql, tconsole->priv->params, TRUE);
g_free (sql);
-
- /* if a query is being executed, then show an error */
- if (tconsole->priv->current_exec) {
- g_object_unref (batch);
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("A query is already being executed, "
- "to execute another query, open a new connection."));
- return;
- }
-
- /* mark the current SQL to be kept by the editor as an internal history */
- query_editor_keep_current_state (tconsole->priv->editor);
-
- /* actual Execution */
- const GSList *stmt_list, *list;
- ExecutionBatch *ebatch;
- ebatch = g_new0 (ExecutionBatch, 1);
- ebatch->batch = batch;
- g_get_current_time (&(ebatch->start_time));
- ebatch->hist_batch = query_editor_history_batch_new (ebatch->start_time, tconsole->priv->params);
-
- stmt_list = gda_batch_get_statements (batch);
- for (list = stmt_list; list; list = list->next) {
- ExecutionStatement *estmt;
- estmt = g_new0 (ExecutionStatement, 1);
- estmt->stmt = GDA_STATEMENT (list->data);
- ebatch->statements = g_slist_prepend (ebatch->statements, estmt);
-
- if (list == stmt_list) {
- estmt->within_transaction =
- browser_connection_get_transaction_status (tconsole->priv->bcnc) ? TRUE : FALSE;
- estmt->exec_id = browser_connection_execute_statement (tconsole->priv->bcnc,
- estmt->stmt,
- tconsole->priv->params,
- GDA_STATEMENT_MODEL_RANDOM_ACCESS,
- FALSE, &(estmt->exec_error));
- if (estmt->exec_id == 0) {
- browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
- _("Error executing query: %s"),
- estmt->exec_error && estmt->exec_error->message ? estmt->exec_error->message : _("No detail"));
- execution_batch_free (ebatch);
- return;
- }
- }
- }
- ebatch->statements = g_slist_reverse (ebatch->statements);
-
- tconsole->priv->current_exec = ebatch;
- tconsole->priv->current_exec_id = g_timeout_add (200,
- (GSourceFunc) query_exec_fetch_cb,
- tconsole);
}
static gboolean
@@ -1135,6 +1076,95 @@ query_exec_fetch_cb (QueryConsolePage *tconsole)
return !alldone;
}
+static void
+actually_execute (QueryConsolePage *tconsole, const gchar *sql, GdaSet *params,
+ gboolean add_editor_history)
+{
+ GdaBatch *batch;
+ GError *error = NULL;
+ const gchar *remain;
+
+ if (!tconsole->priv->parser)
+ tconsole->priv->parser = browser_connection_create_parser (tconsole->priv->bcnc);
+
+ batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, &remain, &error);
+ if (!batch) {
+ browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Error while parsing code: %s"),
+ error && error->message ? error->message : _("No detail"));
+ g_clear_error (&error);
+ return;
+ }
+
+ /* if a query is being executed, then show an error */
+ if (tconsole->priv->current_exec) {
+ g_object_unref (batch);
+ browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("A query is already being executed, "
+ "to execute another query, open a new connection."));
+ return;
+ }
+
+ if (add_editor_history) {
+ /* mark the current SQL to be kept by the editor as an internal history */
+ query_editor_keep_current_state (tconsole->priv->editor);
+ }
+
+ /* actual Execution */
+ const GSList *stmt_list, *list;
+ ExecutionBatch *ebatch;
+ ebatch = g_new0 (ExecutionBatch, 1);
+ ebatch->batch = batch;
+ g_get_current_time (&(ebatch->start_time));
+ ebatch->hist_batch = query_editor_history_batch_new (ebatch->start_time, params);
+
+ stmt_list = gda_batch_get_statements (batch);
+ for (list = stmt_list; list; list = list->next) {
+ ExecutionStatement *estmt;
+ estmt = g_new0 (ExecutionStatement, 1);
+ estmt->stmt = GDA_STATEMENT (list->data);
+ ebatch->statements = g_slist_prepend (ebatch->statements, estmt);
+
+ if (list == stmt_list) {
+ estmt->within_transaction =
+ browser_connection_get_transaction_status (tconsole->priv->bcnc) ? TRUE : FALSE;
+ estmt->exec_id = browser_connection_execute_statement (tconsole->priv->bcnc,
+ estmt->stmt,
+ params,
+ GDA_STATEMENT_MODEL_RANDOM_ACCESS,
+ FALSE, &(estmt->exec_error));
+ if (estmt->exec_id == 0) {
+ browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Error executing query: %s"),
+ estmt->exec_error && estmt->exec_error->message ? estmt->exec_error->message : _("No detail"));
+ execution_batch_free (ebatch);
+ return;
+ }
+ }
+ }
+ ebatch->statements = g_slist_reverse (ebatch->statements);
+
+ tconsole->priv->current_exec = ebatch;
+ tconsole->priv->current_exec_id = g_timeout_add (200,
+ (GSourceFunc) query_exec_fetch_cb,
+ tconsole);
+}
+
+static void
+rerun_requested_cb (QueryResult *qres, QueryEditorHistoryBatch *batch,
+ QueryEditorHistoryItem *item, QueryConsolePage *tconsole)
+{
+ if (!batch || !item || !item->sql) {
+ browser_show_error (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+ _("Internal error, please report error to "
+ "http://bugzilla.gnome.org/ for the \"libgda\" product"));
+ return;
+ }
+
+ actually_execute (tconsole, item->sql, batch->params, FALSE);
+}
+
+
/**
* query_console_page_set_text
* @console: a #QueryConsolePage
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index e52a162..292d93c 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -1399,6 +1399,7 @@ query_editor_add_history_item (QueryEditor *editor, QueryEditorHistoryItem *hist
/**
* query_editor_get_current_history_item
* @editor: a #QueryEditor widget.
+ * @out_in_batch: a pointer to store the #QueryEditorHistoryBatch the returned item is in, or %NULL
*
* Get the current selected #QueryEditorHistoryItem
* passed to query_editor_add_history_item().
@@ -1406,13 +1407,19 @@ query_editor_add_history_item (QueryEditor *editor, QueryEditorHistoryItem *hist
* Returns: a #QueryEditorHistoryItem pointer, or %NULL
*/
QueryEditorHistoryItem *
-query_editor_get_current_history_item (QueryEditor *editor)
+query_editor_get_current_history_item (QueryEditor *editor, QueryEditorHistoryBatch **out_in_batch)
{
g_return_val_if_fail (QUERY_IS_EDITOR (editor), NULL);
g_return_val_if_fail (editor->priv->mode == QUERY_EDITOR_HISTORY, NULL);
- if (editor->priv->hist_focus)
+ if (out_in_batch)
+ *out_in_batch = NULL;
+
+ if (editor->priv->hist_focus) {
+ if (out_in_batch)
+ *out_in_batch = editor->priv->hist_focus->batch;
return editor->priv->hist_focus->item;
+ }
else
return NULL;
}
@@ -1425,7 +1432,7 @@ query_editor_get_current_history_item (QueryEditor *editor)
* a #QueryEditorHistoryItem, but on the #QueryEditorHistoryBatch which was last
* set by a call to query_editor_start_history_batch().
*
- * Returns: a #QueryEditorHistoryItem pointer, or %NULL
+ * Returns: a #QueryEditorHistoryBatch pointer, or %NULL
*/
QueryEditorHistoryBatch *
query_editor_get_current_history_batch (QueryEditor *editor)
diff --git a/tools/browser/query-exec/query-editor.h b/tools/browser/query-exec/query-editor.h
index d235d6d..91687bb 100644
--- a/tools/browser/query-exec/query-editor.h
+++ b/tools/browser/query-exec/query-editor.h
@@ -125,7 +125,8 @@ void query_editor_show_tooltip (QueryEditor *editor, gboolean show_tooltip
/* history API */
void query_editor_start_history_batch (QueryEditor *editor, QueryEditorHistoryBatch *hist_batch);
void query_editor_add_history_item (QueryEditor *editor, QueryEditorHistoryItem *hist_item);
-QueryEditorHistoryItem *query_editor_get_current_history_item (QueryEditor *editor);
+QueryEditorHistoryItem *query_editor_get_current_history_item (QueryEditor *editor,
+ QueryEditorHistoryBatch **out_in_batch);
QueryEditorHistoryBatch *query_editor_get_current_history_batch (QueryEditor *editor);
gboolean query_editor_history_is_empty (QueryEditor *editor);
diff --git a/tools/browser/query-exec/query-result.c b/tools/browser/query-exec/query-result.c
index b757ae2..272b128 100644
--- a/tools/browser/query-exec/query-result.c
+++ b/tools/browser/query-exec/query-result.c
@@ -24,11 +24,10 @@
#include <libgda-ui/libgda-ui.h>
#include <libgda/sql-parser/gda-sql-parser.h>
#include "../common/ui-formgrid.h"
+#include "marshal.h"
struct _QueryResultPrivate {
QueryEditor *history;
- QueryEditorHistoryBatch *hbatch;
- QueryEditorHistoryItem *hitem;
GHashTable *hash; /* key = a QueryEditorHistoryItem, value = a #GtkWidget, refed here all the times */
GtkWidget *child;
@@ -40,6 +39,14 @@ static void query_result_finalize (GObject *object);
static GObjectClass *parent_class = NULL;
+/* signals */
+enum {
+ RERUN_REQUESTED,
+ LAST_SIGNAL
+};
+
+static gint query_result_signals [LAST_SIGNAL] = { 0 };
+
static GtkWidget *make_widget_for_notice (void);
static GtkWidget *make_widget_for_data_model (GdaDataModel *model, QueryResult *qres, const gchar *sql);
static GtkWidget *make_widget_for_set (GdaSet *set);
@@ -56,6 +63,15 @@ query_result_class_init (QueryResultClass *klass)
parent_class = g_type_class_peek_parent (klass);
+ query_result_signals [RERUN_REQUESTED] =
+ g_signal_new ("rerun-requested",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (QueryResultClass, rerun_requested),
+ NULL, NULL,
+ _qe_marshal_VOID__POINTER_POINTER, G_TYPE_NONE,
+ 2, G_TYPE_POINTER, G_TYPE_POINTER);
+
object_class->finalize = query_result_finalize;
}
@@ -67,8 +83,6 @@ query_result_init (QueryResult *result, G_GNUC_UNUSED QueryResultClass *klass)
/* allocate private structure */
result->priv = g_new0 (QueryResultPrivate, 1);
result->priv->history = NULL;
- result->priv->hbatch = NULL;
- result->priv->hitem = NULL;
result->priv->hash = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref);
wid = make_widget_for_notice ();
@@ -107,10 +121,6 @@ query_result_finalize (GObject *object)
G_CALLBACK (history_cleared_cb), result);
g_object_unref (result->priv->history);
}
- if (result->priv->hbatch)
- query_editor_history_batch_unref (result->priv->hbatch);
- if (result->priv->hitem)
- query_editor_history_item_unref (result->priv->hitem);
g_free (result->priv);
result->priv = NULL;
@@ -327,6 +337,15 @@ make_widget_for_notice (void)
return label;
}
+static void
+action_refresh_cb (GtkAction *action, QueryResult *qres)
+{
+ QueryEditorHistoryBatch *batch;
+ QueryEditorHistoryItem *item;
+ item = query_editor_get_current_history_item (qres->priv->history, &batch);
+ g_signal_emit (qres, query_result_signals [RERUN_REQUESTED], 0, batch, item);
+}
+
static GtkWidget *
make_widget_for_data_model (GdaDataModel *model, QueryResult *qres, const gchar *sql)
{
@@ -348,6 +367,29 @@ make_widget_for_data_model (GdaDataModel *model, QueryResult *qres, const gchar
goto out;
ui_formgrid_handle_user_prefs (UI_FORMGRID (grid), bcnc, stmt);
g_object_unref (stmt);
+
+ GtkUIManager *uimanager;
+ GtkActionGroup *agroup;
+ GtkAction *action;
+ guint mid;
+
+ agroup = gtk_action_group_new ("QueryResultGroup");
+ gtk_action_group_set_translation_domain (agroup, GETTEXT_PACKAGE);
+ action = gtk_action_new ("Refresh", "Refresh",
+ _("Re-execute query"),
+ GTK_STOCK_EXECUTE);
+ gtk_action_group_add_action (agroup, action);
+ g_signal_connect (G_OBJECT (action), "activate",
+ G_CALLBACK (action_refresh_cb), qres);
+ g_object_unref (action);
+ uimanager = ui_formgrid_get_ui_manager (UI_FORMGRID (grid));
+ gtk_ui_manager_insert_action_group (uimanager, agroup, 0);
+ g_object_unref (agroup);
+
+ mid = gtk_ui_manager_new_merge_id (uimanager);
+ gtk_ui_manager_add_ui (uimanager, mid, "/ToolBar/RowModifExtension", "Refresh", "Refresh",
+ GTK_UI_MANAGER_AUTO, TRUE);
+ gtk_ui_manager_ensure_update (uimanager);
}
out:
return grid;
diff --git a/tools/browser/query-exec/query-result.h b/tools/browser/query-exec/query-result.h
index a5bfa74..f859a8b 100644
--- a/tools/browser/query-exec/query-result.h
+++ b/tools/browser/query-exec/query-result.h
@@ -42,6 +42,10 @@ struct _QueryResult {
struct _QueryResultClass {
GtkVBoxClass parent_class;
+
+ /* signal */
+ void (*rerun_requested) (QueryResult *qres, QueryEditorHistoryBatch *batch,
+ QueryEditorHistoryItem *item);
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]