2 * Copyright 2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #define LOG_TAG "ICON_PROVIDER"
26 #include <Elementary.h>
29 #include <glib-object.h>
40 #include <livebox-service.h>
41 #include <livebox-errno.h>
44 #include <system_settings.h>
48 #include <com-core_packet.h>
55 #define UTILITY_ADDR "/tmp/.utility.service"
56 #define DEFAULT_ICON_LAYOUT "/usr/apps/org.tizen.data-provider-slave/res/edje/icon.edj"
57 #define DEFAULT_ICON_GROUP "default"
59 #define TEXT_CLASS "tizen"
60 #define DEFAULT_FONT_SIZE -100
62 int script_handler_parse_desc(Evas_Object *edje, const char *descfile);
66 const char *socket_file;
70 .socket_file = UTILITY_ADDR,
74 #define TTL 30.0f /* Can alive only 30 seconds from the last event */
75 #define QUALITY_N_COMPRESS "quality=100 compress=1"
78 * Defined for liblivebox
80 const char *livebox_find_pkgname(const char *filename)
85 int livebox_request_update_by_id(const char *filename)
87 return LB_STATUS_ERROR_NOT_EXIST;
90 int livebox_trigger_update_monitor(const char *id, int is_pd)
92 return LB_STATUS_ERROR_INVALID;
95 static inline Evas *create_virtual_canvas(int w, int h)
97 Ecore_Evas *internal_ee;
100 // Create virtual canvas
101 internal_ee = ecore_evas_buffer_new(w, h);
103 ErrPrint("Failed to create a new canvas buffer\n");
107 ecore_evas_alpha_set(internal_ee, EINA_TRUE);
108 ecore_evas_manual_render_set(internal_ee, EINA_TRUE);
110 // Get the "Evas" object from a virtual canvas
111 internal_e = ecore_evas_get(internal_ee);
113 ecore_evas_free(internal_ee);
114 ErrPrint("Faield to get Evas object\n");
118 ecore_evas_resize(internal_ee, w, h);
119 ecore_evas_show(internal_ee);
124 static inline int flush_data_to_file(Evas *e, char *data, const char *filename, int w, int h)
128 output = evas_object_image_add(e);
130 ErrPrint("Failed to create an image object\n");
134 evas_object_image_data_set(output, NULL);
135 evas_object_image_colorspace_set(output, EVAS_COLORSPACE_ARGB8888);
136 evas_object_image_alpha_set(output, EINA_TRUE);
137 evas_object_image_size_set(output, w, h);
138 evas_object_image_smooth_scale_set(output, EINA_TRUE);
139 evas_object_image_data_set(output, data);
140 evas_object_image_data_update_add(output, 0, 0, w, h);
142 if (evas_object_image_save(output, filename, NULL, QUALITY_N_COMPRESS) == EINA_FALSE) {
143 evas_object_del(output);
144 ErrPrint("Faield to save a captured image (%s)\n", filename);
148 evas_object_del(output);
150 if (access(filename, F_OK) != 0) {
151 ErrPrint("File %s is not found\n", filename);
158 static inline int flush_to_file(Evas *e, const char *filename, int w, int h)
161 Ecore_Evas *internal_ee;
163 internal_ee = ecore_evas_ecore_evas_get(e);
165 ErrPrint("Failed to get ecore evas\n");
169 ecore_evas_manual_render(internal_ee);
171 // Get a pointer of a buffer of the virtual canvas
172 data = (void *)ecore_evas_buffer_pixels_get(internal_ee);
174 ErrPrint("Failed to get pixel data\n");
178 return flush_data_to_file(e, data, filename, w, h);
181 static inline int destroy_virtual_canvas(Evas *e)
185 ee = ecore_evas_ecore_evas_get(e);
187 ErrPrint("Failed to ecore evas object\n");
195 static int disconnected_cb(int handle, void *data)
197 s_info.client_fd = -1;
202 static inline int convert_shortcut_type_to_lb_type(int shortcut_type, char **str)
210 switch (shortcut_type) {
211 case LIVEBOX_TYPE_1x1:
213 return LB_SIZE_TYPE_1x1;
214 case LIVEBOX_TYPE_2x1:
216 return LB_SIZE_TYPE_2x1;
217 case LIVEBOX_TYPE_2x2:
219 return LB_SIZE_TYPE_2x2;
220 case LIVEBOX_TYPE_4x1:
222 return LB_SIZE_TYPE_4x1;
223 case LIVEBOX_TYPE_4x2:
225 return LB_SIZE_TYPE_4x2;
226 case LIVEBOX_TYPE_4x3:
228 return LB_SIZE_TYPE_4x3;
229 case LIVEBOX_TYPE_4x4:
231 return LB_SIZE_TYPE_4x4;
232 case LIVEBOX_TYPE_4x5:
234 return LB_SIZE_TYPE_4x5;
235 case LIVEBOX_TYPE_4x6:
237 return LB_SIZE_TYPE_4x6;
238 case LIVEBOX_TYPE_EASY_1x1:
240 return LB_SIZE_TYPE_EASY_1x1;
241 case LIVEBOX_TYPE_EASY_3x1:
243 return LB_SIZE_TYPE_EASY_3x1;
244 case LIVEBOX_TYPE_EASY_3x3:
246 return LB_SIZE_TYPE_EASY_3x3;
249 return LB_SIZE_TYPE_UNKNOWN;
253 static struct packet *icon_create(pid_t pid, int handle, const struct packet *packet)
256 const char *edje_path;
258 const char *desc_file;
269 ret = packet_get(packet, "sssis", &edje_path, &group, &desc_file, &size_type, &output);
271 ErrPrint("Invalid parameters");
276 if (!edje_path || !strlen(edje_path)) {
277 edje_path = DEFAULT_ICON_LAYOUT;
280 size_type = convert_shortcut_type_to_lb_type(size_type, &size_str);
281 if (!group || !strlen(group)) {
282 snprintf(_group, sizeof(_group), DEFAULT_ICON_GROUP",%s", size_str);
285 DbgPrint("Selected layout: %s(%s)\n", edje_path, group);
287 ret = livebox_service_get_size(size_type, &w, &h);
288 if (ret != LB_STATUS_SUCCESS) {
289 ErrPrint("Unable to get size(%d): %d\n", size_type, ret);
293 e = create_virtual_canvas(w, h);
295 ErrPrint("Unable to create a canvas: %dx%d\n", w, h);
296 ret = LB_STATUS_ERROR_FAULT;
300 parent = evas_object_rectangle_add(e);
302 ErrPrint("Unable to create a parent\n");
303 destroy_virtual_canvas(e);
304 ret = LB_STATUS_ERROR_FAULT;
308 evas_object_resize(parent, w, h);
309 evas_object_color_set(parent, 0, 0, 0, 0);
310 evas_object_show(parent);
312 edje = elm_layout_add(parent);
314 ErrPrint("Unable to add an edje object\n");
315 evas_object_del(parent);
316 destroy_virtual_canvas(e);
320 if (elm_layout_file_set(edje, edje_path, group) == EINA_FALSE) {
322 err = edje_object_load_error_get(elm_layout_edje_get(edje));
323 ErrPrint("Uanble to load an edje %s(%s) - %s\n", edje_path, group, edje_load_error_str(err));
324 evas_object_del(edje);
325 evas_object_del(parent);
326 destroy_virtual_canvas(e);
330 evas_object_resize(edje, w, h);
331 evas_object_show(edje);
333 if (script_handler_parse_desc(edje, desc_file) != LB_STATUS_SUCCESS) {
334 ErrPrint("Unable to parse the %s\n", desc_file);
337 flush_to_file(e, output, w, h);
338 evas_object_del(edje);
339 evas_object_del(parent);
340 destroy_virtual_canvas(e);
344 /* Desc file should be deleted if it fails to create an icon image */
345 if (unlink(desc_file) < 0) {
346 ErrPrint("unlink(%s): %s\n", desc_file, strerror(errno));
350 return packet_create_reply(packet, "i", ret);
353 static inline int client_init(void)
356 struct packet *packet;
357 static struct method service_table[] = {
359 .cmd = "icon_create",
360 .handler = icon_create,
368 com_core_add_event_callback(CONNECTOR_DISCONNECTED, disconnected_cb, NULL);
370 s_info.client_fd = com_core_packet_client_init(s_info.socket_file, 0, service_table);
371 if (s_info.client_fd < 0) {
372 ErrPrint("Failed to make a connection to the master\n");
376 packet = packet_create_noack("service_register", "");
378 ErrPrint("Failed to build a packet\n");
382 ret = com_core_packet_send_only(s_info.client_fd, packet);
383 DbgPrint("Service register sent: %d\n", ret);
384 packet_destroy(packet);
386 com_core_packet_client_fini(s_info.client_fd);
387 s_info.client_fd = -1;
393 DbgPrint("Server FD: %d\n", s_info.client_fd);
397 static inline void client_fini(void)
399 if (s_info.client_fd < 0) {
400 DbgPrint("Client is not initiated\n");
404 com_core_packet_client_fini(s_info.client_fd);
405 s_info.client_fd = -1;
408 static void update_font_cb(void *data)
413 list = edje_text_class_list();
414 DbgPrint("List: %p\n", list);
416 EINA_LIST_FREE(list, text) {
417 if (!strncasecmp(text, TEXT_CLASS, strlen(TEXT_CLASS))) {
418 DbgPrint("Update text class %s (%s, %d)\n", text, s_info.font_name, DEFAULT_FONT_SIZE);
419 edje_text_class_del(text);
420 edje_text_class_set(text, s_info.font_name, DEFAULT_FONT_SIZE);
422 DbgPrint("Skip text class %s\n", text);
426 DbgPrint("New (%s, %d)\n", s_info.font_name, DEFAULT_FONT_SIZE);
427 edje_text_class_set(TEXT_CLASS, s_info.font_name, DEFAULT_FONT_SIZE);
431 static void font_changed_cb(keynode_t *node, void *user_data)
435 if (s_info.font_name) {
436 font_name = vconf_get_str("db/setting/accessibility/font_name");
438 ErrPrint("Invalid font name (NULL)\n");
442 if (!strcmp(s_info.font_name, font_name)) {
443 DbgPrint("Font is not changed (Old: %s(%p) <> New: %s(%p))\n", s_info.font_name, s_info.font_name, font_name, font_name);
448 DbgPrint("Release old font name: %s(%p)\n", s_info.font_name, s_info.font_name);
449 free(s_info.font_name);
454 ret = system_settings_get_value_string(SYSTEM_SETTINGS_KEY_FONT_TYPE, &font_name);
455 if (ret != SYSTEM_SETTINGS_ERROR_NONE || !font_name) {
456 ErrPrint("system settings: %d, font_name[%p]\n", ret, font_name);
461 s_info.font_name = font_name;
462 DbgPrint("Font name is changed to %s(%p)\n", s_info.font_name, s_info.font_name);
464 update_font_cb(NULL);
467 static bool app_create(void *data)
471 if (client_init() < 0) {
472 ErrPrint("Unable to initiate the client\n");
477 * Send a request to reigister as a service.
479 ret = vconf_notify_key_changed("db/setting/accessibility/font_name", font_changed_cb, NULL);
480 DbgPrint("System font is changed: %d\n", ret);
482 font_changed_cb(NULL, NULL);
486 static void app_terminate(void *data)
490 ret = vconf_ignore_key_changed("db/setting/accessibility/font_name", font_changed_cb);
491 DbgPrint("Remove font change callback: %d\n", ret);
495 free(s_info.font_name);
496 s_info.font_name = NULL;
500 static void app_pause(void *data)
502 /* Will not be called */
506 static void app_resume(void *data)
508 /* Will not be called */
512 static void app_service(service_h service, void *data)
516 int main(int argc, char *argv[])
519 app_event_callback_s event_callback;
521 event_callback.create = app_create;
522 event_callback.terminate = app_terminate;
523 event_callback.pause = app_pause;
524 event_callback.resume = app_resume;
525 event_callback.service = app_service;
526 event_callback.low_memory = NULL;
527 event_callback.low_battery = NULL;
528 event_callback.device_orientation = NULL;
529 event_callback.language_changed = NULL;
530 event_callback.region_format_changed = NULL;
532 ret = app_efl_main(&argc, &argv, &event_callback, NULL);