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;
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2009-08-27 19:39:29 -07:00
|
|
|
if ((it1->plugin == action_selector) ||
|
|
|
|
(it2->plugin == action_selector))
|
|
|
|
{
|
|
|
|
if ((it1->plugin == action_selector) &&
|
|
|
|
(it2->plugin == action_selector))
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
else if (it1->plugin == action_selector)
|
|
|
|
return ((it1->plugin->config->priority + it1->priority)
|
|
|
|
- it2->plugin->config->priority);
|
|
|
|
else
|
|
|
|
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;
|
|
|
|
|
2009-08-27 19:25:13 -07:00
|
|
|
if ((it1->plugin == action_selector) ||
|
|
|
|
(it2->plugin == action_selector))
|
|
|
|
{
|
|
|
|
if ((it1->plugin == action_selector) &&
|
|
|
|
(it2->plugin == action_selector))
|
|
|
|
return (it1->priority - it2->priority);
|
|
|
|
else if (it1->plugin == action_selector)
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
int cnt = 0;
|
|
|
|
Eina_List *items = NULL;
|
|
|
|
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEMS_FREE(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
s = p->selector->state;
|
2009-08-21 15:42:06 -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
|
|
|
{
|
|
|
|
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])
|
|
|
|
{
|
|
|
|
evry_item_ref(it);
|
|
|
|
items = eina_list_append(items, it);
|
2009-08-22 20:12:05 -07:00
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, 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
|
|
|
{
|
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;
|
|
|
|
evry_item_ref(it);
|
|
|
|
it->fuzzy_match = 0;
|
2009-08-30 05:01:50 -07:00
|
|
|
items = eina_list_append(items, it);
|
2009-08-30 04:07:10 -07:00
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(lp, l, pp)
|
|
|
|
{
|
|
|
|
EINA_LIST_FOREACH(pp->items, ll, it)
|
|
|
|
{
|
2009-08-30 05:01:50 -07:00
|
|
|
if (evry_history_item_usage_set(p->selector->history, it, input) &&
|
|
|
|
(!eina_list_data_find_list(items, it)))
|
2009-08-30 04:07:10 -07:00
|
|
|
{
|
|
|
|
evry_item_ref(it);
|
|
|
|
items = eina_list_append(items, it);
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|
|
|
|
|
2009-08-30 04:07:10 -07:00
|
|
|
/* NOTE this is kind of weird. list_count returns 2 even if there is
|
|
|
|
only one item in list */
|
|
|
|
if (eina_list_count(lp) == 2)
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
pp = lp->data;
|
|
|
|
EINA_LIST_FOREACH(pp->items, l, it)
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
if (!eina_list_data_find_list(items, it))
|
2009-08-30 01:51:15 -07:00
|
|
|
{
|
2009-08-30 04:07:10 -07:00
|
|
|
evry_item_ref(it);
|
|
|
|
it->fuzzy_match = 0;
|
|
|
|
EVRY_PLUGIN_ITEM_APPEND(p, it);
|
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
|
|
|
{
|
|
|
|
if (it->plugin && it->plugin->icon_get)
|
|
|
|
return it->plugin->icon_get(it->plugin, it, e);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
2009-08-21 15:42:06 -07:00
|
|
|
NULL, _cleanup, _fetch, _action, _icon_get,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
evry_plug_aggregator_free(Evry_Plugin *plugin)
|
|
|
|
{
|
2009-08-22 20:12:05 -07:00
|
|
|
PLUGIN(p, plugin);
|
|
|
|
EVRY_PLUGIN_FREE(p);
|
2009-08-21 15:42:06 -07:00
|
|
|
}
|