summaryrefslogtreecommitdiff
path: root/src/examples/ecore
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2012-12-03 19:36:16 +0000
committerVincent Torri <vincent.torri@gmail.com>2012-12-03 19:36:16 +0000
commit46d4358209ca9e74d77b1580525e309427636411 (patch)
tree921549811a22217ecbad58932266415e10777d32 /src/examples/ecore
parent128074a2bd09fa5c1f467b95c1c0446c68052d99 (diff)
Ecore: add examples
SVN revision: 80097
Diffstat (limited to 'src/examples/ecore')
-rw-r--r--src/examples/ecore/Makefile.am186
-rw-r--r--src/examples/ecore/ecore_animator_example.c117
-rw-r--r--src/examples/ecore/ecore_client_bench.c79
-rw-r--r--src/examples/ecore/ecore_con_client_example.c92
-rw-r--r--src/examples/ecore/ecore_con_client_simple_example.c126
-rw-r--r--src/examples/ecore/ecore_con_lookup_example.c40
-rw-r--r--src/examples/ecore/ecore_con_server_example.c81
-rw-r--r--src/examples/ecore/ecore_con_server_http_example.c136
-rw-r--r--src/examples/ecore/ecore_con_server_simple_example.c133
-rw-r--r--src/examples/ecore/ecore_con_url_cookies_example.c123
-rw-r--r--src/examples/ecore/ecore_con_url_download_example.c115
-rw-r--r--src/examples/ecore/ecore_con_url_headers_example.c106
-rw-r--r--src/examples/ecore/ecore_evas_basics_example.c89
-rw-r--r--src/examples/ecore/ecore_evas_buffer_example_01.c121
-rw-r--r--src/examples/ecore/ecore_evas_buffer_example_02.c126
-rw-r--r--src/examples/ecore/ecore_evas_callbacks.c128
-rw-r--r--src/examples/ecore/ecore_evas_ews_example.c269
-rw-r--r--src/examples/ecore/ecore_evas_object_example.c53
-rw-r--r--src/examples/ecore/ecore_evas_window_sizes_example.c204
-rw-r--r--src/examples/ecore/ecore_event_example_01.c26
-rw-r--r--src/examples/ecore/ecore_event_example_02.c89
-rw-r--r--src/examples/ecore/ecore_exe_example.c100
-rw-r--r--src/examples/ecore/ecore_exe_example_child.c57
-rw-r--r--src/examples/ecore/ecore_fd_handler_example.c89
-rw-r--r--src/examples/ecore/ecore_fd_handler_gnutls_example.c203
-rw-r--r--src/examples/ecore/ecore_file_download_example.c86
-rw-r--r--src/examples/ecore/ecore_idler_example.c117
-rw-r--r--src/examples/ecore/ecore_imf_example.c588
-rw-r--r--src/examples/ecore/ecore_job_example.c50
-rw-r--r--src/examples/ecore/ecore_pipe_gstreamer_example.c190
-rw-r--r--src/examples/ecore/ecore_pipe_simple_example.c67
-rw-r--r--src/examples/ecore/ecore_poller_example.c72
-rw-r--r--src/examples/ecore/ecore_server_bench.c63
-rw-r--r--src/examples/ecore/ecore_thread_example.c397
-rw-r--r--src/examples/ecore/ecore_time_functions_example.c34
-rw-r--r--src/examples/ecore/ecore_timer_example.c187
-rw-r--r--src/examples/ecore/red.pngbin0 -> 225 bytes
37 files changed, 4739 insertions, 0 deletions
diff --git a/src/examples/ecore/Makefile.am b/src/examples/ecore/Makefile.am
new file mode 100644
index 0000000000..94ffd4ba4d
--- /dev/null
+++ b/src/examples/ecore/Makefile.am
@@ -0,0 +1,186 @@
1MAINTAINERCLEANFILES = Makefile.in
2
3AM_CPPFLAGS = \
4-I$(top_srcdir)/src/lib/eina \
5-I$(top_srcdir)/src/lib/eo \
6-I$(top_srcdir)/src/lib/evas \
7-I$(top_srcdir)/src/lib/ecore \
8-I$(top_srcdir)/src/lib/ecore_input \
9-I$(top_srcdir)/src/lib/ecore_con \
10-I$(top_srcdir)/src/lib/ecore_evas \
11-I$(top_builddir)/src/lib/eina \
12-I$(top_builddir)/src/lib/eo \
13-I$(top_builddir)/src/lib/evas \
14-I$(top_builddir)/src/lib/ecore \
15-I$(top_builddir)/src/lib/ecore_input \
16-I$(top_builddir)/src/lib/ecore_con \
17-I$(top_builddir)/src/lib/ecore_evas \
18-DPACKAGE_EXAMPLES_DIR=\"$(datadir)/ecore/examples\" \
19@ECORE_CFLAGS@
20
21EXTRA_PROGRAMS = \
22ecore_animator_example \
23ecore_client_bench \
24ecore_con_client_simple_example \
25ecore_con_lookup_example \
26ecore_con_server_http_example \
27ecore_con_server_simple_example \
28ecore_con_url_cookies_example \
29ecore_con_url_download_example \
30ecore_con_url_headers_example \
31ecore_evas_basics_example \
32ecore_evas_buffer_example_01 \
33ecore_evas_buffer_example_02 \
34ecore_evas_callbacks \
35ecore_evas_ews_example \
36ecore_evas_object_example \
37ecore_evas_window_sizes_example \
38ecore_event_example_01 \
39ecore_event_example_02 \
40ecore_exe_example \
41ecore_exe_example_child \
42ecore_fd_handler_example \
43ecore_idler_example \
44ecore_job_example \
45ecore_pipe_simple_example \
46ecore_poller_example \
47ecore_server_bench \
48ecore_thread_example \
49ecore_time_functions_example \
50ecore_timer_example
51
52ecore_animator_example_SOURCES = ecore_animator_example.c
53ecore_animator_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
54
55ecore_client_bench_SOURCES = ecore_client_bench.c
56ecore_client_bench_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
57
58ecore_con_client_simple_example_SOURCES = ecore_con_client_simple_example.c
59ecore_con_client_simple_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
60
61ecore_con_lookup_example_SOURCES = ecore_con_lookup_example.c
62ecore_con_lookup_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
63
64ecore_con_server_http_example_SOURCES = ecore_con_server_http_example.c
65ecore_con_server_http_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
66
67ecore_con_server_simple_example_SOURCES = ecore_con_server_simple_example.c
68ecore_con_server_simple_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
69
70ecore_con_url_cookies_example_SOURCES = ecore_con_url_cookies_example.c
71ecore_con_url_cookies_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
72
73ecore_con_url_download_example_SOURCES = ecore_con_url_download_example.c
74ecore_con_url_download_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
75
76ecore_con_url_headers_example_SOURCES = ecore_con_url_headers_example.c
77ecore_con_url_headers_example_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
78
79ecore_evas_basics_example_SOURCES = ecore_evas_basics_example.c
80ecore_evas_basics_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
81
82ecore_evas_buffer_example_01_SOURCES = ecore_evas_buffer_example_01.c
83ecore_evas_buffer_example_01_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
84
85ecore_evas_buffer_example_02_SOURCES = ecore_evas_buffer_example_02.c
86ecore_evas_buffer_example_02_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
87
88ecore_evas_callbacks_SOURCES = ecore_evas_callbacks.c
89ecore_evas_callbacks_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
90
91ecore_evas_ews_example_SOURCES = ecore_evas_ews_example.c
92ecore_evas_ews_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
93
94ecore_evas_object_example_SOURCES = ecore_evas_object_example.c
95ecore_evas_object_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
96
97ecore_evas_window_sizes_example_SOURCES = ecore_evas_window_sizes_example.c
98ecore_evas_window_sizes_example_LDADD = $(top_builddir)/src/lib/ecore_evas/libecore_evas.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
99
100ecore_event_example_01_SOURCES = ecore_event_example_01.c
101ecore_event_example_01_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
102
103ecore_event_example_02_SOURCES = ecore_event_example_02.c
104ecore_event_example_02_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
105
106ecore_exe_example_SOURCES = ecore_exe_example.c
107ecore_exe_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
108
109ecore_exe_example_child_SOURCES = ecore_exe_example_child.c
110ecore_exe_example_child_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
111
112ecore_fd_handler_example_SOURCES = ecore_fd_handler_example.c
113ecore_fd_handler_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
114
115ecore_idler_example_SOURCES = ecore_idler_example.c
116ecore_idler_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
117
118ecore_job_example_SOURCES = ecore_job_example.c
119ecore_job_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
120
121ecore_pipe_simple_example_SOURCES = ecore_pipe_simple_example.c
122ecore_pipe_simple_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
123
124ecore_poller_example_SOURCES = ecore_poller_example.c
125ecore_poller_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
126
127ecore_server_bench_SOURCES = ecore_server_bench.c
128ecore_server_bench_LDADD = $(top_builddir)/src/lib/ecore_con/libecore_con.la $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
129
130ecore_thread_example_SOURCES = ecore_thread_example.c
131ecore_thread_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
132
133ecore_time_functions_example_SOURCES = ecore_time_functions_example.c
134ecore_time_functions_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
135
136ecore_timer_example_SOURCES = ecore_timer_example.c
137ecore_timer_example_LDADD = $(top_builddir)/src/lib/ecore/libecore.la @ECORE_LIBS@
138
139SRCS = \
140ecore_animator_example \
141ecore_client_bench \
142ecore_con_client_simple_example \
143ecore_con_lookup_example \
144ecore_con_server_http_example \
145ecore_con_server_simple_example \
146ecore_con_url_cookies_example \
147ecore_con_url_download_example \
148ecore_con_url_headers_example \
149ecore_evas_basics_example \
150ecore_evas_buffer_example_01 \
151ecore_evas_buffer_example_02 \
152ecore_evas_callbacks \
153ecore_evas_ews_example \
154ecore_evas_object_example \
155ecore_evas_window_sizes_example \
156ecore_event_example_01 \
157ecore_event_example_02 \
158ecore_exe_example \
159ecore_exe_example_child \
160ecore_fd_handler_example \
161ecore_idler_example \
162ecore_job_example \
163ecore_pipe_simple_example \
164ecore_poller_example \
165ecore_server_bench \
166ecore_thread_example \
167ecore_time_functions_example \
168ecore_timer_example
169
170EXTRA_DIST = red.png
171
172examples: $(EXTRA_PROGRAMS)
173
174clean-local:
175 rm -f $(EXTRA_PROGRAMS)
176
177install-examples:
178 mkdir -p $(datadir)/ecore/examples
179 $(install_sh_DATA) -c $(SRCS) $(datadir)/ecore/examples
180 $(install_sh_DATA) -c red.png $(datadir)/ecore/examples
181
182uninstall-local:
183 rm -f $(datadir)/ecore/examples/red.png
184 for f in $(SRCS) ; do \
185 rm -f $(datadir)/ecore/examples/$$f ; \
186 done
diff --git a/src/examples/ecore/ecore_animator_example.c b/src/examples/ecore/ecore_animator_example.c
new file mode 100644
index 0000000000..545d48a1e4
--- /dev/null
+++ b/src/examples/ecore/ecore_animator_example.c
@@ -0,0 +1,117 @@
1//Compile with:
2//gcc -g -Wall `pkg-config --cflags --libs ecore-evas` -o ecore_animator_example ecore_animator_example.c
3
4#include <Ecore.h>
5#include <Ecore_Evas.h>
6
7static Eina_Bool _advance_frame(void *data, double pos);
8static Eina_Bool _advance_frame2(void *data, double pos);
9static Eina_Bool _advance_frame3(void *data);
10static Eina_Bool _start_second_anim(void *data);
11static Eina_Bool _freeze_third_anim(void *data);
12static Eina_Bool _thaw_third_anim(void *data);
13
14int
15main(int argc, char *argv[])
16{
17 Evas_Object *rect, *bg, *rect2;
18 Ecore_Evas *ee;
19 Evas *evas;
20 Ecore_Animator *anim;
21
22 ecore_evas_init();
23
24 ee = ecore_evas_new(NULL, 0, 0, 300, 400, NULL);
25 ecore_evas_show(ee);
26 evas = ecore_evas_get(ee);
27
28 bg = evas_object_rectangle_add(evas);
29 evas_object_resize(bg, 300, 400);
30 evas_object_show(bg);
31
32 rect = evas_object_rectangle_add(evas);
33 evas_object_color_set(rect, 0, 0, 255, 255);
34 evas_object_resize(rect, 50, 50);
35 evas_object_show(rect);
36
37 rect2 = evas_object_rectangle_add(evas);
38 evas_object_color_set(rect2, 0, 55, 0, 255);
39 evas_object_resize(rect2, 50, 50);
40 evas_object_show(rect2);
41
42 ecore_animator_frametime_set(1. / 50);
43 ecore_animator_timeline_add(5, _advance_frame, rect);
44
45 anim = ecore_animator_add(_advance_frame3, rect2);
46
47 ecore_timer_add(10, _start_second_anim, rect);
48 ecore_timer_add(5, _freeze_third_anim, anim);
49 ecore_timer_add(10, _thaw_third_anim, anim);
50 ecore_main_loop_begin();
51
52 evas_object_del(rect);
53 ecore_evas_free(ee);
54 ecore_animator_del(anim);
55 ecore_evas_shutdown();
56
57 return 0;
58}
59
60static Eina_Bool
61_advance_frame(void *data, double pos)
62{
63 double frame = pos;
64 frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_SPRING, 1.2, 15);
65
66 evas_object_resize(data, 50 * (1 + frame), 50 * (1 + frame));
67 evas_object_move(data, 100 * frame, 100 * frame);
68 evas_object_color_set(data, 255 * frame, 0, 255 * (1 - frame), 255);
69 return EINA_TRUE;
70}
71
72static Eina_Bool
73_start_second_anim(void *data)
74{
75 ecore_animator_frametime_set(1. / 10);
76 ecore_animator_timeline_add(20, _advance_frame2, data);
77 return EINA_FALSE;
78}
79
80static Eina_Bool
81_advance_frame2(void *data, double pos)
82{
83 double frame = pos;
84 frame = ecore_animator_pos_map(pos, ECORE_POS_MAP_BOUNCE, 1.2, 50);
85
86 evas_object_resize(data, 100 - (50 * frame), 100 - (50 * frame));
87 evas_object_move(data, 100 * (1 - frame), 100 * (1 - frame));
88 evas_object_color_set(data, 255 * (1 - frame), 0, 255 * frame, 255);
89 return EINA_TRUE;
90}
91
92static Eina_Bool
93_advance_frame3(void *data)
94{
95 static int x = 0;
96
97 if (x >= 250)
98 x = 0;
99 evas_object_move(data, ++x, 350);
100
101 return EINA_TRUE;
102}
103
104static Eina_Bool
105_freeze_third_anim(void *data)
106{
107 ecore_animator_freeze(data);
108 return EINA_FALSE;
109}
110
111static Eina_Bool
112_thaw_third_anim(void *data)
113{
114 ecore_animator_thaw(data);
115 return EINA_FALSE;
116}
117
diff --git a/src/examples/ecore/ecore_client_bench.c b/src/examples/ecore/ecore_client_bench.c
new file mode 100644
index 0000000000..dc550eea74
--- /dev/null
+++ b/src/examples/ecore/ecore_client_bench.c
@@ -0,0 +1,79 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5/* Ecore_Con client example
6 * 2010 Mike Blumenkrantz
7 */
8
9#define NUM_CLIENTS 30000
10
11static Eina_Counter *counter;
12static int add = 0;
13static int del = 0;
14
15Eina_Bool
16_add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
17{
18 ++add;
19 printf("Connection #%i!\n", add);
20 if (add == NUM_CLIENTS)
21 ecore_main_loop_quit();
22
23 return ECORE_CALLBACK_RENEW;
24}
25
26Eina_Bool
27_del(void *data, int type, Ecore_Con_Event_Server_Add *ev)
28{
29 ++del;
30 printf("Connection lost! #%i!\n", del);
31
32 return ECORE_CALLBACK_RENEW;
33}
34
35static void
36_spawn(void *data)
37{
38 int x;
39
40 for (x = 0; x < NUM_CLIENTS; x++)
41 {
42// printf("Creating connection %i\n", x);
43 if (!ecore_con_server_connect(ECORE_CON_REMOTE_NODELAY, "127.0.0.1", 8080, NULL))
44 {
45 printf("CRITICAL ERROR!\n"
46 "Could not create connection #%i!\n", x);
47 exit(1);
48 }
49 }
50 printf("***Job done***\n");
51}
52
53int
54main(void)
55{
56 double done;
57 eina_init();
58 ecore_init();
59 ecore_con_init();
60
61 eina_log_domain_level_set("ecore_con", EINA_LOG_LEVEL_ERR);
62 eina_log_domain_level_set("eina", EINA_LOG_LEVEL_ERR);
63 counter = eina_counter_new("client");
64 eina_counter_start(counter);
65 done = ecore_time_get();
66
67 ecore_job_add(_spawn, NULL);
68
69/* set event handler for server connect */
70 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
71 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_del, NULL);
72
73/* start client */
74 ecore_main_loop_begin();
75 eina_counter_stop(counter, 1);
76 printf("\nTime elapsed for %i connections: %f seconds\n%s", NUM_CLIENTS, ecore_time_get() - done, eina_counter_dump(counter));
77 return 0;
78}
79
diff --git a/src/examples/ecore/ecore_con_client_example.c b/src/examples/ecore/ecore_con_client_example.c
new file mode 100644
index 0000000000..c6ab50d6ca
--- /dev/null
+++ b/src/examples/ecore/ecore_con_client_example.c
@@ -0,0 +1,92 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5/* Ecore_Con client example
6 * 2010 Mike Blumenkrantz
7 */
8
9/* comment if not using gnutls */
10static void
11tls_log_func(int level, const char *str)
12{
13 fprintf(stderr, "|<%d>| %s", level, str);
14}
15
16Eina_Bool
17_add(void *data, int type, Ecore_Con_Event_Server_Add *ev)
18{
19 printf("Server with ip %s connected!\n", ecore_con_server_ip_get(ev->server));
20 ecore_con_server_send(ev->server, "hello!", 6);
21 ecore_con_server_flush(ev->server);
22
23 return ECORE_CALLBACK_RENEW;
24}
25
26Eina_Bool
27_del(void *data, int type, Ecore_Con_Event_Server_Del *ev)
28{
29 printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server));
30 ecore_main_loop_quit();
31 return ECORE_CALLBACK_RENEW;
32}
33
34Eina_Bool
35_data(void *data, int type, Ecore_Con_Event_Server_Data *ev)
36{
37 char fmt[128];
38
39 snprintf(fmt, sizeof(fmt),
40 "Received %i bytes from server:\n"
41 ">>>>>\n"
42 "%%.%is\n"
43 ">>>>>\n",
44 ev->size, ev->size);
45
46 printf(fmt, ev->data);
47 return ECORE_CALLBACK_RENEW;
48}
49
50int
51main()
52{
53 Ecore_Con_Server *svr;
54 Eina_Iterator *it;
55 const char *ca;
56
57 eina_init();
58 ecore_init();
59 ecore_con_init();
60
61/* comment if not using gnutls */
62 gnutls_global_set_log_level(9);
63 gnutls_global_set_log_function(tls_log_func);
64
65 if (!(it = eina_file_ls("/etc/ssl/certs")))
66 exit(1);
67
68 if (!(svr = ecore_con_server_connect(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_MIXED, "www.verisign.com", 443, NULL)))
69 exit(1);
70
71 /* add all the CAs */
72 EINA_ITERATOR_FOREACH(it, ca)
73 {
74 if (!ecore_con_ssl_server_cafile_add(svr, ca))
75 printf("Could not load CA: %s!\n", ca);
76 eina_stringshare_del(ca);
77 }
78
79 eina_iterator_free(it);
80 ecore_con_ssl_server_verify(svr);
81
82/* set event handler for server connect */
83 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
84/* set event handler for server disconnect */
85 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
86/* set event handler for receiving server data */
87 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
88
89/* start client */
90 ecore_main_loop_begin();
91}
92
diff --git a/src/examples/ecore/ecore_con_client_simple_example.c b/src/examples/ecore/ecore_con_client_simple_example.c
new file mode 100644
index 0000000000..48b1933ca7
--- /dev/null
+++ b/src/examples/ecore/ecore_con_client_simple_example.c
@@ -0,0 +1,126 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5#ifdef HAVE_CONFIG_H
6# include "config.h"
7#else
8# define EINA_UNUSED
9#endif
10
11struct _Server
12{
13 int sdata;
14};
15
16Eina_Bool
17_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Add *ev)
18{
19 char welcome[] = "hello! - sent from the client";
20 struct _Server *server = malloc(sizeof(*server));
21 server->sdata = 0;
22
23 ecore_con_server_data_set(ev->server, server);
24 printf("Server with ip %s, name %s, port %d, connected = %d!\n",
25 ecore_con_server_ip_get(ev->server),
26 ecore_con_server_name_get(ev->server),
27 ecore_con_server_port_get(ev->server),
28 ecore_con_server_connected_get(ev->server));
29 ecore_con_server_send(ev->server, welcome, sizeof(welcome));
30 ecore_con_server_flush(ev->server);
31
32 return ECORE_CALLBACK_RENEW;
33}
34
35Eina_Bool
36_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Del *ev)
37{
38 if (!ev->server)
39 {
40 printf("Failed to establish connection to the server.\nExiting.\n");
41 ecore_main_loop_quit();
42 return ECORE_CALLBACK_RENEW;
43 }
44
45 struct _Server *server = ecore_con_server_data_get(ev->server);
46
47 printf("Lost server with ip %s!\n", ecore_con_server_ip_get(ev->server));
48
49 if (server)
50 {
51 printf("Total data received from this server: %d\n", server->sdata);
52 free(server);
53 }
54
55 ecore_con_server_del(ev->server);
56
57 ecore_main_loop_quit();
58 return ECORE_CALLBACK_RENEW;
59}
60
61Eina_Bool
62_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Server_Data *ev)
63{
64 char fmt[128];
65 struct _Server *server = ecore_con_server_data_get(ev->server);
66
67 snprintf(fmt, sizeof(fmt),
68 "Received %i bytes from server:\n"
69 ">>>>>\n"
70 "%%.%is\n"
71 ">>>>>\n",
72 ev->size, ev->size);
73
74 printf(fmt, ev->data);
75
76 server->sdata += ev->size;
77 return ECORE_CALLBACK_RENEW;
78}
79
80int
81main(int argc, const char *argv[])
82{
83 Ecore_Con_Server *svr;
84 const char *address;
85 int port = 8080;
86
87 if (argc < 2)
88 {
89 printf("wrong usage. Command syntax is:\n");
90 printf("\tecore_con_client_simple_example <address> [port]\n");
91 exit(1);
92 }
93
94 address = argv[1];
95
96 if (argc > 2)
97 port = atoi(argv[2]);
98
99 eina_init();
100 ecore_init();
101 ecore_con_init();
102
103 if (!(svr = ecore_con_server_connect(ECORE_CON_REMOTE_TCP, address, port, NULL)))
104 {
105 printf("could not connect to the server: %s, port %d.\n",
106 address, port);
107 exit(2);
108 }
109
110 /* set event handler for server connect */
111 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
112 /* set event handler for server disconnect */
113 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
114 /* set event handler for receiving server data */
115 ecore_event_handler_add(ECORE_CON_EVENT_SERVER_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
116
117 /* start client */
118 ecore_main_loop_begin();
119
120 ecore_con_init();
121 ecore_init();
122 eina_init();
123
124 return 0;
125}
126
diff --git a/src/examples/ecore/ecore_con_lookup_example.c b/src/examples/ecore/ecore_con_lookup_example.c
new file mode 100644
index 0000000000..1a47d0ba32
--- /dev/null
+++ b/src/examples/ecore/ecore_con_lookup_example.c
@@ -0,0 +1,40 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5static void
6_lookup_done_cb(const char *canonname, const char *ip, struct sockaddr *addr, int addrlen, void *data)
7{
8 printf("canonname = %s\n", canonname);
9 printf("ip = %s\n", ip);
10 printf("addr = %p\n", addr);
11 printf("addrlen = %d\n", addrlen);
12}
13
14int
15main(int argc, const char *argv[])
16{
17 if (argc < 2)
18 {
19 printf("need one parameter: <address>\n");
20 return -1;
21 }
22
23 ecore_init();
24 ecore_con_init();
25
26 if (!ecore_con_lookup(argv[1], _lookup_done_cb, NULL))
27 {
28 printf("error when trying to start lookup for %s\n", argv[1]);
29 goto end;
30 }
31
32 ecore_main_loop_begin();
33
34end:
35 ecore_con_shutdown();
36 ecore_shutdown();
37
38 return 0;
39}
40
diff --git a/src/examples/ecore/ecore_con_server_example.c b/src/examples/ecore/ecore_con_server_example.c
new file mode 100644
index 0000000000..73335216f5
--- /dev/null
+++ b/src/examples/ecore/ecore_con_server_example.c
@@ -0,0 +1,81 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5/* Ecore_Con server example
6 * 2010 Mike Blumenkrantz
7 */
8
9/* comment if not using gnutls */
10static void
11tls_log_func(int level, const char *str)
12{
13 fprintf(stderr, "|<%d>| %s", level, str);
14}
15
16Eina_Bool
17_add(void *data, int type, Ecore_Con_Event_Client_Add *ev)
18{
19 printf("Client with ip %s connected!\n", ecore_con_client_ip_get(ev->client));
20 ecore_con_client_send(ev->client, "hello!", 6);
21// ecore_con_client_flush(ev->client);
22 ecore_con_client_timeout_set(ev->client, 5);
23
24 return ECORE_CALLBACK_RENEW;
25}
26
27Eina_Bool
28_del(void *data, int type, Ecore_Con_Event_Client_Del *ev)
29{
30 printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client));
31 ecore_main_loop_quit();
32 return ECORE_CALLBACK_RENEW;
33}
34
35Eina_Bool
36_data(void *data, int type, Ecore_Con_Event_Client_Data *ev)
37{
38 char fmt[128];
39
40 snprintf(fmt, sizeof(fmt),
41 "Received %i bytes from client:\n"
42 ">>>>>\n"
43 "%%.%is\n"
44 ">>>>>\n",
45 ev->size, ev->size);
46
47 printf(fmt, ev->data);
48 return ECORE_CALLBACK_RENEW;
49}
50
51int
52main()
53{
54 Ecore_Con_Server *svr;
55 eina_init();
56 ecore_init();
57 ecore_con_init();
58
59/* comment if not using gnutls */
60 gnutls_global_set_log_level(9);
61 gnutls_global_set_log_function(tls_log_func);
62
63/* to use a PEM certificate with TLS and SSL3, uncomment the lines below */
64 if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_TLS | ECORE_CON_USE_SSL3 | ECORE_CON_LOAD_CERT, "127.0.0.1", 8080, NULL)))
65/* to use simple tcp with ssl/tls, use this line */
66// if (!ecore_con_server_add(ECORE_CON_REMOTE_TCP | ECORE_CON_USE_SSL3, "127.0.0.1", 8080, NULL))
67 exit(1);
68
69 ecore_con_ssl_server_cert_add(svr, "server.pem");
70 ecore_con_ssl_server_privkey_add(svr, "server.pem");
71/* set event handler for client connect */
72 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
73/* set event handler for client disconnect */
74 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
75/* set event handler for receiving client data */
76 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
77
78/* start server */
79 ecore_main_loop_begin();
80}
81
diff --git a/src/examples/ecore/ecore_con_server_http_example.c b/src/examples/ecore/ecore_con_server_http_example.c
new file mode 100644
index 0000000000..14d1ecb5b0
--- /dev/null
+++ b/src/examples/ecore/ecore_con_server_http_example.c
@@ -0,0 +1,136 @@
1#include <stdio.h>
2#include <sys/time.h>
3#include <Ecore.h>
4#include <Ecore_Con.h>
5
6#ifdef HAVE_CONFIG_H
7# include "config.h"
8#else
9# define EINA_UNUSED
10#endif
11
12static const char response_template[] =
13 "HTTP/1.0 200 OK\r\n"
14 "Server: Ecore_Con custom server\r\n"
15 "Content-Length: %zd\r\n"
16 "Content-Type: text/html; charset=UTF-8\r\n"
17 "Set-Cookie: MYCOOKIE=1; path=/; expires=%s\r\n"
18 "Set-Cookie: SESSIONCOOKIE=1; path=/\r\n"
19 "\r\n"
20 "%s";
21
22struct _Client
23{
24 int sdata;
25};
26
27Eina_Bool
28_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev)
29{
30 struct _Client *client = malloc(sizeof(*client));
31 client->sdata = 0;
32 static char buf[4096];
33 char welcome[] = "Welcome to Ecore_Con server!";
34 time_t t;
35
36 printf("Client with ip %s, port %d, connected = %d!\n",
37 ecore_con_client_ip_get(ev->client),
38 ecore_con_client_port_get(ev->client),
39 ecore_con_client_connected_get(ev->client));
40
41 ecore_con_client_data_set(ev->client, client);
42
43 t = time(NULL);
44 t += 60 * 60 * 24;
45 snprintf(buf, sizeof(buf), response_template, sizeof(welcome) - 1, ctime(&t), welcome);
46
47 ecore_con_client_send(ev->client, buf, strlen(buf));
48 ecore_con_client_flush(ev->client);
49
50 return ECORE_CALLBACK_RENEW;
51}
52
53Eina_Bool
54_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev)
55{
56 struct _Client *client;
57
58 if (!ev->client)
59 return ECORE_CALLBACK_RENEW;
60
61 client = ecore_con_client_data_get(ev->client);
62
63 printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client));
64 printf("Total data received from this client: %d\n", client->sdata);
65 printf("Client was connected for %0.3f seconds.\n",
66 ecore_con_client_uptime_get(ev->client));
67
68 if (client)
69 free(client);
70
71 ecore_con_client_del(ev->client);
72
73 return ECORE_CALLBACK_RENEW;
74}
75
76Eina_Bool
77_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Data *ev)
78{
79 char fmt[128];
80 struct _Client *client = ecore_con_client_data_get(ev->client);
81
82 snprintf(fmt, sizeof(fmt),
83 "\nReceived %i bytes from client %s port %d:\n"
84 ">>>>>\n"
85 "%%.%is\n"
86 ">>>>>\n\n",
87 ev->size, ecore_con_client_ip_get(ev->client),
88 ecore_con_client_port_get(ev->client), ev->size);
89
90 printf(fmt, ev->data);
91
92 client->sdata += ev->size;
93
94 return ECORE_CALLBACK_RENEW;
95}
96
97int
98main(void)
99{
100 Ecore_Con_Server *svr;
101 Ecore_Con_Client *cl;
102 const Eina_List *clients, *l;
103
104 eina_init();
105 ecore_init();
106 ecore_con_init();
107
108 if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL)))
109 exit(1);
110
111 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
112 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
113 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
114 ecore_con_server_client_limit_set(svr, 3, 0);
115
116 ecore_main_loop_begin();
117
118 clients = ecore_con_server_clients_get(svr);
119 printf("Clients still connected to this server when exiting: %d\n",
120 eina_list_count(clients));
121 EINA_LIST_FOREACH(clients, l, cl)
122 {
123 printf("%s\n", ecore_con_client_ip_get(cl));
124 free(ecore_con_client_data_get(cl));
125 }
126
127 printf("Server was up for %0.3f seconds\n",
128 ecore_con_server_uptime_get(svr));
129
130 ecore_con_shutdown();
131 ecore_shutdown();
132 eina_shutdown();
133
134 return 0;
135}
136
diff --git a/src/examples/ecore/ecore_con_server_simple_example.c b/src/examples/ecore/ecore_con_server_simple_example.c
new file mode 100644
index 0000000000..c771b2af3e
--- /dev/null
+++ b/src/examples/ecore/ecore_con_server_simple_example.c
@@ -0,0 +1,133 @@
1#include <stdio.h>
2#include <Ecore.h>
3#include <Ecore_Con.h>
4
5#ifdef HAVE_CONFIG_H
6# include "config.h"
7#else
8# define EINA_UNUSED
9#endif
10
11struct _Client
12{
13 int sdata;
14};
15
16Eina_Bool
17_add(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Add *ev)
18{
19 char welcome[] = "hello! - sent from the server";
20 Ecore_Con_Server *srv;
21 Ecore_Con_Client *cl;
22 const Eina_List *clients, *l;
23
24 struct _Client *client = malloc(sizeof(*client));
25 client->sdata = 0;
26
27 printf("Client with ip %s, port %d, connected = %d!\n",
28 ecore_con_client_ip_get(ev->client),
29 ecore_con_client_port_get(ev->client),
30 ecore_con_client_connected_get(ev->client));
31
32 ecore_con_client_send(ev->client, welcome, sizeof(welcome));
33 ecore_con_client_flush(ev->client);
34
35 ecore_con_client_timeout_set(ev->client, 6);
36
37 ecore_con_client_data_set(ev->client, client);
38
39 srv = ecore_con_client_server_get(ev->client);
40 printf("Clients connected to this server:\n");
41 clients = ecore_con_server_clients_get(srv);
42 EINA_LIST_FOREACH(clients, l, cl)
43 printf("%s\n", ecore_con_client_ip_get(cl));
44
45 return ECORE_CALLBACK_RENEW;
46}
47
48Eina_Bool
49_del(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Del *ev)
50{
51 struct _Client *client;
52
53 if (!ev->client)
54 return ECORE_CALLBACK_RENEW;
55
56 client = ecore_con_client_data_get(ev->client);
57
58 printf("Lost client with ip %s!\n", ecore_con_client_ip_get(ev->client));
59 printf("Total data received from this client: %d\n", client->sdata);
60 printf("Client was connected for %0.3f seconds.\n",
61 ecore_con_client_uptime_get(ev->client));
62
63 if (client)
64 free(client);
65
66 ecore_con_client_del(ev->client);
67
68 return ECORE_CALLBACK_RENEW;
69}
70
71Eina_Bool
72_data(void *data EINA_UNUSED, int type EINA_UNUSED, Ecore_Con_Event_Client_Data *ev)
73{
74 char fmt[128];
75 struct _Client *client = ecore_con_client_data_get(ev->client);
76
77 snprintf(fmt, sizeof(fmt),
78 "Received %i bytes from client %s port %d:\n"
79 ">>>>>\n"
80 "%%.%is\n"
81 ">>>>>\n",
82 ev->size, ecore_con_client_ip_get(ev->client),
83 ecore_con_client_port_get(ev->client), ev->size);
84
85 printf(fmt, ev->data);
86
87 client->sdata += ev->size;
88
89 return ECORE_CALLBACK_RENEW;
90}
91
92int
93main(void)
94{
95 Ecore_Con_Server *svr;
96 Ecore_Con_Client *cl;
97 const Eina_List *clients, *l;
98
99 eina_init();
100 ecore_init();
101 ecore_con_init();
102
103 if (!(svr = ecore_con_server_add(ECORE_CON_REMOTE_TCP, "127.0.0.1", 8080, NULL)))
104 exit(1);
105
106 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_ADD, (Ecore_Event_Handler_Cb)_add, NULL);
107 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DEL, (Ecore_Event_Handler_Cb)_del, NULL);
108 ecore_event_handler_add(ECORE_CON_EVENT_CLIENT_DATA, (Ecore_Event_Handler_Cb)_data, NULL);
109
110 ecore_con_server_timeout_set(svr, 10);
111 ecore_con_server_client_limit_set(svr, 3, 0);
112
113 ecore_main_loop_begin();
114
115 clients = ecore_con_server_clients_get(svr);
116 printf("Clients connected to this server when exiting: %d\n",
117 eina_list_count(clients));
118 EINA_LIST_FOREACH(clients, l, cl)
119 {
120 printf("%s\n", ecore_con_client_ip_get(cl));
121 free(ecore_con_client_data_get(cl));
122 }
123
124 printf("Server was up for %0.3f seconds\n",
125 ecore_con_server_uptime_get(svr));
126
127 ecore_con_shutdown();
128 ecore_shutdown();
129 eina_shutdown();
130
131 return 0;
132}
133
diff --git a/src/examples/ecore/ecore_con_url_cookies_example.c b/src/examples/ecore/ecore_con_url_cookies_example.c
new file mode 100644
index 0000000000..908df0f2a0
--- /dev/null
+++ b/src/examples/ecore/ecore_con_url_cookies_example.c
@@ -0,0 +1,123 @@
1#include <stdio.h>
2#include <Eina.h>
3#include <Ecore.h>
4#include <Ecore_Con.h>
5
6#ifdef HAVE_CONFIG_H
7# include "config.h"
8#else
9# define EINA_UNUSED
10#endif
11
12#define COOKIEJAR "cookies.jar"
13
14static Eina_Bool
15_url_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
16{
17 Ecore_Con_Event_Url_Data *url_data = event_info;
18 int i;
19
20 printf("\nData received from server:\n>>>>>\n");
21 for (i = 0; i < url_data->size; i++)
22 printf("%c", url_data->data[i]);
23 printf("\n>>>>>>\n\n");
24
25 return EINA_TRUE;
26}
27
28static Eina_Bool
29_url_complete_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event_info)
30{
31 Ecore_Con_Event_Url_Complete *url_complete = event_info;
32 const Eina_List *headers, *l;
33 char *str;
34
35 printf("\n");
36 printf("download completed with status code: %d\n", url_complete->status);
37
38 headers = ecore_con_url_response_headers_get(url_complete->url_con);
39
40 printf("response headers:\n");
41 EINA_LIST_FOREACH(headers, l, str)
42 printf("header: %s", str);
43
44 ecore_con_url_cookies_jar_write(url_complete->url_con);
45
46 ecore_main_loop_quit();
47
48 return EINA_TRUE;
49}
50
51int
52main(int argc, const char *argv[])
53{
54 Ecore_Con_Url *ec_url = NULL;
55 char cmd = '\0';
56 Eina_Bool r;
57
58 if (argc < 2)
59 {
60 printf("need at least one parameter: <url> [command]\n");
61 return -1;
62 }
63
64 if (argc > 2)
65 cmd = argv[2][0];
66
67 ecore_init();
68 ecore_con_init();
69 ecore_con_url_init();
70
71 ec_url = ecore_con_url_new(argv[1]);
72 if (!ec_url)
73 {
74 printf("error when creating ecore con url object.\n");
75 goto end;
76 }
77
78 ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
79 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
80
81 ecore_con_url_additional_header_add(ec_url, "User-Agent", "Ecore_Con client");
82
83 ecore_con_url_cookies_init(ec_url);
84 if (cmd != 'c' && cmd != 's')
85 ecore_con_url_cookies_file_add(ec_url, COOKIEJAR);
86 ecore_con_url_cookies_jar_file_set(ec_url, COOKIEJAR);
87
88 switch (cmd)
89 {
90 case 'c': // clear
91 printf("Cleaning previously set cookies.\n");
92 ecore_con_url_cookies_clear(ec_url);
93 break;
94
95 case 's': // clear session
96 printf("Cleaning previously set session cookies.\n");
97 ecore_con_url_cookies_session_clear(ec_url);
98 break;
99
100 case 'i': // ignore session
101 printf("Ignoring old session cookies.\n");
102 ecore_con_url_cookies_ignore_old_session_set(ec_url, EINA_TRUE);
103 }
104
105 r = ecore_con_url_get(ec_url);
106 if (!r)
107 {
108 printf("could not realize request.\n");
109 goto free_ec_url;
110 }
111
112 ecore_main_loop_begin();
113
114free_ec_url:
115 ecore_con_url_free(ec_url);
116end:
117 ecore_con_url_shutdown();
118 ecore_con_shutdown();
119 ecore_shutdown();
120
121 return 0;
122}
123
diff --git a/src/examples/ecore/ecore_con_url_download_example.c b/src/examples/ecore/ecore_con_url_download_example.c
new file mode 100644
index 0000000000..6eed89afdc
--- /dev/null
+++ b/src/examples/ecore/ecore_con_url_download_example.c
@@ -0,0 +1,115 @@
1#include <stdio.h>
2#include <sys/types.h>
3#include <sys/stat.h>
4#include <fcntl.h>
5#include <unistd.h>
6
7#include <Ecore.h>
8#include <Ecore_Con.h>
9
10struct _request
11{
12 long size;
13};
14
15static Eina_Bool
16_url_progress_cb(void *data, int type, void *event_info)
17{
18 Ecore_Con_Event_Url_Progress *url_progress = event_info;
19 float percent;
20
21 if (url_progress->down.total > 0)
22 {
23 struct _request *req = ecore_con_url_data_get(url_progress->url_con);
24 req->size = url_progress->down.now;
25
26 percent = (url_progress->down.now / url_progress->down.total) * 100;
27 printf("Total of download complete: %0.1f (%0.0f)%%\n",
28 percent, url_progress->down.now);
29 }
30
31 return EINA_TRUE;
32}
33
34static Eina_Bool
35_url_complete_cb(void *data, int type, void *event_info)
36{
37 Ecore_Con_Event_Url_Complete *url_complete = event_info;
38
39 struct _request *req = ecore_con_url_data_get(url_complete->url_con);
40 int nbytes = ecore_con_url_received_bytes_get(url_complete->url_con);
41
42 printf("\n");
43 printf("download completed with status code: %d\n", url_complete->status);
44 printf("Total size of downloaded file: %ld bytes\n", req->size);
45 printf("Total size of downloaded file: %d bytes "
46 "(from received_bytes_get)\n", nbytes);
47 ecore_main_loop_quit();
48
49 return EINA_TRUE;
50}
51
52int
53main(int argc, const char *argv[])
54{
55 Ecore_Con_Url *ec_url = NULL;
56 struct _request *req;
57 int fd;
58 const char *filename = "downloadedfile.dat";
59
60 if (argc < 2)
61 {
62 printf("need one parameter: <url>\n");
63 return -1;
64 }
65
66 fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0644);
67
68 if (fd == -1)
69 {
70 printf("error: could not open file for writing: \"%s\"\n",
71 filename);
72 return -1;
73 }
74
75 ecore_init();
76 ecore_con_init();
77 ecore_con_url_init();
78
79 ec_url = ecore_con_url_new(argv[1]);
80 if (!ec_url)
81 {
82 printf("error when creating ecore con url object.\n");
83 goto end;
84 }
85
86 req = malloc(sizeof(*req));
87 req->size = 0;
88 ecore_con_url_data_set(ec_url, req);
89
90 ecore_con_url_fd_set(ec_url, fd);
91
92 ecore_event_handler_add(ECORE_CON_EVENT_URL_PROGRESS, _url_progress_cb, NULL);
93 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
94
95 if (!ecore_con_url_get(ec_url))
96 {
97 printf("could not realize request.\n");
98 goto free_ec_url;
99 }
100
101 ecore_main_loop_begin();
102
103free_ec_url:
104 free(req);
105 ecore_con_url_free(ec_url);
106end:
107
108 close(fd);
109 ecore_con_url_shutdown();
110 ecore_con_shutdown();
111 ecore_shutdown();
112
113 return 0;
114}
115
diff --git a/src/examples/ecore/ecore_con_url_headers_example.c b/src/examples/ecore/ecore_con_url_headers_example.c
new file mode 100644
index 0000000000..fb05df35ea
--- /dev/null
+++ b/src/examples/ecore/ecore_con_url_headers_example.c
@@ -0,0 +1,106 @@
1#include <stdio.h>
2#include <Eina.h>
3#include <Ecore.h>
4#include <Ecore_Con.h>
5
6static Eina_Bool
7_url_data_cb(void *data, int type, void *event_info)
8{
9 Ecore_Con_Event_Url_Data *url_data = event_info;
10 int i;
11
12 for (i = 0; i < url_data->size; i++)
13 printf("%c", url_data->data[i]);
14
15 return EINA_TRUE;
16}
17
18static Eina_Bool
19_url_complete_cb(void *data, int type, void *event_info)
20{
21 Ecore_Con_Event_Url_Complete *url_complete = event_info;
22 const Eina_List *headers, *l;
23 char *str;
24
25 printf("\n");
26 printf("download completed with status code: %d\n", url_complete->status);
27
28 headers = ecore_con_url_response_headers_get(url_complete->url_con);
29
30 EINA_LIST_FOREACH(headers, l, str)
31 printf("header: %s\n", str);
32
33 ecore_main_loop_quit();
34
35 return EINA_TRUE;
36}
37
38int
39main(int argc, const char *argv[])
40{
41 Ecore_Con_Url *ec_url = NULL;
42 const char *type;
43 Eina_Bool r;
44
45 if (argc < 3)
46 {
47 printf("need at least two parameters: < POST|GET > <url1>\n");
48 return -1;
49 }
50
51 type = argv[1];
52
53 if (strcmp(type, "POST") && (strcmp(type, "GET")))
54 {
55 printf("only POST or GET are supported by this example.\n");
56 return -1;
57 }
58
59 ecore_init();
60 ecore_con_init();
61 ecore_con_url_init();
62
63 // check if requests are being pipelined, and set them if not:
64 if (!ecore_con_url_pipeline_get())
65 ecore_con_url_pipeline_set(EINA_TRUE);
66
67 ec_url = ecore_con_url_custom_new(argv[2], type);
68 if (!ec_url)
69 {
70 printf("error when creating ecore con url object.\n");
71 goto end;
72 }
73
74 ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA, _url_data_cb, NULL);
75 ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE, _url_complete_cb, NULL);
76
77 ecore_con_url_additional_header_add(ec_url, "User-Agent", "blablabla");
78 ecore_con_url_verbose_set(ec_url, EINA_TRUE);
79
80 ecore_con_url_httpauth_set(ec_url, "user", "password", EINA_FALSE);
81
82 ecore_con_url_time(ec_url, ECORE_CON_URL_TIME_IFMODSINCE, 0);
83
84 if (!strcmp(type, "GET"))
85 r = ecore_con_url_get(ec_url);
86 else
87 r = ecore_con_url_post(ec_url, NULL, 0, NULL);
88
89 if (!r)
90 {
91 printf("could not realize request.\n");
92 goto free_ec_url;
93 }
94
95 ecore_main_loop_begin();
96
97free_ec_url:
98 ecore_con_url_free(ec_url);
99end:
100 ecore_con_url_shutdown();
101 ecore_con_shutdown();
102 ecore_shutdown();
103
104 return 0;
105}
106
diff --git a/src/examples/ecore/ecore_evas_basics_example.c b/src/examples/ecore/ecore_evas_basics_example.c
new file mode 100644
index 0000000000..b62c64ad72
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_basics_example.c
@@ -0,0 +1,89 @@
1/**
2 * Ecore example illustrating the basics of ecore evas usage.
3 *
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o ecore_evas_basics_example ecore_evas_basics_example.c `pkg-config --libs --cflags ecore-evas`
9 * @endverbatim
10 */
11
12#include <Ecore.h>
13#include <Ecore_Evas.h>
14#include <unistd.h>
15
16static Eina_Bool
17_stdin_cb(void *data, Ecore_Fd_Handler *handler)
18{
19 Eina_List *l;
20 Ecore_Evas *ee;
21 char c;
22
23 scanf("%c", &c);
24 if (c == 'h')
25 EINA_LIST_FOREACH(ecore_evas_ecore_evas_list_get(), l, ee)
26 ecore_evas_hide(ee);
27 else if (c == 's')
28 EINA_LIST_FOREACH(ecore_evas_ecore_evas_list_get(), l, ee)
29 ecore_evas_show(ee);
30
31 return ECORE_CALLBACK_RENEW;
32}
33
34static void
35_on_delete(Ecore_Evas *ee)
36{
37 free(ecore_evas_data_get(ee, "key"));
38 ecore_main_loop_quit();
39}
40
41int
42main(void)
43{
44 Ecore_Evas *ee;
45 Evas *canvas;
46 Evas_Object *bg;
47 Eina_List *engines, *l;
48 char *data;
49
50 if (ecore_evas_init() <= 0)
51 return 1;
52
53 engines = ecore_evas_engines_get();
54 printf("Available engines:\n");
55 EINA_LIST_FOREACH(engines, l, data)
56 printf("%s\n", data);
57 ecore_evas_engines_free(engines);
58
59 ee = ecore_evas_new(NULL, 0, 0, 200, 200, NULL);
60 ecore_evas_title_set(ee, "Ecore Evas basics Example");
61 ecore_evas_show(ee);
62
63 data = malloc(sizeof(char) * 6);
64 sprintf(data, "%s", "hello");
65 ecore_evas_data_set(ee, "key", data);
66 ecore_evas_callback_delete_request_set(ee, _on_delete);
67
68 printf("Using %s engine!\n", ecore_evas_engine_name_get(ee));
69
70 canvas = ecore_evas_get(ee);
71 if (ecore_evas_ecore_evas_get(canvas) == ee)
72 printf("Everything is sane!\n");
73
74 bg = evas_object_rectangle_add(canvas);
75 evas_object_color_set(bg, 0, 0, 255, 255);
76 evas_object_resize(bg, 200, 200);
77 evas_object_show(bg);
78 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
79
80 ecore_main_fd_handler_add(STDIN_FILENO, ECORE_FD_READ, _stdin_cb, NULL, NULL, NULL);
81
82 ecore_main_loop_begin();
83
84 ecore_evas_free(ee);
85 ecore_evas_shutdown();
86
87 return 0;
88}
89
diff --git a/src/examples/ecore/ecore_evas_buffer_example_01.c b/src/examples/ecore/ecore_evas_buffer_example_01.c
new file mode 100644
index 0000000000..39f6dd11d7
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_buffer_example_01.c
@@ -0,0 +1,121 @@
1/**
2 * Simple Ecore_Evas example on the Evas buffer engine wrapper
3 * functions.
4 *
5 * You must have Evas compiled with the buffer engine.
6 *
7 * Compile with:
8 *
9 * @verbatim
10 * gcc -o evas-buffer-simple evas-buffer-simple.c `pkg-config --libs --cflags evas evas-software-buffer`
11 * @endverbatim
12 *
13 */
14
15#ifdef HAVE_CONFIG_H
16
17#include "config.h"
18#else
19#define EINA_UNUSED
20#endif
21
22#include <Ecore_Evas.h>
23#include <stdio.h>
24
25#define WIDTH (320)
26#define HEIGHT (240)
27
28static Ecore_Evas *ee;
29
30/* support function to save scene as PPM image */
31static void
32_scene_save(Evas *canvas,
33 const char *dest)
34{
35 const unsigned int *pixels, *pixels_end;
36 int width, height;
37 FILE *f;
38
39 evas_output_size_get(canvas, &width, &height);
40
41 f = fopen(dest, "wb+");
42 if (!f)
43 {
44 fprintf(stderr, "ERROR: could not open for writing '%s': %s\n",
45 dest, strerror(errno));
46 return;
47 }
48
49 pixels = ecore_evas_buffer_pixels_get(ee);
50 pixels_end = pixels + (width * height);
51
52 /* PPM P6 format is dead simple to write: */
53 fprintf(f, "P6\n%d %d\n255\n", width, height);
54 for (; pixels < pixels_end; pixels++)
55 {
56 int r, g, b;
57
58 r = ((*pixels) & 0xff0000) >> 16;
59 g = ((*pixels) & 0x00ff00) >> 8;
60 b = (*pixels) & 0x0000ff;
61
62 fprintf(f, "%c%c%c", r, g, b);
63 }
64
65 fclose(f);
66 printf("Saved scene as '%s'\n", dest);
67}
68
69int
70main(void)
71{
72 Evas *canvas;
73 Evas_Object *bg, *r1, *r2, *r3;
74
75 ecore_evas_init();
76
77 ee = ecore_evas_buffer_new(WIDTH, HEIGHT);
78 if (!ee) goto error;
79
80 canvas = ecore_evas_get(ee);
81
82 bg = evas_object_rectangle_add(canvas);
83 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
84 evas_object_move(bg, 0, 0); /* at origin */
85 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
86 evas_object_show(bg);
87
88 r1 = evas_object_rectangle_add(canvas);
89 evas_object_color_set(r1, 255, 0, 0, 255); /* 100% opaque red */
90 evas_object_move(r1, 10, 10);
91 evas_object_resize(r1, 100, 100);
92 evas_object_show(r1);
93
94 r2 = evas_object_rectangle_add(canvas);
95 evas_object_color_set(r2, 0, 128, 0, 128); /* 50% opaque green */
96 evas_object_move(r2, 10, 10);
97 evas_object_resize(r2, 50, 50);
98 evas_object_show(r2);
99
100 r3 = evas_object_rectangle_add(canvas);
101 evas_object_color_set(r3, 0, 128, 0, 255); /* 100% opaque dark green */
102 evas_object_move(r3, 60, 60);
103 evas_object_resize(r3, 50, 50);
104 evas_object_show(r3);
105
106 ecore_evas_manual_render(ee);
107 _scene_save(canvas, "/tmp/evas-buffer-simple-render.ppm");
108
109 ecore_evas_free(ee);
110 ecore_evas_shutdown();
111
112 return 0;
113
114error:
115 fprintf(stderr, "You got to have at least one Evas engine built"
116 " and linked up to ecore-evas for this example to run"
117 " properly.\n");
118 ecore_evas_shutdown();
119 return -1;
120}
121
diff --git a/src/examples/ecore/ecore_evas_buffer_example_02.c b/src/examples/ecore/ecore_evas_buffer_example_02.c
new file mode 100644
index 0000000000..d30d764867
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_buffer_example_02.c
@@ -0,0 +1,126 @@
1/**
2 * Simple Ecore_Evas example on the Evas buffer engine wrapper
3 * functions.
4 *
5 * You must have Evas compiled with the buffer engine.
6 *
7 * Compile with:
8 *
9 * @verbatim
10 * gcc -o evas-buffer-simple evas-buffer-simple.c `pkg-config --libs --cflags evas evas-software-buffer`
11 * @endverbatim
12 *
13 */
14
15#ifdef HAVE_CONFIG_H
16
17#include "config.h"
18#else
19#define EINA_UNUSED
20#define PACKAGE_EXAMPLES_DIR "."
21#endif
22
23#include <Ecore.h>
24#include <Ecore_Evas.h>
25#include <stdio.h>
26
27#define WIDTH (320)
28#define HEIGHT (240)
29
30static Ecore_Evas *ee;
31static const char *border_img_path = PACKAGE_EXAMPLES_DIR "/red.png";
32
33static void
34_on_destroy(Ecore_Evas *ee EINA_UNUSED)
35{
36 ecore_main_loop_quit();
37}
38
39int
40main(void)
41{
42 Evas *canvas, *sub_canvas;
43 Evas_Object *bg, *r1, *r2, *r3; /* "sub" canvas objects */
44 Evas_Object *border, *img; /* canvas objects */
45 Ecore_Evas *sub_ee;
46
47 ecore_evas_init();
48
49 /* this will give you a window with an Evas canvas under the first
50 * engine available */
51 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
52 if (!ee) goto error;
53
54 ecore_evas_size_min_set(ee, WIDTH, HEIGHT);
55 ecore_evas_size_max_set(ee, WIDTH, HEIGHT);
56
57 ecore_evas_callback_delete_request_set(ee, _on_destroy);
58 ecore_evas_title_set(ee, "Ecore_Evas buffer (image) example");
59 ecore_evas_show(ee);
60
61 canvas = ecore_evas_get(ee);
62
63 bg = evas_object_rectangle_add(canvas);
64 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
65 evas_object_move(bg, 0, 0); /* at origin */
66 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
67 evas_object_show(bg);
68
69 /* this is a border around the image containing a scene of another
70 * canvas */
71 border = evas_object_image_filled_add(canvas);
72 evas_object_image_file_set(border, border_img_path, NULL);
73 evas_object_image_border_set(border, 3, 3, 3, 3);
74 evas_object_image_border_center_fill_set(border, EVAS_BORDER_FILL_NONE);
75
76 evas_object_move(border, WIDTH / 6, HEIGHT / 6);
77 evas_object_resize(border, (2 * WIDTH) / 3, (2 * HEIGHT) / 3);
78 evas_object_show(border);
79
80 img = ecore_evas_object_image_new(ee);
81 evas_object_image_filled_set(img, EINA_TRUE);
82 evas_object_image_size_set(
83 img, ((2 * WIDTH) / 3) - 6, ((2 * HEIGHT) / 3) - 6);
84 sub_ee = ecore_evas_object_ecore_evas_get(img);
85 sub_canvas = ecore_evas_object_evas_get(img);
86
87 evas_object_move(img, (WIDTH / 6) + 3, (HEIGHT / 6) + 3);
88
89 /* apply the same size on both! */
90 evas_object_resize(img, ((2 * WIDTH) / 3) - 6, ((2 * HEIGHT) / 3) - 6);
91 ecore_evas_resize(sub_ee, ((2 * WIDTH) / 3) - 6, ((2 * HEIGHT) / 3) - 6);
92
93 r1 = evas_object_rectangle_add(sub_canvas);
94 evas_object_color_set(r1, 255, 0, 0, 255); /* 100% opaque red */
95 evas_object_move(r1, 10, 10);
96 evas_object_resize(r1, 100, 100);
97 evas_object_show(r1);
98
99 r2 = evas_object_rectangle_add(sub_canvas);
100 evas_object_color_set(r2, 0, 128, 0, 128); /* 50% opaque green */
101 evas_object_move(r2, 10, 10);
102 evas_object_resize(r2, 50, 50);
103 evas_object_show(r2);
104
105 r3 = evas_object_rectangle_add(sub_canvas);
106 evas_object_color_set(r3, 0, 128, 0, 255); /* 100% opaque dark green */
107 evas_object_move(r3, 60, 60);
108 evas_object_resize(r3, 50, 50);
109 evas_object_show(r3);
110
111 evas_object_show(img);
112 ecore_main_loop_begin();
113
114 ecore_evas_free(ee);
115 ecore_evas_shutdown();
116
117 return 0;
118
119error:
120 fprintf(stderr, "You got to have at least one Evas engine built"
121 " and linked up to ecore-evas for this example to run"
122 " properly.\n");
123 ecore_evas_shutdown();
124 return -1;
125}
126
diff --git a/src/examples/ecore/ecore_evas_callbacks.c b/src/examples/ecore/ecore_evas_callbacks.c
new file mode 100644
index 0000000000..3e42da161a
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_callbacks.c
@@ -0,0 +1,128 @@
1/**
2 * Ecore example illustrating ecore evas callbacks.
3 *
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o ecore_evas_callbacks ecore_evas_callbacks.c `pkg-config --libs --cflags ecore-evas`
9 * @endverbatim
10 */
11
12#include <Ecore.h>
13#include <Ecore_Evas.h>
14
15static void
16_destroy(Ecore_Evas *ee)
17{
18 printf("destroy\n");
19 ecore_main_loop_quit();
20}
21
22static void
23_delete(Ecore_Evas *ee)
24{
25 printf("delete\n");
26 ecore_main_loop_quit();
27}
28
29static void
30_focus_in(Ecore_Evas *ee)
31{
32 printf("focus_in\n");
33}
34
35static void
36_focus_out(Ecore_Evas *ee)
37{
38 printf("focus_out\n");
39}
40
41static void
42_hide(Ecore_Evas *ee)
43{
44 printf("hide\n");
45}
46
47static void
48_mouse_in(Ecore_Evas *ee)
49{
50 printf("mouse_in\n");
51}
52
53static void
54_show(Ecore_Evas *ee)
55{
56 printf("show\n");
57}
58
59static void
60_mouse_out(Ecore_Evas *ee)
61{
62 printf("mouse_out\n");
63}
64
65static void
66_move(Ecore_Evas *ee)
67{
68 printf("move\n");
69}
70
71static void
72_post_render(Ecore_Evas *ee)
73{
74 printf("post_render\n");
75}
76
77static void
78_pre_free(Ecore_Evas *ee)
79{
80 printf("pre_free\n");
81}
82
83static void
84_pre_render(Ecore_Evas *ee)
85{
86 printf("pre_render\n");
87}
88
89static void
90_resize(Ecore_Evas *ee)
91{
92 printf("resize\n");
93}
94
95int
96main(void)
97{
98 Ecore_Evas *ee;
99
100 ecore_evas_init();
101
102 ee = ecore_evas_new(NULL, 0, 0, 200, 100, NULL);
103 ecore_evas_title_set(ee, "Ecore Evas Callbacks Example");
104 ecore_evas_show(ee);
105
106 //callbacks
107 ecore_evas_callback_delete_request_set(ee, _delete);
108 ecore_evas_callback_destroy_set(ee, _destroy);
109 ecore_evas_callback_focus_in_set(ee, _focus_in);
110 ecore_evas_callback_focus_out_set(ee, _focus_out);
111 ecore_evas_callback_hide_set(ee, _hide);
112 ecore_evas_callback_mouse_in_set(ee, _mouse_in);
113 ecore_evas_callback_mouse_out_set(ee, _mouse_out);
114 ecore_evas_callback_move_set(ee, _move);
115 ecore_evas_callback_post_render_set(ee, _post_render);
116 ecore_evas_callback_pre_free_set(ee, _pre_free);
117 ecore_evas_callback_pre_render_set(ee, _pre_render);
118 ecore_evas_callback_resize_set(ee, _resize);
119 ecore_evas_callback_show_set(ee, _show);
120
121 ecore_main_loop_begin();
122
123 ecore_evas_free(ee);
124 ecore_evas_shutdown();
125
126 return 0;
127}
128
diff --git a/src/examples/ecore/ecore_evas_ews_example.c b/src/examples/ecore/ecore_evas_ews_example.c
new file mode 100644
index 0000000000..1209ffd032
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_ews_example.c
@@ -0,0 +1,269 @@
1/**
2 * Ecore example illustrating the ews of ecore evas usage.
3 *
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o ecore_evas_ews_example ecore_evas_ews_example.c `pkg-config --libs --cflags ecore-evas`
9 * @endverbatim
10 */
11
12#include <Ecore.h>
13#include <Ecore_Evas.h>
14#include <unistd.h>
15#include <stdio.h>
16#include <ctype.h>
17
18static Eina_Bool
19_wm_win_add(void *data, int type, void *event_info)
20{
21 Ecore_Evas *ee = event_info;
22 printf("WM: new window=%p\n", ee);
23 return EINA_TRUE;
24}
25
26static Eina_Bool
27_wm_win_move(void *data, int type, void *event_info)
28{
29 Ecore_Evas *ee = event_info;
30 int x, y;
31 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
32 printf("WM: window=%p moved to %d,%d\n", ee, x, y);
33 return EINA_TRUE;
34}
35
36static Eina_Bool
37_wm_win_resize(void *data, int type, void *event_info)
38{
39 Ecore_Evas *ee = event_info;
40 int w, h;
41 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
42 printf("WM: window=%p resized to %dx%d\n", ee, w, h);
43 return EINA_TRUE;
44}
45
46static Eina_Bool
47_wm_win_show(void *data, int type, void *event_info)
48{
49 Ecore_Evas *ee = event_info;
50 printf("WM: show window=%p\n", ee);
51 return EINA_TRUE;
52}
53
54static void
55optional_ews_window_manager_setup(void)
56{
57 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_ADD, _wm_win_add, NULL);
58 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_MOVE, _wm_win_move, NULL);
59 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_RESIZE, _wm_win_resize, NULL);
60 ecore_event_handler_add(ECORE_EVAS_EWS_EVENT_SHOW, _wm_win_show, NULL);
61
62 /* one may use any known unique identifier, like an app function pointer */
63 ecore_evas_ews_manager_set(optional_ews_window_manager_setup);
64}
65
66static void
67optional_ews_setup(void)
68{
69 Evas_Object *bg;
70 Evas *e;
71
72 ecore_evas_ews_setup(0, 0, 800, 600); /* "screen" size */
73 e = ecore_evas_ews_evas_get(); /* forces "screen" to be allocated */
74
75 bg = evas_object_rectangle_add(e);
76 evas_object_color_set(bg, 128, 32, 32, 255);
77 ecore_evas_ews_background_set(bg);
78}
79
80static Eina_Bool
81_stdin_cb(void *data, Ecore_Fd_Handler *handler)
82{
83 const Eina_List *l;
84 Ecore_Evas *ee;
85 char c = getchar();
86
87 if (c == EOF)
88 {
89 ecore_main_loop_quit();
90 return EINA_FALSE;
91 }
92
93 switch (c) {
94 case 'h':
95 printf("hide all windows\n");
96 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
97 ecore_evas_hide(ee);
98 break;
99
100 case 's':
101 printf("show all windows\n");
102 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
103 ecore_evas_show(ee);
104 break;
105
106 case 'l':
107 printf("move all windows left\n");
108 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
109 {
110 int x, y;
111 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
112 ecore_evas_move(ee, x - 10, y);
113 }
114 break;
115
116 case 'r':
117 printf("move all windows right\n");
118 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
119 {
120 int x, y;
121 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
122 ecore_evas_move(ee, x + 10, y);
123 }
124 break;
125
126 case 't':
127 printf("move all windows top\n");
128 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
129 {
130 int x, y;
131 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
132 ecore_evas_move(ee, x, y - 10);
133 }
134 break;
135
136 case 'b':
137 printf("move all windows bottom\n");
138 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
139 {
140 int x, y;
141 ecore_evas_geometry_get(ee, &x, &y, NULL, NULL);
142 ecore_evas_move(ee, x, y + 10);
143 }
144 break;
145
146 case 'S':
147 printf("make all windows smaller\n");
148 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
149 {
150 int w, h;
151 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
152 ecore_evas_resize(ee, w - 10, h - 10);
153 }
154 break;
155
156 case 'B':
157 printf("make all windows bigger\n");
158 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
159 {
160 int w, h;
161 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
162 ecore_evas_resize(ee, w + 10, h + 10);
163 }
164 break;
165
166 case 'm':
167 printf("make all windows unmaximized\n");
168 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
169 ecore_evas_maximized_set(ee, EINA_FALSE);
170 break;
171
172 case 'M':
173 printf("make all windows maximized\n");
174 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
175 ecore_evas_maximized_set(ee, EINA_TRUE);
176 break;
177
178 case 'i':
179 printf("make all windows uniconified\n");
180 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
181 ecore_evas_iconified_set(ee, EINA_FALSE);
182 break;
183
184 case 'I':
185 printf("make all windows iconified\n");
186 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
187 ecore_evas_iconified_set(ee, EINA_TRUE);
188 break;
189
190 case 'f':
191 printf("make all windows unfullscreen\n");
192 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
193 ecore_evas_fullscreen_set(ee, EINA_FALSE);
194 break;
195
196 case 'F':
197 printf("make all windows fullscreen\n");
198 EINA_LIST_FOREACH(ecore_evas_ews_children_get(), l, ee)
199 ecore_evas_fullscreen_set(ee, EINA_TRUE);
200 break;
201
202 case 'q':
203 printf("quit\n");
204 ecore_main_loop_quit();
205 break;
206
207 default:
208 if (!isspace(c))
209 printf("Unknown command: %c\n", c);
210 }
211 return ECORE_CALLBACK_RENEW;
212}
213
214static void
215_on_delete(Ecore_Evas *ee)
216{
217 free(ecore_evas_data_get(ee, "key"));
218 ecore_main_loop_quit();
219}
220
221int
222main(void)
223{
224 Ecore_Evas *ee;
225 Evas *canvas;
226 Evas_Object *bg;
227
228 if (ecore_evas_init() <= 0)
229 return 1;
230
231 optional_ews_setup();
232 optional_ews_window_manager_setup();
233
234 /* everything should look similar to ecore_evas_basic_example */
235 ee = ecore_evas_ews_new(0, 0, 200, 200);
236 ecore_evas_title_set(ee, "Ecore Evas EWS Example");
237 ecore_evas_show(ee);
238
239 ecore_evas_data_set(ee, "key", strdup("hello"));
240 ecore_evas_callback_delete_request_set(ee, _on_delete);
241
242 printf("Using %s engine!\n", ecore_evas_engine_name_get(ee));
243
244 canvas = ecore_evas_get(ee);
245 if (ecore_evas_ecore_evas_get(canvas) == ee)
246 printf("Everything is sane!\n");
247
248 bg = evas_object_rectangle_add(canvas);
249 evas_object_color_set(bg, 0, 0, 255, 255);
250 evas_object_resize(bg, 200, 200);
251 evas_object_show(bg);
252 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
253
254 /* moving the window should move it in the screen */
255 ecore_evas_move(ee, 50, 50);
256
257 ecore_main_fd_handler_add(STDIN_FILENO,
258 ECORE_FD_READ | ECORE_FD_ERROR,
259 _stdin_cb,
260 NULL, NULL, NULL);
261
262 ecore_main_loop_begin();
263
264 ecore_evas_free(ee);
265 ecore_evas_shutdown();
266
267 return 0;
268}
269
diff --git a/src/examples/ecore/ecore_evas_object_example.c b/src/examples/ecore/ecore_evas_object_example.c
new file mode 100644
index 0000000000..38e4c4b277
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_object_example.c
@@ -0,0 +1,53 @@
1/**
2 * Ecore example illustrating ecore evas object usage.
3 *
4 * You'll need at least one Evas engine built for it (excluding the
5 * buffer one). See stdout/stderr for output.
6 *
7 * @verbatim
8 * gcc -o ecore_evas_object_example ecore_evas_object_example.c `pkg-config --libs --cflags ecore-evas`
9 * @endverbatim
10 */
11
12#include <Ecore.h>
13#include <Ecore_Evas.h>
14
15int
16main(void)
17{
18 Ecore_Evas *ee;
19 Evas_Object *bg, *cursor, *obj;
20 int layer, x, y;
21
22 ecore_evas_init();
23
24 ee = ecore_evas_new(NULL, 0, 0, 200, 200, NULL);
25 ecore_evas_title_set(ee, "Ecore Evas Object Example");
26 ecore_evas_show(ee);
27
28 bg = evas_object_rectangle_add(ecore_evas_get(ee));
29 evas_object_color_set(bg, 0, 0, 255, 255);
30 evas_object_resize(bg, 200, 200);
31 evas_object_show(bg);
32 ecore_evas_object_associate(ee, bg, ECORE_EVAS_OBJECT_ASSOCIATE_BASE);
33
34 if (bg == ecore_evas_object_associate_get(ee))
35 printf("Association worked!\n");
36
37 cursor = evas_object_rectangle_add(ecore_evas_get(ee));
38 evas_object_color_set(cursor, 0, 255, 0, 255);
39 evas_object_resize(cursor, 5, 10);
40 ecore_evas_object_cursor_set(ee, cursor, 0, 1, 1);
41
42 ecore_evas_cursor_get(ee, &obj, &layer, &x, &y);
43 if (obj == cursor && layer == 0 && x == 1 && y == 1)
44 printf("Set cursor worked!\n");
45
46 ecore_main_loop_begin();
47
48 ecore_evas_free(ee);
49 ecore_evas_shutdown();
50
51 return 0;
52}
53
diff --git a/src/examples/ecore/ecore_evas_window_sizes_example.c b/src/examples/ecore/ecore_evas_window_sizes_example.c
new file mode 100644
index 0000000000..833529effc
--- /dev/null
+++ b/src/examples/ecore/ecore_evas_window_sizes_example.c
@@ -0,0 +1,204 @@
1/**
2 * Simple @c Ecore_Evas example illustrating how to deal with window
3 * sizes
4 *
5 * You'll need at least one engine built for it (excluding the buffer
6 * one). See stdout/stderr for output.
7 *
8 * @verbatim
9 * gcc -o evas-smart-object evas-smart-object.c `pkg-config --libs --cflags evas ecore ecore-evas`
10 * @endverbatim
11 */
12
13#ifdef HAVE_CONFIG_H
14
15#include "config.h"
16#else
17#define EINA_UNUSED
18#endif
19
20#include <Ecore.h>
21#include <Ecore_Evas.h>
22
23#define WIDTH (300)
24#define HEIGHT (300)
25
26static Ecore_Evas *ee;
27static Evas_Object *text, *bg;
28static Eina_Bool min_set = EINA_FALSE;
29static Eina_Bool max_set = EINA_FALSE;
30static Eina_Bool base_set = EINA_FALSE;
31static Eina_Bool step_set = EINA_FALSE;
32
33static const char commands[] = \
34 "commands are:\n"
35 "\tm - impose a minumum size to the window\n"
36 "\tx - impose a maximum size to the window\n"
37 "\tb - impose a base size to the window\n"
38 "\ts - impose a step size (different than 1 px) to the window\n"
39 "\th - print help\n";
40
41/* to inform current window's size */
42static void
43_canvas_resize_cb(Ecore_Evas *ee)
44{
45 int w, h;
46 char buf[1024];
47
48 ecore_evas_geometry_get(ee, NULL, NULL, &w, &h);
49 snprintf(buf, sizeof(buf), "%d x %d", w, h);
50 evas_object_text_text_set(text, buf);
51 evas_object_move(text, (w - 150) / 2, (h - 50) / 2);
52
53 evas_object_resize(bg, w, h);
54}
55
56static void
57_on_destroy(Ecore_Evas *ee EINA_UNUSED)
58{
59 ecore_main_loop_quit();
60}
61
62static void
63_on_keydown(void *data EINA_UNUSED,
64 Evas *evas EINA_UNUSED,
65 Evas_Object *o EINA_UNUSED,
66 void *einfo)
67{
68 Evas_Event_Key_Down *ev = einfo;
69
70 if (strcmp(ev->keyname, "h") == 0) /* print help */
71 {
72 fprintf(stdout, commands);
73 return;
74 }
75
76 if (strcmp(ev->keyname, "m") == 0) /* impose a minimum size on the window */
77 {
78 min_set = !min_set;
79
80 if (min_set)
81 {
82 ecore_evas_size_min_set(ee, WIDTH / 2, HEIGHT / 2);
83 fprintf(stdout, "Imposing a minimum size of %d x %d\n",
84 WIDTH / 2, HEIGHT / 2);
85 }
86 else
87 {
88 ecore_evas_size_min_set(ee, 0, 0);
89 fprintf(stdout, "Taking off minimum size restriction from the"
90 " window\n");
91 }
92 return;
93 }
94
95 if (strcmp(ev->keyname, "x") == 0) /* impose a maximum size on the window */
96 {
97 max_set = !max_set;
98
99 if (max_set)
100 {
101 ecore_evas_size_max_set(ee, WIDTH * 2, HEIGHT * 2);
102 fprintf(stdout, "Imposing a maximum size of %d x %d\n",
103 WIDTH * 2, HEIGHT * 2);
104 }
105 else
106 {
107 ecore_evas_size_max_set(ee, 0, 0);
108 fprintf(stdout, "Taking off maximum size restriction from the"
109 " window\n");
110 }
111 return;
112 }
113
114 if (strcmp(ev->keyname, "b") == 0) /* impose a base size on the window */
115 {
116 base_set = !base_set;
117
118 if (base_set)
119 {
120 ecore_evas_size_base_set(ee, WIDTH * 2, HEIGHT * 2);
121 fprintf(stdout, "Imposing a base size of %d x %d\n",
122 WIDTH * 2, HEIGHT * 2);
123 }
124 else
125 {
126 ecore_evas_size_base_set(ee, 0, 0);
127 fprintf(stdout, "Taking off base size restriction from the"
128 " window\n");
129 }
130 return;
131 }
132
133 if (strcmp(ev->keyname, "s") == 0) /* impose a step size on the window */
134 {
135 step_set = !step_set;
136
137 if (step_set)
138 {
139 ecore_evas_size_step_set(ee, 40, 40);
140 fprintf(stdout, "Imposing a step size of %d x %d\n", 40, 40);
141 }
142 else
143 {
144 ecore_evas_size_step_set(ee, 0, 0);
145 fprintf(stdout, "Taking off step size restriction from the"
146 " window\n");
147 }
148 return;
149 }
150}
151
152int
153main(void)
154{
155 Evas *evas;
156
157 if (!ecore_evas_init())
158 return EXIT_FAILURE;
159
160 /* this will give you a window with an Evas canvas under the first
161 * engine available */
162 ee = ecore_evas_new(NULL, 0, 0, WIDTH, HEIGHT, NULL);
163 if (!ee) goto error;
164
165 ecore_evas_callback_delete_request_set(ee, _on_destroy);
166 ecore_evas_title_set(ee, "Ecore_Evas window sizes example");
167 ecore_evas_callback_resize_set(ee, _canvas_resize_cb);
168 ecore_evas_show(ee);
169
170 evas = ecore_evas_get(ee);
171
172 bg = evas_object_rectangle_add(evas);
173 evas_object_color_set(bg, 255, 255, 255, 255); /* white bg */
174 evas_object_move(bg, 0, 0); /* at canvas' origin */
175 evas_object_resize(bg, WIDTH, HEIGHT); /* covers full canvas */
176 evas_object_show(bg);
177
178 evas_object_focus_set(bg, EINA_TRUE);
179 evas_object_event_callback_add(
180 bg, EVAS_CALLBACK_KEY_DOWN, _on_keydown, NULL);
181
182 text = evas_object_text_add(evas);
183 evas_object_color_set(text, 0, 0, 0, 255);
184 evas_object_resize(text, 150, 50);
185 evas_object_text_font_set(text, "Sans", 20);
186 evas_object_show(text);
187
188 _canvas_resize_cb(ee);
189 fprintf(stdout, commands);
190 ecore_main_loop_begin();
191
192 ecore_evas_free(ee);
193 ecore_evas_shutdown();
194
195 return 0;
196
197error:
198 fprintf(stderr, "You got to have at least one Evas engine built"
199 " and linked up to ecore-evas for this example to run"
200 " properly.\n");
201 ecore_evas_shutdown();
202 return -1;
203}
204
diff --git a/src/examples/ecore/ecore_event_example_01.c b/src/examples/ecore/ecore_event_example_01.c
new file mode 100644
index 0000000000..64a5be8650
--- /dev/null
+++ b/src/examples/ecore/ecore_event_example_01.c
@@ -0,0 +1,26 @@
1/*
2 * Compile with:
3 * gcc -g -Wall `pkg-config --cflags --libs ecore` -o ecore_event_example ecore_event_example.c
4 */
5
6#include <Ecore.h>
7
8static Eina_Bool
9_quitter(void *data, int ev_type, void *event)
10{
11 printf("Leaving already?\n");
12 ecore_main_loop_quit();
13 return ECORE_CALLBACK_DONE;
14}
15
16int
17main(int argc, char **argv)
18{
19 ecore_init();
20
21 ecore_event_handler_add(ECORE_EVENT_SIGNAL_EXIT, _quitter, NULL);
22 ecore_main_loop_begin();
23
24 return 0;
25}
26
diff --git a/src/examples/ecore/ecore_event_example_02.c b/src/examples/ecore/ecore_event_example_02.c
new file mode 100644
index 0000000000..c293e65453
--- /dev/null
+++ b/src/examples/ecore/ecore_event_example_02.c
@@ -0,0 +1,89 @@
1#include <Ecore.h>
2#include <unistd.h>
3
4struct context // helper struct to give some context to the callbacks
5{
6 const char *str1, *str2;
7 Ecore_Event_Handler *handler1;
8 Ecore_Event_Handler *handler2;
9};
10
11static int _event_type = 0; // a new type of event will be defined and stored here
12
13static Eina_Bool
14_event_handler1_cb(void *data, int type, void *event)
15{
16 int *number = event;
17 const char *str = data;
18
19 printf("event_handler1: number=%d, data=\"%s\".\n", *number, str);
20
21 if ((*number % 2) == 0)
22 return ECORE_CALLBACK_DONE;
23
24 return ECORE_CALLBACK_PASS_ON;
25}
26
27static Eina_Bool
28_event_handler2_cb(void *data, int type, void *event) // event callback
29{
30 struct context *ctxt = data;
31 int *number = event;
32
33 printf("event_handler2: number=%d.\n", *number);
34
35 if (*number == 5)
36 {
37 const char *old = NULL;
38 old = ecore_event_handler_data_set(ctxt->handler1, (void *)ctxt->str2);
39 printf("changed handler1 data from \"%s\" to \"%s\".\n",
40 old, ctxt->str2);
41 }
42 else if (*number >= 10)
43 {
44 printf("finish main loop.\n");
45 ecore_main_loop_quit();
46 }
47
48 return ECORE_CALLBACK_DONE; // same as EINA_FALSE
49}
50
51int
52main(int argc, char **argv)
53{
54 struct context ctxt = {0};
55 int i;
56 ctxt.str1 = "dataone";
57 ctxt.str2 = "datatwo";
58
59 if (!ecore_init())
60 {
61 printf("ERROR: Cannot init Ecore!\n");
62 return -1;
63 }
64
65 _event_type = ecore_event_type_new();
66
67 ctxt.handler1 = ecore_event_handler_add(_event_type,
68 _event_handler1_cb,
69 ctxt.str1);
70 ctxt.handler2 = ecore_event_handler_add(_event_type,
71 _event_handler2_cb,
72 &ctxt);
73
74 for (i = 0; i <= 15; i++)
75 {
76 int *event_data = malloc(sizeof(*event_data));
77 *event_data = i;
78 ecore_event_add(_event_type, event_data, NULL, NULL);
79 }
80
81 printf("start the main loop.\n");
82
83 ecore_main_loop_begin();
84
85 ecore_shutdown();
86
87 return 0;
88}
89
diff --git a/src/examples/ecore/ecore_exe_example.c b/src/examples/ecore/ecore_exe_example.c
new file mode 100644
index 0000000000..8d0dedc846
--- /dev/null
+++ b/src/examples/ecore/ecore_exe_example.c
@@ -0,0 +1,100 @@
1/**
2 Compile with gcc -o ecore_exe_example ecore_exe_example.c `pkg-config --cflags --libs ecore`
3 */
4
5#include <stdio.h>
6#include <string.h>
7#include <Ecore.h>
8
9#define BUFFER_SIZE 1024
10
11static Eina_Bool
12_msg_from_child_handler(void *data, int type, void *event)
13{
14 Ecore_Exe_Event_Data *dataFromProcess = (Ecore_Exe_Event_Data *)event;
15 char msg[BUFFER_SIZE];
16
17 if (dataFromProcess->size >= (BUFFER_SIZE - 1))
18 {
19 fprintf(stdout, "Data too big for bugger. error\n");
20 return ECORE_CALLBACK_DONE;
21 }
22
23 strncpy(msg, dataFromProcess->data, dataFromProcess->size);
24 msg[dataFromProcess->size] = 0;
25
26 if (strcmp(msg, "quit") == 0)
27 {
28 fprintf(stdout, "My child said to me, QUIT!\n");
29 ecore_main_loop_quit();
30 }
31 else
32 fprintf(stdout, "I received a message from my child: %s\n", msg);
33
34 return ECORE_CALLBACK_DONE;
35}
36
37static Eina_Bool
38_sendMessage(void *data)
39{
40 static int numberOfMessages = 0;
41 Ecore_Exe *childHandle = (Ecore_Exe *)data;
42 char msg[BUFFER_SIZE];
43
44 sprintf(msg, " Message: %d\n", numberOfMessages);
45 numberOfMessages++;
46
47 if (ecore_exe_send(childHandle, msg, strlen(msg)) != EINA_TRUE)
48 fprintf(stderr, "Could not send my name to the child\n");
49 else
50 fprintf(stdout,
51 "I'm the father and I sent this message to the child: %s\n", msg);
52
53 return ECORE_CALLBACK_RENEW;
54}
55
56int
57main(int argc, char **argv)
58{
59 pid_t childPid;
60 Ecore_Exe *childHandle;
61
62 if (!ecore_init())
63 goto exit;
64
65 childHandle = ecore_exe_pipe_run("./ecore_exe_example_child",
66 ECORE_EXE_PIPE_WRITE |
67 ECORE_EXE_PIPE_READ_LINE_BUFFERED |
68 ECORE_EXE_PIPE_READ, NULL);
69
70 if (childHandle == NULL)
71 {
72 fprintf(stderr, "Could not create a child process!\n");
73 goto ecore_shutdown;
74 }
75
76 childPid = ecore_exe_pid_get(childHandle);
77
78 if (childPid == -1)
79 fprintf(stderr, "Could not retrive the PID!\n");
80 else
81 fprintf(stdout, "The child process has PID:%d\n", childPid);
82
83 ecore_event_handler_add(ECORE_EXE_EVENT_DATA, _msg_from_child_handler, NULL);
84 ecore_timer_add(1, _sendMessage, childHandle);
85
86 ecore_main_loop_begin();
87
88 ecore_exe_free(childHandle); //This will not affect the child process
89
90 ecore_shutdown();
91
92 return EXIT_SUCCESS;
93
94ecore_shutdown:
95 ecore_shutdown();
96
97exit:
98 return EXIT_FAILURE;
99}
100
diff --git a/src/examples/ecore/ecore_exe_example_child.c b/src/examples/ecore/ecore_exe_example_child.c
new file mode 100644
index 0000000000..efe97fb111
--- /dev/null
+++ b/src/examples/ecore/ecore_exe_example_child.c
@@ -0,0 +1,57 @@
1/**
2 Compile with gcc -o ecore_exe_example_child ecore_exe_example_child.c `pkg-config --cflags --libs ecore`
3 */
4
5#include <stdio.h>
6#include <unistd.h>
7#include <Ecore.h>
8
9#define BUFFER_SIZE 1024
10
11static Eina_Bool
12_fd_handler_cb(void *data, Ecore_Fd_Handler
13 *fd_handler)
14{
15 static int numberOfMessages = 0;
16 char message[BUFFER_SIZE];
17
18 if (!fgets(message, BUFFER_SIZE, stdin))
19 return ECORE_CALLBACK_RENEW;
20
21 numberOfMessages++;
22
23 if (numberOfMessages < 3)
24 {
25 fprintf(stdout, "My father sent this message to me:%s\n", message);
26 fflush(stdout);
27 return ECORE_CALLBACK_RENEW;
28 }
29 else
30 {
31 fprintf(stdout, "quit\n");
32 fflush(stdout);
33 ecore_main_loop_quit();
34 return ECORE_CALLBACK_DONE;
35 }
36}
37
38int
39main(int argc, char **argv)
40{
41 if (!ecore_init())
42 goto error;
43
44 ecore_main_fd_handler_add(STDIN_FILENO,
45 ECORE_FD_READ,
46 _fd_handler_cb,
47 NULL, NULL, NULL);
48 ecore_main_loop_begin();
49
50 ecore_shutdown();
51
52 return EXIT_SUCCESS;
53
54error:
55 return EXIT_FAILURE;
56}
57
diff --git a/src/examples/ecore/ecore_fd_handler_example.c b/src/examples/ecore/ecore_fd_handler_example.c
new file mode 100644
index 0000000000..381d1014e7
--- /dev/null
+++ b/src/examples/ecore/ecore_fd_handler_example.c
@@ -0,0 +1,89 @@
1#include <Ecore.h>
2#include <unistd.h>
3
4struct context
5{
6 Ecore_Fd_Handler *handler;
7 Ecore_Timer *timer;
8};
9
10static void
11_fd_prepare_cb(void *data, Ecore_Fd_Handler *handler)
12{
13 printf("prepare_cb called.\n");
14}
15
16static Eina_Bool
17_fd_handler_cb(void *data, Ecore_Fd_Handler *handler)
18{
19 struct context *ctxt = data;
20 char buf[1024];
21 size_t nbytes;
22 int fd;
23
24 if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR))
25 {
26 printf("An error has occurred. Stop watching this fd and quit.\n");
27 ecore_main_loop_quit();
28 ctxt->handler = NULL;
29 return ECORE_CALLBACK_CANCEL;
30 }
31
32 fd = ecore_main_fd_handler_fd_get(handler);
33 nbytes = read(fd, buf, sizeof(buf));
34 if (nbytes == 0)
35 {
36 printf("Nothing to read, exiting...\n");
37 ecore_main_loop_quit();
38 ctxt->handler = NULL;
39 return ECORE_CALLBACK_CANCEL;
40 }
41 buf[nbytes - 1] = '\0';
42
43 printf("Read %zd bytes from input: \"%s\"\n", nbytes - 1, buf);
44
45 return ECORE_CALLBACK_RENEW;
46}
47
48static Eina_Bool
49_timer_cb(void *data)
50{
51 printf("Timer expired after 5 seconds...\n");
52
53 return ECORE_CALLBACK_RENEW;
54}
55
56int
57main(int argc, char **argv)
58{
59 struct context ctxt = {0};
60
61 if (!ecore_init())
62 {
63 printf("ERROR: Cannot init Ecore!\n");
64 return -1;
65 }
66
67 ctxt.handler = ecore_main_fd_handler_add(STDIN_FILENO,
68 ECORE_FD_READ | ECORE_FD_ERROR,
69 _fd_handler_cb,
70 &ctxt, NULL, NULL);
71 ecore_main_fd_handler_prepare_callback_set(ctxt.handler, _fd_prepare_cb, &ctxt);
72 ctxt.timer = ecore_timer_add(5, _timer_cb, &ctxt);
73
74 printf("Starting the main loop. Type anything and hit <enter> to "
75 "activate the fd_handler callback, or CTRL+d to shutdown.\n");
76
77 ecore_main_loop_begin();
78
79 if (ctxt.handler)
80 ecore_main_fd_handler_del(ctxt.handler);
81
82 if (ctxt.timer)
83 ecore_timer_del(ctxt.timer);
84
85 ecore_shutdown();
86
87 return 0;
88}
89
diff --git a/src/examples/ecore/ecore_fd_handler_gnutls_example.c b/src/examples/ecore/ecore_fd_handler_gnutls_example.c
new file mode 100644
index 0000000000..5635b131cc
--- /dev/null
+++ b/src/examples/ecore/ecore_fd_handler_gnutls_example.c
@@ -0,0 +1,203 @@
1#include <Ecore.h>
2#include <fcntl.h>
3#include <netinet/tcp.h>
4#include <netinet/in.h>
5#include <sys/socket.h>
6#include <arpa/inet.h>
7#include <errno.h>
8#include <unistd.h>
9#include <gnutls/gnutls.h>
10
11/* Ecore_Fd_Handler example
12 * 2010 Mike Blumenkrantz
13 * compile with gcc $(pkgconfig --cflags --libs gnutls ecore)
14 */
15
16#define print(...) fprintf(stderr, "line %i: ", __LINE__); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n")
17
18static int done = 0;
19
20static void
21tls_log_func(int level, const char *str)
22{
23 fprintf(stderr, "|<%d>| %s", level, str);
24}
25
26static const char *
27SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_description_t status)
28{
29 switch (status)
30 {
31 case GNUTLS_HANDSHAKE_HELLO_REQUEST:
32 return "Hello request";
33
34 case GNUTLS_HANDSHAKE_CLIENT_HELLO:
35 return "Client hello";
36
37 case GNUTLS_HANDSHAKE_SERVER_HELLO:
38 return "Server hello";
39
40 case GNUTLS_HANDSHAKE_CERTIFICATE_PKT:
41 return "Certificate packet";
42
43 case GNUTLS_HANDSHAKE_SERVER_KEY_EXCHANGE:
44 return "Server key exchange";
45
46 case GNUTLS_HANDSHAKE_CERTIFICATE_REQUEST:
47 return "Certificate request";
48
49 case GNUTLS_HANDSHAKE_SERVER_HELLO_DONE:
50 return "Server hello done";
51
52 case GNUTLS_HANDSHAKE_CERTIFICATE_VERIFY:
53 return "Certificate verify";
54
55 case GNUTLS_HANDSHAKE_CLIENT_KEY_EXCHANGE:
56 return "Client key exchange";
57
58 case GNUTLS_HANDSHAKE_FINISHED:
59 return "Finished";
60
61 case GNUTLS_HANDSHAKE_SUPPLEMENTAL:
62 return "Supplemental";
63 }
64 return NULL;
65}
66
67/* Connects to the peer and returns a socket
68 * descriptor.
69 */
70static int
71tcp_connect(void)
72{
73 const char *PORT = "443";
74 const char *SERVER = "69.58.181.89"; //verisign.com
75 int err, sd;
76 int flag = 1, curstate = 0;
77 struct sockaddr_in sa;
78
79 /* sets some fd options such as nonblock */
80 sd = socket(AF_INET, SOCK_STREAM, 0);
81 fcntl(sd, F_SETFL, O_NONBLOCK);
82 fcntl(sd, F_SETFD, FD_CLOEXEC);
83 setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (const void *)&curstate, sizeof(curstate));
84
85 setsockopt(sd, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(int));
86
87 memset(&sa, '\0', sizeof (sa));
88 sa.sin_family = AF_INET;
89 sa.sin_port = htons(atoi(PORT));
90 inet_pton(AF_INET, SERVER, &sa.sin_addr);
91
92 /* connects to server
93 */
94 err = connect(sd, (struct sockaddr *)&sa, sizeof (sa));
95 if ((err < 0) && (errno != EINPROGRESS))
96 {
97 print("Connect error\n");
98 exit(1);
99 }
100
101 return sd;
102}
103
104/* closes the given socket descriptor.
105 */
106static void
107tcp_close(int sd)
108{
109 shutdown(sd, SHUT_RDWR); /* no more receptions */
110 close(sd);
111}
112
113static Eina_Bool
114_process_data(gnutls_session_t client, Ecore_Fd_Handler *fd_handler)
115{
116 static int ret, lastret;
117 static unsigned int count = 0;
118
119 if (!done)
120 {
121 lastret = ret;
122 ret = gnutls_handshake(client);
123 count++;
124 if (gnutls_record_get_direction(client))
125 ecore_main_fd_handler_active_set(fd_handler, ECORE_FD_WRITE);
126 else
127 ecore_main_fd_handler_active_set(fd_handler, ECORE_FD_READ);
128 /* avoid printing messages infinity times */
129 if (lastret != ret)
130 {
131 print("gnutls returned with: %s - %s", gnutls_strerror_name(ret), gnutls_strerror(ret));
132 if ((ret == GNUTLS_E_WARNING_ALERT_RECEIVED) || (ret == GNUTLS_E_FATAL_ALERT_RECEIVED))
133 print("Also received alert: %s", gnutls_alert_get_name(gnutls_alert_get(client)));
134 print("last out: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_out(client)));
135 print("last in: %s", SSL_GNUTLS_PRINT_HANDSHAKE_STATUS(gnutls_handshake_get_last_in(client)));
136 }
137
138 if (gnutls_error_is_fatal(ret))
139 {
140 print("yarrr this be an error!");
141 exit(1);
142 }
143 }
144 if (ret == GNUTLS_E_SUCCESS)
145 {
146 done = 1;
147 print("Handshake successful in %u handshake calls!", count);
148 ecore_main_loop_quit();
149 }
150
151 return ECORE_CALLBACK_RENEW;
152}
153
154int
155main(void)
156{
157 /* credentials */
158 gnutls_anon_client_credentials_t c_anoncred;
159 gnutls_certificate_credentials_t c_certcred;
160
161 gnutls_session_t client;
162 int sd;
163
164 /* General init. */
165 gnutls_global_init();
166 ecore_init();
167 gnutls_global_set_log_function(tls_log_func);
168 gnutls_global_set_log_level(6);
169
170 /* Init client */
171 gnutls_anon_allocate_client_credentials(&c_anoncred);
172 gnutls_certificate_allocate_credentials(&c_certcred);
173 gnutls_init(&client, GNUTLS_CLIENT);
174 /* set very specific priorities */
175 gnutls_priority_set_direct(client, "NONE:%VERIFY_ALLOW_X509_V1_CA_CRT:+RSA:+DHE-RSA:+DHE-DSS:+ANON-DH:+COMP-DEFLATE:+COMP-NULL:+CTYPE-X509:+SHA1:+SHA256:+SHA384:+SHA512:+AES-256-CBC:+AES-128-CBC:+3DES-CBC:+VERS-TLS1.2:+VERS-TLS1.1:+VERS-TLS1.0:+VERS-SSL3.0", NULL);
176 gnutls_credentials_set(client, GNUTLS_CRD_ANON, c_anoncred);
177 gnutls_credentials_set(client, GNUTLS_CRD_CERTIFICATE, c_certcred);
178 gnutls_server_name_set(client, GNUTLS_NAME_DNS, "www.verisign.com", strlen("www.verisign.com"));
179
180 /* connect to the peer
181 */
182 sd = tcp_connect();
183
184 /* associate gnutls with socket */
185 gnutls_transport_set_ptr(client, (gnutls_transport_ptr_t)sd);
186 /* add a callback for data being available for send/receive on socket */
187 if (!ecore_main_fd_handler_add(sd, ECORE_FD_READ | ECORE_FD_WRITE, (Ecore_Fd_Cb)_process_data, client, NULL, NULL))
188 {
189 print("could not create fd handler!");
190 exit(1);
191 }
192 /* begin main loop */
193 ecore_main_loop_begin();
194
195 gnutls_bye(client, GNUTLS_SHUT_RDWR);
196
197 gnutls_deinit(client);
198
199 tcp_close(sd);
200
201 return 0;
202}
203
diff --git a/src/examples/ecore/ecore_file_download_example.c b/src/examples/ecore/ecore_file_download_example.c
new file mode 100644
index 0000000000..42cff6c32d
--- /dev/null
+++ b/src/examples/ecore/ecore_file_download_example.c
@@ -0,0 +1,86 @@
1#include <stdio.h>
2#include <Eina.h>
3#include <Ecore.h>
4#include <Ecore_File.h>
5
6/*
7 * ecore_file_download() example
8 *
9 * compile with:
10 * gcc ecore_file_download_example.c `pkg-config --libs --cflags ecore-file` \
11 * -o ecore_file_download_example
12 *
13 */
14
15#define URL "http://www.kernel.org/pub/linux/kernel/v1.0/linux-1.0.tar.gz"
16#define DST "linux-1.0.tar.gz"
17#define DST_MIME "[x-gzip]linux-1.0.tar.gz"
18
19void
20completion_cb(void *data, const char *file, int status)
21{
22 printf("Done (status: %d)\n", status);
23 ecore_main_loop_quit();
24}
25
26int
27progress_cb(void *data, const char *file,
28 long int dltotal, long int dlnow,
29 long int ultotal, long int ulnow)
30{
31 printf("Progress: %ld/%ld\n", dlnow, dltotal);
32 return ECORE_FILE_PROGRESS_CONTINUE; // continue the download
33}
34
35int
36main(void)
37{
38 double start;
39 Eina_Hash *headers;
40
41 eina_init();
42 ecore_init();
43 ecore_file_init();
44
45 if (ecore_file_exists(DST))
46 ecore_file_unlink(DST);
47
48 start = ecore_time_get();
49
50 if (ecore_file_download(URL, DST, completion_cb, progress_cb, NULL, NULL))
51 {
52 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST);
53 ecore_main_loop_begin();
54 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
55 printf("Downloaded %lld bytes\n", ecore_file_size(DST));
56 }
57 else
58 {
59 printf("Error, can't start download\n");
60 goto done;
61 }
62
63 headers = eina_hash_string_small_new(NULL);
64 eina_hash_add(headers, "Content-type", "application/x-gzip");
65
66 if (ecore_file_download_full(URL, DST_MIME, completion_cb, progress_cb, NULL, NULL, headers))
67 {
68 printf("Download started successfully:\n URL: %s\n DEST: %s\n", URL, DST_MIME);
69 ecore_main_loop_begin();
70 printf("\nTime elapsed: %f seconds\n", ecore_time_get() - start);
71 printf("Downloaded %lld bytes\n", ecore_file_size(DST));
72 }
73 else
74 {
75 printf("Error, can't start download\n");
76 goto done;
77 }
78
79done:
80 if (headers) eina_hash_free(headers);
81 ecore_file_shutdown();
82 ecore_shutdown();
83 eina_shutdown();
84 return 0;
85}
86
diff --git a/src/examples/ecore/ecore_idler_example.c b/src/examples/ecore/ecore_idler_example.c
new file mode 100644
index 0000000000..9db99cd6d4
--- /dev/null
+++ b/src/examples/ecore/ecore_idler_example.c
@@ -0,0 +1,117 @@
1#include <Ecore.h>
2#include <unistd.h>
3
4struct context // helper struct to give some context to the callbacks
5{
6 int count;
7 Ecore_Idle_Enterer *enterer;
8 Ecore_Idler *idler;
9 Ecore_Idle_Exiter *exiter;
10 Ecore_Event_Handler *handler;
11 Ecore_Timer *timer;
12};
13
14static int _event_type = 0; // a new type of event will be defined and stored here
15
16static Eina_Bool
17_enterer_cb(void *data) // the idle enterer callback
18{
19 printf("IDLE ENTERER: Ecore entering in idle state.\n");
20
21 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
22}
23
24static Eina_Bool
25_exiter_cb(void *data) // the idle exiter callback
26{
27 printf("IDLE EXITER: Ecore exiting idle state.\n");
28
29 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
30}
31
32static Eina_Bool
33_idler_cb(void *data) // the idler callback - ran while the mainloop is idle
34{
35 struct context *ctxt = data;
36 printf("IDLER: executing idler callback while in idle state.\n");
37
38 ctxt->count++;
39
40 /* each 10 times that the callback gets called, generate an event that
41 * will wake up the main loop, triggering idle enterers, exiters, etc. */
42 if ((ctxt->count % 10) == 0)
43 ecore_event_add(_event_type, NULL, NULL, NULL);
44
45 return ECORE_CALLBACK_RENEW; // same as EINA_TRUE
46}
47
48static Eina_Bool
49_event_handler_cb(void *data, int type, void *event) // event callback
50{
51 struct context *ctxt = data;
52
53 printf("EVENT: processing callback for the event received.\n");
54
55 if (ctxt->count > 100)
56 {
57 ecore_idle_enterer_del(ctxt->enterer);
58 ecore_idle_exiter_del(ctxt->exiter);
59// ecore_idler_del(ctxt->idler);
60 eo_unref(ctxt->idler);
61
62 ctxt->enterer = NULL;
63 ctxt->exiter = NULL;
64 ctxt->idler = NULL;
65
66 if (ctxt->timer)
67 {
68 ecore_timer_del(ctxt->timer);
69 ctxt->timer = NULL;
70 }
71
72 ecore_main_loop_quit();
73 }
74
75 return ECORE_CALLBACK_DONE; // same as EINA_FALSE
76}
77
78static Eina_Bool
79_timer_cb(void *data)
80{
81 struct context *ctxt = data;
82 printf("TIMER: timer callback called.\n");
83
84 if (ctxt->timer)
85 ctxt->timer = NULL;
86
87 return ECORE_CALLBACK_CANCEL; // same as EINA_FALSE
88}
89
90int
91main(int argc, char **argv)
92{
93 struct context ctxt = {0};
94
95 if (!ecore_init())
96 {
97 printf("ERROR: Cannot init Ecore!\n");
98 return -1;
99 }
100
101 _event_type = ecore_event_type_new();
102
103 ctxt.enterer = ecore_idle_enterer_add(_enterer_cb, &ctxt);
104 ctxt.exiter = ecore_idle_exiter_add(_exiter_cb, &ctxt);
105// ctxt.idler = ecore_idler_add(_idler_cb, &ctxt);
106 ctxt.idler = eo_add_custom(ECORE_IDLER_CLASS, NULL, ecore_idler_constructor(_idler_cb, &ctxt));
107 ctxt.handler = ecore_event_handler_add(_event_type,
108 _event_handler_cb,
109 &ctxt);
110 ctxt.timer = ecore_timer_add(0.0005, _timer_cb, &ctxt);
111
112 ecore_main_loop_begin();
113 ecore_shutdown();
114
115 return 0;
116}
117
diff --git a/src/examples/ecore/ecore_imf_example.c b/src/examples/ecore/ecore_imf_example.c
new file mode 100644
index 0000000000..0ca080e3b5
--- /dev/null
+++ b/src/examples/ecore/ecore_imf_example.c
@@ -0,0 +1,588 @@
1/**
2 * Ecore example illustrating how to use ecore imf.
3 *
4 * @verbatim
5 * gcc -o ecore_imf_example ecore_imf_example.c `pkg-config --cflags --libs ecore evas ecore-evas ecore-imf ecore-imf-evas`
6 * @endverbatim
7 */
8
9#include <Ecore.h>
10#include <Ecore_Evas.h>
11#include <Ecore_IMF.h>
12#include <Ecore_IMF_Evas.h>
13#include <Evas.h>
14#include <stdio.h>
15
16typedef struct _Entry Entry;
17
18struct _Entry
19{
20 Evas_Object *rect;
21 Evas_Object *txt_obj;
22 Evas_Textblock_Style *txt_style;
23 Evas_Textblock_Cursor *cursor;
24 Evas_Textblock_Cursor *preedit_start;
25 Evas_Textblock_Cursor *preedit_end;
26 Ecore_IMF_Context *imf_context;
27 Eina_Bool have_preedit : 1;
28};
29
30static void
31_mouse_up_cb(void *data, Evas *e, Evas_Object *o, void *event_info)
32{
33 Entry *en = data;
34 if (!en) return;
35
36 if (en->imf_context)
37 ecore_imf_context_reset(en->imf_context);
38
39 evas_object_focus_set(en->rect, EINA_TRUE);
40}
41
42static void
43_entry_focus_in_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
44{
45 Entry *en = data;
46 if (!en) return;
47
48 if (en->imf_context)
49 ecore_imf_context_focus_in(en->imf_context);
50}
51
52static void
53_entry_focus_out_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
54{
55 Entry *en = data;
56 if (!en) return;
57
58 if (en->imf_context)
59 {
60 ecore_imf_context_reset(en->imf_context);
61 ecore_imf_context_focus_out(en->imf_context);
62 }
63}
64
65static void
66_canvas_focus_in_cb(void *data, Evas *e, void *event_info)
67{
68 Entry *en;
69 Evas_Object *obj = evas_focus_get(e);
70 if (!obj) return;
71
72 en = evas_object_data_get(obj, "Entry");
73 if (en)
74 _entry_focus_in_cb(en, NULL, NULL, NULL);
75}
76
77static void
78_canvas_focus_out_cb(void *data, Evas *e, void *event_info)
79{
80 Entry *en;
81 Evas_Object *obj = evas_focus_get(e);
82 if (!obj) return;
83
84 en = evas_object_data_get(obj, "Entry");
85 if (en)
86 _entry_focus_out_cb(en, NULL, NULL, NULL);
87}
88
89static void
90_imf_cursor_info_set(Entry *en)
91{
92 Evas_Coord x, y, w, h;
93 Evas_Coord cx, cy, cw, ch; // cursor geometry
94 int cursor_pos; // cursor position in chars (Not bytes)
95
96 if (!en) return;
97
98 // get cursor geometry
99 evas_object_geometry_get(en->txt_obj, &x, &y, &w, &h);
100 evas_textblock_cursor_geometry_get(en->cursor, &cx, &cy, &cw, &ch, NULL, EVAS_TEXTBLOCK_CURSOR_BEFORE);
101
102 // get cursor position
103 cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
104
105 ecore_imf_context_cursor_position_set(en->imf_context, cursor_pos);
106 ecore_imf_context_cursor_location_set(en->imf_context, x + cx, y + cy, cw, ch);
107}
108
109static void
110_preedit_del(Entry *en)
111{
112 if (!en || !en->have_preedit) return;
113 if (!en->preedit_start || !en->preedit_end) return;
114 if (!evas_textblock_cursor_compare(en->preedit_start, en->preedit_end)) return;
115
116 /* delete the preedit characters */
117 evas_textblock_cursor_range_delete(en->preedit_start, en->preedit_end);
118}
119
120static void
121_preedit_clear(Entry *en)
122{
123 if (en->preedit_start)
124 {
125 evas_textblock_cursor_free(en->preedit_start);
126 en->preedit_start = NULL;
127 }
128
129 if (en->preedit_end)
130 {
131 evas_textblock_cursor_free(en->preedit_end);
132 en->preedit_end = NULL;
133 }
134
135 en->have_preedit = EINA_FALSE;
136}
137
138static Eina_Bool
139_ecore_imf_retrieve_surrounding_cb(void *data, Ecore_IMF_Context *ctx, char **text, int *cursor_pos)
140{
141 /* This callback will be called when the Input Method Context module requests the surrounding context. */
142 Entry *en = data;
143 const char *str;
144
145 if (!en) return;
146
147 str = evas_object_textblock_text_markup_get(en->txt_obj);
148
149 if (text)
150 *text = str ? strdup(str) : strdup("");
151
152 /* get the current position of cursor */
153 if (cursor_pos)
154 *cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
155
156 return EINA_TRUE;
157}
158
159static void
160_ecore_imf_event_delete_surrounding_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
161{
162 /* called when the input method needs to delete all or part of the context surrounding the cursor */
163 Entry *en = data;
164 Ecore_IMF_Event_Delete_Surrounding *ev = event_info;
165 Evas_Textblock_Cursor *del_start, *del_end;
166 int cursor_pos;
167
168 if (!en) return;
169
170 cursor_pos = evas_textblock_cursor_pos_get(en->cursor);
171
172 del_start = evas_object_textblock_cursor_new(en->txt_obj);
173 evas_textblock_cursor_pos_set(del_start, cursor_pos + ev->offset);
174
175 del_end = evas_object_textblock_cursor_new(en->txt_obj);
176 evas_textblock_cursor_pos_set(del_end, cursor_pos + ev->offset + ev->n_chars);
177
178 /* implement function to delete character(s) from 'cursor_pos+ev->offset' cursor position to 'cursor_pos + ev->offset + ev->n_chars' */
179 evas_textblock_cursor_range_delete(del_start, del_end);
180
181 evas_textblock_cursor_free(del_start);
182 evas_textblock_cursor_free(del_end);
183}
184
185static void
186_ecore_imf_event_commit_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
187{
188 Entry *en = data;
189 char *commit_str = (char *)event_info;
190 if (!en) return;
191
192 /* delete preedit string */
193 _preedit_del(en);
194 _preedit_clear(en);
195
196 printf("commit string : %s\n", commit_str);
197
198 evas_object_textblock_text_markup_prepend(en->cursor, commit_str);
199
200 /* notify cursor information */
201 _imf_cursor_info_set(en);
202
203 return;
204}
205
206static void
207_ecore_imf_event_preedit_changed_cb(void *data, Ecore_IMF_Context *ctx, void *event_info)
208{
209 /* example how to get preedit string */
210 Entry *en = data;
211 char *preedit_string;
212 int cursor_pos;
213 Eina_List *attrs = NULL;
214 Eina_List *l;
215 Ecore_IMF_Preedit_Attr *attr;
216 Ecore_IMF_Context *imf_context = ctx;
217 int preedit_start_pos, preedit_end_pos;
218 int i;
219 Eina_Bool preedit_end_state = EINA_FALSE;
220
221 if (!en) return;
222
223 /* get preedit string, attributes */
224 ecore_imf_context_preedit_string_with_attributes_get(imf_context, &preedit_string, &attrs, &cursor_pos);
225 printf("preedit string : %s\n", preedit_string);
226
227 if (!strcmp(preedit_string, ""))
228 preedit_end_state = EINA_TRUE;
229
230 /* delete preedit */
231 _preedit_del(en);
232
233 preedit_start_pos = evas_textblock_cursor_pos_get(en->cursor);
234
235 /* insert preedit character(s) */
236 if (strlen(preedit_string) > 0)
237 {
238 if (attrs)
239 {
240 EINA_LIST_FOREACH(attrs, l, attr)
241 {
242 if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB1) // style type
243 {
244 /* apply appropriate style such as underline */
245 }
246 else if (attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB2 || attr->preedit_type == ECORE_IMF_PREEDIT_TYPE_SUB3)
247 {
248 /* apply appropriate style such as underline */
249 }
250 }
251
252 /* insert code to display preedit string in your editor */
253 evas_object_textblock_text_markup_prepend(en->cursor, preedit_string);
254 }
255 }
256
257 if (!preedit_end_state)
258 {
259 /* set preedit start cursor */
260 if (!en->preedit_start)
261 en->preedit_start = evas_object_textblock_cursor_new(en->txt_obj);
262 evas_textblock_cursor_copy(en->cursor, en->preedit_start);
263
264 /* set preedit end cursor */
265 if (!en->preedit_end)
266 en->preedit_end = evas_object_textblock_cursor_new(en->txt_obj);
267 evas_textblock_cursor_copy(en->cursor, en->preedit_end);
268
269 preedit_end_pos = evas_textblock_cursor_pos_get(en->cursor);
270
271 for (i = 0; i < (preedit_end_pos - preedit_start_pos); i++)
272 {
273 evas_textblock_cursor_char_prev(en->preedit_start);
274 }
275
276 en->have_preedit = EINA_TRUE;
277
278 /* set cursor position */
279 evas_textblock_cursor_pos_set(en->cursor, preedit_start_pos + cursor_pos);
280 }
281
282 /* notify cursor information */
283 _imf_cursor_info_set(en);
284
285 EINA_LIST_FREE(attrs, attr)
286 free(attr);
287
288 free(preedit_string);
289}
290
291static void
292_key_down_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
293{
294 Entry *en = data;
295 Evas_Event_Key_Down *ev = event_info;
296 Eina_Bool control, alt, shift;
297 Eina_Bool multiline;
298 Eina_Bool cursor_changed;
299 if (!en) return;
300 if (!ev->key) return;
301
302 if (en->imf_context)
303 {
304 Ecore_IMF_Event_Key_Down ecore_ev;
305 ecore_imf_evas_event_key_down_wrap(ev, &ecore_ev);
306 if (ecore_imf_context_filter_event(en->imf_context,
307 ECORE_IMF_EVENT_KEY_DOWN,
308 (Ecore_IMF_Event *)&ecore_ev))
309 return;
310 }
311
312 control = evas_key_modifier_is_set(ev->modifiers, "Control");
313 alt = evas_key_modifier_is_set(ev->modifiers, "Alt");
314 shift = evas_key_modifier_is_set(ev->modifiers, "Shift");
315
316 if ((!strcmp(ev->keyname, "Escape")) ||
317 (!strcmp(ev->keyname, "Return")) || (!strcmp(ev->keyname, "KP_Enter")))
318 ecore_imf_context_reset(en->imf_context);
319
320 if (!strcmp(ev->key, "BackSpace"))
321 {
322 if (evas_textblock_cursor_char_prev(en->cursor))
323 {
324 evas_textblock_cursor_char_delete(en->cursor);
325 /* notify cursor information */
326 _imf_cursor_info_set(en);
327 }
328 return;
329 }
330 else if (!strcmp(ev->key, "Delete") ||
331 (!strcmp(ev->key, "KP_Delete") && !ev->string))
332 {
333 // FILLME
334 }
335 else if ((control) && (!strcmp(ev->key, "v")))
336 {
337 // ctrl + v
338 // FILLME
339 }
340 else if ((control) && (!strcmp(ev->key, "a")))
341 {
342 // ctrl + a
343 // FILLME
344 }
345 else if ((control) && (!strcmp(ev->key, "A")))
346 {
347 // ctrl + A
348 // FILLME
349 }
350 else if ((control) && ((!strcmp(ev->key, "c") || (!strcmp(ev->key, "Insert")))))
351 {
352 // ctrl + c
353 // FILLME
354 }
355 else if ((control) && ((!strcmp(ev->key, "x") || (!strcmp(ev->key, "m")))))
356 {
357 // ctrl + x
358 // FILLME
359 }
360 else if ((control) && (!strcmp(ev->key, "z")))
361 {
362 // ctrl + z (undo)
363 // FILLME
364 }
365 else if ((control) && (!strcmp(ev->key, "y")))
366 {
367 // ctrl + y (redo)
368 // FILLME
369 }
370 else if ((!strcmp(ev->key, "Return")) || (!strcmp(ev->key, "KP_Enter")))
371 {
372 // FILLME
373 }
374 else
375 {
376 if (ev->string)
377 {
378 printf("key down string : %s\n", ev->string);
379 evas_object_textblock_text_markup_prepend(en->cursor, ev->string);
380 }
381 }
382
383 /* notify cursor information */
384 _imf_cursor_info_set(en);
385}
386
387static void
388_key_up_cb(void *data, Evas *e, Evas_Object *obj, void *event_info)
389{
390 Entry *en = data;
391 Evas_Event_Key_Up *ev = event_info;
392
393 if (!en) return;
394
395 if (en->imf_context)
396 {
397 Ecore_IMF_Event_Key_Up ecore_ev;
398
399 ecore_imf_evas_event_key_up_wrap(ev, &ecore_ev);
400 if (ecore_imf_context_filter_event(en->imf_context,
401 ECORE_IMF_EVENT_KEY_UP,
402 (Ecore_IMF_Event *)&ecore_ev))
403 return;
404 }
405}
406
407static void
408create_input_field(Evas *evas, Entry *en, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
409{
410 if (!en) return;
411
412 /* create background for text input field */
413 en->rect = evas_object_rectangle_add(evas);
414 evas_object_color_set(en->rect, 150, 150, 150, 255); /* gray */
415 evas_object_move(en->rect, x, y);
416 evas_object_resize(en->rect, w, h);
417 evas_object_show(en->rect);
418 evas_object_data_set(en->rect, "Entry", en);
419
420 /* create text object for displaying text */
421 en->txt_obj = evas_object_textblock_add(evas);
422 evas_object_color_set(en->txt_obj, 0, 0, 0, 255);
423 evas_object_pass_events_set(en->txt_obj, EINA_TRUE);
424 evas_object_move(en->txt_obj, x, y);
425 evas_object_resize(en->txt_obj, w, h);
426 evas_object_show(en->txt_obj);
427
428 /* set style on textblock */
429 static const char *style_buf =
430 "DEFAULT='font=Sans font_size=30 color=#000 text_class=entry'"
431 "newline='br'"
432 "b='+ font=Sans:style=bold'";
433 en->txt_style = evas_textblock_style_new();
434 evas_textblock_style_set(en->txt_style, style_buf);
435 evas_object_textblock_style_set(en->txt_obj, en->txt_style);
436
437 /* create cursor */
438 en->cursor = evas_object_textblock_cursor_new(en->txt_obj);
439
440 /* create input context */
441 const char *default_id = ecore_imf_context_default_id_get();
442 if (!default_id)
443 return;
444
445 en->imf_context = ecore_imf_context_add(default_id);
446 ecore_imf_context_client_window_set(en->imf_context, (void *)ecore_evas_window_get(ecore_evas_ecore_evas_get(evas)));
447 ecore_imf_context_client_canvas_set(en->imf_context, evas);
448
449 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_DOWN, _key_down_cb, en);
450 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_KEY_UP, _key_up_cb, en);
451 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_MOUSE_UP, _mouse_up_cb, en);
452 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_IN, _entry_focus_in_cb, en);
453 evas_object_event_callback_add(en->rect, EVAS_CALLBACK_FOCUS_OUT, _entry_focus_out_cb, en);
454
455 en->have_preedit = EINA_FALSE;
456 en->preedit_start = NULL;
457 en->preedit_end = NULL;
458
459 /* register retrieve surrounding callback */
460 ecore_imf_context_retrieve_surrounding_callback_set(en->imf_context, _ecore_imf_retrieve_surrounding_cb, en);
461
462 /* register commit event callback */
463 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_COMMIT, _ecore_imf_event_commit_cb, en);
464
465 /* register preedit changed event handler */
466 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_PREEDIT_CHANGED, _ecore_imf_event_preedit_changed_cb, en);
467
468 /* register surrounding delete event callback */
469 ecore_imf_context_event_callback_add(en->imf_context, ECORE_IMF_CALLBACK_DELETE_SURROUNDING, _ecore_imf_event_delete_surrounding_cb, en);
470}
471
472static void
473delete_input_field(Entry *en)
474{
475 if (!en) return;
476
477 if (en->rect)
478 {
479 evas_object_del(en->rect);
480 en->rect = NULL;
481 }
482
483 if (en->cursor)
484 {
485 evas_textblock_cursor_free(en->cursor);
486 en->cursor = NULL;
487 }
488
489 if (en->preedit_start)
490 {
491 evas_textblock_cursor_free(en->preedit_start);
492 en->preedit_start = NULL;
493 }
494
495 if (en->preedit_end)
496 {
497 evas_textblock_cursor_free(en->preedit_end);
498 en->preedit_end = NULL;
499 }
500
501 if (en->txt_obj)
502 {
503 evas_object_del(en->txt_obj);
504 en->txt_obj = NULL;
505 }
506
507 if (en->txt_style)
508 {