Fix TC-2372 Dialer crashes when BT phone is offline
[profile/ivi/lemolo.git] / messages / 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 "compose.h"
9 #include "util.h"
10 #include "simple-popup.h"
11 #include "contacts-ofono-efl.h"
12
13 #ifdef HAVE_TIZEN
14 #include <appcore-efl.h>
15 #ifdef HAVE_UI_GADGET
16 #include <ui-gadget.h>
17 #endif
18 #endif
19
20 static Evas_Object *win = NULL;
21 static Evas_Object *main_layout = NULL;
22 static Evas_Object *cs = NULL;
23 static Evas_Object *flip = NULL;
24 static Evas_Object *ov = NULL;
25 static Evas_Object *contacts = NULL;
26
27 /* XXX elm_flip should just do the right thing, but it does not */
28 static Eina_Bool in_compose = EINA_FALSE;
29 static Eina_Bool in_flip_anim = EINA_FALSE;
30
31 Eina_List * gui_contact_partial_match_search(const char *query)
32 {
33         return contact_partial_match_search(contacts, query);
34 }
35
36 void gui_overview_genlist_update(Message *msg, const char *contact)
37 {
38         overview_genlist_update(ov, msg, contact);
39 }
40
41 void gui_overview_all_contact_messages_clear(const char *contact)
42 {
43         overview_all_contact_messages_clear(ov, contact);
44 }
45
46 void gui_message_from_file_delete(Message *msg, const char *contact)
47 {
48         overview_message_from_file_delete(ov, msg, contact);
49 }
50
51 void gui_compose_messages_set(Eina_List *list, const char *number)
52 {
53         compose_messages_set(cs, list, number);
54 }
55
56 Contact_Info *gui_contact_search(const char *number, const char **type)
57 {
58         return contact_search(contacts, number, type);
59 }
60
61 Evas_Object *gui_simple_popup(const char *title, const char *message)
62 {
63         return simple_popup_add(win, title, message);
64 }
65
66 void gui_activate(void)
67 {
68         elm_win_raise(win);
69         elm_win_activate(win);
70         evas_object_show(win);
71 }
72
73 void gui_send(const char *number, const char *message, Eina_Bool do_auto)
74 {
75         compose_set(cs, number, message, do_auto);
76 }
77
78 void gui_compose_enter(void)
79 {
80         gui_activate();
81         if (in_compose)
82                 return;
83         in_compose = EINA_TRUE;
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         elm_object_focus_set(cs, EINA_TRUE);
89 }
90
91 void gui_compose_exit(void)
92 {
93         if (!in_compose)
94                 return;
95         in_compose = EINA_FALSE;
96         if (in_flip_anim)
97                 return;
98         in_flip_anim = EINA_TRUE;
99         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
100         elm_object_focus_set(cs, EINA_FALSE);
101 }
102
103 static void _gui_compose_sync(void *data __UNUSED__, Evas_Object *o __UNUSED__,
104                                 void *event_info __UNUSED__)
105 {
106         Eina_Bool showing_compose = !elm_flip_front_visible_get(flip);
107
108         if (showing_compose ^ in_compose) {
109                 DBG("Flip back to sync");
110                 elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
111                 elm_object_focus_set(cs, in_compose);
112         }
113         in_flip_anim = EINA_FALSE;
114 }
115
116 static void _on_clicked(void *data __UNUSED__, Evas_Object *o __UNUSED__,
117                         const char *emission, const char *source __UNUSED__)
118 {
119         DBG("signal: %s", emission);
120
121         EINA_SAFETY_ON_FALSE_RETURN(eina_str_has_prefix(emission, "clicked,"));
122         emission += strlen("clicked,");
123 }
124
125 Eina_Bool gui_init(void)
126 {
127         Evas_Object *lay, *obj, *conform;
128         Evas_Coord w, h;
129
130         /* messages should never, ever quit */
131         elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_NONE);
132
133         win = elm_win_util_standard_add("ofono-messages", "oFono Messages");
134         EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
135         elm_win_autodel_set(win, EINA_FALSE);
136         elm_win_conformant_set(win, EINA_TRUE);
137
138 #ifdef HAVE_TIZEN
139         appcore_set_i18n("ofono-efl", "en-US");
140 #ifdef HAVE_UI_GADGET
141         UG_INIT_EFL(win, UG_OPT_INDICATOR_PORTRAIT_ONLY);
142 #endif
143 #endif
144
145         flip = elm_flip_add(win);
146         evas_object_size_hint_weight_set(flip,
147                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
148         evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
149         elm_win_resize_object_add(win, flip);
150         evas_object_smart_callback_add(flip, "animate,done",
151                                         _gui_compose_sync, NULL);
152         evas_object_show(flip);
153
154         main_layout = lay = layout_add(win, "messages");
155         EINA_SAFETY_ON_NULL_RETURN_VAL(lay, EINA_FALSE);
156         evas_object_size_hint_weight_set(lay,
157                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
158         evas_object_size_hint_align_set(lay, EVAS_HINT_FILL, EVAS_HINT_FILL);
159         elm_object_part_content_set(flip, "front", lay);
160         evas_object_show(lay);
161
162         elm_object_signal_callback_add(lay, "clicked,*", "gui",
163                                         _on_clicked, NULL);
164
165         contacts = obj = contacts_add(win);
166         EINA_SAFETY_ON_NULL_RETURN_VAL(contacts, EINA_FALSE);
167
168         cs = obj = compose_add(win);
169         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
170         evas_object_size_hint_weight_set(obj,
171                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
172         evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
173         evas_object_show(obj);
174
175         ov = obj = overview_add(win);
176         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
177         elm_object_part_content_set(lay, "elm.swallow.overview", obj);
178         evas_object_show(ov);
179
180         conform = elm_conformant_add(win);
181         EINA_SAFETY_ON_NULL_RETURN_VAL(conform, EINA_FALSE);
182         elm_win_resize_object_add(win, conform);
183         evas_object_size_hint_weight_set(conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
184         evas_object_show(conform);
185         elm_object_content_set(conform, cs);
186         elm_object_part_content_set(flip, "back", conform);
187
188         /* TODO: make it match better with Tizen: icon and other properties */
189         obj = elm_layout_edje_get(lay);
190         edje_object_size_min_get(obj, &w, &h);
191         if ((w == 0) || (h == 0))
192                 edje_object_size_min_restricted_calc(obj, &w, &h, w, h);
193         if ((w == 0) || (h == 0))
194                 edje_object_parts_extends_calc(obj, NULL, NULL, &w, &h);
195         evas_object_resize(win, w, h);
196
197         /* do not show it yet, RC will check if it should be visible or not */
198         return EINA_TRUE;
199 }
200
201 void gui_shutdown(void)
202 {
203 }