add messages stub.
[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
12 #ifdef HAVE_TIZEN
13 #include <appcore-efl.h>
14 #include <ui-gadget.h>
15 #include <Ecore_X.h>
16 #endif
17
18 static Evas_Object *win = NULL;
19 static Evas_Object *main_layout = NULL;
20 static Evas_Object *cs = NULL;
21 static Evas_Object *flip = NULL;
22
23 /* XXX elm_flip should just do the right thing, but it does not */
24 static Eina_Bool in_compose = EINA_FALSE;
25 static Eina_Bool in_flip_anim = EINA_FALSE;
26
27 Evas_Object *gui_simple_popup(const char *title, const char *message)
28 {
29         return simple_popup_add(win, title, message);
30 }
31
32 void gui_activate(void)
33 {
34         elm_win_raise(win);
35         elm_win_activate(win);
36         evas_object_show(win);
37 }
38
39 void gui_send(const char *number, const char *message, Eina_Bool do_auto)
40 {
41         compose_set(cs, number, message, do_auto);
42 }
43
44 void gui_compose_enter(void)
45 {
46         gui_activate();
47         if (in_compose)
48                 return;
49         in_compose = EINA_TRUE;
50         if (in_flip_anim)
51                 return;
52         in_flip_anim = EINA_TRUE;
53         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
54         elm_object_focus_set(cs, EINA_TRUE);
55 }
56
57 void gui_compose_exit(void)
58 {
59         if (!in_compose)
60                 return;
61         in_compose = EINA_FALSE;
62         if (in_flip_anim)
63                 return;
64         in_flip_anim = EINA_TRUE;
65         elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
66         elm_object_focus_set(cs, EINA_FALSE);
67 }
68
69 static void _gui_compose_sync(void *data __UNUSED__, Evas_Object *o __UNUSED__,
70                                 void *event_info __UNUSED__)
71 {
72         Eina_Bool showing_compose = !elm_flip_front_visible_get(flip);
73
74         if (showing_compose ^ in_compose) {
75                 DBG("Flip back to sync");
76                 elm_flip_go(flip, ELM_FLIP_ROTATE_Y_CENTER_AXIS);
77                 elm_object_focus_set(cs, in_compose);
78         }
79         in_flip_anim = EINA_FALSE;
80 }
81
82 static void _on_clicked(void *data __UNUSED__, Evas_Object *o __UNUSED__,
83                         const char *emission, const char *source __UNUSED__)
84 {
85         DBG("signal: %s", emission);
86
87         EINA_SAFETY_ON_FALSE_RETURN(eina_str_has_prefix(emission, "clicked,"));
88         emission += strlen("clicked,");
89
90         ERR("TODO: %s", emission);
91 }
92
93 Eina_Bool gui_init(void)
94 {
95         Evas_Object *lay, *obj;
96         Evas_Coord w, h;
97
98         /* messages should never, ever quit */
99         elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_NONE);
100
101         win = elm_win_util_standard_add("ofono-messages", "oFono Messages");
102         EINA_SAFETY_ON_NULL_RETURN_VAL(win, EINA_FALSE);
103         elm_win_autodel_set(win, EINA_FALSE);
104
105 #ifdef HAVE_TIZEN
106         appcore_set_i18n("ofono-efl", "en-US");
107         UG_INIT_EFL(win, UG_OPT_INDICATOR_PORTRAIT_ONLY);
108 #endif
109
110         flip = elm_flip_add(win);
111         evas_object_size_hint_weight_set(flip,
112                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
113         evas_object_size_hint_align_set(flip, EVAS_HINT_FILL, EVAS_HINT_FILL);
114         elm_win_resize_object_add(win, flip);
115         evas_object_smart_callback_add(flip, "animate,done",
116                                         _gui_compose_sync, NULL);
117         evas_object_show(flip);
118
119         main_layout = lay = layout_add(win, "messages");
120         EINA_SAFETY_ON_NULL_RETURN_VAL(lay, EINA_FALSE);
121         evas_object_size_hint_weight_set(lay,
122                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
123         evas_object_size_hint_align_set(lay, EVAS_HINT_FILL, EVAS_HINT_FILL);
124         elm_object_part_content_set(flip, "front", lay);
125         evas_object_show(lay);
126
127         elm_object_signal_callback_add(lay, "clicked,*", "gui",
128                                         _on_clicked, NULL);
129
130         cs = obj = compose_add(win);
131         EINA_SAFETY_ON_NULL_RETURN_VAL(obj, EINA_FALSE);
132         evas_object_size_hint_weight_set(obj,
133                                 EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
134         evas_object_size_hint_align_set(obj, EVAS_HINT_FILL, EVAS_HINT_FILL);
135         elm_object_part_content_set(flip, "back", obj);
136         evas_object_show(obj);
137
138         /* TODO: make it match better with Tizen: icon and other properties */
139         obj = elm_layout_edje_get(lay);
140         edje_object_size_min_get(obj, &w, &h);
141         if ((w == 0) || (h == 0))
142                 edje_object_size_min_restricted_calc(obj, &w, &h, w, h);
143         if ((w == 0) || (h == 0))
144                 edje_object_parts_extends_calc(obj, NULL, NULL, &w, &h);
145         evas_object_resize(win, w, h);
146
147         /* do not show it yet, RC will check if it should be visible or not */
148         return EINA_TRUE;
149 }
150
151 void gui_shutdown(void)
152 {
153 }