diff --git a/bookmarks.c b/bookmarks.c
index 3d142a2..78081e2 100644
--- a/bookmarks.c
+++ b/bookmarks.c
@@ -34,7 +34,7 @@ zathura_bookmark_add(zathura_t* zathura, const gchar* id, unsigned int page)
girara_list_append(zathura->bookmarks.bookmarks, bookmark);
if (zathura->database != NULL) {
- const char* path = zathura_document_get_path(zathura->document);
+ const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_add_bookmark(zathura->database, path, bookmark) == false) {
girara_warning("Failed to add bookmark to database.");
}
@@ -55,7 +55,7 @@ zathura_bookmark_remove(zathura_t* zathura, const gchar* id)
}
if (zathura->database != NULL) {
- const char* path = zathura_document_get_path(zathura->document);
+ const char* path = zathura_document_get_path(zathura->document);
if (zathura_db_remove_bookmark(zathura->database, path, bookmark->id) == false) {
girara_warning("Failed to remove bookmark from database.");
}
diff --git a/commands.c b/commands.c
index c688d2a..e2b4dbf 100644
--- a/commands.c
+++ b/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;
- }
- 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("%s: %s\n", meta_fields[i].name, tmp);
- g_string_append(string, text);
-
- g_free(text);
- g_free(tmp);
+ GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry)
+ for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
+ if (meta_fields[i].field == entry->type) {
+ char* text = g_strdup_printf("%s: %s\n", meta_fields[i].name, entry->value);
+ g_string_append(string, text);
+ g_free(text);
+ }
}
- }
+ 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);
@@ -309,7 +311,7 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
- unsigned int index = (page_id + current_page_number) % number_of_pages;
+ unsigned int index = (page_id + current_page_number) % number_of_pages;
zathura_page_t* page = zathura_document_get_page(zathura->document, index);
if (page == NULL) {
continue;
diff --git a/document.c b/document.c
index 6ffe7f7..654955f 100644
--- a/document.c
+++ b/document.c
@@ -53,10 +53,10 @@ struct zathura_document_s
*/
zathura_page_t** pages;
- /**
- * Used plugin
- */
- zathura_plugin_t* plugin;
+ /**
+ * Used plugin
+ */
+ zathura_plugin_t* plugin;
};
@@ -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*
diff --git a/document.h b/document.h
index 330a8ae..f125f06 100644
--- a/document.h
+++ b/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
diff --git a/page-widget.c b/page-widget.c
index 70798ae..bb7205c 100644
--- a/page-widget.c
+++ b/page-widget.c
@@ -300,7 +300,7 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
if (priv->surface != NULL) {
cairo_save(cairo);
- unsigned int rotation = zathura_document_get_rotation(document);
+ unsigned int rotation = zathura_document_get_rotation(document);
switch (rotation) {
case 90:
cairo_translate(cairo, page_width, 0);
@@ -563,7 +563,7 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
redraw_rect(ZATHURA_PAGE(widget), &priv->selection);
zathura_rectangle_t tmp = priv->selection;
- double scale = zathura_document_get_scale(document);
+ double scale = zathura_document_get_scale(document);
tmp.x1 /= scale;
tmp.x2 /= scale;
tmp.y1 /= scale;
diff --git a/plugin-api.h b/plugin-api.h
index cfd6f54..653e4a7 100644
--- a/plugin-api.h
+++ b/plugin-api.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
diff --git a/render.c b/render.c
index 53e806e..26019ca 100644
--- a/render.c
+++ b/render.c
@@ -111,7 +111,7 @@ render(zathura_t* zathura, zathura_page_t* page)
cairo_restore(cairo);
cairo_save(cairo);
- double scale = zathura_document_get_scale(zathura->document);
+ double scale = zathura_document_get_scale(zathura->document);
if (fabs(scale - 1.0f) > FLT_EPSILON) {
cairo_scale(cairo, scale, scale);
}
diff --git a/shortcuts.c b/shortcuts.c
index 28520ee..64ee9b1 100644
--- a/shortcuts.c
+++ b/shortcuts.c
@@ -20,15 +20,15 @@
static void
readjust_view_after_zooming(zathura_t *zathura, float old_zoom) {
- if (zathura == NULL || zathura->document == NULL) {
- return;
- }
+ if (zathura == NULL || zathura->document == NULL) {
+ return;
+ }
GtkScrolledWindow *window = GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view);
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(window);
GtkAdjustment* hadjustment = gtk_scrolled_window_get_hadjustment(window);
- double scale = zathura_document_get_scale(zathura->document);
+ double scale = zathura_document_get_scale(zathura->document);
gdouble valx = gtk_adjustment_get_value(hadjustment) / old_zoom * scale;
gdouble valy = gtk_adjustment_get_value(vadjustment) / old_zoom * scale;
set_adjustment(hadjustment, valx);
@@ -44,7 +44,7 @@ sc_abort(girara_session_t* session, girara_argument_t* UNUSED(argument),
zathura_t* zathura = session->global.data;
if (zathura->document != NULL) {
- unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
+ unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
if (page == NULL) {
@@ -78,7 +78,7 @@ sc_adjust_window(girara_session_t* session, girara_argument_t* argument,
}
float old_zoom = zathura_document_get_scale(zathura->document);
- zathura_document_set_adjust_mode(zathura->document, argument->n);
+ zathura_document_set_adjust_mode(zathura->document, argument->n);
if (argument->n == ZATHURA_ADJUST_NONE) {
/* there is nothing todo */
goto error_ret;
@@ -185,10 +185,10 @@ sc_focus_inputbar(girara_session_t* session, girara_argument_t* argument, girara
/* append filepath */
if (argument->n == APPEND_FILEPATH && zathura->document != NULL) {
- const char* file_path = zathura_document_get_path(zathura->document);
- if (file_path == NULL) {
- return false;
- }
+ const char* file_path = zathura_document_get_path(zathura->document);
+ if (file_path == NULL) {
+ return false;
+ }
char* path = dirname(g_strdup(file_path));
char* tmp = g_strdup_printf("%s%s/", (char*) argument->data, (g_strcmp0(path, "/") == 0) ? "" : path);
@@ -274,7 +274,7 @@ sc_goto(girara_session_t* session, girara_argument_t* argument, girara_event_t*
if (t != 0) {
/* add offset */
- unsigned int page_offset = zathura_document_get_page_offset(zathura->document);
+ unsigned int page_offset = zathura_document_get_page_offset(zathura->document);
if (page_offset > 0) {
t += page_offset;
}
@@ -468,7 +468,7 @@ sc_rotate(girara_session_t* session, girara_argument_t* argument,
}
/* update rotate value */
- unsigned int rotation = zathura_document_get_rotation(zathura->document);
+ unsigned int rotation = zathura_document_get_rotation(zathura->document);
zathura_document_set_rotation(zathura->document, (rotation + angle) % 360);
/* update scale */
@@ -966,9 +966,9 @@ sc_zoom(girara_session_t* session, girara_argument_t* argument, girara_event_t*
float scale = zathura_document_get_scale(zathura->document);
if (scale < zoom_min) {
- zathura_document_set_scale(zathura->document, zoom_min);
+ zathura_document_set_scale(zathura->document, zoom_min);
} else if (scale > zoom_max) {
- zathura_document_set_scale(zathura->document, zoom_max);
+ zathura_document_set_scale(zathura->document, zoom_max);
}
/* keep position */
diff --git a/types.c b/types.c
index ae12131..a3f219d 100644
--- a/types.c
+++ b/types.c
@@ -1,6 +1,7 @@
/* See LICENSE file for license and copyright information */
#include
+#include
#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);
+}
diff --git a/types.h b/types.h
index 1a520c5..f0e285f 100644
--- a/types.h
+++ b/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