You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1622 lines
50 KiB

#include "ephoto.h"
static void
_complete_ok(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_complete(Ephoto *ephoto, const char *title, const char *text)
{
Evas_Object *popup, *box, *label, *ic, *button;
popup = elm_popup_add(ephoto->win);
elm_object_part_text_set(popup, "title,text", title);
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
label = elm_label_add(box);
elm_object_text_set(label, text);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "window-close");
button = elm_button_add(popup);
elm_object_text_set(button, _("Ok"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _complete_ok, popup);
elm_object_part_content_set(popup, "button1", button);
evas_object_show(button);
evas_object_data_set(popup, "ephoto", ephoto);
elm_object_part_content_set(popup, "default", box);
evas_object_show(popup);
}
static void
_prompt_cancel(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static Evas_Object *
_prompt(Ephoto *ephoto, const char *title, const char *text)
{
Evas_Object *popup, *box, *label;
popup = elm_popup_add(ephoto->win);
elm_object_part_text_set(popup, "title,text", title);
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
label = elm_label_add(box);
elm_object_text_set(label, text);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
evas_object_data_set(popup, "ephoto", ephoto);
elm_object_part_content_set(popup, "default", box);
return popup;
}
static void
_save_image_as_overwrite(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = data;
const char *file = evas_object_data_get(popup, "file");
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
Ephoto_Entry *entry = evas_object_data_get(popup, "entry");
Evas_Object *image = evas_object_data_get(popup, "image");
Eina_Bool success;
if (ecore_file_exists(file))
{
success = ecore_file_unlink(file);
if (!success)
{
_complete(ephoto, _("Save Failed"),
_("Error: Image could not be saved here!"));
ephoto_single_browser_entry_set(ephoto->single_browser, entry);
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
return;
}
}
ephoto_single_browser_path_pending_set(ephoto->single_browser, file);
success =
evas_object_image_save(image, file,
NULL, NULL);
if (!success)
{
_complete(ephoto, _("Save Failed"),
_("Error: Image could not be saved here!"));
ephoto_single_browser_path_pending_unset(ephoto->single_browser);
}
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_upload_entry_anchor_bt(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
char buf[PATH_MAX];
Evas_Object *av = data;
const char *link = evas_object_data_get(av, "link");
elm_entry_anchor_hover_end(av);
snprintf(buf, PATH_MAX, "xdg-open %s", link);
ecore_exe_run(buf, NULL);
}
static void
_upload_entry_anchor(void *data, Evas_Object *obj, void *event_info)
{
Evas_Object *av = data;
Evas_Object *button;
Elm_Entry_Anchor_Hover_Info *ei = event_info;
button = elm_button_add(obj);
elm_object_text_set(button, _("Open Link In Browser"));
elm_object_part_content_set(ei->hover, "middle", button);
evas_object_smart_callback_add(button, "clicked", _upload_entry_anchor_bt,
av);
evas_object_show(button);
}
static void
_upload_image_url_copy(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *entry = data;
elm_entry_select_all(entry);
elm_entry_selection_copy(entry);
elm_entry_select_none(entry);
}
static Eina_Bool
_upload_image_complete_cb(void *data, int ev_type EINA_UNUSED, void *event)
{
Evas_Object *ppopup = data;
Ephoto *ephoto = evas_object_data_get(ppopup, "ephoto");
Ecore_Con_Event_Url_Complete *ev = event;
Ecore_Event_Handler *handler;
Evas_Object *popup, *box, *hbox, *label, *entry, *ic, *button;
int ret;
if (ev->url_con != ephoto->url_up)
return ECORE_CALLBACK_RENEW;
evas_object_del(ppopup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
popup = elm_popup_add(ephoto->win);
elm_object_part_text_set(popup, "title,text", _("Image Uploaded"));
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
label = elm_label_add(box);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
hbox = elm_box_add(box);
elm_box_horizontal_set(hbox, EINA_TRUE);
evas_object_size_hint_weight_set(hbox, EVAS_HINT_FILL, 0.0);
evas_object_size_hint_align_set(hbox, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, hbox);
evas_object_show(hbox);
entry = elm_entry_add(hbox);
elm_entry_anchor_hover_style_set(entry, "popout");
elm_entry_anchor_hover_parent_set(entry, ephoto->pager);
elm_entry_editable_set(entry, EINA_TRUE);
elm_entry_scrollable_set(entry, EINA_TRUE);
elm_entry_context_menu_disabled_set(entry, EINA_TRUE);
elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF,
ELM_SCROLLER_POLICY_OFF);
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_smart_callback_add(entry, "anchor,hover,opened",
_upload_entry_anchor, entry);
elm_box_pack_end(hbox, entry);
evas_object_show(entry);
ic = elm_icon_add(hbox);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_HORIZONTAL, 1, 1);
ret = elm_icon_standard_set(ic, "edit-copy");
button = elm_button_add(hbox);
elm_object_part_content_set(button, "icon", ic);
if (!ret)
elm_object_text_set(button, _("Copy"));
evas_object_smart_callback_add(button, "clicked", _upload_image_url_copy,
entry);
elm_box_pack_end(hbox, button);
evas_object_show(button);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "window-close");
button = elm_button_add(popup);
elm_object_text_set(button, _("Ok"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _prompt_cancel,
popup);
elm_object_part_content_set(popup, "button1", button);
evas_object_show(button);
evas_object_data_set(popup, "ephoto", ephoto);
elm_object_part_content_set(popup, "default", box);
evas_object_show(popup);
EINA_LIST_FREE(ephoto->upload_handlers,
handler) ecore_event_handler_del(handler);
if (!ephoto->url_ret || ev->status != 200)
{
elm_object_text_set(label,
_("There was an error uploading your image!"));
elm_entry_single_line_set(entry, EINA_TRUE);
elm_object_text_set(entry, ephoto->upload_error);
evas_object_show(popup);
ecore_con_url_free(ephoto->url_up);
ephoto->url_up = NULL;
free(ephoto->upload_error);
ephoto->upload_error = NULL;
return EINA_FALSE;
}
else
{
char buf[PATH_MAX], link[PATH_MAX];
snprintf(buf, PATH_MAX, "<a href=\"%s\"><link>%s</link</a>",
ephoto->url_ret, ephoto->url_ret);
snprintf(link, PATH_MAX, "%s", ephoto->url_ret);
evas_object_data_set(entry, "link", strdup(link));
elm_object_text_set(label,
_("Your image was uploaded to the following link:"));
elm_entry_single_line_set(entry, EINA_TRUE);
elm_object_text_set(entry, buf);
evas_object_show(popup);
ecore_con_url_free(ephoto->url_up);
ephoto->url_up = NULL;
free(ephoto->url_ret);
ephoto->url_ret = NULL;
return ECORE_CALLBACK_RENEW;
}
}
static Eina_Bool
_upload_image_xml_parse(void *data, Eina_Simple_XML_Type type,
const char *content, unsigned offset EINA_UNUSED,
unsigned length EINA_UNUSED)
{
Ephoto *ephoto = data;
char *linkf, *linkl;
if (type == EINA_SIMPLE_XML_OPEN)
{
if (!strncmp("link>", content, strlen("link>")))
{
linkf = strchr(content, '>') + 1;
linkl = strtok(linkf, "<");
ephoto->url_ret = strdup(linkl);
}
}
return EINA_TRUE;
}
static Eina_Bool
_upload_image_cb(void *data, int ev_type EINA_UNUSED, void *event)
{
Ephoto *ephoto = data;
Ecore_Con_Event_Url_Data *ev = event;
const char *string = (const char *) ev->data;
if (ev->url_con != ephoto->url_up)
return EINA_TRUE;
eina_simple_xml_parse(string, strlen(string) + 1, EINA_TRUE,
_upload_image_xml_parse, ephoto);
if (!ephoto->url_ret)
ephoto->upload_error = strdup(string);
return EINA_FALSE;
}
static void
_new_dir_confirm(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Evas_Object *popup = data;
Evas_Object *entry = evas_object_data_get(popup, "entry");
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file = evas_object_data_get(popup, "file");
const char *text = elm_object_text_get(entry);
char new_file_name[PATH_MAX];
int ret;
snprintf(new_file_name, PATH_MAX, "%s/%s", file, text);
ret = ecore_file_mkdir(new_file_name);
if (!ret)
{
_complete(ephoto, _("Error"),
_("There was an error creating this directory."));
}
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_new_dir_cancel(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_new_dir(Ephoto *ephoto, const char *file)
{
Evas_Object *popup, *box, *entry, *button, *ic;
popup = elm_popup_add(ephoto->win);
elm_object_part_text_set(popup, "title,text", _("New Directory"));
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "file", file);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
entry = elm_entry_add(box);
elm_entry_single_line_set(entry, EINA_TRUE);
elm_entry_scrollable_set(entry, EINA_TRUE);
elm_entry_editable_set(entry, EINA_TRUE);
elm_object_text_set(entry, _("New Directory"));
elm_entry_select_all(entry);
elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF,
ELM_SCROLLER_POLICY_OFF);
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, entry);
evas_object_show(entry);
evas_object_data_set(popup, "entry", entry);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "document-save");
button = elm_button_add(popup);
elm_object_text_set(button, _("Save"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _new_dir_confirm, popup);
elm_object_part_content_set(popup, "button1", button);
evas_object_show(button);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "window-close");
button = elm_button_add(popup);
elm_object_text_set(button, _("Cancel"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _new_dir_cancel, popup);
elm_object_part_content_set(popup, "button2", button);
evas_object_show(button);
elm_object_part_content_set(popup, "default", box);
evas_object_show(popup);
}
static void
_rename_confirm(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Evas_Object *popup = data;
Evas_Object *entry = evas_object_data_get(popup, "entry");
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file = evas_object_data_get(popup, "file");
const char *text = elm_object_text_get(entry);
char *escaped = ecore_file_escape_name(text);
char new_file_name[PATH_MAX], dir[PATH_MAX];
int ret;
if (!escaped)
{
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
return;
}
snprintf(dir, PATH_MAX, "%s", file);
if (ecore_file_is_dir(file))
snprintf(new_file_name, PATH_MAX, "%s/%s", ecore_file_dir_get(dir), text);
else
snprintf(new_file_name, PATH_MAX, "%s/%s.%s", ecore_file_dir_get(dir), escaped,
strrchr(dir, '.')+1);
ret = ecore_file_mv(file, new_file_name);
if (!ret)
{
if (ecore_file_is_dir(new_file_name))
_complete(ephoto, _("Error"),
_("There was an error renaming this directory."));
else
_complete(ephoto, _("Error"),
_("There was an error renaming this file."));
}
else
{
if (ephoto->state == EPHOTO_STATE_SINGLE)
ephoto_single_browser_path_pending_set(ephoto->single_browser,
new_file_name);
}
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
free(escaped);
}
static void
_rename_cancel(void *data, Evas_Object *obj EINA_UNUSED,
void *event_data EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_rename_file(Ephoto *ephoto, const char *file)
{
Evas_Object *popup, *box, *entry, *button, *ic;
char buf[PATH_MAX], *bn, *string;
popup = elm_popup_add(ephoto->win);
if (ecore_file_is_dir(file))
elm_object_part_text_set(popup, "title, text", _("Rename Directory"));
else
elm_object_part_text_set(popup, "title,text", _("Rename File"));
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "file", file);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
snprintf(buf, PATH_MAX, "%s", file);
bn = basename(buf);
string = ecore_file_strip_ext(bn);
entry = elm_entry_add(box);
elm_entry_single_line_set(entry, EINA_TRUE);
elm_entry_scrollable_set(entry, EINA_TRUE);
elm_entry_editable_set(entry, EINA_TRUE);
elm_object_text_set(entry, string);
elm_entry_select_all(entry);
elm_scroller_policy_set(entry, ELM_SCROLLER_POLICY_OFF,
ELM_SCROLLER_POLICY_OFF);
evas_object_size_hint_weight_set(entry, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(entry, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, entry);
evas_object_show(entry);
evas_object_data_set(popup, "entry", entry);
free(string);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "document-save");
button = elm_button_add(popup);
elm_object_text_set(button, _("Rename"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _rename_confirm, popup);
elm_object_part_content_set(popup, "button1", button);
evas_object_show(button);
ic = elm_icon_add(popup);
evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
elm_icon_standard_set(ic, "window-close");
button = elm_button_add(popup);
elm_object_text_set(button, _("Cancel"));
elm_object_part_content_set(button, "icon", ic);
evas_object_smart_callback_add(button, "clicked", _rename_cancel, popup);
elm_object_part_content_set(popup, "button2", button);
evas_object_show(button);
elm_object_part_content_set(popup, "default", box);
evas_object_show(popup);
}
static Evas_Object *
_processing(Ephoto *ephoto, const char *title, const char *text)
{
Evas_Object *popup, *box, *label, *pb;
popup = elm_popup_add(ephoto->win);
elm_object_part_text_set(popup, "title,text", title);
elm_popup_orient_set(popup, ELM_POPUP_ORIENT_CENTER);
box = elm_box_add(popup);
elm_box_horizontal_set(box, EINA_FALSE);
evas_object_size_hint_weight_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_size_hint_align_set(box, EVAS_HINT_FILL, EVAS_HINT_FILL);
evas_object_show(box);
label = elm_label_add(box);
elm_object_text_set(label, text);
evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
elm_box_pack_end(box, label);
evas_object_show(label);
pb = elm_progressbar_add(box);
evas_object_size_hint_weight_set(pb, EVAS_HINT_EXPAND, 0.0);
evas_object_size_hint_align_set(pb, EVAS_HINT_FILL, 0.5);
elm_object_style_set(pb, "wheel");
elm_progressbar_pulse_set(pb, EINA_TRUE);
elm_box_pack_end(box, pb);
evas_object_show(pb);
elm_progressbar_pulse(pb, EINA_TRUE);
evas_object_data_set(popup, "ephoto", ephoto);
elm_object_part_content_set(popup, "default", box);
return popup;
}
static void
_thread_end_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
}
static void
_move_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *destination = evas_object_data_get(popup, "destination");
const char *file;
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
EINA_LIST_FREE(ephoto->file_pos, file)
{
if (!file)
break;
if (ecore_file_exists(file) && ecore_file_is_dir(destination) &&
evas_object_image_extension_can_load_get(file))
{
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret;
snprintf(fp, PATH_MAX, "%s", file);
snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp));
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
basename(fp));
if (ecore_file_exists(extra))
{
int count;
for (count = 2; ecore_file_exists(extra); count++)
{
memset(extra, 0, sizeof(extra));
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
}
}
ret = ecore_file_mv(file, extra);
}
else
ret = ecore_file_mv(file, dest);
if (!ret)
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
_move_files(Ephoto *ephoto, Eina_List *files,
const char *destination)
{
Evas_Object *popup = _processing(ephoto, _("Moving Files"),
_("Please wait while your files are moved."));
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "destination", destination);
evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files);
eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_move_thread_cb,
_thread_end_cb, _thread_end_cb, popup);
}
static void
_copy_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *destination = evas_object_data_get(popup, "destination");
const char *file;
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
EINA_LIST_FREE(ephoto->file_pos, file)
{
if (ecore_file_exists(file) && ecore_file_is_dir(destination) &&
evas_object_image_extension_can_load_get(file))
{
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret;
snprintf(fp, PATH_MAX, "%s", file);
snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp));
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
basename(fp));
if (ecore_file_exists(extra))
{
int count;
for (count = 2; ecore_file_exists(extra); count++)
{
memset(extra, 0, PATH_MAX);
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
}
}
ret = ecore_file_cp(file, extra);
}
else
ret = ecore_file_cp(file, dest);
if (!ret)
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
_copy_files(Ephoto *ephoto, Eina_List *files,
const char *destination)
{
Evas_Object *popup = _processing(ephoto, _("Copying Files"),
_("Please wait while your files are copied."));
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "destination", destination);
evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files);
eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_copy_thread_cb,
_thread_end_cb, NULL, popup);
}
static void
_delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file;
char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
if (!ecore_file_exists(destination))
ecore_file_mkpath(destination);
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
EINA_LIST_FREE(ephoto->file_pos, file)
{
if (!file)
break;
if (ecore_file_exists(file) && ecore_file_is_dir(destination))
{
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret;
snprintf(fp, PATH_MAX, "%s", file);
snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp));
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
basename(fp));
if (ecore_file_exists(extra))
{
int count;
for (count = 2; ecore_file_exists(extra); count++)
{
memset(extra, 0, sizeof(extra));
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
}
}
ret = ecore_file_mv(file, extra);
}
else
ret = ecore_file_mv(file, dest);
if (!ret)
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
_delete_files(Ephoto *ephoto, Eina_List *files)
{
Evas_Object *popup = _processing(ephoto, _("Deleting Files"),
_("Please wait while your files are deleted."));
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "files", files);
evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files);
eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_delete_thread_cb,
_thread_end_cb, NULL, popup);
}
static void
_delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
Eina_List *files = evas_object_data_get(popup, "files");
const char *dir = eina_list_data_get(files);
char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
if (!ecore_file_exists(destination))
ecore_file_mkpath(destination);
if (dir)
{
char fp[PATH_MAX], dest[PATH_MAX], extra[PATH_MAX];
int ret;
snprintf(fp, PATH_MAX, "%s", dir);
snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp));
if (ecore_file_exists(dir) && ecore_file_is_dir(destination))
{
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
basename(fp));
if (ecore_file_exists(extra))
{
int count;
for (count = 2; ecore_file_exists(extra); count++)
{
memset(extra, 0, sizeof(extra));
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
}
}
ret = ecore_file_mv(dir, extra);
}
else
ret = ecore_file_mv(dir, dest);
if (!ret)
ephoto->file_errors++;
}
}
if (!dir || ephoto->file_errors > 0)
{
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
_delete_dir(Ephoto *ephoto, Eina_List *files)
{
Evas_Object *popup = _processing(ephoto, _("Deleting Directory"),
_("Please wait while your directory is deleted."));
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_data_set(popup, "files", files);
evas_object_show(popup);
ephoto->file_pos = NULL;
ephoto->file_thread = ecore_thread_run(_delete_dir_thread_cb,
_thread_end_cb, NULL, popup);
}
static void
_empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
const char *file;
char trash[PATH_MAX];
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", getenv("HOME"));
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
EINA_LIST_FREE(ephoto->file_pos, file)
{
if (!file)
break;
if (ecore_file_exists(file))
{
int ret;
if (ecore_file_is_dir(file))
ret = ecore_file_recursive_rm(file);
else
ret = ecore_file_unlink(file);
if (!ret)
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
_empty_trash(Ephoto *ephoto, Eina_List *files)
{
Evas_Object *popup = _processing(ephoto, _("Emptying Trash"),
_("Please wait while your files are deleted."));
evas_object_data_set(popup, "ephoto", ephoto);
evas_object_show(popup);
ephoto->file_pos = eina_list_clone(files);
eina_list_free(files);
ephoto->file_thread = ecore_thread_run(_empty_trash_thread_cb,
_thread_end_cb, NULL, popup);
}
static void
_prompt_upload_apply(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *ppopup = data;
Evas_Object *popup;
Ephoto *ephoto = evas_object_data_get(ppopup, "ephoto");
Ephoto_Entry *entry = evas_object_data_get(ppopup, "entry");
char buf[PATH_MAX];
FILE *f;
unsigned char *fdata;
int fsize;
evas_object_del(ppopup);
popup = _processing(ephoto, _("Upload Image"),
("Please wait while your image is uploaded."));
evas_object_show(popup);
f = fopen(entry->path, "rb");
fseek(f, 0, SEEK_END);
fsize = ftell(f);
rewind(f);
fdata = malloc(fsize);
fread(fdata, fsize, 1, f);
fclose(f);
snprintf(buf, PATH_MAX, "image=%s", fdata);
ephoto->upload_handlers =
eina_list_append(ephoto->upload_handlers,
ecore_event_handler_add(ECORE_CON_EVENT_URL_DATA,
_upload_image_cb, ephoto));
ephoto->upload_handlers =
eina_list_append(ephoto->upload_handlers,
ecore_event_handler_add(ECORE_CON_EVENT_URL_COMPLETE,
_upload_image_complete_cb, popup));
ephoto->url_up = ecore_con_url_new("https://api.imgur.com/3/image.xml");
ecore_con_url_additional_header_add(ephoto->url_up, "Authorization",
"Client-ID 67aecc7e6662370");
ecore_con_url_http_version_set(ephoto->url_up, ECORE_CON_URL_HTTP_VERSION_1_0);
ecore_con_url_post(ephoto->url_up, fdata, fsize, NULL);
}
static void
_prompt_save_image_apply(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Evas_Object *popup = data;
Ephoto *ephoto = evas_object_data_get(popup, "ephoto");
Ephoto_Entry *entry = evas_object_data_get(popup, "entry");
Evas_Object *image = evas_object_data_get(popup, "image");
Eina_Bool success;
if (ecore_file_exists(entry->path))
{
success = ecore_file_unlink(entry->path);
if (!success)
{
_complete(ephoto, _("Save Failed"),
_("Error: Image could not be saved here!"));
ephoto_single_browser_entry_set(ephoto->single_browser, entry);
evas_object_del(popup);
elm_object_focus_set(ephoto->pager, EINA_TRUE);
return;
}
}
success =
evas_object_image_save(image, entry->path,
NULL, NULL);