Commit 2c5eb04f authored by Sebastian Ramacher's avatar Sebastian Ramacher
Browse files

Merge branch 'develop' of pwmt.org:zathura into develop

parents 4239d965 8bf7587b
/* See LICENSE file for license and copyright information */ /* See LICENSE file for license and copyright information */
#include <string.h>
#include "commands.h" #include "commands.h"
#include "bookmarks.h" #include "bookmarks.h"
#include "database.h" #include "database.h"
#include "document.h"
#include "zathura.h" #include "zathura.h"
#include "print.h" #include "print.h"
#include "document.h" #include "document.h"
#include "utils.h"
bool bool
cmd_bookmark_create(girara_session_t* UNUSED(session), girara_list_t* cmd_bookmark_create(girara_session_t* UNUSED(session), girara_list_t*
...@@ -65,10 +69,61 @@ cmd_close(girara_session_t* session, girara_list_t* UNUSED(argument_list)) ...@@ -65,10 +69,61 @@ cmd_close(girara_session_t* session, girara_list_t* UNUSED(argument_list))
} }
bool bool
cmd_info(girara_session_t* UNUSED(session), girara_list_t* cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
UNUSED(argument_list))
{ {
return true; g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
if (zathura->document == NULL) {
girara_notify(session, GIRARA_ERROR, "No document opened.");
return false;
}
struct meta_field {
char* name;
zathura_document_meta_t field;
};
struct meta_field meta_fields[] = {
{ "Title", ZATHURA_DOCUMENT_TITLE },
{ "Author", ZATHURA_DOCUMENT_AUTHOR },
{ "Subject", ZATHURA_DOCUMENT_SUBJECT },
{ "Keywords", ZATHURA_DOCUMENT_KEYWORDS },
{ "Creator", ZATHURA_DOCUMENT_CREATOR },
{ "Producer", ZATHURA_DOCUMENT_PRODUCER },
{ "Creation date", ZATHURA_DOCUMENT_CREATION_DATE },
{ "Modiciation date", ZATHURA_DOCUMENT_MODIFICATION_DATE }
};
GString* string = g_string_new(NULL);
if (string == NULL) {
return true;
}
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
char* tmp = zathura_document_meta_get(zathura->document, meta_fields[i].field);
if (tmp != NULL) {
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, tmp);
if (text == NULL) {
g_free(tmp);
return true;
}
g_string_append(string, text);
g_free(text);
g_free(tmp);
}
}
if (strlen(string->str) > 0) {
g_string_erase(string, strlen(string->str) - 1, 1);
girara_notify(session, GIRARA_INFO, string->str);
}
g_string_free(string, TRUE);
return false;
} }
bool bool
......
...@@ -20,8 +20,7 @@ ...@@ -20,8 +20,7 @@
#include "utils.h" #include "utils.h"
#include "zathura.h" #include "zathura.h"
#include "render.h" #include "render.h"
#include "utils.h"
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
void void
zathura_document_plugins_load(zathura_t* zathura) zathura_document_plugins_load(zathura_t* zathura)
...@@ -209,7 +208,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password ...@@ -209,7 +208,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
if (plugin == NULL) { if (plugin == NULL) {
girara_error("unknown file type\n"); girara_error("unknown file type\n");
free(real_path); goto error_free;
} }
document = g_malloc0(sizeof(zathura_document_t)); document = g_malloc0(sizeof(zathura_document_t));
...@@ -353,6 +352,21 @@ zathura_document_attachments_free(zathura_list_t* UNUSED(list)) ...@@ -353,6 +352,21 @@ zathura_document_attachments_free(zathura_list_t* UNUSED(list))
return false; return false;
} }
char*
zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta)
{
if (document == NULL) {
return NULL;
}
if (document->functions.document_meta_get == NULL) {
girara_error("%s not implemented", __FUNCTION__);
return NULL;
}
return document->functions.document_meta_get(document, meta);
}
zathura_page_t* zathura_page_t*
zathura_page_get(zathura_document_t* document, unsigned int page_id) zathura_page_get(zathura_document_t* document, unsigned int page_id)
{ {
......
...@@ -33,6 +33,18 @@ typedef struct zathura_type_plugin_mapping_s ...@@ -33,6 +33,18 @@ typedef struct zathura_type_plugin_mapping_s
zathura_document_plugin_t* plugin; zathura_document_plugin_t* plugin;
} zathura_type_plugin_mapping_t; } zathura_type_plugin_mapping_t;
typedef enum zathura_document_meta_e
{
ZATHURA_DOCUMENT_TITLE,
ZATHURA_DOCUMENT_AUTHOR,
ZATHURA_DOCUMENT_SUBJECT,
ZATHURA_DOCUMENT_KEYWORDS,
ZATHURA_DOCUMENT_CREATOR,
ZATHURA_DOCUMENT_PRODUCER,
ZATHURA_DOCUMENT_CREATION_DATE,
ZATHURA_DOCUMENT_MODIFICATION_DATE
} zathura_document_meta_t;
/** /**
* Function prototype that is called to register a document plugin * Function prototype that is called to register a document plugin
* *
...@@ -195,6 +207,11 @@ struct zathura_document_s ...@@ -195,6 +207,11 @@ struct zathura_document_s
*/ */
zathura_list_t* (*document_attachments_get)(zathura_document_t* document); zathura_list_t* (*document_attachments_get)(zathura_document_t* document);
/**
* Get document information
*/
char* (*document_meta_get)(zathura_document_t* document, zathura_document_meta_t info);
/** /**
* Gets the page object * Gets the page object
*/ */
...@@ -307,6 +324,15 @@ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document); ...@@ -307,6 +324,15 @@ zathura_list_t* zathura_document_attachments_get(zathura_document_t* document);
*/ */
bool zathura_document_attachments_free(zathura_list_t* list); bool zathura_document_attachments_free(zathura_list_t* list);
/**
* Returns a string of the requested information
*
* @param document The zathura document
* @param meta The information field
* @return String or NULL if information could not be retreived
*/
char* zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta);
/** /**
* Get the page object * Get the page object
* *
......
...@@ -22,10 +22,64 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument), ...@@ -22,10 +22,64 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
} }
bool bool
sc_adjust_window(girara_session_t* session, girara_argument_t* UNUSED(argument), sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
unsigned int UNUSED(t)) unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
g_return_val_if_fail(argument != NULL, false);
unsigned int* pages_per_row = girara_setting_get(session, "pages-per-row");
if (zathura->ui.page_view == NULL || zathura->document == NULL || pages_per_row == NULL) {
goto error_ret;
}
/* get window size */
/* TODO: Get correct size of the view widget */
gint width;
gint height;
gtk_window_get_size(GTK_WINDOW(session->gtk.window), &width, &height);
/* calculate total width and max-height */
double total_width = 0;
double max_height = 0;
for (unsigned int page_id = 0; page_id < *pages_per_row; page_id++) {
if (page_id == zathura->document->number_of_pages) {
break;
}
zathura_page_t* page = zathura->document->pages[page_id];
if (page == NULL) {
goto error_free;
}
if (page->height > max_height) {
max_height = page->height;
}
total_width += page->width;
}
if (argument->n == ADJUST_WIDTH) {
zathura->document->scale = width / total_width;
} else if (argument->n == ADJUST_BESTFIT) {
zathura->document->scale = height / max_height;
} else {
goto error_free;
}
/* re-render all pages */
render_all(zathura);
error_free:
/* cleanup */
free(pages_per_row);
error_ret:
return false; return false;
} }
...@@ -121,6 +175,26 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument), ...@@ -121,6 +175,26 @@ sc_reload(girara_session_t* session, girara_argument_t* UNUSED(argument),
unsigned int UNUSED(t)) unsigned int UNUSED(t))
{ {
g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session != NULL, false);
g_return_val_if_fail(session->global.data != NULL, false);
zathura_t* zathura = session->global.data;
if (zathura->document == NULL || zathura->document->file_path == NULL) {
return false;
}
/* save current document path and password */
char* path = g_strdup(zathura->document->file_path);
char* password = zathura->document->password ? g_strdup(zathura->document->password) : NULL;
/* close current document */
document_close(zathura);
/* reopen document */
document_open(zathura, path, password);
/* clean up */
g_free(path);
g_free(password);
return false; return false;
} }
...@@ -157,9 +231,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int ...@@ -157,9 +231,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int
GtkAdjustment* adjustment = NULL; GtkAdjustment* adjustment = NULL;
if ( (argument->n == LEFT) || (argument->n == RIGHT) ) if ( (argument->n == LEFT) || (argument->n == RIGHT) )
adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); adjustment = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
else else
adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view)); adjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
gdouble view_size = gtk_adjustment_get_page_size(adjustment); gdouble view_size = gtk_adjustment_get_page_size(adjustment);
gdouble value = gtk_adjustment_get_value(adjustment); gdouble value = gtk_adjustment_get_value(adjustment);
......
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#include "document.h" #include "document.h"
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
typedef struct page_offset_s typedef struct page_offset_s
{ {
int x; int x;
......
...@@ -63,7 +63,7 @@ zathura_init(int argc, char* argv[]) ...@@ -63,7 +63,7 @@ zathura_init(int argc, char* argv[])
/* plugins */ /* plugins */
zathura->plugins.plugins = girara_list_new(); zathura->plugins.plugins = girara_list_new();
girara_list_set_free_function(zathura->plugins.plugins, girara_list_set_free_function(zathura->plugins.plugins,
(girara_free_function_t)zathura_document_plugin_free); (girara_free_function_t)zathura_document_plugin_free);
zathura->plugins.path = girara_list_new(); zathura->plugins.path = girara_list_new();
girara_list_set_free_function(zathura->plugins.path, g_free); girara_list_set_free_function(zathura->plugins.path, g_free);
...@@ -274,6 +274,8 @@ zathura_free(zathura_t* zathura) ...@@ -274,6 +274,8 @@ zathura_free(zathura_t* zathura)
/* free config variables */ /* free config variables */
g_free(zathura->config.config_dir); g_free(zathura->config.config_dir);
g_free(zathura->config.data_dir); g_free(zathura->config.data_dir);
free(zathura);
} }
gboolean gboolean
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment