[LICENSE] change to Flora-1.1 license
[profile/tv/apps/native/screen-reader.git] / src / screen_reader_vconf.c
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * This file is a modified version of BSD licensed file and
5  * licensed under the Flora License, Version 1.1 (the License);
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *     http://floralicense.org/license/
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an AS IS BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * Please, see the LICENSE file for the original copyright owner and
18  * license.
19  */
20
21 #include <Elementary.h>
22 #include <vconf.h>
23 #include "screen_reader_vconf.h"
24 #include "screen_reader_spi.h"
25 #include "logger.h"
26
27 #ifdef RUN_IPC_TEST_SUIT
28 #include "test_suite/test_suite.h"
29 #endif
30
31 #ifdef LOG_TAG
32 #undef LOG_TAG
33 #endif
34 #define LOG_TAG "SCREEN READER VCONF"
35
36
37 keylist_t *keys = NULL;
38
39 // ------------------------------ vconf callbacks----------------------
40
41 void app_termination_cb(keynode_t *node, void *user_data)
42 {
43    DEBUG("START");
44    DEBUG("Application terminate %d", !node->value.i);
45
46    Service_Data *service_data = user_data;
47    service_data->run_service = node->value.i;
48
49    if(service_data->run_service == 0)
50       {
51          elm_exit();
52       }
53
54    DEBUG("END");
55 }
56
57 void display_language_cb(keynode_t *node, void *user_data)
58 {
59    DEBUG("START");
60    DEBUG("Trying to set LC_MESSAGES to: %s", node->value.s);
61
62    Service_Data *sd = user_data;
63    snprintf(sd->display_language, LANGUAGE_NAME_SIZE, "%s", node->value.s);
64    //to make gettext work
65    setenv("LC_MESSAGES", sd->display_language, 1);
66
67    DEBUG("END");
68 }
69
70 // --------------------------------------------------------------------
71
72 int get_key_values(Service_Data *sd)
73 {
74    DEBUG("START");
75    int to_ret = 0;
76
77    char *display_language = vconf_get_str("db/menu_widget/language");
78    if (display_language)
79      {
80         snprintf(sd->display_language, LANGUAGE_NAME_SIZE, "%s", display_language);
81         //to make gettext work
82         setenv("LC_MESSAGES", sd->display_language, 1);
83         free(display_language);
84      }
85    else
86      WARNING("Can't get db/menu_widget/language value");
87
88    DEBUG("SCREEN READER DATA SET TO: Display_Language: %s, Tracking signal: %s;",
89          sd->display_language, sd->tracking_signal_name);
90
91    DEBUG("END");
92    return to_ret;
93 }
94
95 int _set_vconf_callback_and_print_message_on_error_and_return_error_code(const char *in_key, vconf_callback_fn cb,
96                                                     void *user_data)
97 {
98     int ret = vconf_notify_key_changed(in_key, cb, user_data);
99     if(ret != 0)
100           DEBUG("Could not add notify callback to %s key", in_key);
101
102     return ret;
103 }
104
105 bool vconf_init(Service_Data *service_data)
106 {
107    DEBUG( "--------------------- VCONF_init START ---------------------");
108    int ret = 0;
109
110    if(vconf_set(keys))
111       {
112          DEBUG("nothing is written\n");
113       }
114    else
115       {
116          DEBUG("everything is written\n");
117       }
118
119    vconf_keylist_free(keys);
120    // ----------------------------------------------------------------------------------
121
122    ret = get_key_values(service_data);
123    if(ret != 0)
124       {
125          DEBUG("Could not set data from vconf: %d", ret);
126       }
127
128    _set_vconf_callback_and_print_message_on_error_and_return_error_code("db/menu_widget/language", display_language_cb, service_data);
129
130    DEBUG( "---------------------- VCONF_init END ----------------------\n\n");
131    return true;
132 }