theme: allow specify different theme at command line.
[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_activecall_set(Evas_Object *o)
85 {
86         if (o) {
87                 elm_object_part_content_set(main_layout,
88                                                 "elm.swallow.activecall", o);
89                 elm_object_signal_emit(main_layout, "show,activecall", "gui");
90         } else {
91                 o = elm_object_part_content_unset(
92                         main_layout, "elm.swallow.activecall");
93                 elm_object_signal_emit(main_layout, "hide,activecall", "gui");
94                 evas_object_hide(o);
95         }
96 }
97
98 void gui_call_enter(void)
99 {
100         gui_activate();
101         if (in_call)
102                 return;
103         in_call = EINA_TRUE;
104         if (in_flip_anim)
105                 return;
106         in_flip_anim = EINA_TRUE;
107         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
108         elm_object_focus_set(cs, EINA_TRUE);
109 }
110
111 void gui_call_exit(void)
112 {
113         if (!in_call)
114                 return;
115         in_call = EINA_FALSE;
116         if (in_flip_anim)
117                 return;
118         in_flip_anim = EINA_TRUE;
119         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
120         elm_object_focus_set(cs, EINA_FALSE);
121 }
122
123 static void _gui_call_sync(void *data __UNUSED__, Evas_Object *o __UNUSED__,
124                                 void *event_info __UNUSED__)
125 {
126         Eina_Bool showing_call = !elm_flip_front_visible_get(flip);
127
128         if (showing_call ^ in_call) {
129                 DBG("Flip back to sync");
130                 elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
131                 elm_object_focus_set(cs, in_call);
132         }
133         in_flip_anim = EINA_FALSE;
134 }
135
136 static void _on_clicked(void *data __UNUSED__, Evas_Object *o __UNUSED__,
137                         const char *emission, const char *source __UNUSED__)
138 {
139         DBG("signal: %s", emission);
140
141         EINA_SAFETY_ON_FALSE_RETURN(eina_str_has_prefix(emission, "clicked,"));
142         emission += strlen("clicked,");
143
144         if (strcmp(emission, "keypad") == 0)
145                 _gui_show(keypad);
146         else if (strcmp(emission, "contacts") == 0)
147                 _gui_show(contacts);
148         else if (strcmp(emission, "history") == 0)
149                 _gui_show(history);
150 }
151
152 Eina_Bool gui_init(const char *theme)
153 {
154         Evas_Object *lay, *obj;
155         Evas_Coord w, h;
156
157         /* dialer should never, ever quit */
158         elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_NONE);
159
160         elm_app_compile_bin_dir_set(PACKAGE_BIN_DIR);
161         elm_app_compile_data_dir_set(PACKAGE_DATA_DIR);
162         elm_app_info_set(gui_init, "ofono-efl", "themes/default.edj");
163
164         snprintf(def_theme, sizeof(def_theme), "%s/themes/default.edj",
165                         elm_app_data_dir_get());
166
167         elm_theme_extension_add(NULL, def_theme);
168         if (!theme)
169                 elm_theme_overlay_add(NULL, def_theme);
170         else {
171                 char tmp[PATH_MAX];
172                 if (theme[0] != '/') {
173                         if (eina_str_has_suffix(theme, ".edj")) {
174                                 snprintf(tmp, sizeof(tmp), "%s/themes/%s",
175                                                 elm_app_data_dir_get(), theme);
176                         } else {
177                                 snprintf(tmp, sizeof(tmp), "%s/themes/%s.edj",
178                                                 elm_app_data_dir_get(), theme);
179                         }
180                         theme = tmp;
181                 }
182                 elm_theme_overlay_add(NULL, theme);
183         }
184
185         win = elm_win_util_standard_add("ofono-dialer", "oFono Dialer");
186         EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
187         elm_win_autodel_set(win, EINA_FALSE);
188
189         flip = elm_flip_add(win);
190         evas_object_size_hint_weight_set(flip,
191                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
192         evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
193         elm_win_resize_object_add(win, flip);
194         evas_object_smart_callback_add(flip, "animate,done",
195                                         _gui_call_sync, NULL);
196         evas_object_show(flip);
197
198         main_layout = lay = gui_layout_add(win, "main");
199         EINA_SAFETY_ON_NULL_RETURN_VAL(lay, EINA_FALSE);
200         evas_object_size_hint_weight_set(lay,
201                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
202         evas_object_size_hint_align_set(lay, EVAS_HINT_FILL, EVAS_HINT_FILL);
203         elm_object_part_content_set(flip, "front", lay);
204         evas_object_show(lay);
205
206         elm_object_signal_callback_add(lay, "clicked,*", "gui",
207                                         _on_clicked, NULL);
208
209         keypad = obj = keypad_add(win);
210         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
211         elm_object_part_content_set(lay, "elm.swallow.keypad", obj);
212
213         contacts = obj = contacts_add(win);
214         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
215         elm_object_part_content_set(lay, "elm.swallow.contacts", obj);
216
217         history = obj = history_add(win);
218         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
219         elm_object_part_content_set(lay, "elm.swallow.history", obj);
220
221         _gui_show(keypad);
222
223         cs = obj = callscreen_add(win);
224         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
225         evas_object_size_hint_weight_set(obj,
226                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
227         evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
228         elm_object_part_content_set(flip, "back", obj);
229         evas_object_show(obj);
230
231         /* TODO: make it match better with Tizen: icon and other properties */
232         obj = elm_layout_edje_get(lay);
233         edje_object_size_min_get(obj, &w, &h);
234         if ((w == 0) || (h == 0))
235                 edje_object_size_min_restricted_calc(obj, &w, &h, w, h);
236         if ((w == 0) || (h == 0))
237                 edje_object_parts_extends_calc(obj, NULL, NULL, &w, &h);
238         evas_object_resize(win, w, h);
239
240         /* do not show it yet, RC will check if it should be visible or not */
241         return EINA_TRUE;
242 }
243
244 void gui_shutdown(void)
245 {
246 }