Index: ChangeLog
===================================================================
RCS file: /export/cvs/head/eog/ChangeLog,v
retrieving revision 1.761
diff -p -u -5 -r1.761 ChangeLog
--- ChangeLog	1 Apr 2006 00:24:43 -0000	1.761
+++ ChangeLog	17 Apr 2006 12:28:05 -0000
@@ -1,5 +1,13 @@
+2006-04-17  Manjunath  <manjunath.kadajji@wipro.com>
+
+	* shell/eog-window.c (save_error): Check for read-only status 
+	and file ownership before overwriting.
+	(is_read_only): Check whether file is read-only.
+	(is_owner): Check the owner of the file. 
+	Fixes bugzilla bug #320688. 
+
 2006-03-31  Lucas Rocha  <lucasr@gnome.org>
 
 	* libeog/eog-image-list.c (vfs_monitor_dir_cb): checks mimetype
 	before trying to include new detected files on image list (Fixes
 	bug #336050).
Index: shell/eog-window.c
===================================================================
RCS file: /export/cvs/head/eog/shell/eog-window.c,v
retrieving revision 1.189
diff -p -u -5 -r1.189 eog-window.c
--- shell/eog-window.c	27 Mar 2006 01:29:14 -0000	1.189
+++ shell/eog-window.c	17 Apr 2006 12:28:05 -0000
@@ -942,10 +942,55 @@ save_update_image (EogImage *image)
 	return FALSE;
 }
 #endif
 
 static gboolean
+is_read_only (const gchar *uri)
+{
+	gboolean ret = TRUE; /* default to read only */
+	GnomeVFSFileInfo *info;
+        
+	g_return_val_if_fail (uri != NULL, FALSE);
+
+	info = gnome_vfs_file_info_new ();
+
+	if (gnome_vfs_get_file_info (uri,
+				     info,
+				     GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
+				     GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS) == GNOME_VFS_OK) {
+		if (info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_ACCESS)
+			ret = !(info->permissions & GNOME_VFS_PERM_ACCESS_WRITABLE);
+	}
+
+	gnome_vfs_file_info_unref (info);
+
+	return ret;
+}
+
+static gboolean
+is_owner (const gchar *uri)
+{
+	gboolean ret = FALSE;
+	GnomeVFSFileInfo *info;
+
+	g_return_val_if_fail (uri != NULL, FALSE);
+
+	info = gnome_vfs_file_info_new ();
+
+	if (gnome_vfs_get_file_info (uri,
+				     info,
+				     GNOME_VFS_FILE_INFO_FOLLOW_LINKS |
+				     GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS) == GNOME_VFS_OK) {
+		if ((info -> uid == getuid()) || (info -> uid == geteuid())) 
+			ret = TRUE;
+	}
+
+	gnome_vfs_file_info_unref (info);
+	return ret;
+}
+
+static gboolean
 save_error (SaveErrorData *edata)
 {
 	GtkWidget *dlg;
 	char *header;
 	char *detail = NULL;
@@ -961,29 +1006,63 @@ save_error (SaveErrorData *edata)
 
 	/* display generic error dialog, except for FILE_EXISTS error */
 	if (err_code == EOG_IMAGE_ERROR_FILE_EXISTS) {
 		char *str;
 
-	       	str = gnome_vfs_uri_to_string (edata->dest->uri, 
+		str = gnome_vfs_uri_to_string (edata->dest->uri, 
 					       GNOME_VFS_URI_HIDE_TOPLEVEL_METHOD);
 		
-		header = g_strdup_printf (_("Overwrite file %s?"), str);
-		detail = _("File exists. Do you want to overwrite it?");
-		g_free (str);
-
-		dlg = gtk_message_dialog_new (GTK_WINDOW (edata->window),
-					      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
-					      GTK_MESSAGE_ERROR,
-					      GTK_BUTTONS_NONE,
-					      header);
-		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
-							  detail);
-
-		gtk_dialog_add_button (GTK_DIALOG (dlg), _("Skip"), EOG_SAVE_RESPONSE_SKIP);
-		gtk_dialog_add_button (GTK_DIALOG (dlg), _("Overwrite"), EOG_SAVE_RESPONSE_OVERWRITE);
-		gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, EOG_SAVE_RESPONSE_CANCEL);
-		gtk_dialog_set_default_response (GTK_DIALOG (dlg), EOG_SAVE_RESPONSE_SKIP);
+		if (is_read_only (str)) {
+			if (is_owner (str)) {
+				header = g_strdup_printf (_("Overwrite readonly file %s?"), str);
+				detail = _("File is read-only. Do you want to try to overwrite it?");
+				dlg = gtk_message_dialog_new (GTK_WINDOW (edata->window),
+							      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+							      GTK_MESSAGE_ERROR,
+							      GTK_BUTTONS_NONE,
+							      header);
+				gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+									  detail);
+
+				gtk_dialog_add_button (GTK_DIALOG (dlg), _("Overwrite"), EOG_SAVE_RESPONSE_OVERWRITE);
+				gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, EOG_SAVE_RESPONSE_CANCEL);
+				gtk_dialog_set_default_response (GTK_DIALOG (dlg), EOG_SAVE_RESPONSE_CANCEL);
+			}
+			else {
+				header = g_strdup_printf (_("You are not the owner of the file %s?"), str);
+				detail = _("You do not have the permissions to overwrite this file");
+				dlg = gtk_message_dialog_new (GTK_WINDOW (edata->window),
+							      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+							      GTK_MESSAGE_ERROR,
+							      GTK_BUTTONS_NONE,
+							      header);
+                		gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+									  detail);
+
+                		gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, EOG_SAVE_RESPONSE_CANCEL);
+                		gtk_dialog_set_default_response (GTK_DIALOG (dlg), EOG_SAVE_RESPONSE_CANCEL);
+			}
+			g_free(str);
+		}
+		else {
+			header = g_strdup_printf (_("Overwrite file %s?"), str);
+			detail = _("File exists. Do you want to overwrite it?");
+			g_free (str);
+
+			dlg = gtk_message_dialog_new (GTK_WINDOW (edata->window),
+						      GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+						      GTK_MESSAGE_ERROR,
+						      GTK_BUTTONS_NONE,
+						      header);
+			gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+								  detail);
+			
+			gtk_dialog_add_button (GTK_DIALOG (dlg), _("Skip"), EOG_SAVE_RESPONSE_SKIP);
+			gtk_dialog_add_button (GTK_DIALOG (dlg), _("Overwrite"), EOG_SAVE_RESPONSE_OVERWRITE);
+			gtk_dialog_add_button (GTK_DIALOG (dlg), GTK_STOCK_CANCEL, EOG_SAVE_RESPONSE_CANCEL);
+			gtk_dialog_set_default_response (GTK_DIALOG (dlg), EOG_SAVE_RESPONSE_SKIP);
+		}
 	}
 	else {
 		header = g_strdup_printf (_("Error on saving %s."), eog_image_get_caption (edata->image));
 
 		dlg = gtk_message_dialog_new (GTK_WINDOW (edata->window),
