Exemple #1
0
static void
rb_removable_media_manager_cmd_eject_medium (GtkAction *action, RBRemovableMediaManager *mgr)
{
	RBRemovableMediaManagerPrivate *priv = GET_PRIVATE (mgr);
	RBRemovableMediaSource *source = RB_REMOVABLE_MEDIA_SOURCE (priv->selected_source);
	GVolume *volume;
	GMount *mount;

	/* try ejecting based on volume first, then based on the mount,
	 * and finally try unmounting.
	 */

	g_object_get (source, "volume", &volume, NULL);
	if (volume != NULL) {
		if (g_volume_can_eject (volume)) {
			rb_debug ("ejecting volume");
			g_volume_eject (volume,
					G_MOUNT_UNMOUNT_NONE,
					NULL,
					(GAsyncReadyCallback) rb_removable_media_manager_eject_cb,
					g_object_ref (mgr));
		} else {
			/* this should never happen; the eject command will be
			 * insensitive if the selected source cannot be ejected.
			 */
			rb_debug ("don't know what to do with this volume");
		}
		g_object_unref (volume);
		return;
	}

	g_object_get (source, "mount", &mount, NULL);
	if (mount != NULL) {
		if (g_mount_can_eject (mount)) {
			rb_debug ("ejecting mount");
			g_mount_eject (mount,
				       G_MOUNT_UNMOUNT_NONE,
				       NULL,
				       (GAsyncReadyCallback) rb_removable_media_manager_eject_cb,
				       g_object_ref (mgr));
		} else if (g_mount_can_unmount (mount)) {
			rb_debug ("unmounting mount");
			g_mount_unmount (mount,
					 G_MOUNT_UNMOUNT_NONE,
					 NULL,
					 (GAsyncReadyCallback) rb_removable_media_manager_unmount_cb,
					 g_object_ref (mgr));
		} else {
			/* this should never happen; the eject command will be
			 * insensitive if the selected source cannot be ejected.
			 */
			rb_debug ("don't know what to do with this mount");
		}
		g_object_unref (mount);
	}
}
void vfs_backend_unmount (const gchar *cURI, int iVolumeID, CairoDockFMMountCallback pCallback, Icon *icon, CairoContainer *pContainer)
{
	g_return_if_fail (cURI != NULL);
	cd_message ("%s (%s)", __func__, cURI);
	
	gchar *cTargetURI = NULL;
	GMount *pMount = _cd_find_mount_from_uri (cURI, &cTargetURI);
	if (pMount == NULL || ! G_IS_MOUNT (pMount))
	{
		return ;
	}
	
	if ( ! g_mount_can_unmount (pMount))
		return ;
	
	gboolean bCanEject = g_mount_can_eject (pMount);
	gboolean bCanUnmount = g_mount_can_unmount (pMount);
	cd_message ("eject:%d / unmount:%d\n", bCanEject, bCanUnmount);
	if (! bCanEject && ! bCanUnmount)
		return ;
	
	gpointer *data2 = g_new (gpointer, 5);
	data2[0] = pCallback;
	data2[1] = GINT_TO_POINTER (bCanEject ? 2 : 0);
	data2[2] = g_mount_get_name (pMount);
	data2[3] = icon;
	data2[4] = pContainer;
	if (bCanEject)
		g_mount_eject (pMount,
			G_MOUNT_UNMOUNT_NONE,
			NULL,
			(GAsyncReadyCallback) _vfs_backend_mount_callback,
			data2);
	else
		g_mount_unmount (pMount,
			G_MOUNT_UNMOUNT_NONE ,
			NULL,
			(GAsyncReadyCallback) _vfs_backend_mount_callback,
			data2);
}