billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=e8050e6e281f00619d4ff7936ab6c1c7cc9c63c8

commit e8050e6e281f00619d4ff7936ab6c1c7cc9c63c8
Author: Boris Faure <bill...@gmail.com>
Date:   Mon Oct 6 23:15:44 2014 +0200

    gravatar: use a tooltip
---
 src/bin/gravatar.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/bin/gravatar.h |  3 ++-
 src/bin/termio.c   |  8 +++----
 3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/src/bin/gravatar.c b/src/bin/gravatar.c
index 3d6f741..f266c36 100644
--- a/src/bin/gravatar.c
+++ b/src/bin/gravatar.c
@@ -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__)
 
+#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(const char *email)
+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);
 
-   /* TODO */
+   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
diff --git a/src/bin/gravatar.h b/src/bin/gravatar.h
index 2cd35e3..3336777 100644
--- a/src/bin/gravatar.h
+++ b/src/bin/gravatar.h
@@ -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);
diff --git a/src/bin/termio.c b/src/bin/termio.c
index a6eda03..611b255 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -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);
+          }
      }
 }
 

-- 


Reply via email to