+
+/**
+ * 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)
+{
+ GnomeVFSFileInfo *info;
+ GnomeVFSResult result;
+
+ 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_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;
+}
+
+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;
+}