Rework config loading/saving and remember window size and panel state.

This commit is contained in:
Stephen Houston 2014-11-18 21:18:22 -06:00
parent 833bd4513d
commit b0ef804dd4
5 changed files with 64 additions and 56 deletions

View File

@ -40,7 +40,7 @@ void ephoto_directory_set(Ephoto *ephoto, const char *path);
Ephoto_Orient ephoto_file_orient_get(const char *path); Ephoto_Orient ephoto_file_orient_get(const char *path);
Eina_Bool ephoto_config_init(Ephoto *em); Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em, Eina_Bool instant); void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em); void ephoto_config_free(Ephoto *em);
Evas_Object *ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent); Evas_Object *ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent);
@ -91,15 +91,16 @@ enum _Ephoto_Orient /* matches with exif orientation tag */
struct _Ephoto_Config struct _Ephoto_Config
{ {
int config_version; int config_version;
const char *editor;
double slideshow_timeout;
const char *slideshow_transition;
/* these should be per-window */
int thumb_size; int thumb_size;
int thumb_gen_size; int thumb_gen_size;
const char *directory; const char *directory;
double slideshow_timeout;
const char *slideshow_transition;
const char *editor;
int window_width;
int window_height;
int thumb_browser_panel;
int single_browser_panel;
}; };
struct _Ephoto struct _Ephoto

View File

@ -1,12 +1,11 @@
#include "ephoto.h" #include "ephoto.h"
#define CONFIG_VERSION 7 #define CONFIG_VERSION 8
static int _ephoto_config_load(Ephoto *ephoto); static int _ephoto_config_load(Ephoto *ephoto);
static Eina_Bool _ephoto_on_config_save(void *data); static Eina_Bool _ephoto_on_config_save(void *data);
static Eet_Data_Descriptor *edd = NULL; static Eet_Data_Descriptor *edd = NULL;
static Ecore_Timer *save_timer = NULL;
Eina_Bool Eina_Bool
ephoto_config_init(Ephoto *ephoto) ephoto_config_init(Ephoto *ephoto)
@ -37,57 +36,36 @@ ephoto_config_init(Ephoto *ephoto)
C_VAL(D, T, slideshow_timeout, EET_T_DOUBLE); C_VAL(D, T, slideshow_timeout, EET_T_DOUBLE);
C_VAL(D, T, slideshow_transition, EET_T_STRING); C_VAL(D, T, slideshow_transition, EET_T_STRING);
C_VAL(D, T, editor, EET_T_STRING); C_VAL(D, T, editor, EET_T_STRING);
C_VAL(D, T, window_width, EET_T_INT);
C_VAL(D, T, window_height, EET_T_INT);
C_VAL(D, T, thumb_browser_panel, EET_T_INT);
C_VAL(D, T, single_browser_panel, EET_T_INT);
switch (_ephoto_config_load(ephoto)) switch (_ephoto_config_load(ephoto))
{ {
case 0: case 0:
/* Start a new config */ /* Start a new config */
ephoto->config->config_version = CONFIG_VERSION; ephoto->config->config_version = CONFIG_VERSION;
ephoto->config->thumb_size = 256;
ephoto->config->thumb_gen_size = 256;
ephoto->config->slideshow_timeout = 4.0; ephoto->config->slideshow_timeout = 4.0;
ephoto->config->slideshow_transition = eina_stringshare_add("fade"); ephoto->config->slideshow_transition = eina_stringshare_add("fade");
ephoto->config->editor = eina_stringshare_add("gimp %s"); ephoto->config->editor = eina_stringshare_add("gimp %s");
ephoto->config->window_width = 900;
ephoto->config->window_height = 600;
ephoto->config->thumb_browser_panel = 0;
ephoto->config->single_browser_panel = 0;
break; break;
case -1:
/* Incremental additions */
if (ephoto->config->config_version < 2)
{
ephoto->config->slideshow_timeout = 4.0;
ephoto->config->slideshow_transition =
eina_stringshare_add("fade");
}
if (ephoto->config->config_version < 3)
ephoto->config->editor = eina_stringshare_add("gimp %s");
if (ephoto->config->config_version < 5)
ephoto->config->thumb_gen_size = 256;
ephoto->config->config_version = CONFIG_VERSION;
break;
default: default:
return EINA_TRUE; return EINA_TRUE;
} }
ephoto_config_save(ephoto, EINA_FALSE); ephoto_config_save(ephoto);
return EINA_TRUE; return EINA_TRUE;
} }
void void
ephoto_config_save(Ephoto *ephoto, Eina_Bool instant) ephoto_config_save(Ephoto *ephoto)
{ {
if (save_timer)
{
ecore_timer_del(save_timer);
save_timer = NULL;
}
if (instant)
_ephoto_on_config_save(ephoto); _ephoto_on_config_save(ephoto);
else
save_timer = ecore_timer_add(5.0, _ephoto_on_config_save, ephoto);
} }
void void
@ -126,8 +104,12 @@ _ephoto_config_load(Ephoto *ephoto)
} }
if (ephoto->config->config_version < CONFIG_VERSION) if (ephoto->config->config_version < CONFIG_VERSION)
return -1; {
ecore_file_unlink(buf);
ephoto_config_free(ephoto);
ephoto->config = calloc(1, sizeof(Ephoto_Config));
return 0;
}
return 1; return 1;
} }
@ -154,11 +136,5 @@ _ephoto_on_config_save(void *data)
save_end: save_end:
ecore_file_unlink(buf2); ecore_file_unlink(buf2);
if (save_timer)
{
ecore_timer_del(save_timer);
save_timer = NULL;
}
return ECORE_CALLBACK_CANCEL; return ECORE_CALLBACK_CANCEL;
} }

View File

@ -116,10 +116,24 @@ _win_free(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
{ {
Ephoto *ephoto = data; Ephoto *ephoto = data;
if (ephoto->timer.thumb_regen) ecore_timer_del(ephoto->timer.thumb_regen); if (ephoto->timer.thumb_regen) ecore_timer_del(ephoto->timer.thumb_regen);
ephoto_config_save(ephoto, EINA_TRUE); ephoto_config_save(ephoto);
free(ephoto); free(ephoto);
} }
static void
_resize_cb(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event_info __UNUSED__)
{
Ephoto *ephoto = data;
int w, h;
evas_object_geometry_get(ephoto->win, 0, 0, &w, &h);
if (w && h)
{
ephoto->config->window_width = w;
ephoto->config->window_height = h;
}
}
Evas_Object * Evas_Object *
ephoto_window_add(const char *path) ephoto_window_add(const char *path)
{ {
@ -141,6 +155,8 @@ ephoto_window_add(const char *path)
evas_object_event_callback_add evas_object_event_callback_add
(ephoto->win, EVAS_CALLBACK_FREE, _win_free, ephoto); (ephoto->win, EVAS_CALLBACK_FREE, _win_free, ephoto);
evas_object_event_callback_add
(ephoto->win, EVAS_CALLBACK_RESIZE, _resize_cb, ephoto);
elm_win_autodel_set(ephoto->win, EINA_TRUE); elm_win_autodel_set(ephoto->win, EINA_TRUE);
@ -244,7 +260,7 @@ ephoto_window_add(const char *path)
} }
/* TODO restore size from last run as well? */ /* TODO restore size from last run as well? */
evas_object_resize(ephoto->win, 900, 600); evas_object_resize(ephoto->win, ephoto->config->window_width, ephoto->config->window_height);
evas_object_show(ephoto->win); evas_object_show(ephoto->win);
return ephoto->win; return ephoto->win;
@ -410,7 +426,6 @@ ephoto_thumb_size_set(Ephoto *ephoto, int size)
INF("thumbnail display size changed from %d to %d", INF("thumbnail display size changed from %d to %d",
ephoto->config->thumb_size, size); ephoto->config->thumb_size, size);
ephoto->config->thumb_size = size; ephoto->config->thumb_size = size;
ephoto_config_save(ephoto, EINA_FALSE);
} }
if (size <= 128) ephoto->thumb_gen_size = 128; if (size <= 128) ephoto->thumb_gen_size = 128;

View File

@ -754,6 +754,11 @@ _main_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
Ephoto_Single_Browser *sb = data; Ephoto_Single_Browser *sb = data;
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
if (elm_panel_hidden_get(sb->panel))
sb->ephoto->config->single_browser_panel = 1;
else
sb->ephoto->config->single_browser_panel = 0;
EINA_LIST_FREE(sb->handlers, handler) EINA_LIST_FREE(sb->handlers, handler)
ecore_event_handler_del(handler); ecore_event_handler_del(handler);
if (sb->entry) if (sb->entry)
@ -822,6 +827,9 @@ ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent)
elm_panel_orient_set(sb->panel, ELM_PANEL_ORIENT_LEFT); elm_panel_orient_set(sb->panel, ELM_PANEL_ORIENT_LEFT);
evas_object_size_hint_weight_set(sb->panel, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_weight_set(sb->panel, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(sb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_align_set(sb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
if (sb->ephoto->config->single_browser_panel)
elm_panel_hidden_set(sb->panel, EINA_TRUE);
else
elm_panel_hidden_set(sb->panel, EINA_FALSE); elm_panel_hidden_set(sb->panel, EINA_FALSE);
elm_table_pack(sb->table, sb->panel, 0, 0, 1, 1); elm_table_pack(sb->table, sb->panel, 0, 0, 1, 1);
evas_object_show(sb->panel); evas_object_show(sb->panel);

View File

@ -289,6 +289,11 @@ _main_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
Ephoto_Thumb_Browser *tb = data; Ephoto_Thumb_Browser *tb = data;
Ecore_Event_Handler *handler; Ecore_Event_Handler *handler;
if (elm_panel_hidden_get(tb->panel))
tb->ephoto->config->thumb_browser_panel = 1;
else
tb->ephoto->config->thumb_browser_panel = 0;
_todo_items_free(tb); _todo_items_free(tb);
_grid_items_free(tb); _grid_items_free(tb);
EINA_LIST_FREE(tb->handlers, handler) EINA_LIST_FREE(tb->handlers, handler)
@ -441,6 +446,9 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
elm_panel_orient_set(tb->panel, ELM_PANEL_ORIENT_LEFT); elm_panel_orient_set(tb->panel, ELM_PANEL_ORIENT_LEFT);
evas_object_size_hint_weight_set(tb->panel, 0.0, EVAS_HINT_EXPAND); evas_object_size_hint_weight_set(tb->panel, 0.0, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(tb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_align_set(tb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
if (tb->ephoto->config->thumb_browser_panel)
elm_panel_hidden_set(tb->panel, EINA_TRUE);
else
elm_panel_hidden_set(tb->panel, EINA_FALSE); elm_panel_hidden_set(tb->panel, EINA_FALSE);
elm_table_pack(tb->table, tb->panel, 0, 0, 1, 1); elm_table_pack(tb->table, tb->panel, 0, 0, 1, 1);
evas_object_show(tb->panel); evas_object_show(tb->panel);