changeset 10605:56d4460bb6bd

[gaim-migrate @ 12037] This makes us remember the last used folders for saving files, opening files, and buddy icons (separately). Also fixes a file transfer crash when you decide not to overwrite an existing file but then choose a different file to save to. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 16 Feb 2005 21:07:10 +0000
parents 255225f7639e
children 1a65fc2d7978
files src/gtkaccount.c src/gtkprefs.c src/gtkrequest.c
diffstat 3 files changed, 82 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkaccount.c	Wed Feb 16 20:31:46 2005 +0000
+++ b/src/gtkaccount.c	Wed Feb 16 21:07:10 2005 +0000
@@ -244,7 +244,7 @@
 static void
 icon_filesel_choose_cb(GtkWidget *widget, gint response, AccountPrefsDialog *dialog)
 {
-	char *filename;
+	char *filename, *current_folder;
 
 	if (response != GTK_RESPONSE_ACCEPT) {
 		if (response == GTK_RESPONSE_CANCEL)
@@ -254,22 +254,35 @@
 	}
 
 	filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->icon_filesel));
+	current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(dialog->icon_filesel));
+	if (current_folder != NULL) {
+		gaim_prefs_set_string("/gaim/gtk/filelocations/last_icon_folder", current_folder);
+		g_free(current_folder);
+	}
+
 #else /* FILECHOOSER */
 static void
 icon_filesel_choose_cb(GtkWidget *w, AccountPrefsDialog *dialog)
 {
-	char *filename;
+	char *filename, *current_folder;
 
 	filename = g_strdup(gtk_file_selection_get_filename(
-			GTK_FILE_SELECTION(dialog->icon_filesel)));
+				GTK_FILE_SELECTION(dialog->icon_filesel)));
 
 	/* If they typed in a directory, change there */
 	if (gaim_gtk_check_if_dir(filename,
-			GTK_FILE_SELECTION(dialog->icon_filesel)))
+				GTK_FILE_SELECTION(dialog->icon_filesel)))
 	{
 		g_free(filename);
 		return;
 	}
+
+	current_folder = g_path_get_dirname(filename);
+	if (current_folder != NULL) {
+		gaim_prefs_set_string("/gaim/gtk/filelocations/last_icon_folder", current_folder);
+		g_free(current_folder);
+	}
+
 #endif /* FILECHOOSER */
 
 	if (dialog->icon_path)
@@ -367,12 +380,14 @@
 	GtkWidget *tv;
 	GtkTreeSelection *sel;
 #endif /* FILECHOOSER */
+	const char *current_folder;
 
 	if (dialog->icon_filesel != NULL) {
 		gtk_window_present(GTK_WINDOW(dialog->icon_filesel));
 		return;
 	}
 
+	current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_icon_folder");
 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
 	dialog->icon_filesel = gtk_file_chooser_dialog_new(_("Buddy Icon"),
 									GTK_WINDOW(dialog->window),
@@ -381,22 +396,14 @@
 									GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
 									NULL);
 	gtk_dialog_set_default_response(GTK_DIALOG(dialog->icon_filesel), GTK_RESPONSE_ACCEPT);
-
-
-	/*  I removed code to set the current path to the current icon in the old file selector so I figure
-	 * it shouldn't be here either.  The reason is because the icon will potentially converted and won't
-	 * be anything near what the user selected last time (which is the advantage to doing it this way. 
-	 * The solution is to create a new pref to specify the last chosen buddy icon.  This would also have the
-	 * advantage (?) of not being account-specific. 
-	if (dialog->icon_path != NULL)
-		gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog->icon_filesel),
-			dialog->icon_path);
-	*/
+	if ((current_folder != NULL) && (*current_folder != '\0'))
+		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog->icon_filesel),
+											current_folder);
 
 	dialog->icon_preview = gtk_image_new();
 	dialog->icon_text = gtk_label_new(NULL);
 	gtk_widget_set_size_request(GTK_WIDGET(dialog->icon_preview), -1, 50);
-	gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog->icon_filesel), 
+	gtk_file_chooser_set_preview_widget(GTK_FILE_CHOOSER(dialog->icon_filesel),
 					    GTK_WIDGET(dialog->icon_preview));
 	g_signal_connect(G_OBJECT(dialog->icon_filesel), "update-preview",
 					 G_CALLBACK(icon_preview_change_cb), dialog);
@@ -407,6 +414,9 @@
 	dialog->icon_filesel = gtk_file_selection_new(_("Buddy Icon"));
 	dialog->icon_preview = gtk_image_new();
 	dialog->icon_text = gtk_label_new(NULL);
+	if ((current_folder != NULL) && (*current_folder != '\0'))
+		gtk_file_selection_set_filename(GTK_FILE_SELECTION(dialog->icon_filesel),
+										current_folder);
 
 	gtk_widget_set_size_request(GTK_WIDGET(dialog->icon_preview), -1, 50);
 	hbox = gtk_hbox_new(FALSE, 6);
--- a/src/gtkprefs.c	Wed Feb 16 20:31:46 2005 +0000
+++ b/src/gtkprefs.c	Wed Feb 16 21:07:10 2005 +0000
@@ -2293,6 +2293,12 @@
 	gaim_prefs_add_none("/gaim/gtk/plugins");
 	gaim_prefs_add_string_list("/gaim/gtk/plugins/loaded", NULL);
 
+	/* File locations */
+	gaim_prefs_add_none("/gaim/gtk/filelocations");
+	gaim_prefs_add_string("/gaim/gtk/filelocations/last_save_folder", "");
+	gaim_prefs_add_string("/gaim/gtk/filelocations/last_open_folder", "");
+	gaim_prefs_add_string("/gaim/gtk/filelocations/last_icon_folder", "");
+
 	/* Smiley Themes */
 	gaim_prefs_add_none("/gaim/gtk/smileys");
 	gaim_prefs_add_string("/gaim/gtk/smileys/theme", "default");
--- a/src/gtkrequest.c	Wed Feb 16 20:31:46 2005 +0000
+++ b/src/gtkrequest.c	Wed Feb 16 21:07:10 2005 +0000
@@ -1444,11 +1444,14 @@
 static void
 file_yes_no_cb(GaimGtkRequestData *data, gint id)
 {
-	if (data->cbs[id] != NULL)
-		((GaimRequestFileCb)data->cbs[id])(data->user_data, data->u.file.name);
-
-	if (id == 1)
+	/* Only call the callback if yes was selected, otherwise the request
+	 * (eg. file transfer) will be cancelled, then when a new filename is chosen
+	 * things go BOOM */
+	if (id == 1) {
+		if (data->cbs[1] != NULL)
+			((GaimRequestFileCb)data->cbs[1])(data->user_data, data->u.file.name);
 		gaim_request_close(GAIM_REQUEST_FILE, data);
+	}
 }
 
 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */
@@ -1465,18 +1468,23 @@
 	}
 
 	data->u.file.name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(data->dialog));
-	if (data->u.file.savedialog) {
-		current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(data->dialog));
-		if (current_folder) {
-			gaim_prefs_set_string("/gaim/gtk/filetransfer/last_folder", current_folder);
-			g_free(current_folder);
+	current_folder = gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(data->dialog));
+	if (current_folder != NULL) {
+		if (data->u.file.savedialog) {
+			gaim_prefs_set_string("/gaim/gtk/filelocations/last_save_folder", current_folder);
+		} else {
+			gaim_prefs_set_string("/gaim/gtk/filelocations/last_open_folder", current_folder);
 		}
+		g_free(current_folder);
 	}
+
 #else /* FILECHOOSER */
+
 static void
 file_ok_check_if_exists_cb(GtkWidget *button, GaimGtkRequestData *data)
 {
 	const gchar *name;
+	gchar *current_folder;
 
 	name = gtk_file_selection_get_filename(GTK_FILE_SELECTION(data->dialog));
 
@@ -1484,7 +1492,18 @@
 	if (gaim_gtk_check_if_dir(name, GTK_FILE_SELECTION(data->dialog)))
 		return;
 
+	current_folder = g_path_get_dirname(name);
+	if (current_folder != NULL) {
+		if (data->u.file.savedialog) {
+			gaim_prefs_set_string("/gaim/gtk/filelocations/last_save_folder", current_folder);
+		} else {
+			gaim_prefs_set_string("/gaim/gtk/filelocations/last_open_folder", current_folder);
+		}
+		g_free(current_folder);
+	}
+
 	data->u.file.name = g_strdup(name);
+
 #endif /* FILECHOOSER */
 
 	if ((data->u.file.savedialog == TRUE) &&
@@ -1516,6 +1535,7 @@
 {
 	GaimGtkRequestData *data;
 	GtkWidget *filesel;
+	const gchar *current_folder;
 
 	data = g_new0(GaimGtkRequestData, 1);
 	data->type = GAIM_REQUEST_FILE;
@@ -1539,24 +1559,36 @@
 						GTK_RESPONSE_ACCEPT,
 						NULL);
 	gtk_dialog_set_default_response(GTK_DIALOG(filesel), GTK_RESPONSE_ACCEPT);
-	if (filename != NULL) {
-		if (savedialog) {
-			const gchar *current_folder = gaim_prefs_get_string("/gaim/gtk/filetransfer/last_folder");
-			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel), filename);
-			if (current_folder) {
-				gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filesel), current_folder);
-			}
-		} else
-			gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(filesel), filename);
+
+	if (savedialog) {
+		current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_save_folder");
+	} else {
+		current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_open_folder");
 	}
+	if (filename != NULL)
+		gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(filesel), filename);
+	if ((current_folder != NULL) && (*current_folder != '\0'))
+		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(filesel), current_folder);
+
 	g_signal_connect(G_OBJECT(GTK_FILE_CHOOSER(filesel)), "response",
 					 G_CALLBACK(file_ok_check_if_exists_cb), data);
 #else /* FILECHOOSER */
 	filesel = gtk_file_selection_new(title ? title
 										   : (savedialog ? _("Save File...")
 														 : _("Open File...")));
+	if (savedialog) {
+		current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_save_folder");
+	} else {
+		current_folder = gaim_prefs_get_string("/gaim/gtk/filelocations/last_open_folder");
+	}
+	if (current_folder != NULL) {
+		gchar *path = g_strdup_printf("%s%s", current_folder, G_DIR_SEPARATOR_S);
+		gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), path);
+		g_free(path);
+	}
 	if (filename != NULL)
 		gtk_file_selection_set_filename(GTK_FILE_SELECTION(filesel), filename);
+
 	g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)), "delete_event",
 							 G_CALLBACK(file_cancel_cb), data);
 	g_signal_connect_swapped(G_OBJECT(GTK_FILE_SELECTION(filesel)->cancel_button),