Add an overwrite confirmation dialog for print-to-file. (#474302, Marek
2008-03-12 Matthias Clasen <mclasen@redhat.com> * gtk/gtkprintunixdialog.c: Add an overwrite confirmation dialog for print-to-file. (#474302, Marek Kašík) svn path=/trunk/; revision=19787
This commit is contained in:
parent
b1f8302299
commit
b7aeafa395
@ -1,3 +1,8 @@
|
|||||||
|
2008-03-12 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
|
* gtk/gtkprintunixdialog.c: Add an overwrite confirmation
|
||||||
|
dialog for print-to-file. (#474302, Marek Kašík)
|
||||||
|
|
||||||
2008-03-12 Matthias Clasen <mclasen@redhat.com>
|
2008-03-12 Matthias Clasen <mclasen@redhat.com>
|
||||||
|
|
||||||
* modules/printbackends/cups/gtkprintbackendcups.c: Fix a crash
|
* modules/printbackends/cups/gtkprintbackendcups.c: Fix a crash
|
||||||
|
@ -56,6 +56,9 @@
|
|||||||
#include "gtkprinteroptionwidget.h"
|
#include "gtkprinteroptionwidget.h"
|
||||||
#include "gtkalias.h"
|
#include "gtkalias.h"
|
||||||
|
|
||||||
|
#include "gtkmessagedialog.h"
|
||||||
|
#include "gtkbutton.h"
|
||||||
|
|
||||||
#define EXAMPLE_PAGE_AREA_SIZE 140
|
#define EXAMPLE_PAGE_AREA_SIZE 140
|
||||||
|
|
||||||
#define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o) \
|
#define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o) \
|
||||||
@ -273,6 +276,112 @@ gtk_print_unix_dialog_class_init (GtkPrintUnixDialogClass *class)
|
|||||||
g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
|
g_type_class_add_private (class, sizeof (GtkPrintUnixDialogPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns a toplevel GtkWindow, or NULL if none */
|
||||||
|
static GtkWindow *
|
||||||
|
get_toplevel (GtkWidget *widget)
|
||||||
|
{
|
||||||
|
GtkWidget *toplevel = NULL;
|
||||||
|
|
||||||
|
toplevel = gtk_widget_get_toplevel (widget);
|
||||||
|
if (!GTK_WIDGET_TOPLEVEL (toplevel))
|
||||||
|
return NULL;
|
||||||
|
else
|
||||||
|
return GTK_WINDOW (toplevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
add_custom_button_to_dialog (GtkDialog *dialog,
|
||||||
|
const gchar *mnemonic_label,
|
||||||
|
const gchar *stock_id,
|
||||||
|
gint response_id)
|
||||||
|
{
|
||||||
|
GtkWidget *button = NULL;
|
||||||
|
|
||||||
|
button = gtk_button_new_with_mnemonic (mnemonic_label);
|
||||||
|
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||||
|
gtk_button_set_image (GTK_BUTTON (button),
|
||||||
|
gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_BUTTON));
|
||||||
|
gtk_widget_show (button);
|
||||||
|
|
||||||
|
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), button, response_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Presents an overwrite confirmation dialog ("print to file" backend).
|
||||||
|
*/
|
||||||
|
static gboolean
|
||||||
|
overwrite_confirmation_dialog (GtkPrintUnixDialog *print_dialog,
|
||||||
|
gint print_dialog_response_id,
|
||||||
|
gpointer data)
|
||||||
|
{
|
||||||
|
GtkPrintUnixDialogPrivate *priv = print_dialog->priv;
|
||||||
|
GtkPrinterOption *option = NULL;
|
||||||
|
GtkPrinter *printer = NULL;
|
||||||
|
GtkWindow *toplevel = NULL;
|
||||||
|
GtkWidget *dialog = NULL;
|
||||||
|
gchar *filename = NULL;
|
||||||
|
gchar *basename = NULL;
|
||||||
|
gchar *dirname = NULL;
|
||||||
|
int response;
|
||||||
|
|
||||||
|
if (print_dialog != NULL && print_dialog_response_id == GTK_RESPONSE_OK)
|
||||||
|
{
|
||||||
|
printer = gtk_print_unix_dialog_get_selected_printer (print_dialog);
|
||||||
|
|
||||||
|
if (printer != NULL && gtk_printer_is_virtual (printer))
|
||||||
|
{
|
||||||
|
option = gtk_printer_option_set_lookup (priv->options, "gtk-main-page-custom-input");
|
||||||
|
|
||||||
|
if (option != NULL && option->type == GTK_PRINTER_OPTION_TYPE_FILESAVE)
|
||||||
|
{
|
||||||
|
filename = g_filename_from_uri (option->value, NULL, NULL);
|
||||||
|
|
||||||
|
if (filename != NULL && g_file_test (filename, G_FILE_TEST_EXISTS))
|
||||||
|
{
|
||||||
|
toplevel = get_toplevel (GTK_WIDGET (print_dialog));
|
||||||
|
|
||||||
|
basename = g_path_get_basename (filename);
|
||||||
|
dirname = g_path_get_dirname (filename);
|
||||||
|
|
||||||
|
dialog = gtk_message_dialog_new (toplevel,
|
||||||
|
GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||||
|
GTK_MESSAGE_QUESTION,
|
||||||
|
GTK_BUTTONS_NONE,
|
||||||
|
_("A file named \"%s\" already exists. Do you want to replace it?"),
|
||||||
|
basename);
|
||||||
|
|
||||||
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
||||||
|
_("The file already exists in \"%s\". Replacing it will "
|
||||||
|
"overwrite its contents."),
|
||||||
|
dirname);
|
||||||
|
|
||||||
|
gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL);
|
||||||
|
add_custom_button_to_dialog (GTK_DIALOG (dialog), _("_Replace"), GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT);
|
||||||
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
||||||
|
|
||||||
|
if (toplevel->group)
|
||||||
|
gtk_window_group_add_window (toplevel->group, GTK_WINDOW (dialog));
|
||||||
|
|
||||||
|
response = gtk_dialog_run (GTK_DIALOG (dialog));
|
||||||
|
|
||||||
|
gtk_widget_destroy (dialog);
|
||||||
|
|
||||||
|
if (response != GTK_RESPONSE_ACCEPT)
|
||||||
|
{
|
||||||
|
g_signal_stop_emission_by_name (print_dialog, "response");
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (dirname);
|
||||||
|
g_free (basename);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free (filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
|
gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
|
||||||
{
|
{
|
||||||
@ -289,6 +398,11 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
|
|||||||
(GCallback) gtk_print_unix_dialog_destroy,
|
(GCallback) gtk_print_unix_dialog_destroy,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
|
g_signal_connect (dialog,
|
||||||
|
"response",
|
||||||
|
(GCallback) overwrite_confirmation_dialog,
|
||||||
|
NULL);
|
||||||
|
|
||||||
priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
|
priv->preview_button = gtk_button_new_from_stock (GTK_STOCK_PRINT_PREVIEW);
|
||||||
gtk_widget_show (priv->preview_button);
|
gtk_widget_show (priv->preview_button);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user