fix for showing plugins as icon in aggregator

- make plugin instances be proper evry items so that they are ref counted like everything else.
  now plugin->begin MUST always return a new instance, never the base class


SVN revision: 57206
This commit is contained in:
Hannes Janetzek 2011-02-21 07:30:55 +00:00
parent 09d6cde244
commit 259e268f3c
6 changed files with 91 additions and 58 deletions

View File

@ -20,8 +20,6 @@ struct _Plugin
const char *lang;
const char *input;
Eina_Bool is_first;
unsigned int instances;
};
struct _Module_Config
@ -53,6 +51,7 @@ static E_Config_DD *_conf_edd = NULL;
static const char TRIGGER[] = "s ";
static const char LANG_MODIFIER[] = "lang=";
static int instances = 0;
static Eina_Bool
_exe_restart(Plugin *p)
@ -256,11 +255,14 @@ _cb_del(void *data, int type __UNUSED__, void *event)
static Evry_Plugin *
_begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
{
GET_PLUGIN(p, plugin);
p->instances++;
Plugin *p;
if (p->instances > 1)
if (instances > 1)
return NULL;
EVRY_PLUGIN_INSTANCE(p, plugin);
instances++;
return EVRY_PLUGIN(p);
}
@ -358,30 +360,24 @@ _finish(Evry_Plugin *plugin)
EVRY_PLUGIN_ITEMS_FREE(p);
p->instances--;
instances--;
if (p->instances > 0)
return;
if (p->handler.data)
{
ecore_event_handler_del(p->handler.data);
p->handler.data = NULL;
}
ecore_event_handler_del(p->handler.data);
if (p->handler.del)
{
ecore_event_handler_del(p->handler.del);
p->handler.del = NULL;
}
ecore_event_handler_del(p->handler.del);
if (p->exe)
{
ecore_exe_quit(p->exe);
ecore_exe_free(p->exe);
p->exe = NULL;
}
IF_RELEASE(p->lang);
IF_RELEASE(p->input);
E_FREE(p);
}
static int
@ -395,7 +391,7 @@ _plugins_init(const Evry_API *_api)
if (!evry->api_version_check(EVRY_API_VERSION))
return EINA_FALSE;
_plug = EVRY_PLUGIN_NEW(Plugin, N_("Spell Checker"),
_plug = EVRY_PLUGIN_NEW(Evry_Plugin, N_("Spell Checker"),
_module_icon,
EVRY_TYPE_TEXT,
_begin, _finish, _fetch, NULL);

View File

@ -3,6 +3,13 @@
#include "evry_api.h"
// TODO - show error when input not parseable
typedef struct _Plugin Plugin;
struct _Plugin
{
Evry_Plugin base;
};
static Eina_Bool _cb_data(void *data, int type, void *event);
static Eina_Bool _cb_error(void *data, int type, void *event);
static Eina_Bool _cb_del(void *data, int type, void *event);
@ -21,13 +28,16 @@ static char _module_icon[] = "accessories-calculator";
static Evry_Item *cur_item = NULL;
static Evry_Plugin *
_begin(Evry_Plugin *p, const Evry_Item *item __UNUSED__)
_begin(Evry_Plugin *plugin, const Evry_Item *item __UNUSED__)
{
Evry_Item *it;
Plugin *p;
if (active)
return NULL;
EVRY_PLUGIN_INSTANCE(p, plugin)
if (history)
{
const char *result;
@ -35,22 +45,22 @@ _begin(Evry_Plugin *p, const Evry_Item *item __UNUSED__)
EINA_LIST_FREE(history, result)
{
it = EVRY_ITEM_NEW(Evry_Item, p, result, NULL, NULL);
it->context = eina_stringshare_ref(p->name);
p->items = eina_list_prepend(p->items, it);
it->context = eina_stringshare_ref(p->base.name);
p->base.items = eina_list_prepend(p->base.items, it);
eina_stringshare_del(result);
}
}
it = EVRY_ITEM_NEW(Evry_Item, p, "0", NULL, NULL);
it->context = eina_stringshare_ref(p->name);
it->context = eina_stringshare_ref(p->base.name);
cur_item = it;
active = EINA_TRUE;
return p;
return EVRY_PLUGIN(p);
}
static int
_run_bc(Evry_Plugin *p)
_run_bc(Plugin *p)
{
handlers = eina_list_append
(handlers, ecore_event_handler_add
@ -73,22 +83,17 @@ _run_bc(Evry_Plugin *p)
}
static void
_finish(Evry_Plugin *p)
_finish(Evry_Plugin *plugin)
{
GET_PLUGIN(p, plugin);
Ecore_Event_Handler *h;
Evry_Item *it;
int items = 10;
int items = 0;
if (p->items)
EINA_LIST_FREE(p->base.items, it)
{
EVRY_ITEM_FREE(p->items->data);
p->items = eina_list_remove_list(p->items, p->items);
}
EINA_LIST_FREE(p->items, it)
{
if (items-- > 1)
history = eina_list_prepend(history, eina_stringshare_add(it->label));
if ((items++ > 1) && (items < 10))
history = eina_list_prepend(history, eina_stringshare_add(it->label));
EVRY_ITEM_FREE(it);
}
@ -103,6 +108,8 @@ _finish(Evry_Plugin *p)
exe = NULL;
}
active = EINA_FALSE;
E_FREE(p);
}
static Eina_Bool
@ -149,8 +156,10 @@ _cb_action_performed(__UNUSED__ void *data, __UNUSED__ int type, void *event)
}
static int
_fetch(Evry_Plugin *p, const char *input)
_fetch(Evry_Plugin *plugin, const char *input)
{
GET_PLUGIN(p, plugin);
char buf[1024];
if (!input) return 0;
@ -172,7 +181,7 @@ _fetch(Evry_Plugin *p, const char *input)
error = 0;
}
return !!(p->items);
return !!(p->base.items);
}
static Eina_Bool

View File

@ -386,7 +386,8 @@ EAPI E_Config_Dialog *evry_collection_conf_dialog(E_Container *con, const char *
EAPI extern E_Module_Api e_modapi;
//#define CHECK_REFS
#define CHECK_REFS 0
#define CHECK_TIME 0
#ifdef CHECK_REFS
extern Eina_List *_refd;

View File

@ -11,7 +11,7 @@
#define MATCH_LAG 0.15
#define INITIAL_MATCH_LAG 0.3
#ifdef CHECK_TIME
#if CHECK_TIME || CHECK_REFS
#undef DBG
#define DBG(...) ERR(__VA_ARGS__)
#else
@ -1501,7 +1501,7 @@ _evry_state_pop(Evry_Selector *sel, int immediate)
p->state = prev;
continue;
}
p->finish(p);
EVRY_ITEM_FREE(p);
}
if (!s->delete_me)
@ -2688,7 +2688,9 @@ _evry_matches_update(Evry_Selector *sel, int async)
s->changed = 1;
s->request++;
#ifdef CHECK_TIME
DBG("matches update %f", ecore_time_get() - _evry_time);
#endif
if (sel->update_timer)
{
@ -2801,8 +2803,9 @@ _evry_matches_update(Evry_Selector *sel, int async)
if (p->fetch(p, input))
{
#ifdef CHECK_TIME
DBG("fetch %s %f", p->name, ecore_time_get() - _evry_time);
#endif
s->cur_plugins = eina_list_append(s->cur_plugins, p);
continue;
}

View File

@ -232,11 +232,20 @@ struct _Evry_Event_Action_Performed
#define EVRY_PLUGIN_ITEM_APPEND(_p, _item) \
EVRY_PLUGIN(_p)->items = eina_list_append(EVRY_PLUGIN(_p)->items, EVRY_ITEM(_item))
#define EVRY_PLUGIN_INSTANCE(_p, _plugin) { \
_p = E_NEW(Plugin, 1); \
_p->base = *_plugin; \
_p->base.items = NULL; \
_p->base.base.plugin = (Evry_Plugin*)_p; } \
typedef void (*Evry_Item_Free_Cb) (Evry_Item *it);
#define EVRY_PLUGIN_INSTANCE(_p, _plugin) { \
_p = E_NEW(Plugin, 1); \
_p->base = *_plugin; \
_p->base.items = NULL; \
_p->base.base.ref = 1; \
_p->base.base.free = (Evry_Item_Free_Cb)_p->base.finish; \
_p->base.base.label = eina_stringshare_add(_plugin->base.label); \
_p->base.base.detail = eina_stringshare_add(_plugin->base.detail); \
_p->base.base.icon = eina_stringshare_add(_plugin->base.icon); \
_p->base.base.context = eina_stringshare_add(_plugin->base.context); \
_p->base.base.id = eina_stringshare_add(_plugin->base.id); \
_p->base.base.plugin = (Evry_Plugin*)_p; } \
#define EVRY_PLUGIN_ITEMS_CLEAR(_p) { \
Evry_Item *it; \

View File

@ -1,36 +1,51 @@
#include "e_mod_main.h"
static Evry_Plugin *p1;
static Evry_Plugin *p2;
typedef struct _Plugin Plugin;
struct _Plugin
{
Evry_Plugin base;
};
static Evry_Plugin *p1, *p2;
static Evry_Plugin *
_begin(Evry_Plugin *p, const Evry_Item *it __UNUSED__)
_begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
{
return p;
Plugin *p;
EVRY_PLUGIN_INSTANCE(p, plugin);
return EVRY_PLUGIN(p);
}
static void
_finish(Evry_Plugin *p)
_finish(Evry_Plugin *plugin)
{
GET_PLUGIN(p, plugin);
EVRY_PLUGIN_ITEMS_FREE(p);
E_FREE(p);
}
static int
_fetch(Evry_Plugin *p, const char *input)
_fetch(Evry_Plugin *plugin, const char *input)
{
Evry_Item *it;
GET_PLUGIN(p, plugin);
if (input)
{
if (!p->items)
if (!p->base.items)
{
it = evry_item_new(NULL, p, input, NULL, NULL);
it = evry_item_new(NULL, EVRY_PLUGIN(p), input, NULL, NULL);
it->fuzzy_match = 999;
EVRY_PLUGIN_ITEM_APPEND(p, it);
}
else
{
it = p->items->data;
it = p->base.items->data;
EVRY_ITEM_LABEL_SET(it, input);
evry_item_changed(it, 0, 0);
}