callscreen: activate window on incoming calls.
[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 "contacts.h"
10 #include "history.h"
11 #include "callscreen.h"
12
13 static Evas_Object *win = NULL;
14 static Evas_Object *main_layout = NULL;
15 static Evas_Object *keypad = NULL;
16 static Evas_Object *contacts = NULL;
17 static Evas_Object *history = NULL;
18 static Evas_Object *cs = NULL;
19 static Evas_Object *flip = NULL;
20 static char def_theme[PATH_MAX] = "";
21
22 /* XXX elm_flip should just do the right thing, but it does not */
23 static Eina_Bool in_call = EINA_FALSE;
24 static Eina_Bool in_flip_anim = EINA_FALSE;
25
26 Evas_Object *gui_layout_add(Evas_Object *parent, const char *style)
27 {
28         Evas_Object *layout = elm_layout_add(parent);
29         if (!elm_layout_theme_set(layout, "layout", "dialer", style)) {
30                 CRITICAL("No theme for 'elm/layout/dialer/%s' at %s",
31                                 style, def_theme);
32                 evas_object_del(layout);
33                 return NULL;
34         }
35         return layout;
36 }
37
38 static void _gui_show(Evas_Object *o)
39 {
40         if (o == keypad)
41                 elm_object_signal_emit(main_layout, "show,keypad", "gui");
42         else if (o == contacts)
43                 elm_object_signal_emit(main_layout, "show,contacts", "gui");
44         else if (o == history)
45                 elm_object_signal_emit(main_layout, "show,history", "gui");
46         elm_object_focus_set(o, EINA_TRUE);
47 }
48
49 static void _popup_close(void *data, Evas_Object *bt __UNUSED__, void *event __UNUSED__)
50 {
51         Evas_Object *popup = data;
52         evas_object_del(popup);
53 }
54
55 void gui_simple_popup(const char *title, const char *message)
56 {
57         Evas_Object *p = elm_popup_add(win);
58         Evas_Object *bt;
59
60         evas_object_size_hint_weight_set(p, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
61         elm_object_text_set(p, message);
62         elm_object_part_text_set(p, "title,text", title);
63
64         bt = elm_button_add(p);
65         elm_object_text_set(bt, "Close");
66         elm_object_part_content_set(p, "button1", bt);
67         evas_object_smart_callback_add(bt, "clicked", _popup_close, p);
68         evas_object_show(p);
69 }
70
71 void gui_activate(void)
72 {
73         elm_win_raise(win);
74         elm_win_activate(win);
75         evas_object_show(win);
76 }
77
78 void gui_number_set(const char *number, Eina_Bool auto_dial)
79 {
80         _gui_show(keypad);
81         keypad_number_set(keypad, number, auto_dial);
82 }
83
84 void gui_call_enter(void)
85 {
86         gui_activate();
87         if (in_call)
88                 return;
89         in_call = EINA_TRUE;
90         if (in_flip_anim)
91                 return;
92         in_flip_anim = EINA_TRUE;
93         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
94         elm_object_focus_set(cs, EINA_TRUE);
95 }
96
97 void gui_call_exit(void)
98 {
99         if (!in_call)
100                 return;
101         in_call = EINA_FALSE;
102         if (in_flip_anim)
103                 return;
104         in_flip_anim = EINA_TRUE;
105         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
106         elm_object_focus_set(cs, EINA_FALSE);
107 }
108
109 static void _gui_call_sync(void *data __UNUSED__, Evas_Object *o __UNUSED__,
110                                 void *event_info __UNUSED__)
111 {
112         Eina_Bool showing_call = !elm_flip_front_visible_get(flip);
113
114         if (showing_call ^ in_call) {
115                 DBG("Flip back to sync");
116                 elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
117                 elm_object_focus_set(cs, in_call);
118         }
119         in_flip_anim = EINA_FALSE;
120 }
121
122 static void _on_clicked(void *data __UNUSED__, Evas_Object *o __UNUSED__,
123                         const char *emission, const char *source __UNUSED__)
124 {
125         DBG("signal: %s", emission);
126
127         EINA_SAFETY_ON_FALSE_RETURN(eina_str_has_prefix(emission, "clicked,"));
128         emission += strlen("clicked,");
129
130         if (strcmp(emission, "keypad") == 0)
131                 _gui_show(keypad);
132         else if (strcmp(emission, "contacts") == 0)
133                 _gui_show(contacts);
134         else if (strcmp(emission, "history") == 0)
135                 _gui_show(history);
136 }
137
138 Eina_Bool gui_init(void)
139 {
140         Evas_Object *lay, *obj;
141
142         /* dialer should never, ever quit */
143         elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_NONE);
144
145         elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
146         elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
147         elm_app_info_set(gui_init, "ofono-efl", "themes/default.edj");
148
149         snprintf(def_theme, sizeof(def_theme), "%s/themes/default.edj",
150                         elm_app_data_dir_get());
151
152         elm_theme_extension_add(NULL, def_theme);
153         elm_theme_overlay_add(NULL, def_theme);
154
155         win = elm_win_util_standard_add("ofono-dialer", "oFono Dialer");
156         EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
157         elm_win_autodel_set(win, EINA_FALSE);
158
159         flip = elm_flip_add(win);
160         evas_object_size_hint_weight_set(flip,
161                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
162         evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
163         elm_win_resize_object_add(win, flip);
164         evas_object_smart_callback_add(flip, "animate,done",
165                                         _gui_call_sync, NULL);
166         evas_object_show(flip);
167
168         main_layout = lay = gui_layout_add(win, "main");
169         EINA_SAFETY_ON_NULL_RETURN_VAL(lay, EINA_FALSE);
170         evas_object_size_hint_weight_set(lay,
171                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
172         evas_object_size_hint_align_set(lay, EVAS_HINT_FILL, EVAS_HINT_FILL);
173         elm_object_part_content_set(flip, "front", lay);
174         evas_object_show(lay);
175
176         elm_object_signal_callback_add(lay, "clicked,*", "gui",
177                                         _on_clicked, NULL);
178
179         keypad = obj = keypad_add(win);
180         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
181         elm_object_part_content_set(lay, "elm.swallow.keypad", obj);
182
183         contacts = obj = contacts_add(win);
184         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
185         elm_object_part_content_set(lay, "elm.swallow.contacts", obj);
186
187         history = obj = history_add(win);
188         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
189         elm_object_part_content_set(lay, "elm.swallow.history", obj);
190
191         _gui_show(keypad);
192
193         cs = obj = callscreen_add(win);
194         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
195         evas_object_size_hint_weight_set(obj,
196                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
197         evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
198         elm_object_part_content_set(flip, "back", obj);
199         evas_object_show(obj);
200
201         /* TODO: make it match better with Tizen: icon and other properties */
202         evas_object_resize(win, 720, 1280);
203
204         /* do not show it yet, RC will check if it should be visible or not */
205         return EINA_TRUE;
206 }
207
208 void gui_shutdown(void)
209 {
210 }