Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell/ev-document-types.c
diff options
context:
space:
mode:
authorNickolay V. Shmyrev <nshmyrev@src.gnome.org>2005-06-10 14:49:25 (GMT)
committer Nickolay V. Shmyrev <nshmyrev@src.gnome.org>2005-06-10 14:49:25 (GMT)
commit270571fe9d9ab085696c5b2af5a484dfc272b7a0 (patch)
treeeaf692d3cc9270c54228a9e473c948ee217b9c02 /shell/ev-document-types.c
parentf79d6e977948ded983460e2756fe6fc628719305 (diff)
Transfer remote documents to tmp directory to display them later
Diffstat (limited to 'shell/ev-document-types.c')
-rw-r--r--shell/ev-document-types.c114
1 files changed, 73 insertions, 41 deletions
diff --git a/shell/ev-document-types.c b/shell/ev-document-types.c
index 6ce546b..7133295 100644
--- a/shell/ev-document-types.c
+++ b/shell/ev-document-types.c
@@ -37,6 +37,7 @@
#endif
#include <string.h>
+#include <glib/gi18n.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
#include <libgnomevfs/gnome-vfs-ops.h>
@@ -111,32 +112,13 @@ mime_type_supported_by_gdk_pixbuf (const gchar *mime_type)
return retval;
}
-static char *
-get_slow_mime_type (const char *uri)
-{
- GnomeVFSFileInfo *info;
- char *mime_type;
- GnomeVFSResult result;
-
- info = gnome_vfs_file_info_new ();
- result = gnome_vfs_get_file_info (uri, info,
- GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
- GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE |
- GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
- if (info->mime_type == NULL || result != GNOME_VFS_OK) {
- mime_type = NULL;
- } else {
- mime_type = g_strdup (info->mime_type);
- }
- gnome_vfs_file_info_unref (info);
-
- return mime_type;
-}
static GType
-get_document_type_from_mime (const char *mime_type)
+ev_document_type_from_from_mime (const char *mime_type)
{
int i;
+
+ g_return_val_if_fail (mime_type, G_TYPE_INVALID);
for (i = 0; i < G_N_ELEMENTS (document_types); i++) {
if (strcmp (mime_type, document_types[i].mime_type) == 0) {
@@ -152,32 +134,82 @@ get_document_type_from_mime (const char *mime_type)
return G_TYPE_INVALID;
}
-GType
-ev_document_type_lookup (const char *uri, char **mime_type)
+/**
+ * ev_document_type_get_type:
+ * @uri: String with uri
+ * @slow: Do we need to check slow gnome-vfs mime type
+ * @mime_type: If we've found handled type, the mime_type string is returned here.
+ * @error: Information about error occured
+ *
+ * Return value: G_TYPE_INVALID on error, G_TYPE_NONE when we are not sure about
+ * mime type, and type of EvDocument implementation when we've found document.
+ **/
+static GType
+ev_document_type_get_type (const char *uri, gboolean slow, gchar **mime_type, GError **error)
{
- GType type = G_TYPE_INVALID;
- char *mime;
-
- g_return_val_if_fail (uri, G_TYPE_INVALID);
+ GnomeVFSFileInfo *info;
+ GnomeVFSResult result;
- mime = gnome_vfs_get_mime_type (uri);
- if (mime) {
- type = get_document_type_from_mime (mime);
+ GType type = G_TYPE_INVALID;
+
+ info = gnome_vfs_file_info_new ();
+ result = gnome_vfs_get_file_info (uri, info,
+ GNOME_VFS_FILE_INFO_GET_MIME_TYPE |
+ GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
+ (slow ? GNOME_VFS_FILE_INFO_FORCE_SLOW_MIME_TYPE : 0));
+ if (result != GNOME_VFS_OK) {
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ 0,
+ gnome_vfs_result_to_string (result));
+ gnome_vfs_file_info_unref (info);
+ return G_TYPE_INVALID;
+ }
+
+ if (info->mime_type == NULL) {
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ 0,
+ _("Unknown MIME Type"));
+ gnome_vfs_file_info_unref (info);
+ return slow ? G_TYPE_INVALID : G_TYPE_NONE;
}
-
+
+ type = ev_document_type_from_from_mime (info->mime_type);
+
if (type == G_TYPE_INVALID) {
- g_free (mime);
- mime = get_slow_mime_type (uri);
- if (mime) {
- type = get_document_type_from_mime (mime);
- }
+ g_set_error (error,
+ EV_DOCUMENT_ERROR,
+ 0,
+ _("Unhandled MIME type: '%s'"), info->mime_type);
+ gnome_vfs_file_info_unref (info);
+ return slow ? G_TYPE_INVALID : G_TYPE_NONE;
+ }
+
+ if (mime_type != NULL) {
+ *mime_type = g_strdup (info->mime_type);
}
+ gnome_vfs_file_info_unref (info);
+
+ return type;
+}
- if (mime_type) {
- *mime_type = mime;
- } else {
- g_free (mime);
+GType
+ev_document_type_lookup (const char *uri, gchar **mime_type, GError **error)
+{
+ GType type = G_TYPE_INVALID;
+
+ type = ev_document_type_get_type (uri, FALSE, mime_type, error);
+
+ if (type != G_TYPE_NONE)
+ return type;
+
+ if (error) {
+ g_error_free (*error);
+ *error = NULL;
}
+ type = ev_document_type_get_type (uri, TRUE, mime_type, error);
+
return type;
}