2009-08-21 15:42:06 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
//TODO min input for items not in history
|
|
|
|
|
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;
|
2010-05-15 19:37:07 -07:00
|
|
|
|
2010-05-03 12:51:46 -07:00
|
|
|
Evry_Item *warning;
|
2009-08-21 15:42:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static int
|
|
|
|
_fetch(Evry_Plugin *plugin, const char *input)
|
|
|
|
{
|
|
|
|
Plugin *p = (Plugin *) plugin;
|
2010-10-28 16:07:59 -07:00
|
|
|
Evry_Plugin *pp;
|
2010-04-26 11:21:09 -07:00
|
|
|
Eina_List *l, *ll, *lp = NULL;
|
2010-05-13 15:27:57 -07:00
|
|
|
Evry_Item *it, *it2;
|
2011-08-21 08:41:37 -07:00
|
|
|
int top_level = 0, subj_sel = 0, inp_len = 0, 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];
|
2011-08-21 08:41:37 -07:00
|
|
|
Evry_State *s = plugin->state;
|
|
|
|
Evry_Selector *sel = s->selector;
|
|
|
|
Evry_Selector **sels = sel->win->selectors;
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
if (input && input[0])
|
|
|
|
inp_len = strlen(input);
|
|
|
|
else
|
|
|
|
input = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
if (!sel->states->next)
|
|
|
|
top_level = 1;
|
2009-10-01 15:31:45 -07:00
|
|
|
|
2011-08-21 08:41:37 -07:00
|
|
|
/* get current items' context */
|
|
|
|
if (sel == sels[0])
|
|
|
|
{
|
|
|
|
subj_sel = 1;
|
|
|
|
}
|
|
|
|
else if (sel == sels[1])
|
2009-09-03 07:21:27 -07:00
|
|
|
{
|
2011-08-21 08:41:37 -07:00
|
|
|
it = sels[0]->state->cur_item;
|
|
|
|
if (it) context = it->context;
|
|
|
|
}
|
|
|
|
else if (sel == sels[2])
|
|
|
|
{
|
|
|
|
it = sels[1]->state->cur_item;
|
|
|
|
if (it) context = it->context;
|
2009-09-03 07:21:27 -07:00
|
|
|
}
|
2009-10-01 15:31:45 -07:00
|
|
|
|
2011-08-21 08:41:37 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
/* collect plugins to be shown in aggregator */
|
2010-04-24 16:05:36 -07:00
|
|
|
EINA_LIST_FOREACH(s->cur_plugins, l, pp)
|
|
|
|
{
|
2011-02-20 23:49:21 -08:00
|
|
|
/* dont show in aggregator */
|
2010-05-30 12:16:33 -07:00
|
|
|
if (!pp->config->aggregate)
|
|
|
|
continue;
|
2011-02-20 23:49:21 -08:00
|
|
|
/* do not recurse */
|
2010-05-30 12:16:33 -07:00
|
|
|
if (pp == plugin)
|
2010-05-06 06:09:14 -07:00
|
|
|
continue;
|
2011-02-20 23:49:21 -08:00
|
|
|
/* dont show plugin in top-level */
|
2010-05-30 12:16:33 -07:00
|
|
|
if (top_level && !pp->config->top_level)
|
2010-05-06 06:09:14 -07:00
|
|
|
continue;
|
2010-04-24 16:05:36 -07:00
|
|
|
lp = eina_list_append(lp, pp);
|
|
|
|
}
|
2010-04-23 18:26:10 -07:00
|
|
|
|
2011-02-20 23:49:21 -08:00
|
|
|
/* show non-top-level plugins as item */
|
2010-05-30 12:16:33 -07:00
|
|
|
if (top_level && (!s->trigger_active))
|
2010-05-06 06:09:14 -07:00
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(s->plugins, l, pp)
|
|
|
|
{
|
2010-05-30 12:16:33 -07:00
|
|
|
int min_fuzz = 0;
|
|
|
|
double max_usage = 0.0;
|
2010-05-06 06:09:14 -07:00
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
if (pp->config->top_level)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (pp == plugin)
|
2010-05-06 06:09:14 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!pp->items)
|
|
|
|
continue;
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
/* give plugin item the highest priority of its items */
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
|
|
|
if (it->usage >= 0)
|
|
|
|
evry_history_item_usage_set(it, input, context);
|
|
|
|
|
2011-08-16 16:26:07 -07:00
|
|
|
if (it->usage && (it->usage > max_usage))
|
2011-02-20 23:49:21 -08:00
|
|
|
max_usage = it->usage;
|
2010-05-30 12:16:33 -07:00
|
|
|
|
|
|
|
if (it->fuzzy_match == 0)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
|
|
|
if ((!min_fuzz) || ((it->fuzzy_match > 0) &&
|
|
|
|
(it->fuzzy_match < min_fuzz)))
|
|
|
|
min_fuzz = it->fuzzy_match;
|
|
|
|
}
|
|
|
|
|
|
|
|
GET_ITEM(it, pp);
|
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
it->hi = NULL;
|
2011-02-20 23:49:21 -08:00
|
|
|
/* TODO get better usage estimate */
|
2010-05-30 12:16:33 -07:00
|
|
|
evry_history_item_usage_set(it, NULL, NULL);
|
|
|
|
it->usage /= 100.0;
|
|
|
|
|
2011-02-20 23:49:21 -08:00
|
|
|
if ((it->usage && max_usage) && (it->usage < max_usage))
|
2010-05-30 12:16:33 -07:00
|
|
|
it->usage = max_usage;
|
|
|
|
it->fuzzy_match = min_fuzz;
|
2010-05-13 15:27:57 -07:00
|
|
|
|
2010-05-28 13:32:07 -07:00
|
|
|
IF_RELEASE(it->detail);
|
2011-02-20 23:49:21 -08:00
|
|
|
snprintf(buf, sizeof(buf), "%d %s", eina_list_count(pp->items), _("Items"));
|
2010-05-06 06:09:14 -07:00
|
|
|
it->detail = eina_stringshare_add(buf);
|
|
|
|
|
2010-05-13 15:27:57 -07:00
|
|
|
items = eina_list_append(items, it);
|
2010-05-06 06:09:14 -07:00
|
|
|
}
|
2010-05-26 08:54:07 -07:00
|
|
|
|
2010-05-26 08:09:51 -07:00
|
|
|
/* only one plugin: show items */
|
2010-05-30 12:16:33 -07:00
|
|
|
if ((eina_list_count(s->cur_plugins)) == 1 && items &&
|
|
|
|
(pp = eina_list_data_get(items)) && (pp->config->aggregate))
|
2010-05-26 08:09:51 -07:00
|
|
|
{
|
2010-05-26 08:54:07 -07:00
|
|
|
eina_list_free(items);
|
2010-05-26 08:09:51 -07:00
|
|
|
items = NULL;
|
2010-05-26 08:54:07 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
|
|
|
{
|
|
|
|
if (it->usage >= 0)
|
|
|
|
evry_history_item_usage_set(it, input, context);
|
|
|
|
if (it->fuzzy_match == 0)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
|
|
|
items = eina_list_append(items, it);
|
|
|
|
}
|
2010-05-26 08:09:51 -07:00
|
|
|
}
|
2010-05-30 12:16:33 -07:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
/* append all plugins as items (which were not added above) */
|
|
|
|
if (inp_len >= plugin->config->min_query)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(s->plugins, l, pp)
|
|
|
|
{
|
|
|
|
if (!strcmp(pp->name, "Actions"))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* items MUST only conatin plugins here ! */
|
|
|
|
EINA_LIST_FOREACH(items, ll, pp2)
|
|
|
|
if (pp2->name == pp->name) break;
|
|
|
|
if (pp2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
GET_ITEM(it, pp);
|
|
|
|
|
|
|
|
if ((!input) ||
|
|
|
|
(it->fuzzy_match = evry_fuzzy_match(it->label, input)))
|
|
|
|
{
|
|
|
|
evry_history_item_usage_set(it, input, NULL);
|
|
|
|
it->usage /= 100.0;
|
|
|
|
|
|
|
|
EVRY_ITEM(pp)->plugin->state = s;
|
|
|
|
items = eina_list_append(items, pp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if (!lp && (eina_list_count(items) < 2))
|
|
|
|
{
|
|
|
|
if (items) eina_list_free(items);
|
|
|
|
return 0;
|
|
|
|
}
|
2010-05-06 06:09:14 -07:00
|
|
|
}
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
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
|
|
|
{
|
2010-05-30 12:16:33 -07:00
|
|
|
pp = eina_list_data_get(lp);
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
|
|
|
{
|
|
|
|
if (it->usage >= 0)
|
|
|
|
evry_history_item_usage_set(it, input, context);
|
2010-05-13 15:27:57 -07:00
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
if (it->fuzzy_match == 0)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
|
|
|
items = eina_list_append(items, it);
|
|
|
|
}
|
2010-04-23 18:26:10 -07:00
|
|
|
}
|
2010-05-30 12:16:33 -07:00
|
|
|
/* if there is input append all items that match */
|
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-01 17:58:33 -07:00
|
|
|
if (it->usage >= 0)
|
2010-05-30 12:16:33 -07:00
|
|
|
evry_history_item_usage_set(it, input, context);
|
|
|
|
|
|
|
|
if ((subj_sel) && (top_level) &&
|
2010-10-28 16:07:59 -07:00
|
|
|
(!it->usage) && (inp_len < plugin->config->min_query))
|
2010-05-30 12:16:33 -07:00
|
|
|
continue;
|
2010-05-13 15:27:57 -07:00
|
|
|
|
|
|
|
items = eina_list_append(items, it);
|
2010-05-30 12:16:33 -07:00
|
|
|
}
|
|
|
|
}
|
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)
|
|
|
|
{
|
2011-08-16 16:26:07 -07:00
|
|
|
if ((!subj_sel) || (it->usage < 0) ||
|
|
|
|
(evry_history_item_usage_set(it, input, context)))
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
2010-05-03 12:19:42 -07:00
|
|
|
it->fuzzy_match = 0;
|
2010-05-13 15:27:57 -07:00
|
|
|
items = eina_list_append(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-30 12:16:33 -07:00
|
|
|
if ((!top_level) && (eina_list_count(items) < MAX_ITEMS))
|
2010-04-24 16:05:36 -07:00
|
|
|
{
|
2010-05-30 12:16:33 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
|
|
|
if (eina_list_data_find_list(items, it))
|
|
|
|
continue;
|
2010-05-06 06:09:14 -07:00
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
items = eina_list_append(items, it);
|
|
|
|
}
|
|
|
|
}
|
2010-04-24 16:05:36 -07:00
|
|
|
}
|
2010-04-27 20:22:40 -07:00
|
|
|
|
2010-05-13 15:27:57 -07:00
|
|
|
items = eina_list_sort(items, -1, evry_items_sort_func);
|
2010-05-23 06:54:44 -07:00
|
|
|
|
2010-05-13 15:27:57 -07:00
|
|
|
EINA_LIST_FOREACH(items, l, it)
|
2010-04-14 13:21:56 -07:00
|
|
|
{
|
2011-02-20 23:49:21 -08:00
|
|
|
/* remove duplicates provided by different plugins. e.g.
|
|
|
|
files / places and tracker can find the same files */
|
2010-05-13 15:27:57 -07:00
|
|
|
if (it->id)
|
2010-05-11 19:01:09 -07:00
|
|
|
{
|
2010-05-13 15:27:57 -07:00
|
|
|
EINA_LIST_FOREACH(p->base.items, ll, it2)
|
|
|
|
{
|
|
|
|
if ((it->plugin->name != it2->plugin->name) &&
|
|
|
|
(it->type == it2->type) &&
|
|
|
|
(it->id == it2->id))
|
2010-05-18 05:32:29 -07:00
|
|
|
break;
|
2010-05-13 15:27:57 -07:00
|
|
|
}
|
2010-05-11 19:01:09 -07:00
|
|
|
}
|
2010-05-13 15:27:57 -07:00
|
|
|
|
2010-05-18 05:32:29 -07:00
|
|
|
if (!it->id || !it2)
|
|
|
|
{
|
|
|
|
evry_item_ref(it);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
|
|
|
}
|
2010-05-23 06:54:44 -07:00
|
|
|
|
2010-05-13 15:27:57 -07:00
|
|
|
if (cnt++ > MAX_ITEMS)
|
|
|
|
break;
|
|
|
|
|
2010-04-14 13:21:56 -07:00
|
|
|
}
|
2010-04-16 18:10:20 -07:00
|
|
|
|
2010-05-13 15:27:57 -07:00
|
|
|
if (lp) eina_list_free(lp);
|
|
|
|
|
2010-05-30 12:16:33 -07:00
|
|
|
if (items)
|
|
|
|
{
|
|
|
|
eina_list_free(items);
|
|
|
|
}
|
|
|
|
/* 'text' and 'actions' are always loaded */
|
|
|
|
else if ((subj_sel) && (eina_list_count(s->plugins) == 2))
|
|
|
|
{
|
|
|
|
evry_item_ref(p->warning);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, p->warning);
|
|
|
|
}
|
|
|
|
|
2011-08-21 08:41:37 -07:00
|
|
|
return EVRY_PLUGIN_HAS_ITEMS(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-05-30 12:16:33 -07:00
|
|
|
_finish(Evry_Plugin *plugin)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-05-30 12:16:33 -07:00
|
|
|
GET_PLUGIN(p, plugin);
|
|
|
|
|
2010-05-06 06:09:14 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
2010-05-30 12:16:33 -07:00
|
|
|
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Evry_Plugin *
|
|
|
|
_begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
|
|
|
|
{
|
|
|
|
Plugin *p;
|
|
|
|
|
|
|
|
GET_PLUGIN(base, plugin);
|
|
|
|
EVRY_PLUGIN_INSTANCE(p, plugin);
|
|
|
|
|
|
|
|
p->warning = base->warning;
|
|
|
|
|
|
|
|
return EVRY_PLUGIN(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-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 *
|
2011-08-21 08:41:37 -07:00
|
|
|
evry_aggregator_new(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
|
|
|
|
2011-08-12 10:18:25 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, "All", NULL, 0, _begin, _finish, _fetch, _free);
|
2010-05-12 22:31:06 -07:00
|
|
|
|
2010-05-12 21:13:38 -07:00
|
|
|
if (evry_plugin_register(p, type, -1))
|
|
|
|
{
|
2011-08-21 08:41:37 -07:00
|
|
|
p->config->view_mode = VIEW_MODE_THUMB;
|
2010-05-12 21:13:38 -07:00
|
|
|
}
|
2010-04-27 20:22:40 -07:00
|
|
|
|
|
|
|
GET_PLUGIN(pa, p);
|
2010-05-15 19:37:07 -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
|
|
|
}
|