diff --git a/src/modules/everything/e_mod_main.c b/src/modules/everything/e_mod_main.c index 8af516fbb..bc5352f8d 100644 --- a/src/modules/everything/e_mod_main.c +++ b/src/modules/everything/e_mod_main.c @@ -559,14 +559,13 @@ evry_plugin_new(Evry_Plugin *base, const char *name, const char *label, it = evry_item_new(EVRY_ITEM(p), NULL, label, NULL, _evry_plugin_free); it->plugin = p; it->browseable = EINA_TRUE; - - p->base.icon = icon; - p->base.type = EVRY_TYPE_PLUGIN; - + it->type = EVRY_TYPE_PLUGIN; if (item_type) - p->base.subtype = item_type; + it->subtype = item_type; + if (icon) + it->icon = eina_stringshare_add(icon); - p->name = eina_stringshare_add(name); + p->name = eina_stringshare_add(name); p->begin = begin; p->finish = finish; p->fetch = fetch; diff --git a/src/modules/everything/evry.c b/src/modules/everything/evry.c index af906e1f4..290e06072 100644 --- a/src/modules/everything/evry.c +++ b/src/modules/everything/evry.c @@ -407,11 +407,12 @@ evry_item_free(Evry_Item *it) item_cnt--; #endif - if (it->label) eina_stringshare_del(it->label); - if (it->id) eina_stringshare_del(it->id); - if (it->context) eina_stringshare_del(it->context); - if (it->detail) eina_stringshare_del(it->detail); - + IF_RELEASE(it->label); + IF_RELEASE(it->id); + IF_RELEASE(it->context); + IF_RELEASE(it->detail); + IF_RELEASE(it->icon); + if (it->free) it->free(it); else @@ -543,7 +544,7 @@ evry_plugin_update(Evry_Plugin *p, int action) if (!win) return; - DBG("plugin: %s", p->name); + printf("plugin: %s\n", p->name); sel = _evry_selector_for_plugin_get(p); if (!sel || !sel->state) return; @@ -578,31 +579,34 @@ evry_plugin_update(Evry_Plugin *p, int action) _evry_plugin_select(s, NULL); } - /* update aggregator */ - if ((eina_list_count(s->cur_plugins) > 1 ) || - /* add aggregator for actions */ - (sel == selectors[1] && - (eina_list_count(s->cur_plugins) > 0 ))) + if (!p->config || p->config->aggregate) { - /* add aggregator */ - if (!(s->cur_plugins->data == agg)) + /* update aggregator */ + if ((eina_list_count(s->cur_plugins) > 1 ) || + /* add aggregator for actions */ + (sel == selectors[1] && + (eina_list_count(s->cur_plugins) > 0 ))) { - s->cur_plugins = eina_list_prepend(s->cur_plugins, agg); + /* add aggregator */ + if (!(s->cur_plugins->data == agg)) + { + s->cur_plugins = eina_list_prepend(s->cur_plugins, agg); - if (s->plugin_auto_selected) - _evry_plugin_select(s, NULL); + if (s->plugin_auto_selected) + _evry_plugin_select(s, NULL); + } + agg->fetch(agg, s->input[0] ? s->input : NULL); } - agg->fetch(agg, s->input[0] ? s->input : NULL); - } - else - { - if (s->cur_plugins && s->cur_plugins->data == agg) + else { - agg->finish(agg); - s->cur_plugins = eina_list_remove(s->cur_plugins, agg); + if (s->cur_plugins && s->cur_plugins->data == agg) + { + agg->finish(agg); + s->cur_plugins = eina_list_remove(s->cur_plugins, agg); + } } } - + if (s->sel_items) eina_list_free(s->sel_items); s->sel_items = NULL; diff --git a/src/modules/everything/evry_api.h b/src/modules/everything/evry_api.h index d430b110d..54d15ffb2 100644 --- a/src/modules/everything/evry_api.h +++ b/src/modules/everything/evry_api.h @@ -3,7 +3,7 @@ #include "evry_types.h" -#define EVRY_API_VERSION 19 +#define EVRY_API_VERSION 20 #define EVRY_ACTION_OTHER 0 #define EVRY_ACTION_FINISHED 1 @@ -167,7 +167,6 @@ struct _Evry_API #define EVRY_ITEM_DATA_INT_SET(_item, _data) ((Evry_Item *)_item)->data = (void*)(long) _data #define EVRY_ITEM_DATA_INT_GET(_item) (long) ((Evry_Item *)_item)->data -#define EVRY_ITEM_ICON_SET(_item, _icon) ((Evry_Item *)_item)->icon = _icon #define EVRY_ITEM_DETAIL_SET(_it, _detail) \ if (EVRY_ITEM(_it)->detail) eina_stringshare_del(EVRY_ITEM(_it)->detail); \ @@ -181,6 +180,10 @@ struct _Evry_API if (EVRY_ITEM(_it)->context) eina_stringshare_del(EVRY_ITEM(_it)->context); \ EVRY_ITEM(_it)->context = eina_stringshare_add(_context); +#define EVRY_ITEM_ICON_SET(_it, _icon) \ + if (EVRY_ITEM(_it)->icon) eina_stringshare_del(EVRY_ITEM(_it)->icon); \ + EVRY_ITEM(_it)->icon = eina_stringshare_add(_icon); + #define CHECK_TYPE(_item, _type) \ (((Evry_Item *)_item)->type && ((Evry_Item *)_item)->type == _type) diff --git a/src/modules/everything/evry_history.c b/src/modules/everything/evry_history.c index 92827d7d1..4fb06351a 100644 --- a/src/modules/everything/evry_history.c +++ b/src/modules/everything/evry_history.c @@ -292,6 +292,9 @@ evry_history_item_add(Evry_Item *it, const char *ctxt, const char *input) { id = (it->id ? it->id : it->label); ht = evry_history_types_get(it->type); + if (!ht) + return NULL; + he = eina_hash_find(ht->types, id); if (!he) @@ -376,6 +379,9 @@ evry_history_item_usage_set(Evry_Item *it, const char *input, const char *ctxt) { ht = evry_history_types_get(it->type); + if (!ht) + return 0; + if (!(he = eina_hash_find(ht->types, (it->id ? it->id : it->label)))) return 0; @@ -404,7 +410,6 @@ evry_history_item_usage_set(Evry_Item *it, const char *input, const char *ctxt) if (!hi) return 0; - if (evry_conf->history_sort_mode == 0) { if (!input || !hi->input) diff --git a/src/modules/everything/evry_plug_actions.c b/src/modules/everything/evry_plug_actions.c index 68a181169..1bd4c1e06 100644 --- a/src/modules/everything/evry_plug_actions.c +++ b/src/modules/everything/evry_plug_actions.c @@ -247,7 +247,9 @@ evry_action_new(const char *name, const char *label, int (*check_item) (Evry_Action *act, const Evry_Item *it)) { Evry_Action *act = EVRY_ITEM_NEW(Evry_Action, _base_plug, label, NULL, _action_free_cb); - act->base.icon = icon; + + if (icon) + act->base.icon = eina_stringshare_add(icon); act->name = eina_stringshare_add(name); diff --git a/src/modules/everything/evry_plug_aggregator.c b/src/modules/everything/evry_plug_aggregator.c index 4e265db1f..955df6842 100644 --- a/src/modules/everything/evry_plug_aggregator.c +++ b/src/modules/everything/evry_plug_aggregator.c @@ -30,7 +30,6 @@ _add_item(Plugin *p, Eina_List *items, Evry_Item *it) } } - evry_item_ref(it); items = eina_list_append(items, it); EVRY_PLUGIN_ITEM_APPEND(p, it); @@ -207,8 +206,11 @@ _fetch(Evry_Plugin *plugin, const char *input) } /* EINA_LIST_FOREACH(items, l, it) - * printf("%d %1.20f %s\n", it->fuzzy_match, it->usage, it->label); */ - + * { + * if(CHECK_TYPE(it, EVRY_TYPE_FILE)) + * printf("%d %1.20f %s\n", it->fuzzy_match, it->usage, it->label); + * } */ + if (items) eina_list_free(items); if (lp) eina_list_free(lp); @@ -216,8 +218,11 @@ _fetch(Evry_Plugin *plugin, const char *input) EINA_LIST_FOREACH_SAFE(p->base.items, l, ll, it) { - if (cnt++ < MAX_ITEMS) continue; - evry_item_free(it); + if (cnt++ < MAX_ITEMS) + { + evry_item_ref(it); + continue; + } p->base.items = eina_list_remove_list(p->base.items, l); } diff --git a/src/modules/everything/evry_plug_view_thumb.c b/src/modules/everything/evry_plug_view_thumb.c index 8721121e8..e5281e87c 100644 --- a/src/modules/everything/evry_plug_view_thumb.c +++ b/src/modules/everything/evry_plug_view_thumb.c @@ -101,8 +101,6 @@ _thumb_gen(void *data, Evas_Object *obj, void *event_info) static int _check_item(const Evry_Item *it) { - if (it->type != EVRY_TYPE_FILE) return 0; - GET_FILE(file, it); if (!evry_file_path_get(file) || !file->mime) return 0; @@ -132,21 +130,26 @@ _thumb_idler(void *data) evas_object_show(it->image); } else it->have_thumb = EINA_TRUE; - - /* dirbrowse fetches the mimetype for icon_get */ - if (!it->get_thumb && _check_item(it->item)) - it->get_thumb = EINA_TRUE; } - if (it->get_thumb && !it->thumb && !(it->have_thumb || it->do_thumb)) + if ((CHECK_TYPE(it->item, EVRY_TYPE_FILE)) && + ((!it->thumb && !(it->have_thumb || it->do_thumb)) && + (it->get_thumb || _check_item(it->item) || + (it->item->icon && it->item->icon[0])))) { + it->get_thumb = EINA_TRUE; + it->thumb = e_thumb_icon_add(sd->view->evas); GET_FILE(file, it->item); evas_object_smart_callback_add(it->thumb, "e_thumb_gen", _thumb_gen, it); - e_thumb_icon_file_set(it->thumb, file->path, NULL); + if (it->item->icon && it->item->icon[0]) + e_thumb_icon_file_set(it->thumb, it->item->icon, NULL); + else + e_thumb_icon_file_set(it->thumb, file->path, NULL); + e_thumb_icon_size_set(it->thumb, it->w, it->h); e_thumb_icon_begin(it->thumb); it->do_thumb = EINA_TRUE; @@ -571,9 +574,6 @@ _pan_item_add(Evas_Object *obj, Evry_Item *item) it->item = item; it->changed = EINA_TRUE; - /* if (_check_item(item)) - * it->get_thumb = EINA_TRUE; */ - evry_item_ref(item); _e_smart_reconfigure(obj); @@ -1009,9 +1009,6 @@ _view_update(Evry_View *view, int slide) { v_items = eina_list_append(v_items, v_it->item); - /* if (_check_item(v_it->item)) - * v_it->get_thumb = EINA_TRUE; */ - if (v_it->visible && v_it->changed) update = EINA_TRUE; } diff --git a/src/modules/everything/evry_types.h b/src/modules/everything/evry_types.h index 29b86362e..98c290551 100644 --- a/src/modules/everything/evry_types.h +++ b/src/modules/everything/evry_types.h @@ -187,6 +187,9 @@ struct _Evry_Plugin 'configure' button in everything config */ const char *config_path; + /* set theme file to fetch icons from */ + const char *theme_path; + /* not to be set by plugin! */ Plugin_Config *config; unsigned int request; diff --git a/src/modules/everything/evry_util.c b/src/modules/everything/evry_util.c index de4b8d16b..b6ffe01fa 100644 --- a/src/modules/everything/evry_util.c +++ b/src/modules/everything/evry_util.c @@ -7,6 +7,7 @@ static const char *home_dir = NULL; static int home_dir_len; static char dir_buf[1024]; +static char thumb_buf[4096]; EAPI void evry_util_file_detail_set(Evry_Item_File *file) @@ -68,7 +69,8 @@ evry_fuzzy_match(const char *str, const char *match) unsigned int m_min[MAX_WORDS]; unsigned int m_len = 0; - if (!match || !str) return 0; + if (!match || !str || !match[0] || !str[0]) + return 0; /* remove white spaces at the beginning */ for (; (*match != 0) && isspace(*match); match++); @@ -270,7 +272,7 @@ evry_items_sort_func(const void *data1, const void *data2) if ((act1->it1.type == act1->it1.item->type) && (act2->it1.type != act2->it1.item->type)) return -1; - + if ((act1->it1.type != act1->it1.item->type) && (act2->it1.type == act2->it1.item->type)) return 1; @@ -278,10 +280,16 @@ evry_items_sort_func(const void *data1, const void *data2) /* sort context specific actions before general actions */ - if (act1->remember_context && !act2->remember_context) - return -1; - if (!act1->remember_context && act2->remember_context) - return 1; + if (act1->remember_context) + { + if (!act2->remember_context) + return -1; + } + else + { + if (act2->remember_context) + return 1; + } } /* if (it1->type == EVRY_TYPE_PLUGIN && @@ -488,14 +496,46 @@ evry_icon_mime_get(const char *mime, Evas *e) } static Evas_Object * -_file_icon_get(const Evry_Item *it, Evas *e) +_file_icon_get(Evry_Item *it, Evas *e) { Evas_Object *o = NULL; GET_FILE(file, it); if (it->browseable) - o = evry_icon_theme_get("folder", e); - else if (file->mime) + { + return evry_icon_theme_get("folder", e); + } + + if (it->icon) + { + o = e_icon_add(e); + if (!e_icon_file_set(o, it->icon)) + { + evas_object_del(o); + o = NULL; + } + } + + if ((!o) && (!it->icon) && file->mime && + ((!strncmp(file->mime, "image/", 6)) || + (!strncmp(file->mime, "video/", 6)) || + (!strncmp(file->mime, "application/pdf", 15))) && + (evry_file_url_get(file))) + { + char *sum = evry_util_md5_sum(file->url); + + snprintf(thumb_buf, sizeof(thumb_buf), + "%s/.thumbnails/normal/%s.png", + e_user_homedir_get(), sum); + free(sum); + + if (ecore_file_exists(thumb_buf)) + it->icon = eina_stringshare_add(thumb_buf); + else + it->icon = eina_stringshare_add(""); + } + + if ((!o) && file->mime) o = evry_icon_mime_get(file->mime, e); if (!o) @@ -509,16 +549,16 @@ evry_util_icon_get(Evry_Item *it, Evas *e) { Evas_Object *o = NULL; - if (it->icon_get) - o = it->icon_get(it, e); - - if (!o && it->icon) - o = evry_icon_theme_get(it->icon, e); - if (CHECK_TYPE(it, EVRY_TYPE_FILE)) o = _file_icon_get(it, e); + else + { + if (!o && it->icon_get) + o = it->icon_get(it, e); - /* TODO default type: files, apps */ + if (!o && it->icon) + o = evry_icon_theme_get(it->icon, e); + } return o; } @@ -641,27 +681,29 @@ evry_util_url_unescape(const char *string, int length) if( !ns ) return NULL; - while(--alloc > 0) { - in = *string; - if(('%' == in) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) { - /* this is two hexadecimal digits following a '%' */ - char hexstr[3]; - char *ptr; - hexstr[0] = string[1]; - hexstr[1] = string[2]; - hexstr[2] = 0; + while(--alloc > 0) + { + in = *string; + if(('%' == in) && ISXDIGIT(string[1]) && ISXDIGIT(string[2])) + { + /* this is two hexadecimal digits following a '%' */ + char hexstr[3]; + char *ptr; + hexstr[0] = string[1]; + hexstr[1] = string[2]; + hexstr[2] = 0; - hex = strtoul(hexstr, &ptr, 16); - in = (unsigned char)(hex & (unsigned long) 0xFF); - // in = ultouc(hex); /* this long is never bigger than 255 anyway */ + hex = strtoul(hexstr, &ptr, 16); + in = (unsigned char)(hex & (unsigned long) 0xFF); + // in = ultouc(hex); /* this long is never bigger than 255 anyway */ - string+=2; - alloc-=2; - } + string+=2; + alloc-=2; + } - ns[strindex++] = in; - string++; - } + ns[strindex++] = in; + string++; + } ns[strindex]=0; /* terminate it */ return ns; @@ -692,55 +734,67 @@ _isalnum(unsigned char in) return EINA_FALSE; } -/* FIXME option to not escape '/' */ +char * +_evry_util_url_escape(const char *string, int inlength, int path) +{ + size_t alloc = (inlength?(size_t)inlength:strlen(string))+1; + char *ns; + char *testing_ptr = NULL; + unsigned char in; /* we need to treat the characters unsigned */ + size_t newlen = alloc; + int strindex=0; + size_t length; + + ns = malloc(alloc); + if(!ns) + return NULL; + + length = alloc-1; + while(length--) + { + in = *string; + + if (_isalnum(in) || + (path && ispunct(in))) + { + /* just copy this */ + ns[strindex++]=in; + } + else { + /* encode it */ + newlen += 2; /* the size grows with two, since this'll become a %XX */ + if(newlen > alloc) + { + alloc *= 2; + testing_ptr = realloc(ns, alloc); + if(!testing_ptr) + { + free( ns ); + return NULL; + } + else + { + ns = testing_ptr; + } + } + + snprintf(&ns[strindex], 4, "%%%02X", in); + + strindex+=3; + } + string++; + } + ns[strindex]=0; /* terminate it */ + return ns; +} + EAPI char * evry_util_url_escape(const char *string, int inlength) { - size_t alloc = (inlength?(size_t)inlength:strlen(string))+1; - char *ns; - char *testing_ptr = NULL; - unsigned char in; /* we need to treat the characters unsigned */ - size_t newlen = alloc; - int strindex=0; - size_t length; - - ns = malloc(alloc); - if(!ns) - return NULL; - - length = alloc-1; - while(length--) { - in = *string; - - if (_isalnum(in)) { - /* just copy this */ - ns[strindex++]=in; - } - else { - /* encode it */ - newlen += 2; /* the size grows with two, since this'll become a %XX */ - if(newlen > alloc) { - alloc *= 2; - testing_ptr = realloc(ns, alloc); - if(!testing_ptr) { - free( ns ); - return NULL; - } - else { - ns = testing_ptr; - } - } - - snprintf(&ns[strindex], 4, "%%%02X", in); - - strindex+=3; - } - string++; - } - ns[strindex]=0; /* terminate it */ - return ns; + _evry_util_url_escape(string, inlength, 0); } + EAPI const char* evry_file_path_get(Evry_Item_File *file) { @@ -771,20 +825,27 @@ EAPI const char* evry_file_url_get(Evry_Item_File *file) { char buf[PATH_MAX]; - + char *escaped; + if (file->url) return file->url; if (!file->path) return NULL; - snprintf(buf, sizeof(buf), "file://%s", file->path); + escaped = _evry_util_url_escape(file->path, 0, 1); - /* FIXME escape ? */ + if (escaped) + { + snprintf(buf, sizeof(buf), "file://%s", escaped); + E_FREE(escaped); - file->url = eina_stringshare_add(buf); + file->url = eina_stringshare_add(buf); - return file->url; + return file->url; + } + + return NULL; } static void