Evaluate ZATHURA_LINK_LAUNCH

This commit is contained in:
Moritz Lipp 2012-05-28 02:45:00 +02:00
parent d721721867
commit 2d6a63e6fe
2 changed files with 40 additions and 0 deletions

View File

@ -27,6 +27,14 @@ zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position,
return NULL;
}
link->target.value = g_strdup(target.value);
break;
case ZATHURA_LINK_LAUNCH:
if (target.value == NULL) {
g_free(link);
return NULL;
}
link->target.value = g_strdup(target.value);
break;
default:

32
utils.c
View File

@ -327,6 +327,35 @@ readjust_view_after_zooming(zathura_t *zathura, float old_zoom) {
position_set_delayed(zathura, valx, valy);
}
static void
link_launch(zathura_t* zathura, zathura_link_t* link)
{
if (zathura == NULL || link == NULL || zathura->document == NULL) {
return;
}
/* get file path */
if (link->target.value == NULL) {
return;
};
char* path = NULL;
if (g_path_is_absolute(link->target.value) == TRUE) {
path = g_strdup(link->target.value);
} else {
const char* document = zathura_document_get_path(zathura->document);
char* dir = g_path_get_dirname(document);
path = g_build_filename(dir, link->target.value, NULL);
g_free(dir);
}
if (girara_xdg_open(path) == false) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
}
g_free(path);
}
void
zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
{
@ -346,6 +375,9 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
}
break;
case ZATHURA_LINK_LAUNCH:
link_launch(zathura, link);
break;
default:
break;
}