[evince/wip/bug654832: 5/18] [libdocument] Remove EvTypeInfo



commit b7d26ae239a5676eb30160c4bad511aee379562d
Author: Christian Persch <chpe gnome org>
Date:   Sat Feb 13 17:32:07 2010 +0100

    [libdocument] Remove EvTypeInfo
    
    It's redundant with EvBackendInfo. So just make EvBackendInfo usable
    from ev-document-factory (internal symbols, not exported from
    libevdocument).

 .../libdocument/libevdocument-sections.txt         |    3 -
 libdocument/ev-backends-manager.c                  |   60 +++++++------------
 libdocument/ev-backends-manager.h                  |   12 ++--
 libdocument/ev-document-factory.c                  |   31 +++++-----
 4 files changed, 43 insertions(+), 63 deletions(-)
---
diff --git a/help/reference/libdocument/libevdocument-sections.txt b/help/reference/libdocument/libevdocument-sections.txt
index 8a769d8..7ed303c 100644
--- a/help/reference/libdocument/libevdocument-sections.txt
+++ b/help/reference/libdocument/libevdocument-sections.txt
@@ -679,11 +679,8 @@ ev_mapping_list_free
 
 <SECTION>
 <FILE>ev-backends-manager</FILE>
-EvTypeInfo
 ev_backends_manager_get_document
 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/ev-backends-manager.c b/libdocument/ev-backends-manager.c
index b6d681b..d94c7f6 100644
--- a/libdocument/ev-backends-manager.c
+++ b/libdocument/ev-backends-manager.c
@@ -26,7 +26,6 @@
 
 static GList *ev_backends_list = NULL;
 
-typedef struct _EvBackendInfo EvBackendInfo;
 struct _EvBackendInfo {
 	gchar       *module_name;
 	GTypeModule *module;
@@ -38,6 +37,22 @@ struct _EvBackendInfo {
 	gchar      **mime_types;
 };
 
+const char *
+_ev_backend_info_get_description (EvBackendInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->type_desc;
+}
+
+char **
+_ev_backend_info_get_mime_types  (EvBackendInfo *info)
+{
+        g_return_val_if_fail (info != NULL, NULL);
+
+        return info->mime_types;
+}
+
 #define EV_BACKENDS_GROUP     "Evince Backend"
 #define EV_BACKENDS_EXTENSION ".evince-backend"
 
@@ -287,47 +302,16 @@ ev_backends_manager_get_document_module_name (EvDocument *document)
 	return info ? info->module_name : NULL;
 }
 
-static EvTypeInfo *
-ev_type_info_new (const gchar *desc, const gchar **mime_types)
-{
-	EvTypeInfo *info;
-
-	info = g_new (EvTypeInfo, 1);
-
-	info->desc = desc;
-	info->mime_types = mime_types;
-
-	return info;
-}
-
-EvTypeInfo *
-ev_backends_manager_get_document_type_info (EvDocument *document)
+EvBackendInfo *
+_ev_backends_manager_get_backend_for_document (EvDocument *document)
 {
-	EvBackendInfo *info;
+        g_return_val_if_fail (EV_IS_DOCUMENT (document), NULL);
 
-	info = get_document_backend_info (document);
-	return info ?
-		ev_type_info_new (info->type_desc,
-				  (const gchar **)info->mime_types)
-		: NULL;
+	return get_document_backend_info (document);
 }
 
 GList *
-ev_backends_manager_get_all_types_info (void)
+_ev_backends_manager_get_backends (void)
 {
-	GList *l;
-	GList *retval = NULL;
-
-	for (l = ev_backends_list; l; l = g_list_next (l)) {
-		EvBackendInfo *info;
-		EvTypeInfo    *type_info;
-
-		info = (EvBackendInfo *)l->data;
-
-		type_info = ev_type_info_new (info->type_desc,
-					      (const gchar **)info->mime_types);
-		retval = g_list_prepend (retval, type_info);
-	}
-
-	return retval;
+        return g_list_copy (ev_backends_list);
 }
diff --git a/libdocument/ev-backends-manager.h b/libdocument/ev-backends-manager.h
index f939076..2124619 100644
--- a/libdocument/ev-backends-manager.h
+++ b/libdocument/ev-backends-manager.h
@@ -30,18 +30,18 @@
 
 G_BEGIN_DECLS
 
-typedef struct _EvTypeInfo {
-	const gchar  *desc;
-	const gchar **mime_types;
-} EvTypeInfo;
+typedef struct _EvBackendInfo EvBackendInfo;
+
+const char *   _ev_backend_info_get_description               (EvBackendInfo *info);
+char **        _ev_backend_info_get_mime_types                (EvBackendInfo *info);
+EvBackendInfo *_ev_backends_manager_get_backend_for_document  (EvDocument  *document);
+GList         *_ev_backends_manager_get_backends              (void);
 
 gboolean    _ev_backends_manager_init                     (void);
 void        _ev_backends_manager_shutdown                 (void);
 
 EvDocument  *ev_backends_manager_get_document             (const gchar *mime_type);
 const gchar *ev_backends_manager_get_document_module_name (EvDocument  *document);
-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 1f1eb0d..44ac444 100644
--- a/libdocument/ev-document-factory.c
+++ b/libdocument/ev-document-factory.c
@@ -243,13 +243,17 @@ ev_document_factory_get_document (const char *uri, GError **error)
 }
 
 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;
 
-	while ((mime_type = info->mime_types[i++]))
-		gtk_file_filter_add_mime_type (filter, mime_type);
+        mime_types = _ev_backend_info_get_mime_types (info);
+        if (mime_types == NULL)
+                return;
+
+        for (i = 0; mime_types[i] != NULL; ++i)
+                gtk_file_filter_add_mime_type (filter, mime_types[i]);
 }
 
 /**
@@ -277,7 +281,7 @@ 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 ();
+	all_types = _ev_backends_manager_get_backends ();
 	
 	default_filter = document_filter = filter = gtk_file_filter_new ();
 	gtk_file_filter_set_name (filter, _("All Documents"));
@@ -285,11 +289,11 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
 	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 = _ev_backends_manager_get_backend_for_document (document);
 		default_filter = filter = gtk_file_filter_new ();
-		gtk_file_filter_set_name (filter, info->desc);
+		gtk_file_filter_set_name (filter, _ev_backend_info_get_description (info));
 		file_filter_add_mime_types (info, filter);
 		g_free (info);
 		gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (chooser), filter);
@@ -297,20 +301,15 @@ ev_document_factory_add_filters (GtkWidget *chooser, EvDocument *document)
 		GList *l;
 
 		for (l = all_types; l; l = g_list_next (l)){
-			EvTypeInfo *info;
-
-			info = (EvTypeInfo *)l->data;
+                        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, _ev_backend_info_get_description (info));
 			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, "*");



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