Re: [evolution-patches] set window title to component name



Jeffrey Stedfast wrote:
You can't use toupper() as it doesn't handle UTF-8 and is locale-specific. You'll need to use one of the glib functions for this.

Jeff


Ok.  I copied most of a function from gal to help with this.

And I added the Ximian part back in :)


Thanks,
Jon


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/evolution/shell/ChangeLog,v
retrieving revision 1.1406
diff -p -u -r1.1406 ChangeLog
--- ChangeLog	31 Mar 2004 17:05:51 -0000	1.1406
+++ ChangeLog	31 Mar 2004 22:45:24 -0000
@@ -1,3 +1,10 @@
+2004-03-31  William Jon McCann  <mccann jhu edu>
+
+	* e-shell-window.c (switch_view): set window title to name of
+	current component view.
+	(capitalize): new function to capitalize first char of each word
+	mostly copied from gal.
+
 2004-03-31  Rodney Dawes  <dobey ximian com>
 
 	* e-shell-importer.c (choose_importer_from_list):
Index: e-shell-window.c
===================================================================
RCS file: /cvs/gnome/evolution/shell/e-shell-window.c,v
retrieving revision 1.18
diff -p -u -r1.18 e-shell-window.c
--- e-shell-window.c	26 Jan 2004 21:56:03 -0000	1.18
+++ e-shell-window.c	31 Mar 2004 22:45:25 -0000
@@ -275,11 +275,45 @@ init_view (EShellWindow *window,
 	bonobo_object_release_unref (component_iface, NULL);
 }
 
+static char *
+capitalize (char *text)
+{
+	gboolean first = TRUE;
+	const char *p = text;
+	int utf8len = g_utf8_strlen (text, -1);
+	char *new_text = g_new0 (char, utf8len * 6);
+	char *output = new_text;
+
+	while (p && *p) {
+		gunichar unival = g_utf8_get_char (p);
+		gunichar newval = unival;
+
+		if (g_unichar_isalpha (unival)) {
+			if (first)
+				newval = g_unichar_totitle (unival);
+			else
+				newval = g_unichar_tolower (unival);
+			first = FALSE;
+		} else {
+			first = TRUE;
+		}
+
+		g_unichar_to_utf8 (newval, output);
+		output = g_utf8_next_char (output);
+
+		p = g_utf8_next_char (p);
+	}
+	*output = 0;
+
+	return new_text;
+}
+
 static void
 switch_view (EShellWindow *window, ComponentView *component_view)
 {
 	EShellWindowPrivate *priv = window->priv;
 	GConfClient *gconf_client = gconf_client_get_default ();
+	char *title, *capitalized_alias;
 
 	if (component_view->sidebar_widget == NULL) {
 		init_view (window, component_view);
@@ -293,6 +327,12 @@ switch_view (EShellWindow *window, Compo
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->sidebar_notebook), component_view->notebook_page_num);
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (priv->statusbar_notebook), component_view->notebook_page_num);
 	}
+
+	capitalized_alias = capitalize (component_view->component_alias);
+	title = g_strdup_printf ("Ximian Evolution %s", capitalized_alias);
+	gtk_window_set_title (GTK_WINDOW (window), title);
+	g_free (title);
+	g_free (capitalized_alias);
 
 	gconf_client_set_string (gconf_client, "/apps/evolution/shell/view_defaults/component_id",
 				 (component_view->component_alias != NULL


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