elm bin: Use convenient utility function elm_win_util_standard_add()
[framework/uifw/elementary.git] / src / bin / test_weather.c
1 #ifdef HAVE_CONFIG_H
2 # include "elementary_config.h"
3 #endif
4 #include <Elementary.h>
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;
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_util_standard_add("weather", "Weather");
69    elm_win_autodel_set(win, EINA_TRUE);
70
71 #ifdef HAVE_ELEMENTARY_EWEATHER
72    bx = elm_box_add(win);
73    elm_win_resize_object_add(win, bx);
74    evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
75    evas_object_show(bx);
76
77    fl = elm_flip_add(win);
78    evas_object_size_hint_align_set(fl, EVAS_HINT_FILL, EVAS_HINT_FILL);
79    evas_object_size_hint_weight_set(fl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
80    elm_box_pack_end(bx, fl);
81
82    current = 0;
83
84    module[0] = NULL;
85    weather[0] = eweather_object_add(evas_object_evas_get(win));
86    evas_object_size_hint_weight_set(weather[0], EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
87    evas_object_size_hint_align_set(weather[0], -1.0, -1.0);
88    elm_object_part_content_set(fl, "front", weather[0]);
89    evas_object_show(weather[0]);
90
91    module[1] = NULL;
92    weather[1] = eweather_object_add(evas_object_evas_get(win));
93    eweather = eweather_object_eweather_get(weather[1]);
94    evas_object_size_hint_weight_set(weather[1], EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
95    evas_object_size_hint_align_set(weather[1], -1.0, -1.0);
96    elm_object_part_content_set(fl, "back", weather[1]);
97    evas_object_show(weather[1]);
98
99    evas_object_show(fl);
100
101    //
102    bx0 = elm_box_add(win);
103    elm_box_horizontal_set(bx0, EINA_TRUE);
104    evas_object_size_hint_weight_set(bx0, 1.0, 0.0);
105    elm_box_pack_end(bx, bx0);
106    evas_object_show(bx0);
107
108    bt = elm_button_add(win);
109    elm_object_text_set(bt, "First city");
110    evas_object_show(bt);
111    elm_box_pack_end(bx0, bt);
112    evas_object_smart_callback_add(bt, "clicked", _first_city_cb, NULL);
113
114    bt = elm_button_add(win);
115    elm_object_text_set(bt, "Second city");
116    evas_object_show(bt);
117    elm_box_pack_end(bx0, bt);
118    evas_object_smart_callback_add(bt, "clicked", _second_city_cb, NULL);
119    //
120
121    //
122    bx0 = elm_box_add(win);
123    elm_box_horizontal_set(bx0, EINA_TRUE);
124    evas_object_size_hint_weight_set(bx0, 1.0, 0.0);
125    elm_box_pack_end(bx, bx0);
126    evas_object_show(bx0);
127
128    hv = elm_hoversel_add(win);
129    elm_hoversel_hover_parent_set(hv, win);
130    elm_object_text_set(hv, "data source");
131    evas_object_size_hint_weight_set(hv, 0.0, 0.0);
132    evas_object_size_hint_align_set(hv, 0.5, 0.5);
133    elm_box_pack_end(bx0, hv);
134    evas_object_show(hv);
135
136    array = eweather_plugins_list_get(eweather);
137
138    EINA_ARRAY_ITER_NEXT(array, i, m, it)
139      elm_hoversel_item_add(hv, eweather_plugin_name_get(eweather, i), NULL, ELM_ICON_NONE, _hover_select_cb, NULL);
140
141    en = elm_entry_add(win);
142    elm_entry_line_wrap_set(en, ELM_WRAP_NONE);
143    elm_entry_single_line_set(en, EINA_TRUE);
144    elm_object_text_set(en, "Paris");
145    evas_object_size_hint_weight_set(en, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
146    evas_object_size_hint_align_set(en, EVAS_HINT_FILL, EVAS_HINT_FILL);
147    elm_box_pack_end(bx0, en);
148    evas_object_show(en);
149
150    bt = elm_button_add(win);
151    elm_object_text_set(bt, "Apply");
152    evas_object_show(bt);
153    elm_box_pack_end(bx0, bt);
154    evas_object_smart_callback_add(bt, "clicked", _apply_cb, NULL);
155    //
156
157
158 #else
159     Evas_Object *lbl;
160
161     lbl = elm_label_add(win);
162     elm_win_resize_object_add(win, lbl);
163     elm_object_text_set(lbl, "libeweather is required to display the forecast.");
164     evas_object_show(lbl);
165 #endif
166
167     evas_object_resize(win, 244, 388);
168     evas_object_show(win);
169 }
170 #endif