forked from enlightenment/enlightenment
parent
f80e5cee0b
commit
0d6ce60bc7
|
@ -64,7 +64,6 @@ struct _Data
|
|||
int level;
|
||||
int cnt;
|
||||
Eina_List *files;
|
||||
Eina_List *list;
|
||||
DIR *dirp;
|
||||
int run_cnt;
|
||||
};
|
||||
|
@ -168,83 +167,41 @@ _item_free(Evry_Item *it)
|
|||
}
|
||||
|
||||
static void
|
||||
_scan_func(void *data, Ecore_Thread *thread __UNUSED__)
|
||||
_scan_func(void *data, Ecore_Thread *thread)
|
||||
{
|
||||
Data *d = data;
|
||||
Plugin *p = d->plugin;
|
||||
struct dirent *dp;
|
||||
Eina_Iterator *ls;
|
||||
Eina_File_Direct_Info *info;
|
||||
Evry_Item_File *file;
|
||||
char buf[4096];
|
||||
Eina_Bool is_dir;
|
||||
|
||||
if (!(d->dirp = opendir(d->directory)))
|
||||
if (!(ls = eina_file_stat_ls(d->directory)))
|
||||
return;
|
||||
|
||||
while ((dp = readdir(d->dirp)))
|
||||
EINA_ITERATOR_FOREACH(ls, info)
|
||||
{
|
||||
is_dir = EINA_FALSE;
|
||||
|
||||
if ((dp->d_name[0] == '.') &&
|
||||
((dp->d_name[1] == '\0') ||
|
||||
((dp->d_name[1] == '.') &&
|
||||
(dp->d_name[2] == '\0'))))
|
||||
continue;
|
||||
|
||||
#ifdef _DIRENT_HAVE_D_TYPE
|
||||
if (dp->d_type == DT_FIFO ||
|
||||
dp->d_type == DT_BLK ||
|
||||
dp->d_type == DT_CHR ||
|
||||
dp->d_type == DT_SOCK)
|
||||
continue;
|
||||
#endif
|
||||
if (!p->show_hidden)
|
||||
{
|
||||
if (dp->d_name[0] == '.')
|
||||
continue;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dp->d_name[0] != '.')
|
||||
continue;
|
||||
}
|
||||
|
||||
if (d->directory[1])
|
||||
snprintf(buf, sizeof(buf), "%s/%s",
|
||||
d->directory,
|
||||
dp->d_name);
|
||||
else
|
||||
snprintf(buf, sizeof(buf), "/%s",
|
||||
dp->d_name);
|
||||
|
||||
#ifdef _DIRENT_HAVE_D_TYPE
|
||||
if (dp->d_type & DT_UNKNOWN)
|
||||
{
|
||||
#endif
|
||||
if (ecore_file_is_dir(buf))
|
||||
is_dir = EINA_TRUE;
|
||||
|
||||
#ifdef _DIRENT_HAVE_D_TYPE
|
||||
}
|
||||
else if (dp->d_type & DT_DIR)
|
||||
{
|
||||
is_dir = EINA_TRUE;
|
||||
}
|
||||
#endif
|
||||
if (p->dirs_only && !is_dir)
|
||||
if ((p->show_hidden) != (*(info->path + info->name_start) == '.'))
|
||||
continue;
|
||||
|
||||
file = EVRY_ITEM_NEW(Evry_Item_File, p,
|
||||
NULL, NULL, _item_free);
|
||||
file->path = strdup(buf);
|
||||
EVRY_ITEM(file)->label = strdup(dp->d_name);
|
||||
EVRY_ITEM(file)->browseable = is_dir;
|
||||
file->path = strdup(info->path);
|
||||
EVRY_ITEM(file)->label = strdup(info->path + info->name_start);
|
||||
EVRY_ITEM(file)->browseable = (info->type == EINA_FILE_DIR);
|
||||
|
||||
d->files = eina_list_append(d->files, file);
|
||||
/* TODO dont append files in thread, run mime scan
|
||||
* simultaneously. ecore_thread_feedback(thread, file); */
|
||||
|
||||
if (ecore_thread_check(thread))
|
||||
break;
|
||||
}
|
||||
closedir(d->dirp);
|
||||
|
||||
eina_iterator_free(ls);
|
||||
}
|
||||
|
||||
static void
|
||||
_scan_mime_func(void *data, Ecore_Thread *thread __UNUSED__)
|
||||
_scan_mime_func(void *data, Ecore_Thread *thread)
|
||||
{
|
||||
Data *d = data;
|
||||
Evry_Item_File *file;
|
||||
|
@ -253,6 +210,9 @@ _scan_mime_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
|
||||
EINA_LIST_FOREACH(d->files, l, file)
|
||||
{
|
||||
if (ecore_thread_check(thread))
|
||||
break;
|
||||
|
||||
if ((file->mime = efreet_mime_type_get(file->path)))
|
||||
{
|
||||
if (!strncmp(file->mime, "inode/", 6) &&
|
||||
|
@ -267,7 +227,7 @@ _scan_mime_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
}
|
||||
|
||||
static int
|
||||
_append_files(Plugin *p)
|
||||
_files_filter(Plugin *p)
|
||||
{
|
||||
int match;
|
||||
int cnt = 0;
|
||||
|
@ -318,25 +278,20 @@ _scan_cancel_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
Plugin *p = d->plugin;
|
||||
Evry_Item_File *file;
|
||||
|
||||
if (!d->run_cnt) /* _scan_func was canceled */
|
||||
EINA_LIST_FREE(p->files, file)
|
||||
EVRY_ITEM_FREE(file);
|
||||
|
||||
EINA_LIST_FREE(d->files, file)
|
||||
{
|
||||
EINA_LIST_FREE(d->files, file)
|
||||
{
|
||||
if (file->base.label) free((char *)(file->base.label));
|
||||
if (file->path) free((char *)file->path);
|
||||
free(file);
|
||||
}
|
||||
}
|
||||
else /* _scan_mime_func was canceled */
|
||||
{
|
||||
EINA_LIST_FREE(d->files, file)
|
||||
EVRY_ITEM_FREE(file);
|
||||
if (file->base.label) free((char *)(file->base.label));
|
||||
if (file->path) free((char *)file->path);
|
||||
E_FREE(file);
|
||||
}
|
||||
|
||||
p->thread = NULL;
|
||||
|
||||
if (p->wait_finish)
|
||||
E_FREE(p);
|
||||
else
|
||||
p->thread = NULL;
|
||||
|
||||
free(d->directory);
|
||||
E_FREE(d);
|
||||
|
@ -348,7 +303,7 @@ _cache_mime_get(History_Types *ht, Evry_Item_File *file)
|
|||
History_Entry *he;
|
||||
History_Item *hi;
|
||||
Eina_List *l;
|
||||
|
||||
|
||||
if ((he = eina_hash_find(ht->types, file->path)))
|
||||
{
|
||||
EINA_LIST_FOREACH(he->items, l, hi)
|
||||
|
@ -357,7 +312,7 @@ _cache_mime_get(History_Types *ht, Evry_Item_File *file)
|
|||
continue;
|
||||
|
||||
if (!file->mime)
|
||||
file->mime = eina_stringshare_ref(hi->data);
|
||||
file->mime = hi->data;
|
||||
|
||||
hi->transient = 0;
|
||||
EVRY_ITEM(file)->hi = hi;
|
||||
|
@ -373,7 +328,7 @@ _cache_dir_add(Eina_List *files)
|
|||
Evry_Item *item;
|
||||
History_Item *hi;
|
||||
int cnt = 0;
|
||||
|
||||
|
||||
EINA_LIST_REVERSE_FOREACH(files, l, item)
|
||||
{
|
||||
GET_FILE(file, item);
|
||||
|
@ -396,11 +351,35 @@ _cache_dir_add(Eina_List *files)
|
|||
}
|
||||
|
||||
static void
|
||||
_scan_end_func(void *data, Ecore_Thread *thread __UNUSED__)
|
||||
_file_add(Plugin *p, Evry_Item *item)
|
||||
{
|
||||
GET_FILE(file, item);
|
||||
|
||||
char *filename = (char *)item->label;
|
||||
char *path = (char *) file->path;
|
||||
|
||||
file->path = eina_stringshare_add(path);
|
||||
file->mime = eina_stringshare_ref(file->mime);
|
||||
|
||||
item->label = eina_stringshare_add(filename);
|
||||
item->id = eina_stringshare_ref(file->path);
|
||||
item->context = eina_stringshare_ref(file->mime);
|
||||
|
||||
evry->util_file_detail_set(file);
|
||||
|
||||
p->files = eina_list_append(p->files, file);
|
||||
|
||||
E_FREE(filename);
|
||||
E_FREE(path);
|
||||
}
|
||||
|
||||
static void
|
||||
_scan_end_func(void *data, Ecore_Thread *thread)
|
||||
{
|
||||
Data *d = data;
|
||||
Plugin *p = d->plugin;
|
||||
Evry_Item *item;
|
||||
Evry_Item_File *file;
|
||||
char *filename, *path;
|
||||
Eina_List *l, *ll;
|
||||
History_Types *ht = NULL;
|
||||
|
@ -414,41 +393,16 @@ _scan_end_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
{
|
||||
GET_FILE(file, item);
|
||||
|
||||
filename = (char *)item->label;
|
||||
path = (char *) file->path;
|
||||
|
||||
if (!filename || !path)
|
||||
goto next;
|
||||
|
||||
file->path = eina_stringshare_add(path);
|
||||
|
||||
if (item->browseable)
|
||||
file->mime = eina_stringshare_ref(_mime_dir);
|
||||
file->mime = _mime_dir;
|
||||
else if (ht)
|
||||
_cache_mime_get(ht, file);
|
||||
|
||||
/* check if we can grab the mimetype from history */
|
||||
if (ht) _cache_mime_get(ht, file);
|
||||
|
||||
if (file->mime)
|
||||
{
|
||||
item->context = eina_stringshare_ref(file->mime);
|
||||
|
||||
d->files = eina_list_remove_list(d->files, l);
|
||||
p->files = eina_list_append(p->files, file);
|
||||
_file_add(p, item);
|
||||
}
|
||||
|
||||
item->id = eina_stringshare_ref(file->path);
|
||||
item->label = eina_stringshare_add(filename);
|
||||
evry->util_file_detail_set(file);
|
||||
|
||||
E_FREE(filename);
|
||||
E_FREE(path);
|
||||
continue;
|
||||
|
||||
next:
|
||||
d->files = eina_list_remove(d->files, file);
|
||||
E_FREE(file);
|
||||
E_FREE(filename);
|
||||
E_FREE(path);
|
||||
}
|
||||
|
||||
/* sort files by name for mimetypes scan */
|
||||
|
@ -457,16 +411,10 @@ _scan_end_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
}
|
||||
else /* _scan_mime_func finished */
|
||||
{
|
||||
EINA_LIST_FREE(d->files, item)
|
||||
EINA_LIST_FREE(d->files, file)
|
||||
{
|
||||
GET_FILE(file, item);
|
||||
|
||||
if (!file->mime) break;
|
||||
|
||||
file->mime = eina_stringshare_ref(file->mime);
|
||||
item->context = eina_stringshare_ref(file->mime);
|
||||
|
||||
p->files = eina_list_append(p->files, file);
|
||||
_file_add(p, (Evry_Item*) file);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -491,8 +439,8 @@ _scan_end_func(void *data, Ecore_Thread *thread __UNUSED__)
|
|||
}
|
||||
|
||||
p->files = eina_list_sort(p->files, -1, _cb_sort);
|
||||
|
||||
_append_files(p);
|
||||
|
||||
_files_filter(p);
|
||||
|
||||
EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
|
||||
}
|
||||
|
@ -547,7 +495,7 @@ _dir_watcher(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const c
|
|||
return;
|
||||
}
|
||||
|
||||
_append_files(p);
|
||||
_files_filter(p);
|
||||
|
||||
EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
|
||||
}
|
||||
|
@ -559,7 +507,7 @@ _read_directory(Plugin *p)
|
|||
d->plugin = p;
|
||||
d->directory = strdup(p->directory);
|
||||
d->run_cnt = 0;
|
||||
|
||||
|
||||
p->thread = ecore_thread_run(_scan_func, _scan_end_func, _scan_cancel_func, d);
|
||||
|
||||
if (p->dir_mon)
|
||||
|
@ -635,7 +583,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it)
|
|||
p->parent = EINA_FALSE;
|
||||
p->min_query = 0;
|
||||
_read_directory(p);
|
||||
|
||||
|
||||
return EVRY_PLUGIN(p);
|
||||
}
|
||||
else
|
||||
|
@ -815,7 +763,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
|
|||
p->input = eina_stringshare_add(input);
|
||||
|
||||
if ((p->command) || (!p->min_query) || (len >= p->min_query))
|
||||
_append_files(p);
|
||||
_files_filter(p);
|
||||
|
||||
return !!(EVRY_PLUGIN(p)->items);
|
||||
}
|
||||
|
@ -846,7 +794,7 @@ _cb_sort_recent(const void *data1, const void *data2)
|
|||
}
|
||||
|
||||
static int
|
||||
_recentf_append_files(Plugin *p)
|
||||
_recentf_files_filter(Plugin *p)
|
||||
{
|
||||
int match;
|
||||
int cnt = 0;
|
||||
|
@ -955,7 +903,7 @@ _recentf_end_func(void *data)
|
|||
p->files = eina_list_append(p->files, it);
|
||||
}
|
||||
|
||||
_recentf_append_files(p);
|
||||
_recentf_files_filter(p);
|
||||
|
||||
EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
|
||||
|
||||
|
@ -1159,7 +1107,7 @@ _recentf_fetch(Evry_Plugin *plugin, const char *input)
|
|||
p->files = eina_list_append(p->files, file);
|
||||
E_FREE(d);
|
||||
|
||||
_recentf_append_files(p);
|
||||
_recentf_files_filter(p);
|
||||
|
||||
/* _recentf_end_func(d);
|
||||
* p->thread = NULL; */
|
||||
|
@ -1296,7 +1244,7 @@ _sort_by_date(Plugin *p)
|
|||
}
|
||||
|
||||
p->files = eina_list_sort(p->files, -1, _cb_sort_date);
|
||||
_append_files(p);
|
||||
_files_filter(p);
|
||||
|
||||
EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
|
||||
|
||||
|
@ -1311,7 +1259,7 @@ _sort_by_name(Plugin *p)
|
|||
it->usage = 0;
|
||||
|
||||
p->files = eina_list_sort(p->files, -1, _cb_sort);
|
||||
_append_files(p);
|
||||
_files_filter(p);
|
||||
|
||||
EVRY_PLUGIN_UPDATE(p, EVRY_UPDATE_ADD);
|
||||
|
||||
|
|
Loading…
Reference in New Issue