tizen 2.3 release
[apps/home/b2-clocksetting.git] / src / util.c
1 /*
2  * Copyright (c) 2010 Samsung Electronics, Inc.
3  * All rights reserved.
4  *
5  * This software is a confidential and proprietary information
6  * of Samsung Electronics, Inc. ("Confidential Information").  You
7  * shall not disclose such Confidential Information and shall use
8  * it only in accordance with the terms of the license agreement
9  * you entered into with Samsung Electronics.
10  */
11 /*
12  * util.c
13  *
14  *  Created on: Nov 21, 2013
15  *      Author: min-hoyun
16  */
17
18 #include <string.h>
19 #include <vconf.h>
20 #include <unicode/unum.h>
21 #include <fcntl.h>
22 #include "util.h"
23
24
25 char *setting_gettext(const char *s)
26 {
27         /* fisrt find in app pg */
28
29         if (s == NULL) {
30                 return "NULL";
31         }
32
33         char *p = dgettext(SETTING_PACKAGE, s);
34
35         if (!strcmp(s, p)) {    /* not found */
36                 /* find in system pkg */
37                 p = dgettext(SYSTEM_PACKAGE, s);
38         }
39         return p;
40 }
41
42 char * replace( char * str, char * orig, char * repl)
43 {
44         static char buffer[124];
45         char * ch;
46         if( !(ch = strstr(str, orig)))
47         {
48                 return str;
49         }
50         strncpy(buffer, str, ch - str);
51         buffer[ch - str] = 0;
52         sprintf(buffer + (ch - str), "%s%s", repl, ch + strlen(orig));
53
54         return buffer;
55 }
56
57 void setting_popup_back_cb(void *data, Evas_Object *obj, void *event_info)
58 {
59         appdata *ad = (appdata *)data;
60         if( ad == NULL ) {
61                 return;
62         }
63
64         if (ad->popup) {
65                 evas_object_del(ad->popup);
66                 ad->popup = NULL;
67         }
68 }
69
70 int is_connected_GM()
71 {
72         int enable = 0;
73         vconf_get_bool(VCONFKEY_WMS_WMANAGER_CONNECTED, &enable);
74
75         return enable;
76 }
77
78 bool colorstr_to_decimal(char *color, int *R, int *G, int *B)
79 {
80         DBG("_colorstr_to_decimal");
81         if (color == NULL)
82                 return false;
83
84         char *ptr;
85         long value;
86         value = strtol(color, &ptr, 16);
87         *R = (value>>16)&0xFF;
88         *G = (value>>8)&0xFF;
89         *B = value&0xFF;
90         return true;
91 }
92
93 char *_get_strnum_from_icu(int number)
94 {
95         char *locale_tmp = vconf_get_str(VCONFKEY_REGIONFORMAT);
96         char locale[32] = {0,};
97         char *p = NULL;
98         strcpy(locale, locale_tmp);
99
100         if (locale[0] != '\0') {
101                 p = strstr(locale, ".UTF-8");
102                 if (p) {
103                         *p = 0; 
104                 }    
105         }    
106
107         char *ret_str = NULL;
108         UErrorCode status = U_ZERO_ERROR;
109         
110         UNumberFormat *num_fmt;
111         UChar result[20] = { 0, };
112         char res[20] = { 0, };
113         int32_t len = (int32_t) (sizeof(result) / sizeof((result)[0]));
114
115         num_fmt = unum_open(UNUM_DEFAULT, NULL, -1, locale, NULL, &status);
116         unum_format(num_fmt, number, result, len, NULL, &status);
117
118         u_austrcpy(res, result);
119
120         unum_close(num_fmt);
121
122         ret_str = strdup(res);
123         return ret_str;
124 }
125
126 bool is_file_exist(char * file_path)
127 {
128         int fd;
129
130         if( !file_path && !strlen(file_path) )
131         {
132                 DBG("Setting - file path is wrong!!");
133                 return false;
134         }
135
136         if( (fd = open(file_path, O_RDONLY)) == -1)
137         {
138                 DBG("Setting - file(%s) do not exist!!", file_path);
139                 return false;
140         }
141
142         DBG("Setting - file exist!!");
143
144         return true;
145 }