nautilus-3.6.3/libnautilus-private/nautilus-search-provider.c

No issues found

  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*-
  2  *
  3  *  Copyright (C) 2012 Red Hat, Inc.
  4  *
  5  *  This library is free software; you can redistribute it and/or
  6  *  modify it under the terms of the GNU Library General Public
  7  *  License as published by the Free Software Foundation; either
  8  *  version 2 of the License, or (at your option) any later version.
  9  *
 10  *  This library is distributed in the hope that it will be useful,
 11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  *  Library General Public License for more details.
 14  *
 15  *  You should have received a copy of the GNU Library General Public
 16  *  License along with this library; if not, write to the Free
 17  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 18  *
 19  */
 20 
 21 #include <config.h>
 22 #include "nautilus-search-provider.h"
 23 
 24 #include <glib-object.h>
 25 
 26 enum {
 27        HITS_ADDED,
 28        FINISHED,
 29        ERROR,
 30        LAST_SIGNAL
 31 };
 32 
 33 static guint signals[LAST_SIGNAL];
 34 
 35 static void nautilus_search_provider_base_init (gpointer g_iface);
 36 
 37 GType
 38 nautilus_search_provider_get_type (void)
 39 {
 40 	static GType search_provider_type = 0;
 41 
 42 	if (!search_provider_type) {
 43 		const GTypeInfo search_provider_info = {
 44 			sizeof (NautilusSearchProviderIface), /* class_size */
 45 			nautilus_search_provider_base_init,   /* base_init */
 46 			NULL,           /* base_finalize */
 47 			NULL,
 48 			NULL,           /* class_finalize */
 49 			NULL,           /* class_data */
 50 			0,
 51 			0,              /* n_preallocs */
 52 			NULL
 53 		};
 54 
 55 		search_provider_type = g_type_register_static (G_TYPE_INTERFACE,
 56 							       "NautilusSearchProvider",
 57 							       &search_provider_info,
 58 							       0);
 59 
 60 		g_type_interface_add_prerequisite (search_provider_type, G_TYPE_OBJECT);
 61 	}
 62 
 63 	return search_provider_type;
 64 }
 65 
 66 static void
 67 nautilus_search_provider_base_init (gpointer g_iface)
 68 {
 69 	static gboolean initialized = FALSE;
 70 
 71 	if (initialized) {
 72 		return;
 73 	}
 74 
 75 	signals[HITS_ADDED] = g_signal_new ("hits-added",
 76 					    NAUTILUS_TYPE_SEARCH_PROVIDER,
 77 					    G_SIGNAL_RUN_LAST,
 78 					    G_STRUCT_OFFSET (NautilusSearchProviderIface, hits_added),
 79 					    NULL, NULL,
 80 					    g_cclosure_marshal_VOID__POINTER,
 81 					    G_TYPE_NONE, 1,
 82 					    G_TYPE_POINTER);
 83 
 84 	signals[FINISHED] = g_signal_new ("finished",
 85 					  NAUTILUS_TYPE_SEARCH_PROVIDER,
 86 					  G_SIGNAL_RUN_LAST,
 87 					  G_STRUCT_OFFSET (NautilusSearchProviderIface, finished),
 88 					  NULL, NULL,
 89 					  g_cclosure_marshal_VOID__VOID,
 90 					  G_TYPE_NONE, 0);
 91 
 92 	signals[ERROR] = g_signal_new ("error",
 93 				       NAUTILUS_TYPE_SEARCH_PROVIDER,
 94 				       G_SIGNAL_RUN_LAST,
 95 				       G_STRUCT_OFFSET (NautilusSearchProviderIface, error),
 96 				       NULL, NULL,
 97 				       g_cclosure_marshal_VOID__STRING,
 98 				       G_TYPE_NONE, 1,
 99 				       G_TYPE_STRING);
100 
101 	initialized = TRUE;
102 }
103 
104 void
105 nautilus_search_provider_set_query (NautilusSearchProvider *provider, NautilusQuery *query)
106 {
107 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
108 	g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query != NULL);
109 	g_return_if_fail (NAUTILUS_IS_QUERY (query));
110 
111 	NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->set_query (provider, query);
112 }
113 
114 void
115 nautilus_search_provider_start (NautilusSearchProvider *provider)
116 {
117 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
118 	g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start != NULL);
119 
120 	NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->start (provider);
121 }
122 
123 void
124 nautilus_search_provider_stop (NautilusSearchProvider *provider)
125 {
126 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
127 	g_return_if_fail (NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop != NULL);
128 
129 	NAUTILUS_SEARCH_PROVIDER_GET_IFACE (provider)->stop (provider);
130 }
131 
132 void
133 nautilus_search_provider_hits_added (NautilusSearchProvider *provider, GList *hits)
134 {
135 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
136 
137 	g_signal_emit (provider, signals[HITS_ADDED], 0, hits);
138 }
139 
140 void
141 nautilus_search_provider_finished (NautilusSearchProvider *provider)
142 {
143 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
144 
145 	g_signal_emit (provider, signals[FINISHED], 0);
146 }
147 
148 void
149 nautilus_search_provider_error (NautilusSearchProvider *provider, const char *error_message)
150 {
151 	g_return_if_fail (NAUTILUS_IS_SEARCH_PROVIDER (provider));
152 
153 	g_signal_emit (provider, signals[ERROR], 0, error_message);
154 }