2007-02-03 05:05:30 -08:00
|
|
|
/* vim: set sw=4 ts=4 sts=4 et: */
|
2009-04-20 16:20:40 -07:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
2009-09-21 09:36:29 -07:00
|
|
|
#include <stdio.h>
|
2009-04-20 16:20:40 -07:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <Ecore_Str.h>
|
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
#include "Efreet.h"
|
|
|
|
#include "efreet_private.h"
|
2009-04-20 16:20:40 -07:00
|
|
|
#include "efreet_xml.h"
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
static int init = 0;
|
|
|
|
static int efreet_parsed_locale = 0;
|
|
|
|
static char *efreet_lang = NULL;
|
|
|
|
static char *efreet_lang_country = NULL;
|
|
|
|
static char *efreet_lang_modifier = NULL;
|
2009-09-21 09:36:29 -07:00
|
|
|
int _efreet_log_domain_global = -1;
|
2007-02-03 05:05:30 -08:00
|
|
|
static void efreet_parse_locale(void);
|
|
|
|
static int efreet_parse_locale_setting(const char *env);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns > 0 if the initialization was successful, 0 otherwise
|
|
|
|
* @brief Initializes the Efreet system
|
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI int
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_init(void)
|
|
|
|
{
|
|
|
|
if (init++) return init;
|
2009-09-06 15:23:04 -07:00
|
|
|
if (!eina_init()) return --init;
|
2009-09-21 09:36:29 -07:00
|
|
|
_efreet_log_domain_global = eina_log_domain_register("Efreet",EFREET_DEFAULT_LOG_COLOR);
|
|
|
|
if(_efreet_log_domain_global < 0)
|
|
|
|
{
|
|
|
|
printf("Efreet could create a general log domain.\n");
|
|
|
|
return --init;
|
|
|
|
}
|
2007-02-03 05:05:30 -08:00
|
|
|
if (!efreet_base_init()) return --init;
|
|
|
|
if (!efreet_xml_init()) return --init;
|
|
|
|
if (!efreet_icon_init()) return --init;
|
|
|
|
if (!efreet_ini_init()) return --init;
|
|
|
|
if (!efreet_desktop_init()) return --init;
|
2007-03-25 03:55:45 -07:00
|
|
|
if (!efreet_menu_init()) return --init;
|
2007-02-03 05:05:30 -08:00
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Returns the number of times the init function as been called
|
|
|
|
* minus the corresponding init call.
|
|
|
|
* @brief Shuts down Efreet if a balanced number of init/shutdown calls have
|
2007-09-06 09:15:10 -07:00
|
|
|
* been made
|
2007-02-03 05:05:30 -08:00
|
|
|
*/
|
2007-11-04 01:32:35 -08:00
|
|
|
EAPI int
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_shutdown(void)
|
|
|
|
{
|
|
|
|
if (--init) return init;
|
2007-03-25 04:25:23 -07:00
|
|
|
efreet_menu_shutdown();
|
2007-02-03 05:05:30 -08:00
|
|
|
efreet_desktop_shutdown();
|
|
|
|
efreet_ini_shutdown();
|
|
|
|
efreet_icon_shutdown();
|
|
|
|
efreet_xml_shutdown();
|
|
|
|
efreet_base_shutdown();
|
2009-09-21 09:36:29 -07:00
|
|
|
eina_log_domain_unregister(_efreet_log_domain_global);
|
2009-09-06 15:23:04 -07:00
|
|
|
eina_shutdown();
|
2007-02-03 05:05:30 -08:00
|
|
|
|
|
|
|
IF_FREE(efreet_lang);
|
|
|
|
IF_FREE(efreet_lang_country);
|
|
|
|
IF_FREE(efreet_lang_modifier);
|
|
|
|
efreet_parsed_locale = 0; /* reset this in case they init efreet again */
|
|
|
|
|
|
|
|
return init;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the current users language setting or NULL if none set
|
|
|
|
* @brief Retrieves the current language setting
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the current language country setting or NULL if none set
|
|
|
|
* @brief Retrieves the current country setting for the current language or
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_country_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang_country;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang_country;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns the current language modifier setting or NULL if none
|
|
|
|
* set.
|
|
|
|
* @brief Retrieves the modifier setting for the language.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
efreet_lang_modifier_get(void)
|
|
|
|
{
|
|
|
|
if (efreet_parsed_locale) return efreet_lang_modifier;
|
|
|
|
|
|
|
|
efreet_parse_locale();
|
|
|
|
return efreet_lang_modifier;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @return Returns no value
|
|
|
|
* @brief Parses out the language, country and modifer setting from the
|
|
|
|
* LC_MESSAGES environment variable
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
efreet_parse_locale(void)
|
|
|
|
{
|
|
|
|
efreet_parsed_locale = 1;
|
2007-09-06 09:15:10 -07:00
|
|
|
|
2007-02-03 05:05:30 -08:00
|
|
|
if (efreet_parse_locale_setting("LC_ALL"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (efreet_parse_locale_setting("LC_MESSAGES"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
efreet_parse_locale_setting("LANG");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param env: The environment variable to grab
|
|
|
|
* @return Returns 1 if we parsed something of @a env, 0 otherwise
|
|
|
|
* @brief Tries to parse the lang settings out of the given environment
|
|
|
|
* variable
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
efreet_parse_locale_setting(const char *env)
|
|
|
|
{
|
|
|
|
int found = 0;
|
|
|
|
char *setting;
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
setting = getenv(env);
|
|
|
|
if (!setting) return 0;
|
|
|
|
setting = strdup(setting);
|
|
|
|
|
|
|
|
/* pull the modifier off the end */
|
|
|
|
p = strrchr(setting, '@');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
efreet_lang_modifier = strdup(p + 1);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there is an encoding we ignore it */
|
|
|
|
p = strrchr(setting, '.');
|
|
|
|
if (p) *p = '\0';
|
|
|
|
|
|
|
|
/* get the country if available */
|
|
|
|
p = strrchr(setting, '_');
|
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*p = '\0';
|
|
|
|
efreet_lang_country = strdup(p + 1);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (setting && (*setting != '\0'))
|
|
|
|
{
|
|
|
|
efreet_lang = strdup(setting);
|
|
|
|
found = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(setting);
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @internal
|
|
|
|
* @param buffer: The destination buffer
|
|
|
|
* @param size: The destination buffer size
|
|
|
|
* @param strs: The strings to concatenate together
|
|
|
|
* @return Returns the size of the string in @a buffer
|
|
|
|
* @brief Concatenates the strings in @a strs into the given @a buffer not
|
|
|
|
* exceeding the given @a size.
|
|
|
|
*/
|
|
|
|
size_t
|
|
|
|
efreet_array_cat(char *buffer, size_t size, const char *strs[])
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
size_t n;
|
|
|
|
for (i = 0, n = 0; n < size && strs[i]; i++)
|
|
|
|
{
|
|
|
|
n += ecore_strlcpy(buffer + n, strs[i], size - n);
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|