refactor url handling.

there are still some left to be done, will come to it later.



SVN revision: 77653
This commit is contained in:
Gustavo Sverzut Barbieri 2012-10-09 15:11:09 +00:00
parent 5bfed09e13
commit 2a0e0fd2b4
4 changed files with 37 additions and 28 deletions

View File

@ -112,19 +112,17 @@ _activate_link(Evas_Object *obj)
if (!config) return; if (!config) return;
if (!sd->link.string) return; if (!sd->link.string) return;
if (link_is_url(sd->link.string)) if (link_is_url(sd->link.string))
url = EINA_TRUE;
else if ((!strncasecmp(sd->link.string, "file://", 7)) ||
(!strncasecmp(sd->link.string, "/", 1)))
{ {
path = sd->link.string; if (!strncasecmp(sd->link.string, "file://", 7))
if (!strncasecmp(sd->link.string, "file://", 7)) path = path + 7; // TODO: decode string: %XX -> char
} path = sd->link.string + sizeof("file://") - 1;
else else
{ url = EINA_TRUE;
const char *at = strchr(sd->link.string, '@');
if (at && (strchr(at + 1, '.')))
email = EINA_TRUE;
} }
else if (sd->link.string[0] == '/')
path = sd->link.string;
else if (link_is_email(sd->link.string))
email = EINA_TRUE;
s = eina_str_escape(sd->link.string); s = eina_str_escape(sd->link.string);
if (!s) return; if (!s) return;

View File

@ -1,6 +1,7 @@
#include "private.h" #include "private.h"
#include <Elementary.h> #include <Elementary.h>
#include "termio.h" #include "termio.h"
#include "utils.h"
static Eina_Bool static Eina_Bool
coord_back(int *x, int *y, int w, int h __UNUSED__) coord_back(int *x, int *y, int w, int h __UNUSED__)
@ -56,10 +57,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r
if (!s) break; if (!s) break;
if (goback) if (goback)
{ {
if ((!strncasecmp(s, "http://", 7))|| if (link_is_protocol(s))
(!strncasecmp(s, "https://", 8)) ||
(!strncasecmp(s, "file://", 7)) ||
(!strncasecmp(s, "ftp://", 6)))
{ {
goback = EINA_FALSE; goback = EINA_FALSE;
coord_back(&x1, &y1, w, h); coord_back(&x1, &y1, w, h);
@ -87,7 +85,7 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r
else if (s[0] == '<') endmatch = '>'; else if (s[0] == '<') endmatch = '>';
if ((!strncasecmp((s + 1), "www.", 4)) || if ((!strncasecmp((s + 1), "www.", 4)) ||
(!strncasecmp((s + 1), "ftp.", 4)) || (!strncasecmp((s + 1), "ftp.", 4)) ||
(!strncasecmp((s + 1), "/", 1))) (s[1] == '/'))
{ {
goback = EINA_FALSE; goback = EINA_FALSE;
coord_forward(&x1, &y1, w, h); coord_forward(&x1, &y1, w, h);
@ -160,17 +158,9 @@ _termio_link_find(Evas_Object *obj, int cx, int cy, int *x1r, int *y1r, int *x2r
} }
if ((!isspace(s[0])) && (len > 1)) if ((!isspace(s[0])) && (len > 1))
{ {
const char *at = strchr(s, '@'); if (link_is_email(s) ||
link_is_url(s) ||
if ((at && (strchr(at + 1, '.'))) || (s[0] == '/'))
(!strncasecmp(s, "http://", 7))||
(!strncasecmp(s, "https://", 8)) ||
(!strncasecmp(s, "ftp://", 6)) ||
(!strncasecmp(s, "file://", 7)) ||
(!strncasecmp(s, "www.", 4)) ||
(!strncasecmp(s, "ftp.", 4)) ||
(!strncasecmp(s, "/", 1))
)
{ {
if (x1r) *x1r = x1; if (x1r) *x1r = x1;
if (y1r) *y1r = y1; if (y1r) *y1r = y1;

View File

@ -52,13 +52,31 @@ theme_auto_reload_enable(Evas_Object *edje)
} }
Eina_Bool Eina_Bool
link_is_url(const char *str) link_is_protocol(const char *str)
{ {
if ((!strncasecmp(str, "http://", 7))|| if ((!strncasecmp(str, "http://", 7))||
(!strncasecmp(str, "https://", 8)) || (!strncasecmp(str, "https://", 8)) ||
(!strncasecmp(str, "ftp://", 6)) || (!strncasecmp(str, "ftp://", 6)) ||
(!strncasecmp(str, "file://", 7)))
return EINA_TRUE;
return EINA_FALSE;
}
Eina_Bool
link_is_url(const char *str)
{
if (link_is_protocol(str) ||
(!strncasecmp(str, "www.", 4)) || (!strncasecmp(str, "www.", 4)) ||
(!strncasecmp(str, "ftp.", 4))) (!strncasecmp(str, "ftp.", 4)))
return EINA_TRUE; return EINA_TRUE;
return EINA_FALSE; return EINA_FALSE;
} }
Eina_Bool
link_is_email(const char *str)
{
const char *at = strchr(str, '@');
if (at && strchr(at + 1, '.'))
return EINA_TRUE;
return EINA_FALSE;
}

View File

@ -7,6 +7,9 @@
Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group); Eina_Bool theme_apply(Evas_Object *edje, const Config *config, const char *group);
void theme_reload(Evas_Object *edje); void theme_reload(Evas_Object *edje);
void theme_auto_reload_enable(Evas_Object *edje); void theme_auto_reload_enable(Evas_Object *edje);
Eina_Bool link_is_protocol(const char *str);
Eina_Bool link_is_url(const char *str); Eina_Bool link_is_url(const char *str);
Eina_Bool link_is_email(const char *str);
#endif #endif