Tizen 2.0 Release
[apps/home/settings.git] / src / conf_util / setting_confutil.c
1 /*
2  * setting_confutil
3  *
4  *
5  *
6         $ setting_confutil                              // create a cfg file in default
7         $ setting_confutil export               // export current status to a xml file
8         $ setting_confutil timezone_init        // timezone init
9  */
10 #include <stdio.h>
11
12 #include <setting-cfg.h>
13 #include <setting-debug.h>
14 #include <stdio.h>
15 #include <Elementary.h>
16 #include <setting-common-general-func.h>
17 #include <setting-common-data-slp-setting.h>
18 #include <unistd.h>
19 #include <system_settings.h>
20
21 #include <stdio.h>
22 #include <libxml/parser.h>
23 #include <libxml/tree.h>
24
25 static char* get_timezone();
26
27 static void get_gmt_offset(char *str_buf, int size)
28 {
29         // timezone string +/-<n> ex. +9, -1
30         time_t t = time(0);     // get unix time. sec.
31
32         struct tm* data;
33         data = localtime(&t);           // save time as structure.
34         setting_retm_if(!data, "data is NULL");
35         data->tm_isdst = 0;                     // summer time, not applied.
36         time_t a = mktime(data);
37
38         data = gmtime(&a);
39         data->tm_isdst = 0;                     // summer time, not applied.
40         time_t b = mktime(data);
41
42         int gmtoffset_hour = (a-b)/3600;        // result : hour.
43         int gmtoffset_min = ((a-b)%3600)/60;    // result : min.
44         if(gmtoffset_min != 0) {
45                 gmtoffset_min = 30;
46         }
47
48         snprintf(str_buf, size, "%+d:%02u", gmtoffset_hour, gmtoffset_min);
49         SETTING_TRACE("szTimezone is of a valid format: GMT: %s", str_buf);
50 }
51
52
53 void timezone_init()
54 {
55         char* tzpath = get_timezone();
56         //printf(">>> time zone : %s \n", tzpath+20);
57         int ret = vconf_set_str(VCONFKEY_SETAPPL_TIMEZONE_INT, tzpath+20);
58         if (ret != 0) {
59                 SETTING_TRACE("fail to set vconf");
60         }
61         char str_buf[256] = {0, };
62         get_gmt_offset(str_buf, 256);
63         printf(">>> time zone GMT string : %s \n", str_buf);
64 }
65
66 void get_current_font()
67 {
68         char *value = NULL;
69         int retcode = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &value);
70         if (retcode != 0) {
71                 SETTING_TRACE("fail to set SYSTEM_SETTINGS_KEY_FONT_TYPE");
72         }
73         printf(">>> get current font type : %s \n", value);
74 }
75
76 int status_fp(int total, int current, void* data)
77 {
78         SETTING_TRACE(">> total : %d ---- current : %d ", total, current);
79         return 0;
80 }
81
82
83 /**
84 sh-4.1# /usr/apps/org.tizen.setting/bin/setting_conf_util timezone_check
85 debug level init 1(1)
86 >>> time zone : /usr/share/zoneinfo/Asia/Seoul
87 */
88 int main(int argc, char* argv[])
89 {
90         g_type_init ();
91         int ret;
92         // exporting - current status
93         if ( (argc == 2) && (0 == strcmp(argv[1], "import"))) {
94                 // void setting_import(status_handler fp, void* data)
95
96                 setting_import(status_fp, NULL);
97
98         } else if ( (argc == 2) && (0 == strcmp(argv[1], "export"))) {
99                 setting_export(status_fp, NULL);
100         } else if ( (argc == 2) && (0 == strcmp(argv[1], "timezone_init"))) {
101                 timezone_init();
102         } else if ( (argc == 2) && (0 == strcmp(argv[1], "get_current_font"))) {
103                 get_current_font();
104         } else {
105                 // cfg create
106                 // TRUE or FALSE
107                 ret = setting_cfg_create();
108         }
109         return 0;
110 }
111
112 // automatic
113 static char* get_timezone()
114 {
115         SETTING_TRACE_BEGIN;
116
117     enum { BUFFERSIZE = 1024 };
118     char buf[BUFFERSIZE];
119     ssize_t len = readlink("/opt/etc/localtime", buf, sizeof(buf)-1);
120
121     if (len != -1) {
122         buf[len] = '\0';
123     }
124     else {
125         /* handle error condition */
126     }
127         return g_strdup(buf);
128 }
129