2009-08-21 15:42:06 -07:00
|
|
|
#include "e_mod_main.h"
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct _Plugin Plugin;
|
|
|
|
|
|
|
|
struct _Plugin
|
|
|
|
{
|
|
|
|
Evry_Plugin base;
|
|
|
|
Evry_Selector *selector;
|
|
|
|
};
|
|
|
|
|
2010-04-04 07:11:35 -07:00
|
|
|
inline static int
|
|
|
|
_is_action(const Evry_Item *it)
|
|
|
|
{
|
|
|
|
return (it->plugin->name == action_selector);
|
|
|
|
}
|
|
|
|
|
2009-08-27 19:39:29 -07:00
|
|
|
static int
|
|
|
|
_cb_sort_recent(const void *data1, const void *data2)
|
|
|
|
{
|
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
if (it1->usage && it2->usage)
|
2009-08-31 11:48:54 -07:00
|
|
|
return (it1->usage > it2->usage ? -1 : 1);
|
2009-08-30 01:51:15 -07:00
|
|
|
if (it1->usage && !it2->usage)
|
|
|
|
return -1;
|
|
|
|
if (it2->usage && !it1->usage)
|
|
|
|
return 1;
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2010-04-04 07:11:35 -07:00
|
|
|
if (_is_action(it1) || _is_action(it2))
|
2009-08-27 19:39:29 -07:00
|
|
|
{
|
2010-04-04 07:11:35 -07:00
|
|
|
if (_is_action(it1) && _is_action(it2))
|
2009-08-27 19:39:29 -07:00
|
|
|
return (it1->priority - it2->priority);
|
2010-04-04 07:11:35 -07:00
|
|
|
else if (_is_action(it1))
|
|
|
|
return ((it1->plugin->config->priority + it1->priority) -
|
|
|
|
(it2->plugin->config->priority));
|
2009-08-27 19:39:29 -07:00
|
|
|
else
|
2010-04-04 07:11:35 -07:00
|
|
|
return ((it1->plugin->config->priority) -
|
2009-08-30 01:51:15 -07:00
|
|
|
(it2->plugin->config->priority + it2->priority));
|
2009-08-27 19:39:29 -07:00
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2009-08-27 19:39:29 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
static int
|
|
|
|
_cb_sort(const void *data1, const void *data2)
|
|
|
|
{
|
|
|
|
const Evry_Item *it1 = data1;
|
|
|
|
const Evry_Item *it2 = data2;
|
|
|
|
|
2009-08-30 01:51:15 -07:00
|
|
|
if (it1->usage && it2->usage)
|
2009-08-31 11:48:54 -07:00
|
|
|
return (it1->usage > it2->usage ? -1 : 1);
|
2009-08-30 01:51:15 -07:00
|
|
|
if (it1->usage && !it2->usage)
|
|
|
|
return -1;
|
|
|
|
if (it2->usage && !it1->usage)
|
|
|
|
return 1;
|
|
|
|
|
2010-04-04 07:11:35 -07:00
|
|
|
if (_is_action(it1) || _is_action(it2))
|
2009-08-27 19:25:13 -07:00
|
|
|
{
|
2010-04-04 07:11:35 -07:00
|
|
|
if (_is_action(it1) && _is_action(it2))
|
2009-08-27 19:25:13 -07:00
|
|
|
return (it1->priority - it2->priority);
|
2010-04-04 07:11:35 -07:00
|
|
|
else if (_is_action(it1))
|
2009-08-27 19:39:29 -07:00
|
|
|
return ((it1->plugin->config->priority + it1->priority)
|
|
|
|
- it2->plugin->config->priority);
|
2009-08-27 19:25:13 -07:00
|
|
|
else
|
2009-08-27 19:39:29 -07:00
|
|
|
return (it1->plugin->config->priority -
|
|
|
|
(it1->plugin->config->priority + it2->priority));
|
2009-08-27 19:25:13 -07:00
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
if ((it1->plugin == it2->plugin) &&
|
|
|
|
(it1->priority - it2->priority))
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
|
|
|
|
if (it1->fuzzy_match || it2->fuzzy_match)
|
|
|
|
{
|
|
|
|
if (it1->fuzzy_match && !it2->fuzzy_match)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!it1->fuzzy_match && it2->fuzzy_match)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (it1->fuzzy_match - it2->fuzzy_match)
|
|
|
|
return (it1->fuzzy_match - it2->fuzzy_match);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (it1->plugin->config->priority - it2->plugin->config->priority)
|
|
|
|
return (it1->plugin->config->priority - it2->plugin->config->priority);
|
|
|
|
|
|
|
|
if (it1->priority - it2->priority)
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
return strcasecmp(it1->label, it2->label);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
static int refs = 0;
|
|
|
|
|
|
|
|
static inline Eina_List *
|
|
|
|
_add_item(Plugin *p, Eina_List *items, Evry_Item *it)
|
|
|
|
{
|
|
|
|
evry_item_ref(it);
|
|
|
|
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;
|
2009-08-30 05:01:50 -07:00
|
|
|
Eina_List *l, *ll, *lp;
|
2009-08-21 15:42:06 -07:00
|
|
|
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;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-08 15:37:50 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
s = p->selector->state;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-10-01 15:31:45 -07:00
|
|
|
if (!s || !s->cur_plugins || !s->cur_plugins->next)
|
|
|
|
return 0;
|
|
|
|
|
2009-09-03 07:21:27 -07:00
|
|
|
for (i = 1; i < 3; i++)
|
|
|
|
{
|
|
|
|
Evry_Item *item;
|
|
|
|
if (p->selector == selectors[i])
|
|
|
|
{
|
|
|
|
item = selectors[i-1]->state->cur_item;
|
|
|
|
context = item->context;
|
|
|
|
}
|
|
|
|
}
|
2009-10-01 15:31:45 -07:00
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
/* first is aggregator itself */
|
|
|
|
lp = s->cur_plugins->next;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-31 03:30:55 -07:00
|
|
|
if (input)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-01 21:19:38 -07:00
|
|
|
if (!pp->aggregate) continue;
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
|
|
|
if (!it->fuzzy_match)
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
|
|
|
|
if (it->fuzzy_match || p->selector == selectors[2])
|
2010-04-08 15:37:50 -07:00
|
|
|
items = _add_item(p, items, it);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-30 06:35:06 -07:00
|
|
|
/* always append items of action or object selector */
|
2009-08-31 03:30:55 -07:00
|
|
|
if ((!input) &&
|
2009-08-30 06:35:06 -07:00
|
|
|
((p->selector == selectors[1]) ||
|
|
|
|
(p->selector == selectors[2])))
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-01 21:19:38 -07:00
|
|
|
if (!pp->aggregate) continue;
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
for (cnt = 0, ll = pp->items; ll && cnt < 50; ll = ll->next, cnt++)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2009-08-30 05:01:50 -07:00
|
|
|
if (!eina_list_data_find_list(items, ll->data))
|
2009-08-30 04:07:10 -07:00
|
|
|
{
|
|
|
|
it = ll->data;
|
|
|
|
it->fuzzy_match = 0;
|
2010-04-08 15:37:50 -07:00
|
|
|
items = _add_item(p, items, it);
|
2009-08-30 04:07:10 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
2010-04-01 21:19:38 -07:00
|
|
|
if (!pp->aggregate) continue;
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
2009-09-03 07:21:27 -07:00
|
|
|
if (evry_history_item_usage_set(p->selector->history, it, input, context) &&
|
2009-08-30 05:01:50 -07:00
|
|
|
(!eina_list_data_find_list(items, it)))
|
2009-08-30 04:07:10 -07:00
|
|
|
{
|
2010-04-08 15:37:50 -07:00
|
|
|
items = _add_item(p, items, it);
|
2009-08-30 04:07:10 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2009-10-06 14:39:34 -07:00
|
|
|
if (lp && ((eina_list_count(lp) == 2) || (!EVRY_PLUGIN(p)->items)))
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
pp = lp->data;
|
2010-04-01 21:19:38 -07:00
|
|
|
|
|
|
|
if (pp->aggregate)
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2010-04-01 21:19:38 -07:00
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2010-04-01 21:19:38 -07:00
|
|
|
if (!eina_list_data_find_list(items, it))
|
|
|
|
{
|
|
|
|
it->fuzzy_match = 0;
|
2010-04-08 15:37:50 -07:00
|
|
|
items = _add_item(p, items, it);
|
2010-04-01 21:19:38 -07:00
|
|
|
}
|
2009-08-30 01:51:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
|
|
|
if (items) eina_list_free(items);
|
|
|
|
|
2009-08-31 03:30:55 -07:00
|
|
|
if (input)
|
2009-08-27 19:39:29 -07:00
|
|
|
{
|
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort_recent);
|
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2009-08-21 18:15:21 -07:00
|
|
|
_action(Evry_Plugin *plugin, const Evry_Item *it)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
|
|
|
if (it->plugin && it->plugin->action)
|
2009-08-21 18:15:21 -07:00
|
|
|
return it->plugin->action(it->plugin, it);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_cleanup(Evry_Plugin *plugin)
|
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(plugin);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Evas_Object *
|
2009-08-22 14:22:38 -07:00
|
|
|
_icon_get(Evry_Plugin *plugin, const Evry_Item *it, Evas *e)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-03-14 10:53:13 -07:00
|
|
|
Evas_Object *o = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-03-14 10:53:13 -07:00
|
|
|
if (it->plugin)
|
|
|
|
{
|
|
|
|
if (it->plugin->icon_get)
|
|
|
|
o = it->plugin->icon_get(it->plugin, it, e);
|
|
|
|
else if (it->plugin->icon)
|
|
|
|
o = evry_icon_theme_get(it->plugin->icon, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return o;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2010-04-10 15:38:05 -07:00
|
|
|
static void
|
|
|
|
_plugin_free(Evry_Plugin *plugin)
|
|
|
|
{
|
|
|
|
PLUGIN(p, plugin);
|
|
|
|
|
|
|
|
E_FREE(p);
|
|
|
|
}
|
|
|
|
|
2009-08-21 15:42:06 -07:00
|
|
|
Evry_Plugin *
|
|
|
|
evry_plug_aggregator_new(Evry_Selector *selector)
|
|
|
|
{
|
|
|
|
Plugin *p;
|
|
|
|
Plugin_Config *pc;
|
|
|
|
|
|
|
|
p = E_NEW(Plugin, 1);
|
2009-08-22 20:12:05 -07:00
|
|
|
evry_plugin_new(EVRY_PLUGIN(p), "All", 0, "", "", 0, NULL, NULL,
|
2010-04-10 15:38:05 -07:00
|
|
|
NULL, _cleanup, _fetch, _action, _icon_get, _plugin_free);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
pc = E_NEW(Plugin_Config, 1);
|
|
|
|
pc->enabled = 1;
|
|
|
|
pc->priority = -1;
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN(p)->config = pc;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
|
|
|
p->selector = selector;
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
return EVRY_PLUGIN(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|