gravatar: use a tooltip

This commit is contained in:
Boris Faure 2014-10-06 23:15:44 +02:00
parent c33409048f
commit e8050e6e28
3 changed files with 75 additions and 9 deletions

View File

@ -3,6 +3,10 @@
#include <Elementary.h>
#include "gravatar.h"
#include "config.h"
#include "termio.h"
#include "media.h"
#include "md5/md5.h"
/* specific log domain to help debug the gravatar module */
int _gravatar_log_dom = -1;
@ -19,12 +23,73 @@ int _gravatar_log_dom = -1;
#define INF(...) EINA_LOG_DOM_INFO(_gravatar_log_dom, __VA_ARGS__)
#define DBG(...) EINA_LOG_DOM_DBG (_gravatar_log_dom, __VA_ARGS__)
void
gravatar_tooltip(const char *email)
{
DBG("need to show tooltip for email:%s", email);
#define GRAVATAR_URL_START "http://www.gravatar.com/avatar/"
#define GRAVATAR_URL_END ""
static Evas_Object *
_tooltip_content(void *data,
Evas_Object *obj,
Evas_Object *tt EINA_UNUSED)
{
const char *url = data;
Evas_Object *o;
o = elm_label_add(obj);
elm_object_text_set(o, url);
DBG("url:%s", url);
/* TODO */
//o = media_add(obj, url, config, MEDIA_TOOLTIP, &type);
return o;
}
static void
_tooltip_del(void *data,
Evas_Object *obj EINA_UNUSED,
void *event_info EINA_UNUSED)
{
const char *url = data;
DBG("url:%s", url);
eina_stringshare_del(data);
}
void
gravatar_tooltip(Evas_Object *obj, char *email)
{
int n;
MD5_CTX ctx;
char md5out[(2 * MD5_HASHBYTES) + 1];
unsigned char hash[MD5_HASHBYTES];
static const char hex[] = "0123456789abcdef";
const char *url;
//int type;
//Config *config = termio_config_get(obj);
DBG("need to show tooltip for email:%s", email);
eina_str_tolower(&email);
DBG("lower:%s", email);
MD5Init(&ctx);
MD5Update(&ctx, (unsigned char const*)email, (unsigned)strlen(email));
MD5Final(hash, &ctx);
for (n = 0; n < MD5_HASHBYTES; n++)
{
md5out[2 * n] = hex[hash[n] >> 4];
md5out[2 * n + 1] = hex[hash[n] & 0x0f];
}
md5out[2 * MD5_HASHBYTES] = '\0';
DBG("md5:%s", md5out);
url = eina_stringshare_printf(GRAVATAR_URL_START"%s"GRAVATAR_URL_END,
md5out);
DBG("url:%s", url);
elm_object_tooltip_content_cb_set(obj, _tooltip_content,
(void *) url,
_tooltip_del);
}
void

View File

@ -1,7 +1,8 @@
#ifndef _GRAVATAR_H__
#define _GRAVATAR_H__ 1
void gravatar_tooltip(const char *email);
void
gravatar_tooltip(Evas_Object *obj, char *email);
void gravatar_init(void);
void gravatar_shutdown(void);

View File

@ -1147,10 +1147,6 @@ _update_link(Evas_Object *obj, Termio *sd,
#endif
ty_dbus_link_mousein(xwin, sd->link.string, _x, _y);
}
if ((!popup_exists) && link_is_email(sd->link.string))
{
gravatar_tooltip(sd->link.string);
}
for (y = sd->link.y1; y <= sd->link.y2; y++)
{
o = edje_object_add(evas_object_evas_get(obj));
@ -1192,6 +1188,10 @@ _update_link(Evas_Object *obj, Termio *sd,
_cb_link_up, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_MOVE,
_cb_link_move, obj);
if ((!popup_exists) && link_is_email(sd->link.string))
{
gravatar_tooltip(o, sd->link.string);
}
}
}