[gedit-list] Re: [gnome-love] gedit tasks



Some thoughts about this TODO list:

For the « Saving file using gnome-vfs (Resp: Paolo) » item, I've got the following patch there which needs some love, but may be a starting point. Maybe there should be a link to it from the TODO page. It mainly lacks two things : a way to correctly detect if an uri is writeable, and the saving part needs to be reviewed/partially rewritten to be cleaner. I'll probably rework on that patch in a few weeks if it's not done at this time.
Another problem with that item is that in difficult tasks, there is a « The remote files should be read in an async way (Resp: Paolo) », so remote files should also be written in an async way, which makes the « Saving file using gnome-vfs » task a difficult one ?

Regards,

Christophe


Paolo Maggi <maggi athena polito it> wrote:

> Hi,
>     we have just updated the gedit TODO list 
> (http://cvs.gnome.org/lxr/source/gedit/TODO).
> If you want to claim a task of this list, please contact the responsible 
> person and eventually send a mail to the gedit list.
> We have 4 kind of tasks: difficult tasks, normal tasks, easy tasks and 
> tasks for non developers.
> So, even if you are not a developers or you have only a limited 
> experience, you can find tasks for you as well.
> 
> Please, read the HACKING file 
> (http://cvs.gnome.org/lxr/source/gedit/HACKING) for info about CVS 
> guidelines for gedit.
> 
> ATM, we are using CVS HEAD for gedit development.
> If you are new to CVS, read http://developer.gnome.org/tools/cvs.html
> 
> Best wishes,
> The gedit team
> 
> 
> _______________________________________________
> gnome-love mailing list
> gnome-love gnome org
> http://mail.gnome.org/mailman/listinfo/gnome-love
? src/.gedit-save-IPtD38
? src/.gedit-save-srd6Ba
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/gedit/src/Makefile.am,v
retrieving revision 1.89
diff -u -r1.89 Makefile.am
--- src/Makefile.am	8 Jul 2002 14:01:46 -0000	1.89
+++ src/Makefile.am	23 Aug 2002 14:37:36 -0000
@@ -1,3 +1,4 @@
+
 ## Process this file with automake to produce Makefile.in
 SUBDIRS= dialogs
 
Index: src/gedit-document.c
===================================================================
RCS file: /cvs/gnome/gedit/src/gedit-document.c,v
retrieving revision 1.48
diff -u -r1.48 gedit-document.c
--- src/gedit-document.c	13 Aug 2002 18:31:00 -0000	1.48
+++ src/gedit-document.c	23 Aug 2002 14:37:38 -0000
@@ -1218,6 +1218,9 @@
 	gint fd;
 	gint retval;
 	GeditSaveEncodingSetting encoding_setting;
+	GnomeVFSURI *temp_uri = NULL;
+	GnomeVFSURI *real_uri = NULL;
+	GnomeVFSResult result;
 	
 	gedit_debug (DEBUG_DOCUMENT, "");
 
@@ -1232,6 +1235,7 @@
 	backup_filename = NULL;
 	temp_filename = NULL;
 
+#ifdef TOTO
 	/* We don't support non-file:/// stuff */
 
 	if (!gedit_utils_uri_has_file_scheme (uri))
@@ -1259,52 +1263,57 @@
 		g_free (error_message);
 		return FALSE;
 	}
+#endif
+	if (gedit_utils_uri_has_file_scheme (uri)) {
+		/* Get filename from uri */
+		filename = gnome_vfs_get_local_path_from_uri (uri);
+		
+		if (!filename)
+		{
+			g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, 0,
+				     _("Invalid filename."));
+			goto out;
+		}
+		
+		/* Get the real filename and file permissions */
+		
+		real_filename = follow_symlinks (filename, error);
+		
+		if (!real_filename)
+			goto out;
 
-	/* Get filename from uri */
-	filename = gnome_vfs_get_local_path_from_uri (uri);
-
-	if (!filename)
-	{
-		g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, 0,
-			     _("Invalid filename."));
-		goto out;
-	}
-
-	/* Get the real filename and file permissions */
-
-	real_filename = follow_symlinks (filename, error);
-
-	if (!real_filename)
-		goto out;
+		if (stat (real_filename, &st) != 0)
+		{
+			/* File does not exist? */
+			create_backup_copy = FALSE;
+			
+			/* Use default permissions */
+			st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
+			st.st_uid = getuid ();
+			st.st_gid = getgid ();
+		}
+		
+		/* Save to a temporary file.  We set the umask because some (buggy)
+		 * implementations of mkstemp() use permissions 0666 and we want 0600.
+		 */
 
-	if (stat (real_filename, &st) != 0)
-	{
-		/* File does not exist? */
-		create_backup_copy = FALSE;
+		slashpos = strrchr (real_filename, G_DIR_SEPARATOR);
 
-		/* Use default permissions */
-		st.st_mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
-		st.st_uid = getuid ();
-		st.st_gid = getgid ();
+		if (slashpos)
+		{
+			dirname = g_strdup (real_filename);
+			dirname[slashpos - real_filename + 1] = '\0';
+		}
+		else
+			dirname = g_strdup (".");
+		
+		temp_filename = g_build_filename (dirname, ".gedit-save-XXXXXX", NULL);
+		g_free (dirname);
+	} else {
+		real_filename = g_strdup(uri);
+		temp_filename = g_strdup("/tmp/gedit-save-XXXXXX");
 	}
 
-	/* Save to a temporary file.  We set the umask because some (buggy)
-	 * implementations of mkstemp() use permissions 0666 and we want 0600.
-	 */
-
-	slashpos = strrchr (real_filename, G_DIR_SEPARATOR);
-
-	if (slashpos)
-	{
-		dirname = g_strdup (real_filename);
-		dirname[slashpos - real_filename + 1] = '\0';
-	}
-	else
-		dirname = g_strdup (".");
-
-	temp_filename = g_build_filename (dirname, ".gedit-save-XXXXXX", NULL);
-	g_free (dirname);
-
 	saved_umask = umask (0077);
 	fd = g_mkstemp (temp_filename); /* this modifies temp_filename to the used name */
 	umask (saved_umask);
@@ -1315,6 +1324,9 @@
 		goto out;
 	}
 
+	real_uri = gnome_vfs_uri_new(real_filename);
+	temp_uri = gnome_vfs_uri_new(temp_filename);
+
       	chars = gedit_document_get_buffer (doc);
 
 	encoding_setting = gedit_prefs_manager_get_save_encoding ();
@@ -1408,20 +1420,26 @@
 		goto out;
 	}
 
+/*	if (!gedit_utils_uri_has_file_scheme (uri)) {
+		goto out;
+	}*/
+
 	/* Move the original file to a backup */
 
 	if (create_backup_copy)
 	{
-		gint result;
-
+		GnomeVFSURI *backup_uri;
+		
 		backup_filename = g_strconcat (real_filename, 
-				               gedit_prefs_manager_get_backup_extension (), 
+					       gedit_prefs_manager_get_backup_extension (), 
 					       NULL);
-
-		result = rename (real_filename, backup_filename);
-
-		if (result != 0)
-		{
+		
+		backup_uri = gnome_vfs_uri_new(backup_filename);
+		result = gnome_vfs_xfer_uri(real_uri, backup_uri, GNOME_VFS_XFER_DELETE_ITEMS, GNOME_VFS_XFER_ERROR_MODE_ABORT, GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, NULL, NULL);
+		gnome_vfs_uri_unref(backup_uri);
+		
+		if (result != GNOME_VFS_OK) 
+		{			
 			g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, errno,
 				     _("Could not create a backup file."));
 			unlink (temp_filename);
@@ -1429,30 +1447,33 @@
 		}
 	}
 
-	/* Move the temp file to the original file */
-
-	if (rename (temp_filename, real_filename) != 0)
-	{
-		gint saved_errno;
-
-		saved_errno = errno;
-
-		if (create_backup_copy && rename (backup_filename, real_filename) != 0)
-			g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, saved_errno,
-				     " ");
-		else
-			g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, saved_errno,
-				     " ");
-
+	/* Move the temp file to the original file */	
+	result = gnome_vfs_xfer_uri(temp_uri, real_uri, GNOME_VFS_XFER_DELETE_ITEMS, GNOME_VFS_XFER_ERROR_MODE_ABORT, GNOME_VFS_XFER_OVERWRITE_MODE_REPLACE, NULL, NULL);
+	if (result != GNOME_VFS_OK)
+	{
+		g_set_error (error, GEDIT_DOCUMENT_IO_ERROR, result,
+			     " ");
+		
+		if (create_backup_copy)
+		{
+			GnomeVFSURI *backup_uri = gnome_vfs_uri_new(backup_filename);
+			result = gnome_vfs_xfer_uri(backup_uri, real_uri, 0, GNOME_VFS_XFER_ERROR_MODE_ABORT, GNOME_VFS_XFER_OVERWRITE_MODE_ABORT, NULL, NULL);
+			gnome_vfs_uri_unref(backup_uri);
+		}
+		
 		goto out;
 	}
-
-	/* Restore permissions.  There is not much error checking we can do
-	 * here, I'm afraid.  The final data is saved anyways.
-	 */
-
-	chmod (real_filename, st.st_mode);
-	chown (real_filename, st.st_uid, st.st_gid);
+	
+	if (gedit_utils_uri_has_file_scheme (uri)) 
+	{		
+		
+		/* Restore permissions.  There is not much error checking we can do
+		 * here, I'm afraid.  The final data is saved anyways.
+		 */
+		
+		chmod (real_filename, st.st_mode);
+		chown (real_filename, st.st_uid, st.st_gid);
+	}
 
 	gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (doc), FALSE);
 
@@ -1461,7 +1482,8 @@
 	/* Done */
 
  out:
-
+	gnome_vfs_uri_unref(temp_uri);
+	gnome_vfs_uri_unref(real_uri);
 	g_free (filename);
 	g_free (real_filename);
 	g_free (backup_filename);
Index: src/gedit-utils.c
===================================================================
RCS file: /cvs/gnome/gedit/src/gedit-utils.c,v
retrieving revision 1.33
diff -u -r1.33 gedit-utils.c
--- src/gedit-utils.c	23 Jul 2002 15:30:46 -0000	1.33
+++ src/gedit-utils.c	23 Aug 2002 14:37:39 -0000
@@ -213,22 +213,36 @@
 {
 	gchar* file_uri = NULL;
 	gchar* canonical_uri = NULL;
-
+	GnomeVFSHandle *handle;
+	GnomeVFSResult result;
 	gint res;
 
 	g_return_val_if_fail (uri != NULL, TRUE);
 	
 	gedit_debug (DEBUG_FILE, "URI: %s", uri);
 
-	/* FIXME: all remote files are marked as readonly */
-	if (!gedit_utils_uri_has_file_scheme (uri))
-		return TRUE;
-			
 	canonical_uri = eel_make_uri_canonical (uri);
 	g_return_val_if_fail (canonical_uri != NULL, TRUE);
-	
+
 	gedit_debug (DEBUG_FILE, "CANONICAL URI: %s", canonical_uri);
 
+	/* FIXME: opening and then closing the file to see if it's read-only */
+	/* sucks, there must have a better way to do that with gnome-vfs     */
+	if (!gedit_utils_uri_has_file_scheme (uri))
+	{
+/*		result = gnome_vfs_open(&handle, canonical_uri, 
+					GNOME_VFS_OPEN_WRITE);
+		if (result == GNOME_VFS_OK) {
+			gnome_vfs_close(handle);
+			g_print("File is writeable\n");
+			return FALSE;
+		} else {
+			g_print("File is not writeable\n");
+			return TRUE;
+		}*/
+		return FALSE;
+	}
+			
 	file_uri = gnome_vfs_get_local_path_from_uri (canonical_uri);
 	if (file_uri == NULL)
 	{


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