/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */
/*
+ * Copyright (C) 2009 Carlos Garcia Campos
* Copyright (C) 2004 Marco Pesenti Gritti
*
* This program is free software; you can redistribute it and/or modify
GMutex *ev_doc_mutex = NULL;
GMutex *ev_fc_mutex = NULL;
-EV_DEFINE_INTERFACE (EvDocument, ev_document, G_TYPE_OBJECT)
+G_DEFINE_ABSTRACT_TYPE (EvDocument, ev_document, G_TYPE_OBJECT)
GQuark
ev_document_error_quark (void)
return q;
}
+static EvPage *
+ev_document_impl_get_page (EvDocument *document,
+ gint index)
+{
+ return ev_page_new (index);
+}
+
+static EvDocumentInfo *
+ev_document_impl_get_info (EvDocument *document)
+{
+ return g_new0 (EvDocumentInfo, 1);
+}
+
static void
-ev_document_class_init (EvDocumentIface *klass)
+ev_document_init (EvDocument *document)
{
}
+static void
+ev_document_class_init (EvDocumentClass *klass)
+{
+ klass->get_page = ev_document_impl_get_page;
+ klass->get_info = ev_document_impl_get_info;
+}
+
GMutex *
ev_document_get_doc_mutex (void)
{
* @error: a #GError location to store an error, or %NULL
*
* Loads @document from @uri.
- * On failure, @error is filled in.
+ *
+ * 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.
*/
const char *uri,
GError **error)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
gboolean retval;
-
- retval = iface->load (document, uri, error);
+ GError *err = NULL;
+
+ retval = klass->load (document, uri, &err);
+ if (!retval) {
+ if (err) {
+ g_propagate_error (error, err);
+ } else {
+ g_warning ("%s::EvDocument::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,
GError **error)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
- gboolean retval;
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- retval = iface->save (document, uri, error);
-
- return retval;
+ return klass->save (document, uri, error);
}
int
ev_document_get_n_pages (EvDocument *document)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
- gint retval;
-
- retval = iface->get_n_pages (document);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- return retval;
+ return klass->get_n_pages (document);
}
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);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- return retval;
+ return klass->get_page (document, index);
}
void
double *width,
double *height)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- iface->get_page_size (document, page, width, height);
+ klass->get_page_size (document, page, width, height);
}
-char *
+gchar *
ev_document_get_page_label (EvDocument *document,
EvPage *page)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- if (iface->get_page_label == NULL)
- return NULL;
-
- return iface->get_page_label (document, page);
+ return klass->get_page_label ?
+ klass->get_page_label (document, page) : NULL;
}
EvDocumentInfo *
ev_document_get_info (EvDocument *document)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
-
- return iface->get_info (document);
-}
-
-gboolean
-ev_document_has_attachments (EvDocument *document)
-{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- if (iface->has_attachments == NULL)
- return FALSE;
-
- return iface->has_attachments (document);
-}
-
-GList *
-ev_document_get_attachments (EvDocument *document)
-{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
- GList *retval;
-
- if (iface->get_attachments == NULL)
- return NULL;
- retval = iface->get_attachments (document);
-
- return retval;
+ return klass->get_info (document);
}
cairo_surface_t *
ev_document_render (EvDocument *document,
EvRenderContext *rc)
{
- EvDocumentIface *iface = EV_DOCUMENT_GET_IFACE (document);
- cairo_surface_t *retval;
+ EvDocumentClass *klass = EV_DOCUMENT_GET_CLASS (document);
- g_assert (iface->render);
-
- retval = iface->render (document, rc);
-
- return retval;
+ return klass->render (document, rc);
}
/* EvDocumentInfo */
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