'everything' module: use macros for common stuff

- changed private data to inheritance of Evry_Item
  for Evry_Item_File and _App


SVN revision: 41932
This commit is contained in:
Hannes Janetzek 2009-08-23 03:12:05 +00:00
parent ad84ddfb3e
commit aadf50f851
15 changed files with 551 additions and 474 deletions

View File

@ -10,12 +10,43 @@
typedef struct _Evry_Plugin Evry_Plugin; typedef struct _Evry_Plugin Evry_Plugin;
typedef struct _Evry_Item Evry_Item; typedef struct _Evry_Item Evry_Item;
typedef struct _Evry_Item_App Evry_Item_App;
typedef struct _Evry_Item_File Evry_Item_File;
typedef struct _Evry_Action Evry_Action; typedef struct _Evry_Action Evry_Action;
typedef struct _Evry_State Evry_State; typedef struct _Evry_State Evry_State;
typedef struct _Evry_View Evry_View; typedef struct _Evry_View Evry_View;
typedef struct _Evry_App Evry_App;
typedef struct _Plugin_Config Plugin_Config; typedef struct _Plugin_Config Plugin_Config;
#define EVRY_ITEM(_item) ((Evry_Item *)_item)
#define EVRY_PLUGIN(_plugin) ((Evry_Plugin *) _plugin)
#define EVRY_VIEW(_view) ((Evry_View *) _view)
#define ITEM_FILE(_file, _item) Evry_Item_File *_file = (Evry_Item_File *) _item
#define ITEM_APP(_app, _item) Evry_Item_App *_app = (Evry_Item_App *) _item
#define PLUGIN(_p, _plugin) Plugin *_p = (Plugin*) _plugin
#define EVRY_PLUGIN_ITEMS_CLEAR(_p) \
if (EVRY_PLUGIN(_p)->items) \
eina_list_free(EVRY_PLUGIN(_p)->items); \
EVRY_PLUGIN(_p)->items = NULL;
#define EVRY_PLUGIN_ITEMS_FREE(_p) \
Evry_Item *evryitem; \
EINA_LIST_FREE(EVRY_PLUGIN(_p)->items, evryitem) \
evry_item_free(evryitem);
#define EVRY_PLUGIN_ITEMS_SORT(_p, _sortcb) \
EVRY_PLUGIN(_p)->items = eina_list_sort \
(EVRY_PLUGIN(_p)->items, \
eina_list_count(EVRY_PLUGIN(_p)->items), _sortcb); \
#define EVRY_PLUGIN_ITEM_APPEND(_p, _item) \
EVRY_PLUGIN(_p)->items = \
eina_list_append(EVRY_PLUGIN(_p)->items, EVRY_ITEM(_item)) \
#define EVRY_PLUGIN_FREE(_p) \
evry_plugin_free(EVRY_PLUGIN(_p), 0); \
E_FREE(_p);
struct _Plugin_Config struct _Plugin_Config
{ {
const char *name; const char *name;
@ -36,16 +67,14 @@ struct _Evry_Item
{ {
/* label to show for this item */ /* label to show for this item */
const char *label; const char *label;
const char *icon;
const char *uri;
const char *mime;
/* item can be browsed, e.g. folders */ /* item can be browsed, e.g. folders */
Eina_Bool browseable; Eina_Bool browseable;
/* these are only for internally use by plugins */ /* these are only for internally use by plugins */
/* used e.g. as pointer for item data (Efreet_Desktop) */ /* used e.g. as pointer for item data (Efreet_Desktop) */
void *data[4]; void *data;
/* priority hints for sorting */ /* priority hints for sorting */
int priority; int priority;
@ -61,6 +90,21 @@ struct _Evry_Item
void (*free) (Evry_Item *item); void (*free) (Evry_Item *item);
}; };
struct _Evry_Item_App
{
Evry_Item base;
const char *file;
Efreet_Desktop *desktop;
};
struct _Evry_Item_File
{
Evry_Item base;
const char *uri;
const char *mime;
};
struct _Evry_Plugin struct _Evry_Plugin
{ {
const char *name; const char *name;
@ -170,11 +214,6 @@ struct _Evry_Action
Evas_Object *o_icon; Evas_Object *o_icon;
}; };
struct _Evry_App
{
const char *file;
Efreet_Desktop *desktop;
};
EAPI void evry_plugin_register(Evry_Plugin *p, int priority); EAPI void evry_plugin_register(Evry_Plugin *p, int priority);
EAPI void evry_plugin_unregister(Evry_Plugin *p); EAPI void evry_plugin_unregister(Evry_Plugin *p);
@ -189,7 +228,7 @@ EAPI int evry_list_win_show(void);
EAPI void evry_list_win_hide(void); EAPI void evry_list_win_hide(void);
EAPI Evry_Item *evry_item_new(Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *item)); EAPI Evry_Item *evry_item_new(Evry_Item *base, Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *item));
EAPI void evry_item_free(Evry_Item *it); EAPI void evry_item_free(Evry_Item *it);
EAPI void evry_item_ref(Evry_Item *it); EAPI void evry_item_ref(Evry_Item *it);
@ -200,6 +239,7 @@ EAPI Evas_Object *evry_icon_mime_get(const char *mime, Evas *e);
EAPI Evas_Object *evry_icon_theme_get(const char *icon, Evas *e); EAPI Evas_Object *evry_icon_theme_get(const char *icon, Evas *e);
EAPI int evry_fuzzy_match(const char *str, const char *match); EAPI int evry_fuzzy_match(const char *str, const char *match);
EAPI Eina_List *evry_fuzzy_match_sort(Eina_List *items);
EAPI Evry_Plugin *evry_plugin_new(Evry_Plugin *base, const char *name, int type, EAPI Evry_Plugin *evry_plugin_new(Evry_Plugin *base, const char *name, int type,
const char *type_in, const char *type_out, const char *type_in, const char *type_out,
@ -225,3 +265,4 @@ EAPI Evry_Action *evry_action_new(const char *name, const char *type_in1,
Evas_Object *(*icon_get) (Evry_Action *act, Evas *e)); Evas_Object *(*icon_get) (Evry_Action *act, Evas *e));
EAPI void evry_action_free(Evry_Action *act); EAPI void evry_action_free(Evry_Action *act);

View File

@ -248,12 +248,18 @@ evry_clear_input(void)
/* static int item_cnt = 0; */ /* static int item_cnt = 0; */
EAPI Evry_Item * EAPI Evry_Item *
evry_item_new(Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *item)) evry_item_new(Evry_Item *base, Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *item))
{ {
Evry_Item *it; Evry_Item *it;
if (base)
{
it = base;
}
else
{
it = E_NEW(Evry_Item, 1); it = E_NEW(Evry_Item, 1);
if (!it) return NULL; if (!it) return NULL;
}
it->plugin = p; it->plugin = p;
if (label) it->label = eina_stringshare_add(label); if (label) it->label = eina_stringshare_add(label);
@ -280,15 +286,16 @@ evry_item_free(Evry_Item *it)
* it->label); * it->label);
* item_cnt--; */ * item_cnt--; */
if (it->free) it->free(it);
if (it->label) eina_stringshare_del(it->label); if (it->label) eina_stringshare_del(it->label);
if (it->uri) eina_stringshare_del(it->uri); /* if (it->uri) eina_stringshare_del(it->uri);
if (it->mime) eina_stringshare_del(it->mime); * if (it->mime) eina_stringshare_del(it->mime); */
if (it->o_bg) evas_object_del(it->o_bg); if (it->o_bg) evas_object_del(it->o_bg);
if (it->o_icon) evas_object_del(it->o_icon); if (it->o_icon) evas_object_del(it->o_icon);
if (it->free)
it->free(it);
else
E_FREE(it); E_FREE(it);
} }
@ -553,6 +560,35 @@ evry_fuzzy_match(const char *str, const char *match)
return sum; return sum;
} }
static int
_evry_fuzzy_match_sort_cb(const void *data1, const void *data2)
{
const Evry_Item *it1 = data1;
const Evry_Item *it2 = data2;
if (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);
}
return 0;
}
EAPI Eina_List *
evry_fuzzy_match_sort(Eina_List *items)
{
return eina_list_sort(items, eina_list_count(items), _evry_fuzzy_match_sort_cb);
}
/* local subsystem functions */ /* local subsystem functions */
@ -1147,7 +1183,7 @@ _evry_selectors_switch(void)
if ((s->sel_item) && if ((s->sel_item) &&
(s->sel_item->plugin == action_selector) && (s->sel_item->plugin == action_selector) &&
(act = s->sel_item->data[0]) && (act = s->sel_item->data) &&
(act->type_in2)) (act->type_in2))
{ {
_evry_selector_objects_get(act); _evry_selector_objects_get(act);
@ -1395,7 +1431,7 @@ _evry_plugin_action(Evry_Selector *sel, int finished)
if (s_action->sel_item->plugin == action_selector) if (s_action->sel_item->plugin == action_selector)
{ {
Evry_Action *act = s_action->sel_item->data[0]; Evry_Action *act = s_action->sel_item->data;
Evry_Item *it_object = NULL; Evry_Item *it_object = NULL;
if (selectors[2] == selector) if (selectors[2] == selector)
@ -1513,7 +1549,13 @@ _evry_view_toggle(Evry_State *s, const char *trigger)
} }
else else
{ {
if (s->view)
l = eina_list_data_find_list(evry_conf->views, s->view->id); l = eina_list_data_find_list(evry_conf->views, s->view->id);
else
{
v = evry_conf->views->data;
goto found;
}
if (l && l->next) if (l && l->next)
l = l->next; l = l->next;

View File

@ -97,10 +97,10 @@ _fetch(Evry_Plugin *p, const char *input)
if (!input || match) if (!input || match)
{ {
it = evry_item_new(p, act->name, NULL); it = evry_item_new(NULL, p, act->name, NULL);
it->fuzzy_match = match; it->fuzzy_match = match;
it->data[0] = act; it->data = act;
p->items = eina_list_append(p->items, it); EVRY_PLUGIN_ITEM_APPEND(p, it);
} }
} }
@ -116,7 +116,7 @@ static Evas_Object *
_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; Evas_Object *o = NULL;
Evry_Action *act = it->data[0]; Evry_Action *act = it->data;
if (!act) return NULL; if (!act) return NULL;

View File

@ -54,8 +54,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
s = p->selector->state; s = p->selector->state;
EINA_LIST_FREE(p->base.items, it) EVRY_PLUGIN_ITEMS_FREE(p);
evry_item_free(it);
EINA_LIST_FOREACH(s->cur_plugins, l, pp) EINA_LIST_FOREACH(s->cur_plugins, l, pp)
cnt += eina_list_count(pp->items); cnt += eina_list_count(pp->items);
@ -74,7 +73,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
{ {
evry_item_ref(it); evry_item_ref(it);
items = eina_list_append(items, it); items = eina_list_append(items, it);
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, it);
} }
} }
} }
@ -92,7 +91,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
evry_item_ref(it); evry_item_ref(it);
it->fuzzy_match = 0; it->fuzzy_match = 0;
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, it);
} }
} }
} }
@ -101,8 +100,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (items) eina_list_free(items); if (items) eina_list_free(items);
if (input[0]) if (input[0])
p->base.items = eina_list_sort EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
(p->base.items, eina_list_count(p->base.items), _cb_sort);
return 1; return 1;
} }
@ -119,10 +117,7 @@ _action(Evry_Plugin *plugin, const Evry_Item *it)
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Evry_Item *it; EVRY_PLUGIN_ITEMS_FREE(plugin);
EINA_LIST_FREE(plugin->items, it)
evry_item_free(it);
} }
static Evas_Object * static Evas_Object *
@ -141,25 +136,23 @@ evry_plug_aggregator_new(Evry_Selector *selector)
Plugin_Config *pc; Plugin_Config *pc;
p = E_NEW(Plugin, 1); p = E_NEW(Plugin, 1);
evry_plugin_new(&p->base, "All", 0, "", "", 0, NULL, NULL, evry_plugin_new(EVRY_PLUGIN(p), "All", 0, "", "", 0, NULL, NULL,
NULL, _cleanup, _fetch, _action, _icon_get, NULL, _cleanup, _fetch, _action, _icon_get,
NULL, NULL); NULL, NULL);
pc = E_NEW(Plugin_Config, 1); pc = E_NEW(Plugin_Config, 1);
pc->enabled = 1; pc->enabled = 1;
pc->priority = -1; pc->priority = -1;
p->base.config = pc; EVRY_PLUGIN(p)->config = pc;
p->selector = selector; p->selector = selector;
return &p->base; return EVRY_PLUGIN(p);
} }
void void
evry_plug_aggregator_free(Evry_Plugin *plugin) evry_plug_aggregator_free(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
EVRY_PLUGIN_FREE(p);
evry_plugin_free(&p->base, 0);
E_FREE(p);
} }

