2009-08-21 15:42:06 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
2010-04-16 18:10:20 -07:00
|
|
|
#define MAX_ITEMS 50
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
typedef struct _Plugin Plugin;
|
|
|
|
|
|
|
|
struct _Plugin
|
|
|
|
{
|
|
|
|
Evry_Plugin base;
|
|
|
|
Evry_Selector *selector;
|
2010-05-03 12:51:46 -07:00
|
|
|
|
|
|
|
Evry_Item *warning;
|
2009-08-21 15:42:06 -07:00
|
|
|
};
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
static inline Eina_List *
|
|
|
|
_add_item(Plugin *p, Eina_List *items, Evry_Item *it)
|
2010-04-27 20:22:40 -07:00
|
|
|
{
|
2010-04-25 05:21:41 -07:00
|
|
|
/* remove duplicates provided by different plugins */
|
2010-04-25 09:26:13 -07:00
|
|
|
if (it->id)
|
2010-04-25 05:21:41 -07:00
|
|
|
{
|
2010-04-25 09:26:13 -07:00
|
|
|
Eina_List *_l;
|
|
|
|
Evry_Item *_it;
|
2010-04-25 05:21:41 -07:00
|
|
|
|
2010-04-25 09:26:13 -07:00
|
|
|
EINA_LIST_FOREACH(p->base.items, _l, _it)
|
|
|
|
{
|
|
|
|
if ((it->plugin->name != _it->plugin->name) &&
|
2010-04-27 20:22:40 -07:00
|
|
|
(it->type == _it->type) &&
|
2010-04-25 09:26:13 -07:00
|
|
|
(it->id == _it->id))
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
}
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
items = eina_list_append(items, it);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
static int
|
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
|
|
|
{
|
|
|
|
Plugin *p = (Plugin *) plugin;
|
|
|
|
Evry_Plugin *pp;
|
|
|
|
Evry_State *s;
|
2010-04-26 11:21:09 -07:00
|
|
|
Eina_List *l, *ll, *lp = NULL;
|
|
|
|
Evry_Item *it;
|
2009-09-03 07:21:27 -07:00
|
|
|
int i, cnt = 0;
|
2009-08-21 15:42:06 -07:00
|
|
|
Eina_List *items = NULL;
|
2009-09-03 07:21:27 -07:00
|
|
|
const char *context = NULL;
|
2010-05-06 06:09:14 -07:00
|
|
|
char buf[128];
|
|
|
|
Evry_Selector *sel = p->selector;
|
|
|
|
|
2010-04-23 19:11:14 -07:00
|
|
|
if (input && !input[0]) input = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-23 19:11:14 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
s = sel->state;
|
2010-05-03 16:08:24 -07:00
|
|
|
if (!s) return 0;
|
|
|
|
|
|
|
|
if (!s->cur_plugins)
|
2010-05-03 12:51:46 -07:00
|
|
|
{
|
2010-05-03 13:01:55 -07:00
|
|
|
/* 'text' and 'actions' are always loaded */
|
2010-05-06 06:09:14 -07:00
|
|
|
if ((sel == selectors[0]) &&
|
2010-05-03 13:01:55 -07:00
|
|
|
(eina_list_count(s->plugins) == 2))
|
|
|
|
{
|
|
|
|
evry_item_ref(p->warning);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, p->warning);
|
|
|
|
}
|
2010-05-03 12:51:46 -07:00
|
|
|
return 1;
|
|
|
|
}
|
2009-10-01 15:31:45 -07:00
|
|
|
|
2010-05-03 16:08:24 -07:00
|
|
|
/* get current items' context ... */
|
2009-09-03 07:21:27 -07:00
|
|
|
for (i = 1; i < 3; i++)
|
|
|
|
{
|
2010-05-06 06:09:14 -07:00
|
|
|
if (sel == selectors[i])
|
2009-09-03 07:21:27 -07:00
|
|
|
{
|
2010-04-24 05:10:19 -07:00
|
|
|
it = selectors[i-1]->state->cur_item;
|
|
|
|
if (it) context = it->context;
|
2010-04-23 17:54:12 -07:00
|
|
|
}
|
2009-09-03 07:21:27 -07:00
|
|
|
}
|
2009-10-01 15:31:45 -07:00
|
|
|
|
2010-04-24 16:05:36 -07:00
|
|
|
/* filter all to be shown in aggregator */
|
|
|
|
EINA_LIST_FOREACH(s->cur_plugins, l, pp)
|
|
|
|
{
|
2010-05-06 06:09:14 -07:00
|
|
|
if (!pp->config->aggregate || pp == plugin)
|
|
|
|
continue;
|
|
|
|
if (!sel->states->next && !pp->config->top_level)
|
|
|
|
continue;
|
2010-04-24 16:05:36 -07:00
|
|
|
lp = eina_list_append(lp, pp);
|
|
|
|
}
|
2010-04-23 18:26:10 -07:00
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
/* show non-top-level plugins as item */
|
|
|
|
if (!s->trigger_active && !sel->states->next)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(s->plugins, l, pp)
|
|
|
|
{
|
|
|
|
GET_ITEM(it, pp);
|
|
|
|
|
|
|
|
if (pp->config->top_level || pp == plugin)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!pp->items)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
|
|
|
it->hi = NULL;
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_history_item_usage_set(it, NULL, NULL);
|
2010-05-06 06:09:14 -07:00
|
|
|
|
|
|
|
snprintf(buf, sizeof(buf), "%d %s", eina_list_count(pp->items), _("Items"));
|
|
|
|
if (it->detail)
|
|
|
|
eina_stringshare_del(it->detail);
|
|
|
|
it->detail = eina_stringshare_add(buf);
|
|
|
|
|
|
|
|
items = _add_item(p, items, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!lp && !items) return 0;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-24 05:10:19 -07:00
|
|
|
/* if there is only one plugin append all items */
|
2010-05-06 06:09:14 -07:00
|
|
|
if (lp && !lp->next)
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
|
|
|
pp = lp->data;
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-04-24 16:05:36 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
2010-05-01 17:58:33 -07:00
|
|
|
if (it->usage >= 0)
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_history_item_usage_set(it, input, context);
|
2010-05-06 06:09:14 -07:00
|
|
|
if (it->fuzzy_match == 0)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
2010-04-24 16:05:36 -07:00
|
|
|
items = _add_item(p, items, it);
|
2010-04-23 18:26:10 -07:00
|
|
|
}
|
|
|
|
}
|
2010-04-24 05:10:19 -07:00
|
|
|
/* if there is input append all items that match or have
|
|
|
|
fuzzy_match set to -1 */
|
2010-04-23 18:26:10 -07:00
|
|
|
else if (input)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-23 19:11:14 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
2010-04-22 11:12:17 -07:00
|
|
|
if (it->fuzzy_match == 0)
|
2009-08-21 15:42:06 -07:00
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
if (it->fuzzy_match || sel == selectors[2])
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
2010-05-01 17:58:33 -07:00
|
|
|
if (it->usage >= 0)
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_history_item_usage_set(it, input, context);
|
2010-05-01 17:58:33 -07:00
|
|
|
|
|
|
|
items = _add_item(p, items, it);
|
2010-04-23 18:26:10 -07:00
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 05:10:19 -07:00
|
|
|
/* always append items of action or object selector */
|
2010-04-23 18:26:10 -07:00
|
|
|
else if ((!input) &&
|
2010-05-06 06:09:14 -07:00
|
|
|
((sel == selectors[1]) ||
|
|
|
|
(sel == selectors[2])))
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-23 17:51:08 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-14 13:21:56 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-05-01 17:58:33 -07:00
|
|
|
if (it->usage >= 0)
|
2010-05-11 10:24:38 -07:00
|
|
|
evry_history_item_usage_set(it, NULL, context);
|
2010-04-24 16:05:36 -07:00
|
|
|
it->fuzzy_match = 0;
|
|
|
|
items = _add_item(p, items, it);
|
2009-08-30 04:07:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 05:10:19 -07:00
|
|
|
/* no input: append all items that are in history */
|
2010-04-23 18:26:10 -07:00
|
|
|
else
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2010-04-23 18:26:10 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
2010-05-01 17:58:33 -07:00
|
|
|
if ((it->usage >= 0) &&
|
2010-05-11 10:24:38 -07:00
|
|
|
(evry_history_item_usage_set(it, input, context)) &&
|
2010-05-01 17:58:33 -07:00
|
|
|
(!eina_list_data_find_list(items, it)))
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
2010-05-03 12:19:42 -07:00
|
|
|
it->fuzzy_match = 0;
|
|
|
|
items = _add_item(p, items, it);
|
2010-04-23 18:26:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-30 01:51:15 -07:00
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
if (lp && lp->next && eina_list_count(items) < MAX_ITEMS)
|
2010-04-24 16:05:36 -07:00
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
|
|
|
if (!eina_list_data_find_list(items, it))
|
2010-05-02 15:20:19 -07:00
|
|
|
{
|
|
|
|
it->usage = 0;
|
2010-05-06 06:09:14 -07:00
|
|
|
if (it->fuzzy_match == 0)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
2010-05-02 15:20:19 -07:00
|
|
|
items = _add_item(p, items, it);
|
|
|
|
}
|
2010-04-24 16:05:36 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
/* EINA_LIST_FOREACH(items, l, it)
|
2010-05-11 19:01:09 -07:00
|
|
|
* {
|
|
|
|
* if(CHECK_TYPE(it, EVRY_TYPE_FILE))
|
|
|
|
* printf("%d %1.20f %s\n", it->fuzzy_match, it->usage, it->label);
|
|
|
|
* } */
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
if (items) eina_list_free(items);
|
2010-05-06 06:09:14 -07:00
|
|
|
if (lp) eina_list_free(lp);
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, evry_items_sort_func);
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2010-04-14 13:21:56 -07:00
|
|
|
EINA_LIST_FOREACH_SAFE(p->base.items, l, ll, it)
|
|
|
|
{
|
2010-05-11 19:01:09 -07:00
|
|
|
if (cnt++ < MAX_ITEMS)
|
|
|
|
{
|
|
|
|
evry_item_ref(it);
|
|
|
|
continue;
|
|
|
|
}
|
2010-04-14 13:21:56 -07:00
|
|
|
p->base.items = eina_list_remove_list(p->base.items, l);
|
|
|
|
}
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-06 06:09:14 -07:00
|
|
|
_finish(Evry_Plugin *p)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-05-06 06:09:14 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2010-04-29 09:34:11 -07:00
|
|
|
static void
|
|
|
|
_free(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
GET_PLUGIN(p, plugin);
|
2010-05-02 11:14:21 -07:00
|
|
|
|
2010-04-29 09:34:11 -07:00
|
|
|
_finish(plugin);
|
|
|
|
|
2010-05-03 12:51:46 -07:00
|
|
|
evry_item_free(p->warning);
|
|
|
|
|
2010-04-29 09:34:11 -07:00
|
|
|
free(p);
|
|
|
|
}
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
Evry_Plugin *
|
2010-04-23 17:21:45 -07:00
|
|
|
evry_plug_aggregator_new(Evry_Selector *sel, int type)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-24 17:31:11 -07:00
|
|
|
Evry_Plugin *p;
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-04-29 09:34:11 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("All"), NULL, 0, NULL, _finish, _fetch, _free);
|
2010-04-24 17:31:11 -07:00
|
|
|
p->history = EINA_FALSE;
|
2010-05-12 21:13:38 -07:00
|
|
|
if (evry_plugin_register(p, type, -1))
|
|
|
|
{
|
|
|
|
p->config->view_mode = VIEW_MODE_THUMB;
|
|
|
|
}
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
GET_PLUGIN(pa, p);
|
2010-04-24 17:31:11 -07:00
|
|
|
pa->selector = sel;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-05-03 12:51:46 -07:00
|
|
|
pa->warning = evry_item_new(NULL, p, N_("No plugins loaded"), NULL, NULL);
|
|
|
|
pa->warning->type = EVRY_TYPE_NONE;
|
|
|
|
|
2010-04-24 17:31:11 -07:00
|
|
|
return p;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|