Commit 97247f41 authored by Moritz Lipp's avatar Moritz Lipp
Browse files

Unhitch zathura_t from document_t/page_t/plugin_manager_t

parent b458b8c1
...@@ -82,7 +82,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi ...@@ -82,7 +82,7 @@ cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpoi
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id); zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
GdkRectangle page_rect; GdkRectangle page_rect;
GtkWidget* page_widget = zathura_page_get_widget(page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
gtk_widget_translate_coordinates(page_widget, gtk_widget_translate_coordinates(page_widget,
zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y); zathura->ui.session->gtk.view, 0, 0, &page_rect.x, &page_rect.y);
page_rect.width = zathura_page_get_width(page) * scale; page_rect.width = zathura_page_get_width(page) * scale;
...@@ -194,7 +194,7 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session) ...@@ -194,7 +194,7 @@ cb_sc_follow(GtkEntry* entry, girara_session_t* session)
continue; continue;
} }
GtkWidget* page_widget = zathura_page_get_widget(page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(page_widget, "draw-links", FALSE, NULL); g_object_set(page_widget, "draw-links", FALSE, NULL);
if (eval == true) { if (eval == true) {
......
...@@ -319,7 +319,7 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu ...@@ -319,7 +319,7 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
continue; continue;
} }
GtkWidget* page_widget = zathura_page_get_widget(page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(page_widget, "draw-links", FALSE, NULL); g_object_set(page_widget, "draw-links", FALSE, NULL);
girara_list_t* result = zathura_page_search_text(page, input, &error); girara_list_t* result = zathura_page_search_text(page, input, &error);
......
...@@ -46,7 +46,6 @@ struct zathura_document_s ...@@ -46,7 +46,6 @@ struct zathura_document_s
unsigned int rotate; /**< Rotation */ unsigned int rotate; /**< Rotation */
void* data; /**< Custom data */ void* data; /**< Custom data */
zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */ zathura_adjust_mode_t adjust_mode; /**< Adjust mode (best-fit, width) */
zathura_t* zathura; /**< Zathura instance */
unsigned int page_offset; /**< Page offset */ unsigned int page_offset; /**< Page offset */
/** /**
...@@ -62,7 +61,8 @@ struct zathura_document_s ...@@ -62,7 +61,8 @@ struct zathura_document_s
zathura_document_t* zathura_document_t*
zathura_document_open(zathura_t* zathura, const char* path, const char* password) zathura_document_open(zathura_plugin_manager_t* plugin_manager, const char*
path, const char* password, zathura_error_t* error)
{ {
if (path == NULL) { if (path == NULL) {
return NULL; return NULL;
...@@ -104,7 +104,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password ...@@ -104,7 +104,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
return NULL; return NULL;
} }
zathura_plugin_t* plugin = zathura_plugin_manager_get_plugin(zathura->plugins.manager, content_type); zathura_plugin_t* plugin = zathura_plugin_manager_get_plugin(plugin_manager, content_type);
g_free((void*)content_type); g_free((void*)content_type);
if (plugin == NULL) { if (plugin == NULL) {
...@@ -118,7 +118,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password ...@@ -118,7 +118,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
document->password = password; document->password = password;
document->scale = 1.0; document->scale = 1.0;
document->plugin = plugin; document->plugin = plugin;
document->zathura = zathura;
/* open document */ /* open document */
if (plugin->functions.document_open == NULL) { if (plugin->functions.document_open == NULL) {
...@@ -126,49 +125,16 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password ...@@ -126,49 +125,16 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
goto error_free; goto error_free;
} }
zathura_error_t error = plugin->functions.document_open(document); zathura_error_t int_error = plugin->functions.document_open(document);
if (error != ZATHURA_ERROR_OK) { if (int_error != ZATHURA_ERROR_OK) {
if (error == ZATHURA_ERROR_INVALID_PASSWORD) { if (error != NULL) {
zathura_password_dialog_info_t* password_dialog_info = malloc(sizeof(zathura_password_dialog_info_t)); *error = int_error;
if (password_dialog_info != NULL) {
password_dialog_info->path = g_strdup(path);
password_dialog_info->zathura = zathura;
if (path != NULL) {
girara_dialog(zathura->ui.session, "Enter password:", true, NULL,
(girara_callback_inputbar_activate_t) cb_password_dialog, password_dialog_info);
goto error_free;
} else {
free(password_dialog_info);
}
}
goto error_free;
} }
girara_error("could not open document\n"); girara_error("could not open document\n");
goto error_free; goto error_free;
} }
/* read history file */
zathura_db_get_fileinfo(zathura->database, document->file_path,
&document->current_page_number, &document->page_offset, &document->scale,
&document->rotate);
/* check for valid scale value */
if (document->scale <= FLT_EPSILON) {
girara_warning("document info: '%s' has non positive scale", document->file_path);
document->scale = 1;
}
/* check current page number */
if (document->current_page_number > document->number_of_pages) {
girara_warning("document info: '%s' has an invalid page number", document->file_path);
document->current_page_number = 0;
}
/* update statusbar */
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path);
/* read all pages */ /* read all pages */
document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*)); document->pages = calloc(document->number_of_pages, sizeof(zathura_page_t*));
if (document->pages == NULL) { if (document->pages == NULL) {
...@@ -184,27 +150,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password ...@@ -184,27 +150,6 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
document->pages[page_id] = page; document->pages[page_id] = page;
} }
/* jump to first page if setting enabled */
bool always_first_page = false;
girara_setting_get(zathura->ui.session, "open-first-page", &always_first_page);
if (always_first_page == true) {
document->current_page_number = 0;
}
/* apply open adjustment */
char* adjust_open = "best-fit";
document->adjust_mode = ZATHURA_ADJUST_BESTFIT;
if (girara_setting_get(zathura->ui.session, "adjust-open", &(adjust_open)) == true) {
if (g_strcmp0(adjust_open, "best-fit") == 0) {
document->adjust_mode = ZATHURA_ADJUST_BESTFIT;
} else if (g_strcmp0(adjust_open, "width") == 0) {
document->adjust_mode = ZATHURA_ADJUST_WIDTH;
} else {
document->adjust_mode = ZATHURA_ADJUST_NONE;
}
g_free(adjust_open);
}
return document; return document;
error_free: error_free:
...@@ -611,16 +556,6 @@ guess_type(const char* path) ...@@ -611,16 +556,6 @@ guess_type(const char* path)
return out; return out;
} }
zathura_t*
zathura_document_get_zathura(zathura_document_t* document)
{
if (document == NULL) {
return NULL;
}
return document->zathura;
}
zathura_plugin_t* zathura_plugin_t*
zathura_document_get_plugin(zathura_document_t* document) zathura_document_get_plugin(zathura_document_t* document)
{ {
......
...@@ -3,24 +3,24 @@ ...@@ -3,24 +3,24 @@
#ifndef DOCUMENT_H #ifndef DOCUMENT_H
#define DOCUMENT_H #define DOCUMENT_H
#include <cairo.h>
#include <gtk/gtk.h>
#include <stdbool.h> #include <stdbool.h>
#include <girara/types.h> #include <girara/types.h>
#include "zathura.h"
#include "types.h" #include "types.h"
#include "page.h"
/** /**
* Open the document * Open the document
* *
* @param zathura Zathura object * @param plugin_manager The plugin manager
* @param path Path to the document * @param path Path to the document
* @param password Password of the document or NULL * @param password Password of the document or NULL
* @param error Optional error parameter
* @return The document object * @return The document object
*/ */
zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, zathura_document_t* zathura_document_open(zathura_plugin_manager_t*
const char* password); plugin_manager, const char* path, const char* password, zathura_error_t*
error);
/** /**
* Free the document * Free the document
......
...@@ -15,15 +15,6 @@ typedef struct zathura_password_dialog_info_s ...@@ -15,15 +15,6 @@ typedef struct zathura_password_dialog_info_s
zathura_t* zathura; /**< Zathura session */ zathura_t* zathura; /**< Zathura session */
} zathura_password_dialog_info_t; } zathura_password_dialog_info_t;
/**
* Returns the associated zathura instance
* TODO: Separate zathura_t completely from the document
*
* @param document The docment
* @return The associated zathura instance
*/
zathura_t* zathura_document_get_zathura(zathura_document_t* document);
/** /**
* Returns the associated plugin * Returns the associated plugin
* *
......
...@@ -62,6 +62,7 @@ enum properties_e ...@@ -62,6 +62,7 @@ enum properties_e
{ {
PROP_0, PROP_0,
PROP_PAGE, PROP_PAGE,
PROP_ZATHURA,
PROP_DRAW_LINKS, PROP_DRAW_LINKS,
PROP_LINKS_OFFSET, PROP_LINKS_OFFSET,
PROP_LINKS_NUMBER, PROP_LINKS_NUMBER,
...@@ -98,6 +99,8 @@ zathura_page_widget_class_init(ZathuraPageClass* class) ...@@ -98,6 +99,8 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
/* add properties */ /* add properties */
g_object_class_install_property(object_class, PROP_PAGE, g_object_class_install_property(object_class, PROP_PAGE,
g_param_spec_pointer("page", "page", "the page to draw", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY)); g_param_spec_pointer("page", "page", "the page to draw", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(object_class, PROP_ZATHURA,
g_param_spec_pointer("zathura", "zathura", "the zathura instance", G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property(object_class, PROP_DRAW_LINKS, g_object_class_install_property(object_class, PROP_DRAW_LINKS,
g_param_spec_boolean("draw-links", "draw-links", "Set to true if links should be drawn", FALSE, G_PARAM_WRITABLE)); g_param_spec_boolean("draw-links", "draw-links", "Set to true if links should be drawn", FALSE, G_PARAM_WRITABLE));
g_object_class_install_property(object_class, PROP_LINKS_OFFSET, g_object_class_install_property(object_class, PROP_LINKS_OFFSET,
...@@ -138,11 +141,11 @@ zathura_page_widget_init(ZathuraPage* widget) ...@@ -138,11 +141,11 @@ zathura_page_widget_init(ZathuraPage* widget)
} }
GtkWidget* GtkWidget*
zathura_page_widget_new(zathura_page_t* page) zathura_page_widget_new(zathura_t* zathura, zathura_page_t* page)
{ {
g_return_val_if_fail(page != NULL, NULL); g_return_val_if_fail(page != NULL, NULL);
return g_object_new(ZATHURA_TYPE_PAGE, "page", page, NULL); return g_object_new(ZATHURA_TYPE_PAGE, "page", page, "zathura", zathura, NULL);
} }
static void static void
...@@ -173,13 +176,13 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v ...@@ -173,13 +176,13 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
{ {
ZathuraPage* pageview = ZATHURA_PAGE(object); ZathuraPage* pageview = ZATHURA_PAGE(object);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(pageview); zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(pageview);
zathura_document_t* document = NULL;
switch (prop_id) { switch (prop_id) {
case PROP_PAGE: case PROP_PAGE:
priv->page = g_value_get_pointer(value); priv->page = g_value_get_pointer(value);
document = zathura_page_get_document(priv->page); break;
priv->zathura = zathura_document_get_zathura(document); case PROP_ZATHURA:
priv->zathura = g_value_get_pointer(value);
break; break;
case PROP_DRAW_LINKS: case PROP_DRAW_LINKS:
priv->draw_links = g_value_get_boolean(value); priv->draw_links = g_value_get_boolean(value);
......
...@@ -45,10 +45,11 @@ struct zathura_page_widget_class_s { ...@@ -45,10 +45,11 @@ struct zathura_page_widget_class_s {
GType zathura_page_widget_get_type(void); GType zathura_page_widget_get_type(void);
/** /**
* Create a page view widget. * Create a page view widget.
* @param zathura the zathura instance
* @param page the page to be displayed * @param page the page to be displayed
* @return a page view widget * @return a page view widget
*/ */
GtkWidget* zathura_page_widget_new(zathura_page_t* page); GtkWidget* zathura_page_widget_new(zathura_t* zathura, zathura_page_t* page);
/** /**
* Update the widget's surface. This should only be called from the render * Update the widget's surface. This should only be called from the render
* thread. * thread.
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "document.h" #include "document.h"
#include "page.h" #include "page.h"
#include "page-widget.h"
#include "plugin.h" #include "plugin.h"
#include "utils.h" #include "utils.h"
#include "internal.h" #include "internal.h"
...@@ -18,7 +17,6 @@ struct zathura_page_s { ...@@ -18,7 +17,6 @@ struct zathura_page_s {
unsigned int index; /**< Page number */ unsigned int index; /**< Page number */
void* data; /**< Custom data */ void* data; /**< Custom data */
bool visible; /**< Page is visible */ bool visible; /**< Page is visible */
GtkWidget* widget; /**< Drawing area */
zathura_document_t* document; /**< Document */ zathura_document_t* document; /**< Document */
}; };
...@@ -38,14 +36,6 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error ...@@ -38,14 +36,6 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error
page->index = index; page->index = index;
page->visible = false; page->visible = false;
page->document = document; page->document = document;
page->widget = zathura_page_widget_new(page);
if (page->widget == NULL) {
if (error != NULL) {
*error = ZATHURA_ERROR_UNKNOWN;
}
goto error_free;
}
/* init plugin */ /* init plugin */
zathura_plugin_t* plugin = zathura_document_get_plugin(document); zathura_plugin_t* plugin = zathura_document_get_plugin(document);
...@@ -64,13 +54,6 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error ...@@ -64,13 +54,6 @@ zathura_page_new(zathura_document_t* document, unsigned int index, zathura_error
goto error_free; goto error_free;
} }
/* set widget size */
unsigned int page_height = 0;
unsigned int page_width = 0;
page_calc_height_width(page, &page_height, &page_width, true);
gtk_widget_set_size_request(page->widget, page_width, page_height);
return page; return page;
error_free: error_free:
...@@ -128,16 +111,6 @@ zathura_page_get_index(zathura_page_t* page) ...@@ -128,16 +111,6 @@ zathura_page_get_index(zathura_page_t* page)
return page->index; return page->index;
} }
GtkWidget*
zathura_page_get_widget(zathura_page_t* page)
{
if (page == NULL) {
return NULL;
}
return page->widget;
}
double double
zathura_page_get_width(zathura_page_t* page) zathura_page_get_width(zathura_page_t* page)
{ {
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#define PAGE_H #define PAGE_H
#include <girara/datastructures.h> #include <girara/datastructures.h>
#include <cairo.h>
#include "document.h" #include "document.h"
#include "types.h"
/** /**
* Get the page object * Get the page object
...@@ -44,15 +46,6 @@ zathura_document_t* zathura_page_get_document(zathura_page_t* page); ...@@ -44,15 +46,6 @@ zathura_document_t* zathura_page_get_document(zathura_page_t* page);
*/ */
unsigned int zathura_page_get_index(zathura_page_t* page); unsigned int zathura_page_get_index(zathura_page_t* page);
/**
* Returns the page widget of the page
*
* @param page The page object
* @return The page widget of the page
* @return NULL if an error occured
*/
GtkWidget* zathura_page_get_widget(zathura_page_t* page);
/** /**
* Returns the width of the page * Returns the width of the page
* *
......
...@@ -25,8 +25,6 @@ struct zathura_plugin_s ...@@ -25,8 +25,6 @@ struct zathura_plugin_s
void* handle; /**< DLL handle */ void* handle; /**< DLL handle */
}; };
typedef struct zathura_plugin_manager_s zathura_plugin_manager_t;
/** /**
* Creates a new instance of the plugin manager * Creates a new instance of the plugin manager
* *
......
...@@ -163,7 +163,7 @@ render(zathura_t* zathura, zathura_page_t* page) ...@@ -163,7 +163,7 @@ render(zathura_t* zathura, zathura_page_t* page)
/* update the widget */ /* update the widget */
gdk_threads_enter(); gdk_threads_enter();
GtkWidget* widget = zathura_page_get_widget(page); GtkWidget* widget = zathura_page_get_widget(zathura, page);
zathura_page_widget_update_surface(ZATHURA_PAGE(widget), surface); zathura_page_widget_update_surface(ZATHURA_PAGE(widget), surface);
gdk_threads_leave(); gdk_threads_leave();
...@@ -173,7 +173,7 @@ render(zathura_t* zathura, zathura_page_t* page) ...@@ -173,7 +173,7 @@ render(zathura_t* zathura, zathura_page_t* page)
void void
render_all(zathura_t* zathura) render_all(zathura_t* zathura)
{ {
if (zathura->document == NULL) { if (zathura == NULL || zathura->document == NULL) {
return; return;
} }
...@@ -184,7 +184,7 @@ render_all(zathura_t* zathura) ...@@ -184,7 +184,7 @@ render_all(zathura_t* zathura)
unsigned int page_height = 0, page_width = 0; unsigned int page_height = 0, page_width = 0;
page_calc_height_width(page, &page_height, &page_width, true); page_calc_height_width(page, &page_height, &page_width, true);
GtkWidget* widget = zathura_page_get_widget(page); GtkWidget* widget = zathura_page_get_widget(zathura, page);
gtk_widget_set_size_request(widget, page_width, page_height); gtk_widget_set_size_request(widget, page_width, page_height);
gtk_widget_queue_resize(widget); gtk_widget_queue_resize(widget);
} }
......
...@@ -51,7 +51,7 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), ...@@ -51,7 +51,7 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
continue; continue;
} }
g_object_set(zathura_page_get_widget(page), "draw-links", FALSE, NULL); g_object_set(zathura_page_get_widget(zathura, page), "draw-links", FALSE, NULL);
} }
} }
...@@ -238,7 +238,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument), ...@@ -238,7 +238,7 @@ sc_follow(girara_session_t* session, girara_argument_t* UNUSED(argument),
continue; continue;
} }
GtkWidget* page_widget = zathura_page_get_widget(page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
g_object_set(page_widget, "search-results", NULL, NULL); g_object_set(page_widget, "search-results", NULL, NULL);
if (zathura_page_get_visibility(page) == true) { if (zathura_page_get_visibility(page) == true) {
g_object_set(page_widget, "draw-links", TRUE, NULL); g_object_set(page_widget, "draw-links", TRUE, NULL);
...@@ -580,7 +580,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -580,7 +580,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
continue; continue;
} }
GtkWidget* page_widget = zathura_page_get_widget(page); GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
int num_search_results = 0, current = -1; int num_search_results = 0, current = -1;
g_object_get(page_widget, "search-current", &current, g_object_get(page_widget, "search-current", &current,
...@@ -604,7 +604,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -604,7 +604,7 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
int ntmp = cur_page + diff * (page_id + npage_id); int ntmp = cur_page + diff * (page_id + npage_id);
zathura_page_t* npage = zathura_document_get_page(zathura->document, (ntmp + 2*num_pages) % num_pages); zathura_page_t* npage = zathura_document_get_page(zathura->document, (ntmp + 2*num_pages) % num_pages);
zathura_document_set_current_page_number(zathura->document, zathura_page_get_index(npage)); zathura_document_set_current_page_number(zathura->document, zathura_page_get_index(npage));
GtkWidget* npage_page_widget = zathura_page_get_widget(npage); GtkWidget* npage_page_widget = zathura_page_get_widget(zathura, npage);
g_object_get(npage_page_widget, "search-length", &num_search_results, NULL); g_object_get(npage_page_widget, "search-length", &num_search_results, NULL);
if (num_search_results != 0) { if (num_search_results != 0) {
target_page = npage; target_page = npage;
...@@ -619,14 +619,14 @@ sc_search(girara_session_t* session, girara_argument_t* argument, ...@@ -619,14 +619,14 @@ sc_search(girara_session_t* session, girara_argument_t* argument,
if (target_page != NULL) { if (target_page != NULL) {
girara_list_t* results = NULL; girara_list_t* results = NULL;
GtkWidget* page_widget = zathura_page_get_widget(target_page); GtkWidget* page_widget = zathura_page_get_widget(zathura, target_page);
g_object_set(page_widget, "search-current", target_idx, NULL); g_object_set(page_widget, "search-current", target_idx, NULL);
g_object_get(page_widget, "search-results", &results, NULL); g_object_get(page_widget, "search-results", &results, NULL);
zathura_rectangle_t* rect = girara_list_nth(results, target_idx); zathura_rectangle_t* rect = girara_list_nth(results, target_idx);
zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect); zathura_rectangle_t rectangle = recalc_rectangle(target_page, *rect);
page_offset_t offset; page_offset_t offset;
page_calculate_offset(target_page, &offset); page_calculate_offset(zathura, target_page, &offset);
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); GtkAdjustment* view_hadjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
......
...@@ -5,6 +5,11 @@ ...@@ -5,6 +5,11 @@