summaryrefslogtreecommitdiff
path: root/src/modules/ecore/system/tizen/ecore_system_tizen.c
blob: 69c2cf78f0928be03e15ba76c55bbfd305700526 (plain) (blame)
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <Ecore.h>
#include <vconf.h>
#include <locale.h>

static int _log_dom = -1;

#ifdef CRITICAL
#undef CRITICAL
#endif
#define CRITICAL(...) EINA_LOG_DOM_CRIT(_log_dom, __VA_ARGS__)

#ifdef ERR
#undef ERR
#endif
#define ERR(...) EINA_LOG_DOM_ERR(_log_dom, __VA_ARGS__)

#ifdef WRN
#undef WRN
#endif
#define WRN(...) EINA_LOG_DOM_WARN(_log_dom, __VA_ARGS__)

#ifdef DBG
#undef DBG
#endif
#define DBG(...) EINA_LOG_DOM_DBG(_log_dom, __VA_ARGS__)

static void _low_mem_key_changed_cb(keynode_t *node EINA_UNUSED, void *data EINA_UNUSED)
{
   int status;

   if (vconf_get_int(VCONFKEY_SYSMAN_LOW_MEMORY, &status) < 0)
     return;

   if (status == VCONFKEY_SYSMAN_LOW_MEMORY_NORMAL)
     ecore_memory_state_set(ECORE_MEMORY_STATE_NORMAL);
   else
     ecore_memory_state_set(ECORE_MEMORY_STATE_LOW);
}

static void _charge_key_changed_cb(keynode_t *node EINA_UNUSED, void *data EINA_UNUSED)
{
   int charging, status;

   if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, &charging) < 0)
     return;

   if (charging)
     {
        ecore_power_state_set(ECORE_POWER_STATE_MAINS);
        return;
     }

   if (vconf_get_int(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, &status) < 0)
     return;

   if (status == VCONFKEY_SYSMAN_BAT_NORMAL || status == VCONFKEY_SYSMAN_BAT_FULL)
     ecore_power_state_set(ECORE_POWER_STATE_BATTERY);
   else
     ecore_power_state_set(ECORE_POWER_STATE_LOW);
}

static void _low_batt_key_changed_cb(keynode_t *node EINA_UNUSED, void *data EINA_UNUSED)
{
   _charge_key_changed_cb(NULL, NULL);
}

static void _lang_key_changed_cb(keynode_t *node EINA_UNUSED, void *first)
{
   char *lang;

   lang = vconf_get_str(VCONFKEY_LANGSET);
   if (!lang)
     return;

   setenv("LANG", lang, 1);
   setenv("LC_MESSAGES", lang, 1);
   setlocale(__LC_ALL, "");

   if (!first)
     ecore_event_add(ECORE_EVENT_LOCALE_CHANGED, NULL, NULL, NULL);
   free(lang);
}

static void _region_fmt_key_changed_cb(keynode_t *node EINA_UNUSED, void *first)
{
   char *region;

   region = vconf_get_str(VCONFKEY_REGIONFORMAT);
   if (!region)
     return;

   setenv("LC_CTYPE", region, 1);
   setenv("LC_NUMERIC", region, 1);
   setenv("LC_TIME", region, 1);
   setenv("LC_COLLATE", region, 1);
   setenv("LC_MONETARY", region, 1);
   setenv("LC_PAPER", region, 1);
   setenv("LC_NAME", region, 1);
   setenv("LC_ADDRESS", region, 1);
   setenv("LC_TELEPHONE", region, 1);
   setenv("LC_MEASUREMENT", region, 1);
   setenv("LC_IDENTIFICATION", region, 1);
   setlocale(__LC_ALL, "");

   if (!first)
     ecore_event_add(ECORE_EVENT_LOCALE_CHANGED, NULL, NULL, NULL);
   free(region);
}

static void _time_fmt_key_changed_cb(keynode_t *node EINA_UNUSED, void *data EINA_UNUSED)
{
   ecore_event_add(ECORE_EVENT_LOCALE_CHANGED, NULL, NULL, NULL);
}

static Eina_Bool
_ecore_system_tizen_init(void)
{
   _log_dom = eina_log_domain_register("ecore_system_tizen", NULL);
   if (_log_dom < 0)
     {
        EINA_LOG_ERR("Could not register log domain: ecore_system_tizen");
        return EINA_FALSE;
     }

   if (vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, _low_mem_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_SYSMAN_LOW_MEMORY);
        goto err_low_memory;
     }
   _low_mem_key_changed_cb(NULL, NULL);

   if (vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, _charge_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW);
        goto err_charge;
     }

   if (vconf_notify_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, _low_batt_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_SYSMAN_BATTERY_STATUS_LOW);
        goto err_batt_status_low;
     }
   _low_batt_key_changed_cb(NULL, NULL);

   if (vconf_notify_key_changed(VCONFKEY_LANGSET, _lang_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_LANGSET);
        goto err_lang;
     }
   _lang_key_changed_cb(NULL, (void *)1);

   if (vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, _region_fmt_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_REGIONFORMAT);
        goto err_region_fmt;
     }
   _region_fmt_key_changed_cb(NULL, (void *)1);

   if (vconf_notify_key_changed(VCONFKEY_REGIONFORMAT_TIME1224, _time_fmt_key_changed_cb, NULL) < 0)
     {
        ERR("Unable to register a vconf changed cb to %s.", VCONFKEY_REGIONFORMAT_TIME1224);
        goto err_time_fmt;
     }

   return EINA_TRUE;

err_time_fmt:
   vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, _lang_key_changed_cb);
err_region_fmt:
   vconf_ignore_key_changed(VCONFKEY_LANGSET, _lang_key_changed_cb);
err_lang:
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, _low_batt_key_changed_cb);
err_batt_status_low:
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, _charge_key_changed_cb);
err_charge:
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, _low_mem_key_changed_cb);
err_low_memory:
   eina_log_domain_unregister(_log_dom);
   _log_dom = -1;
   return EINA_FALSE;
}

static void
_ecore_system_tizen_shutdown(void)
{
   vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, _region_fmt_key_changed_cb);
   vconf_ignore_key_changed(VCONFKEY_LANGSET, _lang_key_changed_cb);
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_STATUS_LOW, _low_batt_key_changed_cb);
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_BATTERY_CHARGE_NOW, _charge_key_changed_cb);
   vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, _low_mem_key_changed_cb);
   eina_log_domain_unregister(_log_dom);
   _log_dom = -1;
}

EINA_MODULE_INIT(_ecore_system_tizen_init);
EINA_MODULE_SHUTDOWN(_ecore_system_tizen_shutdown);