Ephoto: More cleanup, eliminate duplicate thumbnails showing up, fix save error.

This commit is contained in:
Stephen okra Houston 2016-02-24 16:47:39 -06:00
parent cc281bd247
commit 3855fd4795
4 changed files with 104 additions and 32 deletions

View File

@ -64,6 +64,7 @@ void ephoto_single_browser_entries_set(Evas_Object *obj, Eina_List *entries);
void ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry); void ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry);
void ephoto_single_browser_path_pending_set(Evas_Object *obj, void ephoto_single_browser_path_pending_set(Evas_Object *obj,
const char *path); const char *path);
void ephoto_single_browser_path_created(Evas_Object *obj, Ephoto_Entry *entry);
void ephoto_single_browser_image_data_update(Evas_Object *main, void ephoto_single_browser_image_data_update(Evas_Object *main,
Evas_Object *image, Eina_Bool finished, unsigned int *image_data, int w, Evas_Object *image, Eina_Bool finished, unsigned int *image_data, int w,
int h); int h);
@ -82,6 +83,7 @@ void ephoto_thumb_browser_fsel_clear(Ephoto *ephoto);
void ephoto_thumb_browser_top_dir_set(Ephoto *ephoto, const char *dir); 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_insert(Ephoto *ephoto, Ephoto_Entry *entry);
void ephoto_thumb_browser_remove(Ephoto *ephoto, Ephoto_Entry *entry); void ephoto_thumb_browser_remove(Ephoto *ephoto, Ephoto_Entry *entry);
void ephoto_thumb_browser_update(Ephoto *ephoto, Ephoto_Entry *entry);
/* smart callbacks called: "selected" - an item in the thumb browser is /* smart callbacks called: "selected" - an item in the thumb browser is
* selected. The selected Ephoto_Entry is passed as event_info argument. */ * selected. The selected Ephoto_Entry is passed as event_info argument. */

View File

@ -474,7 +474,7 @@ _monitor_created(void *data, int type EINA_UNUSED, void *event)
if (strcmp(ephoto->config->directory, dir)) if (strcmp(ephoto->config->directory, dir))
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!strncmp("image/", efreet_mime_type_get(ev->filename), 6)) if (evas_object_image_extension_can_load_get(ev->filename))
{ {
Eina_List *l; Eina_List *l;
Ephoto_Entry *entry; Ephoto_Entry *entry;
@ -488,6 +488,7 @@ _monitor_created(void *data, int type EINA_UNUSED, void *event)
snprintf(buf, PATH_MAX, "%s", ev->filename); snprintf(buf, PATH_MAX, "%s", ev->filename);
entry = ephoto_entry_new(ephoto, ev->filename, basename(buf), entry = ephoto_entry_new(ephoto, ev->filename, basename(buf),
EINA_FILE_REG); EINA_FILE_REG);
ephoto_single_browser_path_created(ephoto->single_browser, entry);
if (!ephoto->entries) if (!ephoto->entries)
{ {
ephoto->entries = eina_list_append(ephoto->entries, entry); ephoto->entries = eina_list_append(ephoto->entries, entry);
@ -519,7 +520,6 @@ _monitor_deleted(void *data, int type EINA_UNUSED, void *event)
Ephoto *ephoto = data; Ephoto *ephoto = data;
Eio_Monitor_Event *ev = event; Eio_Monitor_Event *ev = event;
char file[PATH_MAX], dir[PATH_MAX]; char file[PATH_MAX], dir[PATH_MAX];
const char *mime;
snprintf(file, PATH_MAX, "%s", ev->filename); snprintf(file, PATH_MAX, "%s", ev->filename);
snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file)); snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file));
@ -527,8 +527,7 @@ _monitor_deleted(void *data, int type EINA_UNUSED, void *event)
if (strcmp(ephoto->config->directory, dir)) if (strcmp(ephoto->config->directory, dir))
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
mime = efreet_mime_type_get(ev->filename); if (evas_object_image_extension_can_load_get(ev->filename))
if (!mime || !strncmp("image/", mime, 6))
{ {
Eina_List *l; Eina_List *l;
Ephoto_Entry *entry; Ephoto_Entry *entry;
@ -559,7 +558,7 @@ _monitor_modified(void *data, int type EINA_UNUSED, void *event)
if (strcmp(ephoto->config->directory, dir)) if (strcmp(ephoto->config->directory, dir))
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!strncmp("image/", efreet_mime_type_get(ev->filename), 6)) if (evas_object_image_extension_can_load_get(ev->filename))
{ {
Eina_List *l; Eina_List *l;
Ephoto_Entry *entry; Ephoto_Entry *entry;
@ -575,8 +574,7 @@ _monitor_modified(void *data, int type EINA_UNUSED, void *event)
} }
else else
{ {
ephoto_thumb_browser_remove(ephoto, entry); ephoto_thumb_browser_update(ephoto, entry);
ephoto_thumb_browser_insert(ephoto, entry);
} }
break; break;
} }

View File

@ -1202,15 +1202,19 @@ _save_image_as_overwrite(void *data, Evas_Object *obj EINA_UNUSED,
return; return;
} }
} }
ephoto_single_browser_path_pending_set(sb->ephoto->single_browser, file);
success = success =
evas_object_image_save(elm_image_object_get(v->image), file, evas_object_image_save(elm_image_object_get(v->image), file,
NULL, NULL); NULL, NULL);
if (!success) if (!success)
_failed_save(sb); {
_failed_save(sb);
eina_stringshare_del(sb->pending_path);
sb->pending_path = NULL;
}
else else
{ {
char *dir = ecore_file_dir_get(file); char *dir = ecore_file_dir_get(file);
if (strcmp(dir, sb->ephoto->config->directory)) if (strcmp(dir, sb->ephoto->config->directory))
{ {
ephoto_thumb_browser_fsel_clear(sb->ephoto); ephoto_thumb_browser_fsel_clear(sb->ephoto);
@ -1218,8 +1222,6 @@ _save_image_as_overwrite(void *data, Evas_Object *obj EINA_UNUSED,
ephoto_thumb_browser_top_dir_set(sb->ephoto, ephoto_thumb_browser_top_dir_set(sb->ephoto,
sb->ephoto->config->directory); sb->ephoto->config->directory);
free(dir); free(dir);
ephoto_single_browser_path_pending_set(sb->ephoto->single_browser,
file);
} }
} }
evas_object_del(popup); evas_object_del(popup);
@ -1243,11 +1245,29 @@ _save_image_as_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
Eina_Bool success; Eina_Bool success;
char buf[PATH_MAX]; char buf[PATH_MAX];
const char *ex, *ext;
if (!_ephoto_file_image_can_save(strrchr(selected, '.')+1)) ex = strrchr(selected, '.');
snprintf(buf, PATH_MAX, "%s.jpg", selected); if (!ex)
else {
snprintf(buf, PATH_MAX, "%s", selected); snprintf(buf, PATH_MAX, "%s.jpg", selected);
}
else
{
ext = eina_stringshare_add((strrchr(selected, '.')+1));
if (!_ephoto_file_image_can_save(ext))
{
if (ext)
eina_stringshare_del(ext);
snprintf(buf, PATH_MAX, "%s.jpg", selected);
}
else
{
if (ext)
eina_stringshare_del(ext);
snprintf(buf, PATH_MAX, "%s", selected);
}
}
if (ecore_file_exists(buf)) if (ecore_file_exists(buf))
{ {
Evas_Object *popup, *box, *label, *ic, *button; Evas_Object *popup, *box, *label, *ic, *button;
@ -1313,11 +1333,17 @@ _save_image_as_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
} }
else else
{ {
ephoto_single_browser_path_pending_set(sb->ephoto->
single_browser, buf);
success = success =
evas_object_image_save(elm_image_object_get(v->image), buf, evas_object_image_save(elm_image_object_get(v->image), buf,
NULL, NULL); NULL, NULL);
if (!success) if (!success)
_failed_save(sb); {
_failed_save(sb);
eina_stringshare_del(sb->pending_path);
sb->pending_path = NULL;
}
else else
{ {
char *dir = ecore_file_dir_get(buf); char *dir = ecore_file_dir_get(buf);
@ -1330,8 +1356,6 @@ _save_image_as_done(void *data, Evas_Object *obj EINA_UNUSED, void *event_info)
ephoto_thumb_browser_top_dir_set(sb->ephoto, ephoto_thumb_browser_top_dir_set(sb->ephoto,
sb->ephoto->config->directory); sb->ephoto->config->directory);
free(dir); free(dir);
ephoto_single_browser_path_pending_set(sb->ephoto->
single_browser, buf);
} }
} }
} }
@ -2486,7 +2510,7 @@ _ephoto_single_entry_create(void *data, int type EINA_UNUSED,
Ephoto_Entry *e; Ephoto_Entry *e;
e = ev->entry; e = ev->entry;
if (!sb->entry && sb->pending_path && e->path == sb->pending_path) if (sb->pending_path && !strcmp(e->path, sb->pending_path))
{ {
eina_stringshare_del(sb->pending_path); eina_stringshare_del(sb->pending_path);
sb->pending_path = NULL; sb->pending_path = NULL;
@ -2697,7 +2721,7 @@ ephoto_single_browser_entry_set(Evas_Object *obj, Ephoto_Entry *entry)
sb->entry = entry; sb->entry = entry;
if (entry) if (entry)
ephoto_entry_free_listener_add(entry, _entry_free, sb); ephoto_entry_free_listener_add(entry, _entry_free, sb);
_ephoto_single_browser_recalc(sb); _ephoto_single_browser_recalc(sb);
if (sb->edited_image_data) if (sb->edited_image_data)
@ -2757,9 +2781,28 @@ ephoto_single_browser_path_pending_set(Evas_Object *obj, const char *path)
{ {
Ephoto_Single_Browser *sb = evas_object_data_get(obj, "single_browser"); Ephoto_Single_Browser *sb = evas_object_data_get(obj, "single_browser");
if (sb->pending_path)
{
eina_stringshare_del(sb->pending_path);
sb->pending_path = NULL;
}
sb->pending_path = eina_stringshare_add(path); sb->pending_path = eina_stringshare_add(path);
} }
void
ephoto_single_browser_path_created(Evas_Object *obj, Ephoto_Entry *entry)
{
Ephoto_Single_Browser *sb = evas_object_data_get(obj, "single_browser");
if (sb->pending_path && !strcmp(entry->path, sb->pending_path))
{
eina_stringshare_del(sb->pending_path);
sb->pending_path = NULL;
ephoto_single_browser_entry_set(sb->ephoto->single_browser, entry);
}
}
void void
ephoto_single_browser_image_data_update(Evas_Object *main, Evas_Object *image, ephoto_single_browser_image_data_update(Evas_Object *main, Evas_Object *image,
Eina_Bool finished, unsigned int *image_data, int w, int h) Eina_Bool finished, unsigned int *image_data, int w, int h)

View File

@ -507,6 +507,8 @@ _monitor_created(void *data, int type EINA_UNUSED, void *event)
if (!entry) if (!entry)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!ecore_file_is_dir(ev->filename))
return ECORE_CALLBACK_PASS_ON;
snprintf(file, PATH_MAX, "%s", ev->filename); snprintf(file, PATH_MAX, "%s", ev->filename);
snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file)); snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file));
@ -641,6 +643,8 @@ _monitor_modified(void *data, int type EINA_UNUSED, void *event)
if (!entry) if (!entry)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!ecore_file_is_dir(ev->filename))
return ECORE_CALLBACK_PASS_ON;
snprintf(file, PATH_MAX, "%s", ev->filename); snprintf(file, PATH_MAX, "%s", ev->filename);
snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file)); snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file));
@ -1397,7 +1401,7 @@ _move_idler_cb(void *data)
if (!file) if (!file)
break; break;
if (ecore_file_exists(file) && ecore_file_is_dir(destination) && if (ecore_file_exists(file) && ecore_file_is_dir(destination) &&
!strncmp("image/", efreet_mime_type_get(file), 6)) evas_object_image_extension_can_load_get(file))
{ {
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX]; char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret; int ret;
@ -1496,7 +1500,7 @@ _copy_idler_cb(void *data)
if (!file) if (!file)
break; break;
if (ecore_file_exists(file) && ecore_file_is_dir(destination) && if (ecore_file_exists(file) && ecore_file_is_dir(destination) &&
!strncmp("image/", efreet_mime_type_get(file), 6)) evas_object_image_extension_can_load_get(file))
{ {
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX]; char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret; int ret;
@ -3646,6 +3650,8 @@ _top_monitor_created(void *data, int type EINA_UNUSED, void *event)
if (!tb) if (!tb)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!ecore_file_is_dir(ev->filename))
return ECORE_CALLBACK_PASS_ON;
snprintf(file, PATH_MAX, "%s", ev->filename); snprintf(file, PATH_MAX, "%s", ev->filename);
snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file)); snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file));
@ -3728,6 +3734,8 @@ _top_monitor_modified(void *data, int type EINA_UNUSED, void *event)
if (!tb) if (!tb)
return ECORE_CALLBACK_PASS_ON; return ECORE_CALLBACK_PASS_ON;
if (!ecore_file_is_dir(ev->filename))
return ECORE_CALLBACK_PASS_ON;
snprintf(file, PATH_MAX, "%s", ev->filename); snprintf(file, PATH_MAX, "%s", ev->filename);
snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file)); snprintf(dir, PATH_MAX, "%s", ecore_file_dir_get(file));
@ -3847,6 +3855,29 @@ ephoto_thumb_browser_remove(Ephoto *ephoto, Ephoto_Entry *entry)
} }
} }
void
ephoto_thumb_browser_update(Ephoto *ephoto, Ephoto_Entry *entry)
{
Ephoto_Thumb_Browser *tb =
evas_object_data_get(ephoto->thumb_browser, "thumb_browser");
if (!entry->is_dir)
{
Eina_File *f;
tb->totsize -= entry->size;
f = eina_file_open(entry->path, EINA_FALSE);
entry->size = eina_file_size_get(f);
tb->totsize += (double) entry->size;
eina_file_close(f);
elm_gengrid_item_update(entry->item);
tb->totsize += entry->size;
_update_info_label(tb);
}
}
void void
ephoto_thumb_browser_top_dir_set(Ephoto *ephoto, const char *dir) ephoto_thumb_browser_top_dir_set(Ephoto *ephoto, const char *dir)
{ {
@ -4048,9 +4079,9 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
EVAS_HINT_FILL); EVAS_HINT_FILL);
evas_object_size_hint_align_set(tb->direntry, EVAS_HINT_FILL, evas_object_size_hint_align_set(tb->direntry, EVAS_HINT_FILL,
EVAS_HINT_FILL); EVAS_HINT_FILL);
elm_box_pack_end(tb->leftbox, tb->direntry);
evas_object_smart_callback_add(tb->direntry, "activated", evas_object_smart_callback_add(tb->direntry, "activated",
_ephoto_direntry_go, tb); _ephoto_direntry_go, tb);
elm_box_pack_end(tb->leftbox, tb->direntry);
evas_object_show(tb->direntry); evas_object_show(tb->direntry);
tb->fsel = elm_genlist_add(tb->leftbox); tb->fsel = elm_genlist_add(tb->leftbox);
@ -4059,7 +4090,6 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
evas_object_size_hint_weight_set(tb->fsel, EVAS_HINT_EXPAND, evas_object_size_hint_weight_set(tb->fsel, EVAS_HINT_EXPAND,
EVAS_HINT_EXPAND); EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(tb->fsel, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_align_set(tb->fsel, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(tb->leftbox, tb->fsel);
evas_object_smart_callback_add(tb->fsel, "expand,request", evas_object_smart_callback_add(tb->fsel, "expand,request",
_on_list_expand_req, tb); _on_list_expand_req, tb);
evas_object_smart_callback_add(tb->fsel, "contract,request", evas_object_smart_callback_add(tb->fsel, "contract,request",
@ -4070,6 +4100,7 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
evas_object_event_callback_add(tb->fsel, EVAS_CALLBACK_MOUSE_UP, evas_object_event_callback_add(tb->fsel, EVAS_CALLBACK_MOUSE_UP,
_fsel_mouse_up_cb, tb); _fsel_mouse_up_cb, tb);
evas_object_data_set(tb->fsel, "thumb_browser", tb); evas_object_data_set(tb->fsel, "thumb_browser", tb);
elm_box_pack_end(tb->leftbox, tb->fsel);
evas_object_show(tb->fsel); evas_object_show(tb->fsel);
elm_drop_item_container_add(tb->fsel, ELM_SEL_FORMAT_TARGETS, elm_drop_item_container_add(tb->fsel, ELM_SEL_FORMAT_TARGETS,
_drop_item_getcb, _drop_enter, tb, _drop_leave, tb, _drop_pos, tb, _drop_item_getcb, _drop_enter, tb, _drop_leave, tb, _drop_pos, tb,
@ -4095,11 +4126,11 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
EVAS_HINT_FILL); EVAS_HINT_FILL);
evas_object_size_hint_aspect_set(tb->nolabel, EVAS_ASPECT_CONTROL_VERTICAL, evas_object_size_hint_aspect_set(tb->nolabel, EVAS_ASPECT_CONTROL_VERTICAL,
1, 1); 1, 1);
evas_object_show(tb->nolabel);
if (!tb->ephoto->config->fsel_hide) if (!tb->ephoto->config->fsel_hide)
elm_table_pack(tb->table, tb->nolabel, 1, 0, 4, 1); elm_table_pack(tb->table, tb->nolabel, 1, 0, 4, 1);
else else
elm_table_pack(tb->table, tb->nolabel, 0, 0, 5, 1); elm_table_pack(tb->table, tb->nolabel, 0, 0, 5, 1);
evas_object_show(tb->nolabel);
tb->gridbox = elm_box_add(tb->table); tb->gridbox = elm_box_add(tb->table);
elm_box_horizontal_set(tb->gridbox, EINA_FALSE); elm_box_horizontal_set(tb->gridbox, EINA_FALSE);
@ -4125,17 +4156,15 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
elm_drag_item_container_add(tb->grid, ANIM_TIME, DRAG_TIMEOUT, elm_drag_item_container_add(tb->grid, ANIM_TIME, DRAG_TIMEOUT,
_dnd_item_get, _dnd_item_data_get); _dnd_item_get, _dnd_item_data_get);
evas_object_data_set(tb->grid, "thumb_browser", tb); evas_object_data_set(tb->grid, "thumb_browser", tb);
_zoom_set(tb, tb->ephoto->config->thumb_size);
elm_box_pack_end(tb->gridbox, tb->grid); elm_box_pack_end(tb->gridbox, tb->grid);
evas_object_show(tb->grid); evas_object_show(tb->grid);
if (!tb->ephoto->config->fsel_hide) if (!tb->ephoto->config->fsel_hide)
elm_table_pack(tb->table, tb->gridbox, 1, 0, 4, 1); elm_table_pack(tb->table, tb->gridbox, 1, 0, 4, 1);
else else
elm_table_pack(tb->table, tb->gridbox, 0, 0, 5, 1); elm_table_pack(tb->table, tb->gridbox, 0, 0, 5, 1);
_zoom_set(tb, tb->ephoto->config->thumb_size);
tb->infolabel = elm_label_add(tb->table); tb->infolabel = elm_label_add(tb->table);
elm_label_line_wrap_set(tb->infolabel, ELM_WRAP_WORD); elm_label_line_wrap_set(tb->infolabel, ELM_WRAP_WORD);
elm_object_text_set(tb->infolabel, "Info Label"); elm_object_text_set(tb->infolabel, "Info Label");
@ -4144,8 +4173,8 @@ ephoto_thumb_browser_add(Ephoto *ephoto, Evas_Object *parent)
EVAS_HINT_FILL); EVAS_HINT_FILL);
evas_object_size_hint_aspect_set(tb->infolabel, evas_object_size_hint_aspect_set(tb->infolabel,
EVAS_ASPECT_CONTROL_VERTICAL, 1, 1); EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
evas_object_show(tb->infolabel);
elm_table_pack(tb->table, tb->infolabel, 0, 1, 5, 1); elm_table_pack(tb->table, tb->infolabel, 0, 1, 5, 1);
evas_object_show(tb->infolabel);
tb->handlers = tb->handlers =
eina_list_append(tb->handlers, eina_list_append(tb->handlers,