Evas_Object *img;
const char *stdicon;
Elm_Icon_Lookup_Order lookup_order;
+
+#ifdef HAVE_ELEMENTARY_ETHUMB
+ struct {
+ int id;
+
+ struct {
+ const char *path;
+ const char *key;
+ } file, thumb;
+
+ Ethumb_Exists *exists;
+
+ Ecore_Event_Handler *eeh;
+
+ Ethumb_Thumb_Format format;
+
+ Eina_Bool retry : 1;
+ } thumb;
+#endif
+
#ifdef ELM_EFREET
struct {
int requested_size;
Eina_Bool no_scale : 1;
};
+#ifdef HAVE_ELEMENTARY_ETHUMB
+static Eina_List *_elm_icon_retry = NULL;
+static int _icon_pending_request = 0;
+
+static void _icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data);
+#endif
+
static const char *widtype = NULL;
static void _del_hook(Evas_Object *obj);
static void _theme_hook(Evas_Object *obj);
}
#endif
+#ifdef HAVE_ELEMENTARY_ETHUMB
+static void
+_icon_thumb_stop(Widget_Data *wd, void *ethumbd)
+{
+ if (wd->thumb.id > 0)
+ {
+ ethumb_client_generate_cancel(ethumbd, wd->thumb.id, NULL, NULL, NULL);
+ wd->thumb.id = -1;
+ _icon_pending_request--;
+ }
+
+ if (wd->thumb.exists)
+ {
+ ethumb_client_thumb_exists_cancel(wd->thumb.exists, _icon_thumb_exists, wd);
+ wd->thumb.exists = NULL;
+ _icon_pending_request--;
+ }
+
+ if (wd->thumb.retry)
+ {
+ _elm_icon_retry = eina_list_remove(_elm_icon_retry, wd);
+ wd->thumb.retry = EINA_FALSE;
+ }
+}
+
+static Eina_Bool
+_icon_thumb_display(Widget_Data *wd)
+{
+ Eina_Bool ret = EINA_FALSE;
+
+ if (wd->thumb.format == ETHUMB_THUMB_EET)
+ {
+ static const char *extensions[] = {
+ ".avi", ".mp4", ".ogv", ".mov", ".mpg", ".wmv", NULL
+ };
+ const char **ext, *ptr;
+ int prefix_size;
+ Eina_Bool video = EINA_FALSE;
+
+ prefix_size = eina_stringshare_strlen(wd->thumb.file.path) - 4;
+ if (prefix_size >= 0)
+ {
+ ptr = wd->thumb.file.path + prefix_size;
+ for (ext = extensions; *ext; ++ext)
+ if (!strcasecmp(ptr, *ext))
+ {
+ video = EINA_TRUE;
+ break;
+ }
+ }
+
+ if (video)
+ ret = _els_smart_icon_file_edje_set(wd->img, wd->thumb.thumb.path, "movie/thumb");
+ }
+
+ if (!ret)
+ ret = _els_smart_icon_file_key_set(wd->img, wd->thumb.thumb.path, wd->thumb.thumb.key);
+
+ return ret;
+}
+
+static Eina_Bool
+_icon_thumb_retry(Widget_Data *wd)
+{
+ return _icon_thumb_display(wd);
+}
+
+static void
+_icon_thumb_cleanup(Ethumb_Client *ethumbd)
+{
+ Eina_List *l, *ll;
+ Widget_Data *wd;
+
+ EINA_LIST_FOREACH_SAFE(_elm_icon_retry, l, ll, wd)
+ if (_icon_thumb_retry(wd))
+ {
+ _elm_icon_retry = eina_list_remove_list(_elm_icon_retry, l);
+ wd->thumb.retry = EINA_FALSE;
+ }
+
+ if (_icon_pending_request == 0)
+ EINA_LIST_FREE(_elm_icon_retry, wd)
+ _icon_thumb_stop(wd, ethumbd);
+}
+
+static void
+_icon_thumb_finish(Widget_Data *wd, Ethumb_Client *ethumbd)
+{
+ const char *file, *group;
+ Eina_Bool ret;
+
+ _els_smart_icon_file_get(wd->img, &file, &group);
+ file = eina_stringshare_ref(file);
+ group = eina_stringshare_ref(group);
+
+ ret = _icon_thumb_display(wd);
+
+ if (!ret)
+ {
+ const char *p;
+
+ if (!wd->thumb.retry)
+ {
+ _elm_icon_retry = eina_list_append(_elm_icon_retry, wd);
+ wd->thumb.retry = EINA_TRUE;
+ }
+
+ /* Back to previous image */
+ if (((p = strrchr(file, '.'))) && (!strcasecmp(p, ".edj")))
+ _els_smart_icon_file_edje_set(wd->img, file, group);
+ else
+ _els_smart_icon_file_key_set(wd->img, file, group);
+ }
+
+ _icon_thumb_cleanup(ethumbd);
+
+ eina_stringshare_del(file);
+ eina_stringshare_del(group);
+}
+
+static void
+_icon_thumb_cb(void *data,
+ Ethumb_Client *ethumbd,
+ int id,
+ const char *file __UNUSED__,
+ const char *key __UNUSED__,
+ const char *thumb_path,
+ const char *thumb_key,
+ Eina_Bool success)
+{
+ Widget_Data *wd = data;
+
+ EINA_SAFETY_ON_FALSE_RETURN(wd->thumb.id == id);
+ wd->thumb.id = -1;
+
+ _icon_pending_request--;
+
+ if (success)
+ {
+ eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
+ eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
+ wd->thumb.format = ethumb_client_format_get(ethumbd);
+
+ _icon_thumb_finish(wd, ethumbd);
+ }
+ else
+ {
+ ERR("could not generate thumbnail for %s (key: %s)", file, key);
+ _icon_thumb_cleanup(ethumbd);
+ }
+}
+
+static void
+_icon_thumb_exists(Ethumb_Client *client __UNUSED__, Ethumb_Exists *thread, Eina_Bool exists, void *data)
+{
+ Widget_Data *wd = data;
+ Ethumb_Client *ethumbd;
+
+ if (ethumb_client_thumb_exists_check(thread))
+ return ;
+
+ wd->thumb.exists = NULL;
+
+ ethumbd = elm_thumb_ethumb_client_get();
+
+ if (exists)
+ {
+ const char *thumb_path, *thumb_key;
+
+ _icon_pending_request--;
+ ethumb_client_thumb_path_get(ethumbd, &thumb_path, &thumb_key);
+ eina_stringshare_replace(&wd->thumb.thumb.path, thumb_path);
+ eina_stringshare_replace(&wd->thumb.thumb.key, thumb_key);
+ wd->thumb.format = ethumb_client_format_get(ethumbd);
+
+ _icon_thumb_finish(wd, ethumbd);
+ }
+ else if ((wd->thumb.id = ethumb_client_generate(ethumbd, _icon_thumb_cb, wd, NULL)) == -1)
+ {
+ /* Failed to generate thumbnail */
+ _icon_pending_request--;
+ }
+}
+
+static void
+_icon_thumb_apply(Widget_Data *wd)
+{
+ Ethumb_Client *ethumbd;
+
+ ethumbd = elm_thumb_ethumb_client_get();
+
+ _icon_thumb_stop(wd, ethumbd);
+
+ if (!wd->thumb.file.path) return ;
+
+ _icon_pending_request++;
+ ethumb_client_file_set(ethumbd, wd->thumb.file.path, wd->thumb.file.key);
+ ethumb_client_size_set(ethumbd, 32, 32);
+ wd->thumb.exists = ethumb_client_thumb_exists(ethumbd, _icon_thumb_exists, wd);
+}
+
+static Eina_Bool
+_icon_thumb_apply_cb(void *data, int type __UNUSED__, void *ev __UNUSED__)
+{
+ Widget_Data *wd = data;
+
+ _icon_thumb_apply(wd);
+ return ECORE_CALLBACK_RENEW;
+}
+#endif
+
static void
_del_hook(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
+#ifdef HAVE_ELEMENTARY_ETHUMB
+ Ethumb_Client *ethumbd;
+#endif
if (!wd) return;
if (wd->stdicon) eina_stringshare_del(wd->stdicon);
+
+#ifdef HAVE_ELEMENTARY_ETHUMB
+ ethumbd = elm_thumb_ethumb_client_get();
+ _icon_thumb_stop(wd, ethumbd);
+
+ eina_stringshare_del(wd->thumb.file.path);
+ eina_stringshare_del(wd->thumb.file.key);
+ eina_stringshare_del(wd->thumb.thumb.path);
+ eina_stringshare_del(wd->thumb.thumb.key);
+
+ if (wd->thumb.eeh)
+ ecore_event_handler_del(wd->thumb.eeh);
+#endif
+
free(wd);
}
evas_object_smart_callbacks_descriptions_set(obj, _signals);
+#ifdef HAVE_ELEMENTARY_ETHUMB
+ wd->thumb.id = -1;
+#endif
+
wd->smooth = EINA_TRUE;
wd->scale_up = EINA_TRUE;
wd->scale_down = EINA_TRUE;
_els_smart_icon_file_get(wd->img, file, group);
}
+EAPI void
+elm_icon_thumb_set(const Evas_Object *obj, const char *file, const char *group)
+{
+ ELM_CHECK_WIDTYPE(obj, widtype);
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+#ifdef HAVE_ELEMENTARY_ETHUMB
+ eina_stringshare_replace(&wd->thumb.file.path, file);
+ eina_stringshare_replace(&wd->thumb.file.key, group);
+
+ if (elm_thumb_ethumb_client_connected())
+ {
+ _icon_thumb_apply(wd);
+ return ;
+ }
+
+ if (!wd->thumb.eeh)
+ {
+ wd->thumb.eeh = ecore_event_handler_add(ELM_ECORE_EVENT_ETHUMB_CONNECT, _icon_thumb_apply_cb, wd);
+ }
+#else
+ (void) obj;
+ (void) file;
+ (void) group;
+#endif
+}
+
static Eina_Bool
_icon_standard_set(Widget_Data *wd, Evas_Object *obj, const char *name)
{