Ephoto: Add config saving for the slideshow gadget.

master
Stephen Houston 5 years ago
parent ced5750c9b
commit dc500f0c18
  1. 4
      src/bin/ephoto.c
  2. 132
      src/bin/ephoto.h
  3. 175
      src/bin/ephoto_config.c
  4. 22
      src/bin/ephoto_main.c
  5. 18
      src/bin/ephoto_slideshow.c

@ -62,7 +62,7 @@ main(int argc, char *argv[])
}
else if (argc < 2)
{
Evas_Object *win = ephoto_window_add(NULL, gadget);
Evas_Object *win = ephoto_window_add(NULL, gadget, id_num);
if (!win)
{
@ -86,7 +86,7 @@ main(int argc, char *argv[])
r = 1;
goto end;
}
Evas_Object *win = ephoto_window_add(real, gadget);
Evas_Object *win = ephoto_window_add(real, gadget, id_num);
free(real);
if (!win)

@ -38,6 +38,8 @@
/*local types*/
typedef struct _Ephoto_Config Ephoto_Config;
typedef struct _Ephoto_Gadget_Config Ephoto_Gadget_Config;
typedef struct _Ephoto_Gadget_Config_Item Ephoto_Gadget_Config_Item;
typedef struct _Ephoto Ephoto;
typedef struct _Ephoto_Entry Ephoto_Entry;
typedef struct _Ephoto_Event_Entry_Create Ephoto_Event_Entry_Create;
@ -48,7 +50,7 @@ typedef enum _Ephoto_Sort Ephoto_Sort;
typedef enum _Ephoto_Ipc_Domain Ephoto_Ipc_Domain;
/*main window functions*/
Evas_Object *ephoto_window_add(const char *path, int gadget);
Evas_Object *ephoto_window_add(const char *path, int gadget, int id);
void ephoto_title_set(Ephoto *ephoto, const char *title);
void ephoto_thumb_size_set(Ephoto *ephoto, int size);
Evas_Object *ephoto_thumb_add(Ephoto *ephoto, Evas_Object *parent,
@ -59,10 +61,14 @@ void ephoto_directory_set(Ephoto *ephoto, const char *path,
void ephoto_show_folders(Ephoto *ephoto, Eina_Bool toggle);
/*config panel functions*/
Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em);
void ephoto_config_main(Ephoto *em);
Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em);
Eina_Bool ephoto_gadget_config_init(Ephoto *em);
Ephoto_Gadget_Config_Item *ephoto_gadget_config_item_get(Ephoto *em, int id, const char *profile);
void ephoto_gadget_config_save(Ephoto *em);
void ephoto_gadget_config_free(Ephoto *em);
void ephoto_config_main(Ephoto *em);
/*single image functions*/
Evas_Object *ephoto_single_browser_add(Ephoto *ephoto, Evas_Object *parent);
@ -251,68 +257,84 @@ struct _Ephoto_Config
Evas_Object *panel_size;
};
struct _Ephoto_Gadget_Config
{
int config_version;
Eina_List *config_items;
};
struct _Ephoto_Gadget_Config_Item
{
int id;
const char *profile;
const char *directory;
double slideshow_timeout;
};
struct _Ephoto
{
Evas_Object *win;
Evas_Object *main;
Evas_Object *layout;
Evas_Object *pager;
Evas_Object *statusbar;
Evas_Object *folders_button;
Evas_Object *folders_icon;
Evas_Object *view_button;
Evas_Object *controls_left;
Evas_Object *controls_right;
Evas_Object *infolabel;
Evas_Object *exit;
Evas_Object *thumb_browser;
Evas_Object *single_browser;
Evas_Object *slideshow;
Evas_Object *dir_browser;
Evas_Object *file_popup;
Eina_Bool folders_toggle;
Eina_Bool thumb_browser_dirty;
Eina_List *entries;
Eina_List *selentries;
Eina_List *searchentries;
Eina_List *thumbs;
Eio_Monitor *monitor;
Eina_List *monitor_handlers;
Eina_List *file_pos;
Eina_List *upload_handlers;
Ecore_Thread *file_thread;
Ecore_Con_Url *url_up;
char *url_ret;
char *upload_error;
int file_errors;
const char *top_directory;
const char *config_path;
const char *trash_path;
const char *destination;
int thumb_gen_size;
int gadget;
Evas_Object *win;
Evas_Object *main;
Evas_Object *layout;
Evas_Object *pager;
Evas_Object *statusbar;
Evas_Object *folders_button;
Evas_Object *folders_icon;
Evas_Object *view_button;
Evas_Object *controls_left;
Evas_Object *controls_right;
Evas_Object *infolabel;
Evas_Object *exit;
Evas_Object *thumb_browser;
Evas_Object *single_browser;
Evas_Object *slideshow;
Evas_Object *dir_browser;
Evas_Object *file_popup;
Eina_Bool folders_toggle;
Eina_Bool thumb_browser_dirty;
Eina_List *entries;
Eina_List *selentries;
Eina_List *searchentries;
Eina_List *thumbs;
Eio_Monitor *monitor;
Eina_List *monitor_handlers;
Eina_List *file_pos;
Eina_List *upload_handlers;
Ecore_Thread *file_thread;
Ecore_Con_Url *url_up;
char *url_ret;
char *upload_error;
int file_errors;
const char *top_directory;
const char *config_path;
const char *trash_path;
const char *destination;
int thumb_gen_size;
int gadget;
struct
{
Ecore_Timer *thumb_regen;
Ecore_Timer *thumb_regen;
} timer;
struct
{
Ecore_Job *change_dir;
Ecore_Job *change_dir;
} job;
Eio_File *ls;
Eio_File *ls;
Evas_Object *prefs_win;
Ephoto_State state, prev_state;
Evas_Object *prefs_win;
Ephoto_State state, prev_state;
Ephoto_Config *config;
Ephoto_Sort sort;
Ephoto_Config *config;
Ephoto_Gadget_Config *gadget_config;
Ephoto_Gadget_Config_Item *gci;
Ephoto_Sort sort;
};
struct _Ephoto_Entry

@ -4,8 +4,12 @@
static int _ephoto_config_load(Ephoto *ephoto);
static Eina_Bool _ephoto_on_config_save(void *data);
static int _ephoto_gadget_config_load(Ephoto *ephoto);
static Eina_Bool _ephoto_gadget_on_config_save(void *data);
static Eet_Data_Descriptor *edd = NULL;
static Eet_Data_Descriptor *gedd = NULL;
static Eet_Data_Descriptor *gedds = NULL;
static void
_config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
@ -760,6 +764,8 @@ ephoto_config_save(Ephoto *ephoto)
void
ephoto_config_free(Ephoto *ephoto)
{
eina_stringshare_del(ephoto->config->directory);
eina_stringshare_del(ephoto->config->slideshow_transition);
free(ephoto->config);
ephoto->config = NULL;
}
@ -834,3 +840,172 @@ ephoto_config_init(Ephoto *ephoto)
return EINA_TRUE;
}
static int
_ephoto_gadget_config_load(Ephoto *ephoto)
{
Eet_File *ef;
char buf[4096], buf2[4096];
snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get());
ecore_file_mkpath(buf2);
snprintf(buf, sizeof(buf), "%s/ephoto_gadget.cfg", buf2);
ef = eet_open(buf, EET_FILE_MODE_READ);
if (!ef)
{
ephoto_gadget_config_free(ephoto);
ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
return 0;
}
ephoto->gadget_config = eet_data_read(ef, gedd, "gadget_config");
eet_close(ef);
if (!ephoto->gadget_config || ephoto->gadget_config->config_version > CONFIG_VERSION)
{
ephoto_gadget_config_free(ephoto);
ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
return 0;
}
if (ephoto->gadget_config->config_version < CONFIG_VERSION)
{
ecore_file_unlink(buf);
ephoto_gadget_config_free(ephoto);
ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
return 0;
}
return 1;
}
static Eina_Bool
_ephoto_gadget_on_config_save(void *data)
{
Ephoto *ephoto = data;
Eet_File *ef;
char buf[4096], buf2[4096];
snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.cfg", efreet_config_home_get());
snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
ef = eet_open(buf2, EET_FILE_MODE_WRITE);
if (!ef)
goto save_end;
eet_data_write(ef, gedd, "gadget_config", ephoto->gadget_config, 1);
if (eet_close(ef))
goto save_end;
if (!ecore_file_mv(buf2, buf))
goto save_end;
save_end:
ecore_file_unlink(buf2);
return ECORE_CALLBACK_CANCEL;
}
void
ephoto_gadget_config_save(Ephoto *ephoto)
{
_ephoto_gadget_on_config_save(ephoto);
}
void
ephoto_gadget_config_free(Ephoto *ephoto)
{
Ephoto_Gadget_Config_Item *gci;
if (ephoto->gadget_config)
{
if (eina_list_count(ephoto->gadget_config->config_items))
{
EINA_LIST_FREE(ephoto->gadget_config->config_items, gci)
{
eina_stringshare_del(gci->profile);
eina_stringshare_del(gci->directory);
free(gci);
}
}
free(ephoto->gadget_config);
}
ephoto->gadget_config = NULL;
}
Ephoto_Gadget_Config_Item *
ephoto_gadget_config_item_get(Ephoto *ephoto, int id, const char *profile)
{
Eina_List *l;
Ephoto_Gadget_Config_Item *gci;
EINA_LIST_FOREACH(ephoto->gadget_config->config_items, l, gci)
{
if (gci->id == id && eina_streq(profile, gci->profile))
return gci;
}
gci = calloc(1, sizeof(Ephoto_Gadget_Config_Item));
gci->id = id;
gci->profile = eina_stringshare_add(profile);
gci->directory = eina_stringshare_add(eina_environment_home_get());;
gci->slideshow_timeout = 3;
ephoto->gadget_config->config_items =
eina_list_append(ephoto->gadget_config->config_items, gci);
return gci;
}
Eina_Bool
ephoto_gadget_config_init(Ephoto *ephoto)
{
Eet_Data_Descriptor_Class geddc;
if (!eet_eina_stream_data_descriptor_class_set(&geddc, sizeof(geddc),
"Ephoto_Gadget_Config", sizeof(Ephoto_Gadget_Config)))
{
return EINA_FALSE;
}
if (!gedd)
gedd = eet_data_descriptor_stream_new(&geddc);
if (!eet_eina_stream_data_descriptor_class_set(&geddc, sizeof(geddc),
"Ephoto_Gadget_Config_Item", sizeof(Ephoto_Gadget_Config_Item)))
{
return EINA_FALSE;
}
if (!gedds)
gedds = eet_data_descriptor_stream_new(&geddc);
#undef GT
#undef GD
#define GT Ephoto_Gadget_Config
#define GD gedd
#define GST Ephoto_Gadget_Config_Item
#define GS gedds
#define GC_VAL(gedd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(gedd, type, #member, member, dtype)
#define GCS_VAL(edds, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(gedds, type, #member, member, dtype)
GCS_VAL(GS, GST, id, EET_T_INT);
GCS_VAL(GS, GST, profile, EET_T_STRING);
GCS_VAL(GS, GST, directory, EET_T_STRING);
GCS_VAL(GS, GST, slideshow_timeout, EET_T_DOUBLE);
GC_VAL(GD, GT, config_version, EET_T_INT);
EET_DATA_DESCRIPTOR_ADD_LIST(gedd, Ephoto_Gadget_Config, "config_items", config_items, gedds);
switch (_ephoto_gadget_config_load(ephoto))
{
case 0:
/* Start a new config */
ephoto->gadget_config->config_version = CONFIG_VERSION;
break;
default:
return EINA_TRUE;
}
ephoto_gadget_config_save(ephoto);
return EINA_TRUE;
}

@ -251,6 +251,10 @@ _win_free(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
ephoto_entries_free(ephoto);
if (!ephoto->gadget)
ephoto_config_save(ephoto);
else
ephoto_gadget_config_save(ephoto);
if (ephoto->gadget_config)
ephoto_config_free(ephoto);
free(ephoto->config);
free(ephoto);
}
@ -369,7 +373,7 @@ ephoto_show_folders(Ephoto *ephoto, Eina_Bool toggle)
}
Evas_Object *
ephoto_window_add(const char *path, int gadget)
ephoto_window_add(const char *path, int gadget, int id)
{
Ephoto *ephoto = calloc(1, sizeof(Ephoto));
Evas_Object *ic, *but;
@ -419,6 +423,18 @@ ephoto_window_add(const char *path, int gadget)
evas_object_del(ephoto->win);
return NULL;
}
if (ephoto->gadget)
{
const char *profile;
if (!ephoto_gadget_config_init(ephoto))
{
evas_object_del(ephoto->win);
return NULL;
}
profile = elm_config_profile_get();
ephoto->gci = ephoto_gadget_config_item_get(ephoto, id, profile);
}
if ((ephoto->config->thumb_gen_size != 128) &&
(ephoto->config->thumb_gen_size != 256) &&
@ -685,6 +701,10 @@ ephoto_window_add(const char *path, int gadget)
ephoto->config->firstrun = 0;
}
}
else
{
ephoto_directory_set(ephoto, ephoto->gci->directory, NULL, EINA_FALSE, EINA_TRUE);
}
return ephoto->win;
}

@ -382,7 +382,10 @@ _on_transition_end(void *data, Evas_Object *obj EINA_UNUSED,
evas_object_show(ss->current_item);
elm_layout_signal_emit(ss->slideshow, "ephoto,transition,done", "ephoto");
ss->timeout = ss->ephoto->config->slideshow_timeout;
if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout;
else
ss->timeout = ss->ephoto->gci->slideshow_timeout;
if (ss->timer)
ecore_timer_del(ss->timer);
ss->timer = NULL;
@ -809,11 +812,13 @@ _gadget_settings_save(void *data, Evas_Object *obj EINA_UNUSED,
fentry = evas_object_data_get(popup, "fentry");
spinner = evas_object_data_get(popup, "timeout");
ss->ephoto->config->slideshow_timeout = elm_spinner_value_get(spinner);
ss->ephoto->gci->slideshow_timeout = elm_spinner_value_get(spinner);
path = elm_fileselector_path_get(fentry);
eina_stringshare_replace(&ss->ephoto->gci->directory, path);
if (ecore_file_is_dir(path))
ephoto_directory_set(ss->ephoto, path, NULL, EINA_FALSE, EINA_TRUE);
ephoto_gadget_config_save(ss->ephoto);
evas_object_del(popup);
}
@ -839,7 +844,7 @@ _gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
fentry = elm_fileselector_add(table);
elm_fileselector_is_save_set(fentry, EINA_FALSE);
elm_fileselector_expandable_set(fentry, EINA_FALSE);
elm_fileselector_path_set(fentry, ss->ephoto->config->directory);
elm_fileselector_path_set(fentry, ss->ephoto->gci->directory);
elm_fileselector_buttons_ok_cancel_set(fentry, EINA_FALSE);
elm_fileselector_folder_only_set(fentry, EINA_TRUE);
evas_object_size_hint_weight_set(fentry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
@ -862,7 +867,7 @@ _gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
snprintf(buf, PATH_MAX, "%%1.0f %s", _("seconds"));
elm_spinner_label_format_set(spinner, buf);
elm_spinner_step_set(spinner, 1);
elm_spinner_value_set(spinner, ss->ephoto->config->slideshow_timeout);
elm_spinner_value_set(spinner, ss->ephoto->gci->slideshow_timeout);
elm_spinner_min_max_set(spinner, 1, 60);
elm_table_pack(table, spinner, 1, 5, 1, 1);
evas_object_show(spinner);
@ -1131,7 +1136,10 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
if (entry)
ephoto_entry_free_listener_add(entry, _entry_free, ss);
ss->timeout = ss->ephoto->config->slideshow_timeout;
if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout;
else
ss->timeout = ss->ephoto->gci->slideshow_timeout;
_slideshow_play(ss);
ss->playing = 1;

Loading…
Cancel
Save