utils: add open_url() to avoid code duplication
This commit is contained in:
parent
6122b12e4f
commit
7465f46a9f
|
@ -8,6 +8,7 @@
|
||||||
#include "colors.h"
|
#include "colors.h"
|
||||||
#include "options_colors.h"
|
#include "options_colors.h"
|
||||||
#include "options_themepv.h"
|
#include "options_themepv.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
typedef struct _Color_Scheme_Ctx
|
typedef struct _Color_Scheme_Ctx
|
||||||
{
|
{
|
||||||
|
@ -48,10 +49,6 @@ _cb_ctxp_del(void *data,
|
||||||
Color_Scheme_Info *csi = data;
|
Color_Scheme_Info *csi = data;
|
||||||
EINA_SAFETY_ON_NULL_RETURN(csi);
|
EINA_SAFETY_ON_NULL_RETURN(csi);
|
||||||
csi->ctx->ctxpopup = NULL;
|
csi->ctx->ctxpopup = NULL;
|
||||||
|
|
||||||
/* Force refocus */
|
|
||||||
//term_unfocus(sd->term);
|
|
||||||
//term_focus(sd->term);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -72,47 +69,12 @@ _cb_ctxp_open_website(void *data,
|
||||||
{
|
{
|
||||||
Color_Scheme_Info *csi = data;
|
Color_Scheme_Info *csi = data;
|
||||||
Color_Scheme_Ctx *ctx;
|
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);
|
EINA_SAFETY_ON_NULL_RETURN(csi);
|
||||||
ctx = csi->ctx;
|
ctx = csi->ctx;
|
||||||
config = ctx->config;
|
|
||||||
|
|
||||||
if (!(config->helper.url.general) ||
|
open_url(ctx->config, csi->cs->md.website);
|
||||||
!(config->helper.url.general[0]))
|
|
||||||
goto end;
|
|
||||||
cmd = config->helper.url.general;
|
|
||||||
|
|
||||||
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;
|
ctx->ctxpopup = NULL;
|
||||||
evas_object_del(obj);
|
evas_object_del(obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2686,53 +2686,18 @@ _cb_ctxp_sel_open_as_url(void *data,
|
||||||
{
|
{
|
||||||
Evas_Object *term = data;
|
Evas_Object *term = data;
|
||||||
Termio *sd = evas_object_smart_data_get(term);
|
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_Strbuf *sb = NULL;
|
||||||
|
|
||||||
EINA_SAFETY_ON_NULL_RETURN(sd);
|
EINA_SAFETY_ON_NULL_RETURN(sd);
|
||||||
config = sd->config;
|
|
||||||
|
|
||||||
termio_take_selection(data, ELM_SEL_TYPE_PRIMARY);
|
termio_take_selection(data, ELM_SEL_TYPE_PRIMARY);
|
||||||
|
|
||||||
if (!sd->have_sel || !sd->sel_str)
|
if (!sd->have_sel || !sd->sel_str)
|
||||||
goto end;
|
goto end;
|
||||||
|
|
||||||
if (!(config->helper.url.general) ||
|
open_url(sd->config, sd->sel_str);
|
||||||
!(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);
|
|
||||||
|
|
||||||
end:
|
end:
|
||||||
eina_strbuf_free(sb);
|
|
||||||
free(escaped);
|
|
||||||
free(s);
|
|
||||||
sd->ctxpopup = NULL;
|
sd->ctxpopup = NULL;
|
||||||
evas_object_del(obj);
|
evas_object_del(obj);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#include "private.h"
|
#include "private.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
#include "sb.h"
|
||||||
|
#include <Ecore.h>
|
||||||
|
#include <Ecore_File.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
|
@ -21,3 +24,51 @@ homedir_get(char *buf, size_t size)
|
||||||
return eina_strlcpy(buf, home, size) < 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);
|
||||||
|
}
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
#define _UTILS_H__
|
#define _UTILS_H__
|
||||||
|
|
||||||
#include <Eina.h>
|
#include <Eina.h>
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
Eina_Bool homedir_get(char *buf, size_t size);
|
Eina_Bool homedir_get(char *buf, size_t size);
|
||||||
|
void open_url(const Config *config, const char *url);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue