[evince: 2/13] libdocument: Move backends management into ev-document-factory.c



commit 4cb8ecf9b81e8d101c6e495cb825d1056fae1500
Author: Christian Persch <chpe gnome org>
Date:   Wed May 9 17:48:54 2012 +0200

    libdocument: Move backends management into ev-document-factory.c
    
    Remove EvTypeInfo, since it's redundant with EvBackendInfo. So just
    make EvBackendInfo usable from ev-document-factory (internal symbols,
    not exported from libevdocument).
    
    Remove ev_backends_manager_get_document_module_name, and change
    ev-window-title to use the document class type name instead.
    That code should move to the backend, either directly into the document
    classes' get_title method, or a new get_display_title method.

 .../libdocument/libevdocument-sections.txt         |    4 +-
 libdocument/Makefile.am                            |    3 +-
 libdocument/ev-backend-info.c                      |  147 +++++++++
 libdocument/ev-backend-info.h                      |   54 +++
 libdocument/ev-backends-manager.c                  |  333 -------------------
 libdocument/ev-backends-manager.h                  |    7 +-
 libdocument/ev-document-factory.c                  |  345 ++++++++++++++-----
 libdocument/ev-document-factory.h                  |    3 +
 libdocument/ev-init.c                              |    6 +-
 shell/ev-window-title.c                            |    7 +-
 10 files changed, 473 insertions(+), 436 deletions(-)
---
diff --git a/help/reference/libdocument/libevdocument-sections.txt b/help/reference/libdocument/libevdocument-sections.txt
index 8a769d8..ad72e04 100644
--- a/help/reference/libdocument/libevdocument-sections.txt
+++ b/help/reference/libdocument/libevdocument-sections.txt
@@ -681,9 +681,11 @@ ev_mapping_list_free
 <FILE>ev-backends-manager</FILE>
 EvTypeInfo
 ev_backends_manager_get_document
+ev_backends_manager_get_all_types_info
+
+<SUBSECTION Deprecated>
 ev_backends_manager_get_document_module_name
 ev_backends_manager_get_document_type_info
-ev_backends_manager_get_all_types_info
 </SECTION>
 
 <SECTION>
diff --git a/libdocument/Makefile.am b/libdocument/Makefile.am
index eaa1db6..dcf71b0 100644
--- a/libdocument/Makefile.am
+++ b/libdocument/Makefile.am
@@ -2,6 +2,7 @@ lib_LTLIBRARIES = libevdocument3.la
 
 NOINST_H_FILES =				\
 	ev-debug.h				\
+	ev-backend-info.h			\
 	ev-module.h
 
 INST_H_SRC_FILES = 				\
@@ -52,7 +53,7 @@ libevdocument3_la_SOURCES=			\
 	ev-annotation.c				\
 	ev-async-renderer.c			\
 	ev-attachment.c				\
-	ev-backends-manager.c			\
+	ev-backend-info.c			\
 	ev-layer.c				\
 	ev-link.c				\
 	ev-link-action.c			\
diff --git a/libdocument/ev-backend-info.c b/libdocument/ev-backend-info.c
new file mode 100644
index 0000000..72549d3
--- /dev/null
+++ b/libdocument/ev-backend-info.c
@@ -0,0 +1,147 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2007 Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <config.h>
+
+#include "ev-backend-info.h"
+
+#define EV_BACKENDS_GROUP     "Evince Backend"
+#define EV_BACKENDS_EXTENSION ".evince-backend"
+
+/*
+ * _ev_backend_info_free:
+ * @info:
+ *
+ * Frees @info
+ */
+void
+_ev_backend_info_free (EvBackendInfo *info)
+{
+        if (info == NULL)
+                return;
+
+	g_free (info->module_name);
+	g_free (info->type_desc);
+	g_strfreev (info->mime_types);
+        /* Leak info->module */
+	g_slice_free (EvBackendInfo, info);
+}
+
+/**
+ * _ev_backend_info_new_from_file:
+ * @path: path to the backends file
+ * @error: a location to store a #GError, or %NULL
+ *
+ * Loads backend information from @path.
+ *
+ * Returns: a new #EvBackendInfo, or %NULL on error with @error filled in
+ */
+EvBackendInfo *
+_ev_backend_info_new_from_file (const char *file,
+                                GError **error)
+{
+	EvBackendInfo *info = NULL;
+	GKeyFile      *backend_file = NULL;
+
+	backend_file = g_key_file_new ();
+	if (!g_key_file_load_from_file (backend_file, file, G_KEY_FILE_NONE, error))
+                goto err;
+
+	info = g_slice_new0 (EvBackendInfo);
+
+	info->module_name = g_key_file_get_string (backend_file, EV_BACKENDS_GROUP,
+						   "Module", error);
+	if (!info->module_name)
+                goto err;
+
+	info->resident = g_key_file_get_boolean (backend_file, EV_BACKENDS_GROUP,
+						 "Resident", NULL);
+
+	info->type_desc = g_key_file_get_locale_string (backend_file, EV_BACKENDS_GROUP,
+							"TypeDescription", NULL, error);
+	if (!info->type_desc)
+                goto err;
+
+	info->mime_types = g_key_file_get_string_list (backend_file, EV_BACKENDS_GROUP,
+						       "MimeType", NULL, error);
+	if (!info->mime_types)
+                goto err;
+
+	g_key_file_free (backend_file);
+
+	return info;
+
+    err:
+        g_key_file_free (backend_file);
+        _ev_backend_info_free (info);
+        return NULL;
+}
+
+/*
+ * _ev_backend_info_load_from_dir:
+ * @path: a directory name
+ *
+ * Load all backend infos from @path.
+ *
+ * Returns: a newly allocated #GList containing newly allocated
+ *   #EvBackendInfo objects
+ */
+GList
+*_ev_backend_info_load_from_dir (const char *path)
+{
+        GList       *list = NULL;
+        GDir        *dir;
+        const gchar *dirent;
+        GError      *error = NULL;
+
+        dir = g_dir_open (path, 0, &error);
+        if (!dir) {
+                g_warning ("%s", error->message);
+                g_error_free (error);
+
+                return FALSE;
+        }
+
+        while ((dirent = g_dir_read_name (dir))) {
+                EvBackendInfo *info;
+                gchar         *file;
+                GError        *error = NULL;
+
+                if (!g_str_has_suffix (dirent, EV_BACKENDS_EXTENSION))
+                        continue;
+
+                file = g_build_filename (path, dirent, NULL);
+                info = _ev_backend_info_new_from_file (file, &error);
+                if (error != NULL) {
+                        g_warning ("Failed to load backend info from '%s': %s\n",
+                                   file, error->message);
+                        g_error_free (error);
+                }
+                g_free (file);
+
+                if (info == NULL)
+                        continue;
+
+                list = g_list_prepend (list, info);
+        }
+
+        g_dir_close (dir);
+
+        return list;
+}
diff --git a/libdocument/ev-backend-info.h b/libdocument/ev-backend-info.h
new file mode 100644
index 0000000..14c0895
--- /dev/null
+++ b/libdocument/ev-backend-info.h
@@ -0,0 +1,54 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2007 Carlos Garcia Campos <carlosgc gnome org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#if !defined (EVINCE_COMPILATION)
+#error "This is a private header."
+#endif
+
+#ifndef EV_BACKEND_INFO
+#define EV_BACKEND_INFO
+
+#include <glib.h>
+
+#include "ev-module.h"
+
+G_BEGIN_DECLS
+
+typedef struct _EvBackendInfo EvBackendInfo;
+
+struct _EvBackendInfo {
+        /* These two fields must be first for API/ABI compat with EvTypeInfo */
+        gchar       *type_desc;
+        gchar      **mime_types;
+
+	gchar       *module_name;
+	GTypeModule *module;
+	gboolean     resident;
+};
+
+void            _ev_backend_info_free           (EvBackendInfo *info);
+
+EvBackendInfo  *_ev_backend_info_new_from_file  (const char *file,
+                                                 GError **error);
+
+GList          *_ev_backend_info_load_from_dir  (const char *path);
+
+G_END_DECLS
+
+#endif /* !EV_BACKEND_INFO */
diff --git a/libdocument/ev-backends-manager.h b/libdocument/ev-backends-manager.h
index f939076..ad818d1 100644
--- a/libdocument/ev-backends-manager.h
+++ b/libdocument/ev-backends-manager.h
@@ -35,12 +35,13 @@ typedef struct _EvTypeInfo {
 	const gchar **mime_types;
 } EvTypeInfo;
 
-gboolean    _ev_backends_manager_init                     (void);
-void        _ev_backends_manager_shutdown                 (void);
-
 EvDocument  *ev_backends_manager_get_document             (const gchar *mime_type);
+
+G_GNUC_DEPRECATED
 const gchar *ev_backends_manager_get_document_module_name (EvDocument  *document);
+G_GNUC_DEPRECATED
 EvTypeInfo  *ev_backends_manager_get_document_type_info   (EvDocument  *document);
+
 GList       *ev_backends_manager_get_all_types_info       (void);
 
 G_END_DECLS
diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c
index 7aacb97..c8a9df0 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -29,10 +29,95 @@
 #include <glib/gi18n-lib.h>
 #include <gtk/gtk.h>
 
-#include "ev-backends-manager.h"
+#include "ev-backend-info.h"
 #include "ev-document-factory.h"
 #include "ev-file-helpers.h"
 
+#include "ev-backends-manager.h"
+
+/* Backends manager */
+
+static GList *ev_backends_list = NULL;
+static gchar *ev_backends_dir = NULL;
+
+static EvDocument* ev_document_factory_new_document_for_mime_type (const char *mime_type);
+
+static EvBackendInfo *
+get_backend_info_for_mime_type (const gchar *mime_type)
+{
+        GList *l;
+
+        for (l = ev_backends_list; l; l = l->next) {
+                EvBackendInfo *info = (EvBackendInfo *) l->data;
+                char **mime_types = info->mime_types;
+                guint i;
+
+                for (i = 0; mime_types[i] != NULL; ++i) {
+                        if (g_ascii_strcasecmp (mime_type, mime_types[i]) == 0)
+                                return info;
+                }
+        }
+
+        return NULL;
+}
+
+static EvBackendInfo *
+get_backend_info_for_document (EvDocument *document)
+{
+        GList *l;
+
+        for (l = ev_backends_list; l; l = l->next) {
+                EvBackendInfo *info = (EvBackendInfo *) l->data;
+                GType type;
+
+                if (!info->module)
+                        continue;
+
+                type = ev_module_get_object_type (EV_MODULE (info->module));
+
+                if (G_TYPE_CHECK_INSTANCE_TYPE (document, type))
+                        return info;
+        }
+
+        return NULL;
+}
+
+static EvDocument *
+ev_document_factory_new_document_for_mime_type (const gchar *mime_type)
+{
+        EvDocument    *document;
+        EvBackendInfo *info;
+
+        info = get_backend_info_for_mime_type (mime_type);
+        if (!info)
+                return NULL;
+
+        if (!info->module) {
+                gchar *path;
+
+                path = g_module_build_path (ev_backends_dir, info->module_name);
+                info->module = G_TYPE_MODULE (ev_module_new (path, info->resident));
+                g_free (path);
+        }
+
+        if (!g_type_module_use (info->module)) {
+                const char *err;
+
+                err = g_module_error ();
+                g_warning ("Cannot load backend '%s': %s",
+                          info->module_name, err ? err : "unknown error");
+                g_object_unref (G_OBJECT (info->module));
+                info->module = NULL;
+
+                return NULL;
+        }
+
+        document = EV_DOCUMENT (ev_module_new_object (EV_MODULE (info->module)));
+        g_type_module_unuse (info->module);
+
+        return document;
+}
+
 static EvCompressionType
 get_compression_from_mime_type (const gchar *mime_type)
 {
@@ -56,7 +141,7 @@ get_compression_from_mime_type (const gchar *mime_type)
 
 
 /*
- * get_document_from_uri:
+ * new_document_for_uri:
  * @uri: the document URI
  * @fast: whether to use fast MIME type detection
  * @compression: a location to store the document's compression type
@@ -70,10 +155,10 @@ get_compression_from_mime_type (const gchar *mime_type)
  * Returns: a new #EvDocument instance, or %NULL on error with @error filled in
  */
 static EvDocument *
-get_document_from_uri (const char        *uri,
-		       gboolean           fast,
-		       EvCompressionType *compression,
-		       GError           **error)
+new_document_for_uri (const char        *uri,
+                      gboolean           fast,
+                      EvCompressionType *compression,
+                      GError           **error)
 {
 	EvDocument *document = NULL;
 	gchar      *mime_type = NULL;
@@ -98,7 +183,7 @@ get_document_from_uri (const char        *uri,
 		return NULL;
 	}
 
-	document = ev_backends_manager_get_document (mime_type);
+	document = ev_document_factory_new_document_for_mime_type (mime_type);
 	if (document == NULL) {
 		gchar *content_type, *mime_desc = NULL;
 
@@ -135,11 +220,69 @@ free_uncompressed_uri (gchar *uri_unc)
 	g_free (uri_unc);
 }
 
-/* Try to get and load the document from a file, dealing with errors 
- * differently depending on whether we are using slow or fast mime detection.
+/*
+ * _ev_document_factory_init:
+ *
+ * Initializes the evince document factory.
+ *
+ * Returns: %TRUE if there were any backends found; %FALSE otherwise
  */
-static EvDocument *
-ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
+gboolean
+_ev_document_factory_init (void)
+{
+	if (ev_backends_list)
+		return TRUE;
+
+#ifdef G_OS_WIN32
+{
+        gchar *dir;
+
+        dir = g_win32_get_package_installation_directory_of_module (NULL);
+        ev_backends_dir = g_build_filename (dir, "lib", "evince",
+                                        EV_BACKENDSBINARYVERSION,
+                                        "backends", NULL);
+        g_free (dir);
+}
+#else
+        ev_backends_dir = g_strdup (EV_BACKENDSDIR);
+#endif
+
+        ev_backends_list = _ev_backend_info_load_from_dir (ev_backends_dir);
+
+        return ev_backends_list != NULL;
+}
+
+/*
+ * _ev_document_factory_shutdown:
+ *
+ * Shuts the evince document factory down.
+ */
+void
+_ev_document_factory_shutdown (void)
+{
+	g_list_foreach (ev_backends_list, (GFunc) _ev_backend_info_free, NULL);
+	g_list_free (ev_backends_list);
+	ev_backends_list = NULL;
+
+	g_free (ev_backends_dir);
+        ev_backends_dir = NULL;
+}
+
+/**
+ * ev_document_factory_get_document:
+ * @uri: an URI
+ * @error: a #GError location to store an error, or %NULL
+ *
+ * Creates a #EvDocument for the document at @uri; or, if no backend handling
+ * the document's type is found, or an error occurred on opening the document,
+ * returns %NULL and fills in @error.
+ * If the document is encrypted, it is returned but also @error is set to
+ * %EV_DOCUMENT_ERROR_ENCRYPTED.
+ *
+ * Returns: (transfer full): a new #EvDocument, or %NULL
+ */
+EvDocument *
+ev_document_factory_get_document (const char *uri, GError **error)
 {
 	EvDocument *document;
 	int result;
@@ -147,20 +290,50 @@ ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
 	gchar *uri_unc = NULL;
 	GError *err = NULL;
 
-	document = get_document_from_uri (uri, fast, &compression, &err);
+	g_return_val_if_fail (uri != NULL, NULL);
+
+	document = new_document_for_uri (uri, TRUE, &compression, &err);
 	g_assert (document != NULL || err != NULL);
 
-	if (document == NULL) {
-		if (fast) {
-			/* Try again with slow mime detection */
-			g_clear_error (&err);
-		} else {
-			/* This should have worked, and is usually the second try,
-			 * so set an error for the caller. */
-			g_assert (err != NULL);
+	if (document != NULL) {
+		uri_unc = ev_file_uncompress (uri, compression, &err);
+		if (uri_unc) {
+			g_object_set_data_full (G_OBJECT (document),
+						"uri-uncompressed",
+						uri_unc,
+						(GDestroyNotify) free_uncompressed_uri);
+		} else if (err != NULL) {
+			/* Error uncompressing file */
+			g_object_unref (document);
 			g_propagate_error (error, err);
+			return NULL;
 		}
-		
+
+		result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
+
+		if (result == FALSE || err) {
+			if (err &&
+			    g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
+				g_propagate_error (error, err);
+				return document;
+			    }
+			/* else fall through to slow mime code section below */
+		} else {
+			return document;
+		}
+
+		g_object_unref (document);
+		document = NULL;
+	}
+
+	/* Try again with slow mime detection */
+	g_clear_error (&err);
+	uri_unc = NULL;
+
+	document = new_document_for_uri (uri, FALSE, &compression, &err);
+	if (document == NULL) {
+		g_assert (err != NULL);
+		g_propagate_error (error, err);
 		return NULL;
 	}
 
@@ -172,79 +345,48 @@ ev_document_factory_load_uri (const char *uri, gboolean fast, GError **error)
 					(GDestroyNotify) free_uncompressed_uri);
 	} else if (err != NULL) {
 		/* Error uncompressing file */
-		g_object_unref (document);
 		g_propagate_error (error, err);
 
+		g_object_unref (document);
 		return NULL;
 	}
 
 	result = ev_document_load (document, uri_unc ? uri_unc : uri, &err);
-	if (result)
-		return document;
-		
-	if (err) {
-		if (g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
+	if (result == FALSE) {
+		if (err == NULL) {
+			/* FIXME: this really should not happen; the backend should
+			 * always return a meaningful error.
+			 */
+			g_set_error_literal (&err,
+                                             EV_DOCUMENT_ERROR,
+                                             EV_DOCUMENT_ERROR_INVALID,
+                                             _("Unknown MIME Type"));
+		} else if (g_error_matches (err, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_ENCRYPTED)) {
 			g_propagate_error (error, err);
 			return document;
-
-			/* else fall through to slow mime code detection. */
 		}
-	} else if (!fast) {
-		/* FIXME: this really should not happen; the backend should
-		 * always return a meaningful error.
-		 */
-		g_set_error_literal (&err,
-			EV_DOCUMENT_ERROR,
-			EV_DOCUMENT_ERROR_INVALID,
-			_("Unknown MIME Type"));
-		g_propagate_error (error, err);
-
-		/* else fall through to slow mime code detection. */
-	}
-
-	g_object_unref (document);
-
-	return NULL;
-}
-
-/**
- * ev_document_factory_get_document:
- * @uri: an URI
- * @error: a #GError location to store an error, or %NULL
- *
- * Creates a #EvDocument for the document at @uri; or, if no backend handling
- * the document's type is found, or an error occurred on opening the document,
- * returns %NULL and fills in @error.
- * If the document is encrypted, it is returned but also @error is set to
- * %EV_DOCUMENT_ERROR_ENCRYPTED.
- *
- * Returns: (transfer full): a new #EvDocument, or %NULL.
- */
-EvDocument *
-ev_document_factory_get_document (const char *uri, GError **error)
-{
-	EvDocument *document;
 
-	g_return_val_if_fail (uri != NULL, NULL);
+		g_object_unref (document);
+		document = NULL;
 
-	document = ev_document_factory_load_uri (uri, TRUE, error);
-	if (document)
-		return document;
+		g_propagate_error (error, err);
+	}
 
-	/* Try again with slow mime detection */
-	g_clear_error (error); /* Though this should always be NULL here. */
-	document = ev_document_factory_load_uri (uri, FALSE, error);
 	return document;
 }
 
 static void
-file_filter_add_mime_types (EvTypeInfo *info, GtkFileFilter *filter)
+file_filter_add_mime_types (EvBackendInfo *info, GtkFileFilter *filter)
 {
-	const gchar *mime_type;
-	gint         i = 0;
+        char **mime_types;
+	guint i;
+
+        mime_types = info->mime_types;
+        if (mime_types == NULL)
+                return;
 
-	while ((mime_type = info->mime_types[i++]))
-		gtk_file_filter_add_mime_type (filter, mime_type);
+        for (i = 0; mime_types[i] != NULL; ++i)
+                gtk_file_filter_add_mime_type (filter, mime_types[i]);
 }
 
 /**
@@ -264,7 +406,6 @@ file_filter_add_mime_types (EvTypeInfo *info, GtkFileFilter *filter)
 void
 ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
 {
-	GList         *all_types;
 	GtkFileFilter *filter;
 	GtkFileFilter *default_filter;
 	GtkFileFilter *document_filter;
@@ -272,40 +413,34 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
         g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
         g_return_if_fail (document == NULL || EV_IS_DOCUMENT (document));
 
-	all_types = ev_backends_manager_get_all_types_info ();
-	
 	default_filter = document_filter = filter = gtk_file_filter_new ();
 	gtk_file_filter_set_name (filter, _("All Documents"));
-	g_list_foreach (all_types, (GFunc)file_filter_add_mime_types, filter);
+	g_list_foreach (ev_backends_list, (GFunc)file_filter_add_mime_types, filter);
 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
 
 	if (document) {
-		EvTypeInfo *info;
+		EvBackendInfo *info;
 
-		info = ev_backends_manager_get_document_type_info (document);
+		info = get_backend_info_for_document (document);
+                g_assert (info != NULL);
 		default_filter = filter = gtk_file_filter_new ();
-		gtk_file_filter_set_name (filter, info->desc);
+		gtk_file_filter_set_name (filter, info->type_desc);
 		file_filter_add_mime_types (info, filter);
 		g_free (info);
 		gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
 	} else {
 		GList *l;
 
-		for (l = all_types; l; l = g_list_next (l)){
-			EvTypeInfo *info;
-
-			info = (EvTypeInfo *)l->data;
+		for (l = ev_backends_list; l; l = l->next) {
+                        EvBackendInfo *info = (EvBackendInfo *) l->data;
 
 			default_filter = filter = gtk_file_filter_new ();
-			gtk_file_filter_set_name (filter, info->desc);
+			gtk_file_filter_set_name (filter, info->type_desc);
 			file_filter_add_mime_types (info, filter);
 			gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
 		}
 	}
 
-	g_list_foreach (all_types, (GFunc)g_free, NULL);
-	g_list_free (all_types);
-
 	filter = gtk_file_filter_new ();
 	gtk_file_filter_set_name (filter, _("All Files"));
 	gtk_file_filter_add_pattern (filter, "*");
@@ -314,3 +449,31 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
 	gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (chooser),
 				     document == NULL ? document_filter : default_filter);
 }
+
+/* Deprecated API/ABI compatibility wrappers */
+
+EvDocument  *ev_backends_manager_get_document (const gchar *mime_type)
+{
+        return ev_document_factory_new_document_for_mime_type (mime_type);
+}
+
+const gchar *
+ev_backends_manager_get_document_module_name (EvDocument  *document)
+{
+        EvBackendInfo *info = get_backend_info_for_document (document);
+        if (info == NULL)
+                return NULL;
+
+        return info->module_name;
+}
+
+EvTypeInfo *ev_backends_manager_get_document_type_info (EvDocument  *document)
+{
+        return (EvTypeInfo *) get_backend_info_for_document (document);
+}
+
+GList *
+ev_backends_manager_get_all_types_info       (void)
+{
+        return g_list_copy (ev_backends_list);
+}
diff --git a/libdocument/ev-document-factory.h b/libdocument/ev-document-factory.h
index 501eb2f..b06b11d 100644
--- a/libdocument/ev-document-factory.h
+++ b/libdocument/ev-document-factory.h
@@ -31,6 +31,9 @@
 
 G_BEGIN_DECLS
 
+gboolean   _ev_document_factory_init         (void);
+void       _ev_document_factory_shutdown     (void);
+
 EvDocument* ev_document_factory_get_document (const char *uri, GError **error);
 void 	    ev_document_factory_add_filters  (GtkWidget *chooser, EvDocument *document);
 
diff --git a/libdocument/ev-init.c b/libdocument/ev-init.c
index 71c6784..ac1901c 100644
--- a/libdocument/ev-init.c
+++ b/libdocument/ev-init.c
@@ -26,7 +26,7 @@
 #endif
 
 #include "ev-init.h"
-#include "ev-backends-manager.h"
+#include "ev-document-factory.h"
 #include "ev-debug.h"
 #include "ev-file-helpers.h"
 
@@ -116,7 +116,7 @@ ev_init (void)
 
         _ev_debug_init ();
         _ev_file_helpers_init ();
-        have_backends = _ev_backends_manager_init ();
+        have_backends = _ev_document_factory_init ();
 
         return have_backends;
 }
@@ -139,7 +139,7 @@ ev_shutdown (void)
 		g_free(locale_dir);
 #endif
 
-        _ev_backends_manager_shutdown ();
+        _ev_document_factory_shutdown ();
         _ev_file_helpers_shutdown ();
         _ev_debug_shutdown ();
 }
diff --git a/shell/ev-window-title.c b/shell/ev-window-title.c
index 94dd333..0bfe053 100644
--- a/shell/ev-window-title.c
+++ b/shell/ev-window-title.c
@@ -19,7 +19,6 @@
 
 #include <config.h>
 #include "ev-window-title.h"
-#include "ev-backends-manager.h"
 #include "ev-utils.h"
 
 #include <string.h>
@@ -27,8 +26,8 @@
 #include <glib/gi18n.h>
 
 /* Known backends (for bad extensions fix) */
-#define EV_BACKEND_PS  "psdocument"
-#define EV_BACKEND_PDF "pdfdocument"
+#define EV_BACKEND_PS  "PSDocument"
+#define EV_BACKEND_PDF "PdfDocument"
 
 typedef struct
 {
@@ -89,7 +88,7 @@ ev_window_title_sanitize_title (EvWindowTitle *window_title, char **title) {
 	const gchar *backend;
 	int i;
 
-	backend = ev_backends_manager_get_document_module_name (window_title->document);
+	backend = G_OBJECT_TYPE_NAME (window_title->document);
 
 	for (i = 0; i < G_N_ELEMENTS (bad_extensions); i++) {
 		if (g_ascii_strcasecmp (bad_extensions[i].backend, backend) == 0 && 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]