mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-15 05:36:01 +01:00
Update document information plugin api
This commit is contained in:
parent
2340590e93
commit
ab4c364e56
10 changed files with 154 additions and 68 deletions
36
commands.c
36
commands.c
|
@ -137,35 +137,37 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|||
|
||||
struct meta_field {
|
||||
char* name;
|
||||
zathura_document_meta_t field;
|
||||
zathura_document_information_type_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 }
|
||||
{ "Title", ZATHURA_DOCUMENT_INFORMATION_TITLE },
|
||||
{ "Author", ZATHURA_DOCUMENT_INFORMATION_AUTHOR },
|
||||
{ "Subject", ZATHURA_DOCUMENT_INFORMATION_SUBJECT },
|
||||
{ "Keywords", ZATHURA_DOCUMENT_INFORMATION_KEYWORDS },
|
||||
{ "Creator", ZATHURA_DOCUMENT_INFORMATION_CREATOR },
|
||||
{ "Producer", ZATHURA_DOCUMENT_INFORMATION_PRODUCER },
|
||||
{ "Creation date", ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE },
|
||||
{ "Modiciation date", ZATHURA_DOCUMENT_INFORMATION_MODIFICATION_DATE }
|
||||
};
|
||||
|
||||
girara_list_t* information = zathura_document_get_information(zathura->document, NULL);
|
||||
if (information == NULL) {
|
||||
girara_notify(session, GIRARA_INFO, _("No information available."));
|
||||
return false;
|
||||
}
|
||||
|
||||
GString* string = g_string_new(NULL);
|
||||
if (string == NULL) {
|
||||
return true;
|
||||
}
|
||||
|
||||
GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry)
|
||||
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
|
||||
char* tmp = zathura_document_meta_get(zathura->document, meta_fields[i].field, NULL);
|
||||
if (tmp != NULL) {
|
||||
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, tmp);
|
||||
if (meta_fields[i].field == entry->type) {
|
||||
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, entry->value);
|
||||
g_string_append(string, text);
|
||||
|
||||
g_free(text);
|
||||
g_free(tmp);
|
||||
}
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(information, zathura_document_information_entry_t*, iter, entry);
|
||||
|
||||
if (strlen(string->str) > 0) {
|
||||
g_string_erase(string, strlen(string->str) - 1, 1);
|
||||
|
|
13
document.c
13
document.c
|
@ -515,8 +515,8 @@ zathura_document_attachment_save(zathura_document_t* document, const char* attac
|
|||
return document->plugin->functions.document_attachment_save(document, document->data, attachment, file);
|
||||
}
|
||||
|
||||
char*
|
||||
zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta, zathura_error_t* error)
|
||||
girara_list_t*
|
||||
zathura_document_get_information(zathura_document_t* document, zathura_error_t* error)
|
||||
{
|
||||
if (document == NULL || document->plugin == NULL) {
|
||||
if (error != NULL) {
|
||||
|
@ -525,14 +525,19 @@ zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (document->plugin->functions.document_meta_get == NULL) {
|
||||
if (document->plugin->functions.document_get_information == NULL) {
|
||||
if (error != NULL) {
|
||||
*error = ZATHURA_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return document->plugin->functions.document_meta_get(document, document->data, meta, error);
|
||||
girara_list_t* result = document->plugin->functions.document_get_information(document, document->data, error);
|
||||
if (result != NULL) {
|
||||
girara_list_set_free_function(result, (girara_free_function_t) zathura_document_information_entry_free);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static const gchar*
|
||||
|
|
20
document.h
20
document.h
|
@ -11,21 +11,6 @@
|
|||
#include "zathura.h"
|
||||
#include "types.h"
|
||||
|
||||
/**
|
||||
* Meta data entries
|
||||
*/
|
||||
typedef enum zathura_document_meta_e
|
||||
{
|
||||
ZATHURA_DOCUMENT_TITLE, /**< Title of the document */
|
||||
ZATHURA_DOCUMENT_AUTHOR, /**< Author of the document */
|
||||
ZATHURA_DOCUMENT_SUBJECT, /**< Subject of the document */
|
||||
ZATHURA_DOCUMENT_KEYWORDS, /**< Keywords of the document */
|
||||
ZATHURA_DOCUMENT_CREATOR, /**< Creator of the document */
|
||||
ZATHURA_DOCUMENT_PRODUCER, /**< Producer of the document */
|
||||
ZATHURA_DOCUMENT_CREATION_DATE, /**< Creation data */
|
||||
ZATHURA_DOCUMENT_MODIFICATION_DATE /**< Modification data */
|
||||
} zathura_document_meta_t;
|
||||
|
||||
/**
|
||||
* Open the document
|
||||
*
|
||||
|
@ -231,11 +216,10 @@ zathura_error_t zathura_document_attachment_save(zathura_document_t* document, c
|
|||
* Returns a string of the requested information
|
||||
*
|
||||
* @param document The zathura document
|
||||
* @param meta The information field
|
||||
* @param error Set to an error value (see \ref zathura_error_t) if an
|
||||
* error occured
|
||||
* @return String or NULL if information could not be retreived
|
||||
* @return List of document information entries or NULL if information could not be retreived
|
||||
*/
|
||||
char* zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta, zathura_error_t* error);
|
||||
girara_list_t* zathura_document_get_information(zathura_document_t* document, zathura_error_t* error);
|
||||
|
||||
#endif // DOCUMENT_H
|
||||
|
|
|
@ -100,7 +100,7 @@ struct zathura_plugin_functions_s
|
|||
/**
|
||||
* Get document information
|
||||
*/
|
||||
char* (*document_meta_get)(zathura_document_t* document, void* data, zathura_document_meta_t info, zathura_error_t* error);
|
||||
girara_list_t* (*document_get_information)(zathura_document_t* document, void* data, zathura_error_t* error);
|
||||
|
||||
/**
|
||||
* Gets the page object
|
||||
|
|
40
types.c
40
types.c
|
@ -1,6 +1,7 @@
|
|||
/* See LICENSE file for license and copyright information */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <girara/datastructures.h>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
|
@ -145,3 +146,42 @@ zathura_image_buffer_free(zathura_image_buffer_t* image_buffer)
|
|||
free(image_buffer);
|
||||
}
|
||||
|
||||
girara_list_t*
|
||||
zathura_document_information_entry_list_new()
|
||||
{
|
||||
girara_list_t* list = girara_list_new2((girara_free_function_t)
|
||||
zathura_document_information_entry_free);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
zathura_document_information_entry_t*
|
||||
zathura_document_information_entry_new(zathura_document_information_type_t type,
|
||||
const char* value)
|
||||
{
|
||||
if (value == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
zathura_document_information_entry_t* entry =
|
||||
g_malloc0(sizeof(zathura_document_information_entry_t));
|
||||
|
||||
entry->type = type;
|
||||
entry->value = g_strdup(value);
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
void
|
||||
zathura_document_information_entry_free(zathura_document_information_entry_t* entry)
|
||||
{
|
||||
if (entry == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (entry->value != NULL) {
|
||||
g_free(entry->value);
|
||||
}
|
||||
|
||||
g_free(entry);
|
||||
}
|
||||
|
|
55
types.h
55
types.h
|
@ -23,6 +23,34 @@ typedef enum zathura_plugin_error_e
|
|||
ZATHURA_ERROR_INVALID_PASSWORD /**< The provided password is invalid */
|
||||
} zathura_error_t;
|
||||
|
||||
/**
|
||||
* Possible information entry types
|
||||
*/
|
||||
typedef enum zathura_document_information_type_e
|
||||
{
|
||||
ZATHURA_DOCUMENT_INFORMATION_TITLE, /**< Title of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_AUTHOR, /**< Author of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_SUBJECT, /**< Subject of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_KEYWORDS, /**< Keywords of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_CREATOR, /**< Creator of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_PRODUCER, /**< Producer of the document */
|
||||
ZATHURA_DOCUMENT_INFORMATION_CREATION_DATE, /**< Creation data */
|
||||
ZATHURA_DOCUMENT_INFORMATION_MODIFICATION_DATE, /**< Modification data */
|
||||
ZATHURA_DOCUMENT_INFORMATION_OTHER /**< Any other information */
|
||||
} zathura_document_information_type_t;
|
||||
|
||||
/**
|
||||
* Document information entry
|
||||
*
|
||||
* Represents a single entry in the returned list from the \ref
|
||||
* zathura_document_get_information function
|
||||
*/
|
||||
typedef struct zathura_document_information_entry_s
|
||||
{
|
||||
zathura_document_information_type_t type; /**< Type of the information */
|
||||
char* value; /**< Value */
|
||||
} zathura_document_information_entry_t;
|
||||
|
||||
/**
|
||||
* Image buffer
|
||||
*/
|
||||
|
@ -197,4 +225,31 @@ zathura_rectangle_t zathura_link_get_position(zathura_link_t* link);
|
|||
*/
|
||||
zathura_link_target_t zathura_link_get_target(zathura_link_t* link);
|
||||
|
||||
/**
|
||||
* Creates a list that should be used to store \ref
|
||||
* zathura_document_information_entry_t entries
|
||||
*
|
||||
* @return A list or NULL if an error occured
|
||||
*/
|
||||
girara_list_t* zathura_document_information_entry_list_new();
|
||||
|
||||
/**
|
||||
* Creates a new document information entry
|
||||
*
|
||||
* @param type The type
|
||||
* @param value The value
|
||||
*
|
||||
* @return A new entry or NULL if an error occured
|
||||
*/
|
||||
zathura_document_information_entry_t*
|
||||
zathura_document_information_entry_new(zathura_document_information_type_t
|
||||
type, const char* value);
|
||||
|
||||
/**
|
||||
* Frees a document information entry
|
||||
*
|
||||
* @param entry The entry that should be freed
|
||||
*/
|
||||
void zathura_document_information_entry_free(zathura_document_information_entry_t* entry);
|
||||
|
||||
#endif // TYPES_H
|
||||
|
|
Loading…
Reference in a new issue