nautilus-3.6.3/src/nautilus-view-factory.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
  2 
  3    nautilus-view-factory.c: register and create NautilusViews
  4  
  5    Copyright (C) 2004 Red Hat Inc.
  6   
  7    This program is free software; you can redistribute it and/or
  8    modify it under the terms of the GNU General Public License as
  9    published by the Free Software Foundation; either version 2 of the
 10    License, or (at your option) any later version.
 11   
 12    This program is distributed in the hope that it will be useful,
 13    but WITHOUT ANY WARRANTY; without even the implied warranty of
 14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 15    General Public License for more details.
 16   
 17    You should have received a copy of the GNU General Public
 18    License along with this program; if not, write to the
 19    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 20    Boston, MA 02111-1307, USA.
 21   
 22    Author: Alexander Larsson <alexl@redhat.com>
 23 */
 24 
 25 #include "config.h"
 26 
 27 #include "nautilus-view-factory.h"
 28 
 29 static GList *registered_views;
 30 
 31 void
 32 nautilus_view_factory_register (NautilusViewInfo *view_info)
 33 {
 34 	g_return_if_fail (view_info != NULL);
 35 	g_return_if_fail (view_info->id != NULL);
 36 	g_return_if_fail (nautilus_view_factory_lookup (view_info->id) == NULL);
 37 	
 38 	registered_views = g_list_append (registered_views, view_info);
 39 }
 40 
 41 const NautilusViewInfo *
 42 nautilus_view_factory_lookup (const char *id)
 43 {
 44 	GList *l;
 45 	NautilusViewInfo *view_info;
 46 
 47 	g_return_val_if_fail (id != NULL, NULL);
 48 
 49 	
 50 	for (l = registered_views; l != NULL; l = l->next) {
 51 		view_info = l->data;
 52 		
 53 		if (strcmp (view_info->id, id) == 0) {
 54 			return view_info;
 55 		}
 56 	}
 57 	return NULL;
 58 }
 59 
 60 NautilusView *
 61 nautilus_view_factory_create (const char *id,
 62 			      NautilusWindowSlot *slot)
 63 {
 64 	const NautilusViewInfo *view_info;
 65 	NautilusView *view;
 66 
 67 	view_info = nautilus_view_factory_lookup (id);
 68 	if (view_info == NULL) {
 69 		return NULL;
 70 	}
 71 
 72 	view = view_info->create (slot);
 73 	if (g_object_is_floating (view)) {
 74 		g_object_ref_sink (view);
 75 	}
 76 	return view;
 77 }
 78 
 79 gboolean
 80 nautilus_view_factory_view_supports_uri (const char *id,
 81 					 GFile *location,
 82 					 GFileType file_type,
 83 					 const char *mime_type)
 84 {
 85 	const NautilusViewInfo *view_info;
 86 	char *uri;
 87 	gboolean res;
 88 
 89 	view_info = nautilus_view_factory_lookup (id);
 90 	if (view_info == NULL) {
 91 		return FALSE;
 92 	}
 93 	uri = g_file_get_uri (location);
 94 	res = view_info->supports_uri (uri, file_type, mime_type);
 95 	g_free (uri);
 96 	return res;
 97 	
 98 }
 99 
100 GList *
101 nautilus_view_factory_get_views_for_uri (const char *uri,
102 					 GFileType file_type,
103 					 const char *mime_type)
104 {
105 	GList *l, *res;
106 	const NautilusViewInfo *view_info;
107 
108 	res = NULL;
109 	
110 	for (l = registered_views; l != NULL; l = l->next) {
111 		view_info = l->data;
112 
113 		if (view_info->supports_uri (uri, file_type, mime_type)) {
114 			res = g_list_prepend (res, g_strdup (view_info->id));
115 		}
116 	}
117 	
118 	return g_list_reverse (res);
119 }