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) {
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."));
}
}
zathura_link_evaluate(zathura, index_element->link);
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
}
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

@ -385,14 +385,14 @@ plain_set_fileinfo(zathura_database_t* db, const char* file, zathura_fileinfo_t*
char* tmp = g_strdup_printf("%f", file_info->scale);
g_key_file_set_string (priv->history, name, KEY_SCALE, tmp);
g_free(tmp);
g_free(tmp);
g_key_file_set_integer(priv->history, name, KEY_ROTATE, file_info->rotation);
g_key_file_set_integer(priv->history, name, KEY_PAGES_PER_ROW, file_info->pages_per_row);
tmp = g_strdup_printf("%f", file_info->position_x);
g_key_file_set_string(priv->history, name, KEY_POSITION_X, tmp);
g_free(tmp);
g_free(tmp);
tmp = g_strdup_printf("%f", file_info->position_y);
g_key_file_set_string(priv->history, name, KEY_POSITION_Y, tmp);

View file

@ -22,7 +22,7 @@ static girara_list_t* sqlite_load_bookmarks(zathura_database_t* db,
static bool sqlite_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info);
static bool sqlite_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info);
zathura_fileinfo_t* file_info);
static void sqlite_set_property(GObject* object, guint prop_id,
const GValue* value, GParamSpec* pspec);
@ -280,8 +280,8 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info)
{
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
@ -314,11 +314,11 @@ sqlite_set_fileinfo(zathura_database_t* db, const char* file,
static bool
sqlite_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info)
zathura_fileinfo_t* file_info)
{
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
if (db == NULL || file == NULL || file_info == NULL) {
return false;
}
zathura_sqldatabase_private_t* priv = ZATHURA_SQLDATABASE_GET_PRIVATE(db);
@ -327,7 +327,7 @@ sqlite_get_fileinfo(zathura_database_t* db, const char* file,
sqlite3_stmt* stmt = prepare_statement(priv->session, SQL_FILEINFO_GET);
if (stmt == NULL) {
return false;
return false;
}
if (sqlite3_bind_text(stmt, 1, file, -1, NULL) != SQLITE_OK) {

View file

@ -56,7 +56,7 @@ zathura_db_set_fileinfo(zathura_database_t* db, const char* file,
bool
zathura_db_get_fileinfo(zathura_database_t* db, const char* file,
zathura_fileinfo_t* file_info)
zathura_fileinfo_t* file_info)
{
g_return_val_if_fail(ZATHURA_IS_DATABASE(db) && file != NULL && file_info != NULL, 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

View file

@ -480,10 +480,10 @@ document_open(zathura_t* zathura, const char* path, const char* password)
unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
/* read history file */
zathura_fileinfo_t file_info = { 0, 0, 1, 0, 1, 0, 0 };
zathura_fileinfo_t file_info = { 0, 0, 1, 0, 1, 0, 0 };
zathura_db_get_fileinfo(zathura->database, file_path, &file_info);
/* set page offset */
/* set page offset */
zathura_document_set_page_offset(document, file_info.page_offset);
/* check for valid scale value */
@ -733,7 +733,7 @@ document_close(zathura_t* zathura, bool keep_monitor)
/* store file information */
const char* path = zathura_document_get_path(zathura->document);
zathura_fileinfo_t file_info = { 0 };
zathura_fileinfo_t file_info = { 0 };
file_info.current_page = zathura_document_get_current_page_number(zathura->document);
file_info.page_offset = zathura_document_get_page_offset(zathura->document);
file_info.scale = zathura_document_get_scale(zathura->document);