tizen 2.4 release
[apps/home/ug-setting-notification-efl.git] / ug-setting-notification-do-not-disturb-efl / src / do-not-disturb-efl.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
20 #include <Elementary.h>
21 #include <libintl.h>
22 #include <ui-gadget-module.h>
23 #include <package_manager.h>
24 #include "do-not-disturb-efl.h"
25 #include "pkgmgr-setting-info.h"
26 #include "excepted-apps-efl.h"
27 #include "common-efl.h"
28 /**
29  * @{
30  */
31
32 ug_data *g_ug_data = NULL;
33
34 static Evas_Object* _create_do_not_disturb_gl(ug_data *ugd);
35 static void _append_item_in_list(Evas_Object* genlist);
36
37 ug_data* get_ug_data(_)
38 {
39         return g_ug_data;
40 }
41
42 static void _do_not_disturb_check_changed_cb(void *data, Evas_Object *obj, void *event_info)
43 {
44         NOTISET_DBG("");
45         char *appid = (char*)data;
46
47         Eina_Bool state = elm_check_state_get(obj);
48         set_do_not_disturb(state);
49         NOTISET_DBG("do_not_disturb check value = %s", state==false ? "FALSE":"TRUE");
50 }
51
52
53 static Eina_Bool _notifiacation_setting_main_pop_cb(void *data, Elm_Object_Item * it)
54 {
55         NOTISET_DBG("");
56         ug_data *ugd = (ug_data *) data;
57         retv_if(!ugd, EINA_FALSE);
58
59         ug_destroy_me(ugd->ug);
60
61         return EINA_FALSE;
62 }
63
64 void do_not_disturb_append_item_in_list(Evas_Object* genlist)
65 {       
66         append_gl_start_option(genlist, "multiline", "do-not-disturb");
67
68         append_gl_group_index(genlist, APP_STRING("IDS_ST_HEADER_EXCLUDED_APPS_ABB"));
69
70         append_gl_item_list(genlist, get_excepted_apps_list(), ITEM_STYLE_ONE_ICON);
71 }
72
73 static Evas_Object* _create_do_not_disturb_gl(ug_data *ugd)
74 {
75         Evas_Object *parent = ugd->naviframe;
76         Evas_Object *genlist;
77
78         genlist = elm_genlist_add(parent);
79         elm_genlist_mode_set(genlist, ELM_LIST_SCROLL);
80         elm_genlist_mode_set(genlist, ELM_LIST_COMPRESS);
81         evas_object_size_hint_weight_set(genlist, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
82         evas_object_size_hint_align_set(genlist, EVAS_HINT_FILL, EVAS_HINT_FILL);
83         elm_genlist_block_count_set(genlist, 8);
84
85         /* Add Smart Callback */
86         evas_object_smart_callback_add(genlist, "realized", gl_realized_cb, NULL);
87         evas_object_smart_callback_add(genlist, "loaded", gl_loaded_cb, NULL);
88         evas_object_smart_callback_add(genlist, "longpressed", gl_longpressed_cb, NULL);
89         evas_object_smart_callback_add(genlist, "contracted", gl_contracted_cb, NULL);
90
91         do_not_disturb_append_item_in_list(genlist);
92
93         return genlist;
94 }
95
96 static void _create_main_view(void *data)
97 {
98         NOTISET_DBG("");
99         ug_data *ugd = (ug_data *) data;
100         ret_if(!ugd);
101
102         g_ug_data = ugd;
103         g_ug_data->list_main = _create_do_not_disturb_gl(ugd);
104
105         /* back Button */
106         Evas_Object *back_btn = elm_button_add(ugd->naviframe);
107         elm_object_style_set(back_btn, "naviframe/back_btn/default");
108         evas_object_smart_callback_add(back_btn, "clicked", back_button_cb, ugd->naviframe);
109
110         /* Push to naviframe */
111         g_ug_data->navi_item = elm_naviframe_item_push(ugd->naviframe, APP_STRING("IDS_ST_HEADER_DO_NOT_DISTURB_ABB"), back_btn, NULL, g_ug_data->list_main, NULL);
112         elm_naviframe_item_pop_cb_set(g_ug_data->navi_item, _notifiacation_setting_main_pop_cb, ugd);
113
114         /* Bottom Button */
115         Evas_Object *bottom_box = elm_box_add(ugd->naviframe);
116         evas_object_size_hint_weight_set(bottom_box, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
117         evas_object_size_hint_align_set(bottom_box, EVAS_HINT_FILL, EVAS_HINT_FILL);
118         elm_box_horizontal_set(bottom_box, EINA_TRUE);
119         evas_object_show(bottom_box);
120
121         Evas_Object *bottom_button = elm_button_add(bottom_box);
122         evas_object_show(bottom_button);
123         elm_object_style_set(bottom_button, "bottom");
124         evas_object_size_hint_weight_set(bottom_button, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
125         evas_object_size_hint_align_set(bottom_button, EVAS_HINT_FILL, 0.5);
126         elm_object_translatable_text_set(bottom_button, APP_STRING("IDS_ST_BUTTON_MANAGE_EXCLUDED_APPS_ABB"));
127         evas_object_smart_callback_add(bottom_button, "clicked", exception_application_clicked_cb, g_ug_data);
128         elm_object_item_part_content_set(g_ug_data->navi_item, "toolbar", bottom_box);
129         elm_box_pack_start(bottom_box, bottom_button);
130 }
131
132
133 static Evas_Object *_create_fullview(Evas_Object *parent, ug_data *ugd)
134 {
135         NOTISET_DBG("");
136         retv_if(!ugd, NULL);
137
138         /* Create Full view */
139         ugd->layout = create_layout(parent);
140         elm_layout_theme_set(ugd->layout, "layout", "application", "default");
141         elm_win_indicator_mode_set(parent, ELM_WIN_INDICATOR_SHOW);
142  
143         /* Create background */
144         create_background(ugd->layout);
145
146         /* Create navigation bar */
147         ugd->naviframe = create_naviframe(ugd->layout);
148         
149         /* Create main view */
150         _create_main_view(ugd);
151
152         return ugd->layout;
153 }
154
155 static void *on_create(ui_gadget_h ug, enum ug_mode mode, app_control_h service, void *priv)
156 {
157         Evas_Object *parent;
158         ug_data *ugd;
159
160         if (!ug || !priv)
161                 return NULL;
162
163         ugd = priv;
164         ugd->ug = ug;
165
166         parent = ug_get_parent_layout(ug);
167         if (!parent)
168                 return NULL;
169
170         // set mode
171         ugd->mode = 0;
172
173         create_do_not_disturb_application_list();
174         ugd->layout = _create_fullview(parent, ugd);
175
176         return ugd->layout;
177 }
178
179 static void on_start(ui_gadget_h ug, app_control_h service, void *priv)
180 {
181         NOTISET_DBG("");
182
183 }
184
185 static void on_pause(ui_gadget_h ug, app_control_h service, void *priv)
186 {
187         NOTISET_DBG("");
188
189 }
190
191 static void on_resume(ui_gadget_h ug, app_control_h service, void *priv)
192 {
193         NOTISET_DBG("");
194
195 }
196
197 static void on_destroy(ui_gadget_h ug, app_control_h service, void *priv)
198 {
199         NOTISET_DBG("");
200
201         ug_data *ugd = priv;
202
203         remove_excepted_apps_list();
204
205         EVAS_OBJECT_DELIF(ugd->cancel_button);
206         EVAS_OBJECT_DELIF(ugd->done_button);
207         EVAS_OBJECT_DELIF(ugd->list_sub);
208         EVAS_OBJECT_DELIF(ugd->list_main);
209         EVAS_OBJECT_DELIF(ugd->naviframe);
210         EVAS_OBJECT_DELIF(ugd->layout);
211 }
212
213 static void on_message(ui_gadget_h ug, app_control_h msg, app_control_h service, void *priv)
214 {
215         /* Fill me */
216 }
217
218 static void on_event(ui_gadget_h ug, enum ug_event event, app_control_h service, void *priv)
219 {
220         switch (event) {
221         case UG_EVENT_LOW_MEMORY:
222                 break;
223         case UG_EVENT_LOW_BATTERY:
224                 break;
225         case UG_EVENT_LANG_CHANGE:
226                 break;
227         case UG_EVENT_REGION_CHANGE:
228                 break;
229         case UG_EVENT_ROTATE_PORTRAIT:
230                 break;
231         case UG_EVENT_ROTATE_PORTRAIT_UPSIDEDOWN:
232                 break;
233         case UG_EVENT_ROTATE_LANDSCAPE:
234                 break;
235         case UG_EVENT_ROTATE_LANDSCAPE_UPSIDEDOWN:
236                 break;
237         default:
238                 break;
239         }
240 }
241
242 static void on_key_event(ui_gadget_h ug, enum ug_key_event event, app_control_h service, void *priv)
243 {
244         switch (event) {
245         case UG_KEY_EVENT_NONE:
246                 break;
247         case UG_KEY_EVENT_END:
248                 /**
249                  * @TODO: Terminate UG itself?
250                  */
251                 break;
252         default:
253                 break;
254         }
255 }
256
257 int UG_MODULE_INIT(struct ug_module_ops *ops)
258 {
259         ug_data *ugd;
260
261         if (ops == NULL) {
262                 return -EINVAL;
263         }
264
265         ugd = calloc(1, sizeof(ug_data));
266
267         if (!ugd) {
268                 return -ENOMEM;
269         }
270
271         ops->create = on_create;
272         ops->start = on_start;
273         ops->pause = on_pause;
274         ops->resume = on_resume;
275         ops->destroy = on_destroy;
276         ops->message = on_message;
277         ops->event = on_event;
278         ops->key_event = on_key_event;
279         ops->priv = ugd;
280         ops->opt = UG_OPT_INDICATOR_ENABLE;
281
282         if (bindtextdomain(PKGNAME, "/usr/apps/ug-setting-notification-efl/res/locale") == NULL) {
283                 /* Failed to allocate memory for allocating heap for store the path of LOCALE directory */
284         }
285
286         return 0;
287 }
288
289 void UG_MODULE_EXIT(struct ug_module_ops *ops)
290 {
291         NOTISET_DBG("");
292         ug_data *ugd;
293         
294         if (ops == NULL) {
295                 return;
296         }
297
298         ugd = ops->priv;
299
300         free(ugd);
301 }
302
303 /**
304  * @}
305  */
306
307 /* End of a file */