1 #include "e_mod_main.h"
3 //TODO min input for items not in history
7 typedef struct _Plugin Plugin;
19 _fetch(Evry_Plugin *plugin, const char *input)
21 Plugin *p = (Plugin *) plugin;
24 Eina_List *l, *ll, *lp = NULL;
26 int i, top_level = 0, subj_sel = 0, inp_len = 0, cnt = 0;
27 Eina_List *items = NULL;
28 const char *context = NULL;
30 Evry_Selector *sel = p->win->selectors[p->type];
32 if (input && input[0])
33 inp_len = strlen(input);
37 EVRY_PLUGIN_ITEMS_FREE(p);
42 if (sel == p->win->selectors[0])
45 if (!sel->states->next)
48 /* get current items' context ... */
49 for (i = 1; i < 3; i++)
51 if (sel == p->win->selectors[i])
53 it = p->win->selectors[i-1]->state->cur_item;
54 if (it) context = it->context;
58 /* collect plugins to be shown in aggregator */
59 EINA_LIST_FOREACH(s->cur_plugins, l, pp)
61 /* dont show in aggregator */
62 if (!pp->config->aggregate)
67 /* dont show plugin in top-level */
68 if (top_level && !pp->config->top_level)
70 lp = eina_list_append(lp, pp);
73 /* show non-top-level plugins as item */
74 if (top_level && (!s->trigger_active))
76 EINA_LIST_FOREACH(s->plugins, l, pp)
79 double max_usage = 0.0;
81 if (pp->config->top_level)
90 /* give plugin item the highest priority of its items */
91 EINA_LIST_FOREACH(pp->items, ll, it)
94 evry_history_item_usage_set(it, input, context);
96 if (it->usage && it->usage > max_usage)
97 max_usage = it->usage;
99 if (it->fuzzy_match == 0)
100 it->fuzzy_match = evry_fuzzy_match(it->label, input);
102 if ((!min_fuzz) || ((it->fuzzy_match > 0) &&
103 (it->fuzzy_match < min_fuzz)))
104 min_fuzz = it->fuzzy_match;
110 /* TODO get better usage estimate */
111 evry_history_item_usage_set(it, NULL, NULL);
114 if ((it->usage && max_usage) && (it->usage < max_usage))
115 it->usage = max_usage;
116 it->fuzzy_match = min_fuzz;
118 IF_RELEASE(it->detail);
119 snprintf(buf, sizeof(buf), "%d %s", eina_list_count(pp->items), _("Items"));
120 it->detail = eina_stringshare_add(buf);
122 items = eina_list_append(items, it);
125 /* only one plugin: show items */
126 if ((eina_list_count(s->cur_plugins)) == 1 && items &&
127 (pp = eina_list_data_get(items)) && (pp->config->aggregate))
129 eina_list_free(items);
131 EINA_LIST_FOREACH(pp->items, l, it)
134 evry_history_item_usage_set(it, input, context);
135 if (it->fuzzy_match == 0)
136 it->fuzzy_match = evry_fuzzy_match(it->label, input);
138 items = eina_list_append(items, it);
143 /* append all plugins as items (which were not added above) */
144 if (inp_len >= plugin->config->min_query)
146 EINA_LIST_FOREACH(s->plugins, l, pp)
148 if (!strcmp(pp->name, "Actions"))
151 /* items MUST only conatin plugins here ! */
152 EINA_LIST_FOREACH(items, ll, pp2)
153 if (pp2->name == pp->name) break;
160 (it->fuzzy_match = evry_fuzzy_match(it->label, input)))
162 evry_history_item_usage_set(it, input, NULL);
165 EVRY_ITEM(pp)->plugin->state = s;
166 items = eina_list_append(items, pp);
171 if (!lp && (eina_list_count(items) < 2))
173 if (items) eina_list_free(items);
181 /* if there is only one plugin append all items */
184 pp = eina_list_data_get(lp);
186 EINA_LIST_FOREACH(pp->items, l, it)
189 evry_history_item_usage_set(it, input, context);
191 if (it->fuzzy_match == 0)
192 it->fuzzy_match = evry_fuzzy_match(it->label, input);
194 items = eina_list_append(items, it);
197 /* if there is input append all items that match */
200 EINA_LIST_FOREACH(lp, l, pp)
202 EINA_LIST_FOREACH(pp->items, ll, it)
204 if (it->fuzzy_match == 0)
205 it->fuzzy_match = evry_fuzzy_match(it->label, input);
208 evry_history_item_usage_set(it, input, context);
210 if ((subj_sel) && (top_level) &&
211 (!it->usage) && (inp_len < plugin->config->min_query))
214 items = eina_list_append(items, it);
218 /* no input: append all items that are in history */
221 EINA_LIST_FOREACH(lp, l, pp)
223 EINA_LIST_FOREACH(pp->items, ll, it)
225 if (((it->usage >= 0) &&
226 (evry_history_item_usage_set(it, input, context))) ||
230 items = eina_list_append(items, it);
236 if ((!top_level) && (eina_list_count(items) < MAX_ITEMS))
238 EINA_LIST_FOREACH(lp, l, pp)
240 EINA_LIST_FOREACH(pp->items, ll, it)
242 if (eina_list_data_find_list(items, it))
245 items = eina_list_append(items, it);
250 items = eina_list_sort(items, -1, evry_items_sort_func);
252 EINA_LIST_FOREACH(items, l, it)
254 /* remove duplicates provided by different plugins. e.g.
255 files / places and tracker can find the same files */
258 EINA_LIST_FOREACH(p->base.items, ll, it2)
260 if ((it->plugin->name != it2->plugin->name) &&
261 (it->type == it2->type) &&
270 EVRY_PLUGIN_ITEM_APPEND(p, it);
273 if (cnt++ > MAX_ITEMS)
278 if (lp) eina_list_free(lp);
282 eina_list_free(items);
284 /* 'text' and 'actions' are always loaded */
285 else if ((subj_sel) && (eina_list_count(s->plugins) == 2))
287 evry_item_ref(p->warning);
288 EVRY_PLUGIN_ITEM_APPEND(p, p->warning);
291 return !!(p->base.items);
295 _finish(Evry_Plugin *plugin)
297 GET_PLUGIN(p, plugin);
299 EVRY_PLUGIN_ITEMS_FREE(p);
305 _begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
309 GET_PLUGIN(base, plugin);
310 EVRY_PLUGIN_INSTANCE(p, plugin);
312 p->type = base->type;
314 p->warning = base->warning;
316 return EVRY_PLUGIN(p);
320 _free(Evry_Plugin *plugin)
322 GET_PLUGIN(p, plugin);
324 evry_item_free(p->warning);
330 evry_aggregator_new(Evry_Window *win, int type)
334 p = EVRY_PLUGIN_NEW(Plugin, N_("All"), NULL, 0, _begin, _finish, _fetch, _free);
336 if (evry_plugin_register(p, type, -1))
338 if (type == EVRY_PLUGIN_SUBJECT)
339 p->config->view_mode = VIEW_MODE_THUMB;
346 pa->warning = evry_item_new(NULL, p, N_("No plugins loaded"), NULL, NULL);
347 pa->warning->type = EVRY_TYPE_NONE;