View File

@ -22,25 +22,28 @@ static Eina_List *exe_path = NULL;
static Evry_Plugin * static Evry_Plugin *
_begin(Evry_Plugin *plugin, const Evry_Item *it) _begin(Evry_Plugin *plugin, const Evry_Item *item)
{ {
Plugin *p = (Plugin*) plugin; /* Plugin *p = (Plugin*) plugin; */
PLUGIN(p, plugin);
const char *mime; const char *mime;
if (it) if (item)
{ {
ITEM_FILE(file, item);
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
if (!it->uri) return NULL; if (!file->uri) return NULL;
if (!it->mime) if (!file->mime)
mime = efreet_mime_type_get(it->uri); mime = efreet_mime_type_get(file->uri);
else else
mime = it->mime; mime = file->mime;
if (!mime) return NULL; if (!mime) return NULL;
p->candidate = it; p->candidate = EVRY_ITEM(file);
p->apps_mime = efreet_util_desktop_mime_list(mime); p->apps_mime = efreet_util_desktop_mime_list(mime);
desktop = e_exehist_mime_desktop_get(mime); desktop = e_exehist_mime_desktop_get(mime);
if (desktop) if (desktop)
@ -50,7 +53,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it)
} }
} }
return &p->base; return EVRY_PLUGIN(p);
} }
static void static void
@ -63,20 +66,21 @@ _list_free(Evry_Plugin *plugin)
} }
static void static void
_item_free(Evry_Item *it) _item_free(Evry_Item *item)
{ {
Evry_App *app; ITEM_APP(app, item);
app = it->data[0];
if (app->file) eina_stringshare_del(app->file); if (app->file) eina_stringshare_del(app->file);
if (app->desktop) efreet_desktop_free(app->desktop); if (app->desktop) efreet_desktop_free(app->desktop);
E_FREE(app); E_FREE(app);
} }
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
/* Plugin *p = (Plugin*) plugin; */
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
_list_free(plugin); _list_free(plugin);
@ -91,8 +95,7 @@ _cleanup(Evry_Plugin *plugin)
static int static int
_item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match) _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
{ {
Evry_Item *it; Evry_Item_App *app;
Evry_App *app;
Efreet_Desktop *d2; Efreet_Desktop *d2;
int already_refd = 0; int already_refd = 0;
@ -146,18 +149,18 @@ _item_add(Plugin *p, Efreet_Desktop *desktop, char *file, int match)
file = NULL; file = NULL;
} }
if (desktop) app = E_NEW(Evry_Item_App, 1);
it = evry_item_new(&p->base, desktop->name, _item_free);
else if (desktop)
it = evry_item_new(&p->base, file, _item_free); evry_item_new(EVRY_ITEM(app), EVRY_PLUGIN(p), desktop->name, _item_free);
else
evry_item_new(EVRY_ITEM(app), EVRY_PLUGIN(p), file, _item_free);
app = E_NEW(Evry_App, 1);
app->desktop = desktop; app->desktop = desktop;
app->file = file; app->file = file;
it->data[0] = app; EVRY_ITEM(app)->fuzzy_match = match;
it->fuzzy_match = match;
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, app);
return 1; return 1;
} }
@ -171,7 +174,7 @@ _add_desktop_list(Plugin *p, Eina_List *apps, const char *input)
EINA_LIST_FOREACH(apps, l, desktop) EINA_LIST_FOREACH(apps, l, desktop)
{ {
if (eina_list_count(p->base.items) > 199) continue; if (eina_list_count(EVRY_PLUGIN(p)->items) > 199) continue;
if (!desktop->name || !desktop->exec) continue; if (!desktop->name || !desktop->exec) continue;
char *exec = strrchr(desktop->exec, '/'); char *exec = strrchr(desktop->exec, '/');
@ -192,12 +195,11 @@ _cb_sort(const void *data1, const void *data2)
{ {
const Evry_Item *it1 = data1; const Evry_Item *it1 = data1;
const Evry_Item *it2 = data2; const Evry_Item *it2 = data2;
Evry_App *app1, *app2;
const char *e1, *e2; const char *e1, *e2;
double t1, t2; double t1, t2;
app1 = it1->data[0]; ITEM_APP(app1, it1);
app2 = it2->data[0]; ITEM_APP(app2, it2);
if (app1->desktop) if (app1->desktop)
e1 = app1->desktop->exec; e1 = app1->desktop->exec;
@ -233,19 +235,18 @@ _cb_sort(const void *data1, const void *data2)
static int static int
_fetch(Evry_Plugin *plugin, const char *input) _fetch(Evry_Plugin *plugin, const char *input)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
/* Plugin *p = (Plugin*) plugin; */
Eina_List *l; Eina_List *l;
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
char *file; char *file;
Evry_Item *it;
Evry_App *app;
p->added = eina_hash_string_small_new(NULL); p->added = eina_hash_string_small_new(NULL);
_list_free(plugin); _list_free(plugin);
/* add apps for a given mimetype */ /* add apps for a given mimetype */
if (p->base.type == type_action) if (plugin->type == type_action)
{ {
if (input) if (input)
_add_desktop_list(p, p->apps_mime, input); _add_desktop_list(p, p->apps_mime, input);
@ -321,20 +322,19 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (found) if (found)
{ {
it = evry_item_new(plugin, _("Run Command"), _item_free); Evry_Item_App *app;
app = E_NEW(Evry_App, 1); app = E_NEW(Evry_Item_App, 1);
evry_item_new(EVRY_ITEM(app), plugin, _("Run Command"), _item_free);
app->file = eina_stringshare_add(input); app->file = eina_stringshare_add(input);
it->data[0] = app; EVRY_ITEM(app)->priority = 9999;
it->priority = 9999; EVRY_PLUGIN_ITEM_APPEND(p, app);
plugin->items = eina_list_append(plugin->items, it);
snprintf(cmd, sizeof(cmd), "xterm -hold -e %s", input); snprintf(cmd, sizeof(cmd), "xterm -hold -e %s", input);
it = evry_item_new(plugin, _("Run in Terminal"), _item_free); app = E_NEW(Evry_Item_App, 1);
app = E_NEW(Evry_App, 1); evry_item_new(EVRY_ITEM(app), plugin, _("Run in Terminal"), _item_free);
app->file = eina_stringshare_add(cmd); app->file = eina_stringshare_add(cmd);
it->data[0] = app; EVRY_ITEM(app)->priority = 1000;
it->priority = 1000; EVRY_PLUGIN_ITEM_APPEND(p, app);
plugin->items = eina_list_append(plugin->items, it);
} }
} }
@ -343,6 +343,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (plugin->items) if (plugin->items)
{ {
int prio = 0; int prio = 0;
Evry_Item *it;
l = plugin->items; l = plugin->items;
plugin->items = eina_list_sort(l, eina_list_count(l), _cb_sort); plugin->items = eina_list_sort(l, eina_list_count(l), _cb_sort);
@ -358,8 +359,10 @@ _fetch(Evry_Plugin *plugin, const char *input)
static Evas_Object * static Evas_Object *
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e) _icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{ {
ITEM_APP(app, it);
Evas_Object *o = NULL; Evas_Object *o = NULL;
Evry_App *app = it->data[0];
/* Evry_App *app = it->data[0]; */
if (app->desktop) if (app->desktop)
o = e_util_desktop_icon_add(app->desktop, 64, e); o = e_util_desktop_icon_add(app->desktop, 64, e);
@ -373,7 +376,8 @@ _icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
static int static int
_exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it) _exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{ {
Evry_App *app = it->data[0]; ITEM_APP(app, it);
if (app->desktop) if (app->desktop)
return 1; return 1;
@ -384,30 +388,33 @@ _exec_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
} }
static int static int
_app_action(const Evry_Item *it_app, const Evry_Item *it_file) _app_action(const Evry_Item *it1, const Evry_Item *it2)
{ {
E_Zone *zone; E_Zone *zone;
Evry_App *app = NULL; /* Evry_App *app = NULL; */
Eina_List *files = NULL; Eina_List *files = NULL;
char *exe = NULL; char *exe = NULL;
if (!it_app) return 0; if (!it1) return 0;
/* app = it_app->data[0]; */
ITEM_APP(app, it1);
app = it_app->data[0];
if (!app) return 0; if (!app) return 0;
zone = e_util_zone_current_get(e_manager_current_get()); zone = e_util_zone_current_get(e_manager_current_get());
if (app->desktop) if (app->desktop)
{ {
if (it_file) if (it2)
{ {
ITEM_FILE(file, it2);
Eina_List *l; Eina_List *l;
char *mime; char *mime;
char *path = NULL; char *path = NULL;
int open_folder = 0; int open_folder = 0;
if (!it_file->browseable) if (!EVRY_ITEM(file)->browseable)
{ {
EINA_LIST_FOREACH(app->desktop->mime_types, l, mime) EINA_LIST_FOREACH(app->desktop->mime_types, l, mime)
{ {
@ -421,18 +428,18 @@ _app_action(const Evry_Item *it_app, const Evry_Item *it_file)
if (open_folder) if (open_folder)
{ {
path = ecore_file_dir_get(it_file->uri); path = ecore_file_dir_get(file->uri);
files = eina_list_append(files, path); files = eina_list_append(files, path);
} }
else else
{ {
files = eina_list_append(files, it_file->uri); files = eina_list_append(files, file->uri);
} }
e_exec(zone, app->desktop, NULL, files, NULL); e_exec(zone, app->desktop, NULL, files, NULL);
if (it_file && it_file->mime && !open_folder) if (file && file->mime && !open_folder)
e_exehist_mime_desktop_add(it_file->mime, app->desktop); e_exehist_mime_desktop_add(file->mime, app->desktop);
if (files) if (files)
eina_list_free(files); eina_list_free(files);
@ -445,21 +452,23 @@ _app_action(const Evry_Item *it_app, const Evry_Item *it_file)
} }
else if (app->file) else if (app->file)
{ {
if (it_file && it_file->uri) if (it2)
{ {
ITEM_FILE(file, it2);
int len; int len;
len = strlen(app->file) + strlen(it_file->uri) + 2; len = strlen(app->file) + strlen(file->uri) + 2;
exe = malloc(len); exe = malloc(len);
snprintf(exe, len, "%s %s", app->file, it_file->uri); snprintf(exe, len, "%s %s", app->file, file->uri);
}
else exe = (char *) app->file;
e_exec(zone, NULL, exe, NULL, NULL); e_exec(zone, NULL, exe, NULL, NULL);
if (it_file && it_file->uri)
free(exe); free(exe);
} }
else
{
exe = (char *) app->file;
e_exec(zone, NULL, exe, NULL, NULL);
}
}
return 1; return 1;
} }
@ -473,7 +482,8 @@ _exec_app_action(Evry_Action *act)
static int static int
_open_with_action(Evry_Plugin *plugin, const Evry_Item *it) _open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
/* Plugin *p = (Plugin*) plugin; */
if (p->candidate) if (p->candidate)
return _app_action(it, p->candidate); return _app_action(it, p->candidate);
@ -484,7 +494,8 @@ _open_with_action(Evry_Plugin *plugin, const Evry_Item *it)
static int static int
_edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it) _edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{ {
Evry_App *app = it->data[0]; ITEM_APP(app, it);
/* Evry_App *app = it->data[0]; */
if (app->desktop) if (app->desktop)
return 1; return 1;
@ -494,10 +505,9 @@ _edit_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
static int static int
_edit_app_action(Evry_Action *act) _edit_app_action(Evry_Action *act)
{ {
Evry_App *app;
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
ITEM_APP(app, act->item1);
app = act->item1->data[0];
if (app->desktop) if (app->desktop)
desktop = app->desktop; desktop = app->desktop;
else else
@ -518,7 +528,8 @@ _edit_app_action(Evry_Action *act)
static int static int
_new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it) _new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{ {
Evry_App *app = it->data[0]; ITEM_APP(app, it);
/* Evry_App *app = it->data[0]; */
if (app->desktop) if (app->desktop)
return 1; return 1;
@ -531,14 +542,15 @@ _new_app_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
static int static int
_new_app_action(Evry_Action *act) _new_app_action(Evry_Action *act)
{ {
Evry_App *app; /* Evry_App *app; */
char *name; char *name;
char buf[4096]; char buf[4096];
char *end; char *end;
Efreet_Desktop *desktop; Efreet_Desktop *desktop;
int i; int i;
app = act->item1->data[0]; ITEM_APP(app, act->item1);
/* app = act->item1->data[0]; */
if (app->desktop) if (app->desktop)
name = strdup(app->desktop->name); name = strdup(app->desktop->name);
@ -587,7 +599,7 @@ _new_app_action(Evry_Action *act)
static int static int
_exec_border_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it) _exec_border_check_item(Evry_Action *act __UNUSED__, const Evry_Item *it)
{ {
E_Border *bd = it->data[0]; E_Border *bd = it->data;
E_OBJECT_CHECK_RETURN(bd, 0); E_OBJECT_CHECK_RETURN(bd, 0);
E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, 0); E_OBJECT_TYPE_CHECK_RETURN(bd, E_BORDER_TYPE, 0);
@ -610,14 +622,15 @@ _exec_border_action(Evry_Action *act)
static int static int
_exec_border_intercept(Evry_Action *act) _exec_border_intercept(Evry_Action *act)
{ {
Evry_Item *it = E_NEW(Evry_Item, 1); /* Evry_Item *it = E_NEW(Evry_Item, 1); */
Evry_App *app = E_NEW(Evry_App, 1); Evry_Item_App *app = E_NEW(Evry_Item_App, 1);
E_Border *bd = act->item1->data[0]; E_Border *bd = act->item1->data;
app->desktop = bd->desktop; app->desktop = bd->desktop;
it->data[0] = app; /* it->data[0] = app; */
act->item1 = it; /* act->item1 = it; */
act->item1 = EVRY_ITEM(app);
return 1; return 1;
} }
@ -626,11 +639,12 @@ _exec_border_intercept(Evry_Action *act)
static void static void
_exec_border_cleanup(Evry_Action *act) _exec_border_cleanup(Evry_Action *act)
{ {
Evry_Item *it = (Evry_Item*) act->item1; /* Evry_Item *it = (Evry_Item*) act->item1;
Evry_App *app = it->data[0]; * Evry_App *app = it->data[0]; */
ITEM_APP(app, act->item1);
E_FREE(app); E_FREE(app);
E_FREE(it); /* E_FREE(it); */
} }
@ -640,16 +654,16 @@ _init(void)
char *path, *p, *last; char *path, *p, *last;
p1 = E_NEW(Plugin, 1); p1 = E_NEW(Plugin, 1);
evry_plugin_new(&p1->base, "Applications", type_subject, "", "APPLICATION", 0, NULL, NULL, evry_plugin_new(EVRY_PLUGIN(p1), "Applications", type_subject, "", "APPLICATION", 0, NULL, NULL,
_begin, _cleanup, _fetch, NULL, _icon_get, NULL, NULL); _begin, _cleanup, _fetch, NULL, _icon_get, NULL, NULL);
p2 = E_NEW(Plugin, 1); p2 = E_NEW(Plugin, 1);
evry_plugin_new(&p2->base, "Open With...", type_action, "FILE", "", 0, NULL, NULL, evry_plugin_new(EVRY_PLUGIN(p2), "Open With...", type_action, "FILE", "", 0, NULL, NULL,
_begin, _cleanup, _fetch, _open_with_action, _begin, _cleanup, _fetch, _open_with_action,
_icon_get, NULL, NULL); _icon_get, NULL, NULL);
evry_plugin_register(&p1->base, 1); evry_plugin_register(EVRY_PLUGIN(p1), 1);
evry_plugin_register(&p2->base, 3); evry_plugin_register(EVRY_PLUGIN(p2), 3);
act = evry_action_new("Launch", "APPLICATION", NULL, NULL, act = evry_action_new("Launch", "APPLICATION", NULL, NULL,
"everything-launch", "everything-launch",
@ -710,10 +724,8 @@ _shutdown(void)
{ {
char *str; char *str;
evry_plugin_free(&p1->base, 0); EVRY_PLUGIN_FREE(p1);
evry_plugin_free(&p2->base, 0); EVRY_PLUGIN_FREE(p2);
E_FREE(p1);
E_FREE(p2);
evry_action_free(act); evry_action_free(act);
evry_action_free(act1); evry_action_free(act1);

View File

@ -77,19 +77,20 @@ _space_find(const char *line)
} }
static void static void
_item_add(Evry_Plugin *p, const char *word, int word_size, int prio) _item_add(Plugin *p, const char *word, int word_size, int prio)
{ {
Evry_Item *it; Evry_Item *it;
it = evry_item_new(p, NULL, NULL); it = evry_item_new(NULL, EVRY_PLUGIN(p), NULL, NULL);
if (!it) return; if (!it) return;
it->priority = prio; it->priority = prio;
it->label = eina_stringshare_add_length(word, word_size); it->label = eina_stringshare_add_length(word, word_size);
p->items = eina_list_append(p->items, it);
EVRY_PLUGIN_ITEM_APPEND(p, it);
} }
static void static void
_suggestions_add(Evry_Plugin *p, const char *line) _suggestions_add(Plugin *p, const char *line)
{ {
const char *s; const char *s;
@ -123,18 +124,15 @@ _suggestions_add(Evry_Plugin *p, const char *line)
} }
static void static void
_clear_list(Evry_Plugin *plugin) _clear_list(Plugin *p)
{ {
Evry_Item *it;
EINA_LIST_FREE(plugin->items, it)
evry_item_free(it);
} }
static int static int
_cb_data(void *data, int type __UNUSED__, void *event) _cb_data(void *data, int type __UNUSED__, void *event)
{ {
Plugin *p = data; PLUGIN(p, data);
Evry_Plugin *plugin = &p->base;
Ecore_Exe_Event_Data *e = event; Ecore_Exe_Event_Data *e = event;
Ecore_Exe_Event_Data_Line *l; Ecore_Exe_Event_Data_Line *l;
const char *word; const char *word;
@ -142,7 +140,7 @@ _cb_data(void *data, int type __UNUSED__, void *event)
if (e->exe != p->exe) if (e->exe != p->exe)
return 1; return 1;
_clear_list(plugin); EVRY_PLUGIN_ITEMS_FREE(p);
word = p->input; word = p->input;
for (l = e->lines; l && l->line; l++) for (l = e->lines; l && l->line; l++)
@ -181,12 +179,12 @@ _cb_data(void *data, int type __UNUSED__, void *event)
word = _space_skip(word_end + 1); word = _space_skip(word_end + 1);
} }
if (plugin->items) if (EVRY_PLUGIN(p)->items)
{ {
evry_list_win_show(); evry_list_win_show();
} }
evry_plugin_async_update(plugin, EVRY_ASYNC_UPDATE_ADD); evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD);
return 1; return 1;
} }
@ -207,7 +205,7 @@ _cb_del(void *data, int type __UNUSED__, void *event)
static int static int
_begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__) _begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
{ {
Plugin *p = (Plugin *)plugin; PLUGIN(p, plugin);
if (!p->handler.data) if (!p->handler.data)
p->handler.data = ecore_event_handler_add p->handler.data = ecore_event_handler_add
@ -222,7 +220,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it __UNUSED__)
static int static int
_fetch(Evry_Plugin *plugin, const char *input) _fetch(Evry_Plugin *plugin, const char *input)
{ {
Plugin *p = (Plugin *)plugin; PLUGIN(p, plugin);
const char *s; const char *s;
int len; int len;
@ -235,7 +233,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
{ {
const char *lang; const char *lang;
_clear_list(plugin); EVRY_PLUGIN_ITEMS_FREE(p);
input += len; input += len;
for (s = input; *s != '\0'; s++) for (s = input; *s != '\0'; s++)
@ -292,11 +290,9 @@ _fetch(Evry_Plugin *plugin, const char *input)
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin *)plugin; PLUGIN(p, plugin);
Evry_Item *it;
EINA_LIST_FREE(p->base.items, it) EVRY_PLUGIN_ITEMS_FREE(p)
evry_item_free(it);
if (p->handler.data) if (p->handler.data)
{ {
@ -332,11 +328,11 @@ _init(void)
Plugin *p; Plugin *p;
p = E_NEW(Plugin, 1); p = E_NEW(Plugin, 1);
evry_plugin_new(&p->base, "Spell Checker", type_subject, "", "TEXT", 1, evry_plugin_new(EVRY_PLUGIN(p), "Spell Checker", type_subject, "", "TEXT", 1,
"accessories-dictionary", TRIGGER, "accessories-dictionary", TRIGGER,
NULL, _cleanup, _fetch, NULL, NULL, NULL, NULL); NULL, _cleanup, _fetch, NULL, NULL, NULL, NULL);
evry_plugin_register(&p->base, 100); evry_plugin_register(EVRY_PLUGIN(p), 100);
plugin = p; plugin = p;
return EINA_TRUE; return EINA_TRUE;
@ -345,14 +341,7 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
Plugin *p; EVRY_PLUGIN_FREE(plugin);
p = plugin;
_cleanup(&p->base);
evry_plugin_free(&p->base, 0);
E_FREE(p);
} }
EINA_MODULE_INIT(_init); EINA_MODULE_INIT(_init);

View File

@ -1,13 +1,14 @@
#include "e.h" #include "e.h"
#include "e_mod_main.h" #include "e_mod_main.h"
static Evry_Plugin *p; static Evry_Plugin *plugin;
static Eina_List *handlers = NULL; static Eina_List *handlers = NULL;
static int static int
_cb_border_remove(void *data, int type, void *event) _cb_border_remove(void *data, int type, void *event)
{ {
Evry_Plugin *p = data;
E_Event_Border_Remove *ev; E_Event_Border_Remove *ev;
Eina_List *l; Eina_List *l;
Evry_Item *it; Evry_Item *it;
@ -16,7 +17,7 @@ _cb_border_remove(void *data, int type, void *event)
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->items, l, it)
{ {
if (it->data[0] == ev->border) if (it->data == ev->border)
{ {
p->items = eina_list_remove(p->items, it); p->items = eina_list_remove(p->items, it);
evry_item_free(it); evry_item_free(it);
@ -33,7 +34,7 @@ _begin(Evry_Plugin *p, const Evry_Item *it)
{ {
handlers = eina_list_append handlers = eina_list_append
(handlers, ecore_event_handler_add (handlers, ecore_event_handler_add
(E_EVENT_BORDER_REMOVE, _cb_border_remove, NULL)); (E_EVENT_BORDER_REMOVE, _cb_border_remove, p));
return p; return p;
} }
@ -55,7 +56,10 @@ _cleanup(Evry_Plugin *p)
static void static void
_item_free(Evry_Item *it) _item_free(Evry_Item *it)
{ {
if (it->data[0]) e_object_unref(E_OBJECT(it->data[0])); if (it->data)
e_object_unref(E_OBJECT(it->data));
E_FREE(it);
} }
static void static void
@ -63,16 +67,16 @@ _item_add(Evry_Plugin *p, E_Border *bd, int match, int *prio)
{ {
Evry_Item *it; Evry_Item *it;
it = evry_item_new(p, e_border_name_get(bd), _item_free); it = evry_item_new(NULL, p, e_border_name_get(bd), _item_free);
e_object_ref(E_OBJECT(bd)); e_object_ref(E_OBJECT(bd));
it->data[0] = bd; it->data = bd;
it->fuzzy_match = match; it->fuzzy_match = match;
it->priority = *prio; it->priority = *prio;
*prio += 1; *prio += 1;
p->items = eina_list_append(p->items, it); EVRY_PLUGIN_ITEM_APPEND(p, it);
} }
static int static int
@ -144,7 +148,7 @@ static Evas_Object *
_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e) _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{ {
Evas_Object *o = NULL; Evas_Object *o = NULL;
E_Border *bd = it->data[0]; E_Border *bd = it->data;
if (bd->internal) if (bd->internal)
{ {
@ -218,10 +222,10 @@ _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
static Eina_Bool static Eina_Bool
_init(void) _init(void)
{ {
p = evry_plugin_new(NULL, "Windows", type_subject, NULL, "BORDER", 0, NULL, NULL, plugin = evry_plugin_new(NULL, "Windows", type_subject, NULL, "BORDER", 0, NULL, NULL,
_begin, _cleanup, _fetch, NULL, _item_icon_get, NULL, NULL); _begin, _cleanup, _fetch, NULL, _item_icon_get, NULL, NULL);
evry_plugin_register(p, 2); evry_plugin_register(plugin, 2);
return EINA_TRUE; return EINA_TRUE;
} }
@ -229,7 +233,7 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
evry_plugin_free(p, 1); EVRY_PLUGIN_FREE(plugin);
} }

View File

@ -8,7 +8,7 @@ struct _Inst
E_Border *border; E_Border *border;
}; };
static Evry_Plugin *p; static Evry_Plugin *plugin;
static Inst *inst; static Inst *inst;
@ -88,7 +88,7 @@ _begin(Evry_Plugin *p __UNUSED__, const Evry_Item *item)
{ {
E_Border *bd; E_Border *bd;
bd = item->data[0]; bd = item->data;
/* e_object_ref(E_OBJECT(bd)); */ /* e_object_ref(E_OBJECT(bd)); */
inst->border = bd; inst->border = bd;
@ -104,12 +104,6 @@ _cb_sort(const void *data1, const void *data2)
return (it1->fuzzy_match - it2->fuzzy_match); return (it1->fuzzy_match - it2->fuzzy_match);
} }
static void
_item_free(Evry_Item *it)
{
if (it->data[1]) eina_stringshare_del((const char *)it->data[1]);
}
static void static void
_item_add(Evry_Plugin *p, const char *label, void (*action_cb) (E_Border *bd), const char *icon, const char *input) _item_add(Evry_Plugin *p, const char *label, void (*action_cb) (E_Border *bd), const char *icon, const char *input)
{ {
@ -121,9 +115,9 @@ _item_add(Evry_Plugin *p, const char *label, void (*action_cb) (E_Border *bd), c
if (!match) return; if (!match) return;
it = evry_item_new(p, label, _item_free); it = evry_item_new(NULL, p, label, NULL);
it->data[0] = action_cb; it->icon = eina_stringshare_add(icon);
it->data[1] = (void *) eina_stringshare_add(icon); it->data = action_cb;
it->fuzzy_match = match; it->fuzzy_match = match;
p->items = eina_list_prepend(p->items, it); p->items = eina_list_prepend(p->items, it);
@ -132,10 +126,7 @@ _item_add(Evry_Plugin *p, const char *label, void (*action_cb) (E_Border *bd), c
static void static void
_cleanup(Evry_Plugin *p) _cleanup(Evry_Plugin *p)
{ {
Evry_Item *it; EVRY_PLUGIN_ITEMS_FREE(p);
EINA_LIST_FREE(p->items, it)
evry_item_free(it);
} }
static int static int
@ -193,7 +184,7 @@ static int
_action(Evry_Plugin *p __UNUSED__, const Evry_Item *item) _action(Evry_Plugin *p __UNUSED__, const Evry_Item *item)
{ {
void (*border_action) (E_Border *bd); void (*border_action) (E_Border *bd);
border_action = item->data[0]; border_action = item->data;
border_action(inst->border); border_action(inst->border);
return EVRY_ACTION_FINISHED; return EVRY_ACTION_FINISHED;
@ -204,7 +195,7 @@ _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{ {
Evas_Object *o; Evas_Object *o;
o = evry_icon_theme_get((const char *)it->data[1], e); o = evry_icon_theme_get(it->icon, e);
return o; return o;
} }
@ -212,10 +203,10 @@ _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
static Eina_Bool static Eina_Bool
_init(void) _init(void)
{ {
p = evry_plugin_new(NULL, "Window Action", type_action, "BORDER", NULL, 0, NULL, NULL, plugin = evry_plugin_new(NULL, "Window Action", type_action, "BORDER", NULL, 0, NULL, NULL,
_begin, _cleanup, _fetch, _action, _item_icon_get, NULL, NULL); _begin, _cleanup, _fetch, _action, _item_icon_get, NULL, NULL);
evry_plugin_register(p, 1); evry_plugin_register(plugin, 1);
inst = E_NEW(Inst, 1); inst = E_NEW(Inst, 1);
@ -225,7 +216,7 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
evry_plugin_free(p, 1); EVRY_PLUGIN_FREE(plugin);
E_FREE(inst); E_FREE(inst);
} }

View File

@ -25,13 +25,13 @@ _begin(Evry_Plugin *p, const Evry_Item *item __UNUSED__)
EINA_LIST_FREE(history, result) EINA_LIST_FREE(history, result)
{ {
it = evry_item_new(p, result, NULL); it = evry_item_new(NULL, p, result, NULL);
p->items = eina_list_prepend(p->items, it); p->items = eina_list_prepend(p->items, it);
eina_stringshare_del(result); eina_stringshare_del(result);
} }
} }
it = evry_item_new(p, "0", NULL); it = evry_item_new(NULL, p, "0", NULL);
p->items = eina_list_prepend(p->items, it); p->items = eina_list_prepend(p->items, it);
return p; return p;
@ -120,7 +120,7 @@ _action(Evry_Plugin *p, const Evry_Item *it)
it = p->items->data; it = p->items->data;
it2 = evry_item_new(p, it->label, NULL); it2 = evry_item_new(NULL, p, it->label, NULL);
p->items = eina_list_prepend(p->items, it2); p->items = eina_list_prepend(p->items, it2);
evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_ADD); evry_plugin_async_update(p, EVRY_ASYNC_UPDATE_ADD);
@ -170,7 +170,7 @@ _cb_data(void *data, int type __UNUSED__, void *event)
p->items = eina_list_remove(p->items, it); p->items = eina_list_remove(p->items, it);
evry_item_free(it); evry_item_free(it);
it = evry_item_new(p, ev->lines->line, NULL); it = evry_item_new(NULL, p, ev->lines->line, NULL);
p->items = eina_list_prepend(p->items, it); p->items = eina_list_prepend(p->items, it);
} }
@ -223,7 +223,7 @@ _shutdown(void)
EINA_LIST_FREE(history, result) EINA_LIST_FREE(history, result)
eina_stringshare_del(result); eina_stringshare_del(result);
evry_plugin_free(p1, 1); EVRY_PLUGIN_FREE(p1);
} }

View File

@ -7,10 +7,7 @@ static Evry_Action *act;
static void static void
_cleanup(Evry_Plugin *p) _cleanup(Evry_Plugin *p)
{ {
Evry_Item *it; EVRY_PLUGIN_ITEMS_FREE(p);
EINA_LIST_FREE(p->items, it)
evry_item_free(it);
} }
static void static void
@ -18,24 +15,12 @@ _item_add(Evry_Plugin *p, E_Configure_It *eci, int match, int prio)
{ {
Evry_Item *it; Evry_Item *it;
it = evry_item_new(p, eci->label, NULL); it = evry_item_new(NULL, p, eci->label, NULL);
it->data[0] = eci; it->data = eci;
it->priority = prio; it->priority = prio;
it->fuzzy_match = match; it->fuzzy_match = match;
p->items = eina_list_append(p->items, it); EVRY_PLUGIN_ITEM_APPEND(p, it);
}
static int
_cb_sort(const void *data1, const void *data2)
{
const Evry_Item *it1 = data1;
const Evry_Item *it2 = data2;
if (it1->fuzzy_match - it2->fuzzy_match)
return (it1->fuzzy_match - it2->fuzzy_match);
return (it1->priority - it2->priority);
} }
static int static int
@ -67,7 +52,7 @@ _fetch(Evry_Plugin *p, const char *input)
if (eina_list_count(p->items) > 0) if (eina_list_count(p->items) > 0)
{ {
p->items = eina_list_sort(p->items, eina_list_count(p->items), _cb_sort); p->items = evry_fuzzy_match_sort(p->items);
return 1; return 1;
} }
@ -78,7 +63,7 @@ static Evas_Object *
_item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e) _item_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{ {
Evas_Object *o = NULL; Evas_Object *o = NULL;
E_Configure_It *eci = it->data[0]; E_Configure_It *eci = it->data;
if (eci->icon) if (eci->icon)
{ {
@ -101,7 +86,7 @@ _action(Evry_Action *act)
char buf[1024]; char buf[1024];
int found = 0; int found = 0;
eci = act->item1->data[0]; eci = act->item1->data;
con = e_container_current_get(e_manager_current_get()); con = e_container_current_get(e_manager_current_get());
EINA_LIST_FOREACH(e_configure_registry, l, ecat) EINA_LIST_FOREACH(e_configure_registry, l, ecat)
@ -145,8 +130,7 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
evry_plugin_free(p, 1); EVRY_PLUGIN_FREE(p);
evry_action_free(act); evry_action_free(act);
} }

View File

@ -11,7 +11,7 @@ struct _Plugin
const char *directory; const char *directory;
/* all files of directory */ /* all files of directory */
Eina_List *items; Eina_List *files;
/* current list of files */ /* current list of files */
Eina_List *cur; Eina_List *cur;
Eina_Bool command; Eina_Bool command;
@ -23,32 +23,19 @@ static Evry_Plugin *p2;
static Evry_Action *act; static Evry_Action *act;
static Evry_Item *
_item_add(Plugin *p, const char *directory, const char *file)
{
Evry_Item *it = NULL;
char buf[4096];
it = evry_item_new(&p->base, file, NULL);
if (!it) return NULL;
snprintf(buf, sizeof(buf), "%s/%s", directory, file);
it->uri = eina_stringshare_add(buf);
return it;
}
static void static void
_item_fill(Evry_Item *it) _item_fill(Evry_Item_File *file)
{ {
const char *mime; const char *mime;
if (it->mime) return; if (file->mime) return;
if (ecore_file_is_dir(it->uri)) if (ecore_file_is_dir(file->uri))
{ {
it->mime = eina_stringshare_add("x-directory/normal"); file->mime = eina_stringshare_add("x-directory/normal");
it->browseable = EINA_TRUE; EVRY_ITEM(file)->browseable = EINA_TRUE;
return; return;
} }
@ -67,13 +54,13 @@ _item_fill(Evry_Item *it)
* } * }
* } */ * } */
if ((mime = efreet_mime_type_get(it->uri))) if ((mime = efreet_mime_type_get(file->uri)))
{ {
it->mime = eina_stringshare_add(mime); file->mime = eina_stringshare_add(mime);
return; return;
} }
it->mime = eina_stringshare_add("None"); file->mime = eina_stringshare_add("None");
} }
static int static int
@ -99,23 +86,22 @@ _dirbrowse_idler(void *data)
{ {
Plugin *p = data; Plugin *p = data;
Eina_List *l; Eina_List *l;
Evry_Item *it; Evry_Item_File *file;
int cnt = 10; int cnt = 10;
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->files, l, file)
{ {
if (!it->mime) if (!file->mime)
{ {
_item_fill(it); _item_fill(file);
cnt--; cnt--;
} }
if (cnt == 0) break; if (cnt == 0) break;
} }
l = p->base.items; EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
p->base.items = eina_list_sort(l, eina_list_count(l), _cb_sort); evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD);
evry_plugin_async_update(&p->base, EVRY_ASYNC_UPDATE_ADD);
if (cnt > 0) if (cnt > 0)
{ {
@ -126,31 +112,49 @@ _dirbrowse_idler(void *data)
return 1; return 1;
} }
static void
_item_free(Evry_Item *it)
{
ITEM_FILE(file, it);
if (file->uri) eina_stringshare_del(file->uri);
if (file->mime) eina_stringshare_del(file->mime);
E_FREE(file);
}
static void static void
_read_directory(Plugin *p) _read_directory(Plugin *p)
{ {
char *file; char *filename;
Eina_List *files; Eina_List *files;
Evry_Item *it; Evry_Item *it;
char buf[4096];
Evry_Item_File *file;
files = ecore_file_ls(p->directory); files = ecore_file_ls(p->directory);
EINA_LIST_FREE(files, file) EINA_LIST_FREE(files, filename)
{ {
it = NULL; if (filename[0] == '.')
if (file[0] == '.')
{ {
free(file); free(filename);
continue; continue;
} }
it = _item_add(p, p->directory, file); file = E_NEW(Evry_Item_File, 1);
if (!file) return;
if (it) evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), filename, _item_free);
p->items = eina_list_append(p->items, it);
free(file); /* TODO one could have a function uri() instead that puts
together dir and file name when needed */
snprintf(buf, sizeof(buf), "%s/%s", p->directory, filename);
file->uri = eina_stringshare_add(buf);
if (file)
p->files = eina_list_append(p->files, file);
free(filename);
} }
p->idler = ecore_idler_add(_dirbrowse_idler, p); p->idler = ecore_idler_add(_dirbrowse_idler, p);
@ -159,19 +163,21 @@ _read_directory(Plugin *p)
static Evry_Plugin * static Evry_Plugin *
_begin(Evry_Plugin *plugin, const Evry_Item *it) _begin(Evry_Plugin *plugin, const Evry_Item *it)
{ {
Plugin *p; Plugin *p = NULL;
/* is FILE ? */ /* is FILE ? */
if (it && (it->plugin->type_out == plugin->type_in)) if (it && (it->plugin->type_out == plugin->type_in))
{ {
if (!it->uri || !ecore_file_is_dir(it->uri)) ITEM_FILE(file, it);
if (!file->uri || !ecore_file_is_dir(file->uri))
return NULL; return NULL;
p = E_NEW(Plugin, 1); p = E_NEW(Plugin, 1);
p->base = *plugin; p->base = *plugin;
p->base.items = NULL; p->base.items = NULL;
p->directory = eina_stringshare_add(it->uri); p->directory = eina_stringshare_add(file->uri);
} }
else else
{ {
@ -183,26 +189,26 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it)
_read_directory(p); _read_directory(p);
return &p->base; return EVRY_PLUGIN(p);
} }
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it;
Evry_Item_File *file;
if (p->directory) if (p->directory)
eina_stringshare_del(p->directory); eina_stringshare_del(p->directory);
EINA_LIST_FREE(p->items, it) EINA_LIST_FREE(p->files, file)
evry_item_free(it); evry_item_free(EVRY_ITEM(file));
if (p->idler) if (p->idler)
ecore_idler_del(p->idler); ecore_idler_del(p->idler);
if (plugin->items) EVRY_PLUGIN_ITEMS_CLEAR(p);
eina_list_free(plugin->items);
E_FREE(p); E_FREE(p);
} }
@ -210,16 +216,14 @@ _cleanup(Evry_Plugin *plugin)
static int static int
_fetch(Evry_Plugin *plugin, const char *input) _fetch(Evry_Plugin *plugin, const char *input)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it; Evry_Item_File *file;
Eina_List *l; Eina_List *l;
int cnt = 0; int cnt = 0;
int match;
if (!p->command) if (!p->command)
{ EVRY_PLUGIN_ITEMS_CLEAR(p);
if (p->base.items) eina_list_free(p->base.items);
p->base.items = NULL;
}
/* input is command ? */ /* input is command ? */
if (input) if (input)
@ -228,13 +232,16 @@ _fetch(Evry_Plugin *plugin, const char *input)
{ {
if (p->command) return 1; if (p->command) return 1;
it = evry_item_new(&p->base, "/", NULL); file = E_NEW(Evry_Item_File, 1);
if (!it) return 0; if (file)
it->uri = eina_stringshare_add("/"); {
p->base.items = eina_list_append(p->base.items, it); evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), "/", _item_free);
file->uri = eina_stringshare_add("/");
EVRY_PLUGIN_ITEM_APPEND(p, file);
p->command = EINA_TRUE; p->command = EINA_TRUE;
return 1; return 1;
} }
}
else if (!strncmp(input, "..", 2)) else if (!strncmp(input, "..", 2))
{ {
char *end; char *end;
@ -253,21 +260,29 @@ _fetch(Evry_Plugin *plugin, const char *input)
{ {
tmp = strdup(dir); tmp = strdup(dir);
snprintf(dir, (end - dir) + 1, "%s", tmp); snprintf(dir, (end - dir) + 1, "%s", tmp);
it = evry_item_new(&p->base, dir, NULL);
if (!it) break; file = E_NEW(Evry_Item_File, 1);
it->uri = eina_stringshare_add(dir); if (file)
it->priority = prio; {
p->base.items = eina_list_append(p->base.items, it); evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), dir, _item_free);
file->uri = eina_stringshare_add(dir);
EVRY_ITEM(file)->priority = prio;
EVRY_PLUGIN_ITEM_APPEND(p, file);
}
end = strrchr(dir, '/'); end = strrchr(dir, '/');
free(tmp); free(tmp);
prio--; prio--;
} }
it = evry_item_new(&p->base, "/", NULL); file = E_NEW(Evry_Item_File, 1);
if (!it) return 0; if (file)
it->uri = eina_stringshare_add("/"); {
it->priority = prio; evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), "/", _item_free);
p->base.items = eina_list_append(p->base.items, it); file->uri = eina_stringshare_add("/");
EVRY_ITEM(file)->priority = prio;
EVRY_PLUGIN_ITEM_APPEND(p, file);
}
p->command = EINA_TRUE; p->command = EINA_TRUE;
return 1; return 1;
} }
@ -276,53 +291,50 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (p->command) if (p->command)
{ {
p->command = EINA_FALSE; p->command = EINA_FALSE;
EINA_LIST_FREE(p->base.items, it) EVRY_PLUGIN_ITEMS_FREE(p);
evry_item_free(it);
} }
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->files, l, file)
{ {
if (input) if (input)
{ {
int match; if ((match = evry_fuzzy_match(EVRY_ITEM(file)->label, input)))
if ((match = evry_fuzzy_match(it->label, input))) EVRY_ITEM(file)->fuzzy_match = match;
it->fuzzy_match = match;
else else
it = NULL; file = NULL;
} }
if (it) if (file)
{ {
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, file);
if (cnt++ >= MAX_ITEMS) break; if (cnt++ >= MAX_ITEMS) break;
} }
} }
if (p->base.items) if (!EVRY_PLUGIN(p)->items)
{ return 0;
p->base.items = eina_list_sort
(p->base.items, eina_list_count(p->base.items), _cb_sort); EVRY_PLUGIN_ITEMS_SORT(p, _cb_sort);
return 1; return 1;
}
return 0;
} }
static Evas_Object * static Evas_Object *
_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; Evas_Object *o = NULL;
ITEM_FILE(file, it);
if (!it->mime) if (!file->mime)
_item_fill((Evry_Item *)it); _item_fill(file);
if (!it->mime) return NULL; if (!file->mime) return NULL;
if (it->browseable) if (it->browseable)
o = evry_icon_theme_get("folder", e); o = evry_icon_theme_get("folder", e);
else else
o = evry_icon_mime_get(it->mime, e); o = evry_icon_mime_get(file->mime, e);
return o; return o;
} }
@ -345,16 +357,18 @@ _open_folder_action(Evry_Action *act)
m = e_manager_list(); m = e_manager_list();
ITEM_FILE(file, act->item1);
if (!act->item1->browseable) if (!act->item1->browseable)
{ {
path = ecore_file_dir_get(act->item1->uri); path = ecore_file_dir_get(file->uri);
if (!path) return 0; if (!path) return 0;
action->func.go(E_OBJECT(m->data), path); action->func.go(E_OBJECT(m->data), path);
free(path); free(path);
} }
else else
{ {
action->func.go(E_OBJECT(m->data), act->item1->uri); action->func.go(E_OBJECT(m->data), file->uri);
} }
return 1; return 1;
@ -386,8 +400,8 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
evry_plugin_free(p1, 1); EVRY_PLUGIN_FREE(p1);
evry_plugin_free(p2, 1); EVRY_PLUGIN_FREE(p2);
evry_action_free(act); evry_action_free(act);
} }

View File

@ -23,11 +23,13 @@ static const char *view_types = NULL;
static int static int
_check_item(const Evry_Item *it) _check_item(const Evry_Item *it)
{ {
if ((!it || !it->uri || !it->mime) || if (!it || it->plugin->type_out != view_types) return 0;
(it->plugin->type_out != view_types))
return 0;
if (!strncmp(it->mime, "image/", 6)) ITEM_FILE(file, it);
if (!file->uri || !file->mime) return 0;
if (!strncmp(file->mime, "image/", 6))
return 1; return 1;
return 0; return 0;
@ -46,7 +48,7 @@ _cb_preview_thumb_gen(void *data, Evas_Object *obj, void *event_info)
} }
void void
_show_item(Image_View *v, const Evry_Item *it, int dir) _show_item(Image_View *v, const Evry_Item_File *file, int dir)
{ {
int w, h; int w, h;
@ -75,7 +77,7 @@ _show_item(Image_View *v, const Evry_Item *it, int dir)
} }
v->o_thumb[1] = e_thumb_icon_add(v->evas); v->o_thumb[1] = e_thumb_icon_add(v->evas);
e_thumb_icon_file_set(v->o_thumb[1], it->uri, NULL); e_thumb_icon_file_set(v->o_thumb[1], file->uri, NULL);
evas_object_smart_callback_add(v->o_thumb[1], "e_thumb_gen", _cb_preview_thumb_gen, v); evas_object_smart_callback_add(v->o_thumb[1], "e_thumb_gen", _cb_preview_thumb_gen, v);
edje_object_part_geometry_get(v->o_main, "e.swallow.icon2", NULL, NULL, &w, &h); edje_object_part_geometry_get(v->o_main, "e.swallow.icon2", NULL, NULL, &w, &h);
e_thumb_icon_size_set(v->o_thumb[1], w, h); e_thumb_icon_size_set(v->o_thumb[1], w, h);
@ -96,9 +98,9 @@ _cb_key_down(Evry_View *view, const Ecore_Event_Key *ev)
Image_View *v = (Image_View *) view; Image_View *v = (Image_View *) view;
Eina_List *l; Eina_List *l;
Evry_Item *it = NULL, *cur_item; Evry_Item_File *file = NULL;
cur_item = v->state->sel_item; ITEM_FILE(cur_item, v->state->sel_item);
if (!strcmp(ev->key, "Down")) if (!strcmp(ev->key, "Down"))
{ {
@ -107,14 +109,14 @@ _cb_key_down(Evry_View *view, const Ecore_Event_Key *ev)
l = eina_list_data_find_list(v->items, cur_item); l = eina_list_data_find_list(v->items, cur_item);
if (l && l->next) if (l && l->next)
it = l->next->data; file = l->next->data;
else else
it = v->items->data; file = v->items->data;
if (it && (it != cur_item)) if (file && (file != cur_item))
{ {
_show_item(v, it, 1); _show_item(v, file, 1);
evry_item_select(v->state, it); evry_item_select(v->state, EVRY_ITEM(file));
} }
return 1; return 1;
} }
@ -125,14 +127,14 @@ _cb_key_down(Evry_View *view, const Ecore_Event_Key *ev)
l = eina_list_data_find_list(v->items, cur_item); l = eina_list_data_find_list(v->items, cur_item);
if (l && l->prev) if (l && l->prev)
it = l->prev->data; file = l->prev->data;
else else
it = eina_list_last(v->items)->data; file = eina_list_last(v->items)->data;
if (it && (it != cur_item)) if (file && (file != cur_item))
{ {
_show_item(v, it, -1); _show_item(v, file, -1);
evry_item_select(v->state, it); evry_item_select(v->state, EVRY_ITEM(file));
} }
return 1; return 1;
} }
@ -172,19 +174,20 @@ static int
_view_update(Evry_View *view) _view_update(Evry_View *view)
{ {
Image_View *v = (Image_View *) view; Image_View *v = (Image_View *) view;
Evry_Item *it; Evry_Item_File *file, se;
Evry_Item *selected = v->state->sel_item;
v->items = _get_list(v->state); v->items = _get_list(v->state);
if (!v->items) return 0; if (!v->items) return 0;
it = eina_list_data_find(v->items, v->state->sel_item); file = eina_list_data_find(v->items, selected);
if (!it) if (!file)
{ {
it = v->items->data; file = v->items->data;
evry_item_select(v->state, it); evry_item_select(v->state, EVRY_ITEM(file));
} }
_show_item(v, it, 0); _show_item(v, file, 0);
return 1; return 1;
} }
@ -213,9 +216,9 @@ _view_create(Evry_View *view, const Evry_State *s, const Evas_Object *swallow)
edje_extern_object_min_size_set(v->o_main, w * 3, 100); edje_extern_object_min_size_set(v->o_main, w * 3, 100);
evas_object_resize(v->o_main, w * 3, h); evas_object_resize(v->o_main, w * 3, h);
v->view.o_list = v->o_main; EVRY_VIEW(v)->o_list = v->o_main;
return &v->view; return EVRY_VIEW(v);
} }
static void static void

View File

@ -15,7 +15,7 @@ struct _Plugin
int max_hits; int max_hits;
const char *input; const char *input;
const char *matched; const char *matched;
Eina_List *items; Eina_List *files;
}; };
static E_DBus_Connection *conn = NULL; static E_DBus_Connection *conn = NULL;
@ -25,16 +25,16 @@ static int _prio = 5;
static Evry_Plugin * static Evry_Plugin *
_begin(Evry_Plugin *plugin, const Evry_Item *it) _begin(Evry_Plugin *plugin, const Evry_Item *it)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
p->active = 0; p->active = 0;
/* is APPLICATION ? */ /* is APPLICATION ? */
if (it && it->plugin->type_out == plugin->type_in) if (it && it->plugin->type_out == plugin->type_in)
{ {
ITEM_APP(app, it);
Eina_List *l; Eina_List *l;
const char *mime; const char *mime;
Evry_App *app = it->data[0];
char mime_entry[256]; char mime_entry[256];
char rdf_query[32768]; char rdf_query[32768];
int len = 0; int len = 0;
@ -72,45 +72,57 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it)
return plugin; return plugin;
} }
static Evry_Item * static void
_item_add(Plugin *p, char *file, char *mime, int prio) _item_free(Evry_Item *it)
{ {
Evry_Item *it; ITEM_FILE(file, it);
if (file->uri) eina_stringshare_del(file->uri);
if (file->mime) eina_stringshare_del(file->mime);
E_FREE(file);
}
static Evry_Item_File *
_item_add(Plugin *p, char *path, char *mime, int prio)
{
Evry_Item_File *file;
const char *filename; const char *filename;
int folder = (!strcmp(mime, "Folder")); int folder = (!strcmp(mime, "Folder"));
/* folders are specifically searched */ /* folders are specifically searched */
if (folder && p->base.begin) if (folder && EVRY_PLUGIN(p)->begin)
return NULL; return NULL;
filename = ecore_file_file_get(file); filename = ecore_file_file_get(path);
if (!filename) if (!filename)
return NULL; return NULL;
it = evry_item_new(&p->base, filename, NULL); file = E_NEW(Evry_Item_File, 1);
if (!it) if (!file) return NULL;
return NULL;
it->priority = prio; evry_item_new(EVRY_ITEM(file), EVRY_PLUGIN(p), filename, _item_free);
it->uri = eina_stringshare_add(file); file->uri = eina_stringshare_add(path);
EVRY_ITEM(file)->priority = prio;
if (folder) if (folder)
{ {
it->browseable = EINA_TRUE; EVRY_ITEM(file)->browseable = EINA_TRUE;
it->mime = eina_stringshare_add("x-directory/normal"); file->mime = eina_stringshare_add("x-directory/normal");
it->priority = 1;
} }
else else
it->mime = eina_stringshare_add(mime); file->mime = eina_stringshare_add(mime);
return it; return file;
} }
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it; Evry_Item_File *file;
p->active = 0; p->active = 0;
@ -122,12 +134,10 @@ _cleanup(Evry_Plugin *plugin)
eina_stringshare_del(p->matched); eina_stringshare_del(p->matched);
p->matched = NULL; p->matched = NULL;
EINA_LIST_FREE(p->items, it) EINA_LIST_FREE(p->files, file)
evry_item_free(it); evry_item_free(EVRY_ITEM(file));
if (p->base.items) EVRY_PLUGIN_ITEMS_CLEAR(p);
eina_list_free(p->base.items);
p->base.items = NULL;
} }
static int static int
@ -146,15 +156,15 @@ _dbus_cb_reply(void *data, DBusMessage *msg, DBusError *error)
{ {
DBusMessageIter array, iter, item; DBusMessageIter array, iter, item;
char *uri, *mime, *date; char *uri, *mime, *date;
Evry_Item *it; Evry_Item_File *file;
Eina_List *items = NULL; Eina_List *files = NULL;
Plugin *p = data; Plugin *p = data;
if (p->active) p->active--; if (p->active) p->active--;
if (dbus_error_is_set(error)) if (dbus_error_is_set(error))
{ {
_cleanup(&p->base); _cleanup(EVRY_PLUGIN(p));
printf("Error: %s - %s\n", error->name, error->message); printf("Error: %s - %s\n", error->name, error->message);
return; return;
} }
@ -182,31 +192,28 @@ _dbus_cb_reply(void *data, DBusMessage *msg, DBusError *error)
if (uri && mime && date) if (uri && mime && date)
{ {
it = _item_add(p, uri, mime, atoi(date)); file = _item_add(p, uri, mime, atoi(date));
if (it) if (file) files = eina_list_append(files, file);
items = eina_list_append(items, it);
} }
} }
dbus_message_iter_next(&item); dbus_message_iter_next(&item);
} }
} }
if (p->base.items) EVRY_PLUGIN_ITEMS_CLEAR(p);
eina_list_free(p->base.items);
p->base.items = NULL;
if (items) if (files)
{ {
Eina_List *l; Eina_List *l;
EINA_LIST_FREE(p->items, it) EINA_LIST_FREE(p->files, file)
evry_item_free(it); evry_item_free(EVRY_ITEM(file));
items = eina_list_sort(items, eina_list_count(items), _cb_sort); files = eina_list_sort(files, eina_list_count(files), _cb_sort);
p->items = items; p->files = files;
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->files, l, file)
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, file);
if (p->matched) if (p->matched)
eina_stringshare_del(p->matched); eina_stringshare_del(p->matched);
@ -215,19 +222,19 @@ _dbus_cb_reply(void *data, DBusMessage *msg, DBusError *error)
else else
p->matched = NULL; p->matched = NULL;
} }
else if (p->items && p->input && p->matched && else if (p->files && p->input && p->matched &&
(strlen(p->input) > strlen(p->matched))) (strlen(p->input) > strlen(p->matched)))
{ {
Eina_List *l; Eina_List *l;
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->files, l, file)
if (evry_fuzzy_match(it->label, (p->input + strlen(p->matched)))) if (evry_fuzzy_match(EVRY_ITEM(file)->label, (p->input + strlen(p->matched))))
p->base.items = eina_list_append(p->base.items, it); EVRY_PLUGIN_ITEM_APPEND(p, file);
} }
else else
{ {
EINA_LIST_FREE(p->items, it) EINA_LIST_FREE(p->files, file)
evry_item_free(it); evry_item_free(EVRY_ITEM(file));
if (p->input) if (p->input)
eina_stringshare_del(p->input); eina_stringshare_del(p->input);
@ -238,13 +245,14 @@ _dbus_cb_reply(void *data, DBusMessage *msg, DBusError *error)
p->matched = NULL; p->matched = NULL;
} }
evry_plugin_async_update(&p->base, EVRY_ASYNC_UPDATE_ADD); evry_plugin_async_update(EVRY_PLUGIN(p), EVRY_ASYNC_UPDATE_ADD);
} }
static int static int
_fetch(Evry_Plugin *plugin, const char *input) _fetch(Evry_Plugin *plugin, const char *input)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
DBusMessage *msg; DBusMessage *msg;
int live_query_id = 0; int live_query_id = 0;
int max_hits = p->max_hits; int max_hits = p->max_hits;
@ -321,7 +329,7 @@ _fetch(Evry_Plugin *plugin, const char *input)
if (input && (strlen(input) > 2)) if (input && (strlen(input) > 2))
free(search_text); free(search_text);
if (p->items) return 1; if (p->files) return 1;
return 0; return 0;
} }
@ -329,10 +337,12 @@ _fetch(Evry_Plugin *plugin, const char *input)
static Evas_Object * static Evas_Object *
_icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e) _icon_get(Evry_Plugin *p __UNUSED__, const Evry_Item *it, Evas *e)
{ {
ITEM_FILE(file, it);
if (it->browseable) if (it->browseable)
return evry_icon_theme_get("folder", e); return evry_icon_theme_get("folder", e);
else else
return evry_icon_mime_get(it->mime, e); return evry_icon_mime_get(file->mime, e);
return NULL; return NULL;
} }
@ -349,17 +359,17 @@ _plugin_new(const char *name, int type, char *service, int max_hits, int begin)
p->active = 0; p->active = 0;
if (!begin) if (!begin)
evry_plugin_new(&p->base, name, type, "", "FILE", 0, NULL, NULL, evry_plugin_new(EVRY_PLUGIN(p), name, type, "", "FILE", 0, NULL, NULL,
NULL, _cleanup, _fetch, NULL, _cleanup, _fetch,
NULL, _icon_get, NULL, NULL); NULL, _icon_get, NULL, NULL);
else else
evry_plugin_new(&p->base, name, type, "APPLICATION", "FILE", 0, NULL, NULL, evry_plugin_new(EVRY_PLUGIN(p), name, type, "APPLICATION", "FILE", 0, NULL, NULL,
_begin, _cleanup, _fetch, _begin, _cleanup, _fetch,
NULL, _icon_get, NULL, NULL); NULL, _icon_get, NULL, NULL);
plugins = eina_list_append(plugins, p); plugins = eina_list_append(plugins, p);
evry_plugin_register(&p->base, _prio++); evry_plugin_register(EVRY_PLUGIN(p), _prio++);
} }
@ -391,11 +401,9 @@ _shutdown(void)
EINA_LIST_FREE(plugins, p) EINA_LIST_FREE(plugins, p)
{ {
evry_plugin_free(&p->base, 0);
if (p->condition[0]) free(p->condition); if (p->condition[0]) free(p->condition);
E_FREE(p); EVRY_PLUGIN_FREE(p);
} }
} }

View File

@ -8,14 +8,14 @@
typedef struct _Plugin Plugin; typedef struct _Plugin Plugin;
typedef struct _Import Import; typedef struct _Import Import;
typedef struct _Item_Data Item_Data; typedef struct _Item Item;
struct _Plugin struct _Plugin
{ {
Evry_Plugin base; Evry_Plugin base;
Plugin *prev; Plugin *prev;
Eina_List *items; Eina_List *items;
const Evry_Item *item; const Evry_Item_File *file;
}; };
struct _Import struct _Import
@ -32,8 +32,9 @@ struct _Import
Evas *evas; Evas *evas;
}; };
struct _Item_Data struct _Item
{ {
Evry_Item base;
const char *icon; const char *icon;
int method; int method;
}; };
@ -46,55 +47,68 @@ static int _import_cb_edje_cc_exit(void *data, int type, void *event);
static Evry_Plugin *plugin; static Evry_Plugin *plugin;
static void static void
_item_free(Evry_Item *it) _item_free(Evry_Item *item)
{ {
Item_Data *id = it->data[0]; Item *it = (Item*) item;
E_FREE(id); E_FREE(it);
} }
static void static void
_item_add(Plugin *p, const char *name, int method, const char *icon) _item_add(Plugin *p, const char *name, int method, const char *icon)
{ {
Evry_Item *it; Item *item = E_NEW(Item, 1);
Item_Data *id; evry_item_new(EVRY_ITEM(item), EVRY_PLUGIN(p), name, _item_free);
it = evry_item_new(&p->base, name, _item_free); item->icon = icon;
id = E_NEW(Item_Data, 1); item->method = method;
id->icon = icon;
id->method = method; p->items = eina_list_append(p->items, EVRY_ITEM(item));
it->data[0] = id; }
p->items = eina_list_append(p->items, it);
static Evas_Object *
_item_icon_get(Evry_Plugin *plugin, const Evry_Item *item, Evas *e)
{
return evry_icon_theme_get(((Item*)item)->icon, e);
}
static Evas_Object *
_icon_get(Evry_Plugin *plugin, const Evry_Item *it, Evas *e)
{
return evry_icon_theme_get("preferences-desktop-wallpaper", e);
} }
static Evry_Plugin * static Evry_Plugin *
_begin(Evry_Plugin *plugin, const Evry_Item *item) _begin(Evry_Plugin *plugin, const Evry_Item *item)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it;
/* is FILE ? */ /* is FILE ? */
if (item && item->plugin->type_out == p->base.type_in) if (item && item->plugin->type_out == plugin->type_in)
{ {
if (!item->mime || (strncmp(item->mime, "image/", 6))) Evry_Item *it;
ITEM_FILE(file, item);
if (!file->mime || (strncmp(file->mime, "image/", 6)))
return NULL; return NULL;
p = E_NEW(Plugin, 1); p = E_NEW(Plugin, 1);
p->base = *plugin; p->base = *plugin;
p->base.items = NULL; p->base.items = NULL;
p->item = item; p->file = file;
it = evry_item_new(&p->base, _("Set as Wallpaper"), NULL);
it = evry_item_new(NULL, plugin, _("Set as Wallpaper"), NULL);
it->browseable = EINA_TRUE; it->browseable = EINA_TRUE;
p->items = eina_list_append(p->items, it); p->items = eina_list_append(p->items, it);
return &p->base; return EVRY_PLUGIN(p);
} }
else if (item->plugin->type_out == plugin->type_out) else if (item->plugin->type_out == plugin->type_out)
{ {
p = E_NEW(Plugin, 1); p = E_NEW(Plugin, 1);
p->base = *plugin; p->base = *plugin;
p->base.items = NULL; p->base.items = NULL;
p->base.icon_get = &_item_icon_get;
p->prev = (Plugin*) item->plugin; p->prev = (Plugin*) item->plugin;
_item_add(p, _("Stretch"), IMPORT_STRETCH, _item_add(p, _("Stretch"), IMPORT_STRETCH,
@ -108,7 +122,7 @@ _begin(Evry_Plugin *plugin, const Evry_Item *item)
_item_add(p, _("Fill"), IMPORT_SCALE_ASPECT_OUT, _item_add(p, _("Fill"), IMPORT_SCALE_ASPECT_OUT,
"enlightenment/wallpaper_stretch"); "enlightenment/wallpaper_stretch");
return &p->base; return EVRY_PLUGIN(p);
} }
return NULL; return NULL;
@ -117,11 +131,10 @@ _begin(Evry_Plugin *plugin, const Evry_Item *item)
static void static void
_cleanup(Evry_Plugin *plugin) _cleanup(Evry_Plugin *plugin)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it; Evry_Item *it;
if (p->base.items) eina_list_free(p->base.items); EVRY_PLUGIN_ITEMS_CLEAR(p);
p->base.items = NULL;
EINA_LIST_FREE(p->items, it) EINA_LIST_FREE(p->items, it)
evry_item_free(it); evry_item_free(it);
@ -132,38 +145,41 @@ _cleanup(Evry_Plugin *plugin)
static int static int
_fetch(Evry_Plugin *plugin, const char *input) _fetch(Evry_Plugin *plugin, const char *input)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
Evry_Item *it = NULL; Evry_Item *it = NULL;
Eina_List *l; Eina_List *l;
int match = 0;
if (p->base.items) eina_list_free(p->base.items); EVRY_PLUGIN_ITEMS_CLEAR(p);
p->base.items = NULL;
EINA_LIST_FOREACH(p->items, l, it) EINA_LIST_FOREACH(p->items, l, it)
plugin->items = eina_list_append(plugin->items, it); if (!input || (match = evry_fuzzy_match(it->label, input)))
{
it->fuzzy_match = match;
EVRY_PLUGIN_ITEM_APPEND(p, it);
}
if (input)
plugin->items = evry_fuzzy_match_sort(plugin->items);
return 1; return 1;
} }
static int static int
_action(Evry_Plugin *plugin, const Evry_Item *it) _action(Evry_Plugin *plugin, const Evry_Item *item)
{ {
Plugin *p = (Plugin*) plugin; PLUGIN(p, plugin);
if (p->prev) if (p->prev)
{ {
const Evry_Item *it_file;
Item_Data *id;
Import *import; Import *import;
Item *it = (Item*) item;
import = E_NEW(Import, 1); import = E_NEW(Import, 1);
it_file = p->prev->item; import->method = it->method;
id = it->data[0]; import->file = p->prev->file->uri;
import->method = id->method;
import->file = it_file->uri;
import->quality = 100; import->quality = 100;
import->external = 0; import->external = 0;
import->evas = evas_object_evas_get(it->o_bg); /* Eeek! */ import->evas = evas_object_evas_get(item->o_bg); /* Eeek! */
_import_edj_gen(import); _import_edj_gen(import);
return 1; return 1;
@ -172,26 +188,6 @@ _action(Evry_Plugin *plugin, const Evry_Item *it)
return 0; return 0;
} }
static Evas_Object *
_icon_get(Evry_Plugin *plugin, const Evry_Item *it, Evas *e)
{
/* Plugin *p = (Plugin*) plugin; */
Evas_Object *o = NULL;
if (it->data[0])
{
const char *icon = ((Item_Data*) it->data[0])->icon;
o = evry_icon_theme_get(icon, e);
}
else
{
o = evry_icon_theme_get("preferences-desktop-wallpaper", e);
}
return o;
}
static Eina_Bool static Eina_Bool
_init(void) _init(void)
{ {
@ -208,7 +204,7 @@ _init(void)
static void static void
_shutdown(void) _shutdown(void)
{ {
evry_plugin_free(plugin, 1); EVRY_PLUGIN_FREE(plugin);
} }