[libgda] GdaBrowser: query execution result corrections



commit 614665e85377dae806fb6ca3e5d183660b8115f1
Author: Vivien Malerba <malerba gnome-db org>
Date:   Fri Jan 15 19:12:33 2010 +0100

    GdaBrowser: query execution result corrections

 tools/browser/query-exec/query-console.c |    2 +-
 tools/browser/query-exec/query-editor.c  |   70 +++++++++++++++++++++++-------
 tools/browser/query-exec/query-editor.h  |    1 +
 tools/browser/query-exec/query-result.c  |    6 +--
 4 files changed, 58 insertions(+), 21 deletions(-)
---
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index f69c95b..2493578 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -548,8 +548,8 @@ history_changed_cb (QueryEditor *history, QueryConsole *tconsole)
 	else
 		query_result_show_history_batch (QUERY_RESULT (tconsole->priv->query_result), NULL);
 
-	gtk_widget_set_sensitive (tconsole->priv->history_del_button, act);
 	gtk_widget_set_sensitive (tconsole->priv->history_copy_button, act);
+	gtk_widget_set_sensitive (tconsole->priv->history_del_button, ! query_editor_history_is_empty (qe));
 }
 
 static void
diff --git a/tools/browser/query-exec/query-editor.c b/tools/browser/query-exec/query-editor.c
index c4954d7..ad15fb7 100644
--- a/tools/browser/query-exec/query-editor.c
+++ b/tools/browser/query-exec/query-editor.c
@@ -48,7 +48,7 @@
 
 static void query_editor_history_batch_add_item (QueryEditorHistoryBatch *qib,
 						 QueryEditorHistoryItem *qih);
-static void query_editor_history_batch_del_item (QueryEditorHistoryBatch *qib,
+static void query_editor_history_batch_del_item (QueryEditor *editor, QueryEditorHistoryBatch *qib,
 						 QueryEditorHistoryItem *qih);
 
 typedef void (* CreateTagsFunc) (QueryEditor *editor, const gchar *language);
@@ -779,25 +779,30 @@ query_editor_grab_focus (GtkWidget *widget)
 static void
 hist_data_free_all (QueryEditor *editor)
 {
+	if (editor->priv->hist_focus) {
+		hist_item_data_unref (editor->priv->hist_focus);
+		editor->priv->hist_focus = NULL;
+	}
+
 	if (editor->priv->ts_timeout_id) {
 		g_source_remove (editor->priv->ts_timeout_id);
 		editor->priv->ts_timeout_id = 0;
 	}
-	if (editor->priv->batches_list) {
-		g_slist_foreach (editor->priv->batches_list, (GFunc) query_editor_history_batch_unref, NULL);
-		g_slist_free (editor->priv->batches_list);
-		editor->priv->batches_list = NULL;
-	}
 
 	if (editor->priv->hash) {
 		g_hash_table_destroy (editor->priv->hash);
 		editor->priv->hash = NULL;
 	}
 
-	if (editor->priv->hist_focus) {
-		hist_item_data_unref (editor->priv->hist_focus);
-		editor->priv->hist_focus = NULL;
-	}	
+	if (editor->priv->insert_into_batch) {
+		query_editor_history_batch_unref (editor->priv->insert_into_batch);
+		editor->priv->insert_into_batch = NULL;
+	}
+	if (editor->priv->batches_list) {
+		g_slist_foreach (editor->priv->batches_list, (GFunc) query_editor_history_batch_unref, NULL);
+		g_slist_free (editor->priv->batches_list);
+		editor->priv->batches_list = NULL;
+	}
 }
 
 static void
@@ -1434,6 +1439,20 @@ query_editor_get_current_history_batch (QueryEditor *editor)
 		return NULL;
 }
 
+/**
+ * query_editor_history_is_empty
+ * @editor: a #QueryEditor widget.
+ *
+ * Returns: %TRUE if @editor doe snot have any history item
+ */
+gboolean
+query_editor_history_is_empty (QueryEditor *editor)
+{
+	g_return_val_if_fail (QUERY_IS_EDITOR (editor), FALSE);
+	g_return_val_if_fail (editor->priv->mode == QUERY_EDITOR_HISTORY, FALSE);
+
+	return editor->priv->batches_list ? FALSE : TRUE;
+}
 
 /**
  * query_editor_del_current_history_item
@@ -1477,10 +1496,7 @@ query_editor_del_current_history_item (QueryEditor *editor)
 	g_hash_table_remove (editor->priv->hash, hdata->tag);
 	
 	g_assert (hdata->batch);
-	query_editor_history_item_ref (hdata->item);
-	query_editor_history_batch_del_item (hdata->batch, hdata->item);
-	g_signal_emit (editor, query_editor_signals[HISTORY_ITEM_REMOVED], 0, hdata->item);
-	query_editor_history_item_unref (hdata->item);
+	query_editor_history_batch_del_item (editor, hdata->batch, hdata->item);
 
 	if (! hdata->batch->hist_items) {
 		/* remove hdata->batch */
@@ -1581,7 +1597,7 @@ query_editor_del_history_batch (QueryEditor *editor, QueryEditorHistoryBatch *ba
 		
 		g_hash_table_remove (editor->priv->hash, hdata->item);
 		g_hash_table_remove (editor->priv->hash, hdata->tag);
-		query_editor_history_batch_del_item (batch, (QueryEditorHistoryItem*) list->data);
+		query_editor_history_batch_del_item (editor, batch, (QueryEditorHistoryItem*) list->data);
 	}
 	
 	/* remove batch */
@@ -1810,6 +1826,9 @@ query_editor_history_batch_new (GTimeVal run_time, GdaSet *params)
 	if (params)
 		qib->params = gda_set_copy (params);
 
+#ifdef QUERY_EDITOR_DEBUG
+	g_print ("\t%s() => %p\n", __FUNCTION__, qib);
+#endif
 	return qib;
 }
 
@@ -1835,7 +1854,14 @@ query_editor_history_batch_unref (QueryEditorHistoryBatch *qib)
 			g_object_unref (qib->params);
 
 		g_free (qib);
+#ifdef QUERY_EDITOR_DEBUG
+		g_print ("\t%s() => %p\n", __FUNCTION__, qib);
+#endif
 	}
+#ifdef QUERY_EDITOR_DEBUG
+	else
+		g_print ("\tFAILED %s() => %p:%d\n", __FUNCTION__, qib, qib->ref_count);
+#endif
 }
 
 static void
@@ -1847,11 +1873,13 @@ query_editor_history_batch_add_item (QueryEditorHistoryBatch *qib, QueryEditorHi
 }
 
 static void
-query_editor_history_batch_del_item (QueryEditorHistoryBatch *qib, QueryEditorHistoryItem *qih)
+query_editor_history_batch_del_item (QueryEditor *editor, QueryEditorHistoryBatch *qib, QueryEditorHistoryItem *qih)
 {
 	g_return_if_fail (qib);
 	g_return_if_fail (qih);
 	qib->hist_items = g_slist_remove (qib->hist_items, qih);
+
+	g_signal_emit (editor, query_editor_signals[HISTORY_ITEM_REMOVED], 0, qih);
 	query_editor_history_item_unref (qih);
 }
 
@@ -1873,6 +1901,9 @@ query_editor_history_item_new (const gchar *sql, GObject *result, GError *error)
 	if (error)
 		qih->exec_error = g_error_copy (error);
 
+#ifdef QUERY_EDITOR_DEBUG
+	g_print ("\t%s() => %p\n", __FUNCTION__, qih);
+#endif
 	return qih;
 }
 
@@ -1896,7 +1927,14 @@ query_editor_history_item_unref (QueryEditorHistoryItem *qih)
 		if (qih->exec_error)
 			g_error_free (qih->exec_error);
 		g_free (qih);
+#ifdef QUERY_EDITOR_DEBUG
+		g_print ("\t%s() => %p\n", __FUNCTION__, qih);
+#endif
 	}
+#ifdef QUERY_EDITOR_DEBUG
+	else
+		g_print ("\tFAILED %s() => %p:%d\n", __FUNCTION__, qih, qih->ref_count);
+#endif
 }
 
 /*
diff --git a/tools/browser/query-exec/query-editor.h b/tools/browser/query-exec/query-editor.h
index 077a471..c2f262a 100644
--- a/tools/browser/query-exec/query-editor.h
+++ b/tools/browser/query-exec/query-editor.h
@@ -132,6 +132,7 @@ void       query_editor_start_history_batch (QueryEditor *editor, QueryEditorHis
 void       query_editor_add_history_item (QueryEditor *editor, QueryEditorHistoryItem *hist_item);
 QueryEditorHistoryItem *query_editor_get_current_history_item (QueryEditor *editor);
 QueryEditorHistoryBatch *query_editor_get_current_history_batch (QueryEditor *editor);
+gboolean   query_editor_history_is_empty (QueryEditor *editor);
 
 void       query_editor_del_all_history_items (QueryEditor *editor);
 void       query_editor_del_current_history_item (QueryEditor *editor);
diff --git a/tools/browser/query-exec/query-result.c b/tools/browser/query-exec/query-result.c
index 4c4dc66..166cc54 100644
--- a/tools/browser/query-exec/query-result.c
+++ b/tools/browser/query-exec/query-result.c
@@ -83,14 +83,12 @@ static void
 history_item_removed_cb (QueryEditor *history, QueryEditorHistoryItem *item, QueryResult *result)
 {
 	g_hash_table_remove (result->priv->hash, item);
-	g_print ("Removed GtkWidget for item %p\n", item);
 }
 
 static void
 history_cleared_cb (QueryEditor *history, QueryResult *result)
 {
 	g_hash_table_remove_all (result->priv->hash);
-	g_print ("Removed all GtkWidget\n");
 }
 
 static void
@@ -311,8 +309,8 @@ query_result_show_history_item (QueryResult *qres, QueryEditorHistoryItem *hitem
 			}
 			else 
 				child = make_widget_for_error (hitem->exec_error);
-			g_print ("Inserted GtkWidget %p for item %p\n", child, hitem);
-			g_hash_table_insert (qres->priv->hash, hitem, g_object_ref (G_OBJECT (child)));
+
+			g_hash_table_insert (qres->priv->hash, hitem, g_object_ref_sink (G_OBJECT (child)));
 		}
 	}
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]