1 #include "e_mod_main.h"
3 //TODO min input for items not in history
8 typedef struct _Plugin Plugin;
18 _fetch(Evry_Plugin *plugin, const char *input)
20 Plugin *p = (Plugin *)plugin;
22 Eina_List *l, *ll, *lp = NULL;
24 int top_level = 0, subj_sel = 0, cnt = 0;
26 Eina_List *items = NULL;
27 const char *context = NULL;
29 Evry_State *s = plugin->state;
30 Evry_Selector *sel = s->selector;
31 Evry_Selector **sels = sel->win->selectors;
33 if (input && input[0])
34 inp_len = strlen(input);
38 if ((eina_list_count(sel->states) == 1))
41 /* get current items' context, which is
42 * the previous selectors selected item */
47 else if (sel == sels[1])
49 it = sels[0]->state->cur_item;
50 if (it) context = it->context;
52 else if (sel == sels[2])
54 it = sels[1]->state->cur_item;
55 if (it) context = it->context;
58 EVRY_PLUGIN_ITEMS_FREE(p);
60 /* collect plugins to be shown in aggregator */
61 EINA_LIST_FOREACH (s->cur_plugins, l, pp)
63 /* dont show in aggregator */
64 if (!pp->config->aggregate)
69 /* dont show plugin in top-level */
70 if (top_level && !pp->config->top_level)
72 lp = eina_list_append(lp, pp);
75 /* show non-top-level plugins as item */
76 if ((top_level) && (!s->trigger_active))
78 EINA_LIST_FOREACH (s->plugins, l, pp)
81 double max_usage = 0.0;
83 if (pp->config->top_level)
92 /* give plugin item the highest priority of its items */
93 EINA_LIST_FOREACH (pp->items, ll, it)
96 evry_history_item_usage_set(it, input, context);
98 if (it->usage && (it->usage > max_usage))
99 max_usage = it->usage;
101 if (it->fuzzy_match == 0)
102 it->fuzzy_match = evry_fuzzy_match(it->label, input);
104 if ((!min_fuzz) || ((it->fuzzy_match > 0) &&
105 (it->fuzzy_match < min_fuzz)))
106 min_fuzz = it->fuzzy_match;
112 /* TODO get better usage estimate */
113 evry_history_item_usage_set(it, NULL, NULL);
116 if ((it->usage && max_usage) && (it->usage < max_usage))
117 it->usage = max_usage;
118 it->fuzzy_match = min_fuzz;
120 IF_RELEASE(it->detail);
121 snprintf(buf, sizeof(buf), "%d %s", eina_list_count(pp->items), _("Items"));
122 it->detail = eina_stringshare_add(buf);
124 items = eina_list_append(items, it);
127 /* only one plugin: show items */
128 if ((eina_list_count(s->cur_plugins)) == 1 && items &&
129 (pp = eina_list_data_get(items)) && (pp->config->aggregate))
131 eina_list_free(items);
133 EINA_LIST_FOREACH (pp->items, l, it)
136 evry_history_item_usage_set(it, input, context);
137 if (it->fuzzy_match == 0)
138 it->fuzzy_match = evry_fuzzy_match(it->label, input);
140 items = eina_list_append(items, it);
145 /* append all plugins as items (which were not added above) */
146 if (inp_len >= plugin->config->min_query)
148 EINA_LIST_FOREACH (s->plugins, l, pp)
150 if (!strcmp(pp->name, "Actions"))
153 /* items MUST only conatin plugins here ! */
154 EINA_LIST_FOREACH (items, ll, pp2)
155 if (pp2->name == pp->name) break;
162 (it->fuzzy_match = evry_fuzzy_match(it->label, input)))
164 evry_history_item_usage_set(it, input, NULL);
167 EVRY_ITEM(pp)->plugin->state = s;
168 items = eina_list_append(items, pp);
173 if (!lp && (eina_list_count(items) < 2))
175 if (items) eina_list_free(items);
183 /* if there is input append all items that match */
186 EINA_LIST_FOREACH (lp, l, pp)
188 EINA_LIST_FOREACH (pp->items, ll, it)
190 if (it->fuzzy_match == 0)
191 it->fuzzy_match = evry_fuzzy_match(it->label, input);
194 evry_history_item_usage_set(it, input, context);
196 if ((subj_sel) && (top_level) &&
197 (!it->usage) && (inp_len < plugin->config->min_query))
200 items = eina_list_append(items, it);
204 /* no input: append all items that are in history */
207 EINA_LIST_FOREACH (lp, l, pp)
210 EINA_LIST_FOREACH (pp->items, ll, it)
212 if ((!subj_sel) || (it->usage < 0) ||
213 (evry_history_item_usage_set(it, input, context)))
216 items = eina_list_append(items, it);
217 if (++cnt > MAX_PLUGIN) break;
223 if ((!top_level) && (eina_list_count(items) < MAX_ITEMS))
225 EINA_LIST_FOREACH (lp, l, pp)
227 EINA_LIST_FOREACH (pp->items, ll, it)
229 if (eina_list_data_find_list(items, it))
232 items = eina_list_append(items, it);
237 evry_util_items_sort(&items, 0 /* !input */);
239 EINA_LIST_FOREACH (items, l, it)
241 /* remove duplicates provided by different plugins. e.g.
242 files / places and tracker can find the same files */
245 EINA_LIST_FOREACH (p->base.items, ll, it2)
247 if ((it->plugin->name != it2->plugin->name) &&
248 (it->type == it2->type) &&
257 EVRY_PLUGIN_ITEM_APPEND(p, it);
260 if (cnt++ > MAX_ITEMS)
264 if (lp) eina_list_free(lp);
268 eina_list_free(items);
269 return EVRY_PLUGIN_HAS_ITEMS(p);
271 /* 'text' and 'actions' are always loaded */
272 else if ((subj_sel) && (eina_list_count(s->plugins) == 2))
274 evry_item_ref(p->warning);
275 EVRY_PLUGIN_ITEM_APPEND(p, p->warning);
282 _finish(Evry_Plugin *plugin)
284 GET_PLUGIN(p, plugin);
286 EVRY_PLUGIN_ITEMS_FREE(p);
288 evry_item_free(p->warning);
294 _begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
298 GET_PLUGIN(base, plugin);
299 EVRY_PLUGIN_INSTANCE(p, plugin);
301 p->warning = evry_item_new(NULL, EVRY_PLUGIN(p), N_("No plugins loaded"), NULL, NULL);
302 p->warning->type = EVRY_TYPE_NONE;
304 return EVRY_PLUGIN(p);
308 evry_aggregator_new(int type)
312 p = EVRY_PLUGIN_BASE("All", NULL, 0, _begin, _finish, _fetch);
314 if (evry_plugin_register(p, type, -1))
316 p->config->view_mode = VIEW_MODE_THUMB;