diff --git a/src/modules/everything/Evry.h b/src/modules/everything/Evry.h index 504e9c9a8..3de6306f6 100644 --- a/src/modules/everything/Evry.h +++ b/src/modules/everything/Evry.h @@ -79,11 +79,11 @@ struct _Evry_Plugin /* list of items visible for everything */ Eina_List *items; - /* run when plugin is activated. when return plugin is added + /* run when plugin is activated. when returns positve it is added to the list of current plugins and queried for results */ Evry_Plugin *(*begin) (Evry_Plugin *p, const Evry_Item *item); - /* get candidates matching string, fills 'candidates' list */ + /* get candidates matching string, fill 'items' list */ int (*fetch) (Evry_Plugin *p, const char *input); /* run when state is removed in which this plugin is active */ diff --git a/src/modules/everything/Makefile.am b/src/modules/everything/Makefile.am index d676606cd..dd323d8b3 100644 --- a/src/modules/everything/Makefile.am +++ b/src/modules/everything/Makefile.am @@ -128,6 +128,13 @@ evry_plug_view_help_la_LIBADD = @e_libs@ evry_plug_view_help_la_LDFLAGS = -no-undefined -module -avoid-version evry_plug_view_help_la_LIBTOOLFLAGS = --tag=disable-static +evry_plug_wallpaperdir = $(plugindir) +evry_plug_wallpaper_LTLIBRARIES = evry_plug_wallpaper.la +evry_plug_wallpaper_la_SOURCES = evry_plug_wallpaper.c +evry_plug_wallpaper_la_LIBADD = @e_libs@ +evry_plug_wallpaper_la_LDFLAGS = -no-undefined -module -avoid-version +evry_plug_wallpaper_la_LIBTOOLFLAGS = --tag=disable-static + uninstall: rm -rf $(DESTDIR)$(libdir)/enlightenment/modules/$(MODULE) diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index 1514ef453..de8ea7269 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -154,6 +154,16 @@ evry_show(E_Zone *zone, const char *params) e_popup_show(win->popup); e_popup_show(list->popup); + if (evry_conf->views && selector->state) + { + Evry_View *view =evry_conf->views->data; + Evry_State *s = selector->state; + + s->view = view->create(view, s, list->o_main); + _evry_view_show(s->view); + } + else goto error; + if (!evry_conf->hide_input) edje_object_signal_emit(list->o_main, "e,state,entry_show", "e"); @@ -165,6 +175,7 @@ evry_show(E_Zone *zone, const char *params) (ECORE_X_EVENT_SELECTION_NOTIFY, _evry_cb_selection_notify, win)); + return 1; error: @@ -222,7 +233,7 @@ evry_hide(void) } -void +EAPI void evry_clear_input(void) { Evry_State *s = selector->state; @@ -236,7 +247,7 @@ evry_clear_input(void) /* static int item_cnt = 0; */ -Evry_Item * +EAPI Evry_Item * evry_item_new(Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *item)) { Evry_Item *it; @@ -255,7 +266,7 @@ evry_item_new(Evry_Plugin *p, const char *label, void (*cb_free) (Evry_Item *ite return it; } -void +EAPI void evry_item_free(Evry_Item *it) { if (!it) return; @@ -281,7 +292,7 @@ evry_item_free(Evry_Item *it) E_FREE(it); } -void +EAPI void evry_item_select(const Evry_State *state, Evry_Item *it) { Evry_State *s = (Evry_State *)state; @@ -292,13 +303,13 @@ evry_item_select(const Evry_State *state, Evry_Item *it) _evry_selector_update(selector); } -void +EAPI void evry_item_ref(Evry_Item *it) { it->ref++; } -int +EAPI int evry_list_win_show(void) { if (list->visible) return 0; @@ -308,7 +319,7 @@ evry_list_win_show(void) } -void +EAPI void evry_list_win_hide(void) { _evry_list_win_clear(1); @@ -316,7 +327,7 @@ evry_list_win_hide(void) -void +EAPI void evry_plugin_async_update(Evry_Plugin *p, int action) { Evry_State *s; @@ -387,7 +398,7 @@ evry_plugin_async_update(Evry_Plugin *p, int action) } } -int +EAPI int evry_fuzzy_match(const char *str, const char *match) { const char *p, *m, *next; @@ -808,8 +819,11 @@ _evry_selector_icon_set(Evry_Selector *sel) evas_object_show(o); sel->o_icon = o; } + else + sel->o_icon = NULL; } - else if (s->plugin && s->plugin->icon) + + if (!sel->o_icon && s->plugin && s->plugin->icon) { o = evry_icon_theme_get(s->plugin->icon, win->popup->evas); if (o) @@ -1056,20 +1070,28 @@ _evry_browse_item(Evry_Selector *sel) if (!type_out) return; - EINA_LIST_FOREACH(sel->plugins, l, plugin) - { - if ((!plugin->begin || !plugin->type_in) || - (plugin->type_in != type_out)) - continue; + if (it->plugin->begin && + (p = it->plugin->begin(it->plugin, it))) + plugins = eina_list_append(plugins, p); - if ((p = plugin->begin(plugin, it))) - plugins = eina_list_append(plugins, p); + if (!plugins) + { + EINA_LIST_FOREACH(sel->plugins, l, plugin) + { + /* if (eina_list_data_find_list(plugins, plugin)) + * continue; */ + + if ((!plugin->begin || !plugin->type_in) || + (plugin->type_in != type_out)) + continue; + + if ((p = plugin->begin(plugin, it))) + plugins = eina_list_append(plugins, p); + } } if (!plugins) return; - _evry_view_hide(s->view); - _evry_state_new(sel, plugins); _evry_matches_update(sel); _evry_selector_update(sel); @@ -1088,11 +1110,9 @@ _evry_browse_back(Evry_Selector *sel) _evry_state_pop(sel); s = sel->state; - sel->aggregator->fetch(sel->aggregator, s->input); _evry_selector_update(sel); _evry_update_text_label(s); - _evry_view_show(s->view); } @@ -1382,9 +1402,9 @@ _evry_plugin_action(Evry_Selector *sel, int finished) it_object = selector->state->sel_item; if (act->type_in2 && !it_object) return; - + act->item2 = it_object; - + act->action(act); if (act->cleanup) act->cleanup(act); @@ -1401,7 +1421,7 @@ _evry_plugin_action(Evry_Selector *sel, int finished) if (s_object && s_object->plugin->action) s_object->plugin->action(s_object->plugin, s_object->sel_item); - + if (finished) evry_hide(); } diff --git a/src/modules/everything/evry_plug_aggregator.c b/src/modules/everything/evry_plug_aggregator.c index 1be7d8bf5..973832b29 100644 --- a/src/modules/everything/evry_plug_aggregator.c +++ b/src/modules/everything/evry_plug_aggregator.c @@ -126,7 +126,7 @@ _cleanup(Evry_Plugin *plugin) } static Evas_Object * -_icon_get(Evry_Plugin *p, const Evry_Item *it, Evas *e) +_icon_get(Evry_Plugin *plugin, const Evry_Item *it, Evas *e) { if (it->plugin && it->plugin->icon_get) return it->plugin->icon_get(it->plugin, it, e); @@ -158,7 +158,7 @@ evry_plug_aggregator_new(Evry_Selector *selector) void evry_plug_aggregator_free(Evry_Plugin *plugin) { - Plugin *p = (Plugin *) plugin; + Plugin *p = (Plugin*) plugin; evry_plugin_free(&p->base, 0); E_FREE(p); diff --git a/src/modules/everything/evry_plug_dir_browse.c b/src/modules/everything/evry_plug_dir_browse.c index 86d2cb54f..97d75fccd 100644 --- a/src/modules/everything/evry_plug_dir_browse.c +++ b/src/modules/everything/evry_plug_dir_browse.c @@ -169,14 +169,15 @@ _begin(Evry_Plugin *plugin, const Evry_Item *it) p = E_NEW(Plugin, 1); p->base = *plugin; - + p->base.items = NULL; + p->directory = eina_stringshare_add(it->uri); } else { p = E_NEW(Plugin, 1); p->base = *plugin; - + p->base.items = NULL; p->directory = eina_stringshare_add(e_user_homedir_get()); } @@ -217,7 +218,7 @@ _fetch(Evry_Plugin *plugin, const char *input) if (!p->command) { if (p->base.items) eina_list_free(p->base.items); - plugin->items = NULL; + p->base.items = NULL; } /* input is command ? */ diff --git a/src/modules/everything/evry_plug_view_list.c b/src/modules/everything/evry_plug_view_list.c index 87b9e4610..0ddfaa440 100644 --- a/src/modules/everything/evry_plug_view_list.c +++ b/src/modules/everything/evry_plug_view_list.c @@ -399,7 +399,7 @@ _list_tabs_update(List_View *v) EINA_LIST_FOREACH(v->tabs, ll, tab) if (tab->plugin == p) break; - if (!tab) + if (!tab && (strlen(p->name) > 0)) { tab = E_NEW(List_Tab, 1); tab->plugin = p; @@ -414,8 +414,9 @@ _list_tabs_update(List_View *v) v->tabs = eina_list_append(v->tabs, tab); } - o = tab->o_tab; + if (!tab) continue; + o = tab->o_tab; evas_object_show(o); e_box_pack_end(v->o_tabs, o); diff --git a/src/modules/everything/evry_plug_wallpaper.c b/src/modules/everything/evry_plug_wallpaper.c new file mode 100644 index 000000000..0dd5820f8 --- /dev/null +++ b/src/modules/everything/evry_plug_wallpaper.c @@ -0,0 +1,433 @@ +#include "Evry.h" + +#define IMPORT_STRETCH 0 +#define IMPORT_TILE 1 +#define IMPORT_CENTER 2 +#define IMPORT_SCALE_ASPECT_IN 3 +#define IMPORT_SCALE_ASPECT_OUT 4 + +typedef struct _Plugin Plugin; +typedef struct _Import Import; +typedef struct _Item_Data Item_Data; + +struct _Plugin +{ + Evry_Plugin base; + Plugin *prev; + Eina_List *items; + const Evry_Item *item; +}; + +struct _Import +{ + const char *file; + int method; + int external; + int quality; + + Ecore_Exe *exe; + Ecore_Event_Handler *exe_handler; + char *tmpf; + char *fdest; + Evas *evas; +}; + +struct _Item_Data +{ + const char *icon; + int method; +}; + + +static void _import_edj_gen(Import *import); +static int _import_cb_edje_cc_exit(void *data, int type, void *event); + + +static Evry_Plugin *plugin; + +static void +_item_free(Evry_Item *it) +{ + Item_Data *id = it->data[0]; + E_FREE(id); +} + +static void +_item_add(Plugin *p, const char *name, int method, const char *icon) +{ + Evry_Item *it; + Item_Data *id; + + it = evry_item_new(&p->base, name, _item_free); + id = E_NEW(Item_Data, 1); + id->icon = icon; + id->method = method; + it->data[0] = id; + p->items = eina_list_append(p->items, it); +} + +static Evry_Plugin * +_begin(Evry_Plugin *plugin, const Evry_Item *item) +{ + Plugin *p = (Plugin*) plugin; + Evry_Item *it; + + /* is FILE ? */ + if (item && item->plugin->type_out == p->base.type_in) + { + if (!item->mime || (strncmp(item->mime, "image/", 6))) + return NULL; + + p = E_NEW(Plugin, 1); + p->base = *plugin; + p->base.items = NULL; + p->item = item; + + it = evry_item_new(&p->base, _("Set as Wallpaper"), NULL); + + it->browseable = EINA_TRUE; + p->items = eina_list_append(p->items, it); + + return &p->base; + } + else if (item->plugin->type_out == plugin->type_out) + { + p = E_NEW(Plugin, 1); + p->base = *plugin; + p->base.items = NULL; + p->prev = (Plugin*) item->plugin; + + _item_add(p, _("Stretch"), IMPORT_STRETCH, + "enlightenment/wallpaper_stretch"); + _item_add(p, _("Center"), IMPORT_CENTER, + "enlightenment/wallpaper_center"); + _item_add(p, _("Tile"), IMPORT_TILE, + "enlightenment/wallpaper_tile"); + _item_add(p, _("Within"), IMPORT_SCALE_ASPECT_IN, + "enlightenment/wallpaper_scale_aspect_in"); + _item_add(p, _("Fill"), IMPORT_SCALE_ASPECT_OUT, + "enlightenment/wallpaper_stretch"); + + return &p->base; + } + + return NULL; +} + +static void +_cleanup(Evry_Plugin *plugin) +{ + Plugin *p = (Plugin*) plugin; + Evry_Item *it; + + if (p->base.items) eina_list_free(p->base.items); + p->base.items = NULL; + + EINA_LIST_FREE(p->items, it) + evry_item_free(it); + + E_FREE(p); +} + +static int +_fetch(Evry_Plugin *plugin, const char *input) +{ + Plugin *p = (Plugin*) plugin; + Evry_Item *it = NULL; + Eina_List *l; + + if (p->base.items) eina_list_free(p->base.items); + p->base.items = NULL; + + EINA_LIST_FOREACH(p->items, l, it) + plugin->items = eina_list_append(plugin->items, it); + + return 1; +} + +static int +_action(Evry_Plugin *plugin, const Evry_Item *it) +{ + Plugin *p = (Plugin*) plugin; + + if (p->prev) + { + const Evry_Item *it_file; + Item_Data *id; + Import *import; + + import = E_NEW(Import, 1); + it_file = p->prev->item; + id = it->data[0]; + import->method = id->method; + import->file = it_file->uri; + import->quality = 100; + import->external = 0; + import->evas = evas_object_evas_get(it->o_bg); /* Eeek! */ + _import_edj_gen(import); + + return 1; + } + + 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 +_init(void) +{ + plugin = evry_plugin_new(NULL, "Wallpaper", type_action, "FILE", "", + 0, "preferences-desktop-wallpaper", NULL, + _begin, _cleanup, _fetch, _action, _icon_get, + NULL, NULL); + + evry_plugin_register(plugin, 10); + + return EINA_TRUE; +} + +static void +_shutdown(void) +{ + evry_plugin_free(plugin, 1); +} + + +EINA_MODULE_INIT(_init); +EINA_MODULE_SHUTDOWN(_shutdown); + + + +/* taken from e_int_config_wallpaper_import.c */ +static void +_import_edj_gen(Import *import) +{ + Evas *evas = import->evas; + + Evas_Object *img; + int fd, num = 1; + int w = 0, h = 0; + const char *file, *locale; + char buf[4096], cmd[4096], tmpn[4096], ipart[4096], enc[128]; + char *imgdir = NULL, *fstrip; + int cr = 255, cg = 255, cb = 255, ca = 255; + FILE *f; + size_t len, off; + + file = ecore_file_file_get(import->file); + fstrip = ecore_file_strip_ext(file); + if (!fstrip) return; + len = e_user_dir_snprintf(buf, sizeof(buf), "backgrounds/%s.edj", fstrip); + if (len >= sizeof(buf)) return; + off = len - (sizeof(".edj") - 1); + while (ecore_file_exists(buf)) + { + snprintf(buf + off, sizeof(buf) - off, "-%d.edj", num); + num++; + } + free(fstrip); + strcpy(tmpn, "/tmp/e_bgdlg_new.edc-tmp-XXXXXX"); + fd = mkstemp(tmpn); + if (fd < 0) + { + printf("Error Creating tmp file: %s\n", strerror(errno)); + return; + } + close(fd); + + f = fopen(tmpn, "w"); + if (!f) + { + printf("Cannot open %s for writing\n", tmpn); + return; + } + + imgdir = ecore_file_dir_get(import->file); + if (!imgdir) ipart[0] = '\0'; + else + { + snprintf(ipart, sizeof(ipart), "-id %s", e_util_filename_escape(imgdir)); + free(imgdir); + } + + img = evas_object_image_add(evas); + evas_object_image_file_set(img, import->file, NULL); + evas_object_image_size_get(img, &w, &h); + evas_object_del(img); + + if (import->external) + { + fstrip = strdup(e_util_filename_escape(import->file)); + snprintf(enc, sizeof(enc), "USER"); + } + else + { + fstrip = strdup(e_util_filename_escape(file)); + if (import->quality == 100) + snprintf(enc, sizeof(enc), "COMP"); + else + snprintf(enc, sizeof(enc), "LOSSY %i", import->quality); + } + switch (import->method) + { + case IMPORT_STRETCH: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"0\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, fstrip); + break; + case IMPORT_TILE: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"1\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "image { normal: \"%s\"; }\n" + "fill { size {\n" + "relative: 0.0 0.0;\n" + "offset: %i %i;\n" + "} } } } } } }\n" + , fstrip, enc, w, h, fstrip, w, h); + break; + case IMPORT_CENTER: + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"2\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"col\"; type: RECT; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "color: %i %i %i %i;\n" + "} }\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "min: %i %i; max: %i %i;\n" + "image { normal: \"%s\"; }\n" + "} } } } }\n" + , fstrip, enc, w, h, cr, cg, cb, ca, w, h, w, h, fstrip); + break; + case IMPORT_SCALE_ASPECT_IN: + locale = e_intl_language_get(); + setlocale(LC_NUMERIC, "C"); + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"3\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"col\"; type: RECT; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "color: %i %i %i %i;\n" + "} }\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "aspect: %1.9f %1.9f; aspect_preference: BOTH;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, cr, cg, cb, ca, (double)w / (double)h, (double)w / (double)h, fstrip); + setlocale(LC_NUMERIC, locale); + break; + case IMPORT_SCALE_ASPECT_OUT: + locale = e_intl_language_get(); + setlocale(LC_NUMERIC, "C"); + fprintf(f, + "images { image: \"%s\" %s; }\n" + "collections {\n" + "group { name: \"e/desktop/background\";\n" + "data { item: \"style\" \"4\"; }\n" + "max: %i %i;\n" + "parts {\n" + "part { name: \"bg\"; mouse_events: 0;\n" + "description { state: \"default\" 0.0;\n" + "aspect: %1.9f %1.9f; aspect_preference: NONE;\n" + "image { normal: \"%s\"; scale_hint: STATIC; }\n" + "} } } } }\n" + , fstrip, enc, w, h, (double)w / (double)h, (double)w / (double)h, fstrip); + setlocale(LC_NUMERIC, locale); + break; + default: + /* won't happen */ + break; + } + free(fstrip); + + fclose(f); + + snprintf(cmd, sizeof(cmd), "edje_cc -v %s %s %s", + ipart, tmpn, e_util_filename_escape(buf)); + + import->tmpf = strdup(tmpn); + import->fdest = strdup(buf); + import->exe_handler = + ecore_event_handler_add(ECORE_EXE_EVENT_DEL, + _import_cb_edje_cc_exit, import); + import->exe = ecore_exe_run(cmd, NULL); +} + +static int +_import_cb_edje_cc_exit(void *data, int type, void *event) +{ + Import *import; + Ecore_Exe_Event_Del *ev; + char *fdest; + int r = 1; + + ev = event; + import = data; + if (ev->exe != import->exe) return 1; + + if (ev->exit_code != 0) + { + e_util_dialog_show(_("Picture Import Error"), + _("Enlightenment was unable to import the picture
" + "due to conversion errors.")); + r = 0; + } + + + fdest = strdup(import->fdest); + if (r) + { + e_bg_default_set(fdest); + e_bg_update(); + } + + E_FREE(fdest); + E_FREE(import); + + return 0; +}