11 #include <sys/socket.h>
12 #include <systemd/sd-login.h>
15 #define EFL_CONFIG_SOCK_PATH "/run/user_ext/%d"
16 #define EFL_CONFIG_SOCKET_FILE ".efl-config.sock"
24 #include <libxml/xmlmemory.h>
25 #include <libxml/parser.h>
27 #include <fontconfig/fontconfig.h>
29 #include <Elementary.h>
31 #include <Ecore_Evas.h>
33 #include <pkgmgr-info.h>
35 #include <system_settings.h>
36 #include <system_settings_private.h>
38 #include <tzplatform_config.h>
39 #include <system_settings_util.h>
42 #define SMALL_FONT_DPI (-90)
45 #define SMALL_FONT_DPI (-80)
47 #define MIDDLE_FONT_DPI (-100)
49 #define LARGE_FONT_DPI (-110)
52 #define LARGE_FONT_DPI (-150)
54 #define HUGE_FONT_DPI (-190)
55 #define GIANT_FONT_DPI (-250)
57 #define SETTING_FONT_PRELOAD_FONT_PATH _TZ_SYS_RO_SHARE"/fonts"
58 #define SETTING_FONT_DOWNLOADED_FONT_PATH _TZ_SYS_SHARE"/fonts"
60 #define SETTING_FONT_CONF_FILE _TZ_SYS_ETC"/fonts/conf.avail/99-tizen.conf"
62 #define SETTING_FONT_TIZEN_FONT_ALIAS "Tizen"
63 #define SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS "TizenDefaultFont"
65 static int __font_size_get();
67 /* Returned family name should be free'd manually. */
68 char *__get_main_font_family_name_by_alias(char *alias)
71 FcFontSet *set = NULL;
72 FcPattern *pat = NULL;
73 FcConfig *font_config = NULL;
74 FcChar8 *family = NULL;
78 font_config = FcInitLoadConfigAndFonts();
79 if (font_config == NULL)
82 pat = FcPatternBuild(0, FC_FAMILY, FcTypeString, alias, (char *)0);
85 if (font_config != NULL) {
86 FcConfigDestroy(font_config);
92 FcConfigSubstitute(font_config, pat, FcMatchPattern);
93 FcDefaultSubstitute(pat);
96 set = FcFontSort(font_config, pat, FcTrue, NULL, &res);
98 if (set != NULL && (set->nfont > 0)) {
99 FcPatternGetString(set->fonts[0], FC_FAMILY, 0, &family);
100 ret = g_strdup((char *)family);
102 FcFontSetDestroy(set);
107 FcFontSetDestroy(set);
112 FcPatternDestroy(pat);
116 if (font_config != NULL) {
117 FcConfigDestroy(font_config);
124 /* LCOV_EXCL_START */
125 bool __is_supported_image_type_load(char *path)
132 ee = ecore_evas_new(NULL, 0, 0, 100, 100, NULL);
133 evas = ecore_evas_get(ee);
135 Evas_Object *img = evas_object_image_add(evas);
136 evas_object_image_file_set(img, path, NULL);
137 Evas_Load_Error ret = evas_object_image_load_error_get(img);
140 if (ret == EVAS_LOAD_ERROR_NONE) {
141 SETTING_TRACE("%s - OK", path);
144 SETTING_TRACE("%s - NO", path);
153 char *_get_cur_font()
155 return __get_main_font_family_name_by_alias(SETTING_FONT_TIZEN_FONT_ALIAS);
158 /* LCOV_EXCL_START */
159 void font_config_set_notification()
164 Ecore_X_Window ecore_win = ecore_x_window_root_first_get();
165 Ecore_X_Atom atom = ecore_x_atom_get("FONT_TYPE_change");
166 ecore_x_window_prop_string_set(ecore_win, atom, "tizen");
171 /* LCOV_EXCL_START */
172 int __is_available_font(char *font_name)
175 FcObjectSet *os = NULL;
176 FcFontSet *fs = NULL;
177 FcPattern *pat = NULL;
178 FcConfig *font_config = NULL;
182 if (font_name == NULL)
185 font_config = FcInitLoadConfigAndFonts();
187 /*setting_retvm_if(font_config == NULL, NULL, "Failed: FcInitLoadConfigAndFonts"); */
189 char *locale = setlocale(0, NULL);
191 pat = FcPatternCreate();
193 os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_FAMILYLANG, (char *) 0);
196 fs = FcFontList(font_config, pat, os);
197 FcObjectSetDestroy(os);
202 FcPatternDestroy(pat);
208 SETTING_TRACE("fs->nfont = %d", fs->nfont);
210 for (j = 0; j < fs->nfont; j++) {
211 FcChar8 *family = NULL;
212 FcChar8 *file = NULL;
214 if (FcPatternGetString(fs->fonts[j], FC_FILE, 0, &file) == FcResultMatch) {
215 int preload_path_len = strlen(SETTING_FONT_PRELOAD_FONT_PATH);
216 int download_path_len = strlen(SETTING_FONT_DOWNLOADED_FONT_PATH);
218 if (file && (!strncmp((const char *)file, SETTING_FONT_PRELOAD_FONT_PATH, preload_path_len)
219 || !strncmp((const char *)file, SETTING_FONT_DOWNLOADED_FONT_PATH, download_path_len))) {
220 char *family_result = NULL;
221 FcChar8 *lang = NULL;
223 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
226 if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
229 family_result = (char *)family;
231 /* Find proper family name for current locale. */
232 while (locale && family && lang) {
233 if (!strncmp(locale, (char *)lang, strlen((char *)lang))) {
234 family_result = (char *)family;
238 /* I will set english as default family language. */
239 /* If there is no proper family language for current locale, */
240 /* we have to show the english family name. */
241 if (!strcmp((char *)lang, (char *)"en")) {
242 family_result = (char *)family;
245 if (FcPatternGetString(fs->fonts[j], FC_FAMILY, id, &family) != FcResultMatch) {
248 if (FcPatternGetString(fs->fonts[j], FC_FAMILYLANG, id, &lang) != FcResultMatch) {
254 SETTING_TRACE("-------- FONT - family_result = %s", (char *)family_result);
255 if (strcmp(family_result, font_name) == 0) {
263 FcFontSetDestroy(fs);
266 FcConfigDestroy(font_config);
273 char *_get_default_font()
275 return __get_main_font_family_name_by_alias(SETTING_FONT_TIZEN_DEFAULT_FONT_ALIAS);
278 bool _is_in_system_session()
284 ret = sd_pid_get_slice(getpid(), &slice);
285 if (0 <= ret && slice) {
286 if (0 == strncmp(slice, "system.slice", strlen("system.slice"))) {
291 SETTING_TRACE("sd_pid_get_slice() Fail(%d)", ret);
298 bool _get_active_uid(uid_t *uid)
301 int active_user_count = 0;
302 uid_t *active_user_list = NULL;
304 active_user_count = sd_get_active_uids(&active_user_list);
305 /* the number of active users is 1 in tizen3.0 */
306 if (1 == active_user_count && active_user_list) {
307 *uid = active_user_list[0];
308 SETTING_TRACE("active uid = %d", *uid);
310 SETTING_TRACE("sd_get_active_uids() Fail(%d)", active_user_count);
311 free(active_user_list);
319 _efl_config_set(char *msg)
323 char sock_file[1024] = {0};
324 uid_t active_uid = getuid();
327 if (_is_in_system_session() == true) {
328 if (_get_active_uid(&active_uid) == false) {
329 SETTING_TRACE("get active uid fail");
334 snprintf(sock_file, sizeof(sock_file), EFL_CONFIG_SOCK_PATH"/%s",
336 EFL_CONFIG_SOCKET_FILE);
340 struct sockaddr_un server_addr;
342 fd = socket(PF_UNIX, SOCK_STREAM, 0);
344 SETTING_TRACE("socket[%d] error :%d", fd, errno);
348 flags = fcntl(fd, F_GETFL, 0);
351 r = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
353 SETTING_TRACE("fcntl fail : %d", errno);
355 bzero(&server_addr, sizeof(server_addr));
356 server_addr.sun_family = AF_UNIX;
357 snprintf(server_addr.sun_path, sizeof(server_addr.sun_path), "%s",
360 r = connect(fd, (struct sockaddr *)&server_addr, sizeof(server_addr));
362 SETTING_TRACE("connect error : %d, %d", r, errno);
366 size = write(fd, msg, strlen(msg));
368 SETTING_TRACE("write fail : %d", errno);
377 /* LCOV_EXCL_START */
378 bool font_config_set(char *font_name)
381 char buf[255] = { 0 };
382 int font_size = __font_size_get();
385 snprintf(buf, sizeof(buf), "font_name: %s, font_size: %d", font_name, font_size);
386 ret = _efl_config_set(buf);
392 /* LCOV_EXCL_START */
393 void __font_size_set()
396 char buf[255] = { 0 };
397 int font_size = __font_size_get();
398 char *font_name = _get_cur_font();
400 snprintf(buf, sizeof(buf), "font_name: %s, font_size: %d", font_name, font_size);
401 _efl_config_set(buf);
407 /* LCOV_EXCL_START */
408 static int __font_size_get()
413 int vconf_value = -1;
414 if (vconf_get_int(VCONFKEY_SETAPPL_ACCESSIBILITY_FONT_SIZE, &vconf_value)) {
418 switch (vconf_value) {
419 case SYSTEM_SETTINGS_FONT_SIZE_SMALL:
420 font_size = SMALL_FONT_DPI;
422 case SYSTEM_SETTINGS_FONT_SIZE_NORMAL:
423 font_size = MIDDLE_FONT_DPI;
425 case SYSTEM_SETTINGS_FONT_SIZE_LARGE:
426 font_size = LARGE_FONT_DPI;
428 case SYSTEM_SETTINGS_FONT_SIZE_HUGE:
429 font_size = HUGE_FONT_DPI;
431 case SYSTEM_SETTINGS_FONT_SIZE_GIANT:
432 font_size = GIANT_FONT_DPI;
435 font_size = MIDDLE_FONT_DPI;