'everything' module:

fix preview plugin
some cleanups and added function to initialize a plugin


SVN revision: 41854
This commit is contained in:
Hannes Janetzek 2009-08-18 03:15:36 +00:00
parent 94544c168f
commit 42c652baae
11 changed files with 134 additions and 127 deletions

View File

@ -73,15 +73,9 @@ struct _Evry_Plugin
const char *trigger;
/* sync/async ?*/
Eina_Bool async_query;
/* whether candidates can be shown without input
* e.g. borders, app history */
Eina_Bool need_query;
Eina_Bool browseable;
/* whether the plugin uses evry_async_update to add new items */
int async_fetch;
/* run when plugin is activated. when return true plugin is added
to the list of current plugins and queried for results */
int (*begin) (Evry_Plugin *p, const Evry_Item *item);
@ -100,15 +94,12 @@ struct _Evry_Plugin
/* optional: default action for this plugins items */
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input);
Evry_Action *act;
/* optional: create list of items when shown (e.g. for sorting) */
void (*realize_items) (Evry_Plugin *p, Evas *e);
Eina_List *items;
Evas_Object *(*config_page) (void);
void (*config_apply) (void);
Evas_Object *(*config_page) (Evry_Plugin *p);
void (*config_apply) (Evry_Plugin *p);
/* only for internal use by plugin */
void *private;
@ -216,3 +207,14 @@ int evry_icon_theme_set(Evas_Object *obj, const char *icon);
int evry_fuzzy_match(const char *str, const char *match);
Evry_Plugin *evry_plugin_new(const char *name, int type,
const char *type_in, const char *type_out,
int async_fetch, const char *trigger,
int (*begin) (Evry_Plugin *p, const Evry_Item *item),
void (*cleanup) (Evry_Plugin *p),
int (*fetch) (Evry_Plugin *p, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input),
int (*browse) (Evry_Plugin *p, const Evry_Item *item),
Evas_Object *(*icon_get) (Evry_Plugin *p, const Evry_Item *it, Evas *e),
Evas_Object *(*config_page) (Evry_Plugin *p),
void (*config_apply) (Evry_Plugin *p));

View File

@ -249,7 +249,40 @@ _evry_cb_plugin_sort(const void *data1, const void *data2)
return p1->config->priority - p2->config->priority;
}
EAPI void
Evry_Plugin *
evry_plugin_new(const char *name, int type,
const char *type_in, const char *type_out,
int async_fetch, const char *trigger,
int (*begin) (Evry_Plugin *p, const Evry_Item *item),
void (*cleanup) (Evry_Plugin *p),
int (*fetch) (Evry_Plugin *p, const char *input),
int (*action) (Evry_Plugin *p, const Evry_Item *item, const char *input),
int (*browse) (Evry_Plugin *p, const Evry_Item *item),
Evas_Object *(*icon_get) (Evry_Plugin *p, const Evry_Item *it, Evas *e),
Evas_Object *(*config_page) (Evry_Plugin *p),
void (*config_apply) (Evry_Plugin *p))
{
Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
p->name = eina_stringshare_add(name);
p->type = type;
p->type_in = eina_stringshare_add(type_in);
p->type_out = eina_stringshare_add(type_out);
p->async_fetch = async_fetch;
p->begin = begin;
p->cleanup = cleanup;
p->fetch = fetch;
p->icon_get = icon_get;
p->action = action;
p->browse = browse;
p->config_page = config_page;
p->config_apply = config_apply;
return p;
}
void
evry_plugin_register(Evry_Plugin *plugin, int priority)
{
Eina_List *l;
@ -289,21 +322,21 @@ evry_plugin_register(Evry_Plugin *plugin, int priority)
/* TODO sorting, initialization, etc */
}
EAPI void
void
evry_plugin_unregister(Evry_Plugin *plugin)
{
evry_conf->plugins = eina_list_remove(evry_conf->plugins, plugin);
/* cleanup */
}
EAPI void
void
evry_action_register(Evry_Action *action)
{
evry_conf->actions = eina_list_append(evry_conf->actions, action);
/* TODO sorting, initialization, etc */
}
EAPI void
void
evry_action_unregister(Evry_Action *action)
{
evry_conf->actions = eina_list_remove(evry_conf->actions, action);
@ -320,7 +353,7 @@ _evry_cb_view_sort(const void *data1, const void *data2)
}
EAPI void
void
evry_view_register(Evry_View *view, int priority)
{
view->priority = priority;
@ -332,7 +365,7 @@ evry_view_register(Evry_View *view, int priority)
_evry_cb_view_sort);
}
EAPI void
void
evry_view_unregister(Evry_View *view)
{
evry_conf->views = eina_list_remove(evry_conf->views, view);

View File

@ -470,7 +470,7 @@ evry_fuzzy_match(const char *str, const char *match)
next = str;
m = match;
for (; (m_cnt < m_num) && (*next != 0);)
while((m_cnt < m_num) && (*next != 0))
{
/* reset match */
if (m_cnt == 0) m = match;
@ -563,15 +563,14 @@ evry_fuzzy_match(const char *str, const char *match)
for (m_cnt = 0; m_cnt < m_num; m_cnt++)
{
if (m_min[m_cnt] >= MAX_FUZZ)
sum += m_min[m_cnt];
if (sum >= MAX_FUZZ)
{
sum = 0;
break;
}
sum += m_min[m_cnt];
}
/* if (sum)
* printf("min %d >> %s - %s\n", sum, match, str); */
return sum;
}
@ -1000,17 +999,17 @@ _evry_selector_actions_get(Evry_Item *it)
EINA_LIST_FOREACH(sel->plugins, l, p)
{
if (strcmp(p->type_in, it->plugin->type_out) &&
(p != action_selector) &&
(p != sel->aggregator)) continue;
if (p->begin)
if ((p == action_selector) || (p == sel->aggregator) ||
(strstr(p->type_in, it->plugin->type_out)))
{
if (p->begin(p, it))
if (p->begin)
{
if (p->begin(p, it))
plugins = eina_list_append(plugins, p);
}
else
plugins = eina_list_append(plugins, p);
}
else
plugins = eina_list_append(plugins, p);
}
if (!plugins) return 0;
@ -1170,7 +1169,7 @@ _evry_selectors_switch(void)
if (update_timer)
{
if ((s && !s->plugin->async_query) &&
if ((s && !s->plugin->async_fetch) &&
((selector == selectors[0]) ||
(selector == selectors[1])))
{
@ -1436,7 +1435,7 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
if (update_timer)
{
if ((selector->state->plugin) &&
(!selector->state->plugin->async_query))
(!selector->state->plugin->async_fetch))
{
_evry_matches_update(selector);
_evry_selector_update(selector);
@ -1570,11 +1569,16 @@ _evry_matches_update(Evry_Selector *sel)
Evry_State *s = sel->state;
Evry_Plugin *p;
Eina_List *l;
Eina_Bool has_items = EINA_FALSE;
const char *input;
EINA_LIST_FREE(s->cur_plugins, p);
if (s->input)
if (strlen(s->input) > 0)
input = s->input;
else
input = NULL;
if (input)
{
EINA_LIST_FOREACH(s->plugins, l, p)
{
@ -1598,23 +1602,13 @@ _evry_matches_update(Evry_Selector *sel)
if (p->trigger) continue;
if (p == sel->aggregator) continue;
if (strlen(s->input) == 0)
{
if (!p->need_query)
has_items = p->fetch(p, NULL);
}
else
{
has_items = p->fetch(p, s->input);
}
if (has_items || sel->states->next)
if (p->fetch(p, input) || sel->states->next)
s->cur_plugins = eina_list_append(s->cur_plugins, p);
}
if (eina_list_count(s->cur_plugins) > 1)
{
sel->aggregator->fetch(sel->aggregator, s->input);
sel->aggregator->fetch(sel->aggregator, input);
s->cur_plugins = eina_list_prepend(s->cur_plugins, sel->aggregator);
if (s->plugin_auto_selected)
_evry_select_plugin(s, NULL);
@ -1923,16 +1917,16 @@ _evry_fuzzy_sort_cb(const void *data1, const void *data2)
static int
_evry_plug_actions_init(void)
{
Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
p->name = "Select Action";
p->type = type_action;
p->type_in = "ANY";
p->type_out = "NONE";
p->begin = &_evry_plug_actions_begin;
p->cleanup = &_evry_plug_actions_cleanup;
p->fetch = &_evry_plug_actions_fetch;
p->icon_get = &_evry_plug_actions_item_icon_get;
Evry_Plugin *p;
p = evry_plugin_new("Select Action", type_action, "", "", 0, NULL,
_evry_plug_actions_begin,
_evry_plug_actions_cleanup,
_evry_plug_actions_fetch,
NULL, NULL,
_evry_plug_actions_item_icon_get,
NULL, NULL);
action_selector = p;
evry_plugin_register(p, 2);
@ -2046,15 +2040,17 @@ _evry_plug_actions_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it,
static Evry_Plugin *
_evry_plug_aggregator_new(void)
{
Evry_Plugin *p;
Plugin_Config *pc;
Evry_Plugin *p = E_NEW(Evry_Plugin, 1);
p->name = "All";
p->type_in = "NONE";
p->type_out = "NONE";
p->cleanup = &_evry_plug_aggregator_cleanup;
p->fetch = &_evry_plug_aggregator_fetch;
p->action = &_evry_plug_aggregator_action;
p->icon_get = &_evry_plug_aggregator_item_icon_get;
p = evry_plugin_new("All", 0, "", "", 0, NULL,
NULL,
_evry_plug_aggregator_cleanup,
_evry_plug_aggregator_fetch,
_evry_plug_aggregator_action,
NULL,
_evry_plug_aggregator_item_icon_get,
NULL, NULL);
pc = E_NEW(Plugin_Config, 1);
pc->name = eina_stringshare_add(p->name);
@ -2092,7 +2088,7 @@ _evry_plug_aggregator_fetch(Evry_Plugin *p, const char *input)
cnt += eina_list_count(plugin->items);
if (input[0])
if (input)
{
EINA_LIST_FOREACH(s->cur_plugins, l, plugin)
{
@ -2111,7 +2107,7 @@ _evry_plug_aggregator_fetch(Evry_Plugin *p, const char *input)
}
}
if (!input[0] || eina_list_count(items) < 20)
if (!input || eina_list_count(items) < 20)
{
EINA_LIST_FOREACH(s->cur_plugins, l, plugin)
{
@ -2131,7 +2127,7 @@ _evry_plug_aggregator_fetch(Evry_Plugin *p, const char *input)
eina_list_free(items);
if (input[0])
if (input)
p->items = eina_list_sort(p->items, eina_list_count(p->items), _evry_fuzzy_sort_cb);
return 1;

View File

@ -657,7 +657,6 @@ _init(void)
p1->type = type_subject;
p1->type_in = "NONE";
p1->type_out = "APPLICATION";
p1->need_query = 0;
p1->begin = &_begin;
p1->fetch = &_fetch;
p1->cleanup = &_cleanup;
@ -669,7 +668,6 @@ _init(void)
p2->type = type_action;
p2->type_in = "FILE";
p2->type_out = "NONE";
p2->need_query = 0;
p2->begin = &_begin;
p2->fetch = &_fetch;
p2->action = &_open_with_action;

View File

@ -337,8 +337,6 @@ _init(void)
p->base.type_out = "TEXT";
p->base.icon = "accessories-dictionary";
p->base.trigger = TRIGGER;
p->base.need_query = 0;
p->base.async_query = 1;
p->base.begin = _begin;
p->base.fetch = _fetch;
p->base.cleanup = _cleanup;

View File

@ -185,7 +185,6 @@ _init(void)
p->type = type_subject;
p->type_in = "NONE";
p->type_out = "BORDER";
p->need_query = 0;
p->fetch = &_fetch;
p->cleanup = &_cleanup;
p->icon_get = &_item_icon_get;

View File

@ -218,7 +218,6 @@ _init(void)
p->type = type_action;
p->type_in = "BORDER";
p->type_out = "NONE";
p->need_query = 0;
p->begin = &_begin;
p->fetch = &_fetch;
p->action = &_action;

View File

@ -195,8 +195,6 @@ _init(void)
p1->type_out = "TEXT";
p1->trigger = "=";
p1->icon = "accessories-calculator";
p1->need_query = 0;
p1->async_query = 1;
p1->begin = &_begin;
p1->fetch = &_fetch;
p1->action = &_action;

View File

@ -46,29 +46,31 @@ _item_fill(Evry_Item *it)
{
it->mime = eina_stringshare_add("x-directory/normal");
it->browseable = EINA_TRUE;
return;
}
/* else if ((ext = strrchr(it->label, '.')))
/* if ((ext = strrchr(it->label, '.')))
* {
* if (!strcmp(ext, ".desktop") || !strcmp(ext, ".directory"))
* {
* Efreet_Desktop *desktop;
*
* desktop = efreet_desktop_new(it->uri);
* if (!desktop) return;
* eina_stringshare_del(it->label);
* it->label = eina_stringshare_add(desktop->name);
* it->mime = eina_stringshare_add("None");
* efreet_desktop_free(desktop);
* return;
* }
* } */
else if ((mime = efreet_mime_type_get(it->uri)))
if ((mime = efreet_mime_type_get(it->uri)))
{
it->mime = eina_stringshare_add(mime);
return;
}
else
{
it->mime = eina_stringshare_add("None");
}
it->mime = eina_stringshare_add("None");
}
static int
@ -341,7 +343,7 @@ _fetch(Evry_Plugin *p, const char *input)
}
static Evas_Object *
_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{
Evas_Object *o = NULL;
char *icon_path;
@ -410,36 +412,21 @@ _open_folder_action(Evry_Action *act __UNUSED__, const Evry_Item *it, const Evry
static Eina_Bool
_init(void)
{
p1 = E_NEW(Evry_Plugin, 1);
p1->name = "Files";
p1->type = type_subject;
p1->type_in = "NONE|FILE";
p1->type_out = "FILE";
p1->browseable = EINA_TRUE;
p1->begin = &_begin;
p1->browse = &_browse;
p1->fetch = &_fetch;
p1->cleanup = &_cleanup;
p1->icon_get = &_item_icon_get;
evry_plugin_register(p1, 3);
p1 = evry_plugin_new("Files", type_subject, "FILE", "FILE", 0, NULL,
_begin, _cleanup, _fetch, NULL, _browse, _icon_get,
NULL, NULL);
p2 = E_NEW(Evry_Plugin, 1);
p2->name = "Files";
p2->type = type_object;
p2->type_in = "NONE|FILE";
p2->type_out = "FILE";
p2->browseable = EINA_TRUE;
p2->begin = &_begin;
p2->browse = &_browse;
p2->fetch = &_fetch;
p2->cleanup = &_cleanup;
p2->icon_get = &_item_icon_get;
p2 = evry_plugin_new("Files", type_object, "FILE", "FILE", 0, NULL,
_begin, _cleanup, _fetch, NULL, _browse, _icon_get,
NULL, NULL);
evry_plugin_register(p1, 3);
evry_plugin_register(p2, 1);
act = E_NEW(Evry_Action, 1);
act->name = "Open Folder (EFM)";
act->is_default = EINA_TRUE;
act->type_in1 = "FILE";
act->type_in1 = eina_stringshare_add("FILE");
act->action = &_open_folder_action;
act->check_item = &_open_folder_check;
act->icon = "folder-open";

View File

@ -5,13 +5,14 @@ static Evry_View *view = NULL;
static Evas_Object *o_thumb[5];
static Evas_Object *o_main = NULL;
static Eina_List *items = NULL;
static const char *view_types;
static int
_check_item(const Evry_Item *it)
{
if (!it) return 0;
if (strcmp(it->plugin->type_out, "FILE")) return 0;
if (it->plugin->type_out != view_types) return 0;
if (!it->uri || !it->mime) return 0;
@ -155,9 +156,6 @@ _find_first(const Evry_State *s)
Eina_List *l;
Evry_Item *it, *found = NULL;
if (_check_item(s->sel_item))
return s->sel_item;
eina_list_free(items);
items = NULL;
@ -168,6 +166,9 @@ _find_first(const Evry_State *s)
items = eina_list_append(items, it);
}
if (_check_item(s->sel_item))
return s->sel_item;
return found;
}
@ -224,12 +225,15 @@ _init(void)
view->cleanup = &_cleanup;
evry_view_register(view, 2);
view_types = eina_stringshare_add("FILE");
return EINA_TRUE;
}
static void
_shutdown(void)
{
eina_stringshare_del(view_types);
evry_view_unregister(view);
E_FREE(view);
}

View File

@ -325,7 +325,7 @@ _fetch(Evry_Plugin *p, const char *input)
}
static Evas_Object *
_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{
char *icon_path;
Evas_Object *o = NULL;
@ -359,17 +359,10 @@ _plugin_new(const char *name, int type, char *service, int max_hits, int begin)
Evry_Plugin *p;
Inst *inst;
p = E_NEW(Evry_Plugin, 1);
p->name = name;
p->type = type;
p->type_in = "NONE";
p->type_out = "FILE";
p->async_query = 1;
if (begin)
p->begin = &_begin;
p->fetch = &_fetch;
p->cleanup = &_cleanup;
p->icon_get = &_item_icon_get;
p = evry_plugin_new(name, type, "", "FILE", 0, NULL,
(begin ? _begin : NULL), _cleanup, _fetch,
NULL, NULL, _icon_get, NULL, NULL);
inst = E_NEW(Inst, 1);
inst->condition = "";
inst->service = service;