mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-28 21:36:00 +01:00
Refactor
This commit is contained in:
parent
2899daa838
commit
abb76d8dfe
1 changed files with 75 additions and 69 deletions
130
zathura/links.c
130
zathura/links.c
|
@ -118,75 +118,17 @@ zathura_link_get_target(zathura_link_t* link)
|
|||
}
|
||||
|
||||
static void
|
||||
link_remote(zathura_t* zathura, const char* file)
|
||||
link_goto_dest(zathura_t* zathura, const zathura_link_t* link)
|
||||
{
|
||||
if (zathura == NULL || file == NULL || zathura->document == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* path = zathura_document_get_path(zathura->document);
|
||||
char* dir = g_path_get_dirname(path);
|
||||
char* uri = g_build_filename(dir, file, NULL);
|
||||
|
||||
char* argv[] = {
|
||||
*(zathura->global.arguments),
|
||||
uri,
|
||||
NULL
|
||||
};
|
||||
|
||||
GError* error = NULL;
|
||||
if (g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error) == FALSE) {
|
||||
girara_error("Failed to execute command: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
g_free(uri);
|
||||
g_free(dir);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
if (zathura == NULL || zathura->document == NULL || link == NULL) {
|
||||
if (link->target.destination_type == ZATHURA_LINK_DESTINATION_UNKNOWN) {
|
||||
girara_warning("link destination type unknown");
|
||||
return;
|
||||
}
|
||||
|
||||
bool link_zoom = true;
|
||||
girara_setting_get(zathura->ui.session, "link-zoom", &link_zoom);
|
||||
|
||||
switch (link->type) {
|
||||
case ZATHURA_LINK_GOTO_DEST:
|
||||
if (link->target.destination_type != ZATHURA_LINK_DESTINATION_UNKNOWN) {
|
||||
if (link->target.zoom >= DBL_EPSILON && link_zoom) {
|
||||
if (link->target.zoom >= DBL_EPSILON && link_zoom == true) {
|
||||
zathura_document_set_zoom(zathura->document,
|
||||
zathura_correct_zoom_value(zathura->ui.session, link->target.zoom));
|
||||
render_all(zathura);
|
||||
|
@ -196,6 +138,7 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
|
|||
zathura_page_t* page = zathura_document_get_page(zathura->document,
|
||||
link->target.page_number);
|
||||
if (page == NULL) {
|
||||
girara_warning("link to non-existing page %u", link->target.page_number);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -245,7 +188,70 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
|
|||
zathura_document_set_current_page_number(zathura->document, link->target.page_number);
|
||||
position_set(zathura, pos_x, pos_y);
|
||||
zathura_jumplist_add(zathura);
|
||||
}
|
||||
|
||||
static void
|
||||
link_remote(zathura_t* zathura, const char* file)
|
||||
{
|
||||
if (zathura == NULL || file == NULL || zathura->document == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char* path = zathura_document_get_path(zathura->document);
|
||||
char* dir = g_path_get_dirname(path);
|
||||
char* uri = g_build_filename(dir, file, NULL);
|
||||
|
||||
char* argv[] = {
|
||||
*(zathura->global.arguments),
|
||||
uri,
|
||||
NULL
|
||||
};
|
||||
|
||||
GError* error = NULL;
|
||||
if (g_spawn_async(NULL, argv, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, &error) == FALSE) {
|
||||
girara_error("Failed to execute command: %s", error->message);
|
||||
g_error_free(error);
|
||||
}
|
||||
|
||||
g_free(uri);
|
||||
g_free(dir);
|
||||
}
|
||||
|
||||
static void
|
||||
link_launch(zathura_t* zathura, const zathura_link_t* link)
|
||||
{
|
||||
/* 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)
|
||||
{
|
||||
if (zathura == NULL || zathura->document == NULL || link == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (link->type) {
|
||||
case ZATHURA_LINK_GOTO_DEST:
|
||||
link_goto_dest(zathura, link);
|
||||
break;
|
||||
case ZATHURA_LINK_GOTO_REMOTE:
|
||||
link_remote(zathura, link->target.value);
|
||||
|
|
Loading…
Reference in a new issue