From 10520a9228e11c6b9083eb96948d7ed5e40bda4b Mon Sep 17 00:00:00 2001 From: Owen Taylor Date: Fri, 8 Nov 2002 00:51:25 +0000 Subject: [PATCH] Patch from Havoc Pennington to add functions for setting and getting a Thu Nov 7 19:32:26 2002 Owen Taylor * glib/gutils.[ch] (g_set/get_application_name): Patch from Havoc Pennington to add functions for setting and getting a human readable application name. * configure.in: Up to version 2.1.3, since we'll need to depend on last addition for GTK+. --- ChangeLog | 10 +++++ ChangeLog.pre-2-10 | 10 +++++ ChangeLog.pre-2-12 | 10 +++++ ChangeLog.pre-2-2 | 10 +++++ ChangeLog.pre-2-4 | 10 +++++ ChangeLog.pre-2-6 | 10 +++++ ChangeLog.pre-2-8 | 10 +++++ configure.in | 2 +- docs/reference/glib/tmpl/misc_utils.sgml | 7 +++- glib/gutils.c | 64 ++++++++++++++++++++++++++++++++ glib/gutils.h | 14 ++++--- 11 files changed, 148 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index bf6c800..7c65eae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index bf6c800..7c65eae 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +Thu Nov 7 19:32:26 2002 Owen Taylor + + * glib/gutils.[ch] (g_set/get_application_name): + Patch from Havoc Pennington to add functions for + setting and getting a human readable application + name. + + * configure.in: Up to version 2.1.3, since we'll + need to depend on last addition for GTK+. + 2002-11-06 Tor Lillqvist * glib/glib.def: Add g_main_thread_init. diff --git a/configure.in b/configure.in index b3cb4f2..ad6931a 100644 --- a/configure.in +++ b/configure.in @@ -33,7 +33,7 @@ GLIB_AC_DIVERT_BEFORE_HELP([ # GLIB_MAJOR_VERSION=2 GLIB_MINOR_VERSION=1 -GLIB_MICRO_VERSION=0 +GLIB_MICRO_VERSION=3 GLIB_INTERFACE_AGE=0 GLIB_BINARY_AGE=`expr 100 '*' $GLIB_MINOR_VERSION + $GLIB_MICRO_VERSION` GLIB_VERSION=$GLIB_MAJOR_VERSION.$GLIB_MINOR_VERSION.$GLIB_MICRO_VERSION diff --git a/docs/reference/glib/tmpl/misc_utils.sgml b/docs/reference/glib/tmpl/misc_utils.sgml index c717c9b..50f759a 100644 --- a/docs/reference/glib/tmpl/misc_utils.sgml +++ b/docs/reference/glib/tmpl/misc_utils.sgml @@ -16,7 +16,8 @@ These are portable utility functions. -Gets the name of the program. +Gets the name of the program. This name should NOT be localized, +contrast with g_get_application_name(). (If you are using GDK or GTK+ the program name is set in gdk_init(), which is called by gtk_init(). The program name is found by taking the last component of argv[0].) @@ -27,7 +28,9 @@ component of argv[0].) -Sets the name of the program. +Sets the name of the program. This name should NOT be localized, +contrast with g_set_application_name(). Note that for thread-safety +reasons this function can only be called once. @prgname: the name of the program. diff --git a/glib/gutils.c b/glib/gutils.c index 1688dcc..692d387 100644 --- a/glib/gutils.c +++ b/glib/gutils.c @@ -997,6 +997,70 @@ g_set_prgname (const gchar *prgname) G_UNLOCK (g_prgname); } +G_LOCK_DEFINE (g_application_name); +static gchar *g_application_name = NULL; + +/** + * g_get_application_name: + * + * Gets a human-readable name for the application, as set by + * g_set_application_name(). This name should be localized if + * possible, and is intended for display to the user. Contrast with + * g_get_prgname(), which gets a non-localized name. If + * g_set_application_name() has not been called, returns the result of + * g_get_prgname() (which may be %NULL if g_set_prgname() has also not + * been called). + * + * Return value: human-readable application name. may return %NULL + **/ +G_CONST_RETURN gchar* +g_get_application_name (void) +{ + gchar* retval; + + G_LOCK (g_application_name); + retval = g_application_name; + G_UNLOCK (g_application_name); + + if (retval == NULL) + return g_get_prgname (); + + return retval; +} + +/** + * g_set_application_name: + * @application_name: localized name of the application + * + * Sets a human-readable name for the application. This name should be + * localized if possible, and is intended for display to the user. + * Contrast with g_set_prgname(), which sets a non-localized name. + * g_set_prgname() will be called automatically by gtk_init(), + * but g_set_application_name() will not. + * + * Note that for thread safety reasons, this function can only + * be called once. + * + * The application name will be used in contexts such as error messages, + * or when displaying an application's name in the task list. + * + **/ +void +g_set_application_name (const gchar *application_name) +{ + gboolean already_set = FALSE; + + G_LOCK (g_application_name); + if (g_application_name) + already_set = TRUE; + else + g_application_name = g_strdup (application_name); + G_UNLOCK (g_application_name); + + if (already_set) + g_warning ("g_set_application() name called multiple times"); +} + guint g_direct_hash (gconstpointer v) { diff --git a/glib/gutils.h b/glib/gutils.h index b3b2dcf..b6af703 100644 --- a/glib/gutils.h +++ b/glib/gutils.h @@ -113,12 +113,14 @@ G_BEGIN_DECLS /* Retrive static string info */ -G_CONST_RETURN gchar* g_get_user_name (void); -G_CONST_RETURN gchar* g_get_real_name (void); -G_CONST_RETURN gchar* g_get_home_dir (void); -G_CONST_RETURN gchar* g_get_tmp_dir (void); -gchar* g_get_prgname (void); -void g_set_prgname (const gchar *prgname); +G_CONST_RETURN gchar* g_get_user_name (void); +G_CONST_RETURN gchar* g_get_real_name (void); +G_CONST_RETURN gchar* g_get_home_dir (void); +G_CONST_RETURN gchar* g_get_tmp_dir (void); +gchar* g_get_prgname (void); +void g_set_prgname (const gchar *prgname); +G_CONST_RETURN gchar* g_get_application_name (void); +void g_set_application_name (const gchar *application_name); typedef struct _GDebugKey GDebugKey; -- 2.7.4