Fix
[platform/core/system/system-popup.git] / src / common / popup-ui-normal.c
1 /*
2  *  system-popup
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include "popup-ui.h"
21
22 #define BUF_MAX 512
23
24 int load_normal_popup(const struct popup_ops *ops)
25 {
26         Evas_Object *lbtn;
27         Evas_Object *rbtn;
28         Evas_Object *popup;
29         Evas_Object *win;
30         char *text;
31         char content[BUF_MAX];
32         struct object_ops *obj;
33         int ret;
34
35         if (!ops)
36                 return -EINVAL;
37
38         ret = get_object_by_ops(ops, &obj);
39         if (ret < 0) {
40                 _E("Failed to get object (%d)", ret);
41                 return -EINVAL;
42         }
43
44         win = get_window();
45         if (!win)
46                 return -ENOMEM;
47
48         evas_object_show(win);
49
50         popup = elm_popup_add(win);
51         if (!popup)
52                 return -ENOMEM;
53
54         elm_popup_align_set(popup, ELM_NOTIFY_ALIGN_FILL, 1.0);
55         evas_object_size_hint_weight_set(popup,
56                         EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
57
58         if (ops->title)
59                 elm_object_part_text_set(popup, "title,text", _(ops->title));
60
61         if (ops->content)
62                 snprintf(content, sizeof(content), "%s", _(ops->content));
63         else if (ops->get_content) {
64                 ret = ops->get_content(ops, content, sizeof(content));
65                 if (ret < 0) {
66                         _E("Failed to get popup content");
67                         return ret;
68                 }
69         } else
70                 return -ENOENT;
71
72         text = elm_entry_utf8_to_markup(content);
73         if (!text)
74                 return -ENOMEM;
75         elm_object_text_set(popup, text);
76         free(text);
77
78         if (ops->left_text) {
79                 /* Left button */
80                 lbtn = elm_button_add(popup);
81                 if (lbtn) {
82                         elm_object_text_set(lbtn, _(ops->left_text));
83                         elm_object_style_set(lbtn, "bottom");
84                         elm_object_part_content_set(popup, "button1", lbtn);
85                         evas_object_smart_callback_add(lbtn, "clicked", left_clicked, ops);
86                 }
87         }
88
89         if (ops->right_text) {
90                 /* Right button */
91                 rbtn = elm_button_add(popup);
92                 if (rbtn) {
93                         elm_object_text_set(rbtn, _(ops->right_text));
94                         elm_object_style_set(rbtn, "bottom");
95                         elm_object_part_content_set(popup, "button2", rbtn);
96                         evas_object_smart_callback_add(rbtn, "clicked", right_clicked, ops);
97                 }
98         }
99
100         evas_object_show(popup);
101
102         obj->popup = popup;
103
104         return 0;
105 }