Ephoto: Incorporate the use of monitors to maintain accuracy with the file system. Fix rename extra dot.

This commit is contained in:
Stephen Houston 2016-01-19 13:58:28 -06:00
parent be49678df1
commit ca46030aa4
4 changed files with 824 additions and 215 deletions

View File

@ -76,9 +76,11 @@ void ephoto_slideshow_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
/* smart callbacks called: "back" - the user wants to go back to the previous
* screen. */
Evas_Object *ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent);
void ephoto_thumb_browser_fsel_clear(Ephoto *ephoto);
void ephoto_thumb_browser_top_dir_set(Ephoto *ephoto, const char *dir);
void ephoto_thumb_browser_insert(Ephoto *ephoto, Ephoto_Entry *entry);
void ephoto_thumb_browser_remove(Ephoto *ephoto, Ephoto_Entry *entry);
/* smart callbacks called: "selected" - an item in the thumb browser is
* selected. The selected Ephoto_Entry is passed as event_info argument. */
@ -162,11 +164,15 @@ struct _Ephoto
Elm_Object_Item *sl;
Eina_List *entries;
Eina_List *direntries;
Eina_List *selentries;
Eina_List *searchentries;
Eina_List *thumbs;
Eio_Monitor *monitor;
Eina_List *monitor_handlers;
const char *top_directory;
int thumb_gen_size;
Evas_Coord bottom_bar_size;
struct
@ -191,11 +197,16 @@ struct _Ephoto_Entry
const char *path;
const char *basename;
const char *label;
double size;
Ephoto *ephoto;
Eio_Monitor *monitor;
Eina_List *monitor_handlers;
Elm_Object_Item *item;
Elm_Object_Item *parent;
Eina_List *free_listeners;
Eina_Bool is_dir;
Eina_Bool no_delete;
Evas_Object *genlist;
};
struct _Ephoto_Event_Entry_Create

View File

@ -158,8 +158,18 @@ _win_free(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
{
Ephoto *ephoto = data;
if (ephoto->top_directory)
eina_stringshare_del(ephoto->top_directory);
if (ephoto->timer.thumb_regen)
ecore_timer_del(ephoto->timer.thumb_regen);
ecore_timer_del(ephoto->timer.thumb_regen);
if (ephoto->monitor)
{
Ecore_Event_Handler *handler;
EINA_LIST_FREE(ephoto->monitor_handlers, handler)
ecore_event_handler_del(handler);
eio_monitor_del(ephoto->monitor);
}
ephoto_config_save(ephoto);
free(ephoto);
}
@ -308,7 +318,7 @@ ephoto_window_add(const char *path)
ephoto->single_browser);
ephoto->state = EPHOTO_STATE_SINGLE;
}
ephoto_thumb_browser_top_dir_set(ephoto, ephoto->config->directory);
evas_object_resize(ephoto->win, ephoto->config->window_width,
ephoto->config->window_height);
evas_object_show(ephoto->win);
@ -350,27 +360,7 @@ _ephoto_populate_main(void *data, Eio_File *handler EINA_UNUSED,
info->type);
if (e->is_dir)
{
if (!ed->ephoto->direntries)
ed->ephoto->direntries = eina_list_append(ed->ephoto->direntries, e);
else
{
int near_cmp;
Eina_List *near_node =
eina_list_search_sorted_near_list(ed->ephoto->direntries,
ephoto_entries_cmp, e, &near_cmp);
if (near_cmp < 0)
ed->ephoto->direntries =
eina_list_append_relative_list(ed->ephoto->direntries, e,
near_node);
else
ed->ephoto->direntries =
eina_list_prepend_relative_list(ed->ephoto->direntries, e,
near_node);
}
e->parent = ed->expanded;
}
e->parent = ed->expanded;
else
{
if (!ed->ephoto->entries)
@ -408,7 +398,7 @@ _ephoto_populate_filter(void *data, Eio_File *handler EINA_UNUSED,
if (bname[0] == '.')
return EINA_FALSE;
if (info->type == EINA_FILE_DIR)
if (info->type == EINA_FILE_DIR && !ed->thumbs_only)
{
return EINA_TRUE;
}
@ -445,10 +435,7 @@ _ephoto_populate_entries(Ephoto_Dir_Data *ed)
{
Ephoto_Entry *entry;
if (ed->dirs_only)
EINA_LIST_FREE(ed->ephoto->direntries, entry)
ephoto_entry_free(entry->ephoto, entry);
else if (ed->thumbs_only)
if (ed->thumbs_only)
EINA_LIST_FREE(ed->ephoto->entries, entry)
ephoto_entry_free(entry->ephoto, entry);
else
@ -470,6 +457,128 @@ _ephoto_change_dir(void *data)
_ephoto_populate_entries(ed);
}
static Eina_Bool
_monitor_created(void *data, int type EINA_UNUSED, void *event)
{
Ephoto *ephoto = data;
Eio_Monitor_Event *ev = event;
if (!strncmp("image/", efreet_mime_type_get(ev->filename), 6))
{
Eina_List *l;
Ephoto_Entry *entry;
char buf[PATH_MAX];
EINA_LIST_FOREACH(ephoto->entries, l, entry)
{
char p1[PATH_MAX], p2[PATH_MAX];
snprintf(p1, PATH_MAX, "%s", entry->path);
snprintf(p2, PATH_MAX, "%s", ev->filename);
if (strlen(p1) == strlen(p2))
{
if (!strcmp(p1, p2))
{
return ECORE_CALLBACK_PASS_ON;
}
}
}
snprintf(buf, PATH_MAX, "%s", ev->filename);
entry = ephoto_entry_new(ephoto, ev->filename, basename(buf),
EINA_FILE_REG);
if (!ephoto->entries)
{
ephoto->entries = eina_list_append(ephoto->entries, entry);
}
else
{
int near_cmp;
Eina_List *near_node =
eina_list_search_sorted_near_list(ephoto->entries,
ephoto_entries_cmp, entry, &near_cmp);
if (near_cmp < 0)
ephoto->entries =
eina_list_append_relative_list(ephoto->entries, entry,
near_node);
else
ephoto->entries =
eina_list_prepend_relative_list(ephoto->entries, entry,
near_node);
}
ephoto_thumb_browser_insert(ephoto, entry);
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_monitor_deleted(void *data, int type EINA_UNUSED, void *event)
{
Ephoto *ephoto = data;
Eio_Monitor_Event *ev = event;
if (!strncmp("image/", efreet_mime_type_get(ev->filename), 6))
{
Eina_List *l;
Ephoto_Entry *entry;
EINA_LIST_FOREACH(ephoto->entries, l, entry)
{
char p1[PATH_MAX], p2[PATH_MAX];
snprintf(p1, PATH_MAX, "%s", entry->path);
snprintf(p2, PATH_MAX, "%s", ev->filename);
if (strlen(p1) == strlen(p2))
{
if (!strcmp(p1, p2))
{
ephoto_thumb_browser_remove(ephoto, entry);
ephoto_entry_free(ephoto, entry);
break;
}
}
}
}
return ECORE_CALLBACK_PASS_ON;
}
static Eina_Bool
_monitor_modified(void *data, int type EINA_UNUSED, void *event)
{
Ephoto *ephoto = data;
Eio_Monitor_Event *ev = event;
if (!strncmp("image/", efreet_mime_type_get(ev->filename), 6))
{
Eina_List *l;
Ephoto_Entry *entry;
EINA_LIST_FOREACH(ephoto->entries, l, entry)
{
char p1[PATH_MAX], p2[PATH_MAX];
snprintf(p1, PATH_MAX, "%s", entry->path);
snprintf(p2, PATH_MAX, "%s", ev->filename);
if (strlen(p1) == strlen(p2))
{
if (!strcmp(p1, p2))
{
if (!ecore_file_exists(entry->path))
{
elm_object_item_del(entry->item);
ephoto_entry_free(ephoto, entry);
}
else
{
ephoto_thumb_browser_remove(ephoto, entry);
ephoto_thumb_browser_insert(ephoto, entry);
}
break;
}
}
}
}
return ECORE_CALLBACK_PASS_ON;
}
void
ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded,
Eina_Bool dirs_only, Eina_Bool thumbs_only)
@ -488,6 +597,21 @@ ephoto_directory_set(Ephoto *ephoto, const char *path, Evas_Object *expanded,
if (ed->ephoto->job.change_dir)
ecore_job_del(ed->ephoto->job.change_dir);
ed->ephoto->job.change_dir = ecore_job_add(_ephoto_change_dir, ed);
if (ephoto->monitor)
{
Ecore_Event_Handler *handler;
EINA_LIST_FREE(ephoto->monitor_handlers, handler)
ecore_event_handler_del(handler);
eio_monitor_del(ephoto->monitor);
}
ephoto->monitor = eio_monitor_add(path);
ephoto->monitor_handlers = eina_list_append(ephoto->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_CREATED, _monitor_created, ephoto));
ephoto->monitor_handlers = eina_list_append(ephoto->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_DELETED, _monitor_deleted, ephoto));
ephoto->monitor_handlers = eina_list_append(ephoto->monitor_handlers,
ecore_event_handler_add(EIO_MONITOR_FILE_MODIFIED, _monitor_modified, ephoto));
}
static Eina_Bool
@ -650,18 +774,14 @@ ephoto_entry_free(Ephoto *ephoto, Ephoto_Entry *entry)
{
Ephoto_Entry_Free_Listener *fl;
Eina_List *node;
Ecore_Event_Handler *handler;
EINA_LIST_FREE(entry->free_listeners, fl)
{
fl->cb((void *) fl->data, entry);
free(fl);
}
if (entry->is_dir)
{
node = eina_list_data_find_list(ephoto->direntries, entry);
ephoto->direntries = eina_list_remove_list(ephoto->direntries, node);
}
else
if (!entry->is_dir)
{
node = eina_list_data_find_list(ephoto->entries, entry);
ephoto->entries = eina_list_remove_list(ephoto->entries, node);
@ -673,6 +793,10 @@ ephoto_entry_free(Ephoto *ephoto, Ephoto_Entry *entry)
}
eina_stringshare_del(entry->path);
eina_stringshare_del(entry->label);
if (entry->monitor)
eio_monitor_del(entry->monitor);
EINA_LIST_FREE(entry->monitor_handlers, handler)
ecore_event_handler_del(handler);
free(entry);
}
@ -712,5 +836,4 @@ ephoto_entries_free(Ephoto *ephoto)
Ephoto_Entry *entry;
EINA_LIST_FREE(ephoto->entries, entry) ephoto_entry_free(ephoto, entry);
EINA_LIST_FREE(ephoto->direntries, entry) ephoto_entry_free(ephoto, entry);
}

View File

@ -1198,6 +1198,7 @@ _save_image_as_overwrite(void *data, Evas_Object *obj EINA_UNUSED,
ephoto_thumb_browser_fsel_clear(sb->ephoto);
ephoto_directory_set(sb->ephoto, dir, NULL, EINA_FALSE, EINA_FALSE);
ephoto_thumb_browser_top_dir_set(sb->ephoto, sb->ephoto->config->directory);
free(dir);
ephoto_single_browser_path_pending_set(sb->ephoto->single_browser,
file);
@ -1304,6 +1305,7 @@ _save_image_as_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
ephoto_thumb_browser_fsel_clear(sb->ephoto);
ephoto_directory_set(sb->ephoto, dir, NULL,
EINA_FALSE, EINA_FALSE);
ephoto_thumb_browser_top_dir_set(sb->ephoto, sb->ephoto->config->directory);
free(dir);
ephoto_single_browser_path_pending_set(sb->ephoto->
single_browser, buf);
@ -2390,7 +2392,6 @@ _entry_free(void *data, const Ephoto_Entry *entry)
if (entry == sb->entry)
{
elm_object_item_del(entry->item);
if (eina_list_count(sb->entries) <= 1)
evas_object_smart_callback_call(sb->main, "back", NULL);
else

File diff suppressed because it is too large Load Diff