2 * Copyright 2012 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.
20 #include "quickpanel-ui.h"
22 #include "list_util.h"
23 #include "quickpanel_def.h"
24 #include "noti_list_item.h"
25 #include "noti_node.h"
27 #include "noti_util.h"
28 #ifdef QP_ANIMATED_IMAGE_ENABLE
29 #include "animated_image.h"
32 #define QP_DEFAULT_ICON ICONDIR"/quickpanel_icon_default.png"
35 static Evas_Object *_check_duplicated_progress_loading(Evas_Object *obj, const char *part, const char *style_name) {
36 Evas_Object *old_content = NULL;
37 const char *old_style_name = NULL;
39 retif(obj == NULL, NULL, "Invalid parameter!");
40 retif(part == NULL, NULL, "Invalid parameter!");
41 retif(style_name == NULL, NULL, "Invalid parameter!");
45 old_content = elm_object_part_content_get(obj, part);
46 if (old_content != NULL) {
47 old_style_name = elm_object_style_get(old_content);
48 if (old_style_name != NULL) {
49 DBG("%s", old_style_name);
50 if (strcmp(old_style_name, style_name) == 0)
53 elm_object_part_content_unset(obj, part);
54 evas_object_del(old_content);
61 static Evas_Object *_check_duplicated_image_loading(Evas_Object *obj, const char *part, const char *file_path) {
62 Evas_Object *old_ic = NULL;
63 const char *old_ic_path = NULL;
65 retif(obj == NULL, NULL, "Invalid parameter!");
66 retif(part == NULL, NULL, "Invalid parameter!");
67 retif(file_path == NULL, NULL, "Invalid parameter!");
69 old_ic = elm_object_part_content_get(obj, part);
71 elm_image_file_get(old_ic, &old_ic_path, NULL);
72 if (old_ic_path != NULL) {
73 DBG("%s:%s", old_ic_path, file_path);
74 if (strcmp(old_ic_path, file_path) == 0)
78 elm_object_part_content_unset(obj, part);
79 evas_object_del(old_ic);
85 static void _set_text_to_part(Evas_Object *obj, const char *part, const char *text) {
86 const char *old_text = NULL;
88 retif(obj == NULL, , "Invalid parameter!");
89 retif(part == NULL, , "Invalid parameter!");
90 retif(text == NULL, , "Invalid parameter!");
92 old_text = elm_object_part_text_get(obj, part);
93 if (old_text != NULL) {
94 if (strcmp(old_text, text) == 0) {
99 elm_object_part_text_set(obj, part, text);
102 static char *_noti_get_progress(notification_h noti, char *buf,
106 double percentage = 0.0;
108 retif(noti == NULL, NULL, "Invalid parameter!");
109 retif(buf == NULL, NULL, "Invalid parameter!");
111 notification_get_size(noti, &size);
112 notification_get_progress(noti, &percentage);
114 if (percentage > 0) {
115 if (percentage < 1.0 ) {
116 if (snprintf(buf, buf_len, "%d%%", (int)(percentage * 100)) <= 0) {
120 if (percentage >= 1.0) {
121 snprintf(buf, buf_len, "%d%%", 100);
125 } else if (size > 0 && percentage == 0) {
126 if (size > (1 << 30)) {
127 if (snprintf(buf, buf_len, "%.1lfGB",
128 size / 1000000000.0) <= 0)
132 } else if (size > (1 << 20)) {
133 if (snprintf(buf, buf_len, "%.1lfMB",
134 size / 1000000.0) <= 0)
138 } else if (size > (1 << 10)) {
139 if (snprintf(buf, buf_len, "%.1lfKB",
145 if (snprintf(buf, buf_len, "%lfB", size) <= 0)
155 static void _noti_list_item_ongoing_set_progressbar(Evas_Object *noti_list_item)
157 notification_h noti = NULL;
158 Evas_Object *ic = NULL;
159 Evas_Object *old_ic = NULL;
161 double percentage = 0.0;
162 notification_type_e type = NOTIFICATION_TYPE_NONE;
163 notification_ly_type_e layout = NOTIFICATION_LY_NONE ;
165 retif(noti_list_item == NULL, , "Invalid parameter!");
167 noti_list_item_h *noti_list_item_data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
168 retif(noti_list_item == NULL, , "data is NULL");
170 noti_node_item *item = noti_list_item_data->data;
171 retif(item == NULL, , "data is NULL");
174 retif(noti == NULL, , "noti is NULL");
176 notification_get_type(noti, &type);
177 if (type == NOTIFICATION_TYPE_ONGOING) {
178 notification_get_size(noti, &size);
179 notification_get_progress(noti, &percentage);
180 notification_get_layout(noti, &layout);
182 if (layout != NOTIFICATION_LY_ONGOING_EVENT) {
183 if (percentage > 0 && percentage <= 1) {
184 old_ic = _check_duplicated_progress_loading(noti_list_item,
185 "elm.swallow.progress", "quickpanel/list_progress");
186 if (old_ic == NULL) {
187 ic = elm_progressbar_add(noti_list_item);
190 elm_object_style_set(ic, "quickpanel/list_progress");
195 elm_progressbar_value_set(ic, percentage);
196 elm_progressbar_horizontal_set(ic, EINA_TRUE);
197 elm_progressbar_pulse(ic, EINA_FALSE);
198 } else if (size >= 0 && percentage == 0) {
199 old_ic = _check_duplicated_progress_loading(noti_list_item,
200 "elm.swallow.progress", "quickpanel/pending_list");
201 if (old_ic == NULL) {
202 ic = elm_progressbar_add(noti_list_item);
205 elm_object_style_set(ic, "quickpanel/pending_list");
210 elm_progressbar_horizontal_set(ic, EINA_TRUE);
211 elm_progressbar_pulse(ic, EINA_TRUE);
217 elm_object_part_content_set(noti_list_item, "elm.swallow.progress", ic);
221 static void _noti_list_item_ongoing_set_icon(Evas_Object *noti_list_item)
223 notification_h noti = NULL;
224 Evas_Object *ic = NULL;
225 Evas_Object *old_ic = NULL;
226 char *icon_path = NULL;
227 char *thumbnail_path = NULL;
228 char *main_icon_path = NULL;
229 char *sub_icon_path = NULL;
231 retif(noti_list_item == NULL, , "Invalid parameter!");
233 noti_list_item_h *noti_list_item_data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
234 retif(noti_list_item == NULL, , "data is NULL");
236 noti_node_item *item = noti_list_item_data->data;
237 retif(item == NULL, , "data is NULL");
240 retif(noti == NULL, , "noti is NULL");
242 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_THUMBNAIL,
244 notification_get_image(noti, NOTIFICATION_IMAGE_TYPE_ICON, &icon_path);
246 if (thumbnail_path != NULL && icon_path != NULL) {
247 main_icon_path = thumbnail_path;
248 sub_icon_path = icon_path;
249 } else if (icon_path != NULL && thumbnail_path == NULL) {
250 main_icon_path = icon_path;
251 sub_icon_path = NULL;
252 } else if (icon_path == NULL && thumbnail_path != NULL) {
253 main_icon_path = thumbnail_path;
254 sub_icon_path = NULL;
256 main_icon_path = NULL;
257 sub_icon_path = NULL;
260 if (main_icon_path != NULL) {
261 old_ic = _check_duplicated_image_loading(noti_list_item,
262 "elm.swallow.thumbnail", main_icon_path);
264 if (old_ic == NULL) {
265 ic = elm_image_add(noti_list_item);
266 elm_image_resizable_set(ic, EINA_FALSE, EINA_TRUE);
267 elm_image_file_set(ic, main_icon_path, main_icon_path);
268 elm_object_part_content_set(noti_list_item, "elm.swallow.thumbnail", ic);
269 #ifdef QP_ANIMATED_IMAGE_ENABLE
270 quickpanel_animated_image_add(ic);
275 if (sub_icon_path != NULL) {
276 old_ic = _check_duplicated_image_loading(noti_list_item,
277 "elm.swallow.icon", sub_icon_path);
279 if (old_ic == NULL) {
280 ic = elm_image_add(noti_list_item);
281 elm_image_resizable_set(ic, EINA_FALSE, EINA_TRUE);
282 elm_image_file_set(ic, sub_icon_path, sub_icon_path);
283 elm_object_part_content_set(noti_list_item, "elm.swallow.icon", ic);
287 if (main_icon_path == NULL && sub_icon_path == NULL) {
288 old_ic = _check_duplicated_image_loading(noti_list_item,
289 "elm.swallow.thumbnail", QP_DEFAULT_ICON);
291 if (old_ic == NULL) {
292 ic = elm_image_add(noti_list_item);
293 elm_image_resizable_set(ic, EINA_FALSE, EINA_TRUE);
294 elm_image_file_set(ic, QP_DEFAULT_ICON, QP_DEFAULT_ICON);
295 elm_object_part_content_set(noti_list_item, "elm.swallow.thumbnail", ic);
296 #ifdef QP_ANIMATED_IMAGE_ENABLE
297 quickpanel_animated_image_add(ic);
303 static void _noti_list_item_ongoing_set_text(Evas_Object *noti_list_item)
305 notification_h noti = NULL;
306 notification_error_e noti_err = NOTIFICATION_ERROR_NONE;
308 char *text_utf8 = NULL;
311 char *pkgname = NULL;
312 char *caller_pkgname = NULL;
313 int group_id = 0, priv_id = 0;
314 char buf[128] = { 0, };
315 notification_type_e type = NOTIFICATION_TYPE_NONE;
317 double percentage = 0.0;
318 int isProgressBarEnabled = 1;
319 notification_ly_type_e layout = NOTIFICATION_LY_NONE ;
321 retif(noti_list_item == NULL, , "Invalid parameter!");
323 noti_list_item_h *noti_list_item_data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
324 retif(noti_list_item == NULL, , "data is NULL");
326 noti_node_item *item = noti_list_item_data->data;
327 retif(item == NULL, , "data is NULL");
330 retif(noti == NULL, , "noti is NULL");
332 /* Set text domain */
333 notification_get_text_domain(noti, &domain, &dir);
334 if (domain != NULL && dir != NULL)
335 bindtextdomain(domain, dir);
337 /* Get pkgname & id */
338 notification_get_pkgname(noti, &pkgname);
339 notification_get_application(noti, &caller_pkgname);
340 notification_get_id(noti, &group_id, &priv_id);
341 notification_get_type(noti, &type);
342 notification_get_size(noti, &size);
343 notification_get_progress(noti, &percentage);
344 notification_get_layout(noti, &layout);
346 DBG("percentage:%f size:%f", percentage, size);
348 if (percentage <= 0.0 && size <= 0.0) {
349 isProgressBarEnabled = 0;
352 noti_err = notification_get_text(noti,
353 NOTIFICATION_TEXT_TYPE_TITLE,
356 if (noti_err == NOTIFICATION_ERROR_NONE && text != NULL) {
357 quickpanel_util_char_replace(text, _NEWLINE, _SPACE);
358 _set_text_to_part(noti_list_item, "elm.text.title", text);
361 noti_err = notification_get_text(noti,
362 NOTIFICATION_TEXT_TYPE_CONTENT,
364 if (noti_err == NOTIFICATION_ERROR_NONE && text != NULL) {
365 if (layout == NOTIFICATION_LY_ONGOING_EVENT) {
366 text_utf8 = elm_entry_utf8_to_markup(text);
367 if (text_utf8 != NULL) {
368 _set_text_to_part(noti_list_item, "elm.text.content.multiline", text_utf8);
371 _set_text_to_part(noti_list_item, "elm.text.content.multiline", text);
374 elm_object_signal_emit(noti_list_item, "elm,state,elm.text.content.multiline,active", "elm");
376 quickpanel_util_char_replace(text, _NEWLINE, _SPACE);
377 _set_text_to_part(noti_list_item, "elm.text.content", text);
378 elm_object_signal_emit(noti_list_item, "elm,state,elm.text.content,active", "elm");
382 if (isProgressBarEnabled != 0
383 && layout != NOTIFICATION_LY_ONGOING_EVENT) {
384 text = _noti_get_progress(noti, buf,
387 quickpanel_util_char_replace(text, _NEWLINE, _SPACE);
388 _set_text_to_part(noti_list_item, "elm.text.time", text);
393 static void _noti_list_item_call_item_cb(Evas_Object *noti_list_item, const char *emission) {
394 retif(noti_list_item == NULL, , "invalid parameter");
395 retif(emission == NULL, , "invalid parameter");
399 void (*cb)(void *data, Evas_Object *obj) = NULL;
400 noti_list_item_h *data = NULL;
402 data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
404 if (strncmp(emission,"selected", strlen("selected")) == 0) {
405 cb = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_CB_SELECTED_ITEM);
407 if (cb != NULL && data != NULL) {
408 cb(data->data, noti_list_item);
411 if (strncmp(emission,"button_1", strlen("button_1")) == 0) {
412 cb = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_CB_BUTTON_1);
414 if (cb != NULL && data != NULL) {
415 cb(data->data, noti_list_item);
418 if (strncmp(emission,"deleted", strlen("deleted")) == 0) {
419 cb = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_CB_DELETED_ITEM);
421 if (cb != NULL && data != NULL) {
422 cb(data->data, noti_list_item);
427 static void _signal_cb(void *data, Evas_Object *o, const char *emission, const char *source)
429 retif(data == NULL, , "invalid parameter");
430 retif(o == NULL, , "invalid parameter");
431 retif(emission == NULL, , "invalid parameter");
433 _noti_list_item_call_item_cb(o, emission);
436 HAPI Evas_Object *noti_list_item_create(Evas_Object *parent, notification_ly_type_e layout) {
437 Evas_Object *box = NULL;
439 retif(parent == NULL, NULL, "Invalid parameter!");
441 box = elm_layout_add(parent);
444 elm_layout_file_set(box, DEFAULT_EDJ,
445 "quickpanel/listitem/default");
447 evas_object_size_hint_weight_set(box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
448 evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
449 evas_object_show(box);
451 noti_list_item_h *box_h = (noti_list_item_h *) malloc(sizeof(noti_list_item_h));
452 box_h->layout = layout;
453 box_h->status = STATE_NORMAL;
455 evas_object_data_set(box, E_DATA_NOTI_LIST_ITEM_H, box_h);
456 DBG("created box:%p", box);
459 elm_object_signal_callback_add(box,
467 elm_object_signal_callback_add(box,
475 elm_object_signal_callback_add(box,
485 static void _noti_list_item_set_layout_ongoing_noti(Evas_Object *noti_list_item,
486 notification_h noti) {
488 retif(noti_list_item == NULL, , "invalid parameter");
490 _noti_list_item_ongoing_set_progressbar(noti_list_item);
491 _noti_list_item_ongoing_set_icon(noti_list_item);
492 _noti_list_item_ongoing_set_text(noti_list_item);
495 static void _noti_list_item_set_layout(Evas_Object *noti_list_item, notification_h noti,
496 notification_ly_type_e layout) {
498 DBG("layout:%d", layout);
501 case NOTIFICATION_LY_NOTI_EVENT_SINGLE:
503 case NOTIFICATION_LY_NOTI_EVENT_MULTIPLE:
505 case NOTIFICATION_LY_NOTI_THUMBNAIL:
507 case NOTIFICATION_LY_NONE:
509 case NOTIFICATION_LY_ONGOING_EVENT:
510 case NOTIFICATION_LY_ONGOING_PROGRESS:
511 _noti_list_item_set_layout_ongoing_noti(noti_list_item, noti);
513 case NOTIFICATION_LY_MAX:
514 DBG("not supported layout type:%d", layout);
519 HAPI void noti_list_item_remove(Evas_Object *noti_list_item) {
521 retif(noti_list_item == NULL, , "invalid parameter");
523 noti_list_item_h *noti_list_item_h = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
525 if (noti_list_item_h != NULL)
526 free(noti_list_item_h);
528 evas_object_data_del(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
529 evas_object_data_del(noti_list_item, E_DATA_NOTI_LIST_CB_SELECTED_ITEM);
530 evas_object_data_del(noti_list_item, E_DATA_NOTI_LIST_CB_BUTTON_1);
531 evas_object_data_del(noti_list_item, E_DATA_NOTI_LIST_CB_DELETED_ITEM);
533 evas_object_del(noti_list_item);
536 HAPI void noti_list_item_update(Evas_Object *noti_list_item) {
537 retif(noti_list_item == NULL, , "invalid parameter");
539 _noti_list_item_ongoing_set_progressbar(noti_list_item);
540 _noti_list_item_ongoing_set_icon(noti_list_item);
541 _noti_list_item_ongoing_set_text(noti_list_item);
544 HAPI void noti_list_item_set_status(Evas_Object *noti_list_item, int status) {
545 retif(noti_list_item == NULL, , "invalid parameter");
547 noti_list_item_h *noti_list_item_h = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
549 if (noti_list_item_h != NULL) {
550 noti_list_item_h->status = status;
554 HAPI int noti_list_item_get_status(Evas_Object *noti_list_item) {
555 retif(noti_list_item == NULL, STATE_NORMAL, "invalid parameter");
557 noti_list_item_h *noti_list_item_h = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
559 if (noti_list_item_h != NULL) {
560 return noti_list_item_h->status;
563 return STATE_DELETING;
566 HAPI void noti_list_item_node_set(Evas_Object *noti_list_item, void *data) {
567 retif(noti_list_item == NULL, , "invalid parameter");
568 retif(data == NULL, , "invalid parameter");
570 noti_list_item_h *noti_list_item_data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
572 if (noti_list_item_data != NULL) {
573 noti_list_item_data->data = data;
576 noti_node_item *item = data;
577 _noti_list_item_set_layout(noti_list_item, item->noti, noti_list_item_data->layout);
582 HAPI void *noti_list_item_node_get(Evas_Object *noti_list_item) {
583 retif(noti_list_item == NULL, NULL, "invalid parameter");
585 noti_list_item_h *noti_list_item_data = evas_object_data_get(noti_list_item, E_DATA_NOTI_LIST_ITEM_H);
587 if (noti_list_item_data != NULL) {
588 return noti_list_item_data->data;
594 HAPI void noti_list_item_set_item_selected_cb(Evas_Object *noti_list_item,
595 void(*selected_cb)(void *data, Evas_Object *obj)) {
596 retif(noti_list_item == NULL, , "invalid parameter");
597 retif(selected_cb == NULL, , "invalid parameter");
599 evas_object_data_set(noti_list_item, E_DATA_NOTI_LIST_CB_SELECTED_ITEM, selected_cb);
602 HAPI void noti_list_item_set_item_button_1_cb(Evas_Object *noti_list_item,
603 void(*button_1_cb)(void *data, Evas_Object *obj)) {
604 retif(noti_list_item == NULL, , "invalid parameter");
605 retif(button_1_cb == NULL, , "invalid parameter");
607 evas_object_data_set(noti_list_item, E_DATA_NOTI_LIST_CB_BUTTON_1, button_1_cb);
610 HAPI void noti_list_item_set_item_deleted_cb(Evas_Object *noti_list_item,
611 void(*deleted_cb)(void *data, Evas_Object *obj)) {
612 retif(noti_list_item == NULL, , "invalid parameter");
613 retif(deleted_cb == NULL, , "invalid parameter");
615 evas_object_data_set(noti_list_item, E_DATA_NOTI_LIST_CB_DELETED_ITEM, deleted_cb);