[libgda/LIBGDA_4.2] GdaBrowser: improved connection naming in window's menu



commit f4c0a05009cacfd81480438f9fa6ffb9523a7272
Author: Vivien Malerba <malerba gnome-db org>
Date:   Wed Jul 27 19:42:31 2011 +0200

    GdaBrowser: improved connection naming in window's menu

 tools/browser/browser-connection.c         |   30 +++++++++++++++++++++
 tools/browser/browser-connection.h         |    1 +
 tools/browser/browser-window.c             |   40 +++++++++++----------------
 tools/browser/doc/gda-browser-sections.txt |    1 +
 4 files changed, 48 insertions(+), 24 deletions(-)
---
diff --git a/tools/browser/browser-connection.c b/tools/browser/browser-connection.c
index e465035..c7354d6 100644
--- a/tools/browser/browser-connection.c
+++ b/tools/browser/browser-connection.c
@@ -868,6 +868,36 @@ browser_connection_get_name (BrowserConnection *bcnc)
 }
 
 /**
+ * browser_connection_get_long_name:
+ * @bcnc: a #BrowserConnection
+ *
+ * Get the "long" name of @bcnc
+ *
+ * Returns: a new string
+ */
+gchar *
+browser_connection_get_long_name (BrowserConnection *bcnc)
+{
+	g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
+	const gchar *cncname;
+	const GdaDsnInfo *dsn;
+	GString *title;
+
+	dsn = browser_connection_get_information (bcnc);
+	cncname = browser_connection_get_name (bcnc);
+	title = g_string_new (_("Connection"));
+	g_string_append (title, " ");
+	g_string_append_printf (title, "'%s'", cncname ? cncname : _("unnamed"));
+	if (dsn) {
+		if (dsn->name)
+			g_string_append_printf (title, ", %s '%s'", _("data source"), dsn->name);
+		if (dsn->provider)
+			g_string_append_printf (title, " (%s)", dsn->provider);
+	}
+	return g_string_free (title, FALSE);
+}
+
+/**
  * browser_connection_get_information
  * @bcnc: a #BrowserConnection
  *
diff --git a/tools/browser/browser-connection.h b/tools/browser/browser-connection.h
index e6ebe2b..336277c 100644
--- a/tools/browser/browser-connection.h
+++ b/tools/browser/browser-connection.h
@@ -64,6 +64,7 @@ GType               browser_connection_get_type               (void) G_GNUC_CONS
 
 BrowserConnection  *browser_connection_new                    (GdaConnection *cnc);
 const gchar        *browser_connection_get_name               (BrowserConnection *bcnc);
+gchar              *browser_connection_get_long_name          (BrowserConnection *bcnc);
 const GdaDsnInfo   *browser_connection_get_information        (BrowserConnection *bcnc);
 
 gboolean            browser_connection_is_busy                (BrowserConnection *bcnc, gchar **out_reason);
diff --git a/tools/browser/browser-window.c b/tools/browser/browser-window.c
index 978b297..37b38bd 100644
--- a/tools/browser/browser-window.c
+++ b/tools/browser/browser-window.c
@@ -383,9 +383,6 @@ BrowserWindow*
 browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
 {
 	BrowserWindow *bwin;
-	const gchar *cncname;
-	const GdaDsnInfo *dsn;
-	GString *title;
 
 	g_return_val_if_fail (BROWSER_IS_CONNECTION (bcnc), NULL);
 
@@ -394,19 +391,11 @@ browser_window_new (BrowserConnection *bcnc, BrowserPerspectiveFactory *factory)
 	g_signal_connect (bcnc, "transaction-status-changed",
 			  G_CALLBACK (transaction_status_changed_cb), bwin);
 
-	dsn = browser_connection_get_information (bcnc);
-	cncname = browser_connection_get_name (bcnc);
-	title = g_string_new (_("Connection"));
-	g_string_append (title, " ");
-	g_string_append_printf (title, "'%s'", cncname ? cncname : _("unnamed"));
-	if (dsn) {
-		if (dsn->name)
-			g_string_append_printf (title, ", %s '%s'", _("data source"), dsn->name);
-		if (dsn->provider)
-			g_string_append_printf (title, " (%s)", dsn->provider);
-	}
-	gtk_window_set_title (GTK_WINDOW (bwin), title->str);
-	g_string_free (title, TRUE);
+	gchar *tmp;
+	tmp = browser_connection_get_long_name (bcnc);
+	gtk_window_set_title (GTK_WINDOW (bwin), tmp);
+	g_free (tmp);
+
 	gtk_window_set_default_size ((GtkWindow*) bwin, 900, 650);
 	g_signal_connect (G_OBJECT (bwin), "delete-event",
                           G_CALLBACK (delete_event), bwin);
@@ -759,9 +748,10 @@ connection_busy_cb (BrowserConnection *bcnc, gboolean is_busy, gchar *reason, Br
 		gtk_action_set_sensitive (action, !is_busy);
 	}
 
-	const gchar *cncname;
-	cncname = browser_connection_get_name (bcnc);
+	gchar *cncname;
+	cncname = browser_connection_get_long_name (bcnc);
 	action = gtk_action_group_get_action (bwin->priv->cnc_agroup, cncname);
+	g_free (cncname);
 	if (action)
 		gtk_action_set_sensitive (action, !is_busy);
 }
@@ -771,20 +761,21 @@ static void
 connection_added_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc, BrowserWindow *bwin)
 {
 	GtkAction *action;
-	const gchar *cncname;
+	gchar *cncname;
 	guint mid;
 
 	mid = gtk_ui_manager_new_merge_id (bwin->priv->ui_manager);
-	cncname = browser_connection_get_name (bcnc);
+	cncname = browser_connection_get_long_name (bcnc);
 	action = gtk_action_new (cncname, cncname, NULL, NULL);
 	gtk_action_group_add_action (bwin->priv->cnc_agroup, action);
 	guint *amid = g_new (guint, 1);
 	*amid = mid;
 	g_object_set_data_full (G_OBJECT (action), "mid", amid, g_free);
 	
-	gtk_ui_manager_add_ui (bwin->priv->ui_manager, mid,  "/MenuBar/Window/WindowNewOthers/CncList",
+	gtk_ui_manager_add_ui (bwin->priv->ui_manager, mid, "/MenuBar/Window/WindowNewOthers/CncList",
 			       cncname, cncname,
-			       GTK_UI_MANAGER_AUTO, FALSE);	
+			       GTK_UI_MANAGER_AUTO, FALSE);
+	g_free (cncname);
 	g_signal_connect (action, "activate",
 			  G_CALLBACK (window_new_with_cnc_cb), bwin);
 	g_object_set_data (G_OBJECT (action), "bcnc", bcnc);
@@ -806,11 +797,12 @@ connection_removed_cb (G_GNUC_UNUSED BrowserCore *bcore, BrowserConnection *bcnc
 {
 	GtkAction *action;
 	gchar *path;
-	const gchar *cncname;
+	gchar *cncname;
 	guint *mid;
 
-	cncname = browser_connection_get_name (bcnc);
+	cncname = browser_connection_get_long_name (bcnc);
 	path = g_strdup_printf ("/MenuBar/Window/WindowNewOthers/CncList/%s", cncname);
+	g_free (cncname);
 	action = gtk_ui_manager_get_action (bwin->priv->ui_manager, path);
 	g_free (path);
 	g_assert (action);
diff --git a/tools/browser/doc/gda-browser-sections.txt b/tools/browser/doc/gda-browser-sections.txt
index ffc8ad8..9800d33 100644
--- a/tools/browser/doc/gda-browser-sections.txt
+++ b/tools/browser/doc/gda-browser-sections.txt
@@ -78,6 +78,7 @@ BrowserConnectionPrivate
 BrowserConnection
 browser_connection_new
 browser_connection_get_name
+browser_connection_get_long_name
 browser_connection_get_information
 browser_connection_is_virtual
 browser_connection_is_busy



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