Re: [Utopia] gnome-mount nicknames




... and now the correct patch. Sorry.

-Artem.

Index: src/gnome-mount.c
===================================================================
RCS file: /cvs/gnome/gnome-mount/src/gnome-mount.c,v
retrieving revision 1.6
diff -u -p -r1.6 gnome-mount.c
--- src/gnome-mount.c	8 Feb 2006 18:04:29 -0000	1.6
+++ src/gnome-mount.c	9 Feb 2006 02:14:27 -0000
@@ -632,6 +632,66 @@ mount_option_flags (char **strlist)
 	return flags;
 }
 
+static LibHalVolume *
+volume_findby (LibHalContext *hal_ctx, const char *property, const char *value)
+{
+	int i;
+	char **hal_udis;
+	int num_hal_udis;
+	LibHalVolume *result = NULL;
+	char *found_udi = NULL;
+	DBusError error;
+
+	dbus_error_init (&error);
+	if ((hal_udis = libhal_manager_find_device_string_match (hal_ctx, property, 
+								 value, &num_hal_udis, &error)) == NULL)
+		goto out;
+
+	for (i = 0; i < num_hal_udis; i++) {
+		char *udi;
+		udi = hal_udis[i];
+		if (libhal_device_query_capability (hal_ctx, udi, "volume", &error)) {
+			found_udi = strdup (udi);
+			break;
+		}
+	}
+
+	libhal_free_string_array (hal_udis);
+
+	if (found_udi != NULL)
+		result = libhal_volume_from_udi (hal_ctx, found_udi);
+
+	free (found_udi);
+out:
+	return result;
+}
+
+static LibHalVolume *
+volume_from_nickname (LibHalContext *hal_ctx, const char *name)
+{
+	int name_len;
+	char *path;
+	LibHalVolume *result = NULL;
+
+	if (name[0] == '/') {
+		result = volume_findby (hal_ctx, "volume.mount_point", name);
+	}
+
+	name_len = strlen (name);
+	if ((result == NULL) && ((path = calloc (1, sizeof ("/media/") + name_len + 1)) != NULL)) {
+		strcat(path, "/media/");
+		strcat(path, name);
+		result = volume_findby (hal_ctx, "volume.mount_point", path);
+		free(path);
+	}
+
+	if (result == NULL) {
+		result = volume_findby (hal_ctx, "volume.label", name);
+	}
+
+	return (result);
+}
+
 
 int
 main (int argc, char *argv[])
@@ -646,6 +706,7 @@ main (int argc, char *argv[])
 	static gboolean opt_eject = FALSE;
 	static gchar *opt_hal_udi = NULL;
 	static gchar *opt_device_file = NULL;
+	static gchar *opt_nickname = NULL;
         GError *error = NULL;
         GOptionContext *context = NULL;
         static GOptionEntry entries[] =
@@ -657,6 +718,7 @@ main (int argc, char *argv[])
                         { "eject", 'e', 0, G_OPTION_ARG_NONE, &opt_eject, "Eject rather than mount", NULL},
                         { "hal-udi", 'h', 0, G_OPTION_ARG_STRING, &opt_hal_udi, "Mount by HAL UDI", NULL},
                         { "device", 'd', 0, G_OPTION_ARG_STRING, &opt_device_file, "Mount by device file", NULL},
+                        { "pseudonym", 'p', 0, G_OPTION_ARG_STRING, &opt_nickname, "Mount by one of device's nicknames: mountpoint, label, with or without directory prefix", NULL},
                         { NULL, 0, 0, 0, NULL, NULL, NULL }
                 };
 
@@ -729,6 +791,8 @@ main (int argc, char *argv[])
 		volume = libhal_volume_from_udi (hal_ctx, opt_hal_udi);
 	} else if (opt_device_file != NULL) {
 		volume = libhal_volume_from_device_file (hal_ctx, opt_device_file);
+	} else if (opt_nickname != NULL) {
+		volume = volume_from_nickname (hal_ctx, opt_nickname);
 	} else {
 		g_message (_("Use --hal-udi or --device to specify volume"));
 		goto out;
@@ -801,7 +865,7 @@ main (int argc, char *argv[])
 			GSList *list, *l, *n;
 			GPtrArray *options;
 			guint32 user_opts;
-			guint32 opts;
+			guint32 opts = 0;
 			char *key;
 			
 			udi = libhal_volume_get_udi (volume);



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