summaryrefslogtreecommitdiff
path: root/src/modules/ecore/system
diff options
context:
space:
mode:
authorJosé Roberto de Souza <jose.souza@intel.com>2013-08-14 16:07:53 -0300
committerJosé Roberto de Souza <jose.souza@intel.com>2013-08-15 14:46:30 -0300
commit34c2fdbbba5065515559cd5bff7e41fc82804074 (patch)
tree4796ec40bff4afe361fd3bdf9cc3e4c416f3503b /src/modules/ecore/system
parent76e69f9323f5a1ef87d8f9120b4f8d03498d526b (diff)
ecore system: Simply systemd locale set
Diffstat (limited to 'src/modules/ecore/system')
-rw-r--r--src/modules/ecore/system/systemd/ecore_system_systemd.c87
1 files changed, 27 insertions, 60 deletions
diff --git a/src/modules/ecore/system/systemd/ecore_system_systemd.c b/src/modules/ecore/system/systemd/ecore_system_systemd.c
index 0943775ead..e843344702 100644
--- a/src/modules/ecore/system/systemd/ecore_system_systemd.c
+++ b/src/modules/ecore/system/systemd/ecore_system_systemd.c
@@ -103,54 +103,21 @@ _props_changed_timedate(void *data EINA_UNUSED, const Eldbus_Message *msg)
103 ecore_event_add(ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED, NULL, NULL, NULL); 103 ecore_event_add(ECORE_EVENT_SYSTEM_TIMEDATE_CHANGED, NULL, NULL, NULL);
104} 104}
105 105
106struct locale_cat_desc { 106static void _locale_envs_unset(void)
107 int cat;
108 int namelen;
109 const char *name;
110};
111
112static const struct locale_cat_desc locale_cat_desc[] = {
113#define CAT(name) {name, sizeof(#name) - 1, #name}
114 CAT(LC_CTYPE),
115 CAT(LC_NUMERIC),
116 CAT(LC_TIME),
117 CAT(LC_COLLATE),
118 CAT(LC_MONETARY),
119 CAT(LC_MESSAGES),
120 CAT(LC_ALL),
121 CAT(LC_PAPER),
122 CAT(LC_NAME),
123 CAT(LC_ADDRESS),
124 CAT(LC_TELEPHONE),
125 CAT(LC_MEASUREMENT),
126 CAT(LC_IDENTIFICATION),
127#undef CAT
128 {-1, -1, NULL}
129};
130
131static int _locale_parse(const char *str, int *cat, const char **value)
132{ 107{
133 const struct locale_cat_desc *itr; 108 unsetenv("LC_CTYPE");
134 const char *p = strchr(str, '='); 109 unsetenv("LC_NUMERIC");
135 int klen; 110 unsetenv("LC_TIME");
136 111 unsetenv("LC_COLLATE");
137 if (!p) goto end; 112 unsetenv("LC_MONETARY");
138 113 unsetenv("LC_MESSAGES");
139 klen = p - str; 114 unsetenv("LC_ALL");
140 for (itr = locale_cat_desc; itr->name != NULL; itr++) 115 unsetenv("LC_PAPER");
141 { 116 unsetenv("LC_NAME");
142 if ((klen == itr->namelen) && (memcmp(str, itr->name, klen) == 0)) 117 unsetenv("LC_ADDRESS");
143 { 118 unsetenv("LC_TELEPHONE");
144 *cat = itr->cat; 119 unsetenv("LC_MEASUREMENT");
145 *value = str + itr->namelen + 1; 120 unsetenv("LC_IDENTIFICATION");
146 return itr - locale_cat_desc;
147 }
148 }
149
150 end:
151 *cat = -1;
152 *value = NULL;
153 return -1;
154} 121}
155 122
156static void _locale_get(void *data EINA_UNUSED, const Eldbus_Message *msg, 123static void _locale_get(void *data EINA_UNUSED, const Eldbus_Message *msg,
@@ -158,7 +125,6 @@ static void _locale_get(void *data EINA_UNUSED, const Eldbus_Message *msg,
158{ 125{
159 Eldbus_Message_Iter *variant, *array; 126 Eldbus_Message_Iter *variant, *array;
160 const char *errname, *errmsg, *val; 127 const char *errname, *errmsg, *val;
161 Eina_Bool setlocs[EINA_C_ARRAY_LENGTH(locale_cat_desc)];
162 unsigned int i; 128 unsigned int i;
163 129
164 if (eldbus_message_error_get(msg, &errname, &errmsg)) 130 if (eldbus_message_error_get(msg, &errname, &errmsg))
@@ -178,22 +144,23 @@ static void _locale_get(void *data EINA_UNUSED, const Eldbus_Message *msg,
178 goto end; 144 goto end;
179 } 145 }
180 146
181 memset(setlocs, 0, sizeof(setlocs)); 147 _locale_envs_unset();
148
182 while (eldbus_message_iter_get_and_next(array, 's', &val)) 149 while (eldbus_message_iter_get_and_next(array, 's', &val))
183 { 150 {
184 int cat, idx; 151 char buf[1024], *value, *type;
185 const char *value;
186 idx = _locale_parse(val, &cat, &value);
187 if (idx >= 0)
188 setlocs[idx] = EINA_TRUE;
189 setlocale(cat, value);
190 }
191 152
192 for (i = 0; i < EINA_C_ARRAY_LENGTH(locale_cat_desc); i++) 153 snprintf(buf, sizeof(buf), "%s", val);
193 { 154
194 if ((!setlocs[i]) && (locale_cat_desc[i].cat != LC_ALL)) 155 type = buf;
195 setlocale(locale_cat_desc[i].cat, "C"); 156
157 value = strchr(buf, '=');
158 *value = 0;
159 value++;
160
161 setenv(type, value, 1);
196 } 162 }
163 setlocale(__LC_ALL, "");
197 164
198 end: 165 end:
199 ecore_event_add(ECORE_EVENT_LOCALE_CHANGED, NULL, NULL, NULL); 166 ecore_event_add(ECORE_EVENT_LOCALE_CHANGED, NULL, NULL, NULL);