tizen 2.4 release
[apps/home/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 <Elementary.h>
20 #include <glib.h>
21
22 #include <vconf.h>
23 #include <notification.h>
24 #include <tzsh.h>
25 #include <tzsh_quickpanel_service.h>
26 #include <system_settings.h>
27
28 #include "quickpanel-ui.h"
29 #include "quickpanel_def.h"
30 #include "common_uic.h"
31 #include "common.h"
32 #include "noti_node.h"
33 #include "noti.h"
34 #include "list_util.h"
35 #include "noti_section.h"
36
37 #ifdef QP_SCREENREADER_ENABLE
38 #include "accessibility.h"
39 #endif
40
41 #define NOTI_CLEAR_ALL_SECTION "quickpanel/notisection/clear_all"
42 #define NOTI_DEFAULT_SECTION "quickpanel/notisection/default"
43
44 static void _noti_section_set_text(Evas_Object *noti_section, int count)
45 {
46         char text[128] = { 0, };
47         char *format;
48         const char *old_text;
49
50         if (!noti_section) {
51                 ERR("Invalid parameter");
52                 return;
53         }
54
55         DBG("count is : %d ", count);
56         format = _("IDS_QP_HEADER_NOTIFICATIONS_HPD_ABB");
57         snprintf(text, sizeof(text) - 1, format, count);
58
59         old_text = elm_object_part_text_get(noti_section, "elm.text.notifications_number");
60         if (old_text != NULL) {
61                 if (strcmp(old_text, text) == 0) {
62                         return;
63                 }
64         }
65
66 #ifdef QP_SCREENREADER_ENABLE
67         Evas_Object *ao;
68
69         ao = quickpanel_accessibility_screen_reader_object_get(noti_section, SCREEN_READER_OBJ_TYPE_ELM_OBJECT, "focus.label", noti_section);
70         if (ao != NULL) {
71                 elm_access_info_set(ao, ELM_ACCESS_TYPE, "");
72                 elm_access_info_set(ao, ELM_ACCESS_INFO, text);
73         }
74 #endif
75
76         DBG("Trying to set text :%s ", text);
77         elm_object_part_text_set(noti_section, "elm.text.notifications_number", text);
78         elm_object_part_text_set(noti_section, "text.button.clear_all", _("IDS_QP_HEADER_CLEAR_ALL_ABB"));
79 }
80
81 HAPI Evas_Object *quickpanel_noti_section_create(Evas_Object *parent, qp_item_type_e type)
82 {
83         Evas_Object *section;
84         Evas_Object *focus;
85         struct appdata *ad;
86         qp_item_data *qid;
87         Eina_Bool ret;
88
89         ad = quickpanel_get_app_data();
90         if (!ad || !parent) {
91                 ERR("Invalid parameter");
92                 return NULL;
93         }
94
95         section = elm_layout_add(parent);
96         ret = elm_layout_file_set(section, DEFAULT_EDJ, NOTI_CLEAR_ALL_SECTION);
97         if (ret == EINA_FALSE) {
98                 ERR("Failed to set a file");
99                 evas_object_del(section);
100                 return NULL;
101         }
102
103         evas_object_size_hint_weight_set(section, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
104         evas_object_size_hint_align_set(section, EVAS_HINT_FILL, EVAS_HINT_FILL);
105         quickpanel_uic_initial_resize(section, QP_THEME_LIST_ITEM_NOTI_SECTION_HEIGHT);
106         evas_object_show(section);
107
108         qid = quickpanel_list_util_item_new(type, NULL);
109         if (!qid) {
110                 ERR("Unable to create a qid");
111                 evas_object_del(section);
112                 return NULL;
113         }
114         quickpanel_list_util_item_set_tag(section, qid);
115         quickpanel_list_util_sort_insert(ad->list, section);
116
117         focus = quickpanel_accessibility_ui_get_focus_object(section);
118         if (!focus) {
119                 ERR("Unable to get the focus object");
120                 quickpanel_list_util_item_del(qid);
121                 evas_object_del(section);
122                 return NULL;
123         }
124         elm_object_part_content_set(section, "focus", focus);
125         evas_object_smart_callback_add(focus, "clicked", quickpanel_noti_on_clear_all_clicked, NULL);
126
127         return section;
128 }
129
130 static void _focus_pair_set(Evas_Object *view)
131 {
132         Evas_Object *label = NULL;
133         Evas_Object *button = NULL;
134         retif(view == NULL, , "Invalid parameter!");
135
136         label = elm_object_part_content_get(view, "focus.label");
137         button = elm_object_part_content_get(view, "elm.swallow.icon");
138
139         if (label != NULL && button != NULL) {
140                 /* label */
141                 elm_object_focus_next_object_set(label, button, ELM_FOCUS_RIGHT);
142                 elm_object_focus_next_object_set(label, button, ELM_FOCUS_DOWN);
143
144                 /* button */
145                 elm_object_focus_next_object_set(button, label, ELM_FOCUS_LEFT);
146                 elm_object_focus_next_object_set(button, label, ELM_FOCUS_UP);
147         }
148 }
149
150 HAPI void quickpanel_noti_section_update(Evas_Object *noti_section, int noti_count)
151 {
152         retif(noti_section == NULL, , "invalid parameter");
153
154         _noti_section_set_text(noti_section, noti_count);
155         _focus_pair_set(noti_section);
156
157         quickpanel_noti_set_clear_all_status();
158 }
159
160 HAPI void quickpanel_noti_section_set_deleted_cb(Evas_Object *noti_section,
161                 Evas_Object_Event_Cb func, void *data)
162 {
163         retif(noti_section == NULL, , "invalid parameter");
164         retif(func == NULL, , "invalid parameter");
165
166         evas_object_event_callback_add(noti_section, EVAS_CALLBACK_DEL, func, data);
167 }
168
169 HAPI void quickpanel_noti_section_remove(Evas_Object *noti_section)
170 {
171         struct appdata *ad = quickpanel_get_app_data();
172         retif(ad == NULL, , "invalid parameter");
173         retif(noti_section == NULL, , "invalid parameter");
174
175         quickpanel_list_util_item_del_tag(noti_section);
176         quickpanel_list_util_item_unpack_by_object(ad->list, noti_section, 0, 0);
177 }