summaryrefslogtreecommitdiff
path: root/recipes/nautilus/nautilus-cd-burner/eject1.diff
blob: 9aded68dd8d401481956bf98e1457d0deb48c7b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
From 555f4ef2a64a79d7bb63421859eb8a554cfe104d Mon Sep 17 00:00:00 2001
From: Bastien Nocera <hadess@hadess.net>
Date: Wed, 17 Dec 2008 11:49:06 +0000
Subject: Eject using GIO instead of calling out to eject, or gnome-mount (Closes:

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)


svn path=/trunk/; revision=2270
---
diff --git a/src/nautilus-burn-drive.c b/src/nautilus-burn-drive.c
index b32078b..2322937 100644
--- a/src/nautilus-burn-drive.c
+++ b/src/nautilus-burn-drive.c
@@ -781,6 +781,48 @@ nautilus_burn_drive_is_mounted (NautilusBurnDrive *drive)
         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 @@ nautilus_burn_drive_is_mounted (NautilusBurnDrive *drive)
 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 @@ nautilus_burn_drive_eject (NautilusBurnDrive *drive)
                 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;
+	}
 
-        res = g_spawn_command_line_sync (cmd, NULL, NULL, NULL, NULL);
-        g_free (cmd);
+	memset (&data, 0, sizeof(data));
 
-        /* delay a bit to make sure eject finishes */
-        sleep (1);
+	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);
 
-        return res;
+	g_object_unref (gdrive);
+
+        return data.result;
 }
 
 /**
--
cgit v0.8.3.1