One to many (Drives to Volumes) patch take 3



Here is the third go.

-- 
John (J5) Palmieri
Associate Software Engineer
Desktop Group
Red Hat, Inc.
Blog: http://martianrock.com
? gnome-vfs.one-to-many-1.patch
? gnome-vfs.one-to-many-2.patch
? gnome-vfs.one-to-many-3.patch
? doc/tmpl/gnome-vfs-dns-sd.sgml
? doc/tmpl/gnome-vfs-volumes.sgml
? imported/Makefile
? imported/Makefile.in
? imported/neon/Makefile.in
? libgnomevfs/.gnome-vfs-volume.c.swp
? libgnomevfs/gnome-vfs-drive.c.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume-monitor-private.h.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume-ops.c.one-to-many-volumes
? libgnomevfs/gnome-vfs-volume.c.one-to-many-volumes
? libgnomevfs/s-enum-types-c
? libgnomevfs/s-enum-types-h
? modules/computer-method.c.one-to-many-volumes
? test/test-dns-sd
Index: libgnomevfs/GNOME_VFS_Daemon.idl
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/GNOME_VFS_Daemon.idl,v
retrieving revision 1.7
diff -u -p -r1.7 GNOME_VFS_Daemon.idl
--- libgnomevfs/GNOME_VFS_Daemon.idl	20 Apr 2004 13:27:46 -0000	1.7
+++ libgnomevfs/GNOME_VFS_Daemon.idl	14 Jul 2004 16:04:59 -0000
@@ -54,7 +54,7 @@ module GNOME {
 		struct Drive {
 			long id;
 			long device_type;
-			long volume;
+			sequence<long> volumes;
 			string device_path;
 			string activation_uri;
 			string display_name;
Index: libgnomevfs/gnome-vfs-drive.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-drive.c,v
retrieving revision 1.5
diff -u -p -r1.5 gnome-vfs-drive.c
--- libgnomevfs/gnome-vfs-drive.c	9 Jul 2004 08:39:16 -0000	1.5
+++ libgnomevfs/gnome-vfs-drive.c	14 Jul 2004 16:04:59 -0000
@@ -159,14 +159,20 @@ gnome_vfs_drive_finalize (GObject *objec
 {
 	GnomeVFSDrive *drive = (GnomeVFSDrive *) object;
 	GnomeVFSDrivePrivate *priv;
+	GList *current_vol;
 
 	priv = drive->priv;
 
-	if (priv->volume) {
-		_gnome_vfs_volume_unset_drive (priv->volume,
+	for (current_vol = priv->volumes; current_vol != NULL; current_vol = current_vol->next) {
+		GnomeVFSVolume *vol;
+		vol = GNOME_VFS_VOLUME (current_vol->data);
+
+		_gnome_vfs_volume_unset_drive (vol,
 					       drive);
-		gnome_vfs_volume_unref (priv->volume);
+		gnome_vfs_volume_unref (vol);
 	}
+
+	g_list_free (priv->volumes);
 	g_free (priv->device_path);
 	g_free (priv->activation_uri);
 	g_free (priv->display_name);
@@ -197,46 +203,88 @@ GnomeVFSVolume *
 gnome_vfs_drive_get_mounted_volume (GnomeVFSDrive *drive)
 {
 	GnomeVFSVolume *vol;
-	
+	GList *first_vol;
+
 	G_LOCK (drives);
-	vol = gnome_vfs_volume_ref (drive->priv->volume);
+	first_vol = g_list_first (drive->priv->volumes);
+
+	if (first_vol != NULL) {
+		vol = gnome_vfs_volume_ref (GNOME_VFS_VOLUME (first_vol->data));
+	} else {
+		vol = NULL;
+	}
+
 	G_UNLOCK (drives);
 
 	return vol;
 }
 
+void
+gnome_vfs_drive_volume_list_free (GList *volumes)
+{
+	if (volumes != NULL) {
+		g_list_foreach (volumes, 
+				(GFunc)gnome_vfs_volume_unref,
+				NULL);
+
+		g_list_free (volumes);
+	}
+}
+
+GList *
+gnome_vfs_drive_get_mounted_volumes (GnomeVFSDrive *drive)
+{
+	GList *return_list;
+	
+	G_LOCK (drives);
+	return_list = g_list_copy (drive->priv->volumes);
+	g_list_foreach (return_list, 
+			(GFunc)gnome_vfs_volume_ref,
+			NULL);
+
+	G_UNLOCK (drives);
+
+	return return_list;
+}
+
 gboolean
 gnome_vfs_drive_is_mounted (GnomeVFSDrive *drive)
 {
 	gboolean res;
 	
 	G_LOCK (drives);
-	res = drive->priv->volume != NULL;
+	res = drive->priv->volumes != NULL;
 	G_UNLOCK (drives);
 	
 	return res;
 }
 
-
 void
-_gnome_vfs_drive_unset_volume (GnomeVFSDrive      *drive,
+_gnome_vfs_drive_remove_volume (GnomeVFSDrive      *drive,
 			       GnomeVFSVolume     *volume)
 {
 	G_LOCK (drives);
-	g_assert (drive->priv->volume == volume);
-	drive->priv->volume = NULL;
+	g_assert ((g_list_find (drive->priv->volumes,
+				 volume)) != NULL);
+
+	drive->priv->volumes = g_list_remove (drive->priv->volumes,
+                                              volume);
 	G_UNLOCK (drives);
 	gnome_vfs_volume_unref (volume);
 }
 
 void
-_gnome_vfs_drive_set_mounted_volume  (GnomeVFSDrive      *drive,
+_gnome_vfs_drive_add_mounted_volume  (GnomeVFSDrive      *drive,
 				      GnomeVFSVolume     *volume)
 {
 	G_LOCK (drives);
-	g_assert (drive->priv->volume == NULL);
-	
-	drive->priv->volume = gnome_vfs_volume_ref (volume);
+
+	g_assert ((g_list_find (drive->priv->volumes,
+				 volume)) == NULL);
+
+	drive->priv->volumes = g_list_append (drive->priv->volumes, 
+					      gnome_vfs_volume_ref (volume));
+
 	G_UNLOCK (drives);
 }
 
@@ -325,17 +373,38 @@ void
 gnome_vfs_drive_to_corba (GnomeVFSDrive *drive,
 			  GNOME_VFS_Drive *corba_drive)
 {
-	GnomeVFSVolume *volume;
+	CORBA_sequence_CORBA_long corba_volumes;
 
 	corba_drive->id = drive->priv->id;
 	corba_drive->device_type = drive->priv->device_type;
-	volume = gnome_vfs_drive_get_mounted_volume (drive);
-	if (volume != NULL) {
-		corba_drive->volume = volume->priv->id;
-		gnome_vfs_volume_unref (volume);
+
+	if (drive->priv->volumes != NULL) {
+		guint i;
+		guint length;
+		GList *current_vol;
+
+		length = g_list_length (drive->priv->volumes);
+		current_vol = drive->priv->volumes;
+
+		corba_volumes._maximum = length;
+		corba_volumes._length = length;
+		corba_volumes._buffer = CORBA_sequence_CORBA_long_allocbuf (length);
+		CORBA_sequence_set_release (&corba_volumes, TRUE);
+
+		for (i = 0; i < length; i++) {
+			GnomeVFSVolume *volume;
+
+			volume = GNOME_VFS_VOLUME(current_vol->data);
+			corba_volumes._buffer[i] = volume->priv->id; 
+			current_vol = current_vol->next;
+		}
+
+		corba_drive->volumes = corba_volumes;
 	} else {
-		corba_drive->volume = 0;
+		corba_drive->volumes._maximum = 0;
+		corba_drive->volumes._length = 0;
 	}
+
 	corba_drive->device_path = corba_string_or_null_dup (drive->priv->device_path);
 	corba_drive->activation_uri = corba_string_or_null_dup (drive->priv->activation_uri);
 	corba_drive->display_name = corba_string_or_null_dup (drive->priv->display_name);
@@ -356,11 +425,16 @@ _gnome_vfs_drive_from_corba (const GNOME
 	drive->priv->id = corba_drive->id;
 	drive->priv->device_type = corba_drive->device_type;
 
-	if (corba_drive->volume != 0) {
-		drive->priv->volume = gnome_vfs_volume_monitor_get_volume_by_id (volume_monitor,
-										 corba_drive->volume);
-		if (drive->priv->volume != NULL) {
-			_gnome_vfs_volume_set_drive (drive->priv->volume, drive);
+	if (corba_drive->volumes._length != 0) {
+		int i;
+
+		for (i = 0; i < corba_drive->volumes._length; i++) {
+			GnomeVFSVolume *volume = gnome_vfs_volume_monitor_get_volume_by_id (volume_monitor,
+										 corba_drive->volumes._buffer[i]);
+			if (volume != NULL) {
+				_gnome_vfs_drive_add_mounted_volume (drive, volume);
+				_gnome_vfs_volume_set_drive (volume, drive);
+			}
 		}
 	}
 								  
Index: libgnomevfs/gnome-vfs-drive.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-drive.h,v
retrieving revision 1.6
diff -u -p -r1.6 gnome-vfs-drive.h
--- libgnomevfs/gnome-vfs-drive.h	1 Mar 2004 09:43:31 -0000	1.6
+++ libgnomevfs/gnome-vfs-drive.h	14 Jul 2004 16:05:00 -0000
@@ -60,10 +60,17 @@ GType gnome_vfs_drive_get_type (void) G_
 
 GnomeVFSDrive *gnome_vfs_drive_ref   (GnomeVFSDrive *drive);
 void           gnome_vfs_drive_unref (GnomeVFSDrive *drive);
+void           gnome_vfs_drive_volume_list_free (GList *volumes);
+
 
 gulong             gnome_vfs_drive_get_id              (GnomeVFSDrive *drive);
 GnomeVFSDeviceType gnome_vfs_drive_get_device_type     (GnomeVFSDrive *drive);
+
+#ifndef GNOME_VFS_DISABLE_DEPRECATED
 GnomeVFSVolume *   gnome_vfs_drive_get_mounted_volume  (GnomeVFSDrive *drive);
+#endif /*GNOME_VFS_DISABLE_DEPRECATED*/
+
+GList *            gnome_vfs_drive_get_mounted_volumes (GnomeVFSDrive *drive);
 char *             gnome_vfs_drive_get_device_path     (GnomeVFSDrive *drive);
 char *             gnome_vfs_drive_get_activation_uri  (GnomeVFSDrive *drive);
 char *             gnome_vfs_drive_get_display_name    (GnomeVFSDrive *drive);
@@ -86,5 +93,5 @@ void gnome_vfs_drive_eject   (GnomeVFSDr
 			      gpointer                   user_data);
 
 G_END_DECLS
-
 #endif /* GNOME_VFS_DRIVE_H */
+
Index: libgnomevfs/gnome-vfs-volume-monitor-daemon.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-daemon.c,v
retrieving revision 1.9
diff -u -p -r1.9 gnome-vfs-volume-monitor-daemon.c
--- libgnomevfs/gnome-vfs-volume-monitor-daemon.c	9 Jul 2004 08:39:16 -0000	1.9
+++ libgnomevfs/gnome-vfs-volume-monitor-daemon.c	14 Jul 2004 16:05:00 -0000
@@ -592,7 +592,7 @@ create_drive_from_mount_point (GnomeVFSV
 	drive->priv->display_name = get_drive_name (volume_monitor, drive, mount);
 	
 	drive->priv->is_user_visible = TRUE;
-	drive->priv->volume = NULL;
+	drive->priv->volumes = NULL;
 
 	uri = gnome_vfs_get_uri_from_local_path (mount->mount_path);
 	mounted_volume = _gnome_vfs_volume_monitor_find_mtab_volume_by_activation_uri (volume_monitor, uri);
@@ -600,7 +600,7 @@ create_drive_from_mount_point (GnomeVFSV
 
 	if (mounted_volume != NULL &&
 	    mounted_volume->priv->drive == NULL) {
-		drive->priv->volume = gnome_vfs_volume_ref (mounted_volume);
+		_gnome_vfs_drive_add_mounted_volume (drive, mounted_volume);
 		_gnome_vfs_volume_set_drive (mounted_volume, drive);
 	}
 
@@ -853,14 +853,14 @@ create_vol_from_mount (GnomeVFSVolumeMon
 	g_free (uri);
 
 	if (containing_drive != NULL &&
-	    containing_drive->priv->volume == NULL) {
+	    g_list_find (containing_drive->priv->volumes, vol) == NULL) {
 		/* Make sure the mounted volume for a visible drive is visible */
 		if (containing_drive->priv->is_user_visible) {
 			vol->priv->is_user_visible = 1;
 		}
 		
 		vol->priv->drive = containing_drive;
-		_gnome_vfs_drive_set_mounted_volume (containing_drive, vol);
+		_gnome_vfs_drive_add_mounted_volume (containing_drive, vol);
 	}
 
 	return vol;
Index: libgnomevfs/gnome-vfs-volume-monitor-private.h
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor-private.h,v
retrieving revision 1.5
diff -u -p -r1.5 gnome-vfs-volume-monitor-private.h
--- libgnomevfs/gnome-vfs-volume-monitor-private.h	9 Jul 2004 08:39:16 -0000	1.5
+++ libgnomevfs/gnome-vfs-volume-monitor-private.h	14 Jul 2004 16:05:00 -0000
@@ -72,7 +72,7 @@ struct _GnomeVFSVolumePrivate {
 struct _GnomeVFSDrivePrivate {
 	gulong id;
 	GnomeVFSDeviceType device_type;
-	GnomeVFSVolume *volume; /* Owning ref */
+	GList *volumes; /* GnomeVFSVolume list (Owning ref) */
 
 	/* Only for unix mounts: */
 	char *device_path;
@@ -91,9 +91,9 @@ struct _GnomeVFSDrivePrivate {
 
 void _gnome_vfs_volume_set_drive                (GnomeVFSVolume        *volume,
 						 GnomeVFSDrive         *drive);
-void _gnome_vfs_drive_set_mounted_volume        (GnomeVFSDrive         *drive,
+void _gnome_vfs_drive_add_mounted_volume        (GnomeVFSDrive         *drive,
 						 GnomeVFSVolume        *volume);
-void _gnome_vfs_drive_unset_volume              (GnomeVFSDrive         *drive,
+void _gnome_vfs_drive_remove_volume             (GnomeVFSDrive         *drive,
 						 GnomeVFSVolume        *volume);
 void _gnome_vfs_volume_unset_drive              (GnomeVFSVolume        *volume,
 						 GnomeVFSDrive         *drive);
Index: libgnomevfs/gnome-vfs-volume-monitor.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-monitor.c,v
retrieving revision 1.4
diff -u -p -r1.4 gnome-vfs-volume-monitor.c
--- libgnomevfs/gnome-vfs-volume-monitor.c	9 Jul 2004 08:39:16 -0000	1.4
+++ libgnomevfs/gnome-vfs-volume-monitor.c	14 Jul 2004 16:05:00 -0000
@@ -523,7 +523,7 @@ _gnome_vfs_volume_monitor_unmounted (Gno
 	drive = volume->priv->drive;
 	if (drive != NULL) {
 		_gnome_vfs_volume_unset_drive (volume, drive);
-		_gnome_vfs_drive_unset_volume (drive, volume);
+		_gnome_vfs_drive_remove_volume (drive, volume);
 	}
 	
 	gnome_vfs_volume_unref (volume);
@@ -549,21 +549,28 @@ void
 _gnome_vfs_volume_monitor_disconnected (GnomeVFSVolumeMonitor *volume_monitor,
 					GnomeVFSDrive         *drive)
 {
-	GnomeVFSVolume *volume;
+	GList *vol_list;
+	GList *current_vol;
 	
 	g_mutex_lock (volume_monitor->priv->mutex);
 	volume_monitor->priv->fstab_drives = g_list_remove (volume_monitor->priv->fstab_drives, drive);
 	drive->priv->is_connected = 0;
 	g_mutex_unlock (volume_monitor->priv->mutex);
 
-	volume = drive->priv->volume;
-	if (volume != NULL) {
+	vol_list = gnome_vfs_drive_get_mounted_volumes (drive);	
+
+	for (current_vol = vol_list; current_vol != NULL; current_vol = current_vol->next) {  
+		GnomeVFSVolume *volume;
+		volume = GNOME_VFS_VOLUME (vol_list->data);
+
 		_gnome_vfs_volume_unset_drive (volume, drive);
-		_gnome_vfs_drive_unset_volume (drive, volume);
+		_gnome_vfs_drive_remove_volume (drive, volume);
 	}
-	
+
+	g_list_free (vol_list);
+
 	g_signal_emit (volume_monitor, volume_monitor_signals[DRIVE_DISCONNECTED], 0, drive);
-	
+
 	gnome_vfs_drive_unref (drive);
 }
 
Index: libgnomevfs/gnome-vfs-volume-ops.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-ops.c,v
retrieving revision 1.11
diff -u -p -r1.11 gnome-vfs-volume-ops.c
--- libgnomevfs/gnome-vfs-volume-ops.c	3 Jun 2004 13:49:26 -0000	1.11
+++ libgnomevfs/gnome-vfs-volume-ops.c	14 Jul 2004 16:05:00 -0000
@@ -566,28 +566,21 @@ gnome_vfs_drive_unmount (GnomeVFSDrive  
 			 GnomeVFSVolumeOpCallback  callback,
 			 gpointer                   user_data)
 {
-	char *mount_path, *device_path, *uri;
-	GnomeVFSVolume *volume;
+	GList *vol_list;
+	GList *current_vol;
 
+	vol_list = gnome_vfs_drive_get_mounted_volumes (drive);
 
-	volume = gnome_vfs_drive_get_mounted_volume (drive);
-
-	if (volume != NULL) {
-		emit_pre_unmount (volume);
+	for (current_vol = vol_list; current_vol != NULL; current_vol = current_vol->next) {
+		GnomeVFSVolume *vol;
+		vol = GNOME_VFS_VOLUME (current_vol->data);
+
+		gnome_vfs_volume_unmount (vol,
+					  callback,
+					  user_data);
 	}
 
-	uri = gnome_vfs_drive_get_activation_uri (drive);
-	mount_path = gnome_vfs_get_local_path_from_uri (uri);
-	g_free (uri);
-	device_path = gnome_vfs_drive_get_device_path (drive);
-	mount_unmount_operation (mount_path,
-				 device_path,
-				 (volume == NULL) ? GNOME_VFS_DEVICE_TYPE_UNKNOWN:gnome_vfs_volume_get_device_type (volume),
-				 FALSE, FALSE,
-				 callback, user_data);
-	g_free (mount_path);
-	g_free (device_path);
-	gnome_vfs_volume_unref (volume);
+	gnome_vfs_drive_volume_list_free (vol_list);
 }
 
 void
@@ -595,28 +588,31 @@ gnome_vfs_drive_eject (GnomeVFSDrive  *d
 		       GnomeVFSVolumeOpCallback  callback,
 		       gpointer                   user_data)
 {
-	char *mount_path, *device_path, *uri;
-	GnomeVFSVolume *volume;
+	GList *vol_list;
+	GList * current_vol;
 
+	vol_list = gnome_vfs_drive_get_mounted_volumes (drive);
 
-	volume = gnome_vfs_drive_get_mounted_volume (drive);
+	for (current_vol = vol_list; current_vol != NULL; current_vol = current_vol->next) {
+		GnomeVFSVolume *vol;
+		vol = GNOME_VFS_VOLUME (current_vol->data);
+
+		/* Check to see if this is the last volume */
+		/* If not simply unmount it */
+		/* If so the eject the media along with the unmount */
+		if (current_vol != NULL) { 
+			gnome_vfs_volume_unmount (vol,
+						  callback,
+						  user_data);
+		} else { 
+			gnome_vfs_volume_eject (vol,
+						callback,
+						user_data);
+		}
 
-	if (volume != NULL) {
-		emit_pre_unmount (volume);
 	}
 
-	uri = gnome_vfs_drive_get_activation_uri (drive);
-	mount_path = gnome_vfs_get_local_path_from_uri (uri);
-	g_free (uri);
-	device_path = gnome_vfs_drive_get_device_path (drive);
-	mount_unmount_operation (mount_path,
-				 device_path,
-				 (volume == NULL) ? GNOME_VFS_DEVICE_TYPE_UNKNOWN:gnome_vfs_volume_get_device_type (volume),
-				 FALSE, TRUE,
-				 callback, user_data);
-	g_free (mount_path);
-	g_free (device_path);
-	gnome_vfs_volume_unref (volume);
+	gnome_vfs_drive_volume_list_free (vol_list);
 }
 
 
Index: libgnomevfs/gnome-vfs-volume.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume.c,v
retrieving revision 1.5
diff -u -p -r1.5 gnome-vfs-volume.c
--- libgnomevfs/gnome-vfs-volume.c	9 Jul 2004 08:39:16 -0000	1.5
+++ libgnomevfs/gnome-vfs-volume.c	14 Jul 2004 16:05:00 -0000
@@ -382,7 +382,7 @@ _gnome_vfs_volume_from_corba (const GNOM
 		volume->priv->drive = gnome_vfs_volume_monitor_get_drive_by_id (volume_monitor,
 										corba_volume->drive);
 		if (volume->priv->drive != NULL) {
-			_gnome_vfs_drive_set_mounted_volume (volume->priv->drive, volume);
+			_gnome_vfs_drive_add_mounted_volume (volume->priv->drive, volume);
 			/* The drive reference is weak */
 			gnome_vfs_drive_unref (volume->priv->drive);
 		}
Index: modules/computer-method.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/modules/computer-method.c,v
retrieving revision 1.6
diff -u -p -r1.6 computer-method.c
--- modules/computer-method.c	8 Jun 2004 17:06:53 -0000	1.6
+++ modules/computer-method.c	14 Jul 2004 16:05:00 -0000
@@ -489,10 +489,13 @@ get_data_for_drive (GnomeVFSDrive *drive
 	char *icon;
 	char *data;
 	char *tmp1, *tmp2;
-	GnomeVFSVolume *volume;
+	GList *volume_list;
+
+	volume_list = gnome_vfs_drive_get_mounted_volumes (drive);
+	if (volume_list != NULL) {
+		GnomeVFSVolume *volume;
+		volume = GNOME_VFS_VOLUME (volume_list->data);
 
-	volume = gnome_vfs_drive_get_mounted_volume (drive);
-	if (volume != NULL) {
 		uri = gnome_vfs_volume_get_activation_uri (volume);
 		tmp1 = gnome_vfs_drive_get_display_name (drive);
 		tmp2 = gnome_vfs_volume_get_display_name (volume);


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