1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
/*
* pwlock
*
* Copyright 2012 Samsung Electronics Co., Ltd
*
* Licensed under the Flora License, Version 1.1 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://floralicense.org/license/
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#include <vconf.h>
#include <appcore-efl.h>
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "util.h"
#include "langs.h"
#define LANGLIST_FILE_DIR_PATH "/usr/apps/org.tizen.pwlock/res/"
#define LANGLIST_FILE_PATH LANGLIST_FILE_DIR_PATH"langlist.xml"
static Eina_List *p_langlist;
static void __tree_walk_langlist(xmlNodePtr cur)
{
_DBG("%s", __func__);
xmlNode *cur_node = NULL;
char* id;
char* string;
int number;
for (cur_node = cur; cur_node;cur_node = cur_node->next) {
if (cur_node->type == XML_ELEMENT_NODE) {
_DBG("name: %s title: %s number: %s", xmlGetProp(cur_node, (const xmlChar *)"id"),
xmlGetProp(cur_node, (const xmlChar *)"string"),
xmlGetProp(cur_node, (const xmlChar *)"no"));
id = (char *)strdup((char*)xmlGetProp(cur_node, (const xmlChar *)"id"));
string = (char *)strdup((char*) xmlGetProp(cur_node, (const xmlChar *)"string"));
number = atoi((char*) xmlGetProp(cur_node, (const xmlChar *)"no"));
_DBG(">>>> locale: %s title: %s", (char*)id, (char*)string);
pwlock_lang_entry* pitem = (pwlock_lang_entry*)calloc(1, sizeof(pwlock_lang_entry));
pitem->locale = id;
pitem->title = string;
pitem->number = number;
p_langlist = eina_list_append(p_langlist, pitem);
}
}
}
static void _parseLangListXML(char* filepath)
{
_DBG("%s", __func__);
xmlDocPtr doc;
xmlNodePtr cur;
doc = xmlParseFile(filepath);
if (doc == NULL ) {
_ERR("%s : Document not parsed successfully.", __func__);
return;
}
cur = xmlDocGetRootElement(doc);
if (cur == NULL) {
_ERR("%s : empty document", __func__);
xmlFreeDoc(doc);
return;
}
_DBG("%s : ROOT NODE : %s", __func__, cur->name);
if (xmlStrcmp(cur->name, (const xmlChar *) "langlist")) {
_ERR("%s : document of the wrong type, root node != langlist", __func__);
xmlFreeDoc(doc);
return;
}
cur = cur->xmlChildrenNode;
__tree_walk_langlist(cur);
xmlFreeDoc(doc);
return;
}
int pwlock_langlist_load(void)
{
_DBG("%s", __func__);
if (!p_langlist)
{
_parseLangListXML(LANGLIST_FILE_PATH);
}
return 0;
}
int pwlock_langlist_destroy(void)
{
_DBG("%s", __func__);
Eina_List *li = p_langlist;
pwlock_lang_entry* node;
while (li) {
node = (pwlock_lang_entry*) eina_list_data_get(li);
if (node)
{
_DBG("%s : destroy nodes : locale : %s title : %s", __func__, node->locale, node->title);
PWLOCK_MEMFREE(node->locale);
PWLOCK_MEMFREE(node->title);
PWLOCK_MEMFREE(node);
}
li = eina_list_next(li);
}
p_langlist = eina_list_free(p_langlist);
return 0;
}
const char *pwlock_get_lang_title(void)
{
_DBG("%s", __func__);
int ret = 0;
int index_lang = 0;
Eina_List* list = p_langlist;
Eina_List* elist = NULL;
ret = vconf_get_int(VCONFKEY_SETAPPL_LANG_INT, &index_lang);
if (ret == 0 && index_lang == 0) {
return pwlock_get_string(IDS_IDLE_BODY_AUTOMATIC);
}
pwlock_lang_entry* lang_entry;
char* title = NULL;
EINA_LIST_FOREACH(list, elist, lang_entry)
{
if (lang_entry->number == index_lang) {
_DBG("%s : language -> %s", __func__, lang_entry->title);
title = strdup(lang_entry->title);
}
}
return title;
}
|