diff --git a/src/bin/options_colors.c b/src/bin/options_colors.c index dc3523c7..e6f62230 100644 --- a/src/bin/options_colors.c +++ b/src/bin/options_colors.c @@ -8,6 +8,7 @@ #include "colors.h" #include "options_colors.h" #include "options_themepv.h" +#include "utils.h" typedef struct _Color_Scheme_Ctx { @@ -48,10 +49,6 @@ _cb_ctxp_del(void *data, Color_Scheme_Info *csi = data; EINA_SAFETY_ON_NULL_RETURN(csi); csi->ctx->ctxpopup = NULL; - - /* Force refocus */ - //term_unfocus(sd->term); - //term_focus(sd->term); } static void @@ -72,47 +69,12 @@ _cb_ctxp_open_website(void *data, { Color_Scheme_Info *csi = data; Color_Scheme_Ctx *ctx; - Config *config; - char buf[PATH_MAX], *s = NULL, *escaped = NULL; - const char *cmd; - const char *prefix = "http://"; - Eina_Strbuf *sb = NULL; EINA_SAFETY_ON_NULL_RETURN(csi); ctx = csi->ctx; - config = ctx->config; - if (!(config->helper.url.general) || - !(config->helper.url.general[0])) - goto end; - cmd = config->helper.url.general; + open_url(ctx->config, csi->cs->md.website); - sb = eina_strbuf_new(); - if (!sb) - goto end; - eina_strbuf_append(sb, csi->cs->md.website); - eina_strbuf_trim(sb); - - s = eina_str_escape(eina_strbuf_string_get(sb)); - if (!s) - goto end; - if (casestartswith(s, "http://") || - casestartswith(s, "https://")) - prefix = ""; - - escaped = ecore_file_escape_name(s); - if (!escaped) - goto end; - - snprintf(buf, sizeof(buf), "%s %s%s", cmd, prefix, escaped); - - WRN("trying to launch '%s'", buf); - ecore_exe_run(buf, NULL); - -end: - eina_strbuf_free(sb); - free(escaped); - free(s); ctx->ctxpopup = NULL; evas_object_del(obj); } diff --git a/src/bin/termio.c b/src/bin/termio.c index 26234a9f..18921295 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -2686,53 +2686,18 @@ _cb_ctxp_sel_open_as_url(void *data, { Evas_Object *term = data; Termio *sd = evas_object_smart_data_get(term); - char buf[PATH_MAX], *s = NULL, *escaped = NULL; - const char *cmd; - const char *prefix = "http://"; - Config *config; Eina_Strbuf *sb = NULL; EINA_SAFETY_ON_NULL_RETURN(sd); - config = sd->config; termio_take_selection(data, ELM_SEL_TYPE_PRIMARY); if (!sd->have_sel || !sd->sel_str) goto end; - if (!(config->helper.url.general) || - !(config->helper.url.general[0])) - goto end; - cmd = config->helper.url.general; - - sb = eina_strbuf_new(); - if (!sb) - goto end; - eina_strbuf_append(sb, sd->sel_str); - eina_strbuf_trim(sb); - - s = eina_str_escape(eina_strbuf_string_get(sb)); - if (!s) - goto end; - if (casestartswith(s, "http://") || - casestartswith(s, "https://") || - casestartswith(s, "ftp://") || - casestartswith(s, "mailto:")) - prefix = ""; - - escaped = ecore_file_escape_name(s); - if (!escaped) - goto end; - - snprintf(buf, sizeof(buf), "%s %s%s", cmd, prefix, escaped); - - WRN("trying to launch '%s'", buf); - ecore_exe_run(buf, NULL); + open_url(sd->config, sd->sel_str); end: - eina_strbuf_free(sb); - free(escaped); - free(s); sd->ctxpopup = NULL; evas_object_del(obj); } diff --git a/src/bin/utils.c b/src/bin/utils.c index 34522234..0a90aaa6 100644 --- a/src/bin/utils.c +++ b/src/bin/utils.c @@ -1,5 +1,8 @@ #include "private.h" #include "utils.h" +#include "sb.h" +#include +#include #include #include @@ -21,3 +24,51 @@ homedir_get(char *buf, size_t size) return eina_strlcpy(buf, home, size) < size; } + +void +open_url(const Config *config, const char *url) +{ + char buf[PATH_MAX], *s = NULL, *escaped = NULL; + const char *cmd; + const char *prefix = "http://"; + Eina_Strbuf *sb = NULL; + + EINA_SAFETY_ON_NULL_RETURN(config); + + if (!(config->helper.url.general) || + !(config->helper.url.general[0])) + return; + if (!url || url[0] == '\0') + return; + + cmd = config->helper.url.general; + + sb = eina_strbuf_new(); + if (!sb) + return; + eina_strbuf_append(sb, url); + eina_strbuf_trim(sb); + + s = eina_str_escape(eina_strbuf_string_get(sb)); + if (!s) + goto end; + if (casestartswith(s, "http://") || + casestartswith(s, "https://") || + casestartswith(s, "ftp://") || + casestartswith(s, "mailto:")) + prefix = ""; + + escaped = ecore_file_escape_name(s); + if (!escaped) + goto end; + + snprintf(buf, sizeof(buf), "%s %s%s", cmd, prefix, escaped); + + WRN("trying to launch '%s'", buf); + ecore_exe_run(buf, NULL); + +end: + eina_strbuf_free(sb); + free(escaped); + free(s); +} diff --git a/src/bin/utils.h b/src/bin/utils.h index c08ec43f..3706212d 100644 --- a/src/bin/utils.h +++ b/src/bin/utils.h @@ -2,6 +2,9 @@ #define _UTILS_H__ #include +#include "config.h" + Eina_Bool homedir_get(char *buf, size_t size); +void open_url(const Config *config, const char *url); #endif