nautilus-3.6.3/libnautilus-private/nautilus-search-engine-model.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found nautilus-search-engine-model.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
  2 /*
  3  * Copyright (C) 2005 Red Hat, Inc
  4  *
  5  * Nautilus is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU General Public License as
  7  * published by the Free Software Foundation; either version 2 of the
  8  * License, or (at your option) any later version.
  9  *
 10  * Nautilus 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  * General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public
 16  * License along with this program; see the file COPYING.  If not,
 17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 18  * Boston, MA 02111-1307, USA.
 19  *
 20  * Author: Alexander Larsson <alexl@redhat.com>
 21  *
 22  */
 23 
 24 #include <config.h>
 25 #include "nautilus-search-hit.h"
 26 #include "nautilus-search-provider.h"
 27 #include "nautilus-search-engine-model.h"
 28 #include "nautilus-directory.h"
 29 #include "nautilus-directory-private.h"
 30 #include "nautilus-file.h"
 31 #include "nautilus-ui-utilities.h"
 32 
 33 #include <string.h>
 34 #include <glib.h>
 35 #include <gio/gio.h>
 36 
 37 struct NautilusSearchEngineModelDetails {
 38 	NautilusQuery *query;
 39 
 40 	GList *hits;
 41 	NautilusDirectory *directory;
 42 
 43 	gboolean query_pending;
 44 	guint finished_id;
 45 };
 46 
 47 static void nautilus_search_provider_init (NautilusSearchProviderIface  *iface);
 48 
 49 G_DEFINE_TYPE_WITH_CODE (NautilusSearchEngineModel,
 50 			 nautilus_search_engine_model,
 51 			 G_TYPE_OBJECT,
 52 			 G_IMPLEMENT_INTERFACE (NAUTILUS_TYPE_SEARCH_PROVIDER,
 53 						nautilus_search_provider_init))
 54 
 55 static void
 56 finalize (GObject *object)
 57 {
 58 	NautilusSearchEngineModel *model;
 59 
 60 	model = NAUTILUS_SEARCH_ENGINE_MODEL (object);
 61 
 62 	if (model->details->hits != NULL) {
 63 		g_list_free_full (model->details->hits, g_object_unref);
 64 		model->details->hits = NULL;
 65 	}
 66 
 67 	if (model->details->finished_id != 0) {
 68 		g_source_remove (model->details->finished_id);
 69 		model->details->finished_id = 0;
 70 	}
 71 
 72 	g_clear_object (&model->details->directory);
 73 	g_clear_object (&model->details->query);
 74 
 75 	G_OBJECT_CLASS (nautilus_search_engine_model_parent_class)->finalize (object);
 76 }
 77 
 78 static gboolean
 79 search_finished (NautilusSearchEngineModel *model)
 80 {
 81 	if (model->details->hits != NULL) {
 82 		nautilus_search_provider_hits_added (NAUTILUS_SEARCH_PROVIDER (model),
 83 						     model->details->hits);
 84 		g_list_free_full (model->details->hits, g_object_unref);
 85 		model->details->hits = NULL;
 86 	}
 87 
 88 	model->details->query_pending = FALSE;
 89 	nautilus_search_provider_finished (NAUTILUS_SEARCH_PROVIDER (model));
 90 	g_object_unref (model);
 91 
 92 	return FALSE;
 93 }
 94 
 95 static void
 96 search_finished_idle (NautilusSearchEngineModel *model)
 97 {
 98 	if (model->details->finished_id != 0) {
 99 		return;
100 	}
101 
102 	model->details->finished_id = g_idle_add ((GSourceFunc) search_finished, model);
103 }
104 
105 static void
106 model_directory_ready_cb (NautilusDirectory	*directory,
107 			  GList			*list,
108 			  gpointer		 user_data)
109 {
110 	NautilusSearchEngineModel *model = user_data;
111 	gchar *uri, *display_name;
112 	GList *files, *hits, *mime_types, *l, *m;
113 	NautilusFile *file;
114 	gdouble match;
115 	gboolean found;
116 	NautilusSearchHit *hit;
117 
118 	files = nautilus_directory_get_file_list (directory);
119 	mime_types = nautilus_query_get_mime_types (model->details->query);
120 	hits = NULL;
121 
122 	for (l = files; l != NULL; l = l->next) {
123 		file = l->data;
124 
125 		display_name = nautilus_file_get_display_name (file);
126 		match = nautilus_query_matches_string (model->details->query, display_name);
127 		found = (match > -1);
128 
129 		if (found && mime_types) {
130 			found = FALSE;
131 
132 			for (m = mime_types; m != NULL; m = m->next) {
133 				if (nautilus_file_is_mime_type (file, m->data)) {
134 					found = TRUE;
135 					break;
136 				}
137 			}
138 		}
139 
140 		if (found) {
141 			uri = nautilus_file_get_uri (file);
142 			hit = nautilus_search_hit_new (uri);
143 			nautilus_search_hit_set_fts_rank (hit, match);
144 			hits = g_list_prepend (hits, hit);
145 			g_free (uri);
146 		}
147 
148 		g_free (display_name);
149 	}
150 
151 	g_list_free_full (mime_types, g_free);
152 	nautilus_file_list_free (files);
153 	model->details->hits = hits;
154 
155 	search_finished (model);
156 }
157 
158 static void
159 nautilus_search_engine_model_start (NautilusSearchProvider *provider)
160 {
161 	NautilusSearchEngineModel *model;
162 
163 	model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
164 
165 	if (model->details->query_pending) {
166 		return;
167 	}
168 
169 	g_object_ref (model);
170 	model->details->query_pending = TRUE;
171 
172 	if (model->details->directory == NULL) {
173 		search_finished_idle (model);
174 		return;
175 	}
176 
177 	nautilus_directory_call_when_ready (model->details->directory,
178 					    NAUTILUS_FILE_ATTRIBUTE_INFO,
179 					    TRUE, model_directory_ready_cb, model);
180 }
181 
182 static void
183 nautilus_search_engine_model_stop (NautilusSearchProvider *provider)
184 {
185 	NautilusSearchEngineModel *model;
186 
187 	model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
188 
189 	if (model->details->query_pending) {
190 		nautilus_directory_cancel_callback (model->details->directory,
191 						    model_directory_ready_cb, model);
192 		search_finished_idle (model);
193 	}
194 
195 	g_clear_object (&model->details->directory);
196 }
197 
198 static void
199 nautilus_search_engine_model_set_query (NautilusSearchProvider *provider,
200 					 NautilusQuery          *query)
201 {
202 	NautilusSearchEngineModel *model;
203 
204 	model = NAUTILUS_SEARCH_ENGINE_MODEL (provider);
205 
206 	g_object_ref (query);
207 	g_clear_object (&model->details->query);
208 	model->details->query = query;
209 }
210 
211 static void
212 nautilus_search_provider_init (NautilusSearchProviderIface *iface)
213 {
214 	iface->set_query = nautilus_search_engine_model_set_query;
215 	iface->start = nautilus_search_engine_model_start;
216 	iface->stop = nautilus_search_engine_model_stop;
217 }
218 
219 static void
220 nautilus_search_engine_model_class_init (NautilusSearchEngineModelClass *class)
221 {
222 	GObjectClass *gobject_class;
223 
224 	gobject_class = G_OBJECT_CLASS (class);
225 	gobject_class->finalize = finalize;
226 
227 	g_type_class_add_private (class, sizeof (NautilusSearchEngineModelDetails));
228 }
229 
230 static void
231 nautilus_search_engine_model_init (NautilusSearchEngineModel *engine)
232 {
233 	engine->details = G_TYPE_INSTANCE_GET_PRIVATE (engine, NAUTILUS_TYPE_SEARCH_ENGINE_MODEL,
234 						       NautilusSearchEngineModelDetails);
235 }
236 
237 NautilusSearchEngineModel *
238 nautilus_search_engine_model_new (void)
239 {
240 	NautilusSearchEngineModel *engine;
241 
242 	engine = g_object_new (NAUTILUS_TYPE_SEARCH_ENGINE_MODEL, NULL);
243 
244 	return engine;
245 }
246 
247 void
248 nautilus_search_engine_model_set_model (NautilusSearchEngineModel *model,
249 					NautilusDirectory         *directory)
250 {
251 	g_clear_object (&model->details->directory);
252 	model->details->directory = nautilus_directory_ref (directory);
253 }
254 
255 NautilusDirectory *
256 nautilus_search_engine_model_get_model (NautilusSearchEngineModel *model)
257 {
258 	return model->details->directory;
259 }