X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=libdocument%2Fev-document.c;h=e1521b7b5596982c3e10c5d089f29f9b968390e8;hb=682a585a0bfee24d91343958cc44956931693c6f;hp=2c6db95a0a552b8acec54f285bfdec0e9be91b3e;hpb=982600bbceb76a22d5c7b3e0cbe6e20421105ad6;p=evince.git diff --git a/libdocument/ev-document.c b/libdocument/ev-document.c index 2c6db95a..e1521b7b 100644 --- a/libdocument/ev-document.c +++ b/libdocument/ev-document.c @@ -22,37 +22,10 @@ #include "ev-document.h" -#include "ev-backend-marshalers.h" - -static void ev_document_class_init (gpointer g_class); - - GMutex *ev_doc_mutex = NULL; GMutex *ev_fc_mutex = NULL; -#define LOG(x) -GType -ev_document_get_type (void) -{ - static GType type = 0; - - if (G_UNLIKELY (type == 0)) - { - const GTypeInfo our_info = - { - sizeof (EvDocumentIface), - NULL, - NULL, - (GClassInitFunc)ev_document_class_init - }; - - type = g_type_register_static (G_TYPE_INTERFACE, - "EvDocument", - &our_info, (GTypeFlags)0); - } - - return type; -} +EV_DEFINE_INTERFACE (EvDocument, ev_document, G_TYPE_OBJECT) GQuark ev_document_error_quark (void) @@ -65,7 +38,7 @@ ev_document_error_quark (void) } static void -ev_document_class_init (gpointer g_class) +ev_document_class_init (EvDocumentIface *klass) { } @@ -90,6 +63,12 @@ ev_document_doc_mutex_unlock (void) g_mutex_unlock (ev_document_get_doc_mutex ()); } +gboolean +ev_document_doc_mutex_trylock (void) +{ + return g_mutex_trylock (ev_document_get_doc_mutex ()); +} + GMutex * ev_document_get_fc_mutex (void) { @@ -111,6 +90,29 @@ ev_document_fc_mutex_unlock (void) g_mutex_unlock (ev_document_get_fc_mutex ()); } +gboolean +ev_document_fc_mutex_trylock (void) +{ + return g_mutex_trylock (ev_document_get_fc_mutex ()); +} + +/** + * ev_document_load: + * @document: a #EvDocument + * @uri: the document's URI + * @error: a #GError location to store an error, or %NULL + * + * Loads @document from @uri. + * + * On failure, %FALSE is returned and @error is filled in. + * If the document is encrypted, EV_DEFINE_ERROR_ENCRYPTED is returned. + * If the backend cannot load the specific document, EV_DOCUMENT_ERROR_INVALID + * is returned. Other errors are possible too, depending on the backend + * used to load the document and the URI, e.g. #GIOError, #GFileError, and + * #GConvertError. + * + * Returns: %TRUE on success, or %FALSE on failure. + */ gboolean ev_document_load (EvDocument *document, const char *uri, @@ -118,12 +120,37 @@ ev_document_load (EvDocument *document, { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); gboolean retval; - LOG ("ev_document_load"); - retval = iface->load (document, uri, error); + GError *err = NULL; + + retval = iface->load (document, uri, &err); + if (!retval) { + if (err) { + g_propagate_error (error, err); + } else { + g_warning ("%s::EvDocumentIface::load returned FALSE but did not fill in @error; fix the backend!\n", + G_OBJECT_TYPE_NAME (document)); + + /* So upper layers don't crash */ + g_set_error_literal (error, + EV_DOCUMENT_ERROR, + EV_DOCUMENT_ERROR_INVALID, + "Internal error in backend"); + } + } return retval; } +/** + * ev_document_save: + * @document: + * @uri: the target URI + * @error: a #GError location to store an error, or %NULL + * + * Saves @document to @uri. + * + * Returns: %TRUE on success, or %FALSE on error with @error filled in + */ gboolean ev_document_save (EvDocument *document, const char *uri, @@ -132,7 +159,6 @@ ev_document_save (EvDocument *document, EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); gboolean retval; - LOG ("ev_document_save"); retval = iface->save (document, uri, error); return retval; @@ -144,31 +170,43 @@ ev_document_get_n_pages (EvDocument *document) EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); gint retval; - LOG ("ev_document_get_n_pages"); retval = iface->get_n_pages (document); return retval; } +EvPage * +ev_document_get_page (EvDocument *document, + gint index) +{ + EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); + EvPage *retval; + + if (iface->get_page) + retval = iface->get_page (document, index); + else + retval = ev_page_new (index); + + return retval; +} + void -ev_document_get_page_size (EvDocument *document, - int page, - double *width, - double *height) +ev_document_get_page_size (EvDocument *document, + EvPage *page, + double *width, + double *height) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - LOG ("ev_document_get_page_size"); iface->get_page_size (document, page, width, height); } char * -ev_document_get_page_label(EvDocument *document, - int page) +ev_document_get_page_label (EvDocument *document, + EvPage *page) { EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); - LOG ("ev_document_get_page_label"); if (iface->get_page_label == NULL) return NULL; @@ -200,7 +238,6 @@ ev_document_get_attachments (EvDocument *document) EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); GList *retval; - LOG ("ev_document_get_attachments"); if (iface->get_attachments == NULL) return NULL; retval = iface->get_attachments (document); @@ -215,7 +252,6 @@ ev_document_render (EvDocument *document, EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document); cairo_surface_t *retval; - LOG ("ev_document_render_pixbuf"); g_assert (iface->render); retval = iface->render (document, rc); @@ -223,6 +259,39 @@ ev_document_render (EvDocument *document, return retval; } +/* EvDocumentInfo */ +EV_DEFINE_BOXED_TYPE (EvDocumentInfo, ev_document_info, ev_document_info_copy, ev_document_info_free) + +EvDocumentInfo * +ev_document_info_copy (EvDocumentInfo *info) +{ + EvDocumentInfo *copy; + + g_return_val_if_fail (info != NULL, NULL); + + copy = g_new0 (EvDocumentInfo, 1); + copy->title = g_strdup (info->title); + copy->format = g_strdup (info->format); + copy->author = g_strdup (info->author); + copy->subject = g_strdup (info->subject); + copy->keywords = g_strdup (info->keywords); + copy->security = g_strdup (info->security); + copy->creator = g_strdup (info->creator); + copy->producer = g_strdup (info->producer); + copy->linearized = g_strdup (info->linearized); + + copy->creation_date = info->creation_date; + copy->modified_date = info->modified_date; + copy->layout = info->layout; + copy->mode = info->mode; + copy->ui_hints = info->ui_hints; + copy->permissions = info->permissions; + copy->n_pages = info->n_pages; + copy->fields_mask = info->fields_mask; + + return copy; +} + void ev_document_info_free (EvDocumentInfo *info) { @@ -239,10 +308,36 @@ ev_document_info_free (EvDocumentInfo *info) g_free (info->linearized); g_free (info->security); - g_free (info); } +/* EvRectangle */ +EV_DEFINE_BOXED_TYPE (EvRectangle, ev_rectangle, ev_rectangle_copy, ev_rectangle_free) + +EvRectangle * +ev_rectangle_new (void) +{ + return g_new0 (EvRectangle, 1); +} + +EvRectangle * +ev_rectangle_copy (EvRectangle *rectangle) +{ + EvRectangle *new_rectangle; + + g_return_val_if_fail (rectangle != NULL, NULL); + + new_rectangle = g_new (EvRectangle, 1); + *new_rectangle = *rectangle; + + return new_rectangle; +} + +void +ev_rectangle_free (EvRectangle *rectangle) +{ + g_free (rectangle); +} /* Compares two rects. returns 0 if they're equal */ #define EPSILON 0.0000001 @@ -261,6 +356,3 @@ ev_rect_cmp (EvRectangle *a, (ABS (a->x2 - b->x2) < EPSILON) && (ABS (a->y2 - b->y2) < EPSILON)); } - - -