[evince/wip/bug654832: 13/18] [libdocument] Add GError to ..._new_document_for_mime_type
- From: Christian Persch <chpe src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evince/wip/bug654832: 13/18] [libdocument] Add GError to ..._new_document_for_mime_type
- Date: Wed, 9 May 2012 17:53:09 +0000 (UTC)
commit 1bf86d97a7d13ea2b69eb969e8b7edd92193649f
Author: Christian Persch <chpe gnome org>
Date: Sun Feb 14 15:37:22 2010 +0100
[libdocument] Add GError to ..._new_document_for_mime_type
libdocument/ev-document-factory.c | 70 +++++++++++++++---------------------
libdocument/ev-document-factory.h | 3 +-
properties/ev-properties-main.c | 2 +-
3 files changed, 32 insertions(+), 43 deletions(-)
---
diff --git a/libdocument/ev-document-factory.c b/libdocument/ev-document-factory.c
index 800efbd..2e08929 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -81,14 +81,32 @@ get_backend_info_for_document (EvDocument *document)
}
EvDocument *
-ev_document_factory_new_document_for_mime_type (const gchar *mime_type)
+ev_document_factory_new_document_for_mime_type (const gchar *mime_type,
+ GError **error)
{
EvDocument *document;
EvBackendInfo *info;
+ g_return_val_if_fail (mime_type != NULL, NULL);
+
info = get_backend_info_for_mime_type (mime_type);
- if (!info)
+ if (info == NULL) {
+ char *content_type, *mime_desc = NULL;
+
+ content_type = g_content_type_from_mime_type (mime_type);
+ if (content_type)
+ mime_desc = g_content_type_get_description (content_type);
+
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ EV_DOCUMENT_ERROR_INVALID,
+ _("File type %s (%s) is not supported"),
+ mime_desc ? mime_desc : "(unknown)", mime_type);
+ g_free (mime_desc);
+ g_free (content_type);
+
return NULL;
+ }
if (!info->module) {
gchar *path;
@@ -102,8 +120,9 @@ ev_document_factory_new_document_for_mime_type (const gchar *mime_type)
const char *err;
err = g_module_error ();
- g_warning ("Cannot load backend '%s': %s",
- info->module_name, err ? err : "unknown error");
+ g_set_error (error, EV_DOCUMENT_ERROR, EV_DOCUMENT_ERROR_INVALID,
+ "Failed to load backend for '%s': %s",
+ mime_type, err ? err : "unknown error");
g_object_unref (G_OBJECT (info->module));
info->module = NULL;
@@ -160,47 +179,16 @@ new_document_for_uri (const char *uri,
{
EvDocument *document = NULL;
gchar *mime_type = NULL;
- GError *err = NULL;
*compression = EV_COMPRESSION_NONE;
- mime_type = ev_file_get_mime_type (uri, fast, &err);
-
- if (mime_type == NULL) {
- g_free (mime_type);
-
- if (err == NULL) {
- g_set_error_literal (error,
- EV_DOCUMENT_ERROR,
- EV_DOCUMENT_ERROR_INVALID,
- _("Unknown MIME Type"));
- } else {
- g_propagate_error (error, err);
- }
-
+ mime_type = ev_file_get_mime_type (uri, fast, error);
+ if (mime_type == NULL)
return NULL;
- }
-
- document = ev_document_factory_new_document_for_mime_type (mime_type);
-
- if (document == NULL) {
- gchar *content_type, *mime_desc = NULL;
- content_type = g_content_type_from_mime_type (mime_type);
- if (content_type)
- mime_desc = g_content_type_get_description (content_type);
-
- g_set_error (error,
- EV_DOCUMENT_ERROR,
- EV_DOCUMENT_ERROR_INVALID,
- _("File type %s (%s) is not supported"),
- mime_desc ? mime_desc : "-", mime_type);
- g_free (mime_desc);
- g_free (content_type);
- g_free (mime_type);
-
- return NULL;
- }
+ document = ev_document_factory_new_document_for_mime_type (mime_type, error);
+ if (document == NULL)
+ return NULL;
*compression = get_compression_from_mime_type (mime_type);
@@ -453,7 +441,7 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
EvDocument *ev_backends_manager_get_document (const gchar *mime_type)
{
- return ev_document_factory_new_document_for_mime_type (mime_type);
+ return ev_document_factory_new_document_for_mime_type (mime_type, NULL);
}
const gchar *
diff --git a/libdocument/ev-document-factory.h b/libdocument/ev-document-factory.h
index b4e088b..2640301 100644
--- a/libdocument/ev-document-factory.h
+++ b/libdocument/ev-document-factory.h
@@ -34,7 +34,8 @@ G_BEGIN_DECLS
gboolean _ev_document_factory_init (void);
void _ev_document_factory_shutdown (void);
-EvDocument* ev_document_factory_new_document_for_mime_type (const char *mime_type);
+EvDocument* ev_document_factory_new_document_for_mime_type (const char *mime_type,
+ GError **error);
EvDocument* ev_document_factory_get_document (const char *uri, GError **error);
void ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document);
diff --git a/properties/ev-properties-main.c b/properties/ev-properties-main.c
index 7b7247b..76d6f80 100644
--- a/properties/ev-properties-main.c
+++ b/properties/ev-properties-main.c
@@ -103,7 +103,7 @@ ev_properties_get_pages (NautilusPropertyPageProvider *provider,
uri = nautilus_file_info_get_uri (file);
mime_type = nautilus_file_info_get_mime_type (file);
- document = ev_document_factory_new_document_for_mime_type (mime_type);
+ document = ev_document_factory_new_document_for_mime_type (mime_type, NULL);
if (!document)
goto end;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]