Ephoto: Fix file operation crashes caused by thread nastiness.

This commit is contained in:
Stephen Houston 2016-10-10 13:43:40 -05:00
parent 9c25551f9c
commit 00a2fcfd04
3 changed files with 58 additions and 99 deletions

View File

@ -255,6 +255,7 @@ struct _Ephoto
Evas_Object *slideshow; Evas_Object *slideshow;
Evas_Object *dir_browser; Evas_Object *dir_browser;
Evas_Object *right_menu; Evas_Object *right_menu;
Evas_Object *file_popup;
Elm_Object_Item *tb; Elm_Object_Item *tb;
Elm_Object_Item *sb; Elm_Object_Item *sb;
Elm_Object_Item *sl; Elm_Object_Item *sl;
@ -283,6 +284,7 @@ struct _Ephoto
int file_errors; int file_errors;
const char *top_directory; const char *top_directory;
const char *destination;
int thumb_gen_size; int thumb_gen_size;

View File

@ -578,19 +578,29 @@ _processing(Ephoto *ephoto, const char *title, const char *text)
static void static void
_thread_end_cb(void *data, Ecore_Thread *et EINA_UNUSED) _thread_end_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto"); char msg[PATH_MAX];
evas_object_del(popup); if (ephoto->file_errors > 0)
{
snprintf(msg, PATH_MAX, "%s %d %s.",
_("There was an error completing your action on"), ephoto->file_errors,
ngettext("file", "files", ephoto->file_errors));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_pos = NULL;
ephoto->file_errors = 0;
ephoto->destination = NULL;
evas_object_del(ephoto->file_popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE); elm_object_focus_set(ephoto->pager, EINA_TRUE);
} }
static void static void
_move_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED) _move_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto"); const char *destination = ephoto->destination;
const char *destination = evas_object_data_get(popup, "destination");
const char *file; const char *file;
if (!ephoto->file_pos) if (!ephoto->file_pos)
@ -630,17 +640,6 @@ _move_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
ephoto->file_errors++; ephoto->file_errors++;
} }
} }
if (ephoto->file_errors > 0)
{
char msg[PATH_MAX];
snprintf(msg, PATH_MAX, "%s %d %s.",
_("There was an error moving"), ephoto->file_errors,
ngettext("file", "files", ephoto->file_errors));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_errors = 0;
ephoto->file_pos = NULL;
} }
static void static void
@ -650,23 +649,22 @@ _move_files(Ephoto *ephoto, Eina_List *files,
Evas_Object *popup = _processing(ephoto, _("Moving Files"), Evas_Object *popup = _processing(ephoto, _("Moving Files"),
_("Please wait while your files are moved.")); _("Please wait while your files are moved."));
evas_object_data_set(popup, "ephoto", ephoto); ephoto->file_popup = popup;
evas_object_data_set(popup, "destination", destination); ephoto->destination = destination;
evas_object_show(popup); evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files); ephoto->file_pos = eina_list_clone(files);
if (eina_list_count(files)) if (eina_list_count(files))
eina_list_free(files); eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_move_thread_cb, ephoto->file_thread = ecore_thread_run(_move_thread_cb,
_thread_end_cb, _thread_end_cb, popup); _thread_end_cb, _thread_end_cb, ephoto);
} }
static void static void
_copy_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED) _copy_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto"); const char *destination = ephoto->destination;
const char *destination = evas_object_data_get(popup, "destination");
const char *file; const char *file;
if (!ephoto->file_pos) if (!ephoto->file_pos)
@ -704,17 +702,6 @@ _copy_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
ephoto->file_errors++; ephoto->file_errors++;
} }
} }
if (ephoto->file_errors > 0)
{
char msg[PATH_MAX];
snprintf(msg, PATH_MAX, "%s %d %s.",
_("There was an error copying"), ephoto->file_errors,
ngettext("file", "files", ephoto->file_errors));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_errors = 0;
ephoto->file_pos = NULL;
} }
static void static void
@ -723,22 +710,21 @@ _copy_files(Ephoto *ephoto, Eina_List *files,
{ {
Evas_Object *popup = _processing(ephoto, _("Copying Files"), Evas_Object *popup = _processing(ephoto, _("Copying Files"),
_("Please wait while your files are copied.")); _("Please wait while your files are copied."));
evas_object_data_set(popup, "ephoto", ephoto); ephoto->file_popup = popup;
evas_object_data_set(popup, "destination", destination); ephoto->destination = destination;
evas_object_show(popup); evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files); ephoto->file_pos = eina_list_clone(files);
if (eina_list_count(files)) if (eina_list_count(files))
eina_list_free(files); eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_copy_thread_cb, ephoto->file_thread = ecore_thread_run(_copy_thread_cb,
_thread_end_cb, NULL, popup); _thread_end_cb, NULL, ephoto);
} }
static void static void
_delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED) _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file; const char *file;
char destination[PATH_MAX]; char destination[PATH_MAX];
@ -791,17 +777,6 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
ephoto->file_errors++; ephoto->file_errors++;
} }
} }
if (ephoto->file_errors > 0)
{
char msg[PATH_MAX];
snprintf(msg, PATH_MAX, "%s %d %s.",
_("There was an error deleting"), ephoto->file_errors,
ngettext("file", "files", ephoto->file_errors));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_pos = NULL;
ephoto->file_errors = 0;
} }
static void static void
@ -810,24 +785,21 @@ _delete_files(Ephoto *ephoto, Eina_List *files)
Evas_Object *popup = _processing(ephoto, _("Deleting Files"), Evas_Object *popup = _processing(ephoto, _("Deleting Files"),
_("Please wait while your files are deleted.")); _("Please wait while your files are deleted."));
evas_object_data_set(popup, "ephoto", ephoto); ephoto->file_popup = popup;
evas_object_data_set(popup, "files", files);
evas_object_show(popup); evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files); ephoto->file_pos = eina_list_clone(files);
if (eina_list_count(files)) if (eina_list_count(files))
eina_list_free(files); eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_delete_thread_cb, ephoto->file_thread = ecore_thread_run(_delete_thread_cb,
_thread_end_cb, NULL, popup); _thread_end_cb, NULL, ephoto);
} }
static void static void
_delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED) _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto"); const char *dir = eina_list_data_get(ephoto->file_pos);
Eina_List *files = evas_object_data_get(popup, "files");
const char *dir = eina_list_data_get(files);
char destination[PATH_MAX]; char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME")); snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
@ -866,16 +838,8 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
ephoto->file_errors++; ephoto->file_errors++;
} }
} }
if (!dir || ephoto->file_errors > 0) if (!dir)
{ ephoto->file_errors++;
char msg[PATH_MAX];
snprintf(msg, PATH_MAX, "%s.",
_("There was an error deleting this directory"));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_pos = NULL;
ephoto->file_errors = 0;
} }
static void static void
@ -883,21 +847,18 @@ _delete_dir(Ephoto *ephoto, Eina_List *files)
{ {
Evas_Object *popup = _processing(ephoto, _("Deleting Directory"), Evas_Object *popup = _processing(ephoto, _("Deleting Directory"),
_("Please wait while your directory is deleted.")); _("Please wait while your directory is deleted."));
ephoto->file_popup = popup;
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "files", files);
evas_object_show(popup); evas_object_show(popup);
ephoto->file_pos = NULL; ephoto->file_pos = eina_list_clone(files);
ephoto->file_thread = ecore_thread_run(_delete_dir_thread_cb, ephoto->file_thread = ecore_thread_run(_delete_dir_thread_cb,
_thread_end_cb, NULL, popup); _thread_end_cb, NULL, ephoto);
} }
static void static void
_empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED) _empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED)
{ {
Evas_Object *popup = data; Ephoto *ephoto = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file; const char *file;
char trash[PATH_MAX]; char trash[PATH_MAX];
@ -921,17 +882,6 @@ _empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED)
ephoto->file_errors++; ephoto->file_errors++;
} }
} }
if (ephoto->file_errors > 0)
{
char msg[PATH_MAX];
snprintf(msg, PATH_MAX, "%s %d %s.",
_("There was an error deleting"), ephoto->file_errors,
ngettext("file", "files", ephoto->file_errors));
_complete(ephoto, _("Error"), msg);
}
ephoto->file_pos = NULL;
ephoto->file_errors = 0;
} }
static void static void
@ -939,15 +889,14 @@ _empty_trash(Ephoto *ephoto, Eina_List *files)
{ {
Evas_Object *popup = _processing(ephoto, _("Emptying Trash"), Evas_Object *popup = _processing(ephoto, _("Emptying Trash"),
_("Please wait while your files are deleted.")); _("Please wait while your files are deleted."));
ephoto->file_popup = popup;
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_show(popup); evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files); ephoto->file_pos = eina_list_clone(files);
if (eina_list_count(files)) if (eina_list_count(files))
eina_list_free(files); eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_empty_trash_thread_cb, ephoto->file_thread = ecore_thread_run(_empty_trash_thread_cb,
_thread_end_cb, NULL, popup); _thread_end_cb, NULL, ephoto);
} }
static void static void

View File

@ -1173,7 +1173,7 @@ _ephoto_thumb_search_go(void *data, Evas_Object *obj EINA_UNUSED,
if (tb->original_grid) if (tb->original_grid)
{ {
ephoto_thumb_browser_clear(tb->ephoto); elm_gengrid_clear(tb->grid);
elm_box_unpack(tb->gridbox, tb->grid); elm_box_unpack(tb->gridbox, tb->grid);
evas_object_del(tb->grid); evas_object_del(tb->grid);
tb->grid = tb->original_grid; tb->grid = tb->original_grid;
@ -1307,7 +1307,7 @@ _ephoto_thumb_search_cancel(void *data, Evas_Object *obj EINA_UNUSED,
tb->searchentries = NULL; tb->searchentries = NULL;
if (tb->original_grid) if (tb->original_grid)
{ {
ephoto_thumb_browser_clear(tb->ephoto); elm_gengrid_clear(tb->grid);
elm_box_unpack(tb->gridbox, tb->grid); elm_box_unpack(tb->gridbox, tb->grid);
evas_object_del(tb->grid); evas_object_del(tb->grid);
tb->grid = tb->original_grid; tb->grid = tb->original_grid;
@ -1519,7 +1519,9 @@ static Eina_Bool
_ephoto_thumb_populate_start(void *data, int type EINA_UNUSED, _ephoto_thumb_populate_start(void *data, int type EINA_UNUSED,
void *event EINA_UNUSED) void *event EINA_UNUSED)
{ {
Ephoto_Thumb_Browser *tb = data; Ephoto *ephoto = data;
Ephoto_Thumb_Browser *tb =
evas_object_data_get(ephoto->thumb_browser, "thumb_browser");
if (tb->dirs_only) if (tb->dirs_only)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
@ -1531,7 +1533,7 @@ _ephoto_thumb_populate_start(void *data, int type EINA_UNUSED,
if (tb->searching) if (tb->searching)
_ephoto_thumb_search_cancel(tb->search, NULL, NULL); _ephoto_thumb_search_cancel(tb->search, NULL, NULL);
_todo_items_free(tb); _todo_items_free(tb);
ephoto_thumb_browser_clear(tb->ephoto); elm_gengrid_clear(tb->grid);
tb->totimages = 0; tb->totimages = 0;
tb->totsize = 0; tb->totsize = 0;
@ -1542,7 +1544,9 @@ static Eina_Bool
_ephoto_thumb_populate_end(void *data, int type EINA_UNUSED, _ephoto_thumb_populate_end(void *data, int type EINA_UNUSED,
void *event EINA_UNUSED) void *event EINA_UNUSED)
{ {
Ephoto_Thumb_Browser *tb = data; Ephoto *ephoto = data;
Ephoto_Thumb_Browser *tb =
evas_object_data_get(ephoto->thumb_browser, "thumb_browser");
if (tb->dirs_only) if (tb->dirs_only)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
@ -1580,7 +1584,9 @@ static Eina_Bool
_ephoto_thumb_populate_error(void *data, int type EINA_UNUSED, _ephoto_thumb_populate_error(void *data, int type EINA_UNUSED,
void *event EINA_UNUSED) void *event EINA_UNUSED)
{ {
Ephoto_Thumb_Browser *tb = data; Ephoto *ephoto = data;
Ephoto_Thumb_Browser *tb =
evas_object_data_get(ephoto->thumb_browser, "thumb_browser");
if (tb->dirs_only) if (tb->dirs_only)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
@ -1594,7 +1600,9 @@ _ephoto_thumb_populate_error(void *data, int type EINA_UNUSED,
static Eina_Bool static Eina_Bool
_ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event) _ephoto_thumb_entry_create(void *data, int type EINA_UNUSED, void *event)
{ {
Ephoto_Thumb_Browser *tb = data; Ephoto *ephoto = data;
Ephoto_Thumb_Browser *tb =
evas_object_data_get(ephoto->thumb_browser, "thumb_browser");
Ephoto_Event_Entry_Create *ev = event; Ephoto_Event_Entry_Create *ev = event;
Ephoto_Entry *e; Ephoto_Entry *e;
@ -2177,22 +2185,22 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
tb->handlers = tb->handlers =
eina_list_append(tb->handlers, eina_list_append(tb->handlers,
ecore_event_handler_add(EPHOTO_EVENT_POPULATE_START, ecore_event_handler_add(EPHOTO_EVENT_POPULATE_START,
_ephoto_thumb_populate_start, tb)); _ephoto_thumb_populate_start, ephoto));
tb->handlers = tb->handlers =
eina_list_append(tb->handlers, eina_list_append(tb->handlers,
ecore_event_handler_add(EPHOTO_EVENT_POPULATE_END, ecore_event_handler_add(EPHOTO_EVENT_POPULATE_END,
_ephoto_thumb_populate_end, tb)); _ephoto_thumb_populate_end, ephoto));
tb->handlers = tb->handlers =
eina_list_append(tb->handlers, eina_list_append(tb->handlers,
ecore_event_handler_add(EPHOTO_EVENT_POPULATE_ERROR, ecore_event_handler_add(EPHOTO_EVENT_POPULATE_ERROR,
_ephoto_thumb_populate_error, tb)); _ephoto_thumb_populate_error, ephoto));
tb->handlers = tb->handlers =
eina_list_append(tb->handlers, eina_list_append(tb->handlers,
ecore_event_handler_add(EPHOTO_EVENT_ENTRY_CREATE, ecore_event_handler_add(EPHOTO_EVENT_ENTRY_CREATE,
_ephoto_thumb_entry_create, tb)); _ephoto_thumb_entry_create, ephoto));
return tb->main; return tb->main;