gnome-mount r151 - in trunk: . src



Author: davidz
Date: Mon Feb 25 22:18:56 2008
New Revision: 151
URL: http://svn.gnome.org/viewvc/gnome-mount?rev=151&view=rev

Log:
2008-02-25  David Zeuthen  <davidz redhat com>

        * configure.in: Bump version to 0.8. Get rid of libgnomeui
        dependency. Require recent glib and nautilus versions if building
        the Nautilus extension.

        * src/Makefile.am:
        * src/gnome-mount-properties-view.[ch]:
        * src/gnome-mount-properties.c: Port to new nautilus extensions
        API. Avoid debug spew.

        * src/gnome-mount.c: Fix crasher when unreffing a toplevel; use
        gtk_widget_destroy() instead. Avoid lots of debug spew.



Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/src/Makefile.am
   trunk/src/gnome-mount-properties-view.c
   trunk/src/gnome-mount-properties-view.h
   trunk/src/gnome-mount-properties.c
   trunk/src/gnome-mount.c

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Mon Feb 25 22:18:56 2008
@@ -1,6 +1,6 @@
 AC_PREREQ(2.52)
 
-AC_INIT(gnome-mount, 0.7)
+AC_INIT(gnome-mount, 0.8)
 AC_CONFIG_SRCDIR(src)
 AM_INIT_AUTOMAKE(AC_PACKAGE_NAME, AC_PACKAGE_VERSION)
 AM_CONFIG_HEADER(config.h)
@@ -83,19 +83,19 @@
 fi
 AM_CONDITIONAL(ENABLE_NAUTILUS_EXTENSION, test "x$enable_nautilus_extension" = "xyes")
 
+GLIB_REQUIRED=2.15.0
+NAUTILUS_REQUIRED=2.21.2
+
 PKG_CHECK_MODULES(GNOME_MOUNT, gconf-2.0 gnome-keyring-1 >= 0.4 dbus-glib-1 >= 0.31 hal-storage >= 0.5.8.1 gtk+-2.0 >= 2.8.0)
 AC_SUBST(GNOME_MOUNT_CFLAGS)
 AC_SUBST(GNOME_MOUNT_LIBS)
 
 if test "x$enable_nautilus_extension" = "xyes"; then
-   PKG_CHECK_MODULES(GNOME_MOUNT_PROPERTIES, libgnomeui-2.0 >= 2.1.5 libglade-2.0 hal-storage >= 0.5.8.1 dbus-1 >= 0.60 dbus-glib-1 >= 0.60  gtk+-2.0 >= 2.8.0)
+   PKG_CHECK_MODULES(GNOME_MOUNT_PROPERTIES, libglade-2.0 hal-storage >= 0.5.8.1 dbus-1 >= 0.60 dbus-glib-1 >= 0.60 gtk+-2.0 >= 2.8.0 glib-2.0 >= $GLIB_REQUIRED)
    AC_SUBST(GNOME_MOUNT_PROPERTIES_CFLAGS)
    AC_SUBST(GNOME_MOUNT_PROPERTIES_LIBS)
 
-   NAUTILUS_REQUIRED=2.5.0
-   EEL_REQUIRED=2.5.0
-
-   PKG_CHECK_MODULES(NAUTILUS, libnautilus-extension >= $NAUTILUS_REQUIRED eel-2.0 >= $EEL_REQUIRED)
+   PKG_CHECK_MODULES(NAUTILUS, libnautilus-extension >= $NAUTILUS_REQUIRED)
    AC_SUBST(NAUTILUS_CFLAGS)
    AC_SUBST(NAUTILUS_LIBS)
 fi

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Mon Feb 25 22:18:56 2008
@@ -11,6 +11,7 @@
 	-DGLADEDIR=\"$(pkgdatadir)\"		   \
 	-DDATADIR=\"$(datadir)\"
 
+
 gladedir = $(pkgdatadir)
 glade_DATA = 				\
 	gnome-mount-properties.glade
@@ -26,12 +27,13 @@
 	gnome-mount-properties-view.c		gnome-mount-properties-view.h
 
 if ENABLE_NAUTILUS_EXTENSION
-nautilus_extensiondir=$(libdir)/nautilus/extensions-1.0
+nautilus_extensiondir=$(libdir)/nautilus/extensions-2.0
 
 nautilus_extension_LTLIBRARIES=libgnome-mount.la
 
 libgnome_mount_la_LDFLAGS = -module -avoid-version
 libgnome_mount_la_LIBADD  = $(NAUTILUS_LIBS) $(GNOME_MOUNT_PROPERTIES_LIBS)
+libgnome_mount_la_CFLAGS = -DG_LOG_DOMAIN=\"nautilus-extension-gnome-mount\"
 endif
 
 EXTRA_DIST = $(glade_DATA)

Modified: trunk/src/gnome-mount-properties-view.c
==============================================================================
--- trunk/src/gnome-mount-properties-view.c	(original)
+++ trunk/src/gnome-mount-properties-view.c	Mon Feb 25 22:18:56 2008
@@ -34,7 +34,6 @@
 #include <sys/time.h>
 #include <string.h>
 #include <gconf/gconf-client.h>
-#include <libgnomevfs/gnome-vfs-utils.h>
 
 #ifdef __FreeBSD__
 #include <fstab.h>
@@ -92,7 +91,7 @@
 G_DEFINE_TYPE (GnomeMountPropertiesView, gm_properties_view, GTK_TYPE_VBOX)
 
 static void
-gm_properties_view_dispose (GObject *object)
+gm_properties_view_finalize (GObject *object)
 {
 	GnomeMountPropertiesView *properties = GM_PROPERTIES_VIEW (object);
 
@@ -105,6 +104,8 @@
 		g_free (properties->keydir);
 		properties->keydir = NULL;
 	}
+
+        G_OBJECT_CLASS (gm_properties_view_parent_class)->finalize (object);
 }
 
 static void
@@ -112,7 +113,7 @@
 {
 	GObjectClass *g_object_class = G_OBJECT_CLASS (properties_class);
 
-	g_object_class->dispose = gm_properties_view_dispose;
+	g_object_class->finalize = gm_properties_view_finalize;
 }
 
 static char *
@@ -552,7 +553,7 @@
 			    glade_xml_get_widget (properties->xml, "gm_page_volume_root"),
 			    TRUE, TRUE, 0);
 
-	fssize = gnome_vfs_format_file_size_for_display (libhal_volume_get_size (vol));
+	fssize = g_format_size_for_display (libhal_volume_get_size (vol));
 	if (libhal_volume_get_fstype (vol) != NULL && libhal_volume_get_fsversion (vol) != NULL) {
 		fstype = g_strdup_printf ("%s (%s)", 
 					  libhal_volume_get_fstype (vol),
@@ -790,18 +791,18 @@
 				"volume_fstype_entry",
 				"volume_expander");
 
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "volume_mount_point_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (mount_point_entry_changed), 
-			    properties);
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "volume_fstype_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (fstype_entry_changed), 
-			    properties);
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "volume_mount_options_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (mount_options_entry_changed), 
-			    properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "volume_mount_point_entry"), 
+                          "changed",
+                          G_CALLBACK (mount_point_entry_changed), 
+                          properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "volume_fstype_entry"), 
+                          "changed",
+                          G_CALLBACK (fstype_entry_changed), 
+                          properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "volume_mount_options_entry"), 
+                          "changed",
+                          G_CALLBACK (mount_options_entry_changed), 
+                          properties);
 
 	g_free (fssize);
 	g_free (fstype);
@@ -1038,18 +1039,18 @@
 				"drive_fstype_entry",
 				"drive_expander");
 
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "drive_mount_point_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (mount_point_entry_changed), 
-			    properties);
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "drive_fstype_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (fstype_entry_changed), 
-			    properties);
-	gtk_signal_connect (glade_xml_get_widget (properties->xml, "drive_mount_options_entry"), 
-			    "changed",
-			    GTK_SIGNAL_FUNC (mount_options_entry_changed), 
-			    properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "drive_mount_point_entry"), 
+                          "changed",
+                          G_CALLBACK (mount_point_entry_changed), 
+                          properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "drive_fstype_entry"), 
+                          "changed",
+                          G_CALLBACK (fstype_entry_changed), 
+                          properties);
+	g_signal_connect (glade_xml_get_widget (properties->xml, "drive_mount_options_entry"), 
+                          "changed",
+                          G_CALLBACK (mount_options_entry_changed), 
+                          properties);
 	
 	g_free (vendor);
 	g_free (model);

Modified: trunk/src/gnome-mount-properties-view.h
==============================================================================
--- trunk/src/gnome-mount-properties-view.h	(original)
+++ trunk/src/gnome-mount-properties-view.h	Mon Feb 25 22:18:56 2008
@@ -25,7 +25,6 @@
 
 #include <libhal.h>
 #include <gtk/gtkwidget.h>
-#include <libgnomevfs/gnome-vfs-volume.h>
 
 G_BEGIN_DECLS
 

Modified: trunk/src/gnome-mount-properties.c
==============================================================================
--- trunk/src/gnome-mount-properties.c	(original)
+++ trunk/src/gnome-mount-properties.c	Mon Feb 25 22:18:56 2008
@@ -27,6 +27,7 @@
 #include <libhal.h>
 #include <libhal-storage.h>
 
+#include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
 #include <libnautilus-extension/nautilus-extension-types.h>
@@ -42,153 +43,6 @@
 static void property_page_provider_iface_init (NautilusPropertyPageProviderIface *iface);
 static GList *gmp_properties_get_pages (NautilusPropertyPageProvider *provider, GList *files);
 
-/* Implementation of the NautilusInfoProvider interface */
-
-/* nautilus_info_provider_update_file_info 
- * This function is called by Nautilus when it wants the extension to 
- * fill in data about the file.  It passes a NautilusFileInfo object,
- * which the extension can use to read data from the file, and which
- * the extension should add data to.
- *
- * If the data can be added immediately (without doing blocking IO), 
- * the extension can do so, and return NAUTILUS_OPERATION_COMPLETE.  
- * In this case the 'update_complete' and 'handle' parameters can be 
- * ignored.
- * 
- * If waiting for the deata would block the UI, the extension should
- * perform the task asynchronously, and return 
- * NAUTILUS_OPERATION_IN_PROGRESS.  The function must also set the 
- * 'handle' pointer to a value unique to the object, and invoke the
- * 'update_complete' closure when the update is done.
- * 
- * If the extension encounters an error, it should return 
- * NAUTILUS_OPERATION_FAILED.
- */
-static NautilusOperationResult
-update_file_info (NautilusInfoProvider *provider,
-		  NautilusFileInfo *file,
-		  GClosure *update_complete,
-		  NautilusOperationHandle **handle)
-{
-	char *volume_hal_udi = NULL;
-	char *drive_hal_udi = NULL;
-	GnomeVFSDrive *drive = NULL;
-	GnomeVFSVolume *volume = NULL;
-	NautilusOperationResult result;
-
-
-	result = NAUTILUS_OPERATION_COMPLETE;
-
-
-	drive = nautilus_file_info_get_drive (file);
-	if (drive != NULL)
-		gnome_vfs_drive_ref (drive);
-
-	volume = nautilus_file_info_get_volume (file);
-	if (volume != NULL) {
-		gnome_vfs_volume_ref (volume);
-	} else {
-		if (drive != NULL)
-			volume = gnome_vfs_drive_get_mounted_volume (drive);
-	}
-
-	if (drive == NULL && volume != NULL)
-		drive = gnome_vfs_volume_get_drive (volume);
-
-	if (drive != NULL)
-		drive_hal_udi = gnome_vfs_drive_get_hal_udi (drive);
-	if (volume != NULL)
-		volume_hal_udi = gnome_vfs_volume_get_hal_udi (volume);
-
-	if (volume != NULL && volume_hal_udi != NULL) {
-		char *backing_udi;
-		DBusError error;
-
-		dbus_error_init (&error);
-		backing_udi = libhal_device_get_property_string (
-			hal_ctx,
-			volume_hal_udi,
-			"volume.crypto_luks.clear.backing_volume",
-			&error);
-		if (backing_udi != NULL) {
-			nautilus_file_info_add_emblem (file, "lock");
-			g_message ("setting lock for %x", file);
-			libhal_free_string (backing_udi);
-		}
-
-	}
-
-	if (drive_hal_udi != NULL)
-		g_free (drive_hal_udi);
-	if (volume_hal_udi != NULL)
-		g_free (volume_hal_udi);
-	if (drive != NULL)
-		gnome_vfs_drive_unref (drive);
-	if (volume != NULL)
-		gnome_vfs_volume_unref (volume);
-
-	return result;
-
-#if 0
-	NautilusCvsDirectory *directory;
-	NautilusOperationResult result;
-	
-	directory = get_cvs_directory (file);
-
-	/* Keep the directory alive for as long as the file is around */
-	watch_directory (directory, file);
-
-	if (nautilus_cvs_directory_is_ready (directory)) {
-		update_file_info (file, directory);
-		
-		result = NAUTILUS_OPERATION_COMPLETE;
-	} else {
-		NautilusCvsHandle *cvs_handle;
-		
-		cvs_handle = g_new0 (NautilusCvsHandle, 1);
-
-		cvs_handle->provider = provider;
-		cvs_handle->file = g_object_ref (file);
-
-		/* We need to keep the closure around until we call it
-		 * back. */
-		cvs_handle->update_complete = g_closure_ref (update_complete);
-
-		nautilus_cvs_directory_call_when_ready 
-			(directory, directory_ready_callback, cvs_handle);
-
-		*handle = (NautilusOperationHandle*)cvs_handle;
-
-		result = NAUTILUS_OPERATION_IN_PROGRESS;
-	}
-
-	g_object_unref (directory);
-
-	return result;
-#endif
-}
-
-static void
-cancel_update (NautilusInfoProvider *provider,
-	       NautilusOperationHandle *handle)
-{
-#if 0
-	NautilusCvsHandle *cvs_handle;
-	
-	cvs_handle = (NautilusCvsHandle*)handle;
-	
-	cvs_handle->cancelled = TRUE;
-#endif
-}
-
-static void 
-info_provider_iface_init (NautilusInfoProviderIface *iface)
-{
-	iface->update_file_info = update_file_info;
-	iface->cancel_update = cancel_update;
-}
-
-
 static void
 gnome_mount_properties_plugin_register_type (GTypeModule *module)
 {
@@ -211,12 +65,6 @@
 		NULL
 	};
 
-	static const GInterfaceInfo info_provider_iface_info = {
-		(GInterfaceInitFunc) info_provider_iface_init,
-		NULL,
-		NULL
-	};
-
 	gmp_type = g_type_module_register_type (module, G_TYPE_OBJECT,
 			"GnomeMountPropertiesPlugin",
 			&info, 0);
@@ -225,11 +73,6 @@
 				     gmp_type,
 				     NAUTILUS_TYPE_PROPERTY_PAGE_PROVIDER,
 				     &property_page_provider_iface_info);
-
-	g_type_module_add_interface (module,
-				     gmp_type,
-				     NAUTILUS_TYPE_INFO_PROVIDER,
-				     &info_provider_iface_info);
 }
 
 static void
@@ -248,55 +91,82 @@
 	GList *pages = NULL;
 	char *uri = NULL;
 	NautilusFileInfo *file;
-	GnomeVFSDrive *drive = NULL;
-	GnomeVFSVolume *volume = NULL;
 	GtkWidget *page;
 	GtkWidget *label;
 	NautilusPropertyPage *property_page;
 	char *volume_hal_udi = NULL;
 	char *drive_hal_udi = NULL;
 	gboolean added_volume;
+        GFile *location;
 
 	/* only add properties page if a single file is selected */
 	if (files == NULL || files->next != NULL)
 		goto out;
 	file = files->data;
 
-	/*g_message ("name = '%s'", nautilus_file_info_get_name (file));*/
-
-	drive = nautilus_file_info_get_drive (file);
-	if (drive != NULL)
-		gnome_vfs_drive_ref (drive);
-
-	volume = nautilus_file_info_get_volume (file);
-	if (volume != NULL) {
-		gnome_vfs_volume_ref (volume);
-	} else {
-		if (drive != NULL)
-			volume = gnome_vfs_drive_get_mounted_volume (drive);
-	}
-
-	if (drive == NULL && volume != NULL)
-		drive = gnome_vfs_volume_get_drive (volume);
-
-	if (drive != NULL)
-		drive_hal_udi = gnome_vfs_drive_get_hal_udi (drive);
-	if (volume != NULL)
-		volume_hal_udi = gnome_vfs_volume_get_hal_udi (volume);
+        /* TODO: There is currently no way to get the GVolume or
+         * GDrive for resp. unmounted volumes and drives without media
+         * (in computer:///) for a NautilusFileInfo object.
+         *
+         * http://bugzilla.gnome.org/show_bug.cgi?id=518700
+         */
+
+        location = nautilus_file_info_get_location (file);
+        drive_hal_udi = NULL; volume_hal_udi = NULL;
+
+        if (nautilus_file_info_get_file_type (file) == G_FILE_TYPE_SHORTCUT ||
+            nautilus_file_info_get_file_type (file) == G_FILE_TYPE_MOUNTABLE) {
+                char *activation_uri;
+                activation_uri = nautilus_file_info_get_activation_uri (file);
+                if (activation_uri != NULL) {
+                        GFile *activation_file;
+                        GVolumeMonitor *volume_monitor;
+
+                        activation_file = g_file_new_for_uri (activation_uri);
+                        volume_monitor = g_volume_monitor_get ();
+                        if (volume_monitor != NULL) {
+                                GList *mounts, *l;
+                                mounts = g_volume_monitor_get_mounts (volume_monitor);
+                                for (l = mounts; l != NULL; l = l->next) {
+                                        GMount *mount = l->data;
+                                        GVolume *volume;
+                                        GFile *mount_root;
+
+                                        mount_root = g_mount_get_root (mount);
+                                        if (g_file_equal (mount_root, activation_file)) {
+                                                volume = g_mount_get_volume (mount);
+                                                if (volume != NULL) {
+                                                        volume_hal_udi = g_volume_get_identifier (volume, 
+                                                                                                  G_VOLUME_IDENTIFIER_KIND_HAL_UDI);
+                                                        g_object_unref (volume);
+                                                }
+                                                g_object_unref (mount);
+                                        }
+                                        g_object_unref (mount_root);
+                                }
+                                if (mounts != NULL)
+                                        g_list_free (mounts);
+                        }
+                        g_object_unref (volume_monitor);
+                        g_object_unref (activation_file);
+                        
+                }
+                g_free (activation_uri);
+        }
+        g_object_unref (location);
 
 	added_volume = FALSE;
-	if (volume != NULL && volume_hal_udi != NULL) {
+	if (volume_hal_udi != NULL) {
 		char *udi;
 		LibHalVolume *vol;
-		udi = gnome_vfs_volume_get_hal_udi (volume);
-		vol = libhal_volume_from_udi (hal_ctx, udi);
-		g_free (udi);
+		vol = libhal_volume_from_udi (hal_ctx, volume_hal_udi);
 		if (vol != NULL) {
-			g_debug ("volume=%p vol=%p, vol->udi=%s", 
-				 volume, vol, vol != NULL ? libhal_volume_get_udi (vol) : "none");
+                        if (drive_hal_udi == NULL)
+                                drive_hal_udi = g_strdup (libhal_volume_get_storage_device_udi (vol));
+
 			page = gm_properties_view_new ();
 			gm_properties_view_set_info_volume (GM_PROPERTIES_VIEW (page), vol, hal_ctx);
-			label = gtk_label_new ("Volume");
+			label = gtk_label_new (_("Volume"));
 			gtk_widget_show (page);
 			property_page = nautilus_property_page_new ("gnome-mount-volume-properties", label, page);
 			pages = g_list_prepend (pages, property_page);
@@ -305,16 +175,15 @@
 		}
 	}
 
-	if (drive != NULL && drive_hal_udi) {
+	if (drive_hal_udi != NULL) {
 		char *udi;
-		char *udi2;
+		const char *udi2;
 		LibHalDrive *drv;
 
-		udi = gnome_vfs_drive_get_hal_udi (drive);
-		drv = libhal_drive_from_udi (hal_ctx, udi);
-		if (drv == NULL) {
+		drv = libhal_drive_from_udi (hal_ctx, drive_hal_udi);
+		if (drv == NULL && volume_hal_udi != NULL) {
 			LibHalVolume *vol;
-			vol = libhal_volume_from_udi (hal_ctx, udi);
+			vol = libhal_volume_from_udi (hal_ctx, volume_hal_udi);
 			if (vol != NULL) {
 				udi2 = libhal_volume_get_storage_device_udi (vol);
 				drv = libhal_drive_from_udi (hal_ctx, udi2);
@@ -323,11 +192,9 @@
 				 * show volume dialog anyway then!
 				 */
 				if (!added_volume) {
-					g_debug ("volume=%p vol=%p, vol->udi=%s", 
-						 volume, vol, vol != NULL ? libhal_volume_get_udi (vol) : "none");
 					page = gm_properties_view_new ();
 					gm_properties_view_set_info_volume (GM_PROPERTIES_VIEW (page), vol, hal_ctx);
-					label = gtk_label_new ("Volume");
+					label = gtk_label_new (_("Volume"));
 					gtk_widget_show (page);
 					property_page = nautilus_property_page_new ("gnome-mount-volume-properties", label, page);
 					pages = g_list_prepend (pages, property_page);
@@ -336,15 +203,11 @@
 				libhal_volume_free (vol);
 			}
 		}
-		g_free (udi);
 
 		if (drv != NULL) {
-			g_debug ("drive=%p  drv=%p, drv->udi=%s", 
-				 drive,  drv, drv != NULL ? libhal_drive_get_udi (drv) : "none");
-
 			page = gm_properties_view_new ();
 			gm_properties_view_set_info_drive (GM_PROPERTIES_VIEW (page), drv, hal_ctx);
-			label = gtk_label_new ("Drive");
+			label = gtk_label_new (_("Drive"));
 			gtk_widget_show (page);
 			property_page = nautilus_property_page_new ("gnome-mount-drive-properties", label, page);
 			pages = g_list_prepend (pages, property_page);
@@ -355,14 +218,8 @@
 
 out:
 
-	if (drive_hal_udi != NULL)
-		g_free (drive_hal_udi);
-	if (volume_hal_udi != NULL)
-		g_free (volume_hal_udi);
-	if (drive != NULL)
-		gnome_vfs_drive_unref (drive);
-	if (volume != NULL)
-		gnome_vfs_volume_unref (volume);
+        g_free (drive_hal_udi);
+        g_free (volume_hal_udi);
 
 	return pages;
 }
@@ -421,7 +278,7 @@
 void
 nautilus_module_initialize (GTypeModule  *module)
 {
-	g_print ("Initializing gnome-mount extension\n");
+	//g_print ("Initializing gnome-mount extension\n");
 
 	hal_ctx = do_hal_init ();
 	if (hal_ctx == NULL) {
@@ -444,7 +301,7 @@
 void
 nautilus_module_shutdown (void)
 {
-	g_print ("Shutting down gnome-mount extension\n");
+	//g_print ("Shutting down gnome-mount extension\n");
 }
 
 /* List all the extension types.  */

Modified: trunk/src/gnome-mount.c
==============================================================================
--- trunk/src/gnome-mount.c	(original)
+++ trunk/src/gnome-mount.c	Mon Feb 25 22:18:56 2008
@@ -29,6 +29,12 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <string.h>
+#include <stdlib.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-glib-lowlevel.h>
+#include <libhal.h>
+#include <libhal-storage.h>
 
 #include <glib/gi18n.h>
 #include <gconf/gconf-client.h>
@@ -45,12 +51,6 @@
 #define NOTIFY_EXPIRES_DEFAULT -1
 #endif
 
-#include <dbus/dbus.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
-#include <libhal.h>
-#include <libhal-storage.h>
-
 #if !defined(sun) && !defined(__FreeBSD__)
 #include <mntent.h>
 #elif defined(__FreeBSD__)
@@ -76,6 +76,7 @@
 static gboolean opt_noui = FALSE;
 static gboolean opt_block = FALSE;
 static gboolean opt_nodisplay = FALSE;
+static gboolean opt_verbose = FALSE;
 
 #define DBUS_TIMEOUT G_MAXINT
 
@@ -185,7 +186,7 @@
 		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (w),
 							  _("There is probably no media in the drive."));
 		gtk_dialog_run (GTK_DIALOG (w));
-		gtk_widget_unref (w);
+		gtk_widget_destroy (w);
 	}
 }
 
@@ -254,7 +255,7 @@
 					NULL);
 
 		gtk_dialog_run (GTK_DIALOG (w));
-		gtk_widget_unref (w);
+		gtk_widget_destroy (w);
 	}
 }
 
@@ -370,7 +371,7 @@
 					NULL);
 
 		gtk_dialog_run (GTK_DIALOG (w));
-		gtk_widget_unref (w);
+		gtk_widget_destroy (w);
 	}
 }
 
@@ -460,7 +461,7 @@
 		} else if (strcmp (error_name, "org.freedesktop.Hal.Device.Volume.AlreadyMounted") == 0) {
 
 			/* don't show any dialog for this */
-			gtk_widget_unref (w);
+			gtk_widget_destroy (w);
 			w = NULL;
 
 #if 0
@@ -481,7 +482,7 @@
 			 * and the volume contains signatures are not
 			 * yet cleaned out...
 			 */
-			gtk_widget_unref (w);
+			gtk_widget_destroy (w);
 			w = NULL;
 			 
 		} else if (strcmp (error_name, "org.freedesktop.DBus.Error.UnknownMethod") == 0) {
@@ -490,7 +491,7 @@
 			 *
 			 * Don't show any dialog for this.
 			 */
-			gtk_widget_unref (w);
+			gtk_widget_destroy (w);
 			w = NULL;
 			 
 		} else {
@@ -526,7 +527,7 @@
 						NULL);
 			
 			response = gtk_dialog_run (GTK_DIALOG (w));
-			gtk_widget_unref (w);
+			gtk_widget_destroy (w);
 			
 			switch (response) {
 				/* case MOUNT_ERROR_DIALOG_RESPONSE_INSTALL_DRIVER:
@@ -769,7 +770,8 @@
 	dbus_error_init (&error);
 	if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, dmesg, DBUS_TIMEOUT, &error)) ||
 	    dbus_error_is_set (&error)) {
-		g_warning ("Mount failed for %s\n%s : %s\n", udi, error.name, error.message);
+                if (opt_verbose)
+                        g_message ("Mount failed for %s\n%s : %s\n", udi, error.name, error.message);
 
 		if (strcmp (error.name, "org.freedesktop.Hal.Device.Volume.InvalidMountpoint") == 0 &&
 		    mount_point != NULL) {
@@ -778,7 +780,8 @@
 			if (reply != NULL)
 				dbus_message_unref (reply);
 
-			g_warning ("Given mount point name '%s' was invalid, trying without this...", mount_point);
+                        if (opt_verbose)
+                                g_message ("Given mount point name '%s' was invalid, trying without this...", mount_point);
 
 			/* possibly illegal mount point name; try without that mount point name... */
 			ret = volume_mount_with_options (udi, volume, drive, NULL, fstype, options);
@@ -799,8 +802,9 @@
 
 			new_mount_point = g_strdup_printf ("%s_", mount_point);
 
-			g_warning ("Given mount point name '%s' is unavailable, trying with '%s'...", 
-				   mount_point, new_mount_point);
+                        if (opt_verbose)
+                                g_message ("Given mount point name '%s' is unavailable, trying with '%s'...", 
+                                           mount_point, new_mount_point);
 
 			/* possibly illegal mount point name; try without that mount point name... */
 			ret = volume_mount_with_options (udi, volume, drive, new_mount_point, fstype, options);
@@ -834,7 +838,8 @@
 
 	if ((device_file = get_dev_file (volume, drive)) != NULL) {
 		if ((mounted_at = get_mntent_mount_point(device_file)) != NULL) {
-			g_print (_("Mounted %s at \"%s\"\n"), device_file, mounted_at);
+                        if (opt_verbose)
+                                g_print (_("Mounted %s at \"%s\"\n"), device_file, mounted_at);
 			g_free (mounted_at);
 		}
 	}
@@ -1158,8 +1163,9 @@
 			char *args[3] = {MOUNT, NULL, NULL};
 			char **envp = {NULL};
 
-			g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"), 
-				 device_file, mount_point_fstab);
+                        if (opt_verbose)
+                                g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"), 
+                                         device_file, mount_point_fstab);
 			args[1] = mount_point_fstab;
 			if (!g_spawn_sync ("/",
 					   args,
@@ -1179,8 +1185,9 @@
 			if (exit_status != 0) {
 				char errstr[] = "mount: unknown filesystem type";
 
-				g_warning ("%s said error %d, stdout='%s', stderr='%s'\n", 
-					   MOUNT, exit_status, sout, serr);
+                                if (opt_verbose)
+                                        g_message ("%s said error %d, stdout='%s', stderr='%s'\n", 
+                                                   MOUNT, exit_status, sout, serr);
 
 				notify_parent (FALSE);
 
@@ -1201,7 +1208,8 @@
 
 			}
 
-			g_print (_("Mounted %s at \"%s\" (using /etc/fstab)\n"), device_file, mount_point_fstab);
+                        if (opt_verbose)
+                                g_print (_("Mounted %s at \"%s\" (using /etc/fstab)\n"), device_file, mount_point_fstab);
 
 			g_free (mount_point_fstab);
 			ret = TRUE;
@@ -1718,8 +1726,9 @@
 			char *args[3] = {UMOUNT, NULL, NULL};
 			char **envp = {NULL};
 
-			g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"),
-				 device_file, mount_point);
+                        if (opt_verbose)
+                                g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"),
+                                         device_file, mount_point);
 			args[1] = mount_point;
 			if (!g_spawn_sync ("/",
 					   args,
@@ -1737,8 +1746,9 @@
 			}
 
 			if (exit_status != 0) {
-				g_warning ("%s said error %d, stdout='%s', stderr='%s'\n", 
-					   UMOUNT, exit_status, sout, serr);
+                                if (opt_verbose)
+                                        g_message ("%s said error %d, stdout='%s', stderr='%s'\n", 
+                                                   UMOUNT, exit_status, sout, serr);
 				g_free (mount_point);
 
 				if (strstr (serr, "is busy") != NULL) {
@@ -1754,7 +1764,8 @@
 				goto out;
 			}
 
-			g_print (_("Unmounted %s (using /etc/fstab)\n"), device_file);
+                        if (opt_verbose)
+                                g_print (_("Unmounted %s (using /etc/fstab)\n"), device_file);
 
 			g_free (mount_point);
 			ret = TRUE;
@@ -1818,7 +1829,8 @@
 		if (!is_ro) {
 			unmount_cache_timeout_cancel (FALSE);
 		}
-		g_warning ("Unmount failed for %s: %s : %s\n", udi, error.name, error.message);
+                if (opt_verbose)
+                        g_message ("Unmount failed for %s: %s : %s\n", udi, error.name, error.message);
 
 		if (strcmp (error.name, "org.freedesktop.Hal.Device.PermissionDeniedByPolicy") == 0) {
                         /* attempt to gain privilege */
@@ -1834,7 +1846,8 @@
 		goto out;
 	}
 
-	g_print (_("Unmounted %s\n"), get_dev_file (volume, drive));
+        if (opt_verbose)
+                g_print (_("Unmounted %s\n"), get_dev_file (volume, drive));
 	if (!is_ro) {
 		unmount_cache_timeout_cancel (TRUE);
 	}
@@ -1933,8 +1946,9 @@
 			char *args[3] = {"eject", NULL, NULL};
 			char **envp = {NULL};
 
-			g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"), 
-				 device_file, mount_point);
+                        if (opt_verbose)
+                                g_print (_("Device %s is in /etc/fstab with mount point \"%s\"\n"), 
+                                         device_file, mount_point);
 			args[1] = mount_point;
 			if (!g_spawn_sync ("/",
 					   args,
@@ -1952,8 +1966,9 @@
 			}
 
 			if (exit_status != 0) {
-				g_warning ("%s said error %d, stdout='%s', stderr='%s'\n", 
-					   "eject", exit_status, sout, serr);
+                                if (opt_verbose)
+                                        g_message ("%s said error %d, stdout='%s', stderr='%s'\n", 
+                                                   "eject", exit_status, sout, serr);
 				g_free (mount_point);
 
 				if (strstr (serr, "is busy") != NULL) {
@@ -1969,7 +1984,8 @@
 				goto out;
 			}
 
-			g_print (_("Ejected %s (using /etc/fstab).\n"), device_file);
+                        if (opt_verbose)
+                                g_print (_("Ejected %s (using /etc/fstab).\n"), device_file);
 
 			g_free (mount_point);
 			ret = TRUE;
@@ -2032,7 +2048,8 @@
 		if (!is_ro) {
 			unmount_cache_timeout_cancel (FALSE);
 		}
-		g_warning ("Eject failed for %s: %s : %s\n", udi, error.name, error.message);
+                if (opt_verbose)
+                        g_message ("Eject failed for %s: %s : %s\n", udi, error.name, error.message);
 
 		if (strcmp (error.name, "org.freedesktop.Hal.Device.PermissionDeniedByPolicy") == 0) {
                         /* attempt to gain privilege */
@@ -2048,7 +2065,8 @@
 		goto out;
 	}
 
-	g_print (_("Ejected %s\n"), get_dev_file (volume, drive));
+        if (opt_verbose)
+                g_print (_("Ejected %s\n"), get_dev_file (volume, drive));
 	if (!is_ro) {
 		unmount_cache_timeout_cancel (TRUE);
 	}
@@ -2198,7 +2216,8 @@
 	}
 
 	if (opt_noui) {
-		g_warning ("Not showing password dialog since invoked with --no-ui");
+                if (opt_verbose)
+                        g_message ("Not showing password dialog since invoked with --no-ui");
 		goto out;
 	}
 
@@ -2301,7 +2320,8 @@
 	dbus_error_init (&error);
 	if (!(reply = dbus_connection_send_with_reply_and_block (dbus_connection, msg, DBUS_TIMEOUT, &error)) || 
 	    dbus_error_is_set (&error)) {
-		g_warning ("Setup failed for %s: %s : %s\n", udi, error.name, error.message);
+                if (opt_verbose)
+                        g_message ("Setup failed for %s: %s : %s\n", udi, error.name, error.message);
 		if (strcmp (error.name, "org.freedesktop.Hal.Device.Volume.Crypto.SetupPasswordError") == 0) {
 			*password_error = TRUE;
 		}
@@ -2312,7 +2332,8 @@
 
 	ret = TRUE;
 
-	g_print (_("Setup clear-text device for %s.\n"), get_dev_file (volume, drive));
+        if (opt_verbose)
+                g_print (_("Setup clear-text device for %s.\n"), get_dev_file (volume, drive));
 
 out:
 	if (msg != NULL)
@@ -2378,7 +2399,8 @@
 		goto out;
 	}
 
-	g_print (_("Teared down clear-text device for %s.\n"), get_dev_file (volume, drive));
+        if (opt_verbose)
+                g_print (_("Teared down clear-text device for %s.\n"), get_dev_file (volume, drive));
 
 	ret = TRUE;
 
@@ -2424,7 +2446,8 @@
 
 				g_debug ("%s is backed by %s - will mount", udi, backing_udi);
 
-				g_print (_("Clear text device is %s. Mounting.\n"), get_dev_file (volume, NULL));
+                                if (opt_verbose)
+                                        g_print (_("Clear text device is %s. Mounting.\n"), get_dev_file (volume, NULL));
 					
 				fsuage = libhal_volume_get_fsusage (volume);
 					
@@ -2432,7 +2455,8 @@
 					if (volume_mount (udi, volume, NULL))
 						crypto_setup_rc = 0;
 				} else {
-					g_warning ("%s does not have a mountable filesystem", udi);
+                                        if (opt_verbose)
+                                                g_message ("%s does not have a mountable filesystem", udi);
 				}
 				
 				notify_parent (crypto_setup_rc == 0);
@@ -2448,7 +2472,8 @@
 static gboolean
 crypto_setup_timeout (gpointer data)
 {
-	g_warning ("Timeout for waiting for cleartext device... Exiting.");
+        if (opt_verbose)
+                g_message ("Timeout for waiting for cleartext device... Exiting.");
 	notify_parent (FALSE);
 	gtk_main_quit ();
 	
@@ -2691,7 +2716,6 @@
 	char *resolved_device_file = NULL;
 	static gboolean opt_connect_crypto = FALSE;
 	static gboolean opt_disconnect_crypto = FALSE;
-	static gboolean opt_verbose = FALSE;
 	static gboolean opt_unmount = FALSE;
 	static gboolean opt_eject = FALSE;
 	static gchar *opt_hal_udi = NULL;
@@ -2757,10 +2781,12 @@
 		opt_nodisplay = TRUE;
 	}
 
-	g_print ("%s\n", PACKAGE_STRING);
+        if (opt_verbose)
+                g_print ("%s\n", PACKAGE_STRING);
 
 	if (!gtk_init_check (&argc, &argv)) {
-		g_print (_("X display not available - using text-based operation.\n"));
+                if (opt_verbose)
+                        g_print (_("X display not available - using text-based operation.\n"));
 		opt_nodisplay = TRUE;
 	}
 
@@ -2857,7 +2883,8 @@
 		if (volume != NULL) {
 			g_print (_("Resolved pseudonym \"%s\" -> %s\n"), opt_nickname, get_dev_file (volume, NULL));
 		} else {
-			g_warning (_("Cannot resolve pseudonym \"%s\" to a volume\n"), opt_nickname);
+                        if (opt_verbose)
+                                g_message (_("Cannot resolve pseudonym \"%s\" to a volume\n"), opt_nickname);
 			goto out;
 		}
 	} else {
@@ -2909,8 +2936,9 @@
 			if (found) {
 				goto try_drive;
 			} else {
-				g_warning (_("Drive %s does not contain media."), 
-					 resolved_device_file != NULL ? resolved_device_file : opt_hal_udi);
+                                if (opt_verbose)
+                                        g_message (_("Drive %s does not contain media."), 
+                                                   resolved_device_file != NULL ? resolved_device_file : opt_hal_udi);
 				
 				notify_parent (FALSE);
 				
@@ -2919,8 +2947,9 @@
 
 		} else {
 			/* Silently fail */
-			g_warning (_("Given device '%s' is not a volume or a drive."), 
-				 resolved_device_file != NULL ? resolved_device_file : opt_hal_udi);
+                        if (opt_verbose)
+                                g_message (_("Given device '%s' is not a volume or a drive."), 
+                                           resolved_device_file != NULL ? resolved_device_file : opt_hal_udi);
 		}
 
 		goto out;
@@ -2954,7 +2983,8 @@
 	}
 
 	if (opt_unmount && opt_eject) {
-		g_warning (_("Cannot unmount and eject simultaneously"));
+                if (opt_verbose)
+                        g_message (_("Cannot unmount and eject simultaneously"));
 		goto out;
 	}
 
@@ -3018,8 +3048,9 @@
 			/* see if we're already setup */
 			clear_udi = libhal_volume_crypto_get_clear_volume_udi (hal_ctx, volume);
 			if (clear_udi != NULL) {
-				g_warning (_("Crypto volume '%s' is already setup with clear volume '%s'"), 
-					 udi, clear_udi);
+                                if (opt_verbose)
+                                        g_message (_("Crypto volume '%s' is already setup with clear volume '%s'"), 
+                                                   udi, clear_udi);
 				
 				free (clear_udi);
 				goto out;
@@ -3043,13 +3074,15 @@
 			if (password != NULL) {
 				setup_success = setup_crypto (udi, volume, drive, password, &password_error);
 				if (!setup_success && password_error) {
-					g_warning (_("Bad crypto password"));
+                                        if (opt_verbose)
+                                                g_message (_("Bad crypto password"));
 					if (!opt_nodisplay && password_num_tries < 3) {
 						g_free (password);
 						password_retry = TRUE;
 						goto retry_password;
 					} else {
-						g_warning (_("Bailing out..."));
+                                                if (opt_verbose)
+                                                        g_message (_("Bailing out..."));
 					}
 				}
 			}



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