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

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found nautilus-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    nautilus-monitor.c: file and directory change monitoring for nautilus
  4  
  5    Copyright (C) 2000, 2001 Eazel, 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    Authors: Seth Nickell <seth@eazel.com>
 23             Darin Adler <darin@bentspoon.com>
 24 	    Alex Graveley <alex@ximian.com>
 25 */
 26 
 27 #include <config.h>
 28 #include "nautilus-monitor.h"
 29 #include "nautilus-file-changes-queue.h"
 30 #include "nautilus-file-utilities.h"
 31 
 32 #include <gio/gio.h>
 33 
 34 struct NautilusMonitor {
 35 	GFileMonitor *monitor;
 36 	GVolumeMonitor *volume_monitor;
 37 	GMount *mount;
 38 	GFile *location;
 39 };
 40 
 41 gboolean
 42 nautilus_monitor_active (void)
 43 {
 44 	static gboolean tried_monitor = FALSE;
 45 	static gboolean monitor_success;
 46 	GFileMonitor *dir_monitor;
 47 	GFile *file;
 48 
 49 	if (tried_monitor == FALSE) {	
 50 		file = g_file_new_for_path (g_get_home_dir ());
 51 		dir_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
 52 		g_object_unref (file);
 53 		
 54 		monitor_success = (dir_monitor != NULL);
 55 		if (dir_monitor) {
 56 			g_object_unref (dir_monitor);
 57 		}
 58 
 59 		tried_monitor = TRUE;
 60 	}
 61 
 62 	return monitor_success;
 63 }
 64 
 65 static gboolean call_consume_changes_idle_id = 0;
 66 
 67 static gboolean
 68 call_consume_changes_idle_cb (gpointer not_used)
 69 {
 70 	nautilus_file_changes_consume_changes (TRUE);
 71 	call_consume_changes_idle_id = 0;
 72 	return FALSE;
 73 }
 74 
 75 static void
 76 schedule_call_consume_changes (void)
 77 {
 78 	if (call_consume_changes_idle_id == 0) {
 79 		call_consume_changes_idle_id =
 80 			g_idle_add (call_consume_changes_idle_cb, NULL);
 81 	}
 82 }
 83 
 84 static void
 85 mount_removed (GVolumeMonitor *volume_monitor,
 86 	       GMount *mount,
 87 	       gpointer user_data)
 88 {
 89 	NautilusMonitor *monitor = user_data;
 90 
 91 	if (mount == monitor->mount) {
 92 		nautilus_file_changes_queue_file_removed (monitor->location);
 93 		schedule_call_consume_changes ();
 94 	}
 95 }
 96 
 97 static void
 98 dir_changed (GFileMonitor* monitor,
 99 	     GFile *child,
100 	     GFile *other_file,
101 	     GFileMonitorEvent event_type,
102 	     gpointer user_data)
103 {
104 	char *uri, *to_uri;
105 	
106 	uri = g_file_get_uri (child);
107 	to_uri = NULL;
108 	if (other_file) {
109 		to_uri = g_file_get_uri (other_file);
110 	}
111 
112 	switch (event_type) {
113 	default:
114 	case G_FILE_MONITOR_EVENT_CHANGED:
115 		/* ignore */
116 		break;
117 	case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
118 	case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
119 		nautilus_file_changes_queue_file_changed (child);
120 		break;
121 	case G_FILE_MONITOR_EVENT_UNMOUNTED:
122 	case G_FILE_MONITOR_EVENT_DELETED:
123 		nautilus_file_changes_queue_file_removed (child);
124 		break;
125 	case G_FILE_MONITOR_EVENT_CREATED:
126 		nautilus_file_changes_queue_file_added (child);
127 		break;
128 	}
129 
130 	g_free (uri);
131 	g_free (to_uri);
132 
133 	schedule_call_consume_changes ();
134 }
135  
136 NautilusMonitor *
137 nautilus_monitor_directory (GFile *location)
138 {
139 	GFileMonitor *dir_monitor;
140 	NautilusMonitor *ret;
141 
142 	ret = g_new0 (NautilusMonitor, 1);
143 	dir_monitor = g_file_monitor_directory (location, G_FILE_MONITOR_WATCH_MOUNTS, NULL, NULL);
144 
145 	if (dir_monitor != NULL) {
146 		ret->monitor = dir_monitor;
147 	} else if (!g_file_is_native (location)) {
148 		ret->mount = nautilus_get_mounted_mount_for_root (location);
149 		ret->location = g_object_ref (location);
150 		ret->volume_monitor = g_volume_monitor_get ();
151 	}
152 
153 	if (ret->monitor != NULL) {
154 		g_signal_connect (ret->monitor, "changed",
155 				  G_CALLBACK (dir_changed), ret);
156 	}
157 
158 	if (ret->volume_monitor != NULL) {
159 		g_signal_connect (ret->volume_monitor, "mount-removed",
160 				  G_CALLBACK (mount_removed), ret);
161 	}
162 
163 	/* We return a monitor even on failure, so we can avoid later trying again */
164 	return ret;
165 }
166 
167 void 
168 nautilus_monitor_cancel (NautilusMonitor *monitor)
169 {
170 	if (monitor->monitor != NULL) {
171 		g_signal_handlers_disconnect_by_func (monitor->monitor, dir_changed, monitor);
172 		g_file_monitor_cancel (monitor->monitor);
173 		g_object_unref (monitor->monitor);
174 	}
175 
176 	if (monitor->volume_monitor != NULL) {
177 		g_signal_handlers_disconnect_by_func (monitor->volume_monitor, mount_removed, monitor);
178 		g_object_unref (monitor->volume_monitor);
179 	}
180 
181 	g_clear_object (&monitor->location);
182 	g_clear_object (&monitor->mount);
183 	g_free (monitor);
184 }