This signal gets emitted whenever it is appropriate to present a confirmation dialog when the user has selected a file name that already exists.
The signal only gets emitted when the file chooser is in gtk_file_chooser_action_save mode.
Most applications just need to turn on the do_overwrite_confirmation property (or call the set_do_overwrite_confirmation function), and they will automatically get a stock confirmation dialog. Applications which need to customize this behavior should do that, and also connect to the confirm_overwrite signal.
A signal handler for this signal must return a FileChooserConfirmation value, which indicates the action to take. If the handler determines that the user wants to select a different filename, it should return gtk_file_chooser_confirmation_select_again. If it determines that the user is satisfied with his choice of file name, it should return gtk_file_chooser_confirmation_accept_filename. On the other hand, if it determines that the stock confirmation dialog should be used, it should return gtk_file_chooser_confirmation_confirm. The following example illustrates this.
static GtkFileChooserConfirmation
confirm_overwrite_callback (GtkFileChooser *chooser, gpointer data)
{
char *uri;
uri = gtk_file_chooser_get_uri (chooser);
if (is_uri_read_only (uri))
{
if (user_wants_to_replace_read_only_file (uri))
return GTK_FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME;
else
return GTK_FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN;
} else
return GTK_FILE_CHOOSER_CONFIRMATION_CONFIRM; // fall back to the default dialog
}
...
chooser = gtk_file_chooser_dialog_new (...);
gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
g_signal_connect (chooser, "confirm-overwrite",
G_CALLBACK (confirm_overwrite_callback), NULL);
if (gtk_dialog_run (chooser) == GTK_RESPONSE_ACCEPT)
save_to_file (gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
gtk_widget_destroy (chooser);
a FileChooserConfirmation value that indicates which action to take after emitting the signal. |