From 42307d4e65b5dd721be3bbd57220c44f12a7ba07 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 7 Feb 2012 20:13:39 +0100 Subject: [PATCH 1/4] Added documentation --- document.h | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/document.h b/document.h index d4d8ce8..8fdacfb 100644 --- a/document.h +++ b/document.h @@ -24,22 +24,28 @@ typedef struct zathura_document_plugin_s void* handle; /**< DLL handle */ } zathura_document_plugin_t; +/** + * Plugin mapping + */ typedef struct zathura_type_plugin_mapping_s { - const gchar* type; - zathura_document_plugin_t* plugin; + const gchar* type; /**< Plugin type */ + zathura_document_plugin_t* plugin; /**< Mapped plugin */ } zathura_type_plugin_mapping_t; +/** + * Meta data entries + */ 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_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; /** From 6a3fb02736183babc69b09afdae800f56bd97346 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 7 Feb 2012 20:54:20 +0100 Subject: [PATCH 2/4] Fix automatic reload --- document.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document.c b/document.c index 3de028d..289a215 100644 --- a/document.c +++ b/document.c @@ -309,7 +309,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password goto error_free; } - g_signal_connect(G_OBJECT(document->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), document); + g_signal_connect(G_OBJECT(document->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), zathura->ui.session); g_free(file_uri); From 626fd50e320244cfa6f783d8e7b92677fce0aee8 Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 7 Feb 2012 21:01:54 +0100 Subject: [PATCH 3/4] Introduced zathura_plugin_error_t --- commands.c | 4 +-- completion.c | 4 +-- document.c | 68 ++++++++++++++++++----------------- document.h | 98 +++++++++++++++++++++++++++++++-------------------- page_widget.c | 4 +-- shortcuts.c | 2 +- 6 files changed, 103 insertions(+), 77 deletions(-) diff --git a/commands.c b/commands.c index 02b4c8c..7455326 100644 --- a/commands.c +++ b/commands.c @@ -154,7 +154,7 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list)) } for (unsigned int i = 0; i < LENGTH(meta_fields); i++) { - char* tmp = zathura_document_meta_get(zathura->document, meta_fields[i].field); + 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); if (text == NULL) { @@ -294,7 +294,7 @@ cmd_search(girara_session_t* session, const char* input, girara_argument_t* argu g_object_set(page->drawing_area, "draw-links", FALSE, NULL); - girara_list_t* result = zathura_page_search_text(page, input); + girara_list_t* result = zathura_page_search_text(page, input, NULL); if (result == NULL || girara_list_size(result) == 0) { girara_list_free(result); g_object_set(page->drawing_area, "search-results", NULL, NULL); diff --git a/completion.c b/completion.c index 03a1571..4f26f78 100644 --- a/completion.c +++ b/completion.c @@ -237,8 +237,8 @@ cc_export(girara_session_t* session, const char* input) } const size_t input_length = strlen(input); - girara_list_t* attachments = zathura_document_attachments_get(zathura->document); - if (!attachments) { + girara_list_t* attachments = zathura_document_attachments_get(zathura->document, NULL); + if (attachments == NULL) { goto error_free; } diff --git a/document.c b/document.c index 289a215..cae9cef 100644 --- a/document.c +++ b/document.c @@ -285,7 +285,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password } for (unsigned int page_id = 0; page_id < document->number_of_pages; page_id++) { - zathura_page_t* page = zathura_page_get(document, page_id); + zathura_page_t* page = zathura_page_get(document, page_id, NULL); if (page == NULL) { goto error_free; } @@ -335,7 +335,7 @@ error_free: return NULL; } -bool +zathura_plugin_error_t zathura_document_free(zathura_document_t* document) { if (document == NULL) { @@ -367,7 +367,7 @@ zathura_document_free(zathura_document_t* document) return r; } -bool +zathura_plugin_error_t zathura_document_save_as(zathura_document_t* document, const char* path) { if (document == NULL || path == NULL) { @@ -383,7 +383,7 @@ zathura_document_save_as(zathura_document_t* document, const char* path) } girara_tree_node_t* -zathura_document_index_generate(zathura_document_t* document) +zathura_document_index_generate(zathura_document_t* document, zathura_plugin_error_t* error) { if (document == NULL) { return NULL; @@ -394,11 +394,11 @@ zathura_document_index_generate(zathura_document_t* document) return NULL; } - return document->functions.document_index_generate(document); + return document->functions.document_index_generate(document, error); } girara_list_t* -zathura_document_attachments_get(zathura_document_t* document) +zathura_document_attachments_get(zathura_document_t* document, zathura_plugin_error_t* error) { if (document == NULL) { return NULL; @@ -409,40 +409,45 @@ zathura_document_attachments_get(zathura_document_t* document) return NULL; } - return document->functions.document_attachments_get(document); + return document->functions.document_attachments_get(document, error); } -bool zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file) +zathura_plugin_error_t +zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file) { if (document == NULL) { - return NULL; + return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } if (document->functions.document_attachment_save == NULL) { - girara_error("%s not implemented", __FUNCTION__); - return NULL; + return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } return document->functions.document_attachment_save(document, attachment, file); } char* -zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta) +zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta, zathura_plugin_error_t* error) { if (document == NULL) { + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } if (document->functions.document_meta_get == NULL) { - girara_error("%s not implemented", __FUNCTION__); + if (error != NULL) { + *error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; + } return NULL; } - return document->functions.document_meta_get(document, meta); + return document->functions.document_meta_get(document, meta, error); } 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, zathura_plugin_error_t* error) { if (document == NULL) { return NULL; @@ -453,7 +458,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) return NULL; } - zathura_page_t* page = document->functions.page_get(document, page_id); + zathura_page_t* page = document->functions.page_get(document, page_id, error); if (page != NULL) { page->number = page_id; @@ -467,7 +472,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id) return page; } -bool +zathura_plugin_error_t zathura_page_free(zathura_page_t* page) { if (page == NULL || page->document == NULL) { @@ -483,7 +488,7 @@ zathura_page_free(zathura_page_t* page) } girara_list_t* -zathura_page_search_text(zathura_page_t* page, const char* text) +zathura_page_search_text(zathura_page_t* page, const char* text, zathura_plugin_error_t* error) { if (page == NULL || page->document == NULL || text == NULL) { return NULL; @@ -494,11 +499,11 @@ zathura_page_search_text(zathura_page_t* page, const char* text) return NULL; } - return page->document->functions.page_search_text(page, text); + return page->document->functions.page_search_text(page, text, error); } girara_list_t* -zathura_page_links_get(zathura_page_t* page) +zathura_page_links_get(zathura_page_t* page, zathura_plugin_error_t* error) { if (page == NULL || page->document == NULL) { return NULL; @@ -509,17 +514,17 @@ zathura_page_links_get(zathura_page_t* page) return NULL; } - return page->document->functions.page_links_get(page); + return page->document->functions.page_links_get(page, error); } -bool +zathura_plugin_error_t zathura_page_links_free(girara_list_t* UNUSED(list)) { return false; } girara_list_t* -zathura_page_form_fields_get(zathura_page_t* page) +zathura_page_form_fields_get(zathura_page_t* page, zathura_plugin_error_t* error) { if (page == NULL || page->document == NULL) { return NULL; @@ -530,17 +535,17 @@ zathura_page_form_fields_get(zathura_page_t* page) return NULL; } - return page->document->functions.page_form_fields_get(page); + return page->document->functions.page_form_fields_get(page, error); } -bool +zathura_plugin_error_t zathura_page_form_fields_free(girara_list_t* UNUSED(list)) { return false; } girara_list_t* -zathura_page_images_get(zathura_page_t* page) +zathura_page_images_get(zathura_page_t* page, zathura_plugin_error_t* error) { if (page == NULL || page->document == NULL) { return NULL; @@ -551,11 +556,10 @@ zathura_page_images_get(zathura_page_t* page) return false; } - return page->document->functions.page_images_get(page); - + return page->document->functions.page_images_get(page, error); } -bool +zathura_plugin_error_t zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char* file) { if (page == NULL || page->document == NULL || image == NULL || file == NULL) { @@ -570,16 +574,16 @@ zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char return page->document->functions.page_image_save(page, image, file); } -bool +zathura_plugin_error_t zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing) { if (page == NULL || page->document == NULL || cairo == NULL) { - return NULL; + return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS; } if (page->document->functions.page_render_cairo == NULL) { girara_error("%s not implemented", __FUNCTION__); - return NULL; + return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED; } return page->document->functions.page_render_cairo(page, cairo, printing); diff --git a/document.h b/document.h index 8fdacfb..f8d9cb7 100644 --- a/document.h +++ b/document.h @@ -12,7 +12,26 @@ #define PLUGIN_REGISTER_FUNCTION "plugin_register" -typedef bool (*zathura_document_open_t)(zathura_document_t* document); +/** + * Error types for plugins + */ +typedef enum zathura_plugin_error_e +{ + ZATHURA_PLUGIN_ERROR_OK, /**< No error occured */ + ZATHURA_PLUGIN_ERROR_UNKNOWN, /**< An unknown error occured */ + ZATHURA_PLUGIN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED, /**< The called function has not been implemented */ + ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS, /**< Invalid arguments have been passed */ + ZATHURA_PLUGIN_ERROR_INVALID_PASSWORD /**< The provided password is invalid */ +} zathura_plugin_error_t; + +/** + * Document open function + * + * @param document The document + * @return true if no error occured otherwise false + */ +typedef zathura_plugin_error_t (*zathura_document_open_t)(zathura_document_t* document); /** * Document plugin structure @@ -190,77 +209,77 @@ struct zathura_document_s /** * Frees the document */ - bool (*document_free)(zathura_document_t* document); + zathura_plugin_error_t (*document_free)(zathura_document_t* document); /** * Generates the document index */ - girara_tree_node_t* (*document_index_generate)(zathura_document_t* document); + girara_tree_node_t* (*document_index_generate)(zathura_document_t* document, zathura_plugin_error_t* error); /** * Save the document */ - bool (*document_save_as)(zathura_document_t* document, const char* path); + zathura_plugin_error_t (*document_save_as)(zathura_document_t* document, const char* path); /** * Get list of attachments */ - girara_list_t* (*document_attachments_get)(zathura_document_t* document); + girara_list_t* (*document_attachments_get)(zathura_document_t* document, zathura_plugin_error_t* error); /** * Save attachment to a file */ - bool (*document_attachment_save)(zathura_document_t* document, const char* attachment, const char* file); + zathura_plugin_error_t (*document_attachment_save)(zathura_document_t* document, const char* attachment, const char* file); /** * Get document information */ - char* (*document_meta_get)(zathura_document_t* document, zathura_document_meta_t info); + char* (*document_meta_get)(zathura_document_t* document, zathura_document_meta_t info, zathura_plugin_error_t* error); /** * Gets the page object */ - zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id); + zathura_page_t* (*page_get)(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error); /** * Search text */ - girara_list_t* (*page_search_text)(zathura_page_t* page, const char* text); + girara_list_t* (*page_search_text)(zathura_page_t* page, const char* text, zathura_plugin_error_t* error); /** * Get links on a page */ - girara_list_t* (*page_links_get)(zathura_page_t* page); + girara_list_t* (*page_links_get)(zathura_page_t* page, zathura_plugin_error_t* error); /** * Get form fields */ - girara_list_t* (*page_form_fields_get)(zathura_page_t* page); + girara_list_t* (*page_form_fields_get)(zathura_page_t* page, zathura_plugin_error_t* error); /** * Get list of images */ - girara_list_t* (*page_images_get)(zathura_page_t* page); + girara_list_t* (*page_images_get)(zathura_page_t* page, zathura_plugin_error_t* error); /** * Save image to a file */ - bool (*page_image_save)(zathura_page_t* page, zathura_image_t* image, const char* file); + zathura_plugin_error_t (*page_image_save)(zathura_page_t* page, zathura_image_t* image, const char* file); /** * Renders the page */ - zathura_image_buffer_t* (*page_render)(zathura_page_t* page); + zathura_image_buffer_t* (*page_render)(zathura_page_t* page, zathura_plugin_error_t* error); /** * Renders the page */ - bool (*page_render_cairo)(zathura_page_t* page, cairo_t* cairo, bool printing); + zathura_plugin_error_t (*page_render_cairo)(zathura_page_t* page, cairo_t* cairo, bool printing); /** * Free page */ - bool (*page_free)(zathura_page_t* page); + zathura_plugin_error_t (*page_free)(zathura_page_t* page); } functions; /** @@ -298,24 +317,25 @@ void zathura_document_plugin_free(zathura_document_plugin_t* plugin); * @param password Password of the document or NULL * @return The document object */ -zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, const char* password); +zathura_document_t* zathura_document_open(zathura_t* zathura, const char* path, + const char* password); /** * Free the document * * @param document - * @return true if no error occured, otherwise false + * @return See \ref zathura_plugin_error_t */ -bool zathura_document_free(zathura_document_t* document); +zathura_plugin_error_t zathura_document_free(zathura_document_t* document); /** * Save the document * * @param document The document object * @param path Path for the saved file - * @return true if no error occured, otherwise false + * @return See \ref zathura_plugin_error_t */ -bool zathura_document_save_as(zathura_document_t* document, const char* path); +zathura_plugin_error_t zathura_document_save_as(zathura_document_t* document, const char* path); /** * Generate the document index @@ -324,7 +344,7 @@ bool zathura_document_save_as(zathura_document_t* document, const char* path); * @return Generated index */ -girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document); +girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document, zathura_plugin_error_t* error); /** * Get list of attachments @@ -332,7 +352,7 @@ girara_tree_node_t* zathura_document_index_generate(zathura_document_t* document * @param document The document object * @return List of attachments */ -girara_list_t* zathura_document_attachments_get(zathura_document_t* document); +girara_list_t* zathura_document_attachments_get(zathura_document_t* document, zathura_plugin_error_t* error); /** * Save document attachment @@ -342,7 +362,7 @@ girara_list_t* zathura_document_attachments_get(zathura_document_t* document); * @param file the target filename * @return true on success, false otherwise */ -bool zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file); +zathura_plugin_error_t zathura_document_attachment_save(zathura_document_t* document, const char* attachment, const char* file); /** * Returns a string of the requested information @@ -351,7 +371,7 @@ bool zathura_document_attachment_save(zathura_document_t* document, const char* * @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); +char* zathura_document_meta_get(zathura_document_t* document, zathura_document_meta_t meta, zathura_plugin_error_t* error); /** * Get the page object @@ -360,7 +380,7 @@ char* zathura_document_meta_get(zathura_document_t* document, zathura_document_m * @param page_id Page number * @return Page object or NULL if an error occured */ -zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id); +zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page_id, zathura_plugin_error_t* error); /** * Frees the page object @@ -368,7 +388,7 @@ zathura_page_t* zathura_page_get(zathura_document_t* document, unsigned int page * @param page The page object * @return true if no error occured, otherwise false */ -bool zathura_page_free(zathura_page_t* page); +zathura_plugin_error_t zathura_page_free(zathura_page_t* page); /** * Search page @@ -377,7 +397,7 @@ bool zathura_page_free(zathura_page_t* page); * @param text Search item * @return List of results */ -girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); +girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text, zathura_plugin_error_t* error); /** * Get page links @@ -385,7 +405,7 @@ girara_list_t* zathura_page_search_text(zathura_page_t* page, const char* text); * @param page The page object * @return List of links */ -girara_list_t* zathura_page_links_get(zathura_page_t* page); +girara_list_t* zathura_page_links_get(zathura_page_t* page, zathura_plugin_error_t* error); /** * Free page links @@ -393,7 +413,7 @@ girara_list_t* zathura_page_links_get(zathura_page_t* page); * @param list List of links * @return true if no error occured, otherwise false */ -bool zathura_page_links_free(girara_list_t* list); +zathura_plugin_error_t zathura_page_links_free(girara_list_t* list); /** * Get list of form fields @@ -401,23 +421,25 @@ bool zathura_page_links_free(girara_list_t* list); * @param page The page object * @return List of form fields */ -girara_list_t* zathura_page_form_fields_get(zathura_page_t* page); +girara_list_t* zathura_page_form_fields_get(zathura_page_t* page, zathura_plugin_error_t* error); /** * Free list of form fields * * @param list List of form fields + * @param error See \ref zathura_plugin_error_t * @return true if no error occured, otherwise false */ -bool zathura_page_form_fields_free(girara_list_t* list); +zathura_plugin_error_t zathura_page_form_fields_free(girara_list_t* list); /** * Get list of images * * @param page Page - * @return List of images + * @param error See \ref zathura_plugin_error_t + * @return List of images or NULL if an error occured */ -girara_list_t* zathura_page_images_get(zathura_page_t* page); +girara_list_t* zathura_page_images_get(zathura_page_t* page, zathura_plugin_error_t* error); /** * Save image @@ -425,9 +447,9 @@ girara_list_t* zathura_page_images_get(zathura_page_t* page); * @param page Page * @param image The image * @param file Path to the file - * @return true if no error occured + * @return See \ref zathura_plugin_error_t */ -bool zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char* file); +zathura_plugin_error_t zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const char* file); /** * Render page @@ -435,9 +457,9 @@ bool zathura_page_image_save(zathura_page_t* page, zathura_image_t* image, const * @param page The page object * @param cairo Cairo object * @param printing render for printing - * @return True if no error occured, otherwise false + * @return See \ref zathura_plugin_error_t */ -bool zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing); +zathura_plugin_error_t zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing); /** * Create new index element diff --git a/page_widget.c b/page_widget.c index 1e99e3e..2991b38 100644 --- a/page_widget.c +++ b/page_widget.c @@ -146,7 +146,7 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v priv->draw_links = g_value_get_boolean(value); /* get links */ if (priv->draw_links == true && priv->links_got == false) { - priv->links = zathura_page_links_get(priv->page); + priv->links = zathura_page_links_get(priv->page, NULL); priv->links_got = true; priv->number_of_links = (priv->links == NULL) ? 0 : girara_list_size(priv->links); } @@ -430,7 +430,7 @@ cb_zathura_page_widget_button_press_event(GtkWidget* widget, GdkEventButton* but /* get links */ if (priv->links_got == false) { - priv->links = zathura_page_links_get(priv->page); + priv->links = zathura_page_links_get(priv->page, NULL); priv->links_got = true; priv->number_of_links = (priv->links == NULL) ? 0 : girara_list_size(priv->links); } diff --git a/shortcuts.c b/shortcuts.c index b85c47a..7c1f36f 100644 --- a/shortcuts.c +++ b/shortcuts.c @@ -555,7 +555,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); /* create index */ - document_index = zathura_document_index_generate(zathura->document); + document_index = zathura_document_index_generate(zathura->document, NULL); if (document_index == NULL) { // TODO: Error message goto error_free; From b0cf2749e2948ac50c8765a3545a06b3b3dfb8bc Mon Sep 17 00:00:00 2001 From: Moritz Lipp Date: Tue, 7 Feb 2012 21:13:29 +0100 Subject: [PATCH 4/4] Fix open_function call --- document.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/document.c b/document.c index cae9cef..cff63b9 100644 --- a/document.c +++ b/document.c @@ -270,7 +270,7 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password document->scale = 1; } - if (plugin->open_function == NULL || plugin->open_function(document) == false) { + if (plugin->open_function == NULL || plugin->open_function(document) != ZATHURA_PLUGIN_ERROR_OK) { girara_error("could not open file\n"); goto error_free; }