Imported Upstream version 0.1.0
[debian/lxdm.git] / src / lang.c
1 /*
2 * lang.c - load language list
3 *
4 * Copyright 2009 dgod <dgod.osa@gmail.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19 * MA 02110-1301, USA.
20 */
21
22 #include "lang.h"
23
24 #include <stdio.h>
25 #include <glib.h>
26 #include <string.h>
27
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31
32 #ifndef LXDM_DATA_DIR
33 #define LXDM_DATA_DIR "/usr/share/lxdm"
34 #endif
35
36 #include "gdm/gdm-languages.h"
37
38 int lxdm_load_langs(void *arg,void (*cb)(void *arg,char *lang,char *desc), const char* last_lang)
39 {
40 int ret = -1;
41 char **langs, **lang;
42 char* normal_last_lang;
43
44 //cb(arg,"C","Default");
45 cb(arg,"","Default"); /* default is to use the system wide settings ,not use the "C" */
46 normal_last_lang = last_lang ? gdm_normalize_language_name(last_lang) : NULL;
47
48 if(!normal_last_lang || !normal_last_lang[0])
49 ret = 0;
50
51 /* come up with available languages with gdm-languages */
52 langs = gdm_get_all_language_names();
53 for(lang = langs; *lang; ++lang)
54 {
55 char* normal = gdm_normalize_language_name(*lang);
56 char* readable = gdm_get_language_from_name(normal, normal);
57 cb(arg, normal, readable);
58 if(ret < 0 && g_strcmp0(normal_last_lang, normal) == 0)
59 ret = (lang - langs) + 1;
60 g_free(readable);
61 g_free(normal);
62 }
63 g_free(normal_last_lang);
64 return ret;
65 }