aboutsummaryrefslogtreecommitdiffstats
path: root/src/bin/gravatar.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-10-06 23:15:44 +0200
committerBoris Faure <billiob@gmail.com>2014-10-15 21:44:58 +0200
commite8050e6e281f00619d4ff7936ab6c1c7cc9c63c8 (patch)
treeed5a1d4eae463af441ad3a2947abb1b8fbe6311d /src/bin/gravatar.c
parentadd md5.c,h (diff)
downloadterminology-e8050e6e281f00619d4ff7936ab6c1c7cc9c63c8.tar.gz
gravatar: use a tooltip
Diffstat (limited to 'src/bin/gravatar.c')
-rw-r--r--src/bin/gravatar.c69
1 files changed, 67 insertions, 2 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