Mime type monitor support Take 2



After some feedback from Dave, I've taken a slightly different tack
to this.  2 open questions

1) Do I really need all those attributes ?
2) why is the delay between the change notification and the update
   so long ?
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5376
diff -u -w -r1.5376 ChangeLog
--- ChangeLog	21 Jun 2002 03:40:14 -0000	1.5376
+++ ChangeLog	26 Jun 2002 03:27:51 -0000
@@ -1,3 +1,15 @@
+2002-06-25  Jody Goldberg <jody gnome org>
+
+	* libnautilus-private/nautilus-program-chooser.c
+	(launch_mime_capplet) : take a NautilusFile not a mime type.
+	  Quote the mime type, and pass the quoted file name too.
+	(launch_mime_capplet_and_close_dialog) : pass the file directly.
+	(nautilus_program_chooser_show_no_choices_message) : ditto.
+
+	* libnautilus-private/nautilus-directory-async.c
+	(cb_mime_db_changed) : new.
+	(nautilus_directory_monitor_add_internal) : connect here.
+
 2002-06-20  Mark McLoughlin  <mark skynet ie>
 
 	* src/file-manager/fm-desktop-icon-view.c:
Index: libnautilus-private/nautilus-directory-async.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-async.c,v
retrieving revision 1.185
diff -u -w -r1.185 nautilus-directory-async.c
--- libnautilus-private/nautilus-directory-async.c	10 May 2002 18:49:04 -0000	1.185
+++ libnautilus-private/nautilus-directory-async.c	26 Jun 2002 03:27:53 -0000
@@ -39,6 +39,7 @@
 #include <gtk/gtkmain.h>
 #include <libgnomevfs/gnome-vfs-ops.h>
 #include <libgnomevfs/gnome-vfs-utils.h>
+#include <libgnomevfs/gnome-vfs-mime-monitor.h>
 #include <libxml/parser.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -584,6 +585,31 @@
 
 }
 
+static void
+cb_mime_db_changed (GnomeVFSMIMEMonitor *monitor, NautilusDirectory *dir)
+{
+	GList *attributes = NULL;
+	GList *ptr;
+
+	g_return_if_fail (dir != NULL);
+	g_return_if_fail (dir->details != NULL);
+
+	for (ptr = dir->details->monitor_list ; ptr != NULL ; ptr = ptr->next) {
+		Monitor const *monitor = ptr->data;
+		if (monitor->request.file_info && monitor->file != NULL) {
+			attributes = NULL;
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_CAPABILITIES);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_CUSTOM_ICON);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_MIME_TYPE);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_METADATA);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_FILE_TYPE);
+			attributes = g_list_prepend (attributes, NAUTILUS_FILE_ATTRIBUTE_DIRECTORY_ITEM_MIME_TYPES);
+			nautilus_file_invalidate_attributes (monitor->file, attributes);
+		}
+	}
+}
+
 void
 nautilus_directory_monitor_add_internal (NautilusDirectory *directory,
 					 NautilusFile *file,
@@ -639,6 +665,11 @@
 	 */
 	if (monitor->request.metafile && directory->details->metafile_monitor == NULL) {
 		nautilus_directory_register_metadata_monitor (directory);	
+	}
+
+	if (monitor->request.file_info && directory->details->mime_db_monitor == 0) {
+		g_signal_connect_object (gnome_vfs_mime_monitor_get (), "data_changed",
+			G_CALLBACK (cb_mime_db_changed), directory, 0);			  
 	}
 
 	/* Put the monitor file or all the files on the work queue. */
Index: libnautilus-private/nautilus-directory-private.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-directory-private.h,v
retrieving revision 1.87
diff -u -w -r1.87 nautilus-directory-private.h
--- libnautilus-private/nautilus-directory-private.h	21 Feb 2002 19:26:46 -0000	1.87
+++ libnautilus-private/nautilus-directory-private.h	26 Jun 2002 03:27:53 -0000
@@ -61,6 +61,7 @@
 	GList *monitor_list;
 
 	NautilusMonitor *monitor;
+	gulong 		 mime_db_monitor;
 
 	NautilusIdleQueue *idle_queue;
 	NautilusMetafileMonitor *metafile_monitor;
Index: libnautilus-private/nautilus-program-chooser.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-program-chooser.c,v
retrieving revision 1.73
diff -u -w -r1.73 nautilus-program-chooser.c
--- libnautilus-private/nautilus-program-chooser.c	12 Jun 2002 14:21:59 -0000	1.73
+++ libnautilus-private/nautilus-program-chooser.c	26 Jun 2002 03:27:54 -0000
@@ -916,13 +916,17 @@
 }
 
 static void
-launch_mime_capplet (const char *mime_type)
+launch_mime_capplet (NautilusFile *file)
 {
 	char *command;
+	char *mime_type = nautilus_file_get_mime_type (file);
+	char *file_name = nautilus_file_get_name (file);
 
-	command = g_strconcat (FILE_TYPES_CAPPLET_NAME, " ", mime_type, NULL);
+	command = g_strconcat (FILE_TYPES_CAPPLET_NAME, " '", mime_type, "' '", file_name, "'", NULL);
 	nautilus_launch_application_from_command (FILE_TYPES_CAPPLET_NAME, command, NULL, FALSE);
 	g_free (command);
+	g_free (file_name);
+	g_free (mime_type);
 }
 
 static void
@@ -940,16 +944,11 @@
 launch_mime_capplet_and_close_dialog (GtkButton *button, gpointer callback_data)
 {
 	ProgramFilePair *file_pair;
-	char *mime_type;
 	
 	g_assert (GTK_IS_BUTTON (button));
 
 	file_pair = get_selected_program_file_pair (NAUTILUS_PROGRAM_CHOOSER (callback_data));
-	mime_type = nautilus_file_get_mime_type (file_pair->file);
-	launch_mime_capplet (mime_type);
-	
-	g_free (mime_type);
-
+	launch_mime_capplet (file_pair->file);
 	gtk_dialog_response (GTK_DIALOG (callback_data),
 		GTK_RESPONSE_DELETE_EVENT);
 }
@@ -1550,7 +1549,7 @@
 
 	g_signal_connect (dialog, "response",
 			  G_CALLBACK (launch_mime_capplet_on_ok),
-			  nautilus_file_get_mime_type (file));
+			  file);
 
 	g_free (unavailable_message);
 	g_free (file_name);


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