|
From: <do...@us...> - 2009-01-28 08:07:20
|
Revision: 541
http://enna.svn.sourceforge.net/enna/?rev=541&view=rev
Author: doursse
Date: 2009-01-28 08:07:13 +0000 (Wed, 28 Jan 2009)
Log Message:
-----------
* factorize a bit the code (move walle init and set up to its own file)
* remove deletion of evas objects (useless, evas deletes them automatically)
Modified Paths:
--------------
trunk/wall-e/src/bin/Makefile.am
trunk/wall-e/src/bin/main.c
trunk/wall-e/src/bin/wall-e.h
Added Paths:
-----------
trunk/wall-e/src/bin/walle.c
Modified: trunk/wall-e/src/bin/Makefile.am
===================================================================
--- trunk/wall-e/src/bin/Makefile.am 2009-01-27 18:00:28 UTC (rev 540)
+++ trunk/wall-e/src/bin/Makefile.am 2009-01-28 08:07:13 UTC (rev 541)
@@ -4,7 +4,8 @@
wall_e_SOURCES = \
main.c \
-wall.c
+wall.c \
+walle.c
wall_e_CPPFLAGS = \
-I$(top_srcdir) \
Modified: trunk/wall-e/src/bin/main.c
===================================================================
--- trunk/wall-e/src/bin/main.c 2009-01-27 18:00:28 UTC (rev 540)
+++ trunk/wall-e/src/bin/main.c 2009-01-28 08:07:13 UTC (rev 541)
@@ -7,9 +7,8 @@
#include <string.h>
#include <Ecore.h>
-#include <Ecore_Data.h>
-#include <Ecore_File.h>
#include <Ecore_Evas.h>
+#include <Ecore_File.h>
#include <Edje.h>
#include <Elementary.h>
@@ -17,151 +16,25 @@
#include "wall-e.h"
#include "wall.h"
-static const Ecore_Getopt options = {
- "wall-e",
- "%prog [options]",
- "0.1.0",
- "(C) 2008 Enlightenment",
- "BSD\nThis is a 3 clause bsd bla bla",
- "a simple image viewer using enlightenment foundation libraries.\n"
- "Here is the text of the licence",
- 1,
- {
- ECORE_GETOPT_STORE_STR('e', "engine", "ecore-evas engine to use"),
- ECORE_GETOPT_CALLBACK_NOARGS('E', "list-engines", "list ecore-evas engines",
- ecore_getopt_callback_ecore_evas_list_engines, NULL),
- ECORE_GETOPT_STORE_DEF_BOOL('F', "fullscreen", "fullscreen mode", 0),
- ECORE_GETOPT_CALLBACK_ARGS('g', "geometry", "geometry to use in x:y:w:h form.", "X:Y:W:H",
- ecore_getopt_callback_geometry_parse, NULL),
- ECORE_GETOPT_STORE_STR('p', "path", "path to read the image files from"),
- ECORE_GETOPT_STORE_STR('t', "theme", "path to read the theme file from"),
- ECORE_GETOPT_STORE_INT('f', "fps", "frame per second"),
- ECORE_GETOPT_STORE_INT('l', "lines", "Number of lines to display"),
- ECORE_GETOPT_COUNT('v', "verbose", "be more verbose"),
- ECORE_GETOPT_VERSION('V', "version"),
- ECORE_GETOPT_COPYRIGHT('R', "copyright"),
- ECORE_GETOPT_LICENSE('L', "license"),
- ECORE_GETOPT_HELP('h', "help"),
- ECORE_GETOPT_SENTINEL
- }
-};
-
-static void _walle_win_del_cb(void *data, Evas_Object *obj, void *event_info)
-{
- elm_exit();
-}
-
static void _walle_wall_changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *einfo)
{
Walle *walle;
- Evas_Coord x,y,w,h;
+ Evas_Coord w,h;
walle = data;
evas_object_geometry_get(walle->o_wall, NULL, NULL, NULL, &h);
evas_object_size_hint_min_get(walle->o_wall, &w, NULL);
evas_object_resize(walle->o_wall, w, h);
- }
-
-static void _walle_picture_cb_resize(void *data, Evas *e, Evas_Object *obj, void *einfo)
-{
- Evas_Coord w = 0, h = 0;
- Evas_Object *o_pict = data;
- /* callback when a picture is resized */
- evas_object_geometry_get(o_pict, NULL, NULL, &w, &h);
- evas_object_image_fill_set(o_pict, 0, 0, w, h);
-
}
-static void _populate_wall(Walle *walle, const char *directory, const char *theme)
-{
- Evas_Object *o;
- Evas_Coord ow, oh, w, h;
- Ecore_List *files = NULL;
- char *file = NULL;
- char filename[4096];
-
- if (!ecore_file_is_dir(directory) && ecore_file_dir_is_empty(directory))
- return;
- files = ecore_file_ls(directory);
- if (!files)
- return;
- ecore_list_sort(files, ECORE_COMPARE_CB(strcasecmp), ECORE_SORT_MIN);
- file = ecore_list_first_goto(files);
- while ((file = (char *)ecore_list_next(files)) != NULL)
- {
-
- sprintf(filename, "%s/%s", directory, file);
- o = evas_object_image_add(walle->evas);
- evas_object_image_file_set(o, filename, NULL);
- switch(evas_object_image_load_error_get(o))
- {
- case EVAS_LOAD_ERROR_NONE:
- {
- evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _walle_picture_cb_resize, o);
- evas_object_image_size_get(o, &w, &h);
- oh = 200;
- ow = oh * (float)w/(float)h;
- evas_object_image_load_size_set(o, ow, oh);
- evas_object_image_fill_set(o, 0, 0, ow, oh);
- evas_object_resize(o, ow, oh);
- evas_object_size_hint_min_set(o, ow, oh);
- walle_wall_append(walle->o_wall, o);
- walle->pictures = eina_list_append(walle->pictures, o);
- }
- break;
- default:
- evas_object_del(o);
- break;
-
- }
-
- }
- ecore_list_destroy(files);
-}
-
int
main(int argc, char *argv[])
{
- Eina_Rectangle geometry = {0, 0, 0, 0};
- Eina_List *l;
- Walle *walle = NULL;
- Evas_Object *o;
- char *engine = NULL;
- char *path = NULL;
- char *theme = NULL;
- int fps = 0;
- int lines = 2;
- int verbose = 0;
- unsigned char engines_listed = 0;
- unsigned char is_fullscreen = 0;
- unsigned char help = 0;
- int args;
- int i;
- Evas_Coord x,y,w,h;
- Ecore_Getopt_Value values[] = {
- ECORE_GETOPT_VALUE_STR(engine),
- ECORE_GETOPT_VALUE_BOOL(engines_listed),
- ECORE_GETOPT_VALUE_BOOL(is_fullscreen),
- ECORE_GETOPT_VALUE_PTR_CAST(geometry),
- ECORE_GETOPT_VALUE_STR(path),
- ECORE_GETOPT_VALUE_STR(theme),
- ECORE_GETOPT_VALUE_INT(fps),
- ECORE_GETOPT_VALUE_INT(lines),
- ECORE_GETOPT_VALUE_INT(verbose),
- ECORE_GETOPT_VALUE_NONE,
- ECORE_GETOPT_VALUE_NONE,
- ECORE_GETOPT_VALUE_NONE,
- ECORE_GETOPT_VALUE_BOOL(help),
- ECORE_GETOPT_VALUE_NONE
- };
+ Walle *walle;
- walle = (Walle*)calloc(1, sizeof(Walle));
- if (!walle)
- return EXIT_FAILURE;
-
if (!ecore_evas_init())
- goto free_walle;
+ return EXIT_FAILURE;
if (!ecore_file_init())
goto shutdown_ecore_evas;
@@ -171,149 +44,33 @@
elm_init(argc, argv);
+ walle = walle_init(argc, argv);
+ if (!walle)
+ goto shutdown_elm;
- ecore_app_args_set(argc, (const char **)argv);
+ if (!walle_gui_set(walle))
+ goto shutdown_walle;
- args = ecore_getopt_parse(&options, values, argc, argv);
- if (args < 0)
- {
- fputs("ERROR: could not parse options.\n", stderr);
- goto shutdown_edje;
- }
-
- if (help)
- goto shutdown_edje;
-
- if (engines_listed)
- goto shutdown_edje;
-
- if (is_fullscreen &&
- ((geometry.x != 0) ||
- (geometry.y != 0) ||
- (geometry.w != 0) ||
- (geometry.h != 0)))
- {
- fputs("ERROR: could not set fulllscreen and geometry at same time.\n", stderr);
- goto shutdown_edje;
- }
-
- if (!is_fullscreen &&
- (geometry.x == 0) &&
- (geometry.y == 0) &&
- (geometry.w == 0) &&
- (geometry.h == 0))
- {
- geometry.w = 640;
- geometry.h = 480;
- }
-
- if (!path)
- goto shutdown_edje;
-
- if (!theme)
- {
- theme = getenv("WALLE_THEME");
- if (!theme)
- theme = PACKAGE_DATA_DIR "/data/default.edj";
- }
-
- if (fps != 0)
- ecore_animator_frametime_set(1.0 / (double)fps);
-
- walle->app_w = geometry.w;
- walle->app_h = geometry.h;
-
- walle->o_win = elm_win_add(NULL, "Wall-E", ELM_WIN_BASIC);
- /* Retrieve Evas frome Main Window */
- walle->evas = evas_object_evas_get(walle->o_win);
-
- /* Set Delete window callbak */
- evas_object_smart_callback_add(walle->o_win, "delete-request", _walle_win_del_cb, NULL);
- /* Set Window Title */
- elm_win_title_set(walle->o_win, "Wall-E");
-
-
- /* Create main edje object */
- o = edje_object_add(walle->evas);
- edje_object_file_set(o, theme, "wall-e");
- evas_object_show(o);
- evas_object_size_hint_weight_set(o, 1.0, 1.0);
- walle->o_edje = o;
-
-
- /* Resize win with app_w et app_h */
- elm_win_resize_object_add(walle->o_win, walle->o_edje);
- evas_object_resize(walle->o_edje, walle->app_w, walle->app_h);
-
-
- o = elm_scroller_add(walle->o_win);
- evas_object_show(o);
- edje_object_part_swallow(walle->o_edje, "walle.swallow.content", o);
- walle->o_scroll = o;
-
- o = elm_toolbar_add(walle->o_win);
- evas_object_size_hint_weight_set(o, 0.0, 0.0);
- evas_object_size_hint_align_set(o, -1.0, 0.0);
-
- walle->o_toolbar = o;
-
- o = elm_icon_add(walle->o_win);
- elm_icon_file_set(o, theme, "walle/icon/resize");
- elm_toolbar_item_add(walle->o_toolbar, o, "Resize", NULL, NULL);
-
- o = elm_icon_add(walle->o_win);
- elm_icon_file_set(o, theme, "walle/icon/rotate");
- elm_toolbar_item_add(walle->o_toolbar, o, "Rotate", NULL, NULL);
-
- o = elm_icon_add(walle->o_win);
- elm_icon_file_set(o, theme, "walle/icon/config");
- elm_toolbar_item_add(walle->o_toolbar, o, "Configuration", NULL, NULL);
-
-
- evas_object_size_hint_min_set(walle->o_toolbar, -1, -1);
- edje_object_part_swallow(walle->o_edje, "walle.swallow.toolbar", walle->o_toolbar);
-
- o = walle_wall_add(walle->evas);
- walle_wall_lines_set(o, lines);
- walle->o_wall = o;
-
- _populate_wall(walle, path, theme);
-
- elm_scroller_content_set(walle->o_scroll, o);
-
- /* Finally show window */
- evas_object_resize(walle->o_win, 600, 480);
- evas_object_show(walle->o_win);
-
elm_run();
- /* Free all object created */
- evas_object_del(walle->o_edje);
- evas_object_del(walle->o_toolbar);
- evas_object_del(walle->o_wall);
-
- EINA_LIST_FOREACH(walle->pictures, l, o)
- {
- evas_object_del(o);
- }
-
+ walle_shutdown(walle);
elm_shutdown();
edje_shutdown();
ecore_file_shutdown();
ecore_evas_shutdown();
- free(walle);
-
return EXIT_SUCCESS;
+ shutdown_walle:
+ walle_shutdown(walle);
+ shutdown_elm:
+ elm_shutdown();
shutdown_edje:
edje_shutdown();
shutdown_ecore_file:
ecore_file_shutdown();
shutdown_ecore_evas:
ecore_evas_shutdown();
- free_walle:
- free(walle);
return EXIT_FAILURE;
}
Modified: trunk/wall-e/src/bin/wall-e.h
===================================================================
--- trunk/wall-e/src/bin/wall-e.h 2009-01-27 18:00:28 UTC (rev 540)
+++ trunk/wall-e/src/bin/wall-e.h 2009-01-28 08:07:13 UTC (rev 541)
@@ -2,12 +2,26 @@
struct _Walle
{
- Evas *evas;
+ struct {
+ char *engine;
+ char *path;
+ char *theme;
+ Evas_Coord width;
+ Evas_Coord height;
+ int fps;
+ int lines;
+ } config;
+ Evas *evas;
Evas_Object *o_win;
Evas_Object *o_edje;
Evas_Object *o_wall;
Evas_Object *o_scroll;
Evas_Object *o_toolbar;
- Evas_Coord app_w, app_h;
- Eina_List *pictures;
+ Eina_List *pictures;
};
+
+Walle *walle_init(int argc, char **argv);
+
+void walle_shutdown(Walle *walle);
+
+int walle_gui_set(Walle *walle);
Added: trunk/wall-e/src/bin/walle.c
===================================================================
--- trunk/wall-e/src/bin/walle.c (rev 0)
+++ trunk/wall-e/src/bin/walle.c 2009-01-28 08:07:13 UTC (rev 541)
@@ -0,0 +1,299 @@
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include <stdlib.h>
+
+#include <Ecore_Data.h>
+#include <Ecore_Getopt.h>
+#include <Ecore_File.h>
+
+#include <Elementary.h>
+
+#include "wall-e.h"
+#include "wall.h"
+
+static const Ecore_Getopt options = {
+ "wall-e",
+ "%prog [options]",
+ "0.1.0",
+ "(C) 2008 Enlightenment",
+ "BSD\nThis is a 3 clause bsd bla bla",
+ "a simple image viewer using enlightenment foundation libraries.\n"
+ "Here is the text of the licence",
+ 1,
+ {
+ ECORE_GETOPT_STORE_STR('e', "engine", "ecore-evas engine to use"),
+ ECORE_GETOPT_CALLBACK_NOARGS('E', "list-engines", "list ecore-evas engines",
+ ecore_getopt_callback_ecore_evas_list_engines, NULL),
+ ECORE_GETOPT_STORE_DEF_BOOL('F', "fullscreen", "fullscreen mode", 0),
+ ECORE_GETOPT_CALLBACK_ARGS('g', "geometry", "geometry to use in x:y:w:h form.", "X:Y:W:H",
+ ecore_getopt_callback_geometry_parse, NULL),
+ ECORE_GETOPT_STORE_STR('p', "path", "path to read the image files from"),
+ ECORE_GETOPT_STORE_STR('t', "theme", "path to read the theme file from"),
+ ECORE_GETOPT_STORE_INT('f', "fps", "frame per second"),
+ ECORE_GETOPT_STORE_INT('l', "lines", "Number of lines to display"),
+ ECORE_GETOPT_COUNT('v', "verbose", "be more verbose"),
+ ECORE_GETOPT_VERSION('V', "version"),
+ ECORE_GETOPT_COPYRIGHT('R', "copyright"),
+ ECORE_GETOPT_LICENSE('L', "license"),
+ ECORE_GETOPT_HELP('h', "help"),
+ ECORE_GETOPT_SENTINEL
+ }
+};
+
+static void _walle_win_del_cb(void *data, Evas_Object *obj, void *event_info)
+{
+ elm_exit();
+}
+
+static void _walle_picture_cb_resize(void *data, Evas *e, Evas_Object *obj, void *einfo)
+{
+ Evas_Object *o_pict;
+ Evas_Coord width;
+ Evas_Coord height;
+
+ o_pict = (Evas_Object *)data;
+ width = 0;
+ height = 0;
+ /* callback when a picture is resized */
+ evas_object_geometry_get(o_pict, NULL, NULL, &width, &height);
+ evas_object_image_fill_set(o_pict, 0, 0, width, height);
+
+}
+
+static void _walle_wall_populate(Walle *walle, const char *directory, const char *theme)
+{
+ Evas_Object *o;
+ Evas_Coord ow, oh, w, h;
+ Ecore_List *files = NULL;
+ char *file = NULL;
+ char filename[4096];
+
+ if (!ecore_file_is_dir(directory) && ecore_file_dir_is_empty(directory))
+ return;
+ files = ecore_file_ls(directory);
+ if (!files)
+ return;
+ ecore_list_sort(files, ECORE_COMPARE_CB(strcasecmp), ECORE_SORT_MIN);
+ file = ecore_list_first_goto(files);
+ while ((file = (char *)ecore_list_next(files)) != NULL)
+ {
+
+ sprintf(filename, "%s/%s", directory, file);
+ o = evas_object_image_add(walle->evas);
+ evas_object_image_file_set(o, filename, NULL);
+ switch(evas_object_image_load_error_get(o))
+ {
+ case EVAS_LOAD_ERROR_NONE:
+ {
+ evas_object_event_callback_add(o, EVAS_CALLBACK_RESIZE, _walle_picture_cb_resize, o);
+ evas_object_image_size_get(o, &w, &h);
+ oh = 200;
+ ow = oh * (float)w/(float)h;
+ evas_object_image_load_size_set(o, ow, oh);
+ evas_object_image_fill_set(o, 0, 0, ow, oh);
+ evas_object_resize(o, ow, oh);
+ evas_object_size_hint_min_set(o, ow, oh);
+ walle_wall_append(walle->o_wall, o);
+ walle->pictures = eina_list_append(walle->pictures, o);
+ }
+ break;
+ default:
+ evas_object_del(o);
+ break;
+
+ }
+
+ }
+ ecore_list_destroy(files);
+}
+
+
+Walle *
+walle_init(int argc, char **argv)
+{
+ Eina_Rectangle geometry = {0, 0, 0, 0};
+ char *engine = NULL;
+ char *path = NULL;
+ char *theme = NULL;
+ int fps = 0;
+ int lines = 2;
+ int verbose = 0;
+ int args;
+ unsigned char help = 0;
+ unsigned char engines_listed = 0;
+ unsigned char is_fullscreen = 0;
+ Ecore_Getopt_Value values[] = {
+ ECORE_GETOPT_VALUE_STR(engine),
+ ECORE_GETOPT_VALUE_BOOL(engines_listed),
+ ECORE_GETOPT_VALUE_BOOL(is_fullscreen),
+ ECORE_GETOPT_VALUE_PTR_CAST(geometry),
+ ECORE_GETOPT_VALUE_STR(path),
+ ECORE_GETOPT_VALUE_STR(theme),
+ ECORE_GETOPT_VALUE_INT(fps),
+ ECORE_GETOPT_VALUE_INT(lines),
+ ECORE_GETOPT_VALUE_INT(verbose),
+ ECORE_GETOPT_VALUE_NONE,
+ ECORE_GETOPT_VALUE_NONE,
+ ECORE_GETOPT_VALUE_NONE,
+ ECORE_GETOPT_VALUE_BOOL(help),
+ ECORE_GETOPT_VALUE_NONE
+ };
+
+ Walle *walle;
+
+ ecore_app_args_set(argc, (const char **)argv);
+
+ args = ecore_getopt_parse(&options, values, argc, argv);
+ if (args < 0)
+ {
+ fprintf(stderr, "[Wall-e] ERROR: could not parse options.\n");
+ return NULL;
+ }
+
+ /* parse the options */
+
+ if (help)
+ return NULL;
+
+ if (engines_listed)
+ return NULL;
+
+ if (!engine)
+ {
+ fprintf(stderr, "[Wall-e] ERROR: could not set engine.\n");
+ return NULL;
+ }
+
+ if (!path)
+ {
+ fprintf(stderr, "[Wall-e] ERROR: could not set path.\n");
+ return NULL;
+ }
+
+ if (!theme)
+ {
+ theme = getenv("WALLE_THEME");
+ if (!theme)
+ theme = PACKAGE_DATA_DIR "/data/default.edj";
+ }
+
+ if (is_fullscreen &&
+ ((geometry.x != 0) ||
+ (geometry.y != 0) ||
+ (geometry.w != 0) ||
+ (geometry.h != 0)))
+ {
+ fprintf(stderr, "[Wall-e] ERROR: could not set fulllscreen and geometry at same time.\n");
+ return NULL;
+ }
+
+ if (!is_fullscreen &&
+ (geometry.x == 0) &&
+ (geometry.y == 0) &&
+ (geometry.w == 0) &&
+ (geometry.h == 0))
+ {
+ geometry.w = 640;
+ geometry.h = 480;
+ }
+
+ if (fps != 0)
+ ecore_animator_frametime_set(1.0 / (double)fps);
+
+ /* we set our Walle object */
+
+ walle = (Walle *)calloc(1, sizeof(Walle));
+ if (!walle)
+ return NULL;
+
+ /* config */
+ walle->config.engine = strdup(engine);
+ walle->config.path = strdup(path);
+ walle->config.theme = strdup(theme);
+ walle->config.width = geometry.w;
+ walle->config.height = geometry.h;
+ walle->config.fps = fps;
+ walle->config.lines = lines;
+
+ return walle;
+}
+
+void
+walle_shutdown(Walle *walle)
+{
+ if (!walle)
+ return;
+
+ free(walle->config.engine);
+ free(walle->config.path);
+ free(walle->config.theme);
+ free(walle);
+}
+
+int
+walle_gui_set(Walle *walle)
+{
+ Evas_Object *o;
+
+ /* main window */
+ o = elm_win_add(NULL, "Wall-E", ELM_WIN_BASIC);
+ if (!o)
+ return 0;
+
+ elm_win_title_set(o, "Wall-E");
+ evas_object_smart_callback_add(o, "delete-request", _walle_win_del_cb, NULL);
+ walle->o_win = o;
+
+ walle->evas = evas_object_evas_get(walle->o_win);
+
+ /* main edje object */
+ o = edje_object_add(walle->evas);
+ edje_object_file_set(o, walle->config.theme, "wall-e");
+ evas_object_size_hint_weight_set(o, 1.0, 1.0);
+ elm_win_resize_object_add(walle->o_win, o);
+ evas_object_show(o);
+ walle->o_edje = o;
+
+ /* scroller */
+ o = elm_scroller_add(walle->o_win);
+ edje_object_part_swallow(walle->o_edje, "walle.swallow.content", o);
+ evas_object_show(o);
+ walle->o_scroll = o;
+
+ /* toolbar */
+ o = elm_toolbar_add(walle->o_win);
+ evas_object_size_hint_weight_set(o, 0.0, 0.0);
+ evas_object_size_hint_align_set(o, -1.0, 0.0);
+ evas_object_size_hint_min_set(o, -1, -1);
+ edje_object_part_swallow(walle->o_edje, "walle.swallow.toolbar", o);
+ walle->o_toolbar = o;
+
+ o = elm_icon_add(walle->o_win);
+ elm_icon_file_set(o, walle->config.theme, "walle/icon/resize");
+ elm_toolbar_item_add(walle->o_toolbar, o, "Resize", NULL, NULL);
+
+ o = elm_icon_add(walle->o_win);
+ elm_icon_file_set(o, walle->config.theme, "walle/icon/rotate");
+ elm_toolbar_item_add(walle->o_toolbar, o, "Rotate", NULL, NULL);
+
+ o = elm_icon_add(walle->o_win);
+ elm_icon_file_set(o, walle->config.theme, "walle/icon/config");
+ elm_toolbar_item_add(walle->o_toolbar, o, "Configuration", NULL, NULL);
+
+ /* another brick in the wall */
+ o = walle_wall_add(walle->evas);
+ walle_wall_lines_set(o, walle->config.lines);
+ elm_scroller_content_set(walle->o_scroll, o);
+ walle->o_wall = o;
+
+ _walle_wall_populate(walle, walle->config.path, walle->config.theme);
+
+ /* resize and show window */
+ evas_object_resize(walle->o_win, walle->config.width, walle->config.height);
+ evas_object_show(walle->o_win);
+
+ return 1;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|