elementary: Updated test_bubble.c to do API testing
[framework/uifw/elementary.git] / src / bin / test_weather.c
1 #include <Elementary.h>
2 #ifdef HAVE_CONFIG_H
3 # include "elementary_config.h"
4 #endif
5 #ifndef ELM_LIB_QUICKLAUNCH
6
7 #ifdef HAVE_ELEMENTARY_EWEATHER
8 # include "EWeather_Smart.h"
9 #endif
10
11 #ifdef HAVE_ELEMENTARY_EWEATHER
12 static Evas_Object *en, *hv, *fl;
13 static Evas_Object *weather[2];
14 static int current = 0;
15 static Eina_Module *module[2];
16
17 static void
18 _first_city_cb(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
19 {
20    if (!current) return;
21    current = 0;
22    elm_flip_go(fl, ELM_FLIP_ROTATE_YZ_CENTER_AXIS);
23 }
24
25 static void
26 _second_city_cb(void *dat __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
27 {
28    if (current) return;
29    current = 1;
30    elm_flip_go(fl, ELM_FLIP_ROTATE_XZ_CENTER_AXIS);
31 }
32
33 static void _apply_cb(void *data __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
34 {
35    EWeather *eweather = eweather_object_eweather_get(weather[current]);
36
37    if (module[current])
38      eweather_plugin_set(eweather, module[current]);
39    eweather_code_set(eweather, elm_object_text_get(en));
40    printf("CURRENT %d %p %p\n", current, module[current], eweather);
41 }
42
43 static void
44 _hover_select_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
45 {
46    EWeather *eweather = eweather_object_eweather_get(weather[0]);
47    module[0] = eweather_plugin_search(eweather, elm_object_item_text_get(event_info));
48
49    eweather = eweather_object_eweather_get(weather[1]);
50    module[1] = eweather_plugin_search(eweather, elm_object_item_text_get(event_info));
51    printf("%p %p\n", module[0], module[1]);
52 }
53 #endif
54
55 void
56 test_weather(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
57 {
58    Evas_Object *win, *bg;
59 #ifdef HAVE_ELEMENTARY_EWEATHER
60    Evas_Object *bx, *bx0, *bt;
61    EWeather *eweather;
62    Eina_Array_Iterator it;
63    Eina_Array *array;
64    Eina_Module *m;
65    unsigned int i;
66 #endif
67
68    win = elm_win_add(NULL, "weather", ELM_WIN_BASIC);
69    elm_win_title_set(win, "Weather");
70    elm_win_autodel_set(win, EINA_TRUE);
71
72    bg = elm_bg_add(win);
73    evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
74    elm_win_resize_object_add(win, bg);
75    evas_object_show(bg);
76
77 #ifdef HAVE_ELEMENTARY_EWEATHER
78    bx = elm_box_add(win);
79    elm_win_resize_object_add(win, bx);
80    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
81    evas_object_show(bx);
82
83    fl = elm_flip_add(win);
84    evas_object_size_hint_align_set(fl, EVAS_HINT_FILL, EVAS_HINT_FILL);
85    evas_object_size_hint_weight_set(fl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
86    elm_box_pack_end(bx, fl);
87
88    current = 0;
89
90    module[0] = NULL;
91    weather[0] = eweather_object_add(evas_object_evas_get(win));
92    evas_object_size_hint_weight_set(weather[0], EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
93    evas_object_size_hint_align_set(weather[0], -1.0, -1.0);
94    elm_object_part_content_set(fl, "front", weather[0]);
95    evas_object_show(weather[0]);
96
97    module[1] = NULL;
98    weather[1] = eweather_object_add(evas_object_evas_get(win));
99    eweather = eweather_object_eweather_get(weather[1]);
100    evas_object_size_hint_weight_set(weather[1], EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
101    evas_object_size_hint_align_set(weather[1], -1.0, -1.0);
102    elm_object_part_content_set(fl, "back", weather[1]);
103    evas_object_show(weather[1]);
104
105    evas_object_show(fl);
106
107    //
108    bx0 = elm_box_add(win);
109    elm_box_horizontal_set(bx0, EINA_TRUE);
110    evas_object_size_hint_weight_set(bx0, 1.0, 0.0);
111    elm_box_pack_end(bx, bx0);
112    evas_object_show(bx0);
113
114    bt = elm_button_add(win);
115    elm_object_text_set(bt, "First city");
116    evas_object_show(bt);
117    elm_box_pack_end(bx0, bt);
118    evas_object_smart_callback_add(bt, "clicked", _first_city_cb, NULL);
119
120    bt = elm_button_add(win);
121    elm_object_text_set(bt, "Second city");
122    evas_object_show(bt);
123    elm_box_pack_end(bx0, bt);
124    evas_object_smart_callback_add(bt, "clicked", _second_city_cb, NULL);
125    //
126
127    //
128    bx0 = elm_box_add(win);
129    elm_box_horizontal_set(bx0, EINA_TRUE);
130    evas_object_size_hint_weight_set(bx0, 1.0, 0.0);
131    elm_box_pack_end(bx, bx0);
132    evas_object_show(bx0);
133
134    hv = elm_hoversel_add(win);
135    elm_hoversel_hover_parent_set(hv, win);
136    elm_object_text_set(hv, "data source");
137    evas_object_size_hint_weight_set(hv, 0.0, 0.0);
138    evas_object_size_hint_align_set(hv, 0.5, 0.5);
139    elm_box_pack_end(bx0, hv);
140    evas_object_show(hv);
141
142    array = eweather_plugins_list_get(eweather);
143
144    EINA_ARRAY_ITER_NEXT(array, i, m, it)
145      elm_hoversel_item_add(hv, eweather_plugin_name_get(eweather, i), NULL, ELM_ICON_NONE, _hover_select_cb, NULL);
146
147    en = elm_entry_add(win);
148    elm_entry_line_wrap_set(en, ELM_WRAP_NONE);
149    elm_entry_single_line_set(en, EINA_TRUE);
150    elm_object_text_set(en, "Paris");
151    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
152    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
153    elm_box_pack_end(bx0, en);
154    evas_object_show(en);
155
156    bt = elm_button_add(win);
157    elm_object_text_set(bt, "Apply");
158    evas_object_show(bt);
159    elm_box_pack_end(bx0, bt);
160    evas_object_smart_callback_add(bt, "clicked", _apply_cb, NULL);
161    //
162
163
164 #else
165     Evas_Object *lbl;
166
167     lbl = elm_label_add(win);
168     elm_win_resize_object_add(win, lbl);
169     elm_object_text_set(lbl, "libeweather is required to display the forecast.");
170     evas_object_show(lbl);
171 #endif
172
173     evas_object_resize(win, 244, 388);
174     evas_object_show(win);
175 }
176 #endif