Ejemplo n.º 1
0
EvDocument *
ev_backends_manager_get_document (const gchar *mime_type)
{
	EvDocument    *document;
	EvBackendInfo *info;

	info = ev_backends_manager_get_backend_info (mime_type);
	if (!info)
		return NULL;

	if (!info->module) {
		gchar *path;
		
		path = g_module_build_path (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)) {
		g_warning ("Cannot load backend '%s' since file '%s' cannot be read.",
			   info->module_name,
			   ev_module_get_path (EV_MODULE (info->module)));
		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;
}
Ejemplo n.º 2
0
static EvBackendInfo *
get_document_backend_info (EvDocument *document)
{
	GList *l;

	for (l = ev_backends_list; l; l = g_list_next (l)) {
		EvBackendInfo *info;
		GType          type_id;

		info = (EvBackendInfo *)l->data;

		if (!info->module)
			continue;

		type_id = ev_module_get_object_type (EV_MODULE (info->module));

		if (G_TYPE_CHECK_INSTANCE_TYPE (document, type_id)) {
			return info;
		}
	}

	return NULL;
}
Ejemplo n.º 3
0
static EvDocument *
ev_document_factory_new_document_for_mime_type (const gchar *mime_type,
                                                GError **error)
{
        EvDocument    *document;
        EvBackendInfo *info;
        GTypeModule *module = NULL;

        g_return_val_if_fail (mime_type != NULL, NULL);

        info = get_backend_info_for_mime_type (mime_type);
        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 (ev_module_hash != NULL) {
                module = g_hash_table_lookup (ev_module_hash, info->module_name);
        }
        if (module == NULL) {
                gchar *path;

                path = g_module_build_path (ev_backends_dir, info->module_name);
                module = G_TYPE_MODULE (_ev_module_new (path, info->resident));
                g_free (path);

                if (ev_module_hash == NULL) {
                        ev_module_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                                g_free,
                                                                NULL /* leaked on purpose */);
                }
                g_hash_table_insert (ev_module_hash, g_strdup (info->module_name), module);
        }

        if (!g_type_module_use (module)) {
                const char *err;

                err = g_module_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");
                return NULL;
        }

        document = EV_DOCUMENT (_ev_module_new_object (EV_MODULE (module)));
        g_type_module_unuse (module);

        g_object_set_data_full (G_OBJECT (document), BACKEND_DATA_KEY,
                                _ev_backend_info_ref (info),
                                (GDestroyNotify) _ev_backend_info_unref);

        return document;
}