Commit 8bf7587b authored by Moritz Lipp's avatar Moritz Lipp

Show document information

parent 8b762ddc
/* 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)
...@@ -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
* *
......
...@@ -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);
......
Markdown is supported
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