Re: Nautilus UI change



Attached is the current ui-changing patch (I committed most of the
mechanism to HEAD already).  The text changed a bit from what seth last
suggested to me, so I'm Ccing him for comments on the actual text.

-dave

On Mon, 2004-02-23 at 16:47 +0100, Christian Rose wrote:

> mån 2004-02-23 klockan 16.37 skrev Dave Camp:
> > For security reasons, nautilus has to pop up a dialog and refuse to
> > activate if the sniffed mime type doesn't match the extension.  This
> > will involve a dialog explaining the problem and how to fix it.
> > 
> > It will be an annoying change to document and a slightly annoying one to
> > translate, but we need it for security reasons.
> > 
> > Any objection to me putting this in and sending a patch to the relevant
> > lists when it's ready?
> 
> Is the patch availiable somewhere, say Bugzilla, where one can have a
> look at it?
> 
> 
> Christian
? nautilus-computer.desktop
? nautilus-home.desktop
? nautilus-mime-mismatch.patch
? libnautilus-extension/Makefile
? libnautilus-extension/Makefile.in
? libnautilus-extension/libnautilus-extension.pc
Index: libnautilus-private/nautilus-mime-actions.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-mime-actions.c,v
retrieving revision 1.110
diff -u -r1.110 nautilus-mime-actions.c
--- libnautilus-private/nautilus-mime-actions.c	23 Feb 2004 23:05:58 -0000	1.110
+++ libnautilus-private/nautilus-mime-actions.c	24 Feb 2004 00:30:53 -0000
@@ -447,6 +447,7 @@
 	return user_chosen;
 }
 
+
 GList *
 nautilus_mime_get_short_list_applications_for_file (NautilusFile      *file)
 {
Index: src/file-manager/fm-directory-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-directory-view.c,v
retrieving revision 1.613
diff -u -r1.613 fm-directory-view.c
--- src/file-manager/fm-directory-view.c	23 Feb 2004 23:06:02 -0000	1.613
+++ src/file-manager/fm-directory-view.c	24 Feb 2004 00:30:53 -0000
@@ -39,6 +39,7 @@
 #include <bonobo/bonobo-zoomable.h>
 #include <bonobo/bonobo-ui-util.h>
 #include <bonobo/bonobo-exception.h>
+#include <eel/eel-alert-dialog.h>
 #include <eel/eel-background.h>
 #include <eel/eel-glib-extensions.h>
 #include <eel/eel-gnome-extensions.h>
@@ -3880,6 +3881,106 @@
 }
 
 static void
+warn_mismatched_mime_types_response_cb (GtkWidget *dialog,
+					int response,
+					gpointer user_data)
+{
+	gtk_widget_destroy (dialog);
+}
+
+static void
+warn_mismatched_mime_types (FMDirectoryView *view,
+			    NautilusFile *file)
+{
+	GtkWidget *dialog;
+	char *guessed_mime_type;
+	char *mime_type;
+	const char *guessed_description;
+	const char *real_description;
+	char *primary;
+	char *secondary;
+	char *name;
+	
+	guessed_mime_type = nautilus_file_get_guessed_mime_type (file);
+	mime_type = nautilus_file_get_mime_type (file);
+
+	guessed_description = gnome_vfs_mime_get_description (guessed_mime_type);
+	real_description = gnome_vfs_mime_get_description (mime_type);
+
+	g_free (guessed_mime_type);
+	g_free (mime_type);
+	
+	name = nautilus_file_get_name (file);
+
+	primary = g_strdup_printf (_("Can not open %s"), name);
+
+	secondary = g_strdup_printf 
+		(_("The name \"%s\" indicates that this file is of "
+                   "type \"%s\".  The contents of the file indicate that "
+                   "it is of type \"%s\". This mismatch makes it risky to "
+		   "open the file.\n\n"
+		   "If you created the file yourself or received it from "
+		   "a trusted source:  to open the file, rename it to "
+		   "have the correct extension for \"%s\", or open it by "
+		   "choosing a specific application from the Open With "
+		   "menu."),
+		 name, 
+		 guessed_description, 
+		 real_description,
+		 real_description);
+	
+	dialog = eel_alert_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (view))),
+				       0,
+				       GTK_MESSAGE_ERROR,
+				       GTK_BUTTONS_NONE,
+				       primary,
+				       secondary,
+				       primary);
+
+	g_free (primary);
+	g_free (secondary);
+	g_free (name);
+
+	gtk_dialog_add_button (GTK_DIALOG (dialog),
+			       GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
+	gtk_dialog_set_default_response (GTK_DIALOG (dialog), 
+					 GTK_RESPONSE_CANCEL);
+
+	g_signal_connect (dialog, 
+			  "response",
+			  G_CALLBACK (warn_mismatched_mime_types_response_cb),
+			  file);
+
+	gtk_widget_show (dialog);
+}
+
+static gboolean
+activate_check_mime_types (FMDirectoryView *view,
+			   NautilusFile *file)
+{
+	char *guessed_mime_type;
+	char *mime_type;
+	gboolean ret;
+	
+	g_return_val_if_fail (nautilus_file_check_if_ready (file, NAUTILUS_FILE_ATTRIBUTE_SLOW_MIME_TYPE), FALSE);
+
+	guessed_mime_type = nautilus_file_get_guessed_mime_type (file);
+	mime_type = nautilus_file_get_mime_type (file);
+
+	if (strcmp (guessed_mime_type, mime_type) != 0) {
+		warn_mismatched_mime_types (view, file);
+		ret = FALSE;
+	} else {
+		ret = TRUE;
+	}
+
+	g_free (guessed_mime_type);
+	g_free (mime_type);
+	
+	return ret;
+}
+
+static void
 add_extension_menu_items (FMDirectoryView *view,
 			  GList *files,
 			  GList *menu_items)
@@ -5894,6 +5995,10 @@
 
 	view = FM_DIRECTORY_VIEW (parameters->view);
 
+	if (!activate_check_mime_types (view, file)) {
+		return;
+	}
+
 	orig_uri = uri = nautilus_file_get_activation_uri (file);
 
 	action = ACTIVATION_ACTION_DISPLAY;


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