Closes app now when you hit the back button. This is a temp fix to keep media workin...
[profile/ivi/ug-camera-efl.git] / src / cam_popup.c
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include "cam_popup.h"
19 #include "cam_debug.h"
20 #include "cam.h"
21
22 static GList *g_pop_list = NULL;
23
24 static double bar_percent = 0;
25 static char *bar_text = NULL;
26 static gboolean add_progress_bar = FALSE;
27
28
29 /* remove popup which is add by cam_app_*_popup() functions */
30 void cam_popup_remove(Evas_Object *popup)
31 {
32         if (popup == NULL)
33                 return;
34         GList *popup_list = NULL;
35         popup_list = g_pop_list;
36         g_pop_list = g_list_remove(popup_list, popup);
37         evas_object_del(popup);
38         popup = NULL;
39 }
40
41 void cam_popup_remove_all(void)
42 {
43         GList *popup_list = NULL;
44         popup_list = g_pop_list;
45
46         if (popup_list) {
47                 while (popup_list) {
48                         GList *next = popup_list->next;
49                         evas_object_del(popup_list->data);
50                         popup_list->data = NULL;
51                         popup_list = next;
52                 }
53                 g_list_free(popup_list);
54                 g_pop_list = NULL;
55         }
56         return;
57 }
58
59 #ifdef USE_ELM_POPUP /*it is not use*/
60
61 /* popup with one button,  ELM_POPUP_RESPONSE_OK is sent along with response signal. */
62 void cam_popup_confirm_add(Evas_Object *window, const char *message,
63                            const char *btn_name, cam_popup_respons_cb callback,
64                            void *user_data)
65 {
66
67         Evas_Object *popup = NULL;
68
69         if (callback == NULL) { /* response_cb should be set */
70                 cam_critical(LOG_UI,
71                              "add info popup [%s]  failed, callback is NULL ",
72                              message);
73                 return;
74         }
75
76         popup = elm_popup_add_with_buttons(window, NULL, message,
77                                            1, btn_name, ELM_POPUP_RESPONSE_OK,
78                                            NULL);
79
80         if (popup == NULL) {
81                 cam_critical(LOG_UI, "add confirm popup [%s]  failed ",
82                              message);
83                 return;
84         }
85         evas_object_smart_callback_add(popup, "response", callback, user_data);
86         evas_object_show(popup);
87
88         g_pop_list = g_list_append(g_pop_list, popup);
89
90         return;
91 }
92
93 /* popup with two button, ELM_POPUP_RESPONSE_OK/ELM_POPUP_RESPONSE_CANCEL is sent along with response signal. */
94 void cam_popup_question_add(Evas_Object *window, const char *message,
95                             const char *btn_n_1, const char *btn_n_2,
96                             cam_popup_respons_cb callback, void *user_data)
97 {
98         Evas_Object *popup = NULL;
99
100         if (callback == NULL) { /* response_cb should be set */
101                 cam_critical(LOG_UI,
102                              "add info popup [%s]  failed, callback is NULL ",
103                              message);
104                 return;
105         }
106
107         popup = elm_popup_add_with_buttons(window, NULL, message, 2,
108                                            btn_n_1, btn_n_2,
109                                            ELM_POPUP_RESPONSE_OK,
110                                            ELM_POPUP_RESPONSE_CANCEL, NULL);
111
112         if (popup == NULL) {
113                 cam_critical(LOG_UI, "add question popup [%s]  failed ",
114                              message);
115                 return;
116         }
117         evas_object_smart_callback_add(popup, "response", callback, user_data);
118         evas_object_show(popup);
119
120         g_pop_list = g_list_append(g_pop_list, popup);
121
122         return;
123 }
124 #else                           /* #ifdef USE_ELM_POPUP */
125 void
126 cam_popup_question_add(Evas_Object *window, const char *message,
127                        const char *lbtn_name, void (*left_btn_cb) (void *data,
128                                                                    Evas_Object
129                                                                    *obj,
130                                                                    void
131                                                                    *event_info),
132                        const char *rbtn_name, void (*right_btn_cb) (void *data,
133                                                                     Evas_Object
134                                                                     *obj,
135                                                                     void
136                                                                     *event_info))
137 {
138         Evas_Object *notify = NULL;
139         Evas_Object *layout = NULL;
140         Evas_Object *label = NULL;
141         Evas_Object *button = NULL;
142         int width = 0;
143         char buf[50] = { '\0', };
144
145         notify = elm_notify_add(window);
146         evas_object_size_hint_weight_set(notify, EVAS_HINT_EXPAND,
147                                          EVAS_HINT_EXPAND);
148         elm_notify_align_set(notify, 0.5, 0.5);
149         elm_notify_allow_events_set(notify, EINA_FALSE);
150         evas_object_show(notify);
151
152         layout = elm_layout_add(window);
153         elm_layout_theme_set(layout, "standard", "notify", "style3");
154         evas_object_size_hint_weight_set(layout, EVAS_HINT_EXPAND,
155                                          EVAS_HINT_EXPAND);
156         elm_object_content_set(notify, layout);
157         evas_object_show(layout);
158
159         label = elm_label_add(window);
160
161         elm_object_style_set(label, "popup/description");
162         edje_object_part_geometry_get((Evas_Object *)
163                                       elm_layout_edje_get(layout),
164                                       "elm.swallow.content", NULL, NULL, &width,
165                                       NULL);
166         elm_label_line_wrap_set(label, EINA_TRUE);
167         elm_label_wrap_width_set(label, width);
168
169         snprintf(buf, sizeof(buf), "<align=middle>%s", message);
170
171         elm_object_text_set(label, buf);
172         elm_object_part_content_set(layout, "elm.swallow.content", label);
173         evas_object_show(label);
174
175         if (lbtn_name && left_btn_cb) {
176                 button = elm_button_add(window);
177                 elm_object_text_set(button, lbtn_name);
178                 elm_object_part_content_set(layout, "elm.swallow.left", button);
179                 evas_object_smart_callback_add(button, "focused", left_btn_cb,
180                                                notify);
181                 evas_object_show(button);
182         }
183
184         if (rbtn_name && right_btn_cb) {
185                 button = elm_button_add(window);
186                 elm_object_text_set(button, rbtn_name);
187                 elm_object_part_content_set(layout, "elm.swallow.right", button);
188                 evas_object_smart_callback_add(button, "focused", right_btn_cb,
189                                                notify);
190                 evas_object_show(button);
191         }
192
193         g_pop_list = g_list_append(g_pop_list, notify);
194
195         return;
196 }
197 #endif                          /*  #ifdef USE_ELM_POPUP */
198
199 Evas_Object *cam_popup_guide_screen_add(Evas_Object *window, const char *message)
200 {
201         cam_debug(LOG_UI, "");
202
203         Evas_Object *ctxpopup = NULL;
204         ctxpopup = elm_ctxpopup_add(window);
205
206         if (!ctxpopup) {
207                 cam_critical(LOG_UI, "critical : can't make ctx popup");
208                 return NULL;
209         } else {
210                 elm_object_style_set(ctxpopup, "beat_winset_test/imageeditor");
211                 elm_ctxpopup_item_append(ctxpopup, _("Flickr"), NULL, NULL,
212                                          ctxpopup);
213                 evas_object_move(ctxpopup, 200, 200);
214                 evas_object_show(ctxpopup);
215         }
216
217         return ctxpopup;
218 }
219
220
221 gboolean cam_popup_create(void *data)
222 {
223         struct appdata *ad = (struct appdata *)data;
224         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
225
226         if (ad->progress_popup != NULL)
227                 cam_popup_delete(ad);
228
229         elm_object_part_content_unset(ad->ug_base, "progress_popup_layout");
230
231         // create popup
232         ad->progress_popup = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "progress_popup");
233
234         cam_retvm_if(ad->progress_popup == NULL, FALSE, "progress_popup is NULL");
235         elm_object_part_content_set(ad->ug_base, "progress_popup_layout", ad->progress_popup);
236
237         switch (ad->target_direction) {
238         case CAM_TARGET_DIRECTION_LANDSCAPE:
239         case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
240                 edje_object_signal_emit(_EDJ(ad->progress_popup), "progress_popup,default", "prog");
241                 break;
242         case CAM_TARGET_DIRECTION_PORTRAIT:
243         case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
244                 edje_object_signal_emit(_EDJ(ad->progress_popup), "progress_popup,vertical", "prog");
245                 break;
246         default:
247                 DEBUG_TRACE("wow, reached un-able reached codes");
248         }
249
250         evas_object_show(ad->progress_popup);
251
252         return TRUE;
253 }
254
255 // create popup with progress bar burst_progress_popup
256 gboolean cam_popup_for_burst_create(void *data)
257 {
258         struct appdata *ad = (struct appdata *)data;
259         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
260
261         if (ad->progress_popup != NULL)
262                 cam_popup_delete(ad);
263
264         elm_object_part_content_unset(ad->ug_base, "progress_popup_layout");
265
266         // create popup
267         ad->progress_popup = cam_app_load_edj(ad->ug_base, CAM_UTILS_EDJ_NAME, "burst_progress_popup");
268
269         cam_retvm_if(ad->progress_popup == NULL, FALSE, "progress_popup is NULL");
270         elm_object_part_content_set(ad->ug_base, "progress_popup_layout", ad->progress_popup);
271
272         switch (ad->target_direction) {
273         case CAM_TARGET_DIRECTION_LANDSCAPE:
274         case CAM_TARGET_DIRECTION_LANDSCAPE_INVERSE:
275                 edje_object_signal_emit(_EDJ(ad->progress_popup), "progress_popup,default", "prog");
276                 break;
277         case CAM_TARGET_DIRECTION_PORTRAIT:
278         case CAM_TARGET_DIRECTION_PORTRAIT_INVERSE:
279                 edje_object_signal_emit(_EDJ(ad->progress_popup), "progress_popup,vertical", "prog");
280                 break;
281         default:
282                 DEBUG_TRACE("wow, reached un-able reached codes");
283         }
284
285         evas_object_show(ad->progress_popup);
286
287         return TRUE;
288 }
289
290
291 gboolean cam_popup_add_progress_bar(void *data)
292 {
293         struct appdata *ad = (struct appdata *)data;
294         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
295
296         if (ad->progress_popup_bar != NULL) {
297                 evas_object_del(ad->progress_popup_bar);
298                 ad->progress_popup_bar = NULL;
299         }
300
301         ad->progress_popup_bar = elm_progressbar_add(ad->ug_base);
302         cam_retvm_if(ad->progress_popup_bar == NULL, FALSE, "Cannot add progressbar object\n");
303
304         Evas_Object *pb = ad->progress_popup_bar;
305         edje_object_part_swallow(_EDJ(ad->progress_popup), "progress_popup_bar", pb);
306         elm_object_style_set(pb, "list_progress");
307         evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, EVAS_HINT_FILL);
308         add_progress_bar = TRUE;
309
310         return TRUE;
311 }
312
313 gboolean cam_popup_set_text(void *data, char *text)
314 {
315         struct appdata *ad = (struct appdata *)data;
316         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
317
318         if (ad->progress_popup == NULL )
319                 return FALSE;
320
321         if (text != NULL) {
322                 bar_text = text;
323                 edje_object_part_text_set(_EDJ(ad->progress_popup), "progress_popup_text", text);
324         }
325         return TRUE;
326 }
327
328 gboolean cam_popup_set_bar_value(void *data, double value)
329 {
330         struct appdata *ad = (struct appdata *)data;
331         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
332
333         if (ad->progress_popup_bar) {
334                 bar_percent = value;
335                 elm_progressbar_value_set(ad->progress_popup_bar, value);
336                 evas_object_raise(ad->progress_popup_bar);
337         }
338
339         return TRUE;
340 }
341
342 gboolean cam_popup_delete(void *data)
343 {
344         struct appdata *ad = (struct appdata *)data;
345         cam_retvm_if(ad == NULL, FALSE, "appdata is NULL");
346
347         if (ad->progress_popup != NULL) {
348                 evas_object_del(ad->progress_popup);
349                 ad->progress_popup = NULL;
350         }
351
352         if (ad->progress_popup_bar != NULL) {
353                 evas_object_del(ad->progress_popup_bar);
354                 ad->progress_popup_bar = NULL;
355         }
356
357         bar_percent = 0;
358         bar_text = NULL;
359         add_progress_bar = FALSE;
360
361         return TRUE;
362 }
363
364
365 void cam_popup_rotate(void *data)
366 {
367         struct appdata *ad = (struct appdata *)data;
368         cam_retm_if(ad == NULL, "appdata is NULL");
369
370         unsigned int tmp_percent = bar_percent;
371         char *tmp_text = bar_text;
372         gboolean using_bar = TRUE;
373
374         cam_popup_delete(ad);
375
376         if (!cam_popup_create(ad)) {
377                 cam_critical(LOG_UI, "cam_popup_create() failed");
378                 return;
379         }
380
381         if (add_progress_bar) {
382                 if (!cam_popup_add_progress_bar(ad))
383                         cam_debug(LOG_UI, "cam_popup_add_progress_bar() failed");
384
385                 if (!cam_popup_set_bar_value(ad, tmp_percent))
386                         cam_debug(LOG_UI, "cam_popup_set_bar_value() failed");
387         }
388
389         if (!cam_popup_set_text(ad, tmp_text))
390                 cam_debug(LOG_UI, "cam_popup_set_text() failed");
391 }
392