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-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
|
|
|
|
2010-04-19 00:26:56 -07:00
|
|
|
if (it1->plugin == it2->plugin)
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
|
|
|
|
return strcmp(it1->label, it2->label);
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-04-19 00:26:56 -07:00
|
|
|
return 1;
|
2009-08-27 19:39:29 -07:00
|
|
|
}
|
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;
|
2010-04-23 17:54:12 -07:00
|
|
|
|
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);
|
2010-04-23 17:54:12 -07:00
|
|
|
|
2010-04-22 11:12:17 -07:00
|
|
|
if (it1->fuzzy_match > 0 || it2->fuzzy_match > 0)
|
2009-08-21 15:42:06 -07:00
|
|
|
{
|
2010-04-22 11:12:17 -07:00
|
|
|
if (it2->fuzzy_match <= 0)
|
2009-08-21 15:42:06 -07:00
|
|
|
return -1;
|
|
|
|
|
2010-04-22 11:12:17 -07:00
|
|
|
if (it1->fuzzy_match <= 0)
|
2009-08-21 15:42:06 -07:00
|
|
|
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);
|
|
|
|
|
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 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;
|
2010-04-24 16:05:36 -07:00
|
|
|
Eina_List *l, *ll, *lll, *lp = NULL;
|
2010-04-16 18:10:20 -07:00
|
|
|
Evry_Item *it, *it2;
|
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-04-23 19:11:14 -07:00
|
|
|
if (input && !input[0]) input = NULL;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-17 05:40:28 -07:00
|
|
|
plugin->changed = 1;
|
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-04-23 19:11:14 -07:00
|
|
|
s = p->selector->state;
|
|
|
|
if (!s || !s->cur_plugins)
|
2009-10-01 15:31:45 -07:00
|
|
|
return 0;
|
|
|
|
|
2010-04-17 05:40:28 -07:00
|
|
|
/* get current 'context' ... */
|
2009-09-03 07:21:27 -07:00
|
|
|
for (i = 1; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (p->selector == selectors[i])
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
if (!pp->aggregate || pp == plugin) continue;
|
|
|
|
lp = eina_list_append(lp, pp);
|
|
|
|
}
|
2010-04-23 18:26:10 -07:00
|
|
|
|
2010-04-24 16:05:36 -07:00
|
|
|
if (!lp) return 0;
|
|
|
|
|
2010-04-24 05:10:19 -07:00
|
|
|
/* if there is only one plugin append all items */
|
2010-04-24 16:05:36 -07:00
|
|
|
if (!lp->next)
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
|
|
|
pp = lp->data;
|
2010-04-24 16:05:36 -07:00
|
|
|
|
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
2010-04-24 16:05:36 -07:00
|
|
|
evry_history_item_usage_set(p->selector->history, it, input, context);
|
|
|
|
it->fuzzy_match = evry_fuzzy_match(it->label, input);
|
|
|
|
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);
|
|
|
|
|
|
|
|
if (it->fuzzy_match || p->selector == selectors[2])
|
2010-04-23 18:26:10 -07:00
|
|
|
{
|
|
|
|
evry_history_item_usage_set(p->selector->history, it, input, context);
|
|
|
|
items = _add_item(p, items, it);
|
|
|
|
}
|
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) &&
|
|
|
|
((p->selector == selectors[1]) ||
|
|
|
|
(p->selector == 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-04-24 16:05:36 -07:00
|
|
|
evry_history_item_usage_set(p->selector->history, it, NULL, context);
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (evry_history_item_usage_set(p->selector->history, it, input, context) &&
|
|
|
|
(!eina_list_data_find_list(items, it)))
|
|
|
|
{
|
|
|
|
items = _add_item(p, items, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-08-30 01:51:15 -07:00
|
|
|
}
|
2009-08-30 04:07:10 -07:00
|
|
|
|
2010-04-24 16:05:36 -07:00
|
|
|
if (eina_list_count(items) < MAX_ITEMS)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
|
|
|
if (!eina_list_data_find_list(items, it))
|
|
|
|
items = _add_item(p, items, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
2010-04-14 13:21:56 -07:00
|
|
|
cnt = 0;
|
|
|
|
EINA_LIST_FOREACH_SAFE(p->base.items, l, ll, it)
|
|
|
|
{
|
|
|
|
if (cnt++ < MAX_ITEMS) continue;
|
2010-04-23 17:54:12 -07:00
|
|
|
evry_item_free(it);
|
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
|
|
|
|
|
|
|
/* remove duplicates provided by different plugins */
|
2010-04-23 18:26:10 -07:00
|
|
|
/* EINA_LIST_FOREACH_SAFE(p->base.items, l, ll, it)
|
|
|
|
* {
|
|
|
|
* EINA_LIST_FOREACH(l->next, lll, it2)
|
|
|
|
* {
|
|
|
|
* if ((it->plugin->name != it2->plugin->name) &&
|
|
|
|
* (it->plugin->type_out == it2->plugin->type_out) &&
|
|
|
|
* (it->id == it2->id))
|
|
|
|
* {
|
|
|
|
* p->base.items = eina_list_remove_list(p->base.items, l);
|
|
|
|
* evry_item_free(it);
|
|
|
|
* break;
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* } */
|
2010-04-16 18:10:20 -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)
|
|
|
|
{
|
2010-04-11 06:40:10 -07:00
|
|
|
Evry_Item *it;
|
|
|
|
EINA_LIST_FREE(plugin->items, it)
|
|
|
|
evry_item_free(it);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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-24 17:31:11 -07:00
|
|
|
p = EVRY_PLUGIN_NEW(Plugin, N_("All"), type, "", "",
|
2010-04-23 17:21:45 -07:00
|
|
|
NULL, _cleanup, _fetch, _icon_get, NULL);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-24 17:31:11 -07:00
|
|
|
p->action = &_action;
|
|
|
|
p->history = EINA_FALSE;
|
|
|
|
evry_plugin_register(p, -1);
|
|
|
|
|
|
|
|
PLUGIN(pa, p);
|
|
|
|
pa->selector = sel;
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2010-04-24 17:31:11 -07:00
|
|
|
return p;
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|