2009-06-21 03:31:38 -07:00
|
|
|
#include "e.h"
|
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
|
|
|
typedef struct _Inst Inst;
|
|
|
|
|
|
|
|
struct _Inst
|
|
|
|
{
|
|
|
|
const char *directory;
|
|
|
|
};
|
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
static Evry_Plugin *_plug_new();
|
|
|
|
static void _plug_free(Evry_Plugin *p);
|
|
|
|
static int _begin(Evry_Plugin *p, Evry_Item *item);
|
|
|
|
static int _fetch(Evry_Plugin *p, const char *input);
|
|
|
|
static int _action(Evry_Plugin *p, Evry_Item *item, const char *input);
|
|
|
|
static void _cleanup(Evry_Plugin *p);
|
|
|
|
static int _cb_sort(const void *data1, const void *data2);
|
|
|
|
static void _item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e);
|
|
|
|
static void _list_free(Evry_Plugin *p);
|
|
|
|
static Evry_Item *_item_fill(const char *directory, const char *file);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
|
|
|
static Evry_Plugin_Class class;
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
evry_plug_dir_browse_init(void)
|
|
|
|
{
|
|
|
|
class.name = "Browse Files";
|
|
|
|
class.type_in = "NONE|FILE";
|
|
|
|
class.type_out = "FILE";
|
2009-06-21 14:16:02 -07:00
|
|
|
class.prio = 2;
|
|
|
|
class.new = &_plug_new;
|
|
|
|
class.free = &_plug_free;
|
2009-06-21 03:31:38 -07:00
|
|
|
evry_plugin_register(&class);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
evry_plug_dir_browse_shutdown(void)
|
|
|
|
{
|
|
|
|
evry_plugin_unregister(&class);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evry_Plugin *
|
2009-06-21 14:16:02 -07:00
|
|
|
_plug_new()
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
|
|
|
|
p->class = &class;
|
2009-06-21 14:16:02 -07:00
|
|
|
p->begin = &_begin;
|
|
|
|
p->fetch = &_fetch;
|
|
|
|
p->action = &_action;
|
|
|
|
p->cleanup = &_cleanup;
|
|
|
|
p->icon_get = &_item_icon_get;
|
2009-06-21 03:31:38 -07:00
|
|
|
p->items = NULL;
|
|
|
|
|
|
|
|
Inst *inst = E_NEW(Inst, 1);
|
|
|
|
inst->directory = eina_stringshare_add(e_user_homedir_get());
|
|
|
|
p->priv = inst;
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-21 14:16:02 -07:00
|
|
|
_plug_free(Evry_Plugin *p)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-06-21 14:16:02 -07:00
|
|
|
_cleanup(p);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
|
|
|
Inst *inst = p->priv;
|
|
|
|
eina_stringshare_del(inst->directory);
|
|
|
|
E_FREE(inst);
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2009-06-21 14:16:02 -07:00
|
|
|
_action(Evry_Plugin *p, Evry_Item *item, const char *input)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-21 14:16:02 -07:00
|
|
|
_list_free(Evry_Plugin *p)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Evry_Item *it;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(p->items, it)
|
|
|
|
{
|
|
|
|
if (it->label) eina_stringshare_del(it->label);
|
|
|
|
if (it->uri) eina_stringshare_del(it->uri);
|
|
|
|
if (it->mime) eina_stringshare_del(it->mime);
|
|
|
|
if (it->o_icon) evas_object_del(it->o_icon);
|
|
|
|
|
|
|
|
free(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2009-06-21 14:16:02 -07:00
|
|
|
_cleanup(Evry_Plugin *p)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-06-21 14:16:02 -07:00
|
|
|
_list_free(p);
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-21 14:16:02 -07:00
|
|
|
_begin(Evry_Plugin *p, Evry_Item *item)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Inst *inst = p->priv;
|
|
|
|
|
|
|
|
if (item->uri && ecore_file_is_dir(item->uri))
|
|
|
|
{
|
|
|
|
eina_stringshare_del(inst->directory);
|
|
|
|
inst->directory = eina_stringshare_add(item->uri);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* based on directory-watcher from drawer module */
|
|
|
|
static int
|
2009-06-21 14:16:02 -07:00
|
|
|
_fetch(Evry_Plugin *p, const char *input)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Eina_List *files;
|
|
|
|
char *file;
|
|
|
|
Evry_Item *it;
|
|
|
|
char match1[4096];
|
|
|
|
char match2[4096];
|
|
|
|
Inst *inst = p->priv;
|
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
_list_free(p);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
|
|
|
files = ecore_file_ls(inst->directory);
|
|
|
|
|
2009-06-21 14:16:02 -07:00
|
|
|
if (input)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-06-21 14:16:02 -07:00
|
|
|
snprintf(match1, sizeof(match1), "%s*", input);
|
|
|
|
snprintf(match2, sizeof(match2), "*%s*", input);
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FREE(files, file)
|
|
|
|
{
|
|
|
|
if ((file[0] == '.') ||
|
2009-06-21 14:16:02 -07:00
|
|
|
(input &&
|
2009-06-21 03:31:38 -07:00
|
|
|
(!e_util_glob_case_match(file, match1)) &&
|
|
|
|
(!e_util_glob_case_match(file, match2))))
|
|
|
|
goto end;
|
2009-06-21 14:16:02 -07:00
|
|
|
it = _item_fill(inst->directory, file);
|
2009-06-21 03:31:38 -07:00
|
|
|
if (it)
|
|
|
|
p->items = eina_list_append(p->items, it);
|
|
|
|
|
|
|
|
end:
|
|
|
|
free(file);
|
|
|
|
|
|
|
|
}
|
2009-06-21 16:25:39 -07:00
|
|
|
|
|
|
|
if (eina_list_count(p->items) > 0)
|
|
|
|
{
|
|
|
|
p->items = eina_list_sort(p->items, eina_list_count(p->items),
|
|
|
|
_cb_sort);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* based on directory-watcher from drawer module */
|
|
|
|
static Evry_Item *
|
2009-06-21 14:16:02 -07:00
|
|
|
_item_fill(const char *directory, const char *file)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Evry_Item *it = NULL;
|
|
|
|
char buf[4096];
|
|
|
|
const char *mime, *file_path;
|
|
|
|
|
|
|
|
it = E_NEW(Evry_Item, 1);
|
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", directory, file);
|
|
|
|
|
2009-06-21 16:25:39 -07:00
|
|
|
if ((e_util_glob_case_match(file, "*.desktop")) ||
|
|
|
|
(e_util_glob_case_match(file, "*.directory")))
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
Efreet_Desktop *desktop;
|
|
|
|
|
|
|
|
desktop = efreet_desktop_new(buf);
|
|
|
|
if (!desktop) return NULL;
|
|
|
|
it->label = eina_stringshare_add(desktop->name);
|
|
|
|
efreet_desktop_free(desktop);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
it->label = eina_stringshare_add(file);
|
|
|
|
|
|
|
|
file_path = eina_stringshare_add(buf);
|
|
|
|
|
2009-06-21 16:25:39 -07:00
|
|
|
it->uri = file_path;
|
|
|
|
|
|
|
|
mime = efreet_mime_globs_type_get(file_path);
|
2009-06-21 03:31:38 -07:00
|
|
|
if (mime)
|
|
|
|
{
|
|
|
|
it->mime = eina_stringshare_add(mime);
|
2009-06-21 16:25:39 -07:00
|
|
|
it->priority = 0;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
else if (ecore_file_is_dir(file_path))
|
|
|
|
{
|
|
|
|
it->mime = eina_stringshare_add("Folder");
|
|
|
|
it->priority = 1;
|
|
|
|
}
|
2009-06-21 16:25:39 -07:00
|
|
|
else if ((mime = efreet_mime_type_get(file_path)))
|
|
|
|
{
|
|
|
|
it->mime = eina_stringshare_add(mime);
|
|
|
|
it->priority = 0;
|
|
|
|
}
|
|
|
|
else
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
it->mime = eina_stringshare_add("None");
|
2009-06-21 16:25:39 -07:00
|
|
|
it->priority = 0;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-06-21 14:16:02 -07:00
|
|
|
_item_icon_get(Evry_Plugin *p, Evry_Item *it, Evas *e)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
char *item_path;
|
|
|
|
|
|
|
|
if (!it->mime) return;
|
|
|
|
|
|
|
|
if (!strcmp(it->mime, "Folder"))
|
|
|
|
{
|
|
|
|
it->o_icon = edje_object_add(e);
|
2009-06-21 15:40:21 -07:00
|
|
|
e_theme_edje_object_set(it->o_icon, "base/theme/fileman", "e/icons/folder");
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
item_path = efreet_mime_type_icon_get(it->mime, e_config->icon_theme, 32);
|
|
|
|
|
|
|
|
if (item_path)
|
|
|
|
it->o_icon = e_util_icon_add(item_path, e);
|
2009-06-21 16:25:39 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
it->o_icon = edje_object_add(e);
|
|
|
|
e_theme_edje_object_set(it->o_icon, "base/theme/fileman", "e/icons/fileman/file");
|
|
|
|
}
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-06-21 14:16:02 -07:00
|
|
|
_cb_sort(const void *data1, const void *data2)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
|
|
|
const Evry_Item *it1, *it2;
|
|
|
|
|
|
|
|
it1 = data1;
|
|
|
|
it2 = data2;
|
|
|
|
|
2009-06-21 16:25:39 -07:00
|
|
|
return (it2->priority - it1->priority);
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|