diff options
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | libgphoto2/gphoto2-abilities-list.c | 49 | ||||
-rw-r--r-- | libgphoto2_port/configure.ac | 5 | ||||
-rw-r--r-- | libgphoto2_port/gphoto2/gphoto2-port-info-list.h | 3 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c | 60 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/libgphoto2_port.ver | 3 |
7 files changed, 105 insertions, 21 deletions
@@ -2,6 +2,7 @@ libgphoto2 2.5.29.1 development snapshot general: * fix parallel builds by requiring gettext 0.19.1 for builds from git (PR #797) +* add gp_init_localedir() function to allow for non-standard installations (PR #796) ------------------------------------------------------------------------------ libgphoto2 2.5.29 release diff --git a/configure.ac b/configure.ac index 43540a6fe..9974f7c19 100644 --- a/configure.ac +++ b/configure.ac @@ -89,9 +89,10 @@ dnl libgphoto2-2.3.1.2.trunk (new gp_camera_get_storageinfo() funct dnl A:R:C=0:0:6 libgphoto2-2.5.0 (fixed CameraList API, ... ) dnl A:R:C=1:0:7 libgphoto2-2.5.24 (added GP_EVENT_FILE_CHANGED ... ) dnl A:R:C=2:0:8 libgphoto2-2.5.28 (added gp_filesystem_set_info_dirty ... ) -AC_SUBST([LIBGPHOTO2_AGE], [2]) +dnl A:R:C=3:0:9 libgphoto2-2.5.XXX (added gp_init_localedir ... ) +AC_SUBST([LIBGPHOTO2_AGE], [3]) AC_SUBST([LIBGPHOTO2_REVISION], [0]) -AC_SUBST([LIBGPHOTO2_CURRENT], [8]) +AC_SUBST([LIBGPHOTO2_CURRENT], [9]) AC_SUBST([LIBGPHOTO2_CURRENT_MIN], [`expr $LIBGPHOTO2_CURRENT - $LIBGPHOTO2_AGE`]) AC_SUBST([LIBGPHOTO2_VERSION_INFO], diff --git a/libgphoto2/gphoto2-abilities-list.c b/libgphoto2/gphoto2-abilities-list.c index 33776efc8..b4a9725d1 100644 --- a/libgphoto2/gphoto2-abilities-list.c +++ b/libgphoto2/gphoto2-abilities-list.c @@ -71,27 +71,52 @@ gp_message_codeset (const char *codeset) } /** - * \brief Initialise locale directory. - * - * Call bindtextdomain() with our locale directory. This is called by - * gp_abilities_list_new() so you don't need to call it unless you have a - * non-standard installation. - * \param localedir Root directory of libgphoto2's localisation files. + * \brief Initialize the localedir directory for the libgphoto2 gettext domain + * + * Override the localedir directory libgphoto2 uses for its message + * translations. + * + * You only need to call this if you have a non-standard installation + * where the locale files are at a location which differs from the + * compiled in default location. + * + * If you do need to call this function, call it before calling any + * non-initialization function. + * + * Internally, this will make sure bindtextdomain() is called for the + * relevant gettext text domain(s). + * + * \param localedir Root directory of libgphoto2's localization files. + * If NULL, use the compiled in default value, which + * will be something like "/usr/share/locale". * \return gphoto2 error code. */ int gp_init_localedir (const char *localedir) { - static int locale_initialised = 0; - if (locale_initialised) + static int locale_initialized = 0; + if (locale_initialized) { + gp_log(GP_LOG_DEBUG, "gp_init_localedir", + "ignoring late call (localedir value %s)", + localedir?localedir:"NULL"); return GP_OK; - locale_initialised = 1; - if (bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2, localedir) == NULL) - { + } + const int gpp_result = gp_port_init_localedir (localedir); + if (gpp_result != GP_OK) { + return gpp_result; + } + const char *actual_localedir = (localedir?localedir:LOCALEDIR); + const char *const gettext_domain = GETTEXT_PACKAGE_LIBGPHOTO2; + if (bindtextdomain (gettext_domain, actual_localedir) == NULL) { if (errno == ENOMEM) return GP_ERROR_NO_MEMORY; return GP_ERROR; } + gp_log(GP_LOG_DEBUG, "gp_init_localedir", + "localedir has been set to %s%s", + actual_localedir, + localedir?"":" (compile-time default)"); + locale_initialized = 1; return GP_OK; } @@ -116,7 +141,7 @@ gp_abilities_list_new (CameraAbilitiesList **list) * an other way without introducing a global initialization * function... */ - gp_init_localedir(LOCALEDIR); + gp_init_localedir (NULL); C_MEM (*list = calloc (1, sizeof (CameraAbilitiesList))); diff --git a/libgphoto2_port/configure.ac b/libgphoto2_port/configure.ac index cbf2e6f7f..848dcff6f 100644 --- a/libgphoto2_port/configure.ac +++ b/libgphoto2_port/configure.ac @@ -58,9 +58,10 @@ dnl A:R:C=7:0:7 libgphoto2_port-0.7.0 libgphoto2-2.3 dnl A:R:C=7:1:7 libgphoto2_port-0.7.1 libgphoto2-2.3.x dnl A:R:C=8:0:8 libgphoto2_port-0.8.0 libgphoto2-2.4.x dnl A:R:C=9:1:9 libgphoto2_port-0.10.0 libgphoto2-2.5.x -AC_SUBST([LIBGPHOTO2_PORT_AGE], [0]) +dnl A:R:C=1:0:13 libgphoto2-2.5.XXX (added gp_port_init_localedir ... ) +AC_SUBST([LIBGPHOTO2_PORT_AGE], [1]) AC_SUBST([LIBGPHOTO2_PORT_REVISION], [0]) -AC_SUBST([LIBGPHOTO2_PORT_CURRENT], [12]) +AC_SUBST([LIBGPHOTO2_PORT_CURRENT], [13]) AC_SUBST([LIBGPHOTO2_PORT_CURRENT_MIN], [`expr $LIBGPHOTO2_PORT_CURRENT - $LIBGPHOTO2_PORT_AGE`]) AC_SUBST([LIBGPHOTO2_PORT_VERSION_INFO], diff --git a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h index 9fe85a123..53f9ef39d 100644 --- a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h +++ b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h @@ -94,6 +94,9 @@ int gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info); const char *gp_port_message_codeset (const char*); +int gp_port_init_localedir (const char *localedir); + + /** * Name of the environment variable which may contain the path where * to look for the IO libs. If this environment variable is not defined, diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c index 83c531f30..ad131ef6b 100644 --- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c +++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c @@ -27,6 +27,7 @@ #include <gphoto2/gphoto2-port-info-list.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -63,13 +64,64 @@ struct _GPPortInfoList { /** + * \brief Initialize the localedir directory for the libgphoto2_port gettext domain + * + * Override the localedir directory libgphoto2_port uses for its message + * translations. + * + * This function is called by the gp_init_localedir() function, so if + * you are calling that already, there is no need to call + * gp_port_init_localedir() yourself. + * + * You only need to call this if you have a non-standard installation + * where the locale files are at a location which differs from the + * compiled in default location. + * + * If you need to call this function, call it before calling any + * non-initialization function. + * + * Internally, this will make sure bindtextdomain() is called for the + * relevant gettext text domain(s). + * + * \param localedir Root directory of libgphoto2_port's localization files. + * If NULL, use the compiled in default value, which + * will be something like "/usr/share/locale". + * \return gphoto2 error code. + */ +int +gp_port_init_localedir (const char *localedir) +{ + static int locale_initialized = 0; + if (locale_initialized) { + gp_log(GP_LOG_DEBUG, "gp_port_init_localedir", + "ignoring late call (localedir value %s)", + localedir?localedir:"NULL"); + return GP_OK; + } + const char *const actual_localedir = (localedir?localedir:LOCALEDIR); + const char *const gettext_domain = GETTEXT_PACKAGE_LIBGPHOTO2_PORT; + if (bindtextdomain (gettext_domain, actual_localedir) == NULL) { + if (errno == ENOMEM) + return GP_ERROR_NO_MEMORY; + return GP_ERROR; + } + gp_log(GP_LOG_DEBUG, "gp_port_init_localedir", + "localedir has been set to %s%s", + actual_localedir, + localedir?"":" (compile-time default)"); + locale_initialized = 1; + return GP_OK; +} + + +/** * \brief Specify codeset for translations * - * This function specifies the codeset that are used for the translated + * This function specifies the codeset that is used for the translated * strings that are passed back by the libgphoto2_port functions. * - * This function is called by the gp_message_codeset() function, there is - * no need to call it yourself. + * This function is called by the gp_message_codeset() function, so + * there is no need to call it yourself. * * \param codeset new codeset to use * \return the previous codeset @@ -99,7 +151,7 @@ gp_port_info_list_new (GPPortInfoList **list) * We put this in here because everybody needs to call this function * before accessing ports... */ - bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2_PORT, LOCALEDIR); + gp_port_init_localedir (NULL); C_MEM (*list = calloc (1, sizeof (GPPortInfoList))); diff --git a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver index 0947e2bd9..e8886fc54 100644 --- a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver +++ b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver @@ -27,6 +27,7 @@ LIBGPHOTO2_5_0 { gp_port_info_list_lookup_name; gp_port_info_list_lookup_path; gp_port_info_list_new; + gp_port_init_localedir; gp_port_library_version; gp_port_message_codeset; gp_port_new; @@ -90,7 +91,7 @@ LIBGPHOTO2_INTERNAL { # # The asm(".symver ...") constructs will put stuff into this node, # # it needs to stay. # # Currently used by: -# # gp_port_set_info, gp_port_get_info, +# # gp_port_set_info, gp_port_get_info, # # gp_port_info_list_append, gp_port_info_list_get_info # # # Add new exported functions here too! |