elementary: add eio test with a genlist
authorMichael BOUCHAUD <michael.bouchaud@gmail.com>
Wed, 25 May 2011 19:08:38 +0000 (19:08 +0000)
committerMichael BOUCHAUD <michael.bouchaud@gmail.com>
Wed, 25 May 2011 19:08:38 +0000 (19:08 +0000)
SVN revision: 59675

configure.ac
src/bin/Makefile.am
src/bin/test.c
src/bin/test_eio.c [new file with mode: 0644]

index 1bed7eb..1f05909 100644 (file)
@@ -212,6 +212,10 @@ PKG_CHECK_MODULES([ELEMENTARY],
    ]
 )
 
+PKG_CHECK_MODULES([EIO],[eio], [have_eio="yes"], [have_eio="no"])
+
+AM_CONDITIONAL([HAVE_EIO], [test "x${have_eio}" = "xyes"])
+
 requirement_elm="edje >= 1.0.0 ecore-file >= 1.0.0 ecore-evas >= 1.0.0 ecore >= 1.0.0 evas >= 1.0.0 eet >= 1.4.0 eina >= 1.0.0 ${requirement_elm}"
 
 have_elementary_x="no"
@@ -551,6 +555,7 @@ echo "    EFreet.................: ${have_elementary_efreet}"
 echo "    EWeather...............: ${have_elementary_eweather}"
 echo "    Ethumb.................: ${have_elementary_ethumb}"
 echo "    Quick Launch...........: ${have_fork}"
+echo "    eio....................: ${have_eio}"
 echo
 echo "  eet......................: ${eet_eet}"
 echo "  edje_cc..................: ${edje_cc}"
index b6cfd5e..e72788c 100644 (file)
@@ -19,6 +19,10 @@ AM_CPPFLAGS = \
 @ELEMENTARY_EWEATHER_CFLAGS@ \
 @ELEMENTARY_ETHUMB_CFLAGS@
 
+if HAVE_EIO
+AM_CPPFLAGS += -DHAVE_EIO @EIO_CFLAGS@
+endif
+
 if ELEMENTARY_WINDOWS_BUILD
 AM_CPPFLAGS += -DELEMENTARY_BUILD
 endif
@@ -101,12 +105,19 @@ test_win_state.c \
 test_grid.c \
 test_flip_page.c
 
+if HAVE_EIO
+elementary_test_SOURCES += test_eio.c
+endif
+
 elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la \
        @ELEMENTARY_EWEATHER_LIBS@ \
        @ELEMENTARY_EDBUS_LIBS@ \
        @ELEMENTARY_EFREET_LIBS@ \
        @ELEMENTARY_LIBS@ \
        @my_libs@
+if HAVE_EIO
+elementary_test_LDADD += @EIO_LIBS@
+endif
 elementary_test_LDFLAGS =
 
 elementary_config_SOURCES = \
@@ -155,6 +166,11 @@ elementary_testql_LDADD = $(top_builddir)/src/lib/libelementary.la \
        @ELEMENTARY_EFREET_LIBS@ \
        @ELEMENTARY_LIBS@ \
        @my_libs@
+
+if HAVE_EIO
+elementary_testql_LDADD += @EIO_LIBS@
+endif
+
 elementary_testql_CFLAGS = -DELM_LIB_QUICKLAUNCH=1
 elementary_testql_LDFLAGS =
 endif
index ebeb2e0..a352cba 100644 (file)
@@ -129,6 +129,9 @@ void test_segment_control(void *data, Evas_Object *obj, void *event_info);
 void test_store(void *data, Evas_Object *obj, void *event_info);
 void test_win_inline(void *data, Evas_Object *obj, void *event_info);
 void test_grid(void *data, Evas_Object *obj, void *event_info);
+#ifdef HAVE_EIO
+void test_eio(void *data, Evas_Object *obj, void *event_info);
+#endif
 
 struct elm_test
 {
@@ -330,6 +333,9 @@ my_win_main(char *autorun)
    ADD_TEST("Genlist Group", test_genlist8);
    ADD_TEST("Genlist Group Tree", test_genlist9);
    ADD_TEST("Genlist Mode", test_genlist10);
+#ifdef HAVE_EIO
+   ADD_TEST("Genlist Eio", test_eio);
+#endif
    ADD_TEST("GenGrid", test_gengrid);
    ADD_TEST("GenGrid 2", test_gengrid2);
    ADD_TEST("Checks", test_check);
diff --git a/src/bin/test_eio.c b/src/bin/test_eio.c
new file mode 100644 (file)
index 0000000..89cd2bb
--- /dev/null
@@ -0,0 +1,171 @@
+#include <Elementary.h>
+#ifdef HAVE_CONFIG_H
+# include "elementary_config.h"
+#endif
+#include <Eio.h>
+#include <sys/times.h>
+
+#ifndef ELM_LIB_QUICKLAUNCH
+
+static Elm_Genlist_Item_Class it_eio;
+
+static clock_t st_time;
+static clock_t en_time;
+static struct tms st_cpu;
+static struct tms en_cpu;
+
+
+static void
+_sel_file(void *data, Evas_Object *obj, void *event_info)
+{
+}
+
+static Eina_Bool
+_ls_filter_cb(void *data, Eio_File *handler, const char *file)
+{
+  return EINA_TRUE;
+}
+
+static void
+_ls_main_cb(void *data, Eio_File *handler, const char *file)
+{
+   elm_genlist_item_sorted_insert(data,
+                                  &it_eio,
+                                  eina_stringshare_add(file),
+                                  NULL,
+                                  ELM_GENLIST_ITEM_NONE,
+                                  (Eina_Compare_Cb) strcmp,
+                                  _sel_file,
+                                  NULL);
+}
+
+void
+_ls_done_cb(void *data, Eio_File *handler)
+{
+   en_time = times(&en_cpu);
+   fprintf(stderr, "ls done\n");
+   fprintf(stderr, "Real Time: %.jd, User Time: %.jd, System Time: %.jd\n",
+           en_time - st_time,
+           en_cpu.tms_utime - st_cpu.tms_utime,
+           en_cpu.tms_stime - st_cpu.tms_stime);
+}
+
+void
+_ls_error_cb(void *data, Eio_File *handler, int error)
+{
+   fprintf(stderr, "error: [%s]\n", strerror(error));
+}
+
+static void
+_file_chosen(void            *data,
+             Evas_Object *obj __UNUSED__,
+             void            *event_info)
+{
+   const char *file = event_info;
+   if (file)
+     {
+        st_time = times(&st_cpu);
+        eio_file_ls(file,
+                    _ls_filter_cb,
+                    _ls_main_cb,
+                    _ls_done_cb,
+                    _ls_error_cb,
+                    data);
+     }
+}
+
+static char *
+_gl_label_get(void *data, Evas_Object *obj, const char *part)
+{
+   char buf[PATH_MAX];
+   snprintf(buf, sizeof(buf), "Item # %s", (char*)data);
+   return strdup(buf);
+}
+
+static Evas_Object *
+_gl_icon_get(void *data, Evas_Object *obj, const char *part)
+{
+}
+
+static Eina_Bool
+_gl_state_get(void *data , Evas_Object *obj, const char *part)
+{
+   return EINA_FALSE;
+}
+
+static void
+_gl_del(void *data, Evas_Object *obj)
+{
+}
+
+static void
+_test_eio_clear(void *data, Evas_Object *obj, void *event)
+{
+   elm_genlist_clear(data);
+}
+
+void
+test_eio(void *data       __UNUSED__,
+                         Evas_Object *obj __UNUSED__,
+                         void *event_info __UNUSED__)
+{
+   Evas_Object *win, *bg, *vbox, *hbox, *ic, *bt, *fs_bt, *en, *lb, *gl;
+
+   it_eio.item_style     = "default";
+   it_eio.func.label_get = _gl_label_get;
+   it_eio.func.icon_get  = _gl_icon_get;
+   it_eio.func.state_get = _gl_state_get;
+   it_eio.func.del       = _gl_del;
+
+   win = elm_win_add(NULL, "fileselector-button", ELM_WIN_BASIC);
+   elm_win_title_set(win, "File Selector Button");
+   elm_win_autodel_set(win, 1);
+
+   bg = elm_bg_add(win);
+   elm_win_resize_object_add(win, bg);
+   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(bg);
+
+   vbox = elm_box_add(win);
+   elm_win_resize_object_add(win, vbox);
+   evas_object_size_hint_weight_set(vbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_show(vbox);
+
+   gl = elm_genlist_add(win);
+   evas_object_size_hint_weight_set(gl, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
+   evas_object_size_hint_align_set(gl, EVAS_HINT_FILL, EVAS_HINT_FILL);
+   elm_box_pack_end(vbox, gl);
+   evas_object_show(gl);
+
+   /* file selector button */
+   hbox = elm_box_add(win);
+   elm_box_horizontal_set(hbox, EINA_TRUE);
+   ic = elm_icon_add(win);
+   elm_icon_standard_set(ic, "file");
+   evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
+   fs_bt = elm_fileselector_button_add(win);
+   elm_fileselector_button_label_set(fs_bt, "Select a dir");
+   elm_fileselector_button_icon_set(fs_bt, ic);
+   elm_fileselector_button_inwin_mode_set(fs_bt, EINA_TRUE);
+   elm_fileselector_button_folder_only_set(fs_bt, EINA_TRUE);
+
+   elm_box_pack_end(hbox, fs_bt);
+   elm_box_pack_end(vbox, hbox);
+   evas_object_show(fs_bt);
+   evas_object_show(ic);
+
+   /* attribute setting buttons */
+   bt = elm_button_add(win);
+   elm_button_label_set(bt, "clear");
+   evas_object_smart_callback_add(bt, "clicked", _test_eio_clear, gl);
+   elm_box_pack_end(hbox, bt);
+   evas_object_show(bt);
+   evas_object_show(hbox);
+
+   evas_object_smart_callback_add(fs_bt, "file,chosen", _file_chosen, gl);
+
+   evas_object_resize(win, 300, 500);
+   evas_object_show(win);
+}
+
+#endif