summaryrefslogtreecommitdiff
path: root/src/setting.c
blob: 5f6bdafdd7460637576e9bc80617b951221385a8 (plain)
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
/*
 * Copyright 2013  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 <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <locale.h>

#include <vconf.h>
#include <dlog.h>

#include <Eina.h>

#include "client_life.h"
#include "setting.h"
#include "util.h"
#include "debug.h"
#include "slave_life.h"
#include "critical_log.h"
#include "xmonitor.h"
#include "conf.h"

int errno;

static void lcd_state_cb(keynode_t *node, void *user_data)
{
	if (!node)
		return;

	xmonitor_handle_state_changes();
}

HAPI int setting_is_lcd_off(void)
{
	int state;

	if (vconf_get_int(VCONFKEY_PM_STATE, &state) != 0) {
		ErrPrint("Idle lock state is not valid\n");
		state = VCONFKEY_PM_STATE_NORMAL; /* UNLOCK */
	}

	DbgPrint("State: %d, (%d:lcdoff, %d:sleep)\n", state, VCONFKEY_PM_STATE_LCDOFF, VCONFKEY_PM_STATE_SLEEP);
	return state == VCONFKEY_PM_STATE_LCDOFF || state == VCONFKEY_PM_STATE_SLEEP;
}

static void power_off_cb(keynode_t *node, void *user_data)
{
 	int val;
	CRITICAL_LOG("Terminated(vconf)\n");

	if (vconf_get_int(VCONFKEY_SYSMAN_POWER_OFF_STATUS, &val) != 0) {
		ErrPrint("Failed to get power off status (%d)\n", val);
		return;
	}

	if (val == VCONFKEY_SYSMAN_POWER_OFF_DIRECT || val == VCONFKEY_SYSMAN_POWER_OFF_RESTART) {
		if (creat("/tmp/.stop.provider", 0644) < 0)
			ErrPrint("Failed to create .stop.provider [%s]\n", strerror(errno));

		exit(0);
	} else {
		ErrPrint("Unknown power state: %d\n", val);
	}
}

static void region_changed_cb(keynode_t *node, void *user_data)
{
        char *region;
        char *r;

        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);

	r = setlocale(LC_ALL, "");
	if (r == NULL)
		ErrPrint("Failed to change region\n");

	free(region);
}

static void lang_changed_cb(keynode_t *node, void *user_data)
{
        char *lang;
       	char *r;

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

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

	r = setlocale(LC_ALL, "");
	if (!r)
		ErrPrint("Failed to change locale\n");

	DbgPrint("Locale: %s\n", setlocale(LC_ALL, NULL));
	free(lang);
}

HAPI int setting_init(void)
{
	int ret;

	ret = vconf_notify_key_changed(VCONFKEY_PM_STATE, lcd_state_cb, NULL);
	if (ret < 0)
		ErrPrint("Failed to add vconf for lock state: %d\n", ret);

	ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb, NULL);
	if (ret < 0)
		ErrPrint("Failed to add vconf for power state: %d \n", ret);

	ret = vconf_notify_key_changed(VCONFKEY_LANGSET, lang_changed_cb, NULL);
	if (ret < 0)
		ErrPrint("Failed to add vconf for lang change: %d\n", ret);

	ret = vconf_notify_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb, NULL);
	if (ret < 0)
		ErrPrint("Failed to add vconf for region change: %d\n", ret);

	lang_changed_cb(NULL, NULL);
	region_changed_cb(NULL, NULL);
	return ret;
}

HAPI int setting_fini(void)
{
	int ret;

	ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
	if (ret < 0)
		ErrPrint("Failed to ignore vconf key (%d)\n", ret);

	ret = vconf_ignore_key_changed(VCONFKEY_LANGSET, lang_changed_cb);
	if (ret < 0)
		ErrPrint("Failed to ignore vconf key (%d)\n", ret);

	ret = vconf_ignore_key_changed(VCONFKEY_PM_STATE, lcd_state_cb);
	if (ret < 0)
		ErrPrint("Failed to ignore vconf key (%d)\n", ret);

	ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_POWER_OFF_STATUS, power_off_cb);
	if (ret < 0)
		ErrPrint("Failed to ignore vconf key (%d)\n", ret);

	return ret;
}

/* End of a file */