From cdb8b51c3fe494ee7b80f9332a12655395bfae65 Mon Sep 17 00:00:00 2001 From: Viktor Kojouharov Date: Mon, 13 Sep 2010 22:24:59 +0000 Subject: [PATCH] eet configuration. only stores the slider value for now. eina log domain macros SVN revision: 52201 --- configure.ac | 14 ++++ src/bin/Makefile.am | 5 +- src/bin/ephoto.c | 20 ++++++ src/bin/ephoto.h | 31 ++++++-- src/bin/ephoto_config.c | 127 +++++++++++++++++++++++++++++++++ src/bin/ephoto_main.c | 3 + src/bin/ephoto_thumb_browser.c | 29 +++----- 7 files changed, 203 insertions(+), 26 deletions(-) create mode 100644 src/bin/ephoto_config.c diff --git a/configure.ac b/configure.ac index 70d5394..8a768ff 100644 --- a/configure.ac +++ b/configure.ac @@ -15,6 +15,8 @@ AM_PROG_LIBTOOL AM_WITH_DMALLOC +m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) + dnl Set PACKAGE_LOCALE_DIR in config.h. if test "x$LIBINTL" = "x"; then LIBINTL="$INTLLIBS" @@ -65,6 +67,17 @@ dnl Set PACKAGE_SOURCE_DIR in config.h. packagesrcdir=`cd $srcdir && pwd` AC_DEFINE_UNQUOTED(PACKAGE_SOURCE_DIR, "${packagesrcdir}", [Source code directory]) +PKG_CHECK_MODULES([EET], eet, + [ + have_eet="Yes" + ], + [ + have_eet="No" + echo "Eet was not found by pkg-config!"; + AC_MSG_ERROR([Ephoto needs eet to compile.]) + ] +) + PKG_CHECK_MODULES([EVAS], evas, [ have_evas="Yes" @@ -197,6 +210,7 @@ echo "------------------------------------------------------------------------" echo echo "Configuration Options Summary:" echo +echo " Eet .............: $have_eet" echo " Evas ............: $have_evas" echo " Ecore_File.......: $have_ecoref" echo " Ecore_Evas.......: $have_ecoree" diff --git a/src/bin/Makefile.am b/src/bin/Makefile.am index c36cb34..d3e7065 100644 --- a/src/bin/Makefile.am +++ b/src/bin/Makefile.am @@ -8,11 +8,12 @@ bin_PROGRAMS = ephoto ephoto_SOURCES = \ ephoto.c \ ephoto.h \ + ephoto_config.c \ ephoto_flow_browser.c \ ephoto_main.c \ ephoto_slideshow.c \ ephoto_thumb_browser.c -ephoto_CFLAGS = @EVAS_CFLAGS@ @EDJE_CFLAGS@ @EINA_CFLAGS@ @EFREET_MIME_CFLAGS@ @ETHUMB_CFLAGS@ @ELEMENTARY_CFLAGS@ @EIO_CFLAGS@ -Wall -g -ephoto_LDADD = @EVAS_CFLAGS@ @EDJE_CFLAGS@ @EINA_LIBS@ @EFREET_MIME_LIBS@ @ETHUMB_LIBS@ @ELEMENTARY_LIBS@ @EIO_LIBS@ +ephoto_CFLAGS = @EET_CFLAGS@ @EVAS_CFLAGS@ @EDJE_CFLAGS@ @EINA_CFLAGS@ @EFREET_MIME_CFLAGS@ @ETHUMB_CFLAGS@ @ELEMENTARY_CFLAGS@ @EIO_CFLAGS@ -Wall -g +ephoto_LDADD = @EET_LIBS@ @EVAS_LIBS@ @EDJE_LIBS@ @EINA_LIBS@ @EFREET_MIME_LIBS@ @ETHUMB_LIBS@ @ELEMENTARY_LIBS@ @EIO_LIBS@ diff --git a/src/bin/ephoto.c b/src/bin/ephoto.c index 5fdb661..bb10f29 100644 --- a/src/bin/ephoto.c +++ b/src/bin/ephoto.c @@ -2,6 +2,9 @@ static void _ephoto_display_usage(void); +/* Global log domain pointer */ +int __log_domain = -1; + int main(int argc, char **argv) { @@ -9,11 +12,25 @@ main(int argc, char **argv) elm_need_efreet(); elm_init(argc, argv); + __log_domain = eina_log_domain_register("Ephoto", EINA_COLOR_BLUE); + if (!__log_domain) + { + EINA_LOG_ERR("Could not register log domain: Ephoto"); + elm_shutdown(); + efreet_mime_shutdown(); + ethumb_client_shutdown(); + + return 0; + } + + + DBG("Logging initialized"); if (argc > 2) { printf("Too Many Arguments!\n"); _ephoto_display_usage(); + eina_log_domain_unregister(__log_domain); elm_shutdown(); efreet_mime_shutdown(); ethumb_client_shutdown(); @@ -28,6 +45,7 @@ main(int argc, char **argv) { _ephoto_display_usage(); + eina_log_domain_unregister(__log_domain); elm_shutdown(); efreet_mime_shutdown(); ethumb_client_shutdown(); @@ -46,12 +64,14 @@ main(int argc, char **argv) image = eina_stringshare_add(argv[1]); directory = ecore_file_dir_get(argv[1]); ephoto_create_main_window(directory, image); + free(directory); } else { printf("Incorrect Argument!\n"); _ephoto_display_usage(); + eina_log_domain_unregister(__log_domain); elm_shutdown(); efreet_mime_shutdown(); ethumb_client_shutdown(); diff --git a/src/bin/ephoto.h b/src/bin/ephoto.h index 32a453c..dfb6145 100644 --- a/src/bin/ephoto.h +++ b/src/bin/ephoto.h @@ -5,6 +5,7 @@ #define _GNU_SOURCE #endif +#include #include #include #include @@ -22,9 +23,19 @@ #include #include "config.h" +typedef struct _Ephoto_Config Ephoto_Config; +typedef struct _Ephoto Ephoto; + +typedef enum _Ephoto_State Ephoto_State; + /*Main Functions*/ void ephoto_create_main_window(const char *directory, const char *image); +/* Configuration */ +Eina_Bool ephoto_config_init(Ephoto *em); +void ephoto_config_save(Ephoto *em); +void ephoto_config_free(Ephoto *em); + /*Ephoto Flow Browser*/ Evas_Object *ephoto_create_flow_browser(Evas_Object *parent); void ephoto_flow_browser_image_set(Evas_Object *obj, const char *current_image); @@ -47,8 +58,6 @@ void ephoto_populate_thumbnails(Evas_Object *obj); * "directory,changed" - the user selected a new directory. The selected directory is passed as event_info argument. */ -typedef enum _Ephoto_State Ephoto_State; - /* Enum for the state machine */ enum _Ephoto_State { @@ -57,6 +66,13 @@ enum _Ephoto_State EPHOTO_STATE_SLIDESHOW }; +struct _Ephoto_Config +{ + int config_version; + + int thumb_size; +}; + /*Ephoto Main Structure*/ struct _Ephoto { @@ -70,10 +86,17 @@ struct _Ephoto Eina_List *images; Ephoto_State state; const char *cur_directory; + + Ephoto_Config *config; + + Eet_Data_Descriptor *config_edd; + Ecore_Timer *config_save; }; -typedef struct _Ephoto Ephoto; extern Ephoto *em; -#endif +extern int __log_domain; +#define DBG(...) EINA_LOG_DOM_DBG(__log_domain, __VA_ARGS__) +#define ERR(...) EINA_LOG_DOM_ERR(__log_domain, __VA_ARGS__) +#endif diff --git a/src/bin/ephoto_config.c b/src/bin/ephoto_config.c new file mode 100644 index 0000000..3d7d669 --- /dev/null +++ b/src/bin/ephoto_config.c @@ -0,0 +1,127 @@ +#include "ephoto.h" + +#define CONFIG_VERSION 1 + +static int _ephoto_config_load(Ephoto *em); +static Eina_Bool _ephoto_on_config_save(void *data); + +Eina_Bool +ephoto_config_init(Ephoto *em) +{ + Eet_Data_Descriptor_Class eddc; + + if (!eet_eina_file_data_descriptor_class_set(&eddc, sizeof (eddc), "Ephoto_Config", sizeof(Ephoto_Config))) + { + ERR("Unable to create the config data descriptor!"); + return EINA_FALSE; + } + + em->config_edd = eet_data_descriptor_file_new(&eddc); +#undef T +#undef D +#define T Ephoto_Config +#define D em->config_edd +#define C_VAL(edd, type, member, dtype) EET_DATA_DESCRIPTOR_ADD_BASIC(edd, type, #member, member, dtype) + C_VAL(D, T, config_version, EET_T_INT); + C_VAL(D, T, thumb_size, EET_T_INT); + + switch (_ephoto_config_load(em)) + { + case 0: + /* Start a new config */ + em->config->config_version = CONFIG_VERSION; + em->config->thumb_size = 256; + break; + case -1: + /* Incremental additions */ + em->config->config_version = CONFIG_VERSION; + break; + default: + return EINA_TRUE; + } + ephoto_config_save(em); + return EINA_TRUE; +} + +void +ephoto_config_save(Ephoto *em) +{ + if (em->config_save) + ecore_timer_del(em->config_save); + em->config_save = ecore_timer_add(5, _ephoto_on_config_save, em); +} + +void +ephoto_config_free(Ephoto *em) +{ + free(em->config); + em->config = NULL; +} + +static int +_ephoto_config_load(Ephoto *em) +{ + Eet_File *ef; + char buf[4096], buf2[4096]; + + snprintf(buf2, sizeof(buf2), "%s/.config/ephoto", getenv("HOME")); + ecore_file_mkpath(buf2); + snprintf(buf, sizeof(buf), "%s/ephoto.cfg", buf2); + + ef = eet_open(buf, EET_FILE_MODE_READ); + if (!ef) + { + ephoto_config_free(em); + em->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } + + em->config = eet_data_read(ef, em->config_edd, "config"); + eet_close(ef); + + if (em->config->config_version > CONFIG_VERSION) + { + ephoto_config_free(em); + em->config = calloc(1, sizeof(Ephoto_Config)); + return 0; + } + + if (em->config->config_version < CONFIG_VERSION) + return -1; + + return 1; +} + +static Eina_Bool +_ephoto_on_config_save(void *data) +{ + Ephoto *em = data; + Eet_File *ef; + char buf[4096], buf2[4096]; + int ret; + + snprintf(buf, sizeof(buf), "%s/.config/ephoto/ephoto.cfg", getenv("HOME")); + snprintf(buf2, sizeof(buf2), "%s.tmp", buf); + + ef = eet_open(buf2, EET_FILE_MODE_WRITE); + if (ef) + { + eet_data_write(ef, em->config_edd, "config", em->config, 1); + + if (eet_close(ef)) + goto save_end; + + ret = ecore_file_mv(buf2, buf); + if (!ret) + goto save_end; + + DBG("Config saved"); + ecore_file_unlink(buf2); + } + +save_end: + if (em->config_save) + ecore_timer_del(em->config_save); + em->config_save = NULL; + return ECORE_CALLBACK_CANCEL; +} diff --git a/src/bin/ephoto_main.c b/src/bin/ephoto_main.c index 5d3713a..9a49fa2 100644 --- a/src/bin/ephoto_main.c +++ b/src/bin/ephoto_main.c @@ -56,6 +56,8 @@ void ephoto_create_main_window(const char *directory, const char *image) { em = calloc(1, sizeof(Ephoto)); + if (!ephoto_config_init(em)) + _ephoto_delete_main_window(NULL, NULL, NULL); /*Setup the main window*/ em->win = elm_win_add(NULL, "ephoto", ELM_WIN_BASIC); @@ -133,6 +135,7 @@ _ephoto_delete_main_window(void *data, Evas_Object *obj, void *event_info) evas_object_del(em->bg); if (em->images) eina_list_free(em->images); + ephoto_config_free(em); free(em); elm_exit(); } diff --git a/src/bin/ephoto_thumb_browser.c b/src/bin/ephoto_thumb_browser.c index 4cee689..dbe2124 100644 --- a/src/bin/ephoto_thumb_browser.c +++ b/src/bin/ephoto_thumb_browser.c @@ -21,10 +21,10 @@ struct _Ephoto_Thumb_Browser Elm_Gengrid_Item_Class eg; Ethumb_Client *ec; const char *current_directory; - int cur_val; Eio_File *list; }; +#define THUMB_RATIO (256 / 192) /*Callbacks*/ static void _ephoto_slider_changed(void *data, Evas_Object *obj, void *event_info); @@ -92,8 +92,8 @@ ephoto_create_thumb_browser(Evas_Object *parent, const char *directory) tb->thumb_slider = elm_slider_add(tb->thbox); elm_slider_label_set(tb->thumb_slider, "Thumb Size:"); elm_slider_span_size_set(tb->thumb_slider, 100); - elm_slider_min_max_set(tb->thumb_slider, 0, 100); - elm_slider_value_set(tb->thumb_slider, 50); + elm_slider_min_max_set(tb->thumb_slider, 80, 300); + elm_slider_value_set(tb->thumb_slider, em->config->thumb_size); elm_box_pack_end(tb->thbox, tb->thumb_slider); evas_object_smart_callback_add(tb->thumb_slider, "changed", _ephoto_slider_changed, tb); @@ -102,7 +102,7 @@ ephoto_create_thumb_browser(Evas_Object *parent, const char *directory) tb->thumb_browser = elm_gengrid_add(tb->layout); elm_gengrid_align_set(tb->thumb_browser, 0.5, 0.5); - elm_gengrid_item_size_set(tb->thumb_browser, 256, 192); + elm_gengrid_item_size_set(tb->thumb_browser, em->config->thumb_size, em->config->thumb_size / THUMB_RATIO); elm_gengrid_horizontal_set(tb->thumb_browser, EINA_TRUE); evas_object_size_hint_align_set(tb->thumb_browser, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(tb->thumb_browser, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); @@ -138,8 +138,6 @@ ephoto_create_thumb_browser(Evas_Object *parent, const char *directory) elm_icon_file_set(o, PACKAGE_DATA_DIR "/images/play_slideshow.png", NULL); elm_toolbar_item_add(tb->toolbar, o, "Play Slideshow", _ephoto_view_slideshow, tb); - tb->cur_val = 50; - tb->eg.item_style = "ephoto"; tb->eg.func.label_get = _ephoto_get_label; tb->eg.func.icon_get = _ephoto_get_icon; @@ -261,23 +259,14 @@ ephoto_populate_thumbnails(Evas_Object *obj) static void _ephoto_slider_changed(void *data, Evas_Object *obj, void *event) { - int w, h, val; + int val; Ephoto_Thumb_Browser *tb = data; val = elm_slider_value_get(tb->thumb_slider); - elm_gengrid_item_size_get(tb->thumb_browser, &w, &h); - if (val < tb->cur_val) - { - w -= tb->cur_val-val; - h -= tb->cur_val-val; - } - else if (val > tb->cur_val) - { - w += val-tb->cur_val; - h += val-tb->cur_val; - } - elm_gengrid_item_size_set(tb->thumb_browser, w, h); - tb->cur_val = val; + elm_gengrid_item_size_set(tb->thumb_browser, val, val / THUMB_RATIO); + + em->config->thumb_size = val; + ephoto_config_save(em); } /*Callback when the client is connected*/