Introduce new link types

This commit is contained in:
Moritz Lipp 2012-04-22 10:04:46 +02:00
parent 3412f40093
commit adc9f41264
10 changed files with 69 additions and 67 deletions

View file

@ -148,14 +148,8 @@ cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
return;
}
if (index_element->type == ZATHURA_LINK_TO_PAGE) {
zathura_link_evaluate(zathura, index_element->link);
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
page_set_delayed(zathura, index_element->target.page_number);
} else if (index_element->type == ZATHURA_LINK_EXTERNAL) {
if (girara_xdg_open(index_element->target.uri) == false) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
}
}
}
g_object_unref(model);
@ -200,17 +194,7 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
if (eval == true) {
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page_widget), index);
if (link != NULL) {
switch (link->type) {
case ZATHURA_LINK_TO_PAGE:
page_set_delayed(zathura, link->target.page_number);
break;
case ZATHURA_LINK_EXTERNAL:
girara_xdg_open(link->target.uri);
break;
default:
break;
}
zathura_link_evaluate(zathura, link);
invalid_index = false;
}
}

View file

@ -549,16 +549,7 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
zathura_rectangle_t rect = recalc_rectangle(priv->page, link->position);
if (rect.x1 <= button->x && rect.x2 >= button->x
&& rect.y1 <= button->y && rect.y2 >= button->y) {
switch (link->type) {
case ZATHURA_LINK_TO_PAGE:
page_set_delayed(priv->zathura, link->target.page_number);
return false;
case ZATHURA_LINK_EXTERNAL:
girara_xdg_open(link->target.uri);
return false;
default:
return false;
}
zathura_link_evaluate(priv->zathura, link);
}
GIRARA_LIST_FOREACH_END(priv->links, zathura_link_t*, iter, link);
}

20
types.c
View file

@ -17,16 +17,16 @@ zathura_link_new(zathura_link_type_t type, zathura_rectangle_t position,
link->position = position;
switch (type) {
case ZATHURA_LINK_TO_PAGE:
case ZATHURA_LINK_GOTO_DEST:
link->target.page_number = target.page_number;
break;
case ZATHURA_LINK_EXTERNAL:
if (target.uri == NULL) {
case ZATHURA_LINK_URI:
if (target.value == NULL) {
g_free(link);
return NULL;
}
link->target.uri = g_strdup(target.uri);
link->target.value = g_strdup(target.value);
break;
default:
g_free(link);
@ -43,9 +43,9 @@ zathura_link_free(zathura_link_t* link)
return;
}
if (link->type == ZATHURA_LINK_EXTERNAL) {
if (link->target.uri != NULL) {
g_free(link->target.uri);
if (link->type == ZATHURA_LINK_URI) {
if (link->target.value != NULL) {
g_free(link->target.value);
}
}
@ -106,11 +106,7 @@ zathura_index_element_free(zathura_index_element_t* index)
}
g_free(index->title);
if (index->type == ZATHURA_LINK_EXTERNAL) {
g_free(index->target.uri);
}
zathura_link_free(index->link);
g_free(index);
}

16
types.h
View file

@ -130,14 +130,17 @@ typedef struct zathura_image_s
typedef enum zathura_link_type_e
{
ZATHURA_LINK_INVALID, /**< Invalid type */
ZATHURA_LINK_TO_PAGE, /**< Links to a page */
ZATHURA_LINK_EXTERNAL, /**< Links to an external source */
ZATHURA_LINK_GOTO_DEST, /**< Links to a page */
ZATHURA_LINK_GOTO_REMOTE, /**< Links to a page */
ZATHURA_LINK_URI, /**< Links to an external source */
ZATHURA_LINK_LAUNCH, /**< Links to an external source */
ZATHURA_LINK_NAMED, /**< Links to an external source */
} zathura_link_type_t;
typedef union zathura_link_target_u
{
unsigned int page_number; /**< Page number */
char* uri; /**< Value */
char* value; /**< Value */
} zathura_link_target_t;
/**
@ -151,12 +154,7 @@ typedef struct zathura_link_s zathura_link_t;
typedef struct zathura_index_element_s
{
char* title; /**< Title of the element */
zathura_link_type_t type; /**< Type */
union
{
unsigned int page_number; /**< Page number */
char* uri; /**< Uri */
} target;
zathura_link_t* link;
} zathura_index_element_t;
/**

31
utils.c
View file

@ -10,6 +10,8 @@
#include <math.h>
#include <gtk/gtk.h>
#include <girara/session.h>
#include <girara/utils.h>
#include <glib/gi18n.h>
#include "utils.h"
#include "zathura.h"
@ -148,11 +150,14 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent,
GIRARA_LIST_FOREACH(list, girara_tree_node_t*, iter, node)
zathura_index_element_t* index_element = (zathura_index_element_t*)girara_node_get_data(node);
zathura_link_type_t type = zathura_link_get_type(index_element->link);
zathura_link_target_t target = zathura_link_get_target(index_element->link);
gchar* description = NULL;
if (index_element->type == ZATHURA_LINK_TO_PAGE) {
description = g_strdup_printf("Page %d", index_element->target.page_number);
if (type == ZATHURA_LINK_GOTO_DEST) {
description = g_strdup_printf("Page %d", target.page_number);
} else {
description = g_strdup(index_element->target.uri);
description = g_strdup(target.value);
}
GtkTreeIter tree_iter;
@ -322,3 +327,23 @@ readjust_view_after_zooming(zathura_t *zathura, float old_zoom) {
set_adjustment(vadjustment, valy);
}
void
zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
{
if (zathura == NULL || link == NULL) {
return;
}
switch (link->type) {
case ZATHURA_LINK_GOTO_DEST:
page_set_delayed(zathura, link->target.page_number);
break;
case ZATHURA_LINK_URI:
if (girara_xdg_open(link->target.value) == false) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to run xdg-open."));
}
break;
default:
break;
}
}

View file

@ -122,4 +122,12 @@ GtkWidget* zathura_page_get_widget(zathura_t* zathura, zathura_page_t* page);
*/
void readjust_view_after_zooming(zathura_t* zathura, float old_zoom);
/**
* Evaluate link
*
* @param zathura Zathura instance
* @param link The link
*/
void zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link);
#endif // UTILS_H