Ephoto: Condense path lookups for trash and config into a single variable.

master
Stephen 'Okra' Houston 6 years ago
parent ef805cefa9
commit c6e6047d1a
  1. 2
      src/bin/ephoto.h
  2. 16
      src/bin/ephoto_directory_browser.c
  3. 32
      src/bin/ephoto_file.c
  4. 12
      src/bin/ephoto_main.c
  5. 2
      src/bin/ephoto_scale.c
  6. 4
      src/bin/ephoto_single_browser.c
  7. 17
      src/bin/ephoto_thumb_browser.c

@ -276,6 +276,8 @@ struct _Ephoto
int file_errors;
const char *top_directory;
const char *config_path;
const char *trash_path;
const char *destination;
int thumb_gen_size;

@ -430,7 +430,6 @@ _dir_go_trash(void *data, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
Ephoto_Directory_Browser *db = data;
char path[PATH_MAX];
Evas_Object *ic, *but;
db->fsel_back = db->fsel;
@ -473,12 +472,11 @@ _dir_go_trash(void *data, Evas_Object *obj EINA_UNUSED,
eina_stringshare_replace(&db->back_directory,
db->ephoto->config->directory);
snprintf(path, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(path))
ecore_file_mkpath(path);
if (!ecore_file_exists(db->ephoto->trash_path))
ecore_file_mkpath(db->ephoto->trash_path);
db->thumbs_only = 0;
db->dirs_only = 0;
ephoto_directory_set(db->ephoto, path, NULL,
ephoto_directory_set(db->ephoto, db->ephoto->trash_path, NULL,
db->dirs_only, db->thumbs_only);
ephoto_title_set(db->ephoto, _("Trash"));
ephoto_directory_browser_top_dir_set(db->ephoto, db->ephoto->config->directory);
@ -573,7 +571,6 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
Evas_Object *menu;
Elm_Object_Item *item;
Evas_Event_Mouse_Up *info = event_info;
char trash[PATH_MAX];
Evas_Coord x, y;
evas_pointer_canvas_xy_get(evas_object_evas_get(db->fsel), &x, &y);
@ -607,7 +604,6 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
if (info->button != 3)
return;
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (item)
elm_genlist_item_selected_set(item, EINA_TRUE);
@ -615,7 +611,7 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
menu = elm_menu_add(db->ephoto->win);
elm_menu_move(menu, x, y);
if (strcmp(db->ephoto->config->directory, trash))
if (strcmp(db->ephoto->config->directory, db->ephoto->trash_path))
{
elm_menu_item_add(menu, NULL, "folder-new", _("New Folder"),
_fsel_menu_new_dir_cb, db);
@ -627,13 +623,13 @@ _fsel_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
elm_menu_item_add(menu, NULL, "edit-paste", _("Paste"),
_fsel_menu_paste_cb, db);
}
else if (!strcmp(db->ephoto->config->directory, trash) &&
else if (!strcmp(db->ephoto->config->directory, db->ephoto->trash_path) &&
elm_genlist_first_item_get(db->fsel))
{
elm_menu_item_add(menu, NULL, "edit-delete", _("Empty Trash"),
_menu_empty_cb, db);
}
if (strcmp(db->ephoto->config->directory, trash) && item)
if (strcmp(db->ephoto->config->directory, db->ephoto->trash_path) && item)
{
elm_menu_item_add(menu, NULL, "edit-delete", _("Delete"),
_fsel_menu_delete_cb, db);

@ -726,11 +726,9 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Ephoto *ephoto = data;
const char *file;
char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(destination))
ecore_file_mkpath(destination);
if (!ecore_file_exists(ephoto->trash_path))
ecore_file_mkpath(ephoto->trash_path);
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);
@ -738,7 +736,7 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
if (!file)
break;
if (ecore_file_exists(file) && ecore_file_is_dir(destination))
if (ecore_file_exists(file) && ecore_file_is_dir(ephoto->trash_path))
{
char dest[PATH_MAX], fp[PATH_MAX], extra[PATH_MAX];
int ret;
@ -756,10 +754,10 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
else
{
snprintf(fp, PATH_MAX, "%s", file);
snprintf(dest, PATH_MAX, "%s/%s", destination, basename(fp));
snprintf(dest, PATH_MAX, "%s/%s", ephoto->trash_path, basename(fp));
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
snprintf(extra, PATH_MAX, "%s/CopyOf%s", ephoto->trash_path,
basename(fp));
if (ecore_file_exists(extra))
{
@ -769,7 +767,7 @@ _delete_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
memset(extra, 0, sizeof(extra));
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
ephoto->trash_path, count, basename(fp));
}
}
ret = ecore_file_mv(file, extra);
@ -805,12 +803,9 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
Ephoto *ephoto = data;
const char *dir = eina_list_data_get(ephoto->file_pos);
char destination[PATH_MAX];
snprintf(destination, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ecore_file_exists(destination))
ecore_file_mkpath(destination);
if (!ecore_file_exists(ephoto->trash_path))
ecore_file_mkpath(ephoto->trash_path);
if (dir)
{
@ -818,12 +813,12 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
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))
snprintf(dest, PATH_MAX, "%s/%s", ephoto->trash_path, basename(fp));
if (ecore_file_exists(dir) && ecore_file_is_dir(ephoto->trash_path))
{
if (ecore_file_exists(dest))
{
snprintf(extra, PATH_MAX, "%s/CopyOf%s", destination,
snprintf(extra, PATH_MAX, "%s/CopyOf%s", ephoto->trash_path,
basename(fp));
if (ecore_file_exists(extra))
{
@ -832,7 +827,7 @@ _delete_dir_thread_cb(void *data, Ecore_Thread *et EINA_UNUSED)
{
memset(extra, 0, sizeof(extra));
snprintf(extra, PATH_MAX, "%s/Copy%dOf%s",
destination, count, basename(fp));
ephoto->trash_path, count, basename(fp));
}
}
ret = ecore_file_mv(dir, extra);
@ -865,9 +860,6 @@ _empty_trash_thread_cb(void *data, Ecore_Thread *th EINA_UNUSED)
{
Ephoto *ephoto = data;
const char *file;
char trash[PATH_MAX];
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (!ephoto->file_pos)
ephoto->file_pos = eina_list_nth(ephoto->file_pos, 0);

@ -225,6 +225,10 @@ _win_free(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
free(ephoto->upload_error);
if (ephoto->top_directory)
eina_stringshare_del(ephoto->top_directory);
if (ephoto->config_path)
eina_stringshare_del(ephoto->config_path);
if (ephoto->trash_path)
eina_stringshare_del(ephoto->trash_path);
if (ephoto->timer.thumb_regen)
ecore_timer_del(ephoto->timer.thumb_regen);
if (ephoto->monitor)
@ -340,7 +344,7 @@ ephoto_window_add(const char *path)
{
Ephoto *ephoto = calloc(1, sizeof(Ephoto));
Evas_Object *ic, *but;
char buf[PATH_MAX];
char buf[PATH_MAX], config[PATH_MAX], trash[PATH_MAX];
int ret;
EINA_SAFETY_ON_NULL_RETURN_VAL(ephoto, NULL);
@ -587,6 +591,12 @@ ephoto_window_add(const char *path)
ephoto_single_browser_show_controls(ephoto);
ephoto->state = EPHOTO_STATE_SINGLE;
}
snprintf(config, PATH_MAX, "%s/.config/ephoto", eina_environment_home_get());
ephoto->config_path = eina_stringshare_add(config);
snprintf(trash, PATH_MAX, "%s/trash", ephoto->config_path);
ephoto->trash_path = eina_stringshare_add(trash);
ephoto_directory_browser_top_dir_set(ephoto, ephoto->config->directory);
ephoto_directory_browser_initialize_structure(ephoto);
evas_object_resize(ephoto->win, ephoto->config->window_width,

@ -195,7 +195,7 @@ ephoto_scale_add(Ephoto *ephoto, Evas_Object *main, Evas_Object *parent,
es->parent = parent;
es->image = image;
snprintf(buf, PATH_MAX, "%s/.config/ephoto/temp.%s", eina_environment_home_get(),
snprintf(buf, PATH_MAX, "%s/temp.%s", ephoto->config_path,
strrchr(file, '.')+1);
es->tmp_file = eina_stringshare_add(buf);
if (ecore_file_exists(es->tmp_file))

@ -2070,7 +2070,6 @@ static void
_ephoto_main_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
char tmp_path[PATH_MAX];
Ephoto_Single_Browser *sb = data;
Ecore_Event_Handler *handler;
Eina_Iterator *tmps;
@ -2084,8 +2083,7 @@ _ephoto_main_del(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
if (sb->edit_main)
evas_object_del(sb->edit_main);
sb->edit_main = NULL;
snprintf(tmp_path, PATH_MAX, "%s/.config/ephoto/", eina_environment_home_get());
tmps = eina_file_stat_ls(tmp_path);
tmps = eina_file_stat_ls(sb->ephoto->config_path);
EINA_ITERATOR_FOREACH(tmps, info)
{
const char *bname = info->path + info->name_start;

@ -864,7 +864,6 @@ _grid_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
Eina_Bool ctrl = evas_key_modifier_is_set(info->modifiers, "Control");
Eina_Bool shift = evas_key_modifier_is_set(info->modifiers, "Shift");
Eina_Bool clear_selection = EINA_FALSE;
char trash[PATH_MAX];
const Eina_List *selected = elm_gengrid_selected_items_get(tb->grid);
int x, y;
@ -945,8 +944,6 @@ _grid_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
return;
}
snprintf(trash, PATH_MAX, "%s/.config/ephoto/trash", eina_environment_home_get());
if (item)
{
elm_gengrid_item_selected_set(item, EINA_TRUE);
@ -989,7 +986,7 @@ _grid_mouse_up_cb(void *data, Evas *e EINA_UNUSED,
}
if (elm_gengrid_first_item_get(tb->grid))
{
if (!strcmp(tb->ephoto->config->directory, trash))
if (!strcmp(tb->ephoto->config->directory, tb->ephoto->trash_path))
{
elm_menu_item_add(menu, NULL, "edit-delete", _("Empty Trash"),
_menu_empty_cb, tb);
@ -1720,24 +1717,16 @@ _ephoto_main_key_down(void *data, Evas *e EINA_UNUSED, Evas_Object *obj EINA_UNU
}
else if (!strcasecmp(k, "Delete"))
{
char path[PATH_MAX];
char *trash;
snprintf(path, PATH_MAX, "%s/.config/ephoto/trash",
eina_environment_home_get());
trash = strdup(path);
if ((strlen(trash)) == (strlen(tb->ephoto->config->directory)))
if ((strlen(tb->ephoto->trash_path)) == (strlen(tb->ephoto->config->directory)))
{
if (!strcmp(trash, tb->ephoto->config->directory))
if (!strcmp(tb->ephoto->trash_path, tb->ephoto->config->directory))
{
_menu_empty_cb(tb, NULL, NULL);
free(trash);
return;
}
}
else
_grid_menu_delete_cb(tb, NULL, NULL);
free(trash);
}
}
else if (!strcasecmp(k, "F1"))

Loading…
Cancel
Save