nautilus-cd-burner r2270 - in trunk: . src



Author: hadess
Date: Wed Dec 17 11:49:06 2008
New Revision: 2270
URL: http://svn.gnome.org/viewvc/nautilus-cd-burner?rev=2270&view=rev

Log:
2008-12-17  Bastien Nocera  <hadess hadess net>

	* src/nautilus-burn-drive.c
	(nautilus_burn_drive_get_drive_for_node),
	(nautilus_burn_drive_eject_cb), (nautilus_burn_drive_eject):
	Eject using GIO instead of calling out to eject, or gnome-mount
	(Closes: #504391)



Modified:
   trunk/ChangeLog
   trunk/src/nautilus-burn-drive.c

Modified: trunk/src/nautilus-burn-drive.c
==============================================================================
--- trunk/src/nautilus-burn-drive.c	(original)
+++ trunk/src/nautilus-burn-drive.c	Wed Dec 17 11:49:06 2008
@@ -781,6 +781,48 @@
         return drive->priv->media_is_mounted;
 }
 
+static GDrive *
+nautilus_burn_drive_get_drive_for_node (NautilusBurnDrive *drive)
+{
+	GVolumeMonitor *monitor;
+	GList *drives, *l;
+	GDrive *ret;
+
+	ret = NULL;
+
+	monitor = g_volume_monitor_get ();
+	drives = g_volume_monitor_get_connected_drives (monitor);
+	g_object_unref (monitor);
+
+	for (l = drives; l != NULL && ret == NULL; l = l->next) {
+		GDrive *d = l->data;
+		char *id;
+
+		id = g_drive_get_identifier (d, G_VOLUME_IDENTIFIER_KIND_UNIX_DEVICE);
+		if (g_strcmp0 (id, drive->priv->device) == 0)
+			ret = g_object_ref (d);
+	}
+	g_list_foreach (drives, (GFunc) g_object_unref, NULL);
+	g_list_free (drives);
+
+	return ret;
+}
+
+typedef struct _CdCacheCallbackData {
+	gboolean called;
+	gboolean result;
+} EjectCallbackData;
+
+static void
+nautilus_burn_drive_eject_cb (GObject *source_object,
+			      GAsyncResult *res,
+			      EjectCallbackData *data)
+{
+	data->result = g_drive_eject_finish (G_DRIVE (source_object),
+					     res, NULL);
+	data->called = TRUE;
+}
+
 /**
  * nautilus_burn_drive_eject:
  * @drive: #NautilusBurnDrive
@@ -794,8 +836,8 @@
 gboolean
 nautilus_burn_drive_eject (NautilusBurnDrive *drive)
 {
-        char    *cmd;
-        gboolean res;
+	GDrive *gdrive;
+	EjectCallbackData data;
 
         g_return_val_if_fail (drive != NULL, FALSE);
 
@@ -803,19 +845,25 @@
                 return FALSE;
         }
 
-#ifdef USE_GNOME_MOUNT
-        cmd = g_strdup_printf ("gnome-mount --block --eject --no-ui --device=%s", drive->priv->device);
-#else
-        cmd = g_strdup_printf ("eject %s", drive->priv->device);
-#endif
+	gdrive = nautilus_burn_drive_get_drive_for_node (drive);
+	if (gdrive == NULL)
+		return FALSE;
+	if (g_drive_can_eject (gdrive) == FALSE) {
+		g_object_unref (gdrive);
+		return FALSE;
+	}
+
+	memset (&data, 0, sizeof(data));
+
+	g_drive_eject (gdrive, G_MOUNT_UNMOUNT_FORCE, NULL,
+		       (GAsyncReadyCallback) nautilus_burn_drive_eject_cb,
+		       &data);
+	while (!data.called)
+		g_main_context_iteration (NULL, TRUE);
 
-        res = g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL);
-        g_free (cmd);
+	g_object_unref (gdrive);
 
-        /* delay a bit to make sure eject finishes */
-        sleep (1);
-
-        return res;
+        return data.result;
 }
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]