2010-11-10 20:31:15 +01:00
|
|
|
/* See LICENSE file for license and copyright information */
|
2010-11-12 13:48:18 +01:00
|
|
|
|
2011-10-23 17:01:15 +02:00
|
|
|
#include <girara/statusbar.h>
|
|
|
|
#include <girara/session.h>
|
|
|
|
#include <girara/settings.h>
|
2012-01-21 22:03:08 +01:00
|
|
|
#include <girara/utils.h>
|
2010-11-13 12:40:48 +01:00
|
|
|
#include <stdlib.h>
|
2010-12-29 11:46:13 +01:00
|
|
|
#include <gtk/gtk.h>
|
2012-02-07 17:31:47 +01:00
|
|
|
#include <string.h>
|
2010-11-12 13:48:18 +01:00
|
|
|
|
2011-08-31 14:35:53 +02:00
|
|
|
#include "callbacks.h"
|
2010-11-12 13:48:18 +01:00
|
|
|
#include "zathura.h"
|
2011-01-07 09:07:02 +01:00
|
|
|
#include "render.h"
|
2011-03-05 19:46:05 +01:00
|
|
|
#include "document.h"
|
2011-04-19 20:23:58 +02:00
|
|
|
#include "utils.h"
|
2011-09-29 18:08:37 +02:00
|
|
|
#include "shortcuts.h"
|
2012-02-07 18:30:46 +01:00
|
|
|
#include "page_widget.h"
|
2010-11-12 13:48:18 +01:00
|
|
|
|
|
|
|
gboolean
|
2011-09-21 00:46:03 +02:00
|
|
|
cb_destroy(GtkWidget* UNUSED(widget), gpointer UNUSED(data))
|
2010-11-12 13:48:18 +01:00
|
|
|
{
|
2011-10-16 20:59:25 +02:00
|
|
|
gtk_main_quit();
|
2010-11-12 13:48:18 +01:00
|
|
|
return TRUE;
|
|
|
|
}
|
2010-11-13 12:40:48 +01:00
|
|
|
|
|
|
|
void
|
2012-02-08 15:19:51 +01:00
|
|
|
cb_buffer_changed(girara_session_t* session)
|
2010-11-13 12:40:48 +01:00
|
|
|
{
|
|
|
|
g_return_if_fail(session != NULL);
|
2011-04-18 17:37:03 +02:00
|
|
|
g_return_if_fail(session->global.data != NULL);
|
|
|
|
|
|
|
|
zathura_t* zathura = session->global.data;
|
2010-11-13 12:40:48 +01:00
|
|
|
|
|
|
|
char* buffer = girara_buffer_get(session);
|
2012-03-04 01:30:27 +01:00
|
|
|
if (buffer != NULL) {
|
2011-04-18 17:37:03 +02:00
|
|
|
girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, buffer);
|
2010-11-13 12:40:48 +01:00
|
|
|
free(buffer);
|
2010-12-26 01:12:20 +01:00
|
|
|
} else {
|
2011-04-18 17:37:03 +02:00
|
|
|
girara_statusbar_item_set_text(session, zathura->ui.statusbar.buffer, "");
|
2010-11-29 14:58:56 +01:00
|
|
|
}
|
2010-11-13 12:40:48 +01:00
|
|
|
}
|
2010-12-29 11:46:13 +01:00
|
|
|
|
|
|
|
void
|
2012-02-07 14:56:58 +01:00
|
|
|
cb_view_vadjustment_value_changed(GtkAdjustment* GIRARA_UNUSED(adjustment), gpointer data)
|
2010-12-29 11:46:13 +01:00
|
|
|
{
|
2011-04-18 17:37:03 +02:00
|
|
|
zathura_t* zathura = data;
|
2012-03-04 01:30:27 +01:00
|
|
|
if (zathura == NULL || zathura->document == NULL || zathura->document->pages == NULL
|
|
|
|
|| zathura->ui.page_widget == NULL) {
|
2010-12-29 11:46:13 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-07 14:56:58 +01:00
|
|
|
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));
|
|
|
|
|
|
|
|
GdkRectangle view_rect;
|
2010-12-29 11:46:13 +01:00
|
|
|
/* get current adjustment values */
|
2012-03-04 01:30:27 +01:00
|
|
|
view_rect.y = gtk_adjustment_get_value(view_vadjustment);
|
2012-02-07 14:56:58 +01:00
|
|
|
view_rect.height = gtk_adjustment_get_page_size(view_vadjustment);
|
2012-03-04 01:30:27 +01:00
|
|
|
view_rect.x = gtk_adjustment_get_value(view_hadjustment);
|
|
|
|
view_rect.width = gtk_adjustment_get_page_size(view_hadjustment);
|
2012-02-07 14:56:58 +01:00
|
|
|
|
|
|
|
int page_padding = 1;
|
|
|
|
girara_setting_get(zathura->ui.session, "page-padding", &page_padding);
|
2010-12-29 11:46:13 +01:00
|
|
|
|
2012-02-07 14:56:58 +01:00
|
|
|
GdkRectangle center;
|
|
|
|
center.x = view_rect.x + (view_rect.width + 1) / 2;
|
|
|
|
center.y = view_rect.y + (view_rect.height + 1) / 2;
|
2012-03-04 01:30:27 +01:00
|
|
|
center.height = center.width = (2 * page_padding) + 1;
|
2012-02-07 14:56:58 +01:00
|
|
|
|
|
|
|
bool updated = false;
|
2010-12-29 11:46:13 +01:00
|
|
|
/* find page that fits */
|
2012-03-04 01:30:27 +01:00
|
|
|
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
|
2011-04-18 17:37:03 +02:00
|
|
|
zathura_page_t* page = zathura->document->pages[page_id];
|
2011-01-06 08:59:10 +01:00
|
|
|
|
2012-02-07 14:56:58 +01:00
|
|
|
page_offset_t offset;
|
|
|
|
page_calculate_offset(page, &offset);
|
2011-04-19 20:41:16 +02:00
|
|
|
|
2012-02-07 14:56:58 +01:00
|
|
|
GdkRectangle page_rect;
|
|
|
|
page_rect.x = offset.x;
|
|
|
|
page_rect.y = offset.y;
|
2012-03-04 01:30:27 +01:00
|
|
|
page_rect.width = page->width * zathura->document->scale;
|
2012-02-07 14:56:58 +01:00
|
|
|
page_rect.height = page->height * zathura->document->scale;
|
2011-04-19 20:41:16 +02:00
|
|
|
|
2012-02-07 14:56:58 +01:00
|
|
|
if (gdk_rectangle_intersect(&view_rect, &page_rect, NULL) == TRUE) {
|
2011-04-19 18:33:28 +02:00
|
|
|
page->visible = true;
|
2012-02-21 20:39:42 +01:00
|
|
|
if (zathura->global.update_page_number == true && updated == false
|
|
|
|
&& gdk_rectangle_intersect(¢er, &page_rect, NULL) == TRUE) {
|
2012-02-07 14:56:58 +01:00
|
|
|
zathura->document->current_page_number = page_id;
|
|
|
|
updated = true;
|
|
|
|
}
|
2011-04-19 20:46:33 +02:00
|
|
|
} else {
|
|
|
|
page->visible = false;
|
2010-12-29 11:46:13 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-07 14:56:58 +01:00
|
|
|
|
|
|
|
statusbar_page_number_update(zathura);
|
2010-12-29 11:46:13 +01:00
|
|
|
}
|
2011-07-21 14:47:24 +02:00
|
|
|
|
|
|
|
void
|
2012-02-10 14:13:08 +01:00
|
|
|
cb_pages_per_row_value_changed(girara_session_t* session, const char* UNUSED(name), girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
|
2011-07-21 14:47:24 +02:00
|
|
|
{
|
2011-11-20 11:32:34 +01:00
|
|
|
g_return_if_fail(value != NULL);
|
2012-02-10 14:13:08 +01:00
|
|
|
g_return_if_fail(session != NULL);
|
|
|
|
g_return_if_fail(session->global.data != NULL);
|
|
|
|
zathura_t* zathura = session->global.data;
|
2011-11-20 11:32:34 +01:00
|
|
|
|
|
|
|
int pages_per_row = *(int*) value;
|
2011-07-21 14:47:24 +02:00
|
|
|
|
2011-07-21 14:48:48 +02:00
|
|
|
if (pages_per_row < 1) {
|
2011-07-21 14:47:24 +02:00
|
|
|
pages_per_row = 1;
|
2011-07-21 14:48:48 +02:00
|
|
|
}
|
2011-07-21 14:47:24 +02:00
|
|
|
|
2012-02-07 18:30:46 +01:00
|
|
|
page_widget_set_mode(zathura, pages_per_row);
|
2012-02-12 15:34:05 +01:00
|
|
|
|
|
|
|
if (zathura->document != NULL) {
|
|
|
|
unsigned int current_page = zathura->document->current_page_number;
|
|
|
|
page_set_delayed(zathura, current_page);
|
|
|
|
}
|
2011-07-21 14:47:24 +02:00
|
|
|
}
|
2011-09-29 17:05:54 +02:00
|
|
|
|
|
|
|
void
|
2011-09-29 18:17:03 +02:00
|
|
|
cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
|
2011-12-09 14:50:35 +01:00
|
|
|
GtkTreeViewColumn* UNUSED(column), void* data)
|
2011-09-29 17:05:54 +02:00
|
|
|
{
|
2011-12-09 14:50:35 +01:00
|
|
|
zathura_t* zathura = data;
|
2011-09-29 17:05:54 +02:00
|
|
|
if (tree_view == NULL || zathura == NULL || zathura->ui.session == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
g_object_get(tree_view, "model", &model, NULL);
|
|
|
|
|
2012-03-04 01:30:27 +01:00
|
|
|
if(gtk_tree_model_get_iter(model, &iter, path)) {
|
2011-09-29 17:05:54 +02:00
|
|
|
zathura_index_element_t* index_element;
|
2011-09-29 17:28:09 +02:00
|
|
|
gtk_tree_model_get(model, &iter, 2, &index_element, -1);
|
2011-09-29 17:05:54 +02:00
|
|
|
|
|
|
|
if (index_element == NULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (index_element->type == ZATHURA_LINK_TO_PAGE) {
|
2012-01-24 01:34:09 +01:00
|
|
|
sc_toggle_index(zathura->ui.session, NULL, NULL, 0);
|
2011-10-06 17:48:17 +02:00
|
|
|
page_set_delayed(zathura, index_element->target.page_number);
|
2011-09-29 17:05:54 +02:00
|
|
|
} else if (index_element->type == ZATHURA_LINK_EXTERNAL) {
|
2012-01-22 12:30:25 +01:00
|
|
|
if (girara_xdg_open(index_element->target.uri) == false) {
|
2012-01-21 22:03:08 +01:00
|
|
|
girara_notify(zathura->ui.session, GIRARA_ERROR, "Failed to run xdg-open.");
|
2012-01-13 19:33:37 +01:00
|
|
|
}
|
2011-09-29 17:05:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
g_object_unref(model);
|
|
|
|
}
|
2012-02-07 16:39:02 +01:00
|
|
|
|
2012-02-07 17:31:47 +01:00
|
|
|
bool
|
|
|
|
cb_sc_follow(GtkEntry* entry, girara_session_t* session)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail(session != NULL, FALSE);
|
|
|
|
g_return_val_if_fail(session->global.data != NULL, FALSE);
|
|
|
|
|
|
|
|
zathura_t* zathura = session->global.data;
|
2012-02-08 00:19:35 +01:00
|
|
|
bool eval = true;
|
2012-02-07 17:31:47 +01:00
|
|
|
|
|
|
|
char* input = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
|
2012-02-08 00:19:35 +01:00
|
|
|
if (input == NULL || strlen(input) == 0) {
|
|
|
|
eval = false;
|
2012-02-07 17:31:47 +01:00
|
|
|
}
|
|
|
|
|
2012-02-08 00:19:35 +01:00
|
|
|
int index = 0;
|
|
|
|
if (eval == true) {
|
|
|
|
index = atoi(input);
|
|
|
|
if (index == 0 && g_strcmp0(input, "0") != 0) {
|
|
|
|
girara_notify(session, GIRARA_WARNING, "Invalid input '%s' given.", input);
|
|
|
|
eval = false;
|
|
|
|
}
|
|
|
|
index = index - 1;
|
2012-02-07 17:31:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* set pages to draw links */
|
|
|
|
bool invalid_index = true;
|
|
|
|
for (unsigned int page_id = 0; page_id < zathura->document->number_of_pages; page_id++) {
|
|
|
|
zathura_page_t* page = zathura->document->pages[page_id];
|
|
|
|
if (page == NULL || page->visible == false) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-02-07 18:00:47 +01:00
|
|
|
g_object_set(page->drawing_area, "draw-links", FALSE, NULL);
|
|
|
|
|
2012-02-08 00:19:35 +01:00
|
|
|
if (eval == true) {
|
|
|
|
zathura_link_t* link = zathura_page_widget_link_get(ZATHURA_PAGE(page->drawing_area), 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.value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
invalid_index = false;
|
2012-02-07 17:31:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-02-08 00:19:35 +01:00
|
|
|
if (eval == true && invalid_index == true) {
|
2012-02-07 17:31:47 +01:00
|
|
|
girara_notify(session, GIRARA_WARNING, "Invalid index '%s' given.", input);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free(input);
|
|
|
|
|
2012-02-08 00:19:35 +01:00
|
|
|
return (eval == TRUE) ? TRUE : FALSE;
|
2012-02-07 17:31:47 +01:00
|
|
|
}
|
2012-02-07 19:25:47 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* UNUSED(other_file), GFileMonitorEvent event, girara_session_t* session)
|
|
|
|
{
|
|
|
|
g_return_if_fail(monitor != NULL);
|
|
|
|
g_return_if_fail(file != NULL);
|
|
|
|
g_return_if_fail(session != NULL);
|
|
|
|
|
2012-02-20 20:07:24 +01:00
|
|
|
switch (event) {
|
|
|
|
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
|
|
|
|
case G_FILE_MONITOR_EVENT_CREATED:
|
2012-02-20 20:18:12 +01:00
|
|
|
gdk_threads_enter();
|
2012-02-20 20:07:24 +01:00
|
|
|
sc_reload(session, NULL, NULL, 0);
|
2012-02-20 20:18:12 +01:00
|
|
|
gdk_threads_leave();
|
2012-02-20 20:07:24 +01:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2012-02-07 19:25:47 +01:00
|
|
|
}
|
|
|
|
}
|
2012-02-08 23:21:27 +01:00
|
|
|
|
2012-02-08 23:50:55 +01:00
|
|
|
static gboolean
|
|
|
|
password_dialog(gpointer data)
|
|
|
|
{
|
|
|
|
zathura_password_dialog_info_t* dialog = data;
|
2012-03-04 01:30:27 +01:00
|
|
|
|
2012-02-08 23:50:55 +01:00
|
|
|
if (dialog != NULL) {
|
2012-03-04 01:30:27 +01:00
|
|
|
girara_dialog(
|
|
|
|
dialog->zathura->ui.session,
|
|
|
|
"Incorrect password. Enter password:",
|
|
|
|
true,
|
|
|
|
NULL,
|
|
|
|
(girara_callback_inputbar_activate_t) cb_password_dialog,
|
|
|
|
dialog
|
|
|
|
);
|
2012-02-08 23:50:55 +01:00
|
|
|
}
|
2012-03-04 01:30:27 +01:00
|
|
|
|
2012-02-08 23:50:55 +01:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-02-08 23:21:27 +01:00
|
|
|
bool
|
|
|
|
cb_password_dialog(GtkEntry* entry, zathura_password_dialog_info_t* dialog)
|
|
|
|
{
|
|
|
|
if (entry == NULL || dialog == NULL) {
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->path == NULL) {
|
|
|
|
free(dialog);
|
|
|
|
goto error_ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dialog->zathura == NULL) {
|
|
|
|
goto error_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
char* input = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
|
|
|
|
|
|
|
|
/* no or empty password: ask again */
|
|
|
|
if (input == NULL || strlen(input) == 0) {
|
|
|
|
if (input != NULL) {
|
|
|
|
g_free(input);
|
|
|
|
}
|
|
|
|
|
2012-02-16 16:18:12 +01:00
|
|
|
gdk_threads_add_idle(password_dialog, dialog);
|
2012-02-08 23:21:27 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* try to open document again */
|
2012-02-08 23:50:55 +01:00
|
|
|
if (document_open(dialog->zathura, dialog->path, input) == false) {
|
2012-02-16 16:18:12 +01:00
|
|
|
gdk_threads_add_idle(password_dialog, dialog);
|
2012-02-08 23:50:55 +01:00
|
|
|
} else {
|
|
|
|
g_free(dialog->path);
|
|
|
|
free(dialog);
|
|
|
|
}
|
2012-02-08 23:21:27 +01:00
|
|
|
|
|
|
|
g_free(input);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error_free:
|
|
|
|
|
|
|
|
g_free(dialog->path);
|
|
|
|
free(dialog);
|
|
|
|
|
|
|
|
error_ret:
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2012-02-09 01:46:51 +01:00
|
|
|
|
|
|
|
bool
|
2012-02-14 15:53:04 +01:00
|
|
|
cb_view_resized(GtkWidget* UNUSED(widget), GtkAllocation* allocation, zathura_t* zathura)
|
2012-02-09 01:46:51 +01:00
|
|
|
{
|
|
|
|
if (zathura == NULL || zathura->document == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-02-14 15:53:04 +01:00
|
|
|
static int height = -1;
|
|
|
|
static int width = -1;
|
2012-02-09 01:46:51 +01:00
|
|
|
|
2012-02-14 15:53:04 +01:00
|
|
|
/* adjust only if the allocation changed */
|
|
|
|
if (width != allocation->width || height != allocation->height) {
|
|
|
|
girara_argument_t argument = { zathura->document->adjust_mode, NULL };
|
|
|
|
sc_adjust_window(zathura->ui.session, &argument, NULL, 0);
|
2012-03-04 01:30:27 +01:00
|
|
|
|
|
|
|
width = allocation->width;
|
2012-02-14 15:53:04 +01:00
|
|
|
height = allocation->height;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2012-02-09 01:46:51 +01:00
|
|
|
}
|