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

This commit is contained in:
Stephen Houston 2018-02-13 15:23:11 -06:00
parent c9fbad5399
commit d0ec29d753
5 changed files with 108 additions and 102 deletions

View File

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

View File

@ -40,7 +40,6 @@
/*local types*/ /*local types*/
typedef struct _Ephoto_Config Ephoto_Config; typedef struct _Ephoto_Config Ephoto_Config;
typedef struct _Ephoto_Gadget_Config Ephoto_Gadget_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 Ephoto;
typedef struct _Ephoto_Entry Ephoto_Entry; typedef struct _Ephoto_Entry Ephoto_Entry;
typedef struct _Ephoto_Event_Entry_Create Ephoto_Event_Entry_Create; 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); Eina_Bool ephoto_config_init(Ephoto *em);
void ephoto_config_save(Ephoto *em); void ephoto_config_save(Ephoto *em);
void ephoto_config_free(Ephoto *em); void ephoto_config_free(Ephoto *em);
Eina_Bool ephoto_gadget_config_init(Ephoto *em); Eina_Bool ephoto_gadget_config_init(Ephoto *em, int id, const char *profile);
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_save(Ephoto *em);
void ephoto_gadget_config_remove(Ephoto *em);
void ephoto_gadget_config_free(Ephoto *em); void ephoto_gadget_config_free(Ephoto *em);
void ephoto_config_main(Ephoto *em); void ephoto_config_main(Ephoto *em);
@ -261,17 +260,12 @@ struct _Ephoto_Config
struct _Ephoto_Gadget_Config struct _Ephoto_Gadget_Config
{ {
int config_version; int config_version;
Eina_List *config_items;
};
struct _Ephoto_Gadget_Config_Item
{
int id; int id;
const char *profile; const char *profile;
const char *directory; const char *directory;
double slideshow_timeout; double slideshow_timeout;
}; };
struct _Ephoto struct _Ephoto
{ {
Evas_Object *win; Evas_Object *win;
@ -334,7 +328,6 @@ struct _Ephoto
Ephoto_Config *config; Ephoto_Config *config;
Ephoto_Gadget_Config *gadget_config; Ephoto_Gadget_Config *gadget_config;
Ephoto_Gadget_Config_Item *gci;
Ephoto_Sort sort; Ephoto_Sort sort;
}; };

View File

@ -4,12 +4,11 @@
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 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 Eina_Bool _ephoto_gadget_on_config_save(void *data);
static Eet_Data_Descriptor *edd = NULL; static Eet_Data_Descriptor *edd = NULL;
static Eet_Data_Descriptor *gedd = NULL; static Eet_Data_Descriptor *gedd = NULL;
static Eet_Data_Descriptor *gedds = NULL;
static void static void
_config_save_cb(void *data, Evas_Object *obj EINA_UNUSED, _config_save_cb(void *data, Evas_Object *obj EINA_UNUSED,
@ -849,26 +848,29 @@ ephoto_config_init(Ephoto *ephoto)
} }
static int static int
_ephoto_gadget_config_load(Ephoto *ephoto) _ephoto_gadget_config_load(Ephoto *ephoto, int id, const char *profile)
{ {
Eet_File *ef; Eet_File *ef;
char buf[4096], buf2[4096]; char buf[4096], buf2[4096];
snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get()); if (id >= 0)
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); snprintf(buf2, sizeof(buf2), "%s/ephoto", efreet_config_home_get());
ephoto->gadget_config = calloc(1, sizeof(Ephoto_Gadget_Config)); ecore_file_mkpath(buf2);
return 0; snprintf(buf, sizeof(buf), "%s/ephoto_gadget.%d.%s.cfg", buf2, id, profile);
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;
} }
ephoto->gadget_config = eet_data_read(ef, gedd, "gadget_config");
eet_close(ef);
if (!ephoto->gadget_config || ephoto->gadget_config->config_version > CONFIG_VERSION) if (!ephoto->gadget_config || ephoto->gadget_config->config_version > CONFIG_VERSION)
{ {
ephoto_gadget_config_free(ephoto); ephoto_gadget_config_free(ephoto);
@ -893,20 +895,21 @@ _ephoto_gadget_on_config_save(void *data)
Eet_File *ef; Eet_File *ef;
char buf[4096], buf2[4096]; char buf[4096], buf2[4096];
snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.cfg", efreet_config_home_get()); if (ephoto->gadget_config->id >= 0)
snprintf(buf2, sizeof(buf2), "%s.tmp", buf); {
snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
ef = eet_open(buf2, EET_FILE_MODE_WRITE); ephoto->gadget_config->id, ephoto->gadget_config->profile);
if (!ef) snprintf(buf2, sizeof(buf2), "%s.tmp", buf);
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;
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: save_end:
ecore_file_unlink(buf2); ecore_file_unlink(buf2);
@ -922,48 +925,33 @@ ephoto_gadget_config_save(Ephoto *ephoto)
void void
ephoto_gadget_config_free(Ephoto *ephoto) ephoto_gadget_config_free(Ephoto *ephoto)
{ {
Ephoto_Gadget_Config_Item *gci;
if (ephoto->gadget_config) if (ephoto->gadget_config)
{ {
if (eina_list_count(ephoto->gadget_config->config_items)) eina_stringshare_del(ephoto->gadget_config->profile);
{ eina_stringshare_del(ephoto->gadget_config->directory);
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); free(ephoto->gadget_config);
} }
ephoto->gadget_config = NULL; ephoto->gadget_config = NULL;
} }
Ephoto_Gadget_Config_Item * void
ephoto_gadget_config_item_get(Ephoto *ephoto, int id, const char *profile) ephoto_gadget_config_remove(Ephoto *ephoto)
{ {
Eina_List *l; char buf[4096];
Ephoto_Gadget_Config_Item *gci;
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)) snprintf(buf, sizeof(buf), "%s/ephoto/ephoto_gadget.%d.%s.cfg", efreet_config_home_get(),
return gci; 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 Eina_Bool
ephoto_gadget_config_init(Ephoto *ephoto) ephoto_gadget_config_init(Ephoto *ephoto, int id, const char *profile)
{ {
Eet_Data_Descriptor_Class geddc; Eet_Data_Descriptor_Class geddc;
@ -974,39 +962,29 @@ ephoto_gadget_config_init(Ephoto *ephoto)
} }
if (!gedd) if (!gedd)
gedd = eet_data_descriptor_stream_new(&geddc); 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 GT
#undef GD #undef GD
#define GT Ephoto_Gadget_Config #define GT Ephoto_Gadget_Config
#define GD gedd #define GD gedd
#define GST Ephoto_Gadget_Config_Item
#define GS gedds
#define GC_VAL(gedd, type, member, dtype) \ #define GC_VAL(gedd, type, member, dtype) \
EET_DATA_DESCRIPTOR_ADD_BASIC(gedd, type, #member, 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); 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, id, profile))
switch (_ephoto_gadget_config_load(ephoto))
{ {
case 0: case 0:
/* Start a new config */ /* Start a new config */
ephoto->gadget_config->config_version = CONFIG_VERSION; 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; break;
default: default:

View File

@ -251,8 +251,6 @@ _win_free(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
ephoto_entries_free(ephoto); ephoto_entries_free(ephoto);
if (!ephoto->gadget) if (!ephoto->gadget)
ephoto_config_save(ephoto); ephoto_config_save(ephoto);
else
ephoto_gadget_config_save(ephoto);
if (ephoto->gadget_config) if (ephoto->gadget_config)
ephoto_config_free(ephoto); ephoto_config_free(ephoto);
free(ephoto->config); 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 * Evas_Object *
ephoto_window_add(const char *path, int gadget, int id) 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_title_set(ephoto->win, "Ephoto");
elm_win_alpha_set(ephoto->win, 1); elm_win_alpha_set(ephoto->win, 1);
evas_object_size_hint_aspect_set(ephoto->win, EVAS_ASPECT_CONTROL_BOTH, 1,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) if (!ephoto->win)
{ {
@ -427,13 +439,12 @@ ephoto_window_add(const char *path, int gadget, int id)
{ {
const char *profile; 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); evas_object_del(ephoto->win);
return NULL; return NULL;
} }
profile = elm_config_profile_get();
ephoto->gci = ephoto_gadget_config_item_get(ephoto, id, profile);
} }
if ((ephoto->config->thumb_gen_size != 128) && if ((ephoto->config->thumb_gen_size != 128) &&
@ -703,7 +714,7 @@ ephoto_window_add(const char *path, int gadget, int id)
} }
else 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; return ephoto->win;
} }

View File

@ -385,7 +385,7 @@ _on_transition_end(void *data, Evas_Object *obj EINA_UNUSED,
if (!ss->ephoto->gadget) if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout; ss->timeout = ss->ephoto->config->slideshow_timeout;
else else
ss->timeout = ss->ephoto->gci->slideshow_timeout; ss->timeout = ss->ephoto->gadget_config->slideshow_timeout;
if (ss->timer) if (ss->timer)
ecore_timer_del(ss->timer); ecore_timer_del(ss->timer);
ss->timer = NULL; ss->timer = NULL;
@ -812,9 +812,9 @@ _gadget_settings_save(void *data, Evas_Object *obj EINA_UNUSED,
fentry = evas_object_data_get(popup, "fentry"); fentry = evas_object_data_get(popup, "fentry");
spinner = evas_object_data_get(popup, "timeout"); 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); 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)) if (ecore_file_is_dir(path))
ephoto_directory_set(ss->ephoto, path, NULL, EINA_FALSE, EINA_TRUE); 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); 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 static void
_gadget_settings(void *data, Evas_Object *obj EINA_UNUSED, _gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED) void *event_info EINA_UNUSED)
@ -831,8 +837,12 @@ _gadget_settings(void *data, Evas_Object *obj EINA_UNUSED,
char buf[PATH_MAX]; char buf[PATH_MAX];
popup = elm_win_add(ss->ephoto->win, "win", ELM_WIN_BASIC); 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_data_set(popup, "slideshow", ss);
evas_object_event_callback_add(popup, EVAS_CALLBACK_HIDE, _popup_del, NULL);
table = elm_table_add(popup); table = elm_table_add(popup);
elm_table_homogeneous_set(table, EINA_FALSE); 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); fentry = elm_fileselector_add(table);
elm_fileselector_is_save_set(fentry, EINA_FALSE); elm_fileselector_is_save_set(fentry, EINA_FALSE);
elm_fileselector_expandable_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_buttons_ok_cancel_set(fentry, EINA_FALSE);
elm_fileselector_folder_only_set(fentry, EINA_TRUE); elm_fileselector_folder_only_set(fentry, EINA_TRUE);
evas_object_size_hint_weight_set(fentry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); 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")); snprintf(buf, PATH_MAX, "%%1.0f %s", _("seconds"));
elm_spinner_label_format_set(spinner, buf); elm_spinner_label_format_set(spinner, buf);
elm_spinner_step_set(spinner, 1); 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_spinner_min_max_set(spinner, 1, 60);
elm_table_pack(table, spinner, 1, 5, 1, 1); elm_table_pack(table, spinner, 1, 5, 1, 1);
evas_object_show(spinner); 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; Ephoto_Slideshow *ss = data;
if (ss->notify) if (ss->notify && ss->entry)
{ {
elm_notify_timeout_set(ss->notify, 0.0); elm_notify_timeout_set(ss->notify, 0.0);
evas_object_show(ss->notify); 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; Ephoto_Slideshow *ss = data;
if (ss->notify) if (ss->notify && ss->entry)
elm_notify_timeout_set(ss->notify, 3.0); 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; Ephoto_Slideshow *ss = data;
if (ss->notify) if (ss->notify && ss->entry)
{ {
elm_notify_timeout_set(ss->notify, 3.0); elm_notify_timeout_set(ss->notify, 3.0);
evas_object_show(ss->notify); 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); but = _add_icon(ss->notify_box, "preferences-other", _("Settings"), NULL);
evas_object_smart_callback_add(but, "clicked", _gadget_settings, ss); evas_object_smart_callback_add(but, "clicked", _gadget_settings, ss);
elm_notify_align_set(ss->notify, 0.5, 0.5); 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); evas_object_show(ss->notify);
return; return;
} }
@ -1139,7 +1149,7 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
if (!ss->ephoto->gadget) if (!ss->ephoto->gadget)
ss->timeout = ss->ephoto->config->slideshow_timeout; ss->timeout = ss->ephoto->config->slideshow_timeout;
else else
ss->timeout = ss->ephoto->gci->slideshow_timeout; ss->timeout = ss->ephoto->gadget_config->slideshow_timeout;
_slideshow_play(ss); _slideshow_play(ss);
ss->playing = 1; ss->playing = 1;
@ -1193,5 +1203,16 @@ ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
evas_object_raise(ss->event); evas_object_raise(ss->event);
elm_object_focus_set(ss->event, EINA_TRUE); 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);
}
}
}
} }