nautilus-3.6.3/libnautilus-private/nautilus-trash-monitor.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found nautilus-trash-monitor.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 /* 
  4    nautilus-trash-monitor.c: Nautilus trash state watcher.
  5  
  6    Copyright (C) 2000, 2001 Eazel, Inc.
  7   
  8    This program is free software; you can redistribute it and/or
  9    modify it under the terms of the GNU General Public License as
 10    published by the Free Software Foundation; either version 2 of the
 11    License, or (at your option) any later version.
 12   
 13    This program is distributed in the hope that it will be useful,
 14    but WITHOUT ANY WARRANTY; without even the implied warranty of
 15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16    General Public License for more details.
 17   
 18    You should have received a copy of the GNU General Public
 19    License along with this program; if not, write to the
 20    Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 21    Boston, MA 02111-1307, USA.
 22   
 23    Author: Pavel Cisler <pavel@eazel.com>
 24 */
 25 
 26 #include <config.h>
 27 #include "nautilus-trash-monitor.h"
 28 
 29 #include "nautilus-directory-notify.h"
 30 #include "nautilus-directory.h"
 31 #include "nautilus-file-attributes.h"
 32 #include "nautilus-icon-names.h"
 33 #include <eel/eel-debug.h>
 34 #include <gio/gio.h>
 35 #include <string.h>
 36 
 37 struct NautilusTrashMonitorDetails {
 38 	gboolean empty;
 39 	GIcon *icon;
 40 	GFileMonitor *file_monitor;
 41 };
 42 
 43 enum {
 44 	TRASH_STATE_CHANGED,
 45 	LAST_SIGNAL
 46 };
 47 
 48 static guint signals[LAST_SIGNAL];
 49 static NautilusTrashMonitor *nautilus_trash_monitor = NULL;
 50 
 51 G_DEFINE_TYPE(NautilusTrashMonitor, nautilus_trash_monitor, G_TYPE_OBJECT)
 52 
 53 static void
 54 nautilus_trash_monitor_finalize (GObject *object)
 55 {
 56 	NautilusTrashMonitor *trash_monitor;
 57 
 58 	trash_monitor = NAUTILUS_TRASH_MONITOR (object);
 59 
 60 	if (trash_monitor->details->icon) {
 61 		g_object_unref (trash_monitor->details->icon);
 62 	}
 63 	if (trash_monitor->details->file_monitor) {
 64 		g_object_unref (trash_monitor->details->file_monitor);
 65 	}
 66 
 67 	G_OBJECT_CLASS (nautilus_trash_monitor_parent_class)->finalize (object);
 68 }
 69 
 70 static void
 71 nautilus_trash_monitor_class_init (NautilusTrashMonitorClass *klass)
 72 {
 73 	GObjectClass *object_class;
 74 
 75 	object_class = G_OBJECT_CLASS (klass);
 76 
 77 	object_class->finalize = nautilus_trash_monitor_finalize;
 78 
 79 	signals[TRASH_STATE_CHANGED] = g_signal_new
 80 		("trash_state_changed",
 81 		 G_TYPE_FROM_CLASS (object_class),
 82 		 G_SIGNAL_RUN_LAST,
 83 		 G_STRUCT_OFFSET (NautilusTrashMonitorClass, trash_state_changed),
 84 		 NULL, NULL,
 85 		 g_cclosure_marshal_VOID__BOOLEAN,
 86 		 G_TYPE_NONE, 1,
 87 		 G_TYPE_BOOLEAN);
 88 
 89 	g_type_class_add_private (object_class, sizeof(NautilusTrashMonitorDetails));
 90 }
 91 
 92 static void
 93 update_icon (NautilusTrashMonitor *trash_monitor)
 94 {
 95 	g_clear_object (&trash_monitor->details->icon);
 96 
 97 	if (trash_monitor->details->empty) {
 98 		trash_monitor->details->icon = g_themed_icon_new (NAUTILUS_ICON_TRASH);
 99 	} else {
100 		trash_monitor->details->icon = g_themed_icon_new (NAUTILUS_ICON_TRASH_FULL);
101 	}
102 }
103 
104 static void
105 update_empty_info (NautilusTrashMonitor *trash_monitor,
106 		   gboolean is_empty)
107 {
108 	if (trash_monitor->details->empty == is_empty) {
109 		return;
110 	}
111 	
112 	trash_monitor->details->empty = is_empty;
113 	update_icon (trash_monitor);
114 
115 	/* trash got empty or full, notify everyone who cares */
116 	g_signal_emit (trash_monitor,
117 		       signals[TRASH_STATE_CHANGED], 0,
118 		       trash_monitor->details->empty);
119 }
120 
121 static void
122 enumerate_next_files_cb (GObject *source,
123 			 GAsyncResult *res,
124 			 gpointer user_data)
125 {
126 	NautilusTrashMonitor *trash_monitor = user_data;
127 	GList *infos;
128 
129 	infos = g_file_enumerator_next_files_finish (G_FILE_ENUMERATOR (source), res, NULL);
130 	if (!infos) {
131 		update_empty_info (trash_monitor, TRUE);
132 	} else {
133 		update_empty_info (trash_monitor, FALSE);
134 		g_list_free_full (infos, g_object_unref);
135 	}
136 
137 	g_object_unref (trash_monitor);
138 }
139 
140 static void
141 enumerate_children_cb (GObject *source,
142 		       GAsyncResult *res,
143 		       gpointer user_data)
144 {
145 	GFileEnumerator *enumerator;
146 	NautilusTrashMonitor *trash_monitor = user_data;
147 
148 	enumerator = g_file_enumerate_children_finish (G_FILE (source), res, NULL);
149 	if (!enumerator) {
150 		update_empty_info (trash_monitor, TRUE);
151 		g_object_unref (trash_monitor);
152 		return;
153 	}
154 
155 	g_file_enumerator_next_files_async (enumerator, 1,
156 					    G_PRIORITY_DEFAULT, NULL,
157 					    enumerate_next_files_cb, trash_monitor);
158 	g_object_unref (enumerator);
159 }
160 
161 static void
162 schedule_update_info (NautilusTrashMonitor *trash_monitor)
163 {
164 	GFile *location;
165 
166 	location = g_file_new_for_uri ("trash:///");
167 	g_file_enumerate_children_async (location,
168 					 G_FILE_ATTRIBUTE_STANDARD_TYPE,
169 					 G_FILE_QUERY_INFO_NONE,
170 					 G_PRIORITY_DEFAULT, NULL,
171 					 enumerate_children_cb, g_object_ref (trash_monitor));
172 	
173 	g_object_unref (location);
174 }
175 
176 static void
177 file_changed (GFileMonitor* monitor,
178 	      GFile *child,
179 	      GFile *other_file,
180 	      GFileMonitorEvent event_type,
181 	      gpointer user_data)
182 {
183 	NautilusTrashMonitor *trash_monitor;
184 
185 	trash_monitor = NAUTILUS_TRASH_MONITOR (user_data);
186 
187 	schedule_update_info (trash_monitor);
188 }
189 
190 static void
191 nautilus_trash_monitor_init (NautilusTrashMonitor *trash_monitor)
192 {
193 	GFile *location;
194 
195 	trash_monitor->details = G_TYPE_INSTANCE_GET_PRIVATE (trash_monitor,
196 							      NAUTILUS_TYPE_TRASH_MONITOR,
197 							      NautilusTrashMonitorDetails);
198 
199 	trash_monitor->details->empty = TRUE;
200 	update_icon (trash_monitor);
201 
202 	location = g_file_new_for_uri ("trash:///");
203 
204 	trash_monitor->details->file_monitor = g_file_monitor_file (location, 0, NULL, NULL);
205 
206 	g_signal_connect (trash_monitor->details->file_monitor, "changed",
207 			  (GCallback)file_changed, trash_monitor);
208 
209 	g_object_unref (location);
210 
211 	schedule_update_info (trash_monitor);
212 }
213 
214 static void
215 unref_trash_monitor (void)
216 {
217 	g_object_unref (nautilus_trash_monitor);
218 }
219 
220 NautilusTrashMonitor *
221 nautilus_trash_monitor_get (void)
222 {
223 	if (nautilus_trash_monitor == NULL) {
224 		/* not running yet, start it up */
225 
226 		nautilus_trash_monitor = NAUTILUS_TRASH_MONITOR
227 			(g_object_new (NAUTILUS_TYPE_TRASH_MONITOR, NULL));
228 		eel_debug_call_at_shutdown (unref_trash_monitor);
229 	}
230 
231 	return nautilus_trash_monitor;
232 }
233 
234 gboolean
235 nautilus_trash_monitor_is_empty (void)
236 {
237 	NautilusTrashMonitor *monitor;
238 
239 	monitor = nautilus_trash_monitor_get ();
240 	return monitor->details->empty;
241 }
242 
243 GIcon *
244 nautilus_trash_monitor_get_icon (void)
245 {
246 	NautilusTrashMonitor *monitor;
247 
248 	monitor = nautilus_trash_monitor_get ();
249 	if (monitor->details->icon) {
250 		return g_object_ref (monitor->details->icon);
251 	}
252 	return NULL;
253 }
254 
255 void
256 nautilus_trash_monitor_add_new_trash_directories (void)
257 {
258 	/* We trashed something... */
259 }