2010-04-10 13:05:57 -07:00
|
|
|
/*
|
|
|
|
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Evry.h"
|
2009-09-17 23:33:33 -07:00
|
|
|
#include "e_mod_main.h"
|
2009-08-13 08:10:54 -07:00
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
#define MAX_ITEMS 50
|
2009-09-17 23:33:33 -07:00
|
|
|
#define TERM_ACTION_DIR "%s"
|
2009-08-10 04:36:37 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
typedef struct _Plugin Plugin;
|
2009-08-27 15:58:34 -07:00
|
|
|
typedef struct _Data Data;
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
struct _Plugin
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-21 15:42:06 -07:00
|
|
|
Evry_Plugin base;
|
|
|
|
|
2010-04-16 11:36:28 -07:00
|
|
|
Eina_List *files;
|
2009-06-21 03:31:38 -07:00
|
|
|
const char *directory;
|
2010-04-16 11:36:28 -07:00
|
|
|
const char *input;
|
2009-08-11 06:31:38 -07:00
|
|
|
Eina_Bool command;
|
2010-04-15 06:58:44 -07:00
|
|
|
Eina_Bool parent;
|
2010-04-16 11:36:28 -07:00
|
|
|
Eina_Bool hist_added;
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
Ecore_Thread *thread;
|
2010-04-15 06:58:44 -07:00
|
|
|
Eina_Bool cleanup;
|
2009-08-27 15:58:34 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _Data
|
|
|
|
{
|
|
|
|
Plugin *plugin;
|
|
|
|
long id;
|
|
|
|
int level;
|
|
|
|
int cnt;
|
|
|
|
Eina_List *files;
|
2010-04-16 07:15:30 -07:00
|
|
|
Eina_List *list;
|
2009-06-21 03:31:38 -07:00
|
|
|
};
|
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
static Evry_Plugin *p1 = NULL;
|
|
|
|
static Evry_Plugin *p2 = NULL;
|
|
|
|
static Evry_Action *act1 = NULL;
|
|
|
|
static Evry_Action *act2 = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
static E_Module *module = NULL;
|
|
|
|
static Eina_Bool active = EINA_FALSE;
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
static void _cleanup(Evry_Plugin *plugin);
|
|
|
|
|
2010-04-13 15:15:56 -07:00
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
static void
|
2009-08-22 20:12:05 -07:00
|
|
|
_item_fill(Evry_Item_File *file)
|
2009-08-11 06:31:38 -07:00
|
|
|
{
|
2009-08-17 18:00:18 -07:00
|
|
|
const char *mime;
|
2010-04-13 15:15:56 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
if (file->mime) return;
|
2009-08-10 04:36:37 -07:00
|
|
|
|
2010-04-07 08:03:27 -07:00
|
|
|
if ((mime = efreet_mime_type_get(file->path)))
|
2009-08-11 06:31:38 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
file->mime = eina_stringshare_add(mime);
|
2009-09-03 07:21:27 -07:00
|
|
|
EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime);
|
2010-04-13 15:15:56 -07:00
|
|
|
|
2009-08-27 15:58:34 -07:00
|
|
|
if ((!strcmp(mime, "inode/directory")) ||
|
|
|
|
(!strcmp(mime, "inode/mount-point")))
|
|
|
|
EVRY_ITEM(file)->browseable = EINA_TRUE;
|
|
|
|
|
2009-08-17 20:15:36 -07:00
|
|
|
return;
|
2009-08-11 06:31:38 -07:00
|
|
|
}
|
2009-08-17 20:15:36 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
file->mime = eina_stringshare_add("None");
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-14 07:44:18 -07:00
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
2009-08-11 06:31:38 -07:00
|
|
|
|
2009-08-14 07:44:18 -07:00
|
|
|
if (it1->browseable && !it2->browseable)
|
|
|
|
return -1;
|
2009-08-11 06:31:38 -07:00
|
|
|
|
2009-08-14 07:44:18 -07:00
|
|
|
if (!it1->browseable && it2->browseable)
|
|
|
|
return 1;
|
|
|
|
|
2009-08-25 20:12:00 -07:00
|
|
|
if (it1->fuzzy_match && it2->fuzzy_match)
|
|
|
|
if (it1->fuzzy_match - it2->fuzzy_match)
|
|
|
|
return (it1->fuzzy_match - it2->fuzzy_match);
|
2009-08-14 07:44:18 -07:00
|
|
|
|
|
|
|
return strcasecmp(it1->label, it2->label);
|
2009-08-11 06:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
static void
|
|
|
|
_item_free(Evry_Item *it)
|
|
|
|
{
|
|
|
|
ITEM_FILE(file, it);
|
2010-04-07 08:03:27 -07:00
|
|
|
if (file->path) eina_stringshare_del(file->path);
|
2009-08-22 20:12:05 -07:00
|
|
|
if (file->mime) eina_stringshare_del(file->mime);
|
|
|
|
|
|
|
|
E_FREE(file);
|
|
|
|
}
|
|
|
|
|
2009-08-12 12:14:45 -07:00
|
|
|
static void
|
2009-08-27 15:58:34 -07:00
|
|
|
_scan_func(void *data)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-27 15:58:34 -07:00
|
|
|
Data *d = data;
|
|
|
|
Plugin *p = d->plugin;
|
|
|
|
char *filename;
|
2010-04-16 07:15:30 -07:00
|
|
|
const char *mime;
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
Evry_Item_File *file;
|
2009-08-27 15:58:34 -07:00
|
|
|
char buf[4096];
|
2010-04-16 07:15:30 -07:00
|
|
|
int cnt = 0;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
if (!d->list)
|
|
|
|
d->list = ecore_file_ls(p->directory);
|
2009-08-12 05:17:43 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
EINA_LIST_FREE(d->list, filename)
|
2009-07-10 08:47:19 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
if (filename[0] == '.')
|
2009-08-12 05:17:43 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
free(filename);
|
2009-08-12 05:17:43 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
file = E_NEW(Evry_Item_File, 1);
|
2009-08-27 15:58:34 -07:00
|
|
|
if (!file)
|
|
|
|
{
|
|
|
|
free(filename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), NULL, _item_free);
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
EVRY_ITEM(file)->label = filename;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
snprintf(buf, sizeof(buf), "%s/%s", p->directory, filename);
|
2010-04-07 08:03:27 -07:00
|
|
|
file->path = strdup(buf);
|
2009-08-27 15:58:34 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
if (ecore_file_is_dir(file->path))
|
|
|
|
{
|
|
|
|
file->mime = "inode/directory";
|
|
|
|
EVRY_ITEM(file)->browseable = EINA_TRUE;
|
|
|
|
}
|
|
|
|
else if ((mime = efreet_mime_type_get(file->path)))
|
|
|
|
{
|
|
|
|
file->mime = mime;
|
|
|
|
}
|
|
|
|
|
2009-08-27 15:58:34 -07:00
|
|
|
d->files = eina_list_append(d->files, file);
|
2010-04-16 07:15:30 -07:00
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
if (cnt > MAX_ITEMS)
|
2010-04-16 07:15:30 -07:00
|
|
|
break;
|
2009-08-27 15:58:34 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
_append_file(Plugin *p, Evry_Item_File *file)
|
|
|
|
{
|
|
|
|
int match;
|
|
|
|
|
|
|
|
if (p->input && (match = evry_fuzzy_match(EVRY_ITEM(file)->label, p->input)))
|
|
|
|
{
|
|
|
|
EVRY_ITEM(file)->fuzzy_match = match;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else if (!p->input)
|
|
|
|
{
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, file);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-04-08 15:37:50 -07:00
|
|
|
_scan_cancel_func(void *data)
|
2009-08-27 15:58:34 -07:00
|
|
|
{
|
|
|
|
Data *d = data;
|
|
|
|
Plugin *p = d->plugin;
|
2010-04-08 15:37:50 -07:00
|
|
|
Evry_Item_File *file;
|
2010-04-16 07:15:30 -07:00
|
|
|
char *filename;
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
EINA_LIST_FREE(d->files, file)
|
2009-08-27 15:58:34 -07:00
|
|
|
{
|
2010-04-16 07:15:30 -07:00
|
|
|
free((char *)EVRY_ITEM(file)->label);
|
|
|
|
free((char *)file->path);
|
|
|
|
free(file);
|
2009-08-27 15:58:34 -07:00
|
|
|
}
|
2010-04-16 07:15:30 -07:00
|
|
|
|
|
|
|
EINA_LIST_FREE(d->list, filename)
|
|
|
|
free(filename);
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
E_FREE(d);
|
|
|
|
|
|
|
|
if (p->directory)
|
|
|
|
eina_stringshare_del(p->directory);
|
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
p->thread = NULL;
|
|
|
|
|
|
|
|
if (p->cleanup)
|
|
|
|
_cleanup(EVRY_PLUGIN(p));
|
2010-04-08 15:37:50 -07:00
|
|
|
}
|
2009-08-12 05:17:43 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
static void
|
|
|
|
_scan_end_func(void *data)
|
|
|
|
{
|
|
|
|
Data *d = data;
|
|
|
|
Plugin *p = d->plugin;
|
|
|
|
Evry_Item *item;
|
2010-04-16 07:15:30 -07:00
|
|
|
Evry_Item_File *f;
|
|
|
|
char *filename, *path, *mime;
|
|
|
|
int cnt = eina_list_count(p->base.items);
|
|
|
|
Eina_List *l;
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
p->thread = NULL;
|
2010-04-16 07:15:30 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
|
2009-08-27 15:58:34 -07:00
|
|
|
EINA_LIST_FREE(d->files, item)
|
|
|
|
{
|
|
|
|
ITEM_FILE(file, item);
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
filename = (char *)item->label;
|
2010-04-07 08:03:27 -07:00
|
|
|
path = (char *) file->path;
|
2010-04-16 07:15:30 -07:00
|
|
|
mime = (char *) file->mime;
|
|
|
|
|
2010-04-07 08:03:27 -07:00
|
|
|
file->path = eina_stringshare_add(path);
|
2010-04-16 07:15:30 -07:00
|
|
|
|
|
|
|
/* filter out files that we already have from history */
|
|
|
|
EINA_LIST_FOREACH(p->files, l, f)
|
|
|
|
{
|
|
|
|
if (f->path == file->path)
|
|
|
|
{
|
|
|
|
free(filename);
|
|
|
|
free(path);
|
|
|
|
E_FREE(file);
|
|
|
|
file = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!file) continue;
|
|
|
|
|
|
|
|
if (mime)
|
|
|
|
file->mime = eina_stringshare_add(mime);
|
|
|
|
else
|
|
|
|
file->mime = eina_stringshare_add("None");
|
|
|
|
item->context = eina_stringshare_ref(file->mime);
|
|
|
|
item->id = eina_stringshare_ref(file->path);
|
2009-08-27 15:58:34 -07:00
|
|
|
item->label = eina_stringshare_add(filename);
|
2010-04-16 07:15:30 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
free(filename);
|
2010-04-07 08:03:27 -07:00
|
|
|
free(path);
|
2009-08-27 15:58:34 -07:00
|
|
|
|
|
|
|
p->files = eina_list_append(p->files, file);
|
|
|
|
|
2010-04-14 03:49:28 -07:00
|
|
|
evry_util_file_detail_set(file);
|
2009-09-03 07:21:27 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
if (cnt >= MAX_ITEMS) continue;
|
2009-08-27 15:58:34 -07:00
|
|
|
cnt += _append_file(p, file);
|
2010-04-19 00:26:56 -07:00
|
|
|
item->priority = cnt;
|
2009-08-27 15:58:34 -07:00
|
|
|
}
|
2010-04-16 07:15:30 -07:00
|
|
|
if (d->files)
|
|
|
|
p->thread = ecore_thread_run(_scan_func, _scan_end_func, _scan_cancel_func, d);
|
|
|
|
else
|
|
|
|
E_FREE(d);
|
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
2010-04-19 00:26:56 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD);
|
2009-08-27 15:58:34 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_read_directory(Plugin *p)
|
|
|
|
{
|
|
|
|
Data *d = E_NEW(Data, 1);
|
|
|
|
d->plugin = p;
|
2010-04-10 13:05:57 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
p->thread = ecore_thread_run(_scan_func, _scan_end_func, _scan_cancel_func, d);
|
2009-08-12 12:14:45 -07:00
|
|
|
}
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
static Evry_Plugin *
|
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *it)
|
2009-08-12 12:14:45 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
Plugin *p = NULL;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
/* is FILE ? */
|
|
|
|
if (it && (it->plugin->type_out == plugin->type_in))
|
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_FILE(file, it);
|
|
|
|
|
2010-04-07 08:03:27 -07:00
|
|
|
if (!file->path || !ecore_file_is_dir(file->path))
|
2009-08-21 15:42:06 -07:00
|
|
|
return NULL;
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
p = E_NEW(Plugin, 1);
|
|
|
|
p->base = *plugin;
|
2009-08-22 14:22:38 -07:00
|
|
|
p->base.items = NULL;
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2010-04-07 08:03:27 -07:00
|
|
|
p->directory = eina_stringshare_add(file->path);
|
2010-04-15 06:58:44 -07:00
|
|
|
p->parent = EINA_TRUE;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
2009-08-22 20:12:05 -07:00
|
|
|
else
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
|
|
|
p = E_NEW(Plugin, 1);
|
|
|
|
p->base = *plugin;
|
2009-08-22 14:22:38 -07:00
|
|
|
p->base.items = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
p->directory = eina_stringshare_add(e_user_homedir_get());
|
2010-04-15 06:58:44 -07:00
|
|
|
p->parent = EINA_FALSE;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
_read_directory(p);
|
2009-08-12 13:26:27 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
return EVRY_PLUGIN(p);
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2010-04-17 21:41:08 -07:00
|
|
|
static int
|
|
|
|
_hist_add(Evry_Plugin *plugin, Evry_Item_File *file)
|
|
|
|
{
|
|
|
|
Eina_List *l;
|
|
|
|
History_Item *hi;
|
|
|
|
History_Entry *he;
|
|
|
|
|
|
|
|
he = eina_hash_find(evry_hist->subjects, file->path);
|
|
|
|
|
|
|
|
if (!he) return 0;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(he->items, l, hi)
|
|
|
|
{
|
|
|
|
if (hi->type != plugin->type_out)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (hi->data)
|
|
|
|
eina_stringshare_del(hi->data);
|
|
|
|
|
|
|
|
hi->data = eina_stringshare_ref(file->mime);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
static void
|
2009-08-21 15:42:06 -07:00
|
|
|
_cleanup(Evry_Plugin *plugin)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
|
|
|
|
|
|
|
Evry_Item_File *file;
|
2010-04-15 06:58:44 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
if (p->thread)
|
2010-04-10 13:05:57 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
ecore_thread_cancel(p->thread);
|
2010-04-15 06:58:44 -07:00
|
|
|
p->cleanup = EINA_TRUE;
|
2010-04-08 15:37:50 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (p->directory)
|
|
|
|
eina_stringshare_del(p->directory);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
EINA_LIST_FREE(p->files, file)
|
2010-04-17 21:41:08 -07:00
|
|
|
{
|
|
|
|
_hist_add(plugin, file);
|
|
|
|
evry_item_free(EVRY_ITEM(file));
|
|
|
|
}
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
if (p->input)
|
|
|
|
eina_stringshare_del(p->input);
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
E_FREE(p);
|
|
|
|
}
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_hist_items_add_cb(const Eina_Hash *hash, const void *key, void *data, void *fdata)
|
2009-08-27 15:58:34 -07:00
|
|
|
{
|
2010-04-16 07:15:30 -07:00
|
|
|
History_Entry *he = data;
|
|
|
|
History_Item *hi;
|
|
|
|
Plugin *p = fdata;
|
2010-04-16 11:36:28 -07:00
|
|
|
Eina_List *l, *ll;
|
2010-04-16 07:15:30 -07:00
|
|
|
Evry_Item_File *file;
|
|
|
|
const char *label;
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(he->items, l, hi)
|
|
|
|
{
|
2010-04-16 18:10:20 -07:00
|
|
|
if (hi->type != p->base.type_out)
|
2010-04-16 07:15:30 -07:00
|
|
|
continue;
|
|
|
|
|
2010-04-16 11:36:28 -07:00
|
|
|
/* filter out files that we already have from history */
|
|
|
|
EINA_LIST_FOREACH(p->files, ll, file)
|
2010-04-16 18:10:20 -07:00
|
|
|
if (!strcmp(file->path, key))
|
2010-04-16 11:36:28 -07:00
|
|
|
return EINA_TRUE;
|
2010-04-17 05:40:28 -07:00
|
|
|
|
|
|
|
/* XXX this blocks ui when drive is sleeping */
|
|
|
|
/* if (!ecore_file_exists(key))
|
|
|
|
* continue; */
|
2009-08-27 15:58:34 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
label = ecore_file_file_get(key);
|
|
|
|
if (!label)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
file = E_NEW(Evry_Item_File, 1);
|
|
|
|
if (!file)
|
|
|
|
continue;
|
2009-08-27 15:58:34 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), label, _item_free);
|
|
|
|
|
|
|
|
file->path = eina_stringshare_add(key);
|
2010-04-17 17:17:15 -07:00
|
|
|
if (hi->data)
|
|
|
|
file->mime = eina_stringshare_add(hi->data);
|
|
|
|
if (hi->data)
|
2010-04-16 07:15:30 -07:00
|
|
|
EVRY_ITEM(file)->context = eina_stringshare_ref(file->mime);
|
|
|
|
|
|
|
|
EVRY_ITEM(file)->id = eina_stringshare_ref(file->path);
|
|
|
|
|
|
|
|
evry_util_file_detail_set(file);
|
2010-04-16 11:36:28 -07:00
|
|
|
|
2010-04-17 21:41:08 -07:00
|
|
|
if (file->mime)
|
|
|
|
{
|
|
|
|
if ((!strcmp(file->mime, "inode/directory")) ||
|
|
|
|
(!strcmp(file->mime, "inode/mount-point")))
|
|
|
|
EVRY_ITEM(file)->browseable = EINA_TRUE;
|
|
|
|
}
|
|
|
|
/* else */
|
2010-04-17 17:17:15 -07:00
|
|
|
/* if (ecore_file_is_dir(file->path))
|
|
|
|
* EVRY_ITEM(file)->browseable = EINA_TRUE; */
|
2010-04-16 11:36:28 -07:00
|
|
|
|
2010-04-16 07:15:30 -07:00
|
|
|
p->files = eina_list_append(p->files, file);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return EINA_TRUE;
|
2009-08-27 15:58:34 -07:00
|
|
|
}
|
|
|
|
|
2009-06-21 03:31:38 -07:00
|
|
|
static int
|
2009-08-21 15:42:06 -07:00
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
|
|
|
Evry_Item_File *file;
|
2009-08-10 04:36:37 -07:00
|
|
|
Eina_List *l;
|
|
|
|
int cnt = 0;
|
2009-08-12 12:00:25 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
if (!p->command)
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_CLEAR(p);
|
2009-08-12 05:17:43 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
if (p->input)
|
|
|
|
eina_stringshare_del(p->input);
|
|
|
|
p->input = NULL;
|
2009-08-27 15:58:34 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
if (!p->parent && input)
|
2009-07-10 07:08:06 -07:00
|
|
|
{
|
2010-04-16 07:15:30 -07:00
|
|
|
/* input is command ? */
|
2010-04-15 06:58:44 -07:00
|
|
|
if (!strcmp(input, "/"))
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-16 07:15:30 -07:00
|
|
|
/* browse root */
|
2010-04-15 06:58:44 -07:00
|
|
|
EINA_LIST_FREE(p->files, file)
|
|
|
|
evry_item_free(EVRY_ITEM(file));
|
|
|
|
|
|
|
|
eina_stringshare_del(p->directory);
|
|
|
|
p->directory = eina_stringshare_add("/");
|
|
|
|
_read_directory(p);
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2009-08-27 15:58:34 -07:00
|
|
|
p->command = EINA_TRUE;
|
2010-04-15 06:58:44 -07:00
|
|
|
return 0;
|
|
|
|
}
|
2010-04-16 11:36:28 -07:00
|
|
|
|
|
|
|
/* add recent files */
|
|
|
|
if (!p->hist_added)
|
|
|
|
eina_hash_foreach(evry_hist->subjects, _hist_items_add_cb, p);
|
|
|
|
p->hist_added = EINA_TRUE;
|
2010-04-15 06:58:44 -07:00
|
|
|
}
|
2009-08-22 20:12:05 -07:00
|
|
|
|
2010-04-16 11:36:28 -07:00
|
|
|
/* clear command items */
|
2010-04-15 06:58:44 -07:00
|
|
|
if (!p->parent && !input && p->command)
|
|
|
|
{
|
|
|
|
p->command = EINA_FALSE;
|
2010-04-16 11:36:28 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
EINA_LIST_FREE(p->files, file)
|
|
|
|
evry_item_free(EVRY_ITEM(file));
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
eina_stringshare_del(p->directory);
|
|
|
|
p->directory = eina_stringshare_add(e_user_homedir_get());
|
|
|
|
_read_directory(p);
|
|
|
|
return 0;
|
2009-07-10 07:08:06 -07:00
|
|
|
}
|
2009-08-11 06:31:38 -07:00
|
|
|
|
2010-04-15 06:58:44 -07:00
|
|
|
if (input)
|
2009-08-11 06:31:38 -07:00
|
|
|
{
|
2010-04-16 11:36:28 -07:00
|
|
|
/* skip command prefix */
|
2010-04-15 06:58:44 -07:00
|
|
|
if (p->command)
|
|
|
|
p->input = eina_stringshare_add(input + 1);
|
|
|
|
else
|
|
|
|
p->input = eina_stringshare_add(input);
|
2009-08-11 06:31:38 -07:00
|
|
|
}
|
2010-04-19 00:26:56 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
EINA_LIST_FOREACH(p->files, l, file)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2010-04-19 00:26:56 -07:00
|
|
|
if (cnt <= MAX_ITEMS)
|
|
|
|
{
|
|
|
|
cnt += _append_file(p, file);
|
|
|
|
EVRY_ITEM(file)->priority = cnt;
|
|
|
|
}
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
2009-06-21 16:25:39 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
if (!EVRY_PLUGIN(p)->items)
|
|
|
|
return 0;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
2009-08-28 21:42:17 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
return 1;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-08-10 04:36:37 -07:00
|
|
|
static Evas_Object *
|
2009-08-17 20:15:36 -07:00
|
|
|
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2009-08-12 12:00:25 -07:00
|
|
|
Evas_Object *o = NULL;
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_FILE(file, it);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
if (!file->mime)
|
|
|
|
_item_fill(file);
|
2009-08-10 04:36:37 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
if (!file->mime) return NULL;
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
if (it->browseable)
|
2009-08-18 07:29:30 -07:00
|
|
|
o = evry_icon_theme_get("folder", e);
|
2009-06-21 03:31:38 -07:00
|
|
|
else
|
2009-08-22 20:12:05 -07:00
|
|
|
o = evry_icon_mime_get(file->mime, e);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2009-08-12 12:00:25 -07:00
|
|
|
return o;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
|
|
|
|
2009-08-15 21:08:35 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
_open_folder_check(Evry_Action *act __UNUSED__, const Evry_Item *it)
|
|
|
|
{
|
2009-08-16 09:26:49 -07:00
|
|
|
return (it->browseable && e_action_find("fileman"));
|
2009-08-15 21:08:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_open_folder_action(Evry_Action *act)
|
2009-08-15 21:47:43 -07:00
|
|
|
{
|
2009-08-15 21:08:35 -07:00
|
|
|
E_Action *action = e_action_find("fileman");
|
2009-08-15 21:47:43 -07:00
|
|
|
char *path;
|
2009-08-15 21:08:35 -07:00
|
|
|
Eina_List *m;
|
2009-08-15 21:47:43 -07:00
|
|
|
|
2009-08-15 21:08:35 -07:00
|
|
|
if (!action) return 0;
|
|
|
|
|
|
|
|
m = e_manager_list();
|
2009-08-15 21:47:43 -07:00
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
ITEM_FILE(file, act->item1);
|
|
|
|
|
2009-08-21 18:15:21 -07:00
|
|
|
if (!act->item1->browseable)
|
2009-08-15 21:47:43 -07:00
|
|
|
{
|
2010-04-07 08:03:27 -07:00
|
|
|
path = ecore_file_dir_get(file->path);
|
2009-08-15 21:47:43 -07:00
|
|
|
if (!path) return 0;
|
|
|
|
action->func.go(E_OBJECT(m->data), path);
|
|
|
|
free(path);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-07 08:03:27 -07:00
|
|
|
action->func.go(E_OBJECT(m->data), file->path);
|
2009-08-15 21:47:43 -07:00
|
|
|
}
|
2009-08-15 21:08:35 -07:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
static int
|
|
|
|
_open_term_action(Evry_Action *act)
|
|
|
|
{
|
|
|
|
ITEM_FILE(file, act->item1);
|
|
|
|
Evry_Item_App *tmp;
|
2009-09-17 23:33:33 -07:00
|
|
|
char cwd[4096];
|
|
|
|
char *dir;
|
2009-08-27 19:25:13 -07:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (act->item1->browseable)
|
2010-04-07 08:03:27 -07:00
|
|
|
dir = strdup(file->path);
|
2009-08-27 19:25:13 -07:00
|
|
|
else
|
2010-04-07 08:03:27 -07:00
|
|
|
dir = ecore_file_dir_get(file->path);
|
2009-08-27 19:25:13 -07:00
|
|
|
|
2009-09-17 23:33:33 -07:00
|
|
|
if (dir)
|
2009-08-27 19:25:13 -07:00
|
|
|
{
|
2009-09-17 23:33:33 -07:00
|
|
|
getcwd(cwd, sizeof(cwd));
|
|
|
|
chdir(dir);
|
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
tmp = E_NEW(Evry_Item_App, 1);
|
2009-09-17 23:33:33 -07:00
|
|
|
tmp->file = evry_conf->cmd_terminal;
|
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
ret = evry_util_exec_app(EVRY_ITEM(tmp), NULL);
|
|
|
|
E_FREE(tmp);
|
2009-09-17 23:33:33 -07:00
|
|
|
E_FREE(dir);
|
|
|
|
chdir(cwd);
|
2009-08-27 19:25:13 -07:00
|
|
|
}
|
2009-09-17 23:33:33 -07:00
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
static Eina_Bool
|
2010-04-10 13:05:57 -07:00
|
|
|
module_init(void)
|
2009-06-21 03:31:38 -07:00
|
|
|
{
|
2010-04-08 04:55:15 -07:00
|
|
|
if (!evry_api_version_check(EVRY_API_VERSION))
|
|
|
|
return EINA_FALSE;
|
|
|
|
|
2010-04-19 09:09:35 -07:00
|
|
|
p1 = EVRY_PLUGIN_NEW(NULL, N_("Files"), type_subject, "FILE", "FILE",
|
2010-04-15 14:42:30 -07:00
|
|
|
_begin, _cleanup, _fetch, _icon_get, NULL);
|
2009-07-04 04:10:28 -07:00
|
|
|
|
2010-04-19 09:09:35 -07:00
|
|
|
p2 = EVRY_PLUGIN_NEW(NULL, N_("Files"), type_object, "FILE", "FILE",
|
2010-04-15 14:42:30 -07:00
|
|
|
_begin, _cleanup, _fetch, _icon_get, NULL);
|
2009-08-30 01:51:15 -07:00
|
|
|
|
2009-08-17 20:15:36 -07:00
|
|
|
evry_plugin_register(p1, 3);
|
2009-08-16 09:26:49 -07:00
|
|
|
evry_plugin_register(p2, 1);
|
2009-06-21 03:31:38 -07:00
|
|
|
|
2010-04-19 09:09:35 -07:00
|
|
|
act1 = EVRY_ACTION_NEW(N_("Open Folder (EFM)"), "FILE", NULL, "folder-open",
|
2010-04-15 14:42:30 -07:00
|
|
|
_open_folder_action, _open_folder_check);
|
2009-08-27 19:25:13 -07:00
|
|
|
evry_action_register(act1, 0);
|
|
|
|
|
2010-04-19 09:09:35 -07:00
|
|
|
act2 = EVRY_ACTION_NEW(N_("Open Terminal here"), "FILE", NULL, "system-run",
|
2010-04-15 14:42:30 -07:00
|
|
|
_open_term_action, NULL);
|
2009-08-27 19:25:13 -07:00
|
|
|
evry_action_register(act2, 2);
|
2009-08-27 15:58:34 -07:00
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
return EINA_TRUE;
|
2009-06-21 03:31:38 -07:00
|
|
|
}
|
2009-08-10 04:36:37 -07:00
|
|
|
|
2009-08-11 06:31:38 -07:00
|
|
|
static void
|
2010-04-10 13:05:57 -07:00
|
|
|
module_shutdown(void)
|
2009-08-10 04:36:37 -07:00
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_FREE(p1);
|
|
|
|
EVRY_PLUGIN_FREE(p2);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
evry_action_free(act1);
|
|
|
|
evry_action_free(act2);
|
2009-08-10 04:36:37 -07:00
|
|
|
}
|
2009-08-11 06:31:38 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
|
|
|
|
/***************************************************************************/
|
2010-04-16 11:36:28 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
EAPI E_Module_Api e_modapi =
|
|
|
|
{
|
|
|
|
E_MODULE_API_VERSION,
|
|
|
|
"everything-files"
|
|
|
|
};
|
|
|
|
|
|
|
|
EAPI void *
|
|
|
|
e_modapi_init(E_Module *m)
|
|
|
|
{
|
|
|
|
module = m;
|
|
|
|
|
|
|
|
if (e_datastore_get("everything_loaded"))
|
|
|
|
active = module_init();
|
2010-04-10 14:38:36 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
e_module_delayed_set(m, 1);
|
2010-04-10 14:38:36 -07:00
|
|
|
|
2010-04-10 13:05:57 -07:00
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_shutdown(E_Module *m)
|
|
|
|
{
|
|
|
|
if (active && e_datastore_get("everything_loaded"))
|
|
|
|
module_shutdown();
|
|
|
|
|
|
|
|
module = NULL;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI int
|
|
|
|
e_modapi_save(E_Module *m)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|