nautilus-3.6.3/libnautilus-private/nautilus-dbus-manager.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found nautilus-dbus-manager.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 /*
  2  * nautilus-dbus-manager: nautilus DBus interface
  3  *
  4  * Copyright (C) 2010, Red Hat, Inc.
  5  *
  6  * Nautilus is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License as
  8  * published by the Free Software Foundation; either version 2 of the
  9  * License, or (at your option) any later version.
 10  *
 11  * Nautilus is distributed in the hope that it will be useful,
 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 14  * General Public License for more details.
 15  *
 16  * You should have received a copy of the GNU General Public License
 17  * along with this program; if not, write to the Free Software
 18  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 19  *
 20  * Author: Cosimo Cecchi <cosimoc@redhat.com>
 21  *
 22  */
 23 
 24 #include <config.h>
 25 
 26 #include "nautilus-dbus-manager.h"
 27 #include "nautilus-generated.h"
 28 
 29 #include "nautilus-file-operations.h"
 30 
 31 #define DEBUG_FLAG NAUTILUS_DEBUG_DBUS
 32 #include "nautilus-debug.h"
 33 
 34 #include <gio/gio.h>
 35 
 36 typedef struct _NautilusDBusManager NautilusDBusManager;
 37 typedef struct _NautilusDBusManagerClass NautilusDBusManagerClass;
 38 
 39 struct _NautilusDBusManager {
 40   GObject parent;
 41 
 42   GDBusConnection *connection;
 43   GApplication *application;
 44 
 45   GDBusObjectManagerServer *object_manager;
 46   NautilusDBusFileOperations *file_operations;
 47 
 48   guint owner_id;
 49 };
 50 
 51 struct _NautilusDBusManagerClass {
 52   GObjectClass parent_class;
 53 };
 54 
 55 enum {
 56   PROP_APPLICATION = 1,
 57   NUM_PROPERTIES
 58 };
 59 
 60 #define SERVICE_TIMEOUT 5
 61 
 62 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 63 
 64 static GType nautilus_dbus_manager_get_type (void) G_GNUC_CONST;
 65 G_DEFINE_TYPE (NautilusDBusManager, nautilus_dbus_manager, G_TYPE_OBJECT);
 66 
 67 static NautilusDBusManager *singleton = NULL;
 68 
 69 static void
 70 nautilus_dbus_manager_dispose (GObject *object)
 71 {
 72   NautilusDBusManager *self = (NautilusDBusManager *) object;
 73 
 74   /* Unown before unregistering so we're not registred in a partial state */
 75   if (self->owner_id != 0)
 76     {
 77       g_bus_unown_name (self->owner_id);
 78       self->owner_id = 0;
 79     }
 80 
 81   if (self->file_operations) {
 82     g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (self->file_operations));
 83     g_object_unref (self->file_operations);
 84     self->file_operations = NULL;
 85   }
 86 
 87   if (self->object_manager) {
 88     g_object_unref (self->object_manager);
 89     self->object_manager = NULL;
 90   }
 91 
 92   g_clear_object (&self->connection);
 93 
 94   G_OBJECT_CLASS (nautilus_dbus_manager_parent_class)->dispose (object);
 95 }
 96 
 97 static gboolean
 98 service_timeout_handler (gpointer user_data)
 99 {
100   NautilusDBusManager *self = user_data;
101 
102   DEBUG ("Reached the DBus service timeout");
103 
104   /* just unconditionally release here, as if an operation has been
105    * called, its progress handler will hold it alive for all the task duration.
106    */
107   g_application_release (self->application);
108 
109   return FALSE;
110 }
111 
112 static gboolean
113 handle_copy_file (NautilusDBusFileOperations *object,
114 		  GDBusMethodInvocation *invocation,
115 		  const gchar *source_uri,
116 		  const gchar *source_display_name,
117 		  const gchar *dest_dir_uri,
118 		  const gchar *dest_name)
119 {
120   GFile *source_file, *target_dir;
121   const gchar *target_name = NULL, *source_name = NULL;
122 
123   source_file = g_file_new_for_uri (source_uri);
124   target_dir = g_file_new_for_uri (dest_dir_uri);
125 
126   if (dest_name != NULL && dest_name[0] != '\0')
127     target_name = dest_name;
128 
129   if (source_display_name != NULL && source_display_name[0] != '\0')
130     source_name = source_display_name;
131 
132   nautilus_file_operations_copy_file (source_file, target_dir, source_name, target_name,
133 				      NULL, NULL, NULL);
134 
135   g_object_unref (source_file);
136   g_object_unref (target_dir);
137 
138   nautilus_dbus_file_operations_complete_copy_file (object, invocation);
139   return TRUE; /* invocation was handled */
140 }
141 
142 static gboolean
143 handle_copy_uris (NautilusDBusFileOperations *object,
144 		  GDBusMethodInvocation *invocation,
145 		  const gchar **sources,
146 		  const gchar *destination)
147 {
148   GList *source_files = NULL;
149   GFile *dest_dir;
150   gint idx;
151 
152   dest_dir = g_file_new_for_uri (destination);
153 
154   for (idx = 0; sources[idx] != NULL; idx++)
155     source_files = g_list_prepend (source_files,
156                                    g_file_new_for_uri (sources[idx]));
157 
158   nautilus_file_operations_copy (source_files, NULL,
159                                  dest_dir,
160                                  NULL, NULL, NULL);
161 
162   g_list_free_full (source_files, g_object_unref);
163   g_object_unref (dest_dir);
164 
165   nautilus_dbus_file_operations_complete_copy_uris (object, invocation);
166   return TRUE; /* invocation was handled */
167 }
168 
169 static gboolean
170 handle_empty_trash (NautilusDBusFileOperations *object,
171 		    GDBusMethodInvocation *invocation)
172 {
173   nautilus_file_operations_empty_trash (NULL);
174 
175   nautilus_dbus_file_operations_complete_empty_trash (object, invocation);
176   return TRUE; /* invocation was handled */
177 }
178 
179 static void
180 bus_acquired_handler_cb (GDBusConnection *conn,
181                          const gchar *name,
182                          gpointer user_data)
183 {
184   NautilusDBusManager *self = user_data;
185 
186   DEBUG ("Bus acquired at %s", name);
187 
188   self->connection = g_object_ref (conn);
189 
190   self->object_manager = g_dbus_object_manager_server_new ("/org/gnome/Nautilus");
191 
192   self->file_operations = nautilus_dbus_file_operations_skeleton_new ();
193 
194   g_signal_connect (self->file_operations,
195 		    "handle-copy-uris",
196 		    G_CALLBACK (handle_copy_uris),
197 		    self);
198   g_signal_connect (self->file_operations,
199 		    "handle-copy-file",
200 		    G_CALLBACK (handle_copy_file),
201 		    self);
202   g_signal_connect (self->file_operations,
203 		    "handle-empty-trash",
204 		    G_CALLBACK (handle_empty_trash),
205 		    self);
206 
207   g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (self->file_operations), self->connection,
208 				    "/org/gnome/Nautilus", NULL);
209 
210   g_dbus_object_manager_server_set_connection (self->object_manager, self->connection);
211 
212   g_timeout_add_seconds (SERVICE_TIMEOUT, service_timeout_handler, self);
213 }
214 
215 static void
216 on_name_lost (GDBusConnection *connection,
217 	      const gchar     *name,
218 	      gpointer         user_data)
219 {
220   DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
221 }
222 
223 static void
224 on_name_acquired (GDBusConnection *connection,
225 		  const gchar     *name,
226 		  gpointer         user_data)
227 {
228   DEBUG ("Acquired the name %s on the session message bus\n", name);
229 }
230 
231 static void
232 nautilus_dbus_manager_init (NautilusDBusManager *self)
233 {
234   /* do nothing */
235 }
236 
237 static void
238 nautilus_dbus_manager_set_property (GObject *object,
239                                     guint property_id,
240                                     const GValue *value,
241                                     GParamSpec *pspec)
242 {
243   NautilusDBusManager *self = (NautilusDBusManager *) (object);
244 
245   switch (property_id)
246     {
247     case PROP_APPLICATION:
248       self->application = g_value_get_object (value);
249       break;
250     default:
251       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
252       break;
253     }
254 }
255 
256 static void
257 nautilus_dbus_manager_constructed (GObject *object)
258 {
259   NautilusDBusManager *self = (NautilusDBusManager *) (object);
260 
261   G_OBJECT_CLASS (nautilus_dbus_manager_parent_class)->constructed (object);
262 
263   g_application_hold (self->application);
264 
265   self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
266 				   "org.gnome.Nautilus",
267 				   G_BUS_NAME_OWNER_FLAGS_NONE,
268 				   bus_acquired_handler_cb,
269 				   on_name_acquired,
270 				   on_name_lost,
271 				   self,
272 				   NULL);
273 }
274 
275 static void
276 nautilus_dbus_manager_class_init (NautilusDBusManagerClass *klass)
277 {
278   GObjectClass *oclass = G_OBJECT_CLASS (klass);
279 
280   oclass->dispose = nautilus_dbus_manager_dispose;
281   oclass->constructed = nautilus_dbus_manager_constructed;
282   oclass->set_property = nautilus_dbus_manager_set_property;
283 
284   properties[PROP_APPLICATION] =
285     g_param_spec_object ("application",
286                          "GApplication instance",
287                          "The owning GApplication instance",
288                          G_TYPE_APPLICATION,
289                          G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
290                          G_PARAM_STATIC_STRINGS);
291 
292   g_object_class_install_properties (oclass, NUM_PROPERTIES, properties);
293 }
294 
295 void
296 nautilus_dbus_manager_start (GApplication *application)
297 {
298   singleton = g_object_new (nautilus_dbus_manager_get_type (),
299                             "application", application,
300                             NULL);
301 }
302 
303 void
304 nautilus_dbus_manager_stop (void)
305 {
306   g_clear_object (&singleton);
307 }