Enlightenment CVS committal Author : essiene Project : e17 Module : proto
Dir : e17/proto/entrance_edit_gui/src/gui Modified Files: Egui.h Makefile.am background.c theme.c Added Files: egui_graphics_selector.c Log Message: Done one badass-refactoring(tm). The core code in theme.c has been made generic and moved to egui_graphics_selector.c and is now being used by both the theme.c and the background.c config. And both work properly. For all who say OOP is the only way to reuse code, i say... be very afraid ;-) =================================================================== RCS file: /cvs/e/e17/proto/entrance_edit_gui/src/gui/Egui.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- Egui.h 12 Aug 2006 14:54:42 -0000 1.2 +++ Egui.h 13 Aug 2006 22:41:44 -0000 1.3 @@ -1,6 +1,16 @@ #ifndef _EGUI_H #define _EGUI_H +typedef struct _Egui_Graphics_Selector { + char *name; + char *files_path; + char *preview_edje_part; + char *dialog_title; + char *list_title; + char *entrance_edit_key; +} Egui_Graphics_Selector; + + void egui_theme_dialog_show(void); void egui_background_dialog_show(void); void egui_layout_dialog_show(void); @@ -8,5 +18,7 @@ void egui_behavior_dialog_show(void); void egui_sessions_dialog_show(void); void egui_x_settings_dialog_show(void); + +void egui_gs_dialog_show(Egui_Graphics_Selector); #endif =================================================================== RCS file: /cvs/e/e17/proto/entrance_edit_gui/src/gui/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -u -3 -r1.7 -r1.8 --- Makefile.am 13 Aug 2006 17:00:15 -0000 1.7 +++ Makefile.am 13 Aug 2006 22:41:44 -0000 1.8 @@ -9,12 +9,13 @@ sessions.c \ theme.c \ x_settings.c \ + egui_graphics_selector.c \ Egui.h entrance_edit_gui_CFLAGS = \ -I$(top_srcdir)/src/widgets \ @etk_cflags@ [EMAIL PROTECTED]@ this line broke the build for me [EMAIL PROTECTED]@ entrance_edit_gui_LDFLAGS = \ -L$(top_srcdir)/src/widgets =================================================================== RCS file: /cvs/e/e17/proto/entrance_edit_gui/src/gui/background.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -3 -r1.5 -r1.6 --- background.c 13 Aug 2006 21:33:45 -0000 1.5 +++ background.c 13 Aug 2006 22:41:44 -0000 1.6 @@ -3,131 +3,21 @@ #include <Ecore_Data.h> #include <Entrance_Widgets.h> #include <Entrance_Edit.h> +#include <Egui.h> -static void _background_cb_selected(void); -static void _background_cb_ok(void *, void *); -static void _background_cb_apply(void *, void *); -static void _background_cb_close(void *, void *); - -static char* _background_get_path(const char *); -static void _background_close(void); -static void _background_apply(void); - -static Entrance_Dialog win; -static Entrance_Widget img_preview; -static Entrance_List list_thumbs; -static Entrance_Widget group_backgrounds; -static Entrance_Widget group_preview; -static Entrance_Widget group_options; void egui_background_dialog_show() { - Ecore_List *backgrounds; - char *background; - - win = ew_dialog_new(_("Entrance - Background Chooser"), EW_FALSE); - - group_preview = ew_dialog_group_add(win, _("Preview")); - - img_preview = ew_image_new(320, 240); - ew_group_add(group_preview, img_preview); - - group_backgrounds = ew_dialog_group_add(win, _("Backgrounds")); - - list_thumbs = ew_textlist_new(NULL, 320, 140, 20, 90); - - /* scan for backgrounds and add them to the list */ - backgrounds = ecore_file_ls("/usr/share/enlightenment/data/backgrounds"); - if(!backgrounds || ecore_list_is_empty(backgrounds)) - return; - - background = ecore_list_first(backgrounds); - char *background_file = _background_get_path(background); - ew_image_edje_load(img_preview, background_file, "desktop/background"); - free(background_file); - /*FIXME: selecting the first row doesn't work - maybe we select first row while adding elements to the list:(*/ - ew_list_first_row_select(list_thumbs); - - ecore_list_goto_first(backgrounds); - while((background = ecore_list_next(backgrounds))) - { - char *background_no_ext = ecore_file_strip_ext(background); - ew_textlist_add(list_thumbs, background_no_ext, background, strlen(background) + 1, _background_cb_selected); - - free(background_no_ext); - } - ecore_list_destroy(backgrounds); - - ew_group_add(group_backgrounds, list_thumbs); - - /*Entrance_Widget group_options = ew_dialog_group_add(win, _("Options"));*/ - - ew_dialog_close_button_add(win, _background_cb_close, NULL); - ew_dialog_apply_button_add(win, _background_cb_apply, NULL); - ew_dialog_ok_button_add(win, _background_cb_ok, NULL); - - ew_dialog_show(win); -} - -static void -_background_cb_selected() -{ - char* background = ew_list_selected_data_get(list_thumbs); - char* background_path = _background_get_path(background); - ew_image_edje_load(img_preview, background_path, "desktop/background"); - - free(background_path); -} - - -static void -_background_cb_ok(void *object, void *data) -{ - _background_apply(); - _background_close(); -} + Egui_Graphics_Selector background_egs = { + "background", + "/usr/share/enlightenment/data/backgrounds", + "desktop/background", + "Entrance Configuration - Background", + "Backgrounds", + ENTRANCE_EDIT_KEY_CLIENT_BACKGROUND_STR + }; -static void -_background_cb_apply(void *object, void *data) -{ - _background_apply(); -} + egui_gs_dialog_show(background_egs); -static void -_background_cb_close(void *object, void *data) -{ - _background_close(); -} - -static char* -_background_get_path(const char *t) -{ - char *path = calloc(PATH_MAX, sizeof(*path)); - snprintf(path, PATH_MAX, "/usr/share/enlightenment/data/backgrounds/%s", t); - - return path; -} - -static void -_background_apply(void) -{ - char *background = ew_list_selected_data_get(list_thumbs); - if(!background) - { - printf("Error. Please select a background first\n"); - return; - } - - entrance_edit_string_set(ENTRANCE_EDIT_KEY_CLIENT_BACKGROUND_STR, background); - if(!entrance_edit_save()) - { - printf("Error setting background - %s. Please check your permissions\n", background); - } -} - -static void -_background_close(void) -{ - ew_dialog_destroy(win); } =================================================================== RCS file: /cvs/e/e17/proto/entrance_edit_gui/src/gui/theme.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -3 -r1.6 -r1.7 --- theme.c 13 Aug 2006 21:33:45 -0000 1.6 +++ theme.c 13 Aug 2006 22:41:44 -0000 1.7 @@ -3,156 +3,20 @@ #include <Ecore_Data.h> #include <Entrance_Widgets.h> #include <Entrance_Edit.h> +#include <Egui.h> -#define THEME_PATH "/usr/share/entrance/themes" -#define THEME_PREVIEW_EDJE_PART "Preview" -#define THEME_LIST_TITLE "Themes" - -static void _theme_cb_selected(void); -static void _theme_cb_ok(void *, void *); -static void _theme_cb_apply(void *, void *); -static void _theme_cb_close(void *, void *); - -static char* _theme_get_path(const char *); -static void _theme_close(void); -static void _theme_apply(void); -static char* _theme_populate_list(void); -static void _theme_load_preview(const char *); - -static Entrance_Dialog win; -static Entrance_Widget img_preview; -static Entrance_List list_thumbs; -static Entrance_Widget group_themes; -static Entrance_Widget group_preview; -static Entrance_Widget group_options; - -/*static char* theme_path; -static char* theme_preview_edje_part; -static char* theme_list_title;*/ void egui_theme_dialog_show() { - - win = ew_dialog_new(_("Entrance - Theme Chooser"), EW_FALSE); - - group_preview = ew_dialog_group_add(win, _("Preview")); - - img_preview = ew_image_new(320, 240); - ew_group_add(group_preview, img_preview); - - group_themes = ew_dialog_group_add(win, _(THEME_LIST_TITLE)); - - list_thumbs = ew_textlist_new(NULL, 320, 140, 20, 90); - - char *first_theme = _theme_populate_list(); - _theme_load_preview(first_theme); - - ew_group_add(group_themes, list_thumbs); - - /*Entrance_Widget group_options = ew_dialog_group_add(win, _("Options"));*/ - - ew_dialog_close_button_add(win, _theme_cb_close, NULL); - ew_dialog_apply_button_add(win, _theme_cb_apply, NULL); - ew_dialog_ok_button_add(win, _theme_cb_ok, NULL); - - ew_dialog_show(win); -} - -static void -_theme_cb_selected() -{ - char* theme = ew_list_selected_data_get(list_thumbs); - char* theme_path = _theme_get_path(theme); - ew_image_edje_load(img_preview, theme_path, THEME_PREVIEW_EDJE_PART); - - free(theme_path); -} + Egui_Graphics_Selector theme_egs = { + "theme", + "/usr/share/entrance/themes", + "Preview", + "Entrance Configuration - Themes", + "Themes", + ENTRANCE_EDIT_KEY_CLIENT_THEME_STR + }; - -static void -_theme_cb_ok(void *object, void *data) -{ - _theme_apply(); - _theme_close(); -} - -static void -_theme_cb_apply(void *object, void *data) -{ - _theme_apply(); -} - -static void -_theme_cb_close(void *object, void *data) -{ - _theme_close(); -} - -static char* -_theme_get_path(const char *t) -{ - char *path = calloc(PATH_MAX, sizeof(*path)); - snprintf(path, PATH_MAX, THEME_PATH "/%s", t); - - return path; -} - -static void -_theme_apply(void) -{ - char *theme = ew_list_selected_data_get(list_thumbs); - if(!theme) - { - printf("Error. Please select a theme first\n"); - return; - } - - entrance_edit_string_set(ENTRANCE_EDIT_KEY_CLIENT_THEME_STR, theme); - if(!entrance_edit_save()) - { - printf("Error setting theme - %s. Please check your permissions\n", theme); - } -} - -static void -_theme_close(void) -{ - ew_dialog_destroy(win); -} - -static char* -_theme_populate_list(void) -{ - Ecore_List *theme_list = ecore_file_ls(THEME_PATH); - char* first_theme; - - if(theme_list && !ecore_list_is_empty(theme_list)) - { - ecore_list_goto_first(theme_list); - - char* theme; - first_theme = strdup(ecore_list_first(theme_list)); - - while((theme = ecore_list_next(theme_list))) - { - char *theme_no_ext = ecore_file_strip_ext(theme); - ew_textlist_add(list_thumbs, theme_no_ext, theme, strlen(theme) + 1, _theme_cb_selected); - free(theme_no_ext); - } - - ecore_list_destroy(theme_list); - } - - return first_theme; -} - -static void -_theme_load_preview(const char *theme) -{ - char *theme_file = _theme_get_path(theme); - ew_image_edje_load(img_preview, theme_file, THEME_PREVIEW_EDJE_PART); - free(theme_file); - /*FIXME: selecting the first row doesn't work - maybe we select first row while adding elements to the list:(*/ - /*ew_list_first_row_select(list_thumbs);*/ + egui_gs_dialog_show(theme_egs); } ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs