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