Ephoto: Rework the gadget config to support multiple instances better. Always show settings icon when no pictures exists. Delete gadget win/popup on hide.

master
Stephen Houston 5 years ago
parent c9fbad5399
commit d0ec29d753
  1. 3
      data/desktop/slideshow.desktop
  2. 13
      src/bin/ephoto.h
  3. 128
      src/bin/ephoto_config.c
  4. 23
      src/bin/ephoto_main.c
  5. 43
      src/bin/ephoto_slideshow.c

@ -4,3 +4,6 @@ Type=Application
Name=Slideshow
Icon=ephoto
Exec=ephoto
X-Gadget-Version=1.5
X-Gadget-Bugreport=https://www.enlightenment.org/contrib/report-bug
X-Gadget-Orientations=None

@ -40,7 +40,6 @@
/*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;
@ -65,9 +64,9 @@ void ephoto_show_folders(Ephoto *ephoto, Eina_Bool toggle);
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);
Eina_Bool ephoto_gadget_config_init(Ephoto *em, int id, const char *profile);
void ephoto_gadget_config_save(Ephoto *em);
void ephoto_gadget_config_remove(Ephoto *em);
void ephoto_gadget_config_free(Ephoto *em);
void ephoto_config_main(Ephoto *em);
@ -261,17 +260,12 @@ struct _Ephoto_Config
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;
@ -334,7 +328,6 @@ struct _Ephoto
Ephoto_Config *config;
Ephoto_Gadget_Config *gadget_config;
Ephoto_Gadget_Config_Item *gci;
Ephoto_Sort sort;
};

@ -4,12 +4,11 @@
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 int _ephoto_gadget_config_load(Ephoto *ephoto, int id, const char *profile);
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,
@ -849,26 +848,29 @@ ephoto_config_init(Ephoto *ephoto)
}
static int
_ephoto_gadget_config_load(Ephoto *ephoto)
_ephoto_gadget_config_load(Ephoto *ephoto, int id, const char *profile)
{
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)
if (id >= 0)
{
ephoto_gadget_config_free(ephoto);
ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config));
return 0;
}
snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get());
ecore_file_mkpath(buf2);
snprintf(buf, sizeof(buf), "%s/ephoto_gadget.%d.%s.cfg", buf2, id, profile);
ephoto->gadget_config = eet_data_read(ef, gedd, "gadget_config");
eet_close(ef);
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);
return 1;
}
if (!ephoto->gadget_config || ephoto->gadget_config->config_version > CONFIG_VERSION)
{
ephoto_gadget_config_free(ephoto);
@ -893,20 +895,21 @@ _ephoto_gadget_on_config_save(void *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;
if (ephoto->gadget_config->id >= 0)
{
snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
ephoto->gadget_config->id, ephoto->gadget_config->profile);
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);
@ -922,48 +925,33 @@ ephoto_gadget_config_save(Ephoto *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);
}
}
eina_stringshare_del(ephoto->gadget_config->profile);
eina_stringshare_del(ephoto->gadget_config->directory);
free(ephoto->gadget_config);
}
ephoto->gadget_config = NULL;
}
Ephoto_Gadget_Config_Item *
ephoto_gadget_config_item_get(Ephoto *ephoto, int id, const char *profile)
void
ephoto_gadget_config_remove(Ephoto *ephoto)
{
Eina_List *l;
Ephoto_Gadget_Config_Item *gci;
char buf[4096];
EINA_LIST_FOREACH(ephoto->gadget_config->config_items, l, gci)
printf("%d x %s\n", ephoto->gadget_config->id, ephoto->gadget_config->profile);
if (ephoto->gadget_config->id >= 0)
{
if (gci->id == id && eina_streq(profile, gci->profile))
return gci;
snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
ephoto->gadget_config->id, ephoto->gadget_config->profile);
printf("%s\n", buf);
ecore_file_unlink(buf);
}
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)
ephoto_gadget_config_init(Ephoto *ephoto, int id, const char *profile)
{
Eet_Data_Descriptor_Class geddc;
@ -974,39 +962,29 @@ ephoto_gadget_config_init(Ephoto *ephoto)
}
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, id, EET_T_INT);
GC_VAL(GD, GT, profile, EET_T_STRING);
GC_VAL(GD, GT, directory, EET_T_STRING);
GC_VAL(GD, GT, 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))
switch (_ephoto_gadget_config_load(ephoto, id, profile))
{
case 0:
/* Start a new config */
ephoto->gadget_config->config_version = CONFIG_VERSION;
ephoto->gadget_config->id = id;
ephoto->gadget_config->profile = eina_stringshare_add(profile);
ephoto->gadget_config->directory = eina_stringshare_add(eina_environment_home_get());;
ephoto->gadget_config->slideshow_timeout = 3;
break;
default:

@ -251,8 +251,6 @@ _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);
@ -372,6 +370,19 @@ ephoto_show_folders(Ephoto *ephoto, Eina_Bool toggle)
}
}
static Eina_Bool
_gadget_removed_cb(void *data, int type EINA_UNUSED, void *event_data)
{
Ecore_Event_Signal_User *user = event_data;
Ephoto *ephoto = data;
if (user->number == 2)
{
ephoto_gadget_config_remove(ephoto);
}
return EINA_TRUE;
}
Evas_Object *
ephoto_window_add(const char *path, int gadget, int id)
{
@ -405,6 +416,7 @@ ephoto_window_add(const char *path, int gadget, int id)
elm_win_title_set(ephoto->win, "Ephoto");
elm_win_alpha_set(ephoto->win, 1);
evas_object_size_hint_aspect_set(ephoto->win, EVAS_ASPECT_CONTROL_BOTH, 1,1);
ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER, _gadget_removed_cb, ephoto);
}
if (!ephoto->win)
{
@ -427,13 +439,12 @@ ephoto_window_add(const char *path, int gadget, int id)
{
const char *profile;
if (!ephoto_gadget_config_init(ephoto))
profile = elm_config_profile_get();
if (!ephoto_gadget_config_init(ephoto, id, profile))
{
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) &&
@ -703,7 +714,7 @@ ephoto_window_add(const char *path, int gadget, int id)
}
else
{
ephoto_directory_set(ephoto, ephoto->gci->directory, NULL, EINA_FALSE, EINA_TRUE);
ephoto_directory_set(ephoto, ephoto->gadget_config->directory, NULL, EINA_FALSE, EINA_TRUE);
}
return ephoto->win;
}

@ -385,7 +385,7 @@ _on_transition_end(void *data, Evas_Object *obj EINA_UNUSED,
if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout;
else
ss->timeout = ss->ephoto->gci->slideshow_timeout;
ss->timeout = ss->ephoto->gadget_config->slideshow_timeout;
if (ss->timer)
ecore_timer_del(ss->timer);
ss->timer = NULL;
@ -812,9 +812,9 @@ _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->gci->slideshow_timeout = elm_spinner_value_get(spinner);
ss->ephoto->gadget_config->slideshow_timeout = elm_spinner_value_get(spinner);
path = elm_fileselector_path_get(fentry);
eina_stringshare_replace(&ss->ephoto->gci->directory, path);
eina_stringshare_replace(&ss->ephoto->gadget_config->directory, path);
if (ecore_file_is_dir(path))
ephoto_directory_set(ss->ephoto, path, NULL, EINA_FALSE, EINA_TRUE);
@ -822,6 +822,12 @@ _gadget_settings_save(void *data, Evas_Object *obj EINA_UNUSED,
evas_object_del(popup);
}
static void
_popup_del(void *data EINA_UNUSED, Evas *e EINA_UNUSED, Evas_Object *obj, void *event_data EINA_UNUSED)
{
evas_object_del(obj);
}
static void
_gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
@ -831,8 +837,12 @@ _gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
char buf[PATH_MAX];
popup = elm_win_add(ss->ephoto->win, "win", ELM_WIN_BASIC);
elm_win_alpha_set(popup, 1);
if (ss->ephoto->gadget)
elm_win_alpha_set(popup, 1);
else
elm_win_autodel_set(popup, 1);
evas_object_data_set(popup, "slideshow", ss);
evas_object_event_callback_add(popup, EVAS_CALLBACK_HIDE, _popup_del, NULL);
table = elm_table_add(popup);
elm_table_homogeneous_set(table, EINA_FALSE);
@ -844,7 +854,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->gci->directory);
elm_fileselector_path_set(fentry, ss->ephoto->gadget_config->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);
@ -867,7 +877,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->gci->slideshow_timeout);
elm_spinner_value_set(spinner, ss->ephoto->gadget_config->slideshow_timeout);
elm_spinner_min_max_set(spinner, 1, 60);
elm_table_pack(table, spinner, 1, 5, 1, 1);
evas_object_show(spinner);
@ -969,7 +979,7 @@ _mouse_in(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
{
Ephoto_Slideshow *ss = data;
if (ss->notify)
if (ss->notify && ss->entry)
{
elm_notify_timeout_set(ss->notify, 0.0);
evas_object_show(ss->notify);
@ -982,7 +992,7 @@ _mouse_out(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
{
Ephoto_Slideshow *ss = data;
if (ss->notify)
if (ss->notify && ss->entry)
elm_notify_timeout_set(ss->notify, 3.0);
}
@ -992,7 +1002,7 @@ _mouse_move(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
{
Ephoto_Slideshow *ss = data;
if (ss->notify)
if (ss->notify && ss->entry)
{
elm_notify_timeout_set(ss->notify, 3.0);
evas_object_show(ss->notify);
@ -1023,7 +1033,7 @@ ephoto_slideshow_show_controls(Ephoto *ephoto)
but = _add_icon(ss->notify_box, "preferences-other", _("Settings"), NULL);
evas_object_smart_callback_add(but, "clicked", _gadget_settings, ss);
elm_notify_align_set(ss->notify, 0.5, 0.5);
elm_notify_timeout_set(ss->notify, 3.0);
elm_notify_timeout_set(ss->notify, 0.0);
evas_object_show(ss->notify);
return;
}
@ -1139,7 +1149,7 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout;
else
ss->timeout = ss->ephoto->gci->slideshow_timeout;
ss->timeout = ss->ephoto->gadget_config->slideshow_timeout;
_slideshow_play(ss);
ss->playing = 1;
@ -1193,5 +1203,16 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
evas_object_raise(ss->event);
elm_object_focus_set(ss->event, EINA_TRUE);
}
else
{
if (ss->notify)
{
if (!elm_notify_timeout_get(ss->notify))
{
elm_notify_timeout_set(ss->notify, 3.0);
evas_object_show(ss->notify);
}
}
}
}

Loading…
Cancel
Save