Introduced zathura_plugin_error_t

This commit is contained in:
Moritz Lipp 2012-02-07 21:01:54 +01:00
parent 6a3fb02736
commit 626fd50e32
6 changed files with 103 additions and 77 deletions

View file

@ -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++) { 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) { if (tmp != NULL) {
char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, tmp); char* text = g_strdup_printf("<b>%s:</b> %s\n", meta_fields[i].name, tmp);
if (text == NULL) { 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); 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) { if (result == NULL || girara_list_size(result) == 0) {
girara_list_free(result); girara_list_free(result);
g_object_set(page->drawing_area, "search-results", NULL, NULL); g_object_set(page->drawing_area, "search-results", NULL, NULL);

View file

@ -237,8 +237,8 @@ cc_export(girara_session_t* session, const char* input)
} }
const size_t input_length = strlen(input); const size_t input_length = strlen(input);
girara_list_t* attachments = zathura_document_attachments_get(zathura->document); girara_list_t* attachments = zathura_document_attachments_get(zathura->document, NULL);
if (!attachments) { if (attachments == NULL) {
goto error_free; goto error_free;
} }

View file

@ -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++) { 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) { if (page == NULL) {
goto error_free; goto error_free;
} }
@ -335,7 +335,7 @@ error_free:
return NULL; return NULL;
} }
bool zathura_plugin_error_t
zathura_document_free(zathura_document_t* document) zathura_document_free(zathura_document_t* document)
{ {
if (document == NULL) { if (document == NULL) {
@ -367,7 +367,7 @@ zathura_document_free(zathura_document_t* document)
return r; return r;
} }
bool zathura_plugin_error_t
zathura_document_save_as(zathura_document_t* document, const char* path) zathura_document_save_as(zathura_document_t* document, const char* path)
{ {
if (document == NULL || path == NULL) { if (document == NULL || path == NULL) {
@ -383,7 +383,7 @@ zathura_document_save_as(zathura_document_t* document, const char* path)
} }
girara_tree_node_t* 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) { if (document == NULL) {
return NULL; return NULL;
@ -394,11 +394,11 @@ zathura_document_index_generate(zathura_document_t* document)
return NULL; return NULL;
} }
return document->functions.document_index_generate(document); return document->functions.document_index_generate(document, error);
} }
girara_list_t* 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) { if (document == NULL) {
return NULL; return NULL;
@ -409,40 +409,45 @@ zathura_document_attachments_get(zathura_document_t* document)
return NULL; 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) { if (document == NULL) {
return NULL; return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS;
} }
if (document->functions.document_attachment_save == NULL) { if (document->functions.document_attachment_save == NULL) {
girara_error("%s not implemented", __FUNCTION__); return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED;
return NULL;
} }
return document->functions.document_attachment_save(document, attachment, file); return document->functions.document_attachment_save(document, attachment, file);
} }
char* 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 (document == NULL) {
if (error != NULL) {
*error = ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED;
}
return NULL; return NULL;
} }
if (document->functions.document_meta_get == 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 NULL;
} }
return document->functions.document_meta_get(document, meta); return document->functions.document_meta_get(document, meta, error);
} }
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, zathura_plugin_error_t* error)
{ {
if (document == NULL) { if (document == NULL) {
return NULL; return NULL;
@ -453,7 +458,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
return NULL; 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) { if (page != NULL) {
page->number = page_id; page->number = page_id;
@ -467,7 +472,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
return page; return page;
} }
bool zathura_plugin_error_t
zathura_page_free(zathura_page_t* page) zathura_page_free(zathura_page_t* page)
{ {
if (page == NULL || page->document == NULL) { if (page == NULL || page->document == NULL) {
@ -483,7 +488,7 @@ zathura_page_free(zathura_page_t* page)
} }
girara_list_t* 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) { if (page == NULL || page->document == NULL || text == NULL) {
return NULL; return NULL;
@ -494,11 +499,11 @@ zathura_page_search_text(zathura_page_t* page, const char* text)
return NULL; return NULL;
} }
return page->document->functions.page_search_text(page, text); return page->document->functions.page_search_text(page, text, error);
} }
girara_list_t* 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) { if (page == NULL || page->document == NULL) {
return NULL; return NULL;
@ -509,17 +514,17 @@ zathura_page_links_get(zathura_page_t* page)
return NULL; 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)) zathura_page_links_free(girara_list_t* UNUSED(list))
{ {
return false; return false;
} }
girara_list_t* 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) { if (page == NULL || page->document == NULL) {
return NULL; return NULL;
@ -530,17 +535,17 @@ zathura_page_form_fields_get(zathura_page_t* page)
return NULL; 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)) zathura_page_form_fields_free(girara_list_t* UNUSED(list))
{ {
return false; return false;
} }
girara_list_t* 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) { if (page == NULL || page->document == NULL) {
return NULL; return NULL;
@ -551,11 +556,10 @@ zathura_page_images_get(zathura_page_t* page)
return false; 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) 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) { 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); 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) zathura_page_render(zathura_page_t* page, cairo_t* cairo, bool printing)
{ {
if (page == NULL || page->document == NULL || cairo == NULL) { if (page == NULL || page->document == NULL || cairo == NULL) {
return NULL; return ZATHURA_PLUGIN_ERROR_INVALID_ARGUMENTS;
} }
if (page->document->functions.page_render_cairo == NULL) { if (page->document->functions.page_render_cairo == NULL) {
girara_error("%s not implemented", __FUNCTION__); girara_error("%s not implemented", __FUNCTION__);
return NULL; return ZATHURA_PLUGIN_ERROR_NOT_IMPLEMENTED;
} }
return page->document->functions.page_render_cairo(page, cairo, printing); return page->document->functions.page_render_cairo(page, cairo, printing);

View file

@ -12,7 +12,26 @@
#define PLUGIN_REGISTER_FUNCTION "plugin_register" #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 * Document plugin structure
@ -190,77 +209,77 @@ struct zathura_document_s
/** /**
* Frees the document * Frees the document
*/ */
bool (*document_free)(zathura_document_t* document); zathura_plugin_error_t (*document_free)(zathura_document_t* document);
/** /**
* Generates the document index * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * 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 * Free page
*/ */
bool (*page_free)(zathura_page_t* page); zathura_plugin_error_t (*page_free)(zathura_page_t* page);
} functions; } functions;
/** /**
@ -298,24 +317,25 @@ void zathura_document_plugin_free(zathura_document_plugin_t* plugin);
* @param password Password of the document or NULL * @param password Password of the document or NULL
* @return The document object * @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 * Free the document
* *
* @param 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 * Save the document
* *
* @param document The document object * @param document The document object
* @param path Path for the saved file * @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 * Generate the document index
@ -324,7 +344,7 @@ bool zathura_document_save_as(zathura_document_t* document, const char* path);
* @return Generated index * @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 * 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 * @param document The document object
* @return List of attachments * @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 * Save document attachment
@ -342,7 +362,7 @@ girara_list_t* zathura_document_attachments_get(zathura_document_t* document);
* @param file the target filename * @param file the target filename
* @return true on success, false otherwise * @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 * 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 * @param meta The information field
* @return String or NULL if information could not be retreived * @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 * 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 * @param page_id Page number
* @return Page object or NULL if an error occured * @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 * 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 * @param page The page object
* @return true if no error occured, otherwise false * @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 * Search page
@ -377,7 +397,7 @@ bool zathura_page_free(zathura_page_t* page);
* @param text Search item * @param text Search item
* @return List of results * @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 * 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 * @param page The page object
* @return List of links * @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 * Free page links
@ -393,7 +413,7 @@ girara_list_t* zathura_page_links_get(zathura_page_t* page);
* @param list List of links * @param list List of links
* @return true if no error occured, otherwise false * @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 * Get list of form fields
@ -401,23 +421,25 @@ bool zathura_page_links_free(girara_list_t* list);
* @param page The page object * @param page The page object
* @return List of form fields * @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 * Free list of form fields
* *
* @param list 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 * @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 * Get list of images
* *
* @param page Page * @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 * Save image
@ -425,9 +447,9 @@ girara_list_t* zathura_page_images_get(zathura_page_t* page);
* @param page Page * @param page Page
* @param image The image * @param image The image
* @param file Path to the file * @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 * 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 page The page object
* @param cairo Cairo object * @param cairo Cairo object
* @param printing render for printing * @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 * Create new index element

View file

@ -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); priv->draw_links = g_value_get_boolean(value);
/* get links */ /* get links */
if (priv->draw_links == true && priv->links_got == false) { 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->links_got = true;
priv->number_of_links = (priv->links == NULL) ? 0 : girara_list_size(priv->links); 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 */ /* get links */
if (priv->links_got == false) { 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->links_got = true;
priv->number_of_links = (priv->links == NULL) ? 0 : girara_list_size(priv->links); priv->number_of_links = (priv->links == NULL) ? 0 : girara_list_size(priv->links);
} }

View file

@ -555,7 +555,7 @@ sc_toggle_index(girara_session_t* session, girara_argument_t* UNUSED(argument),
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
/* create index */ /* create index */
document_index = zathura_document_index_generate(zathura->document); document_index = zathura_document_index_generate(zathura->document, NULL);
if (document_index == NULL) { if (document_index == NULL) {
// TODO: Error message // TODO: Error message
goto error_free; goto error_free;