Index: gedit/gedit-tab.c
===================================================================
--- gedit/gedit-tab.c	(revision 5420)
+++ gedit/gedit-tab.c	(working copy)
@@ -1311,7 +1311,8 @@
 						  G_CALLBACK (externally_modified_error_message_area_response),
 						  tab);
 			}
-			else if (error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP)
+			else if (error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP ||
+				 error->code == GEDIT_DOCUMENT_ERROR_INVALID_BACKUP_DIR)
 			{
 				/* This error is recoverable */
 				emsg = gedit_no_backup_saving_error_message_area_new (
Index: gedit/gedit-io-error-message-area.c
===================================================================
--- gedit/gedit-io-error-message-area.c	(revision 5420)
+++ gedit/gedit-io-error-message-area.c	(working copy)
@@ -1045,7 +1045,8 @@
 	g_return_val_if_fail (uri != NULL, NULL);
 	g_return_val_if_fail (error != NULL, NULL);
 	g_return_val_if_fail (error->domain == GEDIT_DOCUMENT_ERROR, NULL);
-	g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP, NULL);
+	g_return_val_if_fail (error->code == GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP ||
+			      error->code == GEDIT_DOCUMENT_ERROR_INVALID_BACKUP_DIR, NULL);
 
 	full_formatted_uri = gedit_utils_format_uri_for_display (uri);
 
@@ -1104,9 +1105,17 @@
 	GTK_WIDGET_SET_FLAGS (primary_label, GTK_CAN_FOCUS);
 	gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
 
-	secondary_text = _("gedit could not backup the old copy of the file before saving the new one. "
-			   "You can ignore this warning and save the file anyway, but if an error "
-			   "occurs while saving, you could lose the old copy of the file. Save anyway?");
+	if (error->code == GEDIT_DOCUMENT_ERROR_INVALID_BACKUP_DIR)
+		secondary_text = _("gedit could not backup the old copy of the file to the backup "
+				   "folder specified in the preferences. Please make sure that the "
+				   "backup folder path is valid.\n"
+				   "You can ignore this warning and save the file anyway, but if an error "
+				   "occurs while saving, you could lose the old copy of the file. Save anyway?");
+	else
+		secondary_text = _("gedit could not backup the old copy of the file before saving the new one. "
+				   "You can ignore this warning and save the file anyway, but if an error "
+				   "occurs while saving, you could lose the old copy of the file. Save anyway?");
+
   	secondary_markup = g_strdup_printf ("<small>%s</small>",
 					    secondary_text);
 	secondary_label = gtk_label_new (secondary_markup);
Index: gedit/gedit-document.h
===================================================================
--- gedit/gedit-document.h	(revision 5420)
+++ gedit/gedit-document.h	(working copy)
@@ -134,6 +134,7 @@
 	GEDIT_DOCUMENT_ERROR_EXTERNALLY_MODIFIED = GNOME_VFS_NUM_ERRORS,
 	GEDIT_DOCUMENT_ERROR_NOT_REGULAR_FILE,
 	GEDIT_DOCUMENT_ERROR_CANT_CREATE_BACKUP,
+	GEDIT_DOCUMENT_ERROR_INVALID_BACKUP_DIR,
 	GEDIT_DOCUMENT_NUM_ERRORS 
 };
 
Index: gedit/gedit-prefs-manager.c
===================================================================
--- gedit/gedit-prefs-manager.c	(revision 5420)
+++ gedit/gedit-prefs-manager.c	(working copy)
@@ -521,6 +521,38 @@
 		  GPM_CREATE_BACKUP_COPY,
 		  GPM_DEFAULT_CREATE_BACKUP_COPY)
 
+/* Create backups in current directory? */
+DEFINE_BOOL_PREF (backups_in_current_dir,
+		  GPM_BACKUPS_IN_CURRENT_DIR,
+		  GPM_DEFAULT_BACKUPS_IN_CURRENT_DIR)
+
+/* Backup copy directory */
+gchar *
+gedit_prefs_manager_get_backup_copy_directory (void)
+{
+	gedit_debug (DEBUG_PREFS);
+
+	return gedit_prefs_manager_get_string (GPM_BACKUP_COPY_DIRECTORY,
+					       GPM_DEFAULT_BACKUP_COPY_DIRECTORY);
+}
+
+void
+gedit_prefs_manager_set_backup_copy_directory (const gchar *dir)
+{
+	gedit_debug (DEBUG_PREFS);
+	
+	gedit_prefs_manager_set_string (GPM_BACKUP_COPY_DIRECTORY,
+					dir);
+}
+
+gboolean
+gedit_prefs_manager_backup_copy_directory_can_set (void)
+{
+	gedit_debug (DEBUG_PREFS);
+
+	return gedit_prefs_manager_key_is_writable (GPM_BACKUP_COPY_DIRECTORY);
+}
+
 /* Backup extension. This is configurable only using gconftool or gconf-editor */
 gchar *
 gedit_prefs_manager_get_backup_extension (void)
Index: gedit/gedit-prefs-manager.h
===================================================================
--- gedit/gedit-prefs-manager.h	(revision 5420)
+++ gedit/gedit-prefs-manager.h	(working copy)
@@ -54,6 +54,8 @@
 
 #define GPM_SAVE_DIR			GPM_PREFS_DIR  "/editor/save"
 #define GPM_CREATE_BACKUP_COPY  	GPM_SAVE_DIR "/create_backup_copy"
+#define GPM_BACKUPS_IN_CURRENT_DIR	GPM_SAVE_DIR "/backups_in_current_dir"
+#define GPM_BACKUP_COPY_DIRECTORY	GPM_SAVE_DIR "/backup_copy_directory"
 #define GPM_BACKUP_COPY_EXTENSION	GPM_SAVE_DIR "/backup_copy_extension"
 
 #define GPM_AUTO_SAVE			GPM_SAVE_DIR "/auto_save"
@@ -164,6 +166,8 @@
 #define GPM_DEFAULT_SELECTION_COLOR	(const gchar*) "#000000009c9c"
 
 #define GPM_DEFAULT_CREATE_BACKUP_COPY	1 /* TRUE */
+#define GPM_DEFAULT_BACKUPS_IN_CURRENT_DIR 1 /* TRUE */
+#define GPM_DEFAULT_BACKUP_COPY_DIRECTORY (const gchar*) ".gnome/gedit/backups"
 #define GPM_DEFAULT_BACKUP_COPY_EXTENSION (const gchar*) "~"
 
 #define GPM_DEFAULT_AUTO_SAVE		0 /* FALSE */
@@ -293,6 +297,16 @@
 /* Backup extension. This is configurable only using gconftool or gconf-editor */
 gchar			*gedit_prefs_manager_get_backup_extension	(void);
 
+/* Backups in current dir */
+gboolean		 gedit_prefs_manager_get_backups_in_current_dir (void);
+void			 gedit_prefs_manager_set_backups_in_current_dir (gboolean bcd);
+gboolean		 gedit_prefs_manager_backups_in_current_dir_can_set (void);
+
+/* Backup copy directory */
+gchar			*gedit_prefs_manager_get_backup_copy_directory  (void);
+void			 gedit_prefs_manager_set_backup_copy_directory  (const gchar *directory);
+gboolean		 gedit_prefs_manager_backup_copy_directory_can_set (void);
+
 /* Auto save */
 gboolean		 gedit_prefs_manager_get_auto_save		(void);
 void			 gedit_prefs_manager_set_auto_save		(gboolean as);
Index: gedit/gedit-document-saver.c
===================================================================
--- gedit/gedit-document-saver.c	(revision 5420)
+++ gedit/gedit-document-saver.c	(working copy)
@@ -72,6 +72,7 @@
 	gboolean		  keep_backup;
 	gchar			 *backup_ext;
 	gboolean                  backups_in_curr_dir;
+	gchar			 *backup_dir;
 
 	time_t                    doc_mtime;
 	gchar                    *mime_type; //CHECK use FileInfo instead?
@@ -116,6 +117,7 @@
 		gnome_vfs_uri_unref (priv->vfs_uri);
 
 	g_free (priv->backup_ext);
+	g_free (priv->backup_dir);
 
 	g_free (priv->local_path);
 	g_free (priv->mime_type);
@@ -328,11 +330,12 @@
 }
 
 static gchar *
-get_backup_filename (GeditDocumentSaver *saver)
+get_backup_filename_in_current_dir (GeditDocumentSaver *saver)
 {
 	gchar *fname;
-	gchar *bak_ext = NULL;
 
+	gchar *bak_ext;
+
 	if ((saver->priv->backup_ext != NULL) &&
 	    (strlen (saver->priv->backup_ext) > 0))
 		bak_ext = saver->priv->backup_ext;
@@ -368,6 +371,106 @@
 	return fname;
 }
 
+static gchar *
+mangle_local_filename (const gchar *local_name)
+{
+	/* for now I am just using the basename */
+	/* TODO: mangle the whole file path so
+	 * that /opt/foo/bar.txt becomes opt-foo-bar.txt
+	 * but /home/paolo/stuff/bar.txt just becomes
+	 * stuff-bar.txt */
+
+	return g_path_get_basename (local_name);
+}
+
+static gchar *
+get_backup_filename (GeditDocumentSaver *saver, GError **error)
+{
+	gchar *fname;
+	int ret;
+	gchar *real_backup_dir;
+	gchar *basename = NULL;
+
+	/* Save backup in current dir */
+	if (saver->priv->backups_in_curr_dir ||
+	    (!saver->priv->keep_backup))
+	{
+		fname = get_backup_filename_in_current_dir (saver);
+
+		if (fname == NULL)
+		{
+			/* bad bad luck... */
+			g_warning (_("Could not obtain backup filename"));
+
+			g_set_error (error,
+				     GEDIT_DOCUMENT_ERROR,
+				     GNOME_VFS_ERROR_GENERIC,
+				     gnome_vfs_result_to_string (GNOME_VFS_ERROR_GENERIC));
+
+			return NULL;
+		}
+
+		return fname;
+	}
+
+	if (saver->priv->backup_dir == NULL)
+	{
+		/* actually we should never get here */
+		g_warning ("backup_dir was NULL");
+		goto error;
+	}
+
+	if (g_path_is_absolute (saver->priv->backup_dir))
+	{
+		real_backup_dir = g_strdup (saver->priv->backup_dir);
+	}
+	else if (saver->priv->backup_dir[0] == '.' &&
+		 saver->priv->backup_dir[1] == '/')
+	{
+		gchar *tmp;
+
+		tmp = g_path_get_dirname (saver->priv->local_path);
+		real_backup_dir = g_build_filename (tmp,
+						    saver->priv->backup_dir,
+						    NULL);
+		g_free (tmp);
+	}
+	else
+	{
+		real_backup_dir = g_build_filename (g_get_home_dir (),
+						    saver->priv->backup_dir,
+						    NULL);
+	}
+
+	ret = g_mkdir_with_parents (real_backup_dir, 0777);
+	if (ret == -1)
+		goto error;
+
+	basename = mangle_local_filename (saver->priv->local_path);
+	if (basename == NULL)
+		goto error;
+
+	fname = g_build_filename (real_backup_dir, basename, NULL);
+
+	g_free (real_backup_dir);	
+	g_free (basename);
+
+	return fname;
+
+ error:
+	/* FIXME: how do we propagate up the reason why
+	 * the specified backup dir does not work? */
+
+	g_set_error (error,
+		     GEDIT_DOCUMENT_ERROR,
+		     GEDIT_DOCUMENT_ERROR_INVALID_BACKUP_DIR,
+		     "No backup created: invalid backup dir");
+
+	g_free (basename);
+
+	return NULL;
+}
+
 /* like unlink, but doesn't fail if the file wasn't there at all */
 static gboolean
 remove_file (const gchar *name)
@@ -560,21 +663,6 @@
 		goto out;
 	}
 
-	/* prepare the backup name */
-	backup_filename = get_backup_filename (saver);
-	if (backup_filename == NULL)
-	{
-		/* bad bad luck... */
-		g_warning (_("Could not obtain backup filename"));
-
-		g_set_error (&saver->priv->error,
-			     GEDIT_DOCUMENT_ERROR,
-			     GNOME_VFS_ERROR_GENERIC,
-			     gnome_vfs_result_to_string (GNOME_VFS_ERROR_GENERIC));
-
-		goto out;
-	}
-
 	/* We now use two backup strategies.
 	 * The first one (which is faster) consist in saving to a
 	 * tmp file then rename the original file to the backup and the
@@ -662,6 +750,20 @@
 			goto out;
 		}
 
+		backup_filename = get_backup_filename (saver, &saver->priv->error);
+		if (backup_filename == NULL)
+		{
+			/* this should never happen, since we do not
+			 * use backup dir in this strategy */
+			gedit_debug_message (DEBUG_SAVER, "could get backup filename");
+
+			close (tmpfd);
+			unlink (tmp_filename);
+			g_free (tmp_filename);
+
+			goto out;
+		}
+
 		/* original -> backup */
 		if (rename (saver->priv->local_path, backup_filename) != 0)
 		{
@@ -760,6 +862,14 @@
 
 		gedit_debug_message (DEBUG_SAVER, "copying to backup");
 
+		backup_filename = get_backup_filename (saver, &saver->priv->error);
+		if (backup_filename == NULL)
+		{
+			gedit_debug_message (DEBUG_SAVER, "could get backup filename");
+
+			goto out;
+		}
+
 		/* move away old backups */
 		if (!remove_file (backup_filename))
 		{
@@ -1459,9 +1569,14 @@
 	else
 		saver->priv->keep_backup = gedit_prefs_manager_get_create_backup_copy ();
 
-	/* TODO: add support for configurable backup dir */
-	saver->priv->backups_in_curr_dir = TRUE;
+	/* is there a specified dir for backups */
+	saver->priv->backups_in_curr_dir = gedit_prefs_manager_get_backups_in_current_dir ();
 
+	if (saver->priv->backups_in_curr_dir == FALSE)
+		saver->priv->backup_dir = gedit_prefs_manager_get_backup_copy_directory ();
+	else
+		saver->priv->backup_dir = NULL;
+
 	if (encoding != NULL)
 		saver->priv->encoding = encoding;
 	else
Index: data/gedit.schemas.in
===================================================================
--- data/gedit.schemas.in	(revision 5420)
+++ data/gedit.schemas.in	(working copy)
@@ -117,6 +117,38 @@
     </schema>
 
     <schema>
+      <key>/schemas/apps/gedit-2/preferences/editor/save/backups_in_current_dir</key>
+      <applyto>/apps/gedit-2/preferences/editor/save/backups_in_current_dir</applyto>
+      <owner>gedit</owner>
+      <type>bool</type>
+      <default>TRUE</default>
+      <locale name="C">
+	<short>Backups In Current Directory</short>
+	<long>Whether gedit should create its backups in the file's current
+	folder or in the folder specified by the "Backup Copy Directory"
+	option. This option only takes effect if "Create Backup Copies"
+	is true.</long>
+      </locale>
+    </schema>
+
+    <schema>
+      <key>/schemas/apps/gedit-2/preferences/editor/save/backup_copy_directory</key>
+      <applyto>/apps/gedit-2/preferences/editor/save/backup_copy_directory</applyto>
+      <owner>gedit</owner>
+      <type>string</type>
+      <default>.gnome2/gedit/backups</default>
+      <locale name="C">
+	<short>Backup Copy Directory</short>
+	<long>Path to use to store backup copies of files in. This will only
+	take effect if both the "Create Backup Copies" and "Backups In Current
+	Directory" options are on. It can be an absolute or relative path.
+	If the path is relative and starts with "./" it is considered relative
+	to the current document folder otherwise it is considered relative
+	to Home.</long>
+      </locale>
+    </schema>
+
+    <schema>
       <key>/schemas/apps/gedit-2/preferences/editor/save/backup_copy_extension</key>
       <applyto>/apps/gedit-2/preferences/editor/save/backup_copy_extension</applyto>
       <owner>gedit</owner>
