Enlightenment CVS committal Author : rephorm Project : e17 Module : apps/elicit
Dir : e17/apps/elicit/src Modified Files: Elicit.h elicit.c shots.c swatches.c swatches.h util.c util.h Log Message: Begin moving elicit away from edb dependency. Now saves shots in a .eet file, and swatches in gimp's palette (.gpl) format. Allow reordering of swatches/shots using the middle mouse button. Some cleanups. Still need to change autofoo and add conditionals around remaining edb code. =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/Elicit.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- Elicit.h 8 Mar 2005 05:02:13 -0000 1.14 +++ Elicit.h 18 Dec 2005 06:53:46 -0000 1.15 @@ -6,9 +6,12 @@ #include <Ecore_X.h> #include <Ecore_Evas.h> #include <Ecore_Config.h> +#include <Ecore_File.h> #include <Edje.h> #include <Esmart/Esmart_Draggies.h> #include <Esmart/Esmart_Container.h> +#include <Edb.h> +#include <Eet.h> #include <X11/Xlib.h> #include <Imlib2.h> #include <stdlib.h> =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/elicit.c,v retrieving revision 1.25 retrieving revision 1.26 diff -u -3 -r1.25 -r1.26 --- elicit.c 12 Nov 2005 06:11:18 -0000 1.25 +++ elicit.c 18 Dec 2005 06:53:46 -0000 1.26 @@ -111,6 +111,11 @@ ecore_evas_borderless_set(el->ee, 1); ecore_evas_shaped_set(el->ee, 1); + el->gui = edje_object_add(el->evas); + evas_object_name_set(el->gui, "gui"); + evas_object_move(el->gui, 0, 0); + evas_object_show(el->gui); + el->draggie = esmart_draggies_new(el->ee); esmart_draggies_button_set(el->draggie, 1); evas_object_layer_set(el->draggie, -1); @@ -118,11 +123,6 @@ evas_object_name_set(el->draggie, "draggie"); evas_object_show(el->draggie); - el->gui = edje_object_add(el->evas); - evas_object_name_set(el->gui, "gui"); - evas_object_move(el->gui, 0, 0); - evas_object_show(el->gui); - elicit_config_color_get(&el->color.r, &el->color.g, &el->color.b); elicit_util_colors_set_from_rgb(el); el->zoom = elicit_config_zoom_get(); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/shots.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -3 -r1.11 -r1.12 --- shots.c 5 Sep 2005 19:45:47 -0000 1.11 +++ shots.c 18 Dec 2005 06:53:46 -0000 1.12 @@ -3,6 +3,10 @@ #include <string.h> void _elicit_shots_update_scroll_bar(Elicit *el); +void _elicit_shots_load_eet(Elicit *el); +void _elicit_shots_load_edb(Elicit *el); +void _elicit_shots_save_eet(Elicit *el); +void _elicit_shots_save_edb(Elicit *el); int elicit_shots_init(Elicit *el) @@ -12,6 +16,8 @@ char *dir; el->shots.cont = esmart_container_new(el->evas); + esmart_container_move_button_set(el->shots.cont, 2); + esmart_container_callback_order_change_set(el->shots.cont, (void (*)(void *data))elicit_shots_save, el); dir = (char *)edje_object_data_get(el->gui, "shots.direction"); if (dir && (dir[0] == 'h' || dir[0] == 'H')) @@ -59,6 +65,56 @@ void elicit_shots_save(Elicit *el) { + _elicit_shots_save_eet(el); +} + +void +_elicit_shots_save_eet(Elicit *el) +{ + Evas_List *l; + Eet_File *eet; + int i = 0; + char buf[PATH_MAX]; + + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/shots.eet", getenv("HOME"), el->app_name); + + eet = eet_open(buf, EET_FILE_MODE_WRITE); + + if (!eet) return; + + for (l = esmart_container_elements_get(el->shots.cont); l; l = l->next, i++) + { + Evas_Object *obj; + Elicit_Shot *sh; + void *data; + int iw, ih; + + obj = (Evas_Object *)(l->data); + sh = evas_object_data_get(obj, "shot"); + + snprintf(buf, PATH_MAX, "shots/%d/name", i); + if (sh->name) { + eet_write(eet, buf, sh->name, strlen(sh->name), 1); + } else { + eet_write(eet, buf, "Unnamed", 7, 1); + } + + evas_object_image_size_get(sh->shot, &iw, &ih); + data = evas_object_image_data_get(sh->shot, 1); + + snprintf(buf, PATH_MAX, "shots/%d/shot", i); + eet_data_image_write(eet, buf, data, iw, ih, 0, 9, 100, 0); + } + + snprintf(buf, PATH_MAX, "%d", i); + eet_write(eet, "shots/num", buf, strlen(buf), 1); + + eet_close(eet); +} + +void +_elicit_shots_save_edb(Elicit *el) +{ Evas_List *l; E_DB_File *db; int i = 0; @@ -131,6 +187,100 @@ void elicit_shots_load(Elicit *el) { + char buf[PATH_MAX]; + + /* upgrade path -- if eet file doesn't exist, load shots from edb */ + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/shots.eet", getenv("HOME"), el->app_name); + + if(!ecore_file_exists(buf)) + { + _elicit_shots_load_edb(el); + _elicit_shots_save_eet(el); + } + else + { + _elicit_shots_load_eet(el); + } +} + +void +_elicit_shots_load_eet(Elicit *el) +{ + Eet_File *eet = NULL; + int num = 0; + int i; + char file[PATH_MAX]; + char buf[PATH_MAX]; + char *ret = 0; + int size_ret = 0; + char *theme = NULL; + + + snprintf(file, PATH_MAX, "%s/.e/apps/%s/shots.eet", getenv("HOME"), el->app_name); + + eet = eet_open(file, EET_FILE_MODE_READ); + if (!eet) return; + + ret = eet_read(eet, "shots/num", &size_ret); + if (size_ret >= PATH_MAX) return; + + memcpy(buf, ret, size_ret); + buf[size_ret] = '\0'; + num = atoi(buf); + + theme = elicit_config_theme_get(el); + for (i = 0; i < num; i++) + { + Elicit_Shot *sh; + Evas_Coord mw, mh; + + sh = calloc(1, sizeof(Elicit_Shot)); + + snprintf(buf, PATH_MAX, "/shots/%d/name", i); + ret = eet_read(eet, buf, &size_ret); + memcpy(buf, ret, size_ret); + buf[size_ret] = '\0'; + sh->name = strdup(buf); + + sh->obj = edje_object_add(el->evas); + sh->shot = evas_object_image_add(el->evas); + + edje_object_file_set(sh->obj, + elicit_theme_find(theme), + "shot"); + edje_object_size_min_get(sh->obj, &mw, &mh); + if (mw != 0 && mh != 0) + evas_object_resize(sh->obj, mw, mh); + else + evas_object_resize(sh->obj, 20, 20); + + evas_object_show(sh->obj); + evas_object_data_set(sh->obj, "shot", sh); + evas_object_data_set(sh->obj, "elicit", el); + + edje_object_signal_callback_add(sh->obj, "elicit,shot,load", "", elicit_shot_load_cb, sh); + edje_object_signal_callback_add(sh->obj, "elicit,shot,del", "", elicit_shot_del_cb, sh); + edje_object_signal_callback_add(sh->obj, "elicit,shot,name,show", "", elicit_shot_name_show_cb, sh); + + snprintf(buf, sizeof(buf), "shots/%d/shot", i); + evas_object_image_file_set(sh->shot, file, buf); + evas_object_pass_events_set(sh->shot, 1); + evas_object_show(sh->shot); + edje_object_part_swallow(sh->obj, "shot", sh->shot); + + esmart_container_element_append(el->shots.cont, sh->obj); + } + + el->shots.length = esmart_container_elements_length_get(el->shots.cont); + + free(theme); + eet_close(eet); + +} + +void +_elicit_shots_load_edb(Elicit *el) +{ E_DB_File *db; int num, ok; int i; =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/swatches.c,v retrieving revision 1.12 retrieving revision 1.13 diff -u -3 -r1.12 -r1.13 --- swatches.c 5 Sep 2005 19:45:47 -0000 1.12 +++ swatches.c 18 Dec 2005 06:53:46 -0000 1.13 @@ -4,6 +4,12 @@ void _elicit_swatches_update_scroll_bar(Elicit *el); +void _elicit_swatches_save_eet(Elicit *el); +void _elicit_swatches_load_eet(Elicit *el); +void _elicit_swatches_load_edb(Elicit *el); +void _elicit_swatches_load_gpl(Elicit *el); +void _elicit_swatches_save_edb(Elicit *el); +void _elicit_swatches_save_gpl(Elicit *el); int elicit_swatches_init(Elicit *el) @@ -13,6 +19,8 @@ char *dir; el->swatches.cont = esmart_container_new(el->evas); + esmart_container_move_button_set(el->swatches.cont, 2); + esmart_container_callback_order_change_set(el->swatches.cont, (void (*)(void *data))elicit_swatches_save, el); dir = (char *)edje_object_data_get(el->gui, "swatches.direction"); if (dir && (dir[0] == 'h' || dir[0] == 'H')) @@ -59,6 +67,81 @@ void elicit_swatches_save(Elicit *el) { + _elicit_swatches_save_gpl(el); +} + +void +_elicit_swatches_save_gpl(Elicit *el) +{ + Evas_List *l; + FILE *f = NULL; + char buf[PATH_MAX]; + + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.gpl", getenv("HOME"), el->app_name); + + f = fopen(buf, "w"); + + if (!f) return; + + fprintf(f, "GIMP Palette\nName: Elicit\nColumns: 1\n#\n"); + for (l = esmart_container_elements_get(el->swatches.cont); l; l = l->next) + { + Evas_Object *obj; + Elicit_Swatch *sw; + + obj = (Evas_Object *)(l->data); + sw = evas_object_data_get(obj, "swatch"); + + fprintf(f, "%-3d %-3d %-3d %s\n", sw->r, sw->g, sw->b, sw->name); + } + + fclose(f); +} + +void +_elicit_swatches_save_eet(Elicit *el) +{ + Evas_List *l; + Eet_File *eet; + int i = 0; + char buf[PATH_MAX]; + char *hex; + + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.eet", getenv("HOME"), el->app_name); + + eet = eet_open(buf, EET_FILE_MODE_WRITE); + + if (!eet) return; + + for (l = esmart_container_elements_get(el->swatches.cont); l; l = l->next) + { + Evas_Object *obj; + Elicit_Swatch *sw; + + obj = (Evas_Object *)(l->data); + sw = evas_object_data_get(obj, "swatch"); + + snprintf(buf, PATH_MAX, "swatches/%d/name", i); + eet_write(eet, buf, sw->name, strlen(sw->name), 1); + + snprintf(buf, PATH_MAX, "swatches/%d/hex", i); + hex = elicit_color_rgb_to_hex(sw->r, sw->g, sw->b); + eet_write(eet, buf, hex, strlen(hex), 1); + free(hex); + + i++; + } + + snprintf(buf, PATH_MAX, "%d", i); + eet_write(eet, "swatches/num", buf, strlen(buf), 1); + + eet_close(eet); +} + + +void +_elicit_swatches_save_edb(Elicit *el) +{ Evas_List *l; E_DB_File *db; int i = 0; @@ -122,64 +205,138 @@ void elicit_swatches_load(Elicit *el) { + char buf[PATH_MAX]; + + /* upgrade path -- if no gpl file exists, try to load from an old edb file. */ + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.gpl", getenv("HOME"), el->app_name); + + if (!ecore_file_exists(buf)) + { + _elicit_swatches_load_edb(el); + _elicit_swatches_save_gpl(el); + } + else + { + _elicit_swatches_load_gpl(el); + } +} + +void +_elicit_swatches_load_gpl(Elicit *el) +{ + FILE *f; + char buf[PATH_MAX]; + char *name; + int r, g, b; + + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.gpl", getenv("HOME"), el->app_name); + + f = fopen(buf, "r"); + if (!f) return; + + name = calloc(PATH_MAX, sizeof(char)); + if (!name) return; + + while(fgets(buf, PATH_MAX, f)) + { + if (sscanf(buf, "%3d %3d %3d\t%s\n", &r, &g, &b, name) == 4) + { + elicit_swatch_new(el, name, r, g, b); + } + } + + el->swatches.length = esmart_container_elements_length_get(el->swatches.cont); + free(name); +} + + +void +_elicit_swatches_load_eet(Elicit *el) +{ + Eet_File *eet; + int num = 0; + int i = 0; + char buf[PATH_MAX]; + char *ret = NULL; + int size_ret; + char *name; + int r, g, b; + + snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.eet", getenv("HOME"), el->app_name); + + eet = eet_open(buf, EET_FILE_MODE_READ); + if (!eet) return; + + ret = eet_read(eet, "swatches/num", &size_ret); + if (ret) { + memcpy(buf, ret, size_ret); + buf[size_ret] = '\0'; + num = atoi(buf); + free(ret); + } + + for (i = 0; i < num; i++) + { + Elicit_Swatch *sw; + + sw = calloc(1, sizeof(Elicit_Swatch)); + + snprintf(buf, PATH_MAX, "swatches/%d/name", i); + ret = eet_read(eet, buf, &size_ret); + if (ret) { + memcpy(buf, ret, size_ret); + buf[size_ret] = '\0'; + name = strdup(buf); + } + + snprintf(buf, PATH_MAX, "swatches/%d/hex", i); + ret = eet_read(eet, buf, &size_ret); + if (ret) { + memcpy(buf, ret, size_ret); + buf[size_ret] = '\0'; + elicit_color_hex_to_rgb(buf, &(r), &(g), &(b)); + free(ret); + } + + sw = elicit_swatch_new(el, name, r, g, b); + } + + el->swatches.length = esmart_container_elements_length_get(el->swatches.cont); + eet_close(eet); +} + +void +_elicit_swatches_load_edb(Elicit *el) +{ E_DB_File *db; - int num, ok; + int num; int i; char buf[PATH_MAX]; - char *theme; + char *name; + int r, g, b; snprintf(buf, PATH_MAX, "%s/.e/apps/%s/swatches.db", getenv("HOME"), el->app_name); db = e_db_open_read(buf); if (db) - ok = e_db_int_get(db, "/swatches/num", &num); + e_db_int_get(db, "/swatches/num", &num); else return; for (i = 0; i < num; i++) { Elicit_Swatch *sw; - Evas_Coord mw, mh; - - sw = calloc(1, sizeof(Elicit_Swatch)); snprintf(buf, PATH_MAX, "/swatches/%d/name", i); - sw->name = e_db_str_get(db, buf); + name = e_db_str_get(db, buf); snprintf(buf, PATH_MAX, "/swatches/%d/r", i); - e_db_int_get(db, buf, &(sw->r)); + e_db_int_get(db, buf, &r); snprintf(buf, PATH_MAX, "/swatches/%d/g", i); - e_db_int_get(db, buf, &(sw->g)); + e_db_int_get(db, buf, &g); snprintf(buf, PATH_MAX, "/swatches/%d/b", i); - e_db_int_get(db, buf, &(sw->b)); - - sw->obj = edje_object_add(el->evas); - sw->rect = evas_object_rectangle_add(el->evas); - - theme = elicit_config_theme_get(el); - edje_object_file_set(sw->obj, - elicit_theme_find(theme), - "swatch"); - free(theme); - - edje_object_size_min_get(sw->obj, &mw, &mh); - if (mw != 0 && mh != 0) - evas_object_resize(sw->obj, mw, mh); - else - evas_object_resize(sw->obj, 12, 12); - - evas_object_show(sw->obj); - evas_object_data_set(sw->obj, "swatch", sw); - evas_object_data_set(sw->obj, "elicit", el); - - edje_object_signal_callback_add(sw->obj, "elicit,swatch,load", "", elicit_swatch_load_cb, sw); - edje_object_signal_callback_add(sw->obj, "elicit,swatch,del", "", elicit_swatch_del_cb, sw); - edje_object_signal_callback_add(sw->obj, "elicit,swatch,name,show", "", elicit_swatch_name_show_cb, sw); - - evas_object_color_set(sw->rect, sw->r, sw->g, sw->b, 255); - evas_object_pass_events_set(sw->rect, 1); - evas_object_show(sw->rect); - edje_object_part_swallow(sw->obj, "swatch", sw->rect); - esmart_container_element_append(el->swatches.cont, sw->obj); + e_db_int_get(db, buf, &b); + + sw = elicit_swatch_new(el, name, r, g, b); } el->swatches.length = esmart_container_elements_length_get(el->swatches.cont); e_db_close(db); @@ -202,19 +359,46 @@ { Elicit *el = data; Elicit_Swatch *sw; - Evas_Coord mw, mh; double length; Evas_Coord w, h; + + sw = elicit_swatch_new(el, el->color.hex, el->color.r, el->color.g, el->color.b); + + /* scroll to the end of the list */ + length = esmart_container_elements_length_get(el->swatches.cont); + el->swatches.length = length; + evas_object_geometry_get(el->swatches.cont, NULL, NULL, &w, &h); + if (el->swatches.dir == CONTAINER_DIRECTION_HORIZONTAL && length > w) + { + esmart_container_scroll_offset_set(el->swatches.cont, + w - length - 10 ); + _elicit_swatches_update_scroll_bar(el); + } + else if (el->swatches.dir == CONTAINER_DIRECTION_VERTICAL && length > h) + { + esmart_container_scroll_offset_set(el->swatches.cont, + h - length - 10 ); + _elicit_swatches_update_scroll_bar(el); + } + + elicit_swatches_save(el); +} + +Elicit_Swatch * +elicit_swatch_new(Elicit *el, char *name, int r, int g, int b) +{ + Elicit_Swatch *sw; char *theme; + Evas_Coord mw, mh; sw = calloc(1, sizeof(Elicit_Swatch)); sw->obj = edje_object_add(el->evas); sw->rect = evas_object_rectangle_add(el->evas); - sw->r = el->color.r; - sw->g = el->color.g; - sw->b = el->color.b; - sw->name = strdup(el->color.hex); + sw->r = r; + sw->g = g; + sw->b = b; + sw->name = strdup(name); theme = elicit_config_theme_get(el); edje_object_file_set(sw->obj, @@ -241,25 +425,8 @@ evas_object_show(sw->rect); edje_object_part_swallow(sw->obj, "swatch", sw->rect); esmart_container_element_append(el->swatches.cont, sw->obj); - - /* scroll to the end of the list */ - length = esmart_container_elements_length_get(el->swatches.cont); - el->swatches.length = length; - evas_object_geometry_get(el->swatches.cont, NULL, NULL, &w, &h); - if (el->swatches.dir == CONTAINER_DIRECTION_HORIZONTAL && length > w) - { - esmart_container_scroll_offset_set(el->swatches.cont, - w - length - 10 ); - _elicit_swatches_update_scroll_bar(el); - } - else if (el->swatches.dir == CONTAINER_DIRECTION_VERTICAL && length > h) - { - esmart_container_scroll_offset_set(el->swatches.cont, - h - length - 10 ); - _elicit_swatches_update_scroll_bar(el); - } - - elicit_swatches_save(el); + + return sw; } void =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/swatches.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -3 -r1.2 -r1.3 --- swatches.h 12 Aug 2004 22:26:30 -0000 1.2 +++ swatches.h 18 Dec 2005 06:53:46 -0000 1.3 @@ -1,8 +1,6 @@ #ifndef ELICIT_SWATCHES_H #define ELICIT_SWATCHES_H -#include <Edb.h> - int elicit_swatches_init(Elicit *el); void elicit_swatches_shutdown(Elicit *el); void elicit_swatches_load(Elicit *el); @@ -10,6 +8,7 @@ void elicit_swatch_free(Elicit_Swatch *sw); +Elicit_Swatch *elicit_swatch_new(Elicit *el, char *name, int r, int g, int b); void elicit_swatch_save_cb(void *data, Evas_Object *o, const char *emission, const char *source); void elicit_swatch_load_cb(void *data, Evas_Object *o, const char *emission, const char *source); void elicit_swatch_del_cb(void *data, Evas_Object *o, const char *emission, const char *source); =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/util.c,v retrieving revision 1.10 retrieving revision 1.11 diff -u -3 -r1.10 -r1.11 --- util.c 5 Sep 2005 19:45:47 -0000 1.10 +++ util.c 18 Dec 2005 06:53:46 -0000 1.11 @@ -8,6 +8,7 @@ void elicit_color_rgb_to_hsv(int rr, int gg, int bb, double *hh, double *ss, double *vv); void elicit_color_hsv_to_rgb(double hh, double ss, double vv, int *rr, int *gg, int *bb); char * elicit_color_rgb_to_hex(int rr, int gg, int bb); +void elicit_color_hex_to_rgb(char *hex, int *rr, int *gg, int *bb); void elicit_util_color_at_pointer_get(int *r, int *g, int *b) @@ -239,6 +240,28 @@ return (char *)strdup(buf); } +void +elicit_color_hex_to_rgb(char *hex, int *rr, int *gg, int *bb) +{ + unsigned int r = 0, g = 0, b = 0; + int len; + int num; + + if (!hex) return; + + len = strlen(hex); + if (len == 7) hex++; + else if (len != 6) return; + + num = sscanf(hex, "%02x%02x%02x", &r, &g, &b); + if (3 == num) + { + if (rr) *rr = r; + if (gg) *gg = g; + if (bb) *bb = b; + } +} + int elicit_glob_match(const char *str, const char *glob) { =================================================================== RCS file: /cvsroot/enlightenment/e17/apps/elicit/src/util.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -3 -r1.4 -r1.5 --- util.h 8 Mar 2005 05:02:13 -0000 1.4 +++ util.h 18 Dec 2005 06:53:46 -0000 1.5 @@ -13,4 +13,6 @@ void elicit_util_shot_save(Elicit *el, const char *filename); +char *elicit_color_rgb_to_hex(int r, int g, int b); +void elicit_color_hex_to_rgb(char *hex, int *r, int *g, int *b); #endif ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs