Rework config loading/saving and remember window size and panel state.
This commit is contained in:
parent
833bd4513d
commit
b0ef804dd4
|
@ -40,7 +40,7 @@ void ephoto_directory_set(Ephoto *ephoto, const char *path);
|
|||
Ephoto_Orient ephoto_file_orient_get(const char *path);
|
||||
|
||||
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);
|
||||
|
||||
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
|
||||
{
|
||||
int config_version;
|
||||
const char *editor;
|
||||
double slideshow_timeout;
|
||||
const char *slideshow_transition;
|
||||
|
||||
/* these should be per-window */
|
||||
int thumb_size;
|
||||
int thumb_gen_size;
|
||||
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
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
#include "ephoto.h"
|
||||
|
||||
#define CONFIG_VERSION 7
|
||||
#define CONFIG_VERSION 8
|
||||
|
||||
static int _ephoto_config_load(Ephoto *ephoto);
|
||||
static Eina_Bool _ephoto_on_config_save(void *data);
|
||||
|
||||
static Eet_Data_Descriptor *edd = NULL;
|
||||
static Ecore_Timer *save_timer = NULL;
|
||||
|
||||
Eina_Bool
|
||||
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_transition, 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))
|
||||
{
|
||||
case 0:
|
||||
/* Start a new config */
|
||||
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_transition = eina_stringshare_add("fade");
|
||||
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;
|
||||
|
||||
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:
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
ephoto_config_save(ephoto, EINA_FALSE);
|
||||
ephoto_config_save(ephoto);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
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);
|
||||
else
|
||||
save_timer = ecore_timer_add(5.0, _ephoto_on_config_save, ephoto);
|
||||
_ephoto_on_config_save(ephoto);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -126,8 +104,12 @@ _ephoto_config_load(Ephoto *ephoto)
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -154,11 +136,5 @@ _ephoto_on_config_save(void *data)
|
|||
save_end:
|
||||
ecore_file_unlink(buf2);
|
||||
|
||||
if (save_timer)
|
||||
{
|
||||
ecore_timer_del(save_timer);
|
||||
save_timer = NULL;
|
||||
}
|
||||
|
||||
return ECORE_CALLBACK_CANCEL;
|
||||
}
|
||||
|
|
|
@ -116,10 +116,24 @@ _win_free(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
|
|||
{
|
||||
Ephoto *ephoto = data;
|
||||
if (ephoto->timer.thumb_regen) ecore_timer_del(ephoto->timer.thumb_regen);
|
||||
ephoto_config_save(ephoto, EINA_TRUE);
|
||||
ephoto_config_save(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 *
|
||||
ephoto_window_add(const char *path)
|
||||
{
|
||||
|
@ -141,6 +155,8 @@ ephoto_window_add(const char *path)
|
|||
|
||||
evas_object_event_callback_add
|
||||
(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);
|
||||
|
||||
|
@ -244,7 +260,7 @@ ephoto_window_add(const char *path)
|
|||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
return ephoto->win;
|
||||
|
@ -410,7 +426,6 @@ ephoto_thumb_size_set(Ephoto *ephoto, int size)
|
|||
INF("thumbnail display size changed from %d to %d",
|
||||
ephoto->config->thumb_size, size);
|
||||
ephoto->config->thumb_size = size;
|
||||
ephoto_config_save(ephoto, EINA_FALSE);
|
||||
}
|
||||
|
||||
if (size <= 128) ephoto->thumb_gen_size = 128;
|
||||
|
|
|
@ -754,6 +754,11 @@ _main_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
|
|||
Ephoto_Single_Browser *sb = data;
|
||||
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)
|
||||
ecore_event_handler_del(handler);
|
||||
if (sb->entry)
|
||||
|
@ -822,7 +827,10 @@ ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent)
|
|||
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_align_set(sb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_panel_hidden_set(sb->panel, EINA_FALSE);
|
||||
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_table_pack(sb->table, sb->panel, 0, 0, 1, 1);
|
||||
evas_object_show(sb->panel);
|
||||
|
||||
|
|
|
@ -289,6 +289,11 @@ _main_del(void *data, Evas *e __UNUSED__, Evas_Object *o __UNUSED__, void *event
|
|||
Ephoto_Thumb_Browser *tb = data;
|
||||
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);
|
||||
_grid_items_free(tb);
|
||||
EINA_LIST_FREE(tb->handlers, handler)
|
||||
|
@ -385,7 +390,7 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
|
|||
evas_object_size_hint_weight_set(tb->main, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
|
||||
evas_object_size_hint_align_set(tb->main, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
evas_object_event_callback_add(tb->main, EVAS_CALLBACK_DEL, _main_del, tb);
|
||||
evas_object_event_callback_add
|
||||
evas_object_event_callback_add
|
||||
(tb->main, EVAS_CALLBACK_KEY_DOWN, _key_down, tb);
|
||||
evas_object_data_set(tb->main, "thumb_browser", tb);
|
||||
|
||||
|
@ -441,10 +446,13 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
|
|||
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_align_set(tb->panel, EVAS_HINT_FILL, EVAS_HINT_FILL);
|
||||
elm_panel_hidden_set(tb->panel, EINA_FALSE);
|
||||
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_table_pack(tb->table, tb->panel, 0, 0, 1, 1);
|
||||
evas_object_show(tb->panel);
|
||||
|
||||
|
||||
tb->bar = elm_toolbar_add(tb->panel);
|
||||
EINA_SAFETY_ON_NULL_GOTO(tb->bar, error);
|
||||
elm_toolbar_horizontal_set(tb->bar, EINA_FALSE);
|
||||
|
|
Loading…
Reference in New Issue