4 * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
22 #include <notification.h>
23 #include <notification_status_internal.h>
33 #define STR_BUF_SIZE 256
34 #define QUEUE_TIMEOUT 1
35 #define QUEUE_TIMEOUT2 5
38 #define MESSAGE_LINE1 "message.text"
39 #define MESSAGE_LINE2 "message.text2"
42 typedef struct _str_buf {
49 static int msg_type = 0;
50 static Ecore_Timer *msg_timer = NULL;
51 static Ecore_Timer *ani_temp_timer = NULL;
53 extern int current_angle;
54 static int block_width = 0;
55 static int string_width = 0;
56 static char* message_buf = NULL;
57 static Ecore_Timer *retry_timer=NULL;
58 static int msg_retry = 0;
59 static struct appdata *app_data = NULL;
60 static Ecore_Timer *queue_timer=NULL;
61 static int current_buf_index = 0;
62 static int current_buf_cnt = 0;
63 static MsgBuf msg_queue[QUEUE_SIZE];
67 static Eina_Bool _ani_temp_timeout_cb(void *data)
69 retif(data == NULL, ECORE_CALLBACK_CANCEL, "Invalid parameter!");
73 ecore_timer_del(ani_temp_timer);
74 ani_temp_timer = NULL;
77 return ECORE_CALLBACK_CANCEL;
82 void start_temp_ani_timer(void* data)
84 retif(data == NULL, , "Invalid parameter!");
85 win_info* win = (win_info*)data;
87 if(ani_temp_timer != NULL)
89 ecore_timer_del(ani_temp_timer);
90 ani_temp_timer = NULL;
92 ani_temp_timer = ecore_timer_add(0.3, (Ecore_Task_Cb)_ani_temp_timeout_cb, (void*)win);
98 static void _hide_message(void* data)
100 retif(data == NULL, , "Invalid parameter!");
101 win_info* win = NULL;
102 win = (win_info*)data;
104 box_update_display(win);
106 start_temp_ani_timer(data);
107 util_signal_emit_by_win(win,"message.hide", "indicator.prog");
112 static void _hide_message_all(void* data)
114 retif(data == NULL, , "Invalid parameter!");
116 util_signal_emit(data,"message.line2.hide.noeffect","indicator.prog");
121 static void _show_message(void* data)
123 retif(data == NULL, , "Invalid parameter!");
124 win_info* win = NULL;
125 win = (win_info*)data;
126 struct appdata* ad = (struct appdata*)win->data;
128 start_temp_ani_timer(data);
129 if(ad->opacity_mode==INDICATOR_OPACITY_TRANSPARENT)
132 util_signal_emit_by_win(win,"message.show.noeffect", "indicator.prog");
133 evas_object_show(win->win);
137 util_signal_emit_by_win(win,"message.show", "indicator.prog");
143 static void _show_message_line2(void* data)
145 retif(data == NULL, , "Invalid parameter!");
146 win_info* win = NULL;
147 win = (win_info*)data;
151 util_signal_emit_by_win(win,"message.line2.show", "indicator.prog");
157 static Eina_Bool _msg_timeout_cb(void *data)
159 retif(data == NULL, ECORE_CALLBACK_CANCEL, "Invalid parameter!");
161 win_info* win = (win_info*)data;
167 return ECORE_CALLBACK_CANCEL;
169 else if(msg_type == 2)
175 ecore_timer_del(msg_timer);
177 msg_timer = ecore_timer_add(3, (Ecore_Task_Cb)_msg_timeout_cb, (void*)win);
178 _show_message_line2(win);
179 return ECORE_CALLBACK_CANCEL;
186 return ECORE_CALLBACK_CANCEL;
192 static Eina_Bool _retry_timeout_cb(void *data)
194 retif(data == NULL, EINA_TRUE , "Invalid parameter!");
196 if(message_buf!=NULL)
202 if (retry_timer!=NULL)
204 ecore_timer_del(retry_timer);
213 static int __get_block_width(void* data, const char* part)
215 Evas_Object * eo = NULL;
218 retif(data == NULL,-1, "Invalid parameter!");
219 retif(part == NULL,-1, "Invalid parameter!");
221 win_info* win = (win_info*)data;
223 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
225 evas_object_geometry_get(eo, NULL, NULL, &geo_dx, &geo_dy);
232 static int __get_string_width(void* data, const char* part)
234 Evas_Object * eo = NULL;
237 retif(data == NULL,-1, "Invalid parameter!");
238 retif(part == NULL,-1, "Invalid parameter!");
240 win_info* win = (win_info*)data;
242 eo = (Evas_Object *) edje_object_part_object_get(elm_layout_edje_get(win->layout), part);
244 evas_object_textblock_size_formatted_get(eo, &text_dx, &text_dy);
251 static void __handle_2line(win_info* win,char* origin, char* part1, char* part2)
253 retif(origin == NULL, , "Invalid parameter!");
254 retif(part1 == NULL, , "Invalid parameter!");
255 retif(part2 == NULL, , "Invalid parameter!");
257 Eina_Unicode *uni_out = NULL;
258 Eina_Unicode buf[STR_BUF_SIZE] = {0,};
261 Eina_Unicode temp1[STR_BUF_SIZE] = {0,};
262 Eina_Unicode temp2[STR_BUF_SIZE] = {0,};
268 uni_out = eina_unicode_utf8_to_unicode(origin, &len);
270 if(len >= STR_BUF_SIZE)
272 len2 = STR_BUF_SIZE-1;
279 eina_unicode_strncpy(buf,uni_out,len2);
281 int exceed_index = len2 * block_width / string_width;
286 Eina_Unicode temp1[STR_BUF_SIZE] = {0,};
290 eina_unicode_strncpy(temp1,buf,exceed_index);
291 out1 = eina_unicode_unicode_to_utf8(temp1,&char_len1);
292 util_part_text_emit_by_win(win,"message.text.compare", out1);
294 width = __get_string_width(win,"message.text.compare");
296 if(width > block_width)
298 exceed_index = exceed_index -1;
299 DBG("reduce exceed index(%d)",exceed_index,width);
313 Eina_Unicode temp1[STR_BUF_SIZE] = {0,};
317 eina_unicode_strncpy(temp1,buf,exceed_index);
318 out1 = eina_unicode_unicode_to_utf8(temp1,&char_len1);
319 util_part_text_emit_by_win(win,"message.text.compare", out1);
321 width = __get_string_width(win,"message.text.compare");
323 if(width < block_width)
325 exceed_index = exceed_index +1;
326 DBG("increase exceed index(%d)",exceed_index,width);
330 exceed_index = exceed_index -1;
344 ERR("INDEX %d",exceed_index);
348 int i = exceed_index;
362 Eina_Unicode *temp3 = NULL;
363 eina_unicode_strncpy(temp1,buf,index);
364 temp3 = &(buf[index]);
365 eina_unicode_strncpy(temp2,temp3,len2-index);
369 Eina_Unicode *temp3 = NULL;
370 eina_unicode_strncpy(temp1,buf,exceed_index);
371 temp3 = &(buf[exceed_index]);
372 eina_unicode_strncpy(temp2,temp3,len2-exceed_index);
375 out1 = eina_unicode_unicode_to_utf8(temp1,&char_len1);
376 out2 = eina_unicode_unicode_to_utf8(temp2,&char_len2);
378 if(char_len1>=STR_BUF_SIZE)
379 char_len1 = STR_BUF_SIZE-1;
380 if(char_len2>=STR_BUF_SIZE)
381 char_len2 = STR_BUF_SIZE-1;
382 strncpy(part1,out1,char_len1);
383 strncpy(part2,out2,char_len2);
396 static void _handle_message_by_win(char *message, void *data)
398 win_info* win = NULL;
399 char part1[256] = {0,};
400 char part2[256] = {0,};
404 retif(message == NULL, , "Invalid parameter!");
405 retif(data == NULL, , "Invalid parameter!");
411 ecore_timer_del(msg_timer);
415 SECURE_DBG("message %s", message);
417 temp = strdup(message);
419 util_char_replace(temp,'\n',' ');
421 text = evas_textblock_text_utf8_to_markup(NULL, temp);
429 block_width = __get_block_width(win,"message.text");
430 util_part_text_emit_by_win(win,"message.text.compare", text);
431 string_width = __get_string_width(win,"message.text.compare");
433 if(block_width > string_width)
442 DBG("msg_type %d", msg_type);
449 util_part_text_emit_by_win(win,"message.text", text);
450 util_send_status_message_start(win,2.5);
455 __handle_2line(win,text,part1,part2);
456 util_part_text_emit_by_win(win,"message.text", part1);
457 util_part_text_emit_by_win(win,"message.line2.text", part2);
458 util_send_status_message_start(win,5);
464 msg_timer = ecore_timer_add(time_clk, (Ecore_Task_Cb)_msg_timeout_cb, (void*)win);
472 static void __message_callback(const char *message, void *data)
474 struct appdata *ad = NULL;
475 win_info* win = NULL;
482 char buf[256] = {0,};
483 strncpy(buf,message,256-1);
484 #ifdef _SUPPORT_SCREEN_READER2
485 indicator_service_tts_play(buf);
488 if(message_buf!=NULL)
494 message_buf = strdup(message);
497 _hide_message_all(data);
500 _handle_message_by_win(message_buf,win);
502 if(retry_timer!=NULL)
504 ecore_timer_del(retry_timer);
506 retry_timer = ecore_timer_add(0.5, (Ecore_Task_Cb)_retry_timeout_cb, (void*)win);
512 static void _buf_timeout_callback(void* data)
515 if(current_buf_index<QUEUE_SIZE)
516 if(msg_queue[current_buf_index].data!=NULL)
518 DBG("index %d,%s",current_buf_index,msg_queue[current_buf_index].data);
519 __message_callback(msg_queue[current_buf_index].data,data);
520 if(msg_queue[current_buf_index].data!=NULL)
522 free(msg_queue[current_buf_index].data);
523 msg_queue[current_buf_index].data = NULL;
525 if(current_buf_index+1<QUEUE_SIZE)
527 if(msg_queue[current_buf_index+1].data!=NULL)
529 if(queue_timer!=NULL)
531 ecore_timer_del(queue_timer);
534 current_buf_index = current_buf_index+1;
535 queue_timer = ecore_timer_add(msg_queue[current_buf_index].timer_val, (Ecore_Task_Cb)_buf_timeout_callback, data);
541 if(queue_timer!=NULL)
543 ecore_timer_del(queue_timer);
547 current_buf_index = 0;
548 DBG("quit buffering..");
553 static void __buffer_msg_callback(const char *message, void *data)
555 struct appdata *ad = NULL;
556 retif(data == NULL, , "Invalid parameter!");
559 win_info *win = NULL;
564 block_width = __get_block_width(win,"message.text");
565 util_part_text_emit_by_win(win,"message.text.compare", message);
566 string_width = __get_string_width(win,"message.text.compare");
568 if(block_width > string_width)
570 timer_val = QUEUE_TIMEOUT;
574 timer_val = QUEUE_TIMEOUT2;
577 if(queue_timer!=NULL)
579 if(current_buf_cnt>=QUEUE_SIZE)
584 SECURE_DBG("buffering... %d,%s",current_buf_cnt,message);
585 if(msg_queue[current_buf_cnt].data!=NULL)
587 free(msg_queue[current_buf_cnt].data);
588 msg_queue[current_buf_cnt].data = NULL;
590 msg_queue[current_buf_cnt].data = strdup(message);
591 msg_queue[current_buf_cnt].index = current_buf_cnt;
592 msg_queue[current_buf_cnt].timer_val = timer_val;
597 queue_timer = ecore_timer_add(timer_val, (Ecore_Task_Cb)_buf_timeout_callback, data);
598 __message_callback(message,data);
603 int indicator_message_disp_check(void)
605 if (msg_timer != NULL)
613 int message_ani_playing_check(void)
615 if(ani_temp_timer != NULL)
623 int indicator_message_retry_check(void)
625 if(retry_timer!=NULL)
633 void indicator_message_display_trigger(void)
635 win_info* win = NULL;
642 DBG("retry message");
646 win = &(app_data->win);
647 _handle_message_by_win(message_buf,win);
653 int indicator_message_init(void *data)
657 for(i=0;i<QUEUE_SIZE;i++)
659 memset(&msg_queue[i],0x00,sizeof(MsgBuf));
661 ret = notification_status_monitor_message_cb_set(__buffer_msg_callback, data);
670 int indicator_message_fini(void)
674 ret = notification_status_monitor_message_cb_unset();