[libgda] GdaBrowser: improved notification messages



commit e5760aa97b0b4c2d8c9ef51d7a22c57d5ec6e727
Author: Vivien Malerba <malerba gnome-db org>
Date:   Thu Sep 2 22:30:56 2010 +0200

    GdaBrowser: improved notification messages

 tools/browser/browser-window.c             |  185 ++++++++++++++++++++++++++--
 tools/browser/browser-window.h             |    4 +
 tools/browser/data-manager/data-console.c  |    4 +-
 tools/browser/doc/gda-browser-sections.txt |    2 +
 tools/browser/doc/tmpl/browser-window.sgml |   21 +++
 tools/browser/query-exec/query-console.c   |   16 ++--
 tools/browser/schema-browser/table-info.c  |    6 +-
 tools/browser/support.c                    |   87 +-------------
 tools/browser/support.h                    |    1 -
 9 files changed, 215 insertions(+), 111 deletions(-)
---
diff --git a/tools/browser/browser-window.c b/tools/browser/browser-window.c
index 385f7d8..3a9b6db 100644
--- a/tools/browser/browser-window.c
+++ b/tools/browser/browser-window.c
@@ -98,6 +98,11 @@ struct _BrowserWindowPrivate {
 	gulong             cnc_added_sigid;
 	gulong             cnc_removed_sigid;
 
+#if GTK_CHECK_VERSION (2,18,0)
+	GtkWidget         *notif_box;
+	GSList            *notif_widgets;
+#endif
+
 	GtkWidget         *statusbar;
 	guint              cnc_statusbar_context;
 
@@ -206,6 +211,11 @@ browser_window_dispose (GObject *object)
 		}
 		if (bwin->priv->perspectives_nb)
 			g_object_unref (bwin->priv->perspectives_nb);
+
+#if GTK_CHECK_VERSION (2,18,0)
+		if (bwin->priv->notif_widgets)
+			g_slist_free (bwin->priv->notif_widgets);
+#endif
 		g_free (bwin->priv);
 		bwin->priv = NULL;
 	}
@@ -423,6 +433,13 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
         gtk_widget_show (toolbar);
 	bwin->priv->toolbar_style = gtk_toolbar_get_style (GTK_TOOLBAR (toolbar));
 
+#if GTK_CHECK_VERSION (2,18,0)
+	bwin->priv->notif_box = gtk_vbox_new (FALSE, 0);
+	gtk_box_pack_start (GTK_BOX (vbox), bwin->priv->notif_box, FALSE, FALSE, 0);
+        gtk_widget_show (bwin->priv->notif_box);
+	bwin->priv->notif_widgets = NULL;
+#endif
+
 	GtkToolItem *ti;
 	GtkWidget *spinner, *svbox, *align;
 
@@ -449,7 +466,6 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
 	/* statusbar */
 	bwin->priv->statusbar = gtk_statusbar_new ();
 
-
 	GSList *connections, *list;
 	bwin->priv->cnc_agroup = gtk_action_group_new ("CncActions");
 	connections = browser_core_get_connections ();
@@ -897,9 +913,9 @@ window_fullscreen_cb (GtkToggleAction *action, BrowserWindow *bwin)
 {
 	if (gtk_toggle_action_get_active (action)) {
 		gtk_window_fullscreen (GTK_WINDOW (bwin));
-		browser_show_notice (GTK_WINDOW (bwin),
-				     "fullscreen-esc",
-				     _("Hit the Escape key\nto leave the fullscreen mode"));
+		browser_window_show_notice_printf (bwin,
+						"fullscreen-esc",
+						_("Hit the Escape key to leave the fullscreen mode"));
 	}
 	else
 		gtk_window_unfullscreen (GTK_WINDOW (bwin));
@@ -1008,7 +1024,7 @@ connection_properties_cb (GtkAction *action, BrowserWindow *bwin)
 		if (res == GTK_RESPONSE_OK) {
 			GError *error = NULL;
 			if (!browser_virtual_connection_modify_specs (BROWSER_VIRTUAL_CONNECTION (bwin->priv->bcnc),
-					connection_binding_properties_get_specs (CONNECTION_BINDING_PROPERTIES (win)),
+								      connection_binding_properties_get_specs (CONNECTION_BINDING_PROPERTIES (win)),
 								      &error)) {
 				browser_show_error ((GtkWindow*) bwin,
 						    _("Error updating bound connection: %s"),
@@ -1247,6 +1263,147 @@ browser_window_pop_status (BrowserWindow *bwin, const gchar *context)
 }
 
 /**
+ * browser_window_show_notice_printf
+ * @bwin: a #BrowserWindow
+ * @context: textual description of what context the message is being used in
+ * @format: the text to display
+ *
+ * Make @bwin display a notice
+ */
+void
+browser_window_show_notice_printf (BrowserWindow *bwin, const gchar *context,
+				   const gchar *format, ...)
+{
+	va_list args;
+        gchar sz[2048];
+
+	g_return_if_fail (BROWSER_IS_WINDOW (bwin));
+
+        /* build the message string */
+        va_start (args, format);
+        vsnprintf (sz, sizeof (sz), format, args);
+        va_end (args);
+	browser_window_show_notice (bwin, context, sz);
+}
+
+
+#if GTK_CHECK_VERSION (2,18,0)
+static void
+info_bar_response_cb (GtkInfoBar *ibar, gint response, BrowserWindow *bwin)
+{
+	bwin->priv->notif_widgets = g_slist_remove (bwin->priv->notif_widgets, ibar);	
+	gtk_widget_destroy ((GtkWidget*) ibar);
+}
+#endif
+
+/* hash table to remain which context notices have to be hidden: key=context, value=GINT_TO_POINTER (1) */
+static GHashTable *hidden_contexts = NULL;
+
+static void
+hide_notice_toggled_cb (GtkToggleButton *toggle, gchar *context)
+{
+	g_assert (hidden_contexts);
+	if (gtk_toggle_button_get_active (toggle))
+		g_hash_table_insert (hidden_contexts, g_strdup (context), GINT_TO_POINTER (TRUE));
+	else
+		g_hash_table_remove (hidden_contexts, context);
+}
+
+/**
+ * browser_window_show_notice
+ * @bwin: a #BrowserWindow
+ * @context: textual description of what context the message is being used in
+ * @text: the information's text
+ *
+ * Makes @bwin display a notice
+ */
+void
+browser_window_show_notice (BrowserWindow *bwin, const gchar *context, const gchar *text)
+{
+	g_return_if_fail (BROWSER_IS_WINDOW (bwin));
+	gboolean hide = FALSE;
+
+	if (context) {
+		if (!hidden_contexts)
+			hidden_contexts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
+		hide = GPOINTER_TO_INT (g_hash_table_lookup (hidden_contexts, context));
+	}
+
+	if (hide) {
+		gchar *ptr, *tmp;
+		tmp = g_strdup (text);
+		for (ptr = tmp; *ptr && (*ptr != '\n'); ptr++);
+		if (*ptr) {
+			*ptr = '.'; ptr++;
+			*ptr = '.'; ptr++;
+			*ptr = '.'; ptr++;
+			*ptr = 0;
+		}
+		browser_window_push_status (bwin, "SupportNotice", tmp, TRUE);
+		g_free (tmp);
+	}
+	else {
+		GtkWidget *cb = NULL;
+		if (context) {
+			cb = gtk_check_button_new_with_label (_("Don't show this message again"));
+			g_signal_connect_data (cb, "toggled",
+					       G_CALLBACK (hide_notice_toggled_cb), g_strdup (context),
+					       (GClosureNotify) g_free, 0);
+		}
+
+#if GTK_CHECK_VERSION (2,18,0)
+		/* use a GtkInfoBar */
+		GtkWidget *ibar, *content_area, *label;
+		
+		ibar = gtk_info_bar_new_with_buttons (GTK_STOCK_CLOSE, 1, NULL);
+		gtk_info_bar_set_message_type (GTK_INFO_BAR (ibar), GTK_MESSAGE_INFO);
+		label = gtk_label_new ("");
+		gtk_label_set_markup (GTK_LABEL (label), text);
+		gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
+		gtk_misc_set_alignment (GTK_MISC (label), 0., -1);
+		content_area = gtk_info_bar_get_content_area (GTK_INFO_BAR (ibar));
+		if (cb) {
+			GtkWidget *box;
+			box = gtk_hbox_new (FALSE, 0);
+			gtk_box_pack_start (GTK_BOX (box), label, TRUE, TRUE, 0);
+			gtk_box_pack_start (GTK_BOX (box), cb, FALSE, FALSE, 0);
+			gtk_container_add (GTK_CONTAINER (content_area), box);
+			gtk_widget_show_all (box);
+		}
+		else {
+			gtk_container_add (GTK_CONTAINER (content_area), label);
+			gtk_widget_show (label);
+		}
+		g_signal_connect (ibar, "response",
+				  G_CALLBACK (info_bar_response_cb), bwin);
+		gtk_box_pack_start (GTK_BOX (bwin->priv->notif_box), ibar, TRUE, TRUE, 0);
+		bwin->priv->notif_widgets = g_slist_append (bwin->priv->notif_widgets, ibar);
+		if (g_slist_length (bwin->priv->notif_widgets) > 2) {
+			gtk_widget_destroy (GTK_WIDGET (bwin->priv->notif_widgets->data));
+			bwin->priv->notif_widgets = g_slist_delete_link (bwin->priv->notif_widgets,
+									 bwin->priv->notif_widgets);
+		}
+		gtk_widget_show (ibar);
+#else
+		/* create the error message dialog */
+		GtkWidget *dialog;
+		dialog = gtk_message_dialog_new_with_markup (GTK_WINDOW (bwin),
+							     GTK_DIALOG_DESTROY_WITH_PARENT |
+							     GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
+							     GTK_BUTTONS_CLOSE,
+							     "<span weight=\"bold\">%s</span>\n%s", _("Note:"), text);
+		if (cb)
+			gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), cb, FALSE, FALSE, 10);
+	
+		gtk_widget_show_all (dialog);
+		gtk_dialog_run (GTK_DIALOG (dialog));
+		gtk_widget_destroy (dialog);
+#endif
+	}
+}
+
+
+/**
  * browser_window_customize_perspective_ui
  * @bwin: a #BrowserWindow
  * @bpers: the #BrowserPerspective concerned
@@ -1345,13 +1502,17 @@ browser_window_change_perspective (BrowserWindow *bwin, const gchar *perspective
 	}
 	g_list_free (actions);
 
-	browser_show_notice (GTK_WINDOW (bwin), "Perspective change",
-			     _("The current perspective has changed to the '%s' perspective, you "
-			       "can switch back to previous perspective through the "
-			       "'Perspective/%s' menu, or using the '%s' shortcut"),
-			     bwin->priv->current_perspective->factory->perspective_name,
-			     current_pdata->factory->perspective_name,
-			     current_pdata->factory->menu_shortcut);
+	gchar *tmp;
+	tmp = g_markup_printf_escaped (_("The current perspective has changed to the '%s' perspective, you "
+					 "can switch back to previous perspective through the "
+					 "'Perspective/%s' menu, or using the '%s' shortcut"),
+				       bwin->priv->current_perspective->factory->perspective_name,
+				       current_pdata->factory->perspective_name,
+				       current_pdata->factory->menu_shortcut);
+
+			
+	browser_window_show_notice (bwin, "Perspective change", tmp);
+	g_free (tmp);
 
 	return bpers;
 }
diff --git a/tools/browser/browser-window.h b/tools/browser/browser-window.h
index 3c97bd3..ee79e9c 100644
--- a/tools/browser/browser-window.h
+++ b/tools/browser/browser-window.h
@@ -58,6 +58,10 @@ BrowserConnection  *browser_window_get_connection         (BrowserWindow *bwin);
 guint               browser_window_push_status            (BrowserWindow *bwin, const gchar *context,
 							   const gchar *text, gboolean auto_clear);
 void                browser_window_pop_status             (BrowserWindow *bwin, const gchar *context);
+void                browser_window_show_notice            (BrowserWindow *bwin, const gchar *context,
+							   const gchar *text);
+void                browser_window_show_notice_printf     (BrowserWindow *bwin, const gchar *context,
+							   const gchar *format, ...);
 
 void                browser_window_customize_perspective_ui (BrowserWindow *bwin, BrowserPerspective *bpers,
 							     GtkActionGroup *actions_group,
diff --git a/tools/browser/data-manager/data-console.c b/tools/browser/data-manager/data-console.c
index 8c4b24b..a4a64ab 100644
--- a/tools/browser/data-manager/data-console.c
+++ b/tools/browser/data-manager/data-console.c
@@ -880,9 +880,9 @@ compose_mode_toggled_cb (GtkToggleAction *action, DataConsole *dconsole)
 	}
 
 	if (pagenb == MAIN_PAGE_DATA)
-		browser_show_notice ((GtkWindow*) gtk_widget_get_toplevel ((GtkWidget*) dconsole),
+		browser_window_show_notice_printf (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) dconsole)),
 				     "data-manager-exec-mode-switched",
-				     _("Switching to execution mode.\n\nHit the Escape key\n"
+				     _("Switching to execution mode. Hit the Escape key "
 				       "to return to the compose mode"));
 	gtk_notebook_set_current_page (GTK_NOTEBOOK (dconsole->priv->main_notebook), pagenb);
 }
diff --git a/tools/browser/doc/gda-browser-sections.txt b/tools/browser/doc/gda-browser-sections.txt
index 3904917..d05208d 100644
--- a/tools/browser/doc/gda-browser-sections.txt
+++ b/tools/browser/doc/gda-browser-sections.txt
@@ -7,6 +7,8 @@ browser_window_new
 browser_window_get_connection
 browser_window_push_status
 browser_window_pop_status
+browser_window_show_notice
+browser_window_show_notice_printf
 browser_window_customize_perspective_ui
 browser_window_change_perspective
 browser_window_is_fullscreen
diff --git a/tools/browser/doc/tmpl/browser-window.sgml b/tools/browser/doc/tmpl/browser-window.sgml
index d62f097..32634b7 100644
--- a/tools/browser/doc/tmpl/browser-window.sgml
+++ b/tools/browser/doc/tmpl/browser-window.sgml
@@ -81,6 +81,27 @@ Top level browser window
 @context: 
 
 
+<!-- ##### FUNCTION browser_window_show_notice ##### -->
+<para>
+
+</para>
+
+ bwin: 
+ context: 
+ text: 
+
+
+<!-- ##### FUNCTION browser_window_show_notice_printf ##### -->
+<para>
+
+</para>
+
+ bwin: 
+ context: 
+ format: 
+ Varargs: 
+
+
 <!-- ##### FUNCTION browser_window_customize_perspective_ui ##### -->
 <para>
 
diff --git a/tools/browser/query-exec/query-console.c b/tools/browser/query-exec/query-console.c
index d08eb0d..74dd0ab 100644
--- a/tools/browser/query-exec/query-console.c
+++ b/tools/browser/query-exec/query-console.c
@@ -934,14 +934,14 @@ query_exec_fetch_cb (QueryConsole *tconsole)
 				if (! history->within_transaction &&
 				    browser_connection_get_transaction_status (tconsole->priv->bcnc) &&
 				    gda_statement_get_statement_type (estmt->stmt) != GDA_SQL_STATEMENT_BEGIN) {
-					browser_show_notice (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
-							     "QueryExecTransactionStarted",
-							     "%s", _("A transaction has automatically been started\n"
-								     "during this statement's execution, this usually\n"
-								     "happens when blobs are selected (and the transaction\n"
-								     "will have to remain opened while the blobs are still\n"
-								     "accessible, clear the corresponding history item before\n"
-								     "closing the transaction)."));
+					browser_window_show_notice_printf (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tconsole)),
+									"QueryExecTransactionStarted",
+									"%s", _("A transaction has automatically been started\n"
+										"during this statement's execution, this usually\n"
+										"happens when blobs are selected (and the transaction\n"
+										"will have to remain opened while the blobs are still\n"
+										"accessible, clear the corresponding history item before\n"
+										"closing the transaction)."));
 				}
 				
 				query_editor_add_history_item (tconsole->priv->history, history);
diff --git a/tools/browser/schema-browser/table-info.c b/tools/browser/schema-browser/table-info.c
index f8c54fa..271c160 100644
--- a/tools/browser/schema-browser/table-info.c
+++ b/tools/browser/schema-browser/table-info.c
@@ -521,9 +521,9 @@ static void statement_executed_cb (BrowserConnection *bcnc,
 				    error->message ?
 				    error->message : _("No detail"));
 	else
-		browser_show_notice (GTK_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tinfo)),
-				     "DataInsertQuery",
-				     _("Data successfully inserted"));
+		browser_window_show_notice_printf (BROWSER_WINDOW (gtk_widget_get_toplevel ((GtkWidget*) tinfo)),
+						"DataInsertQuery",
+						_("Data successfully inserted"));
 }
 
 static void
diff --git a/tools/browser/support.c b/tools/browser/support.c
index a4b70c5..ec1131e 100644
--- a/tools/browser/support.c
+++ b/tools/browser/support.c
@@ -151,90 +151,6 @@ browser_show_error (GtkWindow *parent, const gchar *format, ...)
         gtk_widget_destroy (dialog);
 }
 
-/* hash table to remain which context notices have to be hidden: key=context, value=GINT_TO_POINTER (1) */
-static GHashTable *hidden_contexts = NULL;
-
-static void
-hide_notice_toggled_cb (GtkToggleButton *toggle, gchar *context)
-{
-	g_assert (hidden_contexts);
-	if (gtk_toggle_button_get_active (toggle))
-		g_hash_table_insert (hidden_contexts, g_strdup (context), GINT_TO_POINTER (TRUE));
-	else
-		g_hash_table_remove (hidden_contexts, context);
-}
-
-/**
- * browser_show_notice
- * @parent: a #GtkWindow
- * @context: a context string or %NULL
- * @format: printf() style format string
- * @...: arguments for @format
- *
- * Displays a modal notice until the user aknowledges it.
- *
- * If @context is not NULL, then the message box contains a check box to avoid displaying the
- * same massage again.
- */
-void
-browser_show_notice (GtkWindow *parent, const gchar *context, const gchar *format, ...)
-{
-        va_list args;
-        gchar sz[2048];
-        GtkWidget *dialog;
-	gboolean hide = FALSE;
-
-        /* build the message string */
-        va_start (args, format);
-        vsnprintf (sz, sizeof (sz), format, args);
-        va_end (args);
-
-	if (context) {
-		if (!hidden_contexts)
-			hidden_contexts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
-		hide = GPOINTER_TO_INT (g_hash_table_lookup (hidden_contexts, context));
-	}
-
-	if (hide) {
-		if (BROWSER_IS_WINDOW (parent)) {
-			gchar *ptr;
-			for (ptr = sz; *ptr && (*ptr != '\n'); ptr++);
-			if (*ptr) {
-				*ptr = '.'; ptr++;
-				*ptr = '.'; ptr++;
-				*ptr = '.'; ptr++;
-				*ptr = 0;
-			}
-			browser_window_push_status (BROWSER_WINDOW (parent),
-						    "SupportNotice", sz, TRUE);
-		}
-	}
-	else {
-		/* create the error message dialog */
-		dialog = gtk_message_dialog_new_with_markup (parent,
-							     GTK_DIALOG_DESTROY_WITH_PARENT |
-							     GTK_DIALOG_MODAL, GTK_MESSAGE_INFO,
-							     GTK_BUTTONS_CLOSE,
-							     "<span weight=\"bold\">%s</span>\n%s", _("Note:"), sz);
-		if (context) {
-			GtkWidget *cb;
-			cb = gtk_check_button_new_with_label (_("Don't show this message again"));
-			g_signal_connect_data (cb, "toggled",
-					       G_CALLBACK (hide_notice_toggled_cb), g_strdup (context),
-					       (GClosureNotify) g_free, 0);
-#if GTK_CHECK_VERSION(2,18,0)
-			gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), cb, FALSE, FALSE, 10);
-#else
-			gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), cb, FALSE, FALSE, 10);
-#endif
-		}
-		
-		gtk_widget_show_all (dialog);
-		gtk_dialog_run (GTK_DIALOG (dialog));
-		gtk_widget_destroy (dialog);
-	}
-}
-
 #ifdef HAVE_GDU
 /**
  * browser_show_help
@@ -314,7 +230,8 @@ browser_show_help (GtkWindow *parent, const gchar *topic)
 		g_error_free (error);
 	}
 	else
-		browser_show_notice (parent, "show-help", _("Help is being loaded, please wait..."));
+		browser_window_show_notice (BROWSER_WINDOW (parent),
+					 "show-help", _("Help is being loaded, please wait..."));
 
 	g_free (uri);
 }
diff --git a/tools/browser/support.h b/tools/browser/support.h
index 4529338..4b9b470 100644
--- a/tools/browser/support.h
+++ b/tools/browser/support.h
@@ -36,7 +36,6 @@ G_BEGIN_DECLS
 BrowserConnection *browser_connection_open (GError **error);
 gboolean           browser_connection_close (GtkWindow *parent, BrowserConnection *bcnc);
 void               browser_show_error (GtkWindow *parent, const gchar *format, ...);
-void               browser_show_notice (GtkWindow *parent, const gchar *context, const gchar *format, ...);
 #ifdef HAVE_GDU
 void               browser_show_help (GtkWindow *parent, const gchar *topic);
 #endif



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