[Rawstudio-commit] r3315 - trunk/src

Klaus Post klauspost at gmail.com
Fri Apr 2 19:34:55 CEST 2010


Author: post
Date: 2010-04-02 19:34:55 +0200 (Fri, 02 Apr 2010)
New Revision: 3315

Modified:
   trunk/src/rs-save-dialog.c
Log:
Export As: Set default filename with extension, change extension when choosing different file type & don't crash if no filename given.

Modified: trunk/src/rs-save-dialog.c
===================================================================
--- trunk/src/rs-save-dialog.c	2010-04-02 14:26:37 UTC (rev 3314)
+++ trunk/src/rs-save-dialog.c	2010-04-02 17:34:55 UTC (rev 3315)
@@ -107,6 +107,7 @@
 	dialog->chooser = gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_SAVE);
 	if (folder)
 		gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog->chooser), folder);
+
 	dialog->type_box = gui_confbox_new((const gchar *) "save-as-filetype");
 	dialog->pref_bin = gtk_alignment_new(0.0, 0.5, 1.0, 1.0);
 
@@ -133,9 +134,10 @@
 	gtk_box_pack_start(GTK_BOX(dialog->vbox), button_box, FALSE, TRUE, 0);
 
 	gtk_widget_show_all(dialog->vbox);
+
 	/* Set default action */
 	GTK_WIDGET_SET_FLAGS(button_save, GTK_CAN_DEFAULT);
-    gtk_window_set_default(window, button_save);
+	gtk_window_set_default(window, button_save);
 
 	gui_confbox_set_callback(dialog->type_box, dialog, file_type_changed);
 	savers = g_type_children (RS_TYPE_OUTPUT, &n_savers);
@@ -201,7 +203,24 @@
 	gtk_spin_button_set_value(dialog->w_spin, dialog->w_original);
 	gtk_spin_button_set_value(dialog->h_spin, dialog->h_original);
 	gtk_spin_button_set_value(dialog->p_spin, 100.0);
+	
+	gchar* basename = g_path_get_basename(photo->filename);
+	gchar* output = g_strrstr(basename, ".");
+	/* Terminate basename at last "." */
+	if (output != NULL)
+		*output = '\0';
 
+	/* Find extension */
+	const gchar *ext = "jpg";
+	if (dialog->output && g_object_class_find_property(G_OBJECT_GET_CLASS(dialog->output), "filename"))
+		ext = rs_output_get_extension(RS_OUTPUT(dialog->output));
+	
+	gchar* name_ext = g_strdup_printf("%s.%s",basename, ext);
+
+	gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog->chooser), name_ext);
+	g_free(basename);
+	g_free(name_ext);
+	
 	dialog->snapshot = snapshot;
 }
 
@@ -220,7 +239,23 @@
 	dialog->file_pref = rs_output_get_parameter_widget(dialog->output, "save-as");
 
 	if (g_object_class_find_property(G_OBJECT_GET_CLASS(dialog->output), "filename"))
+	{
 		gtk_widget_show(dialog->chooser);
+		gchar* cur_file = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser));
+		if( cur_file)
+		{
+			gchar* basename = g_path_get_basename(cur_file);
+			gchar* output = g_strrstr(basename, ".");
+			/* Terminate basename at last "." */
+			if (output != NULL)
+				*output = '\0';
+			gchar* name_ext = g_strdup_printf("%s.%s",basename, rs_output_get_extension(RS_OUTPUT(dialog->output)));
+			gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog->chooser), name_ext);
+			g_free(cur_file);
+			g_free(basename);
+			g_free(name_ext);
+		}
+	}
 	else
 		gtk_widget_hide(dialog->chooser);
 
@@ -253,7 +288,10 @@
 	gfloat actual_scale;
 	RSSaveDialog *dialog = RS_SAVE_DIALOG(data);
 
-	gchar *description = g_strdup_printf(_("Exporting to %s"), gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser)));
+	gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser));
+	if (!filename)
+		return NULL;
+	gchar *description = g_strdup_printf(_("Exporting to %s"), filename);
 	rs_job_update_description(slot, description);
 	g_free(description);
 
@@ -304,15 +342,15 @@
 
 	rs_job_update_progress(slot, 0.15);
 	if (g_object_class_find_property(G_OBJECT_GET_CLASS(dialog->output), "filename"))
-		g_object_set(dialog->output, "filename", gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser)), NULL);
+		g_object_set(dialog->output, "filename", filename, NULL);
 	if(!rs_output_execute(dialog->output, dialog->fend))
-		show_save_error(_("Could not save file: %s\n\nCheck that you have write permissions to this folder."),
-			gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser)));
+		show_save_error(_("Could not save file: %s\n\nCheck that you have write permissions to this folder."),filename);
 	rs_job_update_progress(slot, 0.75);
 
 	gdk_threads_enter();
 	gtk_widget_destroy(GTK_WIDGET(dialog));
 	gdk_threads_leave();
+	g_free(filename);
 
 	return NULL;
 }
@@ -321,14 +359,18 @@
 save_clicked(GtkButton *button, gpointer user_data)
 {
 	RSSaveDialog *dialog = RS_SAVE_DIALOG(user_data);
-	gchar *dirname = g_path_get_dirname(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser)));
-	rs_conf_set_string(CONF_EXPORT_AS_FOLDER, dirname);
-	g_free(dirname);
+	gchar *filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog->chooser));
+	if (filename)
+	{
+		gchar *dirname = g_path_get_dirname(filename);
+		rs_conf_set_string(CONF_EXPORT_AS_FOLDER, dirname);
+		g_free(filename);
+		g_free(dirname);
 
-	/* Just hide it for now, we destroy it in job() */
-	gtk_widget_hide_all(GTK_WIDGET(dialog));
-
-	rs_job_queue_add_job(job, g_object_ref(dialog), FALSE);
+		/* Just hide it for now, we destroy it in job() */
+		gtk_widget_hide_all(GTK_WIDGET(dialog));
+		rs_job_queue_add_job(job, g_object_ref(dialog), FALSE);
+	}
 }
 
 static void




More information about the Rawstudio-commit mailing list