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