Re: [patch] pluggable property dialog pages



On Thu, 2002-10-24 at 11:05, Alexander Larsson wrote:
> On 23 Oct 2002, James Willcox wrote:
> 
> > Hi,
> > 
> > I've attached a patch that makes it possible to have mime-type-sensitive
> > pages in the properties dialog.  It uses the good 'ol NautilusView stuff
> > people are used to, so there wasn't much required to make it happen. 
> > I've also attached a sample view that lets you see metadata contained in
> > audio files (mp3, ogg, etc).  Let me know what you think.
<snip>

Ok, I've fixed some more stuff.  See the attached patch w/ changelog.

Thanks,
James
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5565
diff -u -r1.5565 ChangeLog
--- ChangeLog	24 Oct 2002 15:54:28 -0000	1.5565
+++ ChangeLog	24 Oct 2002 20:34:08 -0000
@@ -1,3 +1,24 @@
+2002-10-24  James Willcox  <jwillcox gnome org>
+
+	* components/notes/Nautilus_View_notes.server.in.in:
+	* libnautilus-private/nautilus-mime-actions.c:
+	(nautilus_mime_has_any_components_for_file_extended),
+	(nautilus_mime_has_any_components_for_file):
+	* libnautilus-private/nautilus-mime-actions.h:
+	* libnautilus-private/nautilus-program-chooser.c:
+	(repopulate_program_list):
+	* libnautilus-private/nautilus-program-choosing.c:
+	(choose_component_callback):
+	* src/file-manager/fm-properties-window.c: (clear_bonobo_pages),
+	(refresh_bonobo_pages), (properties_window_file_changed_callback),
+	(bonobo_page_error_message), (bonobo_page_activate_callback),
+	(append_bonobo_pages):
+
+	* Activate the bonobo property pages asynchronously
+	* Hide the bonobo property pages from the component chooser
+	* Slightly modify the notes sidebar to also work as a property page
+	* Handle changes in the file type (add/remove pages)
+
 2002-10-24  Alexander Larsson  <alexl redhat com>
 
 	* components/Makefile.am:
Index: components/notes/Nautilus_View_notes.server.in.in
===================================================================
RCS file: /cvs/gnome/nautilus/components/notes/Nautilus_View_notes.server.in.in,v
retrieving revision 1.12
diff -u -r1.12 Nautilus_View_notes.server.in.in
--- components/notes/Nautilus_View_notes.server.in.in	22 Jul 2002 15:52:42 -0000	1.12
+++ components/notes/Nautilus_View_notes.server.in.in	24 Oct 2002 20:34:08 -0000
@@ -13,6 +13,11 @@
 	<oaf_attribute name="nautilus:recommended_uri_schemes" type="stringv">
 		<item value="*"/>
 	</oaf_attribute>
+	<oaf_attribute name="bonobo:supported_mime_types" type="stringv">
+		<item value="*/*"/>
+	</oaf_attribute>
+	<oaf_attribute name="nautilus:view_as_name" type="string" _value="Notes"/>
+	<oaf_attribute name="nautilus:property_page_name" type="string" _value="Notes"/>
 </oaf_server>
 
 </oaf_info>
Index: libnautilus-private/nautilus-mime-actions.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-mime-actions.c,v
retrieving revision 1.101
diff -u -r1.101 nautilus-mime-actions.c
--- libnautilus-private/nautilus-mime-actions.c	24 Oct 2002 15:54:33 -0000	1.101
+++ libnautilus-private/nautilus-mime-actions.c	24 Oct 2002 20:34:09 -0000
@@ -811,18 +811,25 @@
 }
 
 gboolean
-nautilus_mime_has_any_components_for_file (NautilusFile      *file)
+nautilus_mime_has_any_components_for_file_extended (NautilusFile *file,
+						    char *extra_reqs)
 {
 	GList *list;
 	gboolean result;
 
-	list = nautilus_mime_get_all_components_for_file (file);
+	list = nautilus_mime_get_all_components_for_file_extended (file,
+								   extra_reqs);
 	result = list != NULL;
 	gnome_vfs_mime_component_list_free (list);
 
 	return result;
 }
 
+gboolean
+nautilus_mime_has_any_components_for_file (NautilusFile *file)
+{
+	return nautilus_mime_has_any_components_for_file_extended (file, NULL);
+}
 
 static GList *
 mime_get_all_components_for_uri_scheme (const char *uri_scheme)
Index: libnautilus-private/nautilus-mime-actions.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-mime-actions.h,v
retrieving revision 1.24
diff -u -r1.24 nautilus-mime-actions.h
--- libnautilus-private/nautilus-mime-actions.h	24 Oct 2002 15:54:33 -0000	1.24
+++ libnautilus-private/nautilus-mime-actions.h	24 Oct 2002 20:34:09 -0000
@@ -45,6 +45,7 @@
 GList *                  nautilus_mime_get_all_components_for_file                 (NautilusFile           *file);
 GList *                  nautilus_mime_get_all_components_for_file_extended        (NautilusFile           *file, char *extra_requirements);
  gboolean                 nautilus_mime_has_any_components_for_file                 (NautilusFile           *file);
+ gboolean                 nautilus_mime_has_any_components_for_file_extended        (NautilusFile           *file, char *extra_requirements);
 gboolean                 nautilus_mime_has_any_applications_for_file               (NautilusFile           *file);
 gboolean                 nautilus_mime_has_any_applications_for_file_type          (NautilusFile           *file);
 GnomeVFSResult           nautilus_mime_set_default_action_type_for_file            (NautilusFile           *file,
Index: libnautilus-private/nautilus-program-chooser.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-program-chooser.c,v
retrieving revision 1.77
diff -u -r1.77 nautilus-program-chooser.c
--- libnautilus-private/nautilus-program-chooser.c	2 Oct 2002 05:36:50 -0000	1.77
+++ libnautilus-private/nautilus-program-chooser.c	24 Oct 2002 20:34:09 -0000
@@ -433,7 +433,7 @@
 	gchar *program_name, *status_text;
 	GtkTreeIter iter;
 	GtkTreePath *path;
-	
+
 	type = program_chooser->details->action_type;
 
 	g_assert (type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT
@@ -441,7 +441,7 @@
 	
 
 	programs = type == GNOME_VFS_MIME_ACTION_TYPE_COMPONENT
-		? nautilus_mime_get_all_components_for_file (program_chooser->details->file)
+		? nautilus_mime_get_all_components_for_file_extended (program_chooser->details->file, "(NOT nautilus:property_page_name.defined)")
 		: nautilus_mime_get_all_applications_for_file (program_chooser->details->file);
 
 	list_store = program_chooser->details->list_store;
Index: libnautilus-private/nautilus-program-choosing.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-program-choosing.c,v
retrieving revision 1.61
diff -u -r1.61 nautilus-program-choosing.c
--- libnautilus-private/nautilus-program-choosing.c	2 Oct 2002 05:36:50 -0000	1.61
+++ libnautilus-private/nautilus-program-choosing.c	24 Oct 2002 20:34:09 -0000
@@ -193,7 +193,8 @@
 
 	identifier = NULL;
 	dialog = NULL;
-	if (nautilus_mime_has_any_components_for_file (file)) {
+	if (nautilus_mime_has_any_components_for_file_extended (file,
+	    "(NOT nautilus:property_page_name.defined()")) {
 		dialog = set_up_program_chooser (file, GNOME_VFS_MIME_ACTION_TYPE_COMPONENT,
 						 choose_data->parent_window);
 		if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) {
Index: src/file-manager/fm-properties-window.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-properties-window.c,v
retrieving revision 1.158
diff -u -r1.158 fm-properties-window.c
--- src/file-manager/fm-properties-window.c	24 Oct 2002 15:54:34 -0000	1.158
+++ src/file-manager/fm-properties-window.c	24 Oct 2002 20:34:10 -0000
@@ -133,6 +133,12 @@
 	FMDirectoryView *directory_view;
 } StartupData;
 
+typedef struct {
+	FMPropertiesWindow *window;
+	GtkWidget *vbox;
+	char *view_name;
+} ActivationData;
+
 
 /* drag and drop definitions */
 
@@ -169,6 +175,8 @@
 						   gboolean                 cancel_timed_wait,
 						   gboolean                 cancel_destroy_handler);
 
+static void append_bonobo_pages                   (FMPropertiesWindow *window);
+
 GNOME_CLASS_BOILERPLATE (FMPropertiesWindow, fm_properties_window,
 			 GtkWindow, GTK_TYPE_WINDOW)
 
@@ -618,7 +626,35 @@
 }
 
 static void
-properties_window_file_changed_callback (GtkWindow *window, NautilusFile *file)
+clear_bonobo_pages (FMPropertiesWindow *window)
+{
+	int i;
+	int num_pages;
+	GtkWidget *page;
+
+	num_pages = gtk_notebook_get_n_pages
+				(GTK_NOTEBOOK (window->details->notebook));
+				 
+	for (i=0; i <  num_pages; i++) {
+		page = gtk_notebook_get_nth_page
+				(GTK_NOTEBOOK (window->details->notebook), i);
+
+		if (g_object_get_data (G_OBJECT (page), "is-bonobo-page")) {
+			gtk_notebook_remove_page
+				(GTK_NOTEBOOK (window->details->notebook), i);
+		}
+	}
+}
+
+static void
+refresh_bonobo_pages (FMPropertiesWindow *window)
+{
+	clear_bonobo_pages (window);
+	append_bonobo_pages (window);	
+}
+
+static void
+properties_window_file_changed_callback (FMPropertiesWindow *window, NautilusFile *file)
 {
 	g_assert (GTK_IS_WINDOW (window));
 	g_assert (NAUTILUS_IS_FILE (file));
@@ -626,7 +662,25 @@
 	if (nautilus_file_is_gone (file)) {
 		gtk_widget_destroy (GTK_WIDGET (window));
 	} else {
-		update_properties_window_title (window, file);
+		char *orig_mime_type;
+		char *new_mime_type;
+
+		orig_mime_type = nautilus_file_get_mime_type
+						(window->details->target_file);
+		nautilus_file_unref (window->details->target_file);
+
+		window->details->target_file = nautilus_file_ref (file);
+
+		update_properties_window_title (GTK_WINDOW (window), file);
+
+		new_mime_type = nautilus_file_get_mime_type
+						(window->details->target_file);
+
+		if (strcmp (orig_mime_type, new_mime_type) == 0) {
+			refresh_bonobo_pages (window);
+		}
+
+		g_free (orig_mime_type);
 	}
 }
 
@@ -2107,31 +2161,84 @@
 }
 
 static GtkWidget *
-bonobo_page_error_message (NautilusViewIdentifier *view_id,
-			   CORBA_Environment *ev)
+bonobo_page_error_message (const char *view_name,
+			   const char *msg)
 {
 	GtkWidget *hbox;
 	GtkWidget *label;
 	GtkWidget *image;
-	char *msg;
 
 	hbox = gtk_hbox_new (FALSE, GNOME_PAD);
 	image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_ERROR,
 					  GTK_ICON_SIZE_DIALOG);
 
-	msg = g_strdup_printf ("There was an error while trying to create the view named `%s':  %s", view_id->name, CORBA_exception_id (ev));
+	msg = g_strdup_printf ("There was an error while trying to create the view named `%s':  %s", view_name, msg);
 	label = gtk_label_new (msg);
-	g_free (msg);
 
 	gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
 
 	gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
 	gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
+	gtk_widget_show_all (hbox);
 
 	return hbox;
 }
 
 static void
+bonobo_page_activate_callback (CORBA_Object obj,
+			       const char *error_reason,
+			       gpointer user_data)
+{
+	ActivationData *data;
+	FMPropertiesWindow *window;
+	GtkWidget *widget;
+	CORBA_Environment ev;
+
+	data = (ActivationData *)user_data;
+	window = data->window;
+
+	g_return_if_fail (FM_IS_PROPERTIES_WINDOW (window));
+
+	CORBA_exception_init (&ev);
+	widget = NULL;
+
+	if (obj != CORBA_OBJECT_NIL) {
+		Bonobo_Control control;
+		Nautilus_View view;
+		char *uri;
+		
+		control = Bonobo_Unknown_queryInterface
+				(obj, "IDL:Bonobo/Control:1.0", &ev);
+
+		view = Bonobo_Unknown_queryInterface
+				(control, "IDL:Nautilus/View:1.0", &ev);
+
+		uri = nautilus_file_get_uri
+			(window->details->target_file);
+
+		Nautilus_View_load_location (view, uri, &ev);
+		
+		if (!BONOBO_EX (&ev)) {
+			widget = bonobo_widget_new_control_from_objref
+					(control, CORBA_OBJECT_NIL);
+		}
+
+		g_free (uri);
+	}
+
+	if (widget == NULL) {
+		widget = bonobo_page_error_message (data->view_name,
+						    error_reason);
+	}
+
+	gtk_container_add (GTK_CONTAINER (data->vbox), widget);
+	gtk_widget_show (widget);
+
+	g_free (data->view_name);
+	g_free (data);
+}
+
+static void
 append_bonobo_pages (FMPropertiesWindow *window)
 {
 	GList *components, *l;
@@ -2148,54 +2255,28 @@
 	while (l != NULL) {
 		NautilusViewIdentifier *view_id;
 		Bonobo_ServerInfo *server;
-		GtkWidget *vbox, *widget;
-		Bonobo_Unknown obj;
-
-		widget = NULL;
+		ActivationData *data;
+		GtkWidget *vbox;
 
 		server = l->data;
 		l = l->next;
 
 		view_id = nautilus_view_identifier_new_from_property_page (server);
-
-		obj = bonobo_activation_activate_from_id (view_id->iid,
-							  0, NULL, &ev);
-
-		if (!BONOBO_EX (&ev)) {
-			Bonobo_Control control;
-			Nautilus_View view;
-			char *uri;
-			
-			control = Bonobo_Unknown_queryInterface
-					(obj, "IDL:Bonobo/Control:1.0", &ev);
-
-			view = Bonobo_Unknown_queryInterface
-					(control, "IDL:Nautilus/View:1.0", &ev);
-
-			uri = nautilus_file_get_uri
-				(window->details->target_file);
-
-			Nautilus_View_load_location (view, uri, &ev);
-			
-			if (!BONOBO_EX (&ev)) {
-				widget = bonobo_widget_new_control_from_objref
-						(control, CORBA_OBJECT_NIL);
-			}
-
-			g_free (uri);
-		}
-
-		if (widget == NULL) {
-			widget = bonobo_page_error_message (view_id, &ev);
-		}
-		
-
 		vbox = create_page_with_vbox (window->details->notebook,
 					      view_id->name);
-		gtk_container_add (GTK_CONTAINER (vbox), widget);
-		gtk_widget_show_all (vbox);
-		
-		nautilus_view_identifier_free (view_id);
+
+		/* just a tag...the value doesn't matter */
+		g_object_set_data (G_OBJECT (vbox), "is-bonobo-page",
+				  vbox);
+
+		data = g_new (ActivationData, 1);
+		data->window = window;
+		data->vbox = vbox;
+		data->view_name = g_strdup (view_id->name);
+
+		bonobo_activation_activate_from_id_async (view_id->iid,
+					0, bonobo_page_activate_callback,
+					data, &ev);
 	}
 
 }


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