Sort list of files before inserting
Signed-off-by: Eduardo Lima (Etrunko) <eduardo.lima@intel.com>
This commit is contained in:
parent
3813ef7c45
commit
be675a14cc
178
src/bin/dnd.c
178
src/bin/dnd.c
|
@ -6,6 +6,9 @@
|
||||||
#include "winlist.h"
|
#include "winlist.h"
|
||||||
#include "dnd.h"
|
#include "dnd.h"
|
||||||
|
|
||||||
|
static int pending_dir = 0;
|
||||||
|
static Eina_List *playlist = NULL;
|
||||||
|
|
||||||
void
|
void
|
||||||
_cb_drag_enter(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED)
|
_cb_drag_enter(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +27,31 @@ _cb_drag_pos(void *data EINA_UNUSED, Evas_Object *o EINA_UNUSED, Evas_Coord x EI
|
||||||
/* printf("dnd at %i %i act:%i\n", x, y, action); */
|
/* printf("dnd at %i %i act:%i\n", x, y, action); */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_dnd_finish(Evas_Object *win)
|
||||||
|
{
|
||||||
|
Eina_List *l;
|
||||||
|
char *path;
|
||||||
|
|
||||||
|
if (!eina_list_count(playlist))
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
EINA_LIST_FOREACH(playlist, l, path)
|
||||||
|
{
|
||||||
|
printf("inserting '%s'\n", path);
|
||||||
|
win_video_insert(win, path);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
win_video_next(win);
|
||||||
|
win_list_content_update(win);
|
||||||
|
|
||||||
|
end:
|
||||||
|
pending_dir = 0;
|
||||||
|
eina_list_free(playlist);
|
||||||
|
playlist = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
_xtov(char x)
|
_xtov(char x)
|
||||||
{
|
{
|
||||||
|
@ -64,19 +92,47 @@ _escape_parse(const char *str)
|
||||||
struct _recurse_data
|
struct _recurse_data
|
||||||
{
|
{
|
||||||
Evas_Object *win;
|
Evas_Object *win;
|
||||||
Eina_Bool inserted;
|
Eina_List *list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
_pathcmp(const char *p1, const char *p2)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
if (!p1)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (!p2)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/* skip common path */
|
||||||
|
while (p1[i] == p2[i])
|
||||||
|
++i;
|
||||||
|
|
||||||
|
return strcasecmp(p1+i, p2+i);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_cb_recurse_end(void *data, Eio_File *f EINA_UNUSED)
|
_cb_recurse_end(void *data, Eio_File *f EINA_UNUSED)
|
||||||
{
|
{
|
||||||
struct _recurse_data *d = data;
|
struct _recurse_data *d = data;
|
||||||
if (d->inserted)
|
|
||||||
|
if (!eina_list_count(d->list))
|
||||||
|
goto end;
|
||||||
|
|
||||||
|
if (!playlist)
|
||||||
{
|
{
|
||||||
win_video_next(d->win);
|
playlist = d->list;
|
||||||
win_list_content_update(d->win);
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playlist = eina_list_sorted_merge(playlist, d->list, EINA_COMPARE_CB(_pathcmp));
|
||||||
|
|
||||||
|
end:
|
||||||
|
if (--pending_dir == 0)
|
||||||
|
_dnd_finish(d->win);
|
||||||
|
|
||||||
free(d);
|
free(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,15 +152,10 @@ static void
|
||||||
_cb_recurse(void *data, Eio_File *f EINA_UNUSED, const Eina_File_Direct_Info *info)
|
_cb_recurse(void *data, Eio_File *f EINA_UNUSED, const Eina_File_Direct_Info *info)
|
||||||
{
|
{
|
||||||
struct _recurse_data *d = data;
|
struct _recurse_data *d = data;
|
||||||
char *path;
|
|
||||||
if (info->type == EINA_FILE_DIR)
|
if (info->type == EINA_FILE_DIR)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
path = _escape_parse(info->path);
|
d->list = eina_list_sorted_insert(d->list, EINA_COMPARE_CB(_pathcmp), _escape_parse(info->path));
|
||||||
printf("inserting '%s'\n", path);
|
|
||||||
win_video_insert(d->win, path);
|
|
||||||
d->inserted = EINA_TRUE;
|
|
||||||
free(path);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -120,96 +171,35 @@ Eina_Bool
|
||||||
_cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
|
_cb_drop(void *data, Evas_Object *o EINA_UNUSED, Elm_Selection_Data *ev)
|
||||||
{
|
{
|
||||||
Evas_Object *win = data;
|
Evas_Object *win = data;
|
||||||
Eina_Bool inserted = EINA_FALSE;
|
char **plist, **p, *esc;
|
||||||
|
|
||||||
if (!ev->data) return EINA_TRUE;
|
if (!ev->data)
|
||||||
if (strchr(ev->data, '\n'))
|
return EINA_TRUE;
|
||||||
{
|
|
||||||
char *p, *p2, *p3, *tb, *tt;
|
|
||||||
|
|
||||||
tb = malloc(strlen(ev->data) + 1);
|
plist = eina_str_split((char *) ev->data, "\n", -1);
|
||||||
if (tb)
|
for (p = plist; *p != NULL; ++p)
|
||||||
{
|
|
||||||
for (p = ev->data; p;)
|
|
||||||
{
|
|
||||||
p2 = strchr(p, '\n');
|
|
||||||
p3 = strchr(p, '\r');
|
|
||||||
if (p2 && p3)
|
|
||||||
{
|
|
||||||
if (p3 < p2) p2 = p3;
|
|
||||||
}
|
|
||||||
if (p2)
|
|
||||||
{
|
|
||||||
strncpy(tb, p, p2 - p);
|
|
||||||
tb[p2 - p] = 0;
|
|
||||||
p = p2;
|
|
||||||
while ((*p) && (isspace(*p))) p++;
|
|
||||||
if (strlen(tb) > 0)
|
|
||||||
{
|
|
||||||
tt = _escape_parse(tb);
|
|
||||||
if (tt)
|
|
||||||
{
|
|
||||||
if (ecore_file_is_dir(tt))
|
|
||||||
{
|
|
||||||
_recurse_dir(win, tt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
win_video_insert(win, tt);
|
|
||||||
inserted = EINA_TRUE;
|
|
||||||
}
|
|
||||||
free(tt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
strcpy(tb, p);
|
|
||||||
if (strlen(tb) > 0)
|
|
||||||
{
|
|
||||||
tt = _escape_parse(tb);
|
|
||||||
if (tt)
|
|
||||||
{
|
|
||||||
if (ecore_file_is_dir(tt))
|
|
||||||
{
|
|
||||||
_recurse_dir(win, tt);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
win_video_insert(win, tt);
|
|
||||||
inserted = EINA_TRUE;
|
|
||||||
}
|
|
||||||
free(tt);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
free(tb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
char *tt = _escape_parse(ev->data);
|
esc = _escape_parse(*p);
|
||||||
if (tt)
|
if (!esc)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (ecore_file_is_dir(esc))
|
||||||
{
|
{
|
||||||
if (ecore_file_is_dir(tt))
|
pending_dir++;
|
||||||
{
|
_recurse_dir(win, esc);
|
||||||
_recurse_dir(win, tt);
|
free(esc);
|
||||||
}
|
continue;
|
||||||
else
|
|
||||||
{
|
|
||||||
win_video_insert(win, tt);
|
|
||||||
inserted = EINA_TRUE;
|
|
||||||
}
|
|
||||||
free(tt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playlist = eina_list_sorted_insert(playlist, EINA_COMPARE_CB(_pathcmp), esc);
|
||||||
}
|
}
|
||||||
if (inserted)
|
|
||||||
{
|
free(*plist);
|
||||||
win_video_next(win);
|
free(plist);
|
||||||
win_list_content_update(win);
|
|
||||||
}
|
if (!pending_dir)
|
||||||
|
_dnd_finish(win);
|
||||||
|
|
||||||
return EINA_TRUE;
|
return EINA_TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue