merge from 2.4 , block compile error
[apps/core/preloaded/quickpanel.git] / daemon / notifications / noti_section.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18
19 #include <notification.h>
20 #include "quickpanel-ui.h"
21 #include "quickpanel_def.h"
22 #include "common.h"
23 #include "noti.h"
24 #include "noti_section.h"
25 #include "list_util.h"
26 #ifdef QP_SCREENREADER_ENABLE
27 #include "accessibility.h"
28 #endif
29
30  #define NOTI_CLEAR_ALL_SECTION "quickpanel/notisection/clear_all"
31  #define NOTI_DEFAULT_SECTION "quickpanel/notisection/default"
32
33 static void _noti_section_set_text(Evas_Object *noti_section, int count)
34 {
35 #ifdef QP_SCREENREADER_ENABLE
36         Evas_Object *ao = NULL;
37 #endif
38
39         DBG("count is : %d ", count);
40
41         char text[128] = {0,};
42         char *format = NULL;
43         const char *old_text = NULL;
44
45         retif(noti_section == NULL, , "invalid parameter");
46
47         format = _("IDS_QP_HEADER_NOTIFICATIONS_HPD_ABB");
48         snprintf(text, sizeof(text), format, count);
49
50         old_text = elm_object_part_text_get(noti_section, "elm.text.notifications_number");
51         if (old_text != NULL) {
52                 if (strcmp(old_text, text) == 0) {
53                         return;
54                 }
55         }
56
57 #ifdef QP_SCREENREADER_ENABLE
58         ao = quickpanel_accessibility_screen_reader_object_get(noti_section,
59                         SCREEN_READER_OBJ_TYPE_ELM_OBJECT, "focus.label", noti_section);
60
61         if (ao != NULL) {
62                 elm_access_info_set(ao, ELM_ACCESS_TYPE, "");
63                 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
64         }
65 #endif
66
67         DBG("Trying to set text :%s ", text);
68
69         elm_object_part_text_set(noti_section, "elm.text.notifications_number", text);
70         elm_object_part_text_set(noti_section, "text.button.clear_all", _("IDS_QP_HEADER_CLEAR_ALL_ABB"));
71 }
72
73 HAPI Evas_Object *quickpanel_noti_section_create(Evas_Object *parent, qp_item_type_e type)
74 {
75         Eina_Bool ret = EINA_FALSE;
76         Evas_Object *section = NULL;
77
78         struct appdata *ad = quickpanel_get_app_data();
79         retif(ad == NULL, NULL, "invalid parameter");
80         retif(parent == NULL, NULL, "invalid parameter");
81
82         section = elm_layout_add(parent);
83         if (type == QP_ITEM_TYPE_ONGOING_NOTI_GROUP) {
84                 ret = elm_layout_file_set(section, DEFAULT_EDJ,
85                                 NOTI_CLEAR_ALL_SECTION);
86         } else { //in higgs there is only one type of notifications
87                 ret = elm_layout_file_set(section, DEFAULT_EDJ,
88                                 NOTI_CLEAR_ALL_SECTION);
89         }
90         retif(ret == EINA_FALSE, NULL, "failed to load layout");
91
92         evas_object_size_hint_weight_set(section, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
93         evas_object_size_hint_align_set(section, EVAS_HINT_FILL, EVAS_HINT_FILL);
94         quickpanel_uic_initial_resize(section, QP_THEME_LIST_ITEM_NOTI_SECTION_HEIGHT);
95         evas_object_show(section);
96
97         qp_item_data *qid
98                 = quickpanel_list_util_item_new(type, NULL);
99         quickpanel_list_util_item_set_tag(section, qid);
100         quickpanel_list_util_sort_insert(ad->list, section);
101
102         Evas_Object *focus = quickpanel_accessibility_ui_get_focus_object(section);
103         elm_object_part_content_set(section, "focus", focus);
104         evas_object_smart_callback_add(focus, "clicked", quickpanel_noti_on_clear_all_clicked, NULL);
105
106         focus = quickpanel_accessibility_ui_get_focus_object(section);
107         elm_object_part_content_set(section, "focus.label", focus);
108
109         return section;
110 }
111
112 static void _focus_pair_set(Evas_Object *view)
113 {
114         Evas_Object *label = NULL;
115         Evas_Object *button = NULL;
116         retif(view == NULL, , "Invalid parameter!");
117
118         label = elm_object_part_content_get(view, "focus.label");
119         button = elm_object_part_content_get(view, "elm.swallow.icon");
120
121         if (label != NULL && button != NULL) {
122                 /* label */
123                 elm_object_focus_next_object_set(label, button, ELM_FOCUS_RIGHT);
124                 elm_object_focus_next_object_set(label, button, ELM_FOCUS_DOWN);
125
126                 /* button */
127                 elm_object_focus_next_object_set(button, label, ELM_FOCUS_LEFT);
128                 elm_object_focus_next_object_set(button, label, ELM_FOCUS_UP);
129         }
130 }
131
132 HAPI void quickpanel_noti_section_update(Evas_Object *noti_section, int noti_count)
133 {
134         retif(noti_section == NULL, , "invalid parameter");
135
136         _noti_section_set_text(noti_section, noti_count);
137         _focus_pair_set(noti_section);
138
139         quickpanel_noti_set_clear_all_status();
140 }
141
142 HAPI void quickpanel_noti_section_set_deleted_cb(Evas_Object *noti_section,
143                 Evas_Object_Event_Cb func, void *data)
144 {
145         retif(noti_section == NULL, , "invalid parameter");
146         retif(func == NULL, , "invalid parameter");
147
148         evas_object_event_callback_add(noti_section, EVAS_CALLBACK_DEL, func, data);
149 }
150
151 HAPI void quickpanel_noti_section_remove(Evas_Object *noti_section)
152 {
153         struct appdata *ad = quickpanel_get_app_data();
154         retif(ad == NULL, , "invalid parameter");
155         retif(noti_section == NULL, , "invalid parameter");
156
157         quickpanel_list_util_item_del_tag(noti_section);
158         quickpanel_list_util_item_unpack_by_object(ad->list, noti_section, 0, 0);
159 }