window at 720x1280, Tizen's default.
[profile/ivi/lemolo.git] / dialer / gui.c
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4 #include <Elementary.h>
5
6 #include "log.h"
7 #include "gui.h"
8 #include "keypad.h"
9 #include "callscreen.h"
10
11 static Evas_Object *win = NULL;
12 static Evas_Object *kp = NULL;
13 static Evas_Object *cs = NULL;
14 static Evas_Object *flip = NULL;
15 static char def_theme[PATH_MAX] = "";
16
17 /* XXX elm_flip should just do the right thing, but it does not */
18 static Eina_Bool in_call = EINA_FALSE;
19 static Eina_Bool in_flip_anim = EINA_FALSE;
20
21 Evas_Object *gui_layout_add(Evas_Object *parent, const char *style)
22 {
23         Evas_Object *layout = elm_layout_add(parent);
24         if (!elm_layout_theme_set(layout, "layout", "dialer", style)) {
25                 CRITICAL("No theme for 'elm/layout/dialer/%s' at %s",
26                                 style, def_theme);
27                 evas_object_del(layout);
28                 return NULL;
29         }
30         return layout;
31 }
32
33 static void _popup_close(void *data, Evas_Object *bt __UNUSED__, void *event __UNUSED__)
34 {
35         Evas_Object *popup = data;
36         evas_object_del(popup);
37 }
38
39 void gui_simple_popup(const char *title, const char *message)
40 {
41         Evas_Object *p = elm_popup_add(win);
42         Evas_Object *bt;
43
44         evas_object_size_hint_weight_set(p, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
45         elm_object_text_set(p, message);
46         elm_object_part_text_set(p, "title,text", title);
47
48         bt = elm_button_add(p);
49         elm_object_text_set(bt, "Close");
50         elm_object_part_content_set(p, "button1", bt);
51         evas_object_smart_callback_add(bt, "clicked", _popup_close, p);
52         evas_object_show(p);
53 }
54
55 void gui_activate(void)
56 {
57         elm_win_raise(win);
58         elm_win_activate(win);
59         evas_object_show(win);
60 }
61
62 void gui_number_set(const char *number, Eina_Bool auto_dial)
63 {
64         /* TODO: show keypad */
65         keypad_number_set(kp, number, auto_dial);
66 }
67
68 void gui_call_enter(void)
69 {
70         if (in_call)
71                 return;
72         in_call = EINA_TRUE;
73         if (in_flip_anim)
74                 return;
75         in_flip_anim = EINA_TRUE;
76         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
77 }
78
79 void gui_call_exit(void)
80 {
81         if (!in_call)
82                 return;
83         in_call = EINA_FALSE;
84         if (in_flip_anim)
85                 return;
86         in_flip_anim = EINA_TRUE;
87         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
88 }
89
90 static void _gui_call_sync(void *data __UNUSED__, Evas_Object *o __UNUSED__,
91                                 void *event_info __UNUSED__)
92 {
93         Eina_Bool showing_call = !elm_flip_front_visible_get(flip);
94
95         if (showing_call ^ in_call) {
96                 DBG("Flip back to sync");
97                 elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
98         }
99         in_flip_anim = EINA_FALSE;
100 }
101
102 Eina_Bool gui_init(void)
103 {
104         Evas_Object *lay, *obj;
105
106         /* dialer should never, ever quit */
107         elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_NONE);
108
109         elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
110         elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
111         elm_app_info_set(gui_init, "ofono-efl", "themes/default.edj");
112
113         snprintf(def_theme, sizeof(def_theme), "%s/themes/default.edj",
114                         elm_app_data_dir_get());
115
116         elm_theme_extension_add(NULL, def_theme);
117         elm_theme_overlay_add(NULL, def_theme);
118
119         win = elm_win_util_standard_add("ofono-dialer", "oFono Dialer");
120         EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
121         elm_win_autodel_set(win, EINA_FALSE);
122
123         flip = elm_flip_add(win);
124         evas_object_size_hint_weight_set(flip,
125                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
126         evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
127         elm_win_resize_object_add(win, flip);
128         evas_object_smart_callback_add(flip, "animate,done",
129                                         _gui_call_sync, NULL);
130         evas_object_show(flip);
131
132         lay = gui_layout_add(win, "main");
133         EINA_SAFETY_ON_NULL_RETURN_VAL(lay, EINA_FALSE);
134         evas_object_size_hint_weight_set(lay,
135                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
136         evas_object_size_hint_align_set(lay, EVAS_HINT_FILL, EVAS_HINT_FILL);
137         elm_object_part_content_set(flip, "front", lay);
138         evas_object_show(lay);
139
140         kp = obj = keypad_add(win);
141         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
142         elm_object_part_content_set(lay, "elm.swallow.keypad", obj);
143
144         cs = obj = callscreen_add(win);
145         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
146         evas_object_size_hint_weight_set(obj,
147                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148         evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
149         elm_object_part_content_set(flip, "back", obj);
150         evas_object_show(obj);
151
152         /* TODO: make it match better with Tizen: icon and other properties */
153         evas_object_resize(win, 720, 1280);
154
155         /* do not show it yet, RC will check if it should be visible or not */
156         return EINA_TRUE;
157 }
158
159 void gui_shutdown(void)
160 {
161 }