[Utopia] [patch] one-to-many HAL integration



Here you go Dave.  There is still the crasher bug when mounting more
than one partition on a drive which seems to be more on Nautilus's side
but I wanted to get this out before the freeze.  

-- 
John (J5) Palmieri
Associate Software Engineer
Desktop Group
Red Hat, Inc.
Blog: http://martianrock.com
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-vfs/configure.in,v
retrieving revision 1.319
diff -u -p -r1.319 configure.in
--- configure.in	16 Jul 2004 16:25:37 -0000	1.319
+++ configure.in	19 Jul 2004 23:14:52 -0000
@@ -695,8 +695,8 @@ else
 fi
 
 PKG_CHECK_MODULES(LIBGNOMEVFS, glib-2.0 >= $GLIB_REQUIRED gmodule-2.0 >= $GLIB_REQUIRED gthread-2.0 >= $GLIB_REQUIRED gconf-2.0 >= $GCONF_REQUIRED bonobo-activation-2.0 >= $BONOBO_ACTIVATION_REQUIRED libbonobo-2.0 >= $BONOBO_REQUIRED ORBit-2.0 >= $ORBIT_REQUIRED libxml-2.0 >= $XML_REQUIRED gnome-mime-data-2.0)
-LIBGNOMEVFS_CFLAGS="$LIBGNOMEVFS_CFLAGS $OPENSSL_CFLAGS $LIBGNUTLS_CFLAGS $HOWL_CFLAGS"
-LIBGNOMEVFS_LIBS="$LIBGNOMEVFS_LIBS $OPENSSL_LIBS $LIBGNUTLS_LIBS $HOWL_LIBS"
+LIBGNOMEVFS_CFLAGS="$LIBGNOMEVFS_CFLAGS $OPENSSL_CFLAGS $LIBGNUTLS_CFLAGS $HOWL_CFLAGS $HAL_CFLAGS"
+LIBGNOMEVFS_LIBS="$LIBGNOMEVFS_LIBS $OPENSSL_LIBS $LIBGNUTLS_LIBS $HOWL_LIBS $HAL_LIBS"
 AC_SUBST(LIBGNOMEVFS_CFLAGS)
 AC_SUBST(LIBGNOMEVFS_LIBS)
 
Index: libgnomevfs/gnome-vfs-hal-mounts.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-hal-mounts.c,v
retrieving revision 1.2
diff -u -p -r1.2 gnome-vfs-hal-mounts.c
--- libgnomevfs/gnome-vfs-hal-mounts.c	14 Jul 2004 08:13:16 -0000	1.2
+++ libgnomevfs/gnome-vfs-hal-mounts.c	19 Jul 2004 23:14:56 -0000
@@ -21,9 +21,9 @@
    Author: David Zeuthen <david fubar dk>
 */
 
-#ifdef USE_HAL
 
 #include <config.h>
+#ifdef USE_HAL
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -857,8 +857,8 @@ _hal_add_drive_no_partitions (
 	}
 	
 	/* see if drive was already added */
-	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (
-		volume_monitor, udi);
+	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (volume_monitor, udi);
+
 	if (drive == NULL ) {
 
 		/* nope, make one */
@@ -876,7 +876,7 @@ _hal_add_drive_no_partitions (
 		drive->priv->icon = g_strdup (icon);
 		drive->priv->display_name = _gnome_vfs_volume_monitor_uniquify_drive_name (volume_monitor, name);
 		drive->priv->is_user_visible = computer_visible;
-		drive->priv->volume = NULL;
+		drive->priv->volumes = NULL;
 		drive->priv->hal_udi = g_strdup (udi);
 		
 		_gnome_vfs_volume_monitor_connected (volume_monitor, drive);
@@ -1020,6 +1020,7 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 		computer_visible = FALSE;
 	}
 
+	
 #ifdef HAL_ONLY_SHOW_MOUNTED_VOLUMES
 	/* we should also show blank discs */
 	if (!hal_vol->is_mounted && !is_blank_disc)
@@ -1027,13 +1028,8 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 #endif
 
 	/* see if it was already added */
-	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (
-		volume_monitor, 
-#ifdef HAL_ONLY_SHOW_MOUNTED_VOLUMES
-			udi);
-#else
-			hal_drive->no_partitions ? hal_drive->udi : udi);
-#endif
+	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (volume_monitor, hal_drive->udi);
+
 	if (drive == NULL ) {
 
 		/* nope, make one */
@@ -1043,7 +1039,7 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 		device_type = _hal_get_drive_type (hal_vol, hal_drive, hal_ctx);
 
 		drive = g_object_new (GNOME_VFS_TYPE_DRIVE, NULL);
-		drive->priv->device_path = g_strdup (hal_vol->device_file);
+		drive->priv->device_path = g_strdup (hal_drive->device_file);
 
 		drive->priv->activation_uri = gnome_vfs_get_uri_from_local_path (mount_point);
 		drive->priv->is_connected = TRUE;
@@ -1051,15 +1047,9 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 		drive->priv->icon = g_strdup (icon);
 		drive->priv->display_name = _gnome_vfs_volume_monitor_uniquify_drive_name (volume_monitor, name);
 		drive->priv->is_user_visible = computer_visible;
-		drive->priv->volume = NULL;
+		drive->priv->volumes = NULL;
 
-		drive->priv->hal_udi = g_strdup (
-#ifdef HAL_ONLY_SHOW_MOUNTED_VOLUMES
-			udi
-#else
-			hal_drive->no_partitions ? hal_drive->udi : udi
-#endif
-		);
+		drive->priv->hal_udi = g_strdup (hal_drive->udi);
 		_gnome_vfs_volume_monitor_connected (volume_monitor, drive);
 		gnome_vfs_drive_unref (drive);
 	} 
@@ -1101,8 +1091,12 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 				vol->priv->filesystem_type = g_strdup (hal_vol->fstype);
 
 			} else {
+				char *uri;
+
 				vol->priv->device_path = g_strdup (hal_vol->device_file);
+
 				vol->priv->activation_uri = gnome_vfs_get_uri_from_local_path (mount_point);
+
 				vol->priv->unix_device = makedev (hal_vol->device_major, 
 								  hal_vol->device_minor);
 				vol->priv->filesystem_type = g_strdup (hal_vol->fstype);
@@ -1119,7 +1113,7 @@ _hal_add_volume (GnomeVFSVolumeMonitorDa
 			vol->priv->hal_udi = g_strdup (udi);
 			
 			vol->priv->drive = drive;
-			_gnome_vfs_drive_set_mounted_volume (drive, vol);
+			_gnome_vfs_drive_add_mounted_volume (drive, vol);
 			
 			_gnome_vfs_volume_monitor_mounted (volume_monitor, vol);			gnome_vfs_volume_unref (vol);
 
@@ -1150,8 +1144,7 @@ _hal_remove_volume (GnomeVFSVolumeMonito
 
 	volume_monitor = GNOME_VFS_VOLUME_MONITOR (volume_monitor_daemon);
 
-	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (
-		volume_monitor, udi);
+	drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (volume_monitor, udi);
 	if (drive != NULL ) {
 		_gnome_vfs_volume_monitor_disconnected (volume_monitor, drive);
 	}
@@ -1188,8 +1181,8 @@ _hal_volume_unmounted (GnomeVFSVolumeMon
 #ifdef HAL_ONLY_SHOW_MOUNTED_VOLUMES
 	{
 		GnomeVFSDrive *drive;
-		drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (
-			volume_monitor, udi);
+		drive = _gnome_vfs_volume_monitor_find_drive_by_hal_udi (volume_monitor, udi);
+
 		if (drive != NULL ) {
 			_gnome_vfs_volume_monitor_disconnected (volume_monitor, drive);
 		}
Index: libgnomevfs/gnome-vfs-volume-ops.c
===================================================================
RCS file: /cvs/gnome/gnome-vfs/libgnomevfs/gnome-vfs-volume-ops.c,v
retrieving revision 1.13
diff -u -p -r1.13 gnome-vfs-volume-ops.c
--- libgnomevfs/gnome-vfs-volume-ops.c	15 Jul 2004 13:21:15 -0000	1.13
+++ libgnomevfs/gnome-vfs-volume-ops.c	19 Jul 2004 23:14:58 -0000
@@ -28,6 +28,7 @@
 #include <pthread.h>
 #include <libbonobo.h>
 #include <gconf/gconf-client.h>
+#include <fstab.h>
 #include "gnome-vfs-i18n.h"
 #include "gnome-vfs-volume-monitor-private.h"
 #include "gnome-vfs-volume.h"
@@ -36,6 +37,10 @@
 #include "gnome-vfs-client.h"
 #include "gnome-vfs-private.h"
 
+#ifdef USE_HAL
+#include <hal/libhal.h>
+#endif /*USE_HAL*/
+
 #ifdef USE_VOLRMMOUNT
 
 static const char *volrmmount_locations [] = {
@@ -547,19 +552,90 @@ gnome_vfs_drive_mount (GnomeVFSDrive  *d
 		       GnomeVFSVolumeOpCallback  callback,
 		       gpointer                   user_data)
 {
-	char *mount_path, *device_path, *uri;
+	gboolean hal_succeded = FALSE;
 	
-	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,
-				 GNOME_VFS_DEVICE_TYPE_UNKNOWN,
-				 TRUE, FALSE,
-				 callback, user_data);
-	g_free (mount_path);
-	g_free (device_path);
+#ifdef USE_HAL
+	if (drive->priv->hal_udi != NULL) {
+		LibHalContext *hal_ctx;
+		if ((hal_ctx = 
+		     hal_initialize (NULL, FALSE)) == NULL) {
+			g_warning ("hal_initialize failed\n");
+		} else {
+			char **volume_list;
+			int num_volumes, i;
+
+			volume_list = 
+			  hal_manager_find_device_string_match (hal_ctx,
+								"info.parent",
+								drive->priv->hal_udi,
+								&num_volumes);
+
+			for (i = 0; i < num_volumes; i++) {
+				char *mount_path, *device_path, *udi;
+				gboolean is_mounted;
+				struct fstab *fst;
+
+				udi = volume_list[i];
+
+				is_mounted = 
+				  hal_device_get_property_bool (hal_ctx,
+								udi,
+								"volume.is_mounted");
+				mount_path = NULL;
+
+				device_path =
+				   hal_device_get_property_string (hal_ctx,
+								  udi, 
+								  "block.device");
+
+				
+				/* get mount point from /etc/fstab */
+				if (setfsent () == 1) {
+					fst = getfsspec (device_path);
+					if (fst != NULL )
+						mount_path = g_strdup (fst->fs_file);
+					endfsent ();
+				}
+
+				if (mount_path == NULL || device_path == NULL) {
+					continue;
+				}
+
+				if (!is_mounted)
+					mount_unmount_operation (mount_path,
+								 device_path,
+								 GNOME_VFS_DEVICE_TYPE_UNKNOWN,
+								 TRUE, FALSE,
+				 				 callback, user_data);
+
+				/*g_free (mount_path);
+				hal_free_string(device_path);*/
+			}
+
+			hal_free_string_array (volume_list);
+
+			if (num_volumes != 0)
+				hal_succeded = TRUE;
+		}	
+	}
+
+#endif /*USE_HAL*/
+
+	if (!hal_succeded) {
+		char *mount_path, *device_path, *uri;
+
+		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,
+					 GNOME_VFS_DEVICE_TYPE_UNKNOWN,
+					 TRUE, FALSE,
+				 	 callback, user_data);
+		g_free (mount_path);
+		g_free (device_path);
+	}
 }
 
 void


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