RH bug 204621 - "GtkPrint" asks for "Letter" size paper when "A4" size

was chosen

        Patch by Marek Kasik.

        * gtk/gtk.symbols:
        * gtk/gtkprinter.[hc]: Add gtk_printer_get_default_page_size.

        * gtk/gtkprintbackend.[hc]: Add fallback implementation.

        * modules/printbackends/file/gtkprintbackendfile.c:
        * modules/printbackends/cups/gtkprintbackendcups.c: Implement
        get_default_page_size.

        * gtk/gtkpagesetupunixdialog.c: When selecting a different printer,
        select its default paper size.

        * gtk/gtkprintunixdialog.c: If no explicit page setup has been set,
        use the printer default.

        * gtk/gtkprintoperation-unix.c: Don't create an empty page setup
        if we don't have a default page setup.

svn path=/trunk/; revision=20120
This commit is contained in:
Matthias Clasen 2008-05-21 02:17:30 +00:00
parent 75a9722aa1
commit 59ae44d00e
13 changed files with 201 additions and 73 deletions

View File

@ -1,3 +1,28 @@
2008-05-20 Matthias Clasen <mclasen@redhat.com>
RH bug 204621 - "GtkPrint" asks for "Letter" size paper when "A4" size
was chosen
Patch by Marek Kasik.
* gtk/gtk.symbols:
* gtk/gtkprinter.[hc]: Add gtk_printer_get_default_page_size.
* gtk/gtkprintbackend.[hc]: Add fallback implementation.
* modules/printbackends/file/gtkprintbackendfile.c:
* modules/printbackends/cups/gtkprintbackendcups.c: Implement
get_default_page_size.
* gtk/gtkpagesetupunixdialog.c: When selecting a different printer,
select its default paper size.
* gtk/gtkprintunixdialog.c: If no explicit page setup has been set,
use the printer default.
* gtk/gtkprintoperation-unix.c: Don't create an empty page setup
if we don't have a default page setup.
2008-05-20 Gian Mario Tagliaretti <gianmt@gnome.org>
* gtk/gtkdnd.c: (gtk_drag_set_icon_pixmap): Fix the docs, the mask param

View File

@ -1,3 +1,7 @@
2008-05-20 Matthias Clasen <mclasen@redhat.com>
* gtk/gtk-sections.txt: Add gtk_printer_get_default_page_size
2008-05-20 Matthias Clasen <mclasen@redhat.com>
Bug 533761 - gdk_accelerator_parse() does not exist, should be

View File

@ -6435,6 +6435,7 @@ gtk_printer_compare
gtk_printer_has_details
gtk_printer_request_details
gtk_printer_get_capabilities
gtk_printer_get_default_page_size
GtkPrinterFunc
gtk_enumerate_printers

View File

@ -2704,6 +2704,7 @@ gtk_printer_get_type G_GNUC_CONST
gtk_printer_get_backend
gtk_printer_get_name
gtk_printer_get_description
gtk_printer_get_default_page_size
gtk_printer_get_state_message
gtk_printer_get_location
gtk_printer_get_icon_name

View File

@ -681,8 +681,6 @@ fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
GtkTreeIter iter;
gint i;
current_page_setup = get_current_page_setup (dialog);
gtk_list_store_clear (priv->page_setup_list);
if (printer == NULL)
@ -720,6 +718,15 @@ fill_paper_sizes_from_printer (GtkPageSetupUnixDialog *dialog,
fill_custom_paper_sizes (dialog);
current_page_setup = NULL;
/* When selecting a different printer, select its default paper size */
if (printer != NULL)
current_page_setup = gtk_printer_get_default_page_size (printer);
if (current_page_setup == NULL)
current_page_setup = get_current_page_setup (dialog);
if (!set_paper_size (dialog, current_page_setup, FALSE, FALSE))
set_paper_size (dialog, current_page_setup, TRUE, TRUE);

View File

@ -283,16 +283,17 @@ gtk_print_backend_load_modules (void)
G_DEFINE_TYPE (GtkPrintBackend, gtk_print_backend, G_TYPE_OBJECT)
static void fallback_printer_request_details (GtkPrinter *printer);
static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer,
GtkPrinterOptionSet *options);
static void fallback_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right);
static GList * fallback_printer_list_papers (GtkPrinter *printer);
static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer);
static void fallback_printer_request_details (GtkPrinter *printer);
static gboolean fallback_printer_mark_conflicts (GtkPrinter *printer,
GtkPrinterOptionSet *options);
static void fallback_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,
gdouble *bottom,
gdouble *left,
gdouble *right);
static GList * fallback_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * fallback_printer_get_default_page_size (GtkPrinter *printer);
static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer);
static void
gtk_print_backend_class_init (GtkPrintBackendClass *class)
@ -308,6 +309,7 @@ gtk_print_backend_class_init (GtkPrintBackendClass *class)
class->printer_mark_conflicts = fallback_printer_mark_conflicts;
class->printer_get_hard_margins = fallback_printer_get_hard_margins;
class->printer_list_papers = fallback_printer_list_papers;
class->printer_get_default_page_size = fallback_printer_get_default_page_size;
class->printer_get_capabilities = fallback_printer_get_capabilities;
g_type_class_add_private (class, sizeof (GtkPrintBackendPrivate));
@ -419,6 +421,12 @@ fallback_printer_list_papers (GtkPrinter *printer)
return NULL;
}
static GtkPageSetup *
fallback_printer_get_default_page_size (GtkPrinter *printer)
{
return NULL;
}
static GtkPrintCapabilities
fallback_printer_get_capabilities (GtkPrinter *printer)
{

View File

@ -99,6 +99,7 @@ struct _GtkPrintBackendClass
GtkPrintSettings *settings,
GtkPageSetup *page_setup);
GList * (*printer_list_papers) (GtkPrinter *printer);
GtkPageSetup * (*printer_get_default_page_size) (GtkPrinter *printer);
void (*printer_get_hard_margins) (GtkPrinter *printer,
double *top,
double *bottom,
@ -123,7 +124,6 @@ struct _GtkPrintBackendClass
void (*_gtk_reserved4) (void);
void (*_gtk_reserved5) (void);
void (*_gtk_reserved6) (void);
void (*_gtk_reserved7) (void);
};
GType gtk_print_backend_get_type (void) G_GNUC_CONST;

View File

@ -832,6 +832,27 @@ gtk_printer_list_papers (GtkPrinter *printer)
return backend_class->printer_list_papers (printer);
}
/**
* gtk_printer_get_default_page_size:
* @printer: a #GtkPrinter
*
* Returns default page size of @printer.
*
* Return value: a newly allocated #GtkPageSetup with default page size of the printer.
*
* Since: 2.13
*/
GtkPageSetup *
gtk_printer_get_default_page_size (GtkPrinter *printer)
{
GtkPrintBackendClass *backend_class;
g_return_val_if_fail (GTK_IS_PRINTER (printer), NULL);
backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend);
return backend_class->printer_get_default_page_size (printer);
}
void
_gtk_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,

View File

@ -83,28 +83,29 @@ struct _GtkPrinterClass
void (*_gtk_reserved7) (void);
};
GType gtk_printer_get_type (void) G_GNUC_CONST;
GtkPrinter *gtk_printer_new (const gchar *name,
GtkPrintBackend *backend,
gboolean virtual_);
GtkPrintBackend *gtk_printer_get_backend (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_name (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_state_message (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_description (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_location (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_icon_name (GtkPrinter *printer);
gint gtk_printer_get_job_count (GtkPrinter *printer);
gboolean gtk_printer_is_active (GtkPrinter *printer);
gboolean gtk_printer_is_virtual (GtkPrinter *printer);
gboolean gtk_printer_is_default (GtkPrinter *printer);
gboolean gtk_printer_accepts_pdf (GtkPrinter *printer);
gboolean gtk_printer_accepts_ps (GtkPrinter *printer);
GList *gtk_printer_list_papers (GtkPrinter *printer);
gint gtk_printer_compare (GtkPrinter *a,
GtkPrinter *b);
gboolean gtk_printer_has_details (GtkPrinter *printer);
void gtk_printer_request_details (GtkPrinter *printer);
GtkPrintCapabilities gtk_printer_get_capabilities (GtkPrinter *printer);
GType gtk_printer_get_type (void) G_GNUC_CONST;
GtkPrinter *gtk_printer_new (const gchar *name,
GtkPrintBackend *backend,
gboolean virtual_);
GtkPrintBackend *gtk_printer_get_backend (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_name (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_state_message (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_description (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_location (GtkPrinter *printer);
G_CONST_RETURN gchar *gtk_printer_get_icon_name (GtkPrinter *printer);
gint gtk_printer_get_job_count (GtkPrinter *printer);
gboolean gtk_printer_is_active (GtkPrinter *printer);
gboolean gtk_printer_is_virtual (GtkPrinter *printer);
gboolean gtk_printer_is_default (GtkPrinter *printer);
gboolean gtk_printer_accepts_pdf (GtkPrinter *printer);
gboolean gtk_printer_accepts_ps (GtkPrinter *printer);
GList *gtk_printer_list_papers (GtkPrinter *printer);
GtkPageSetup *gtk_printer_get_default_page_size (GtkPrinter *printer);
gint gtk_printer_compare (GtkPrinter *a,
GtkPrinter *b);
gboolean gtk_printer_has_details (GtkPrinter *printer);
void gtk_printer_request_details (GtkPrinter *printer);
GtkPrintCapabilities gtk_printer_get_capabilities (GtkPrinter *printer);
typedef gboolean (*GtkPrinterFunc) (GtkPrinter *printer,
gpointer data);

View File

@ -349,7 +349,6 @@ get_print_dialog (GtkPrintOperation *op,
{
GtkPrintOperationPrivate *priv = op->priv;
GtkWidget *pd, *label;
GtkPageSetup *page_setup;
const gchar *custom_tab_label;
pd = gtk_print_unix_dialog_new (NULL, parent);
@ -366,13 +365,8 @@ get_print_dialog (GtkPrintOperation *op,
gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
priv->print_settings);
if (priv->default_page_setup)
page_setup = gtk_page_setup_copy (priv->default_page_setup);
else
page_setup = gtk_page_setup_new ();
gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd),
page_setup);
g_object_unref (page_setup);
gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd),
priv->default_page_setup);
g_signal_emit_by_name (op, "create-custom-widget",
&priv->custom_widget);
@ -432,6 +426,10 @@ finish_print (PrintResponseData *rdata,
{
gtk_print_operation_set_print_settings (op, settings);
priv->print_context = _gtk_print_context_new (op);
if ( (page_setup != NULL) && (gtk_print_operation_get_default_page_setup (op) == NULL))
gtk_print_operation_set_default_page_setup (op, page_setup);
_gtk_print_context_set_page_setup (priv->print_context, page_setup);
if (!rdata->do_preview)

View File

@ -133,6 +133,7 @@ struct GtkPrintUnixDialogPrivate
GtkTreeModelFilter *printer_list_filter;
GtkPageSetup *page_setup;
gboolean page_setup_set;
GtkWidget *all_pages_radio;
GtkWidget *current_page_radio;
@ -407,6 +408,7 @@ gtk_print_unix_dialog_init (GtkPrintUnixDialog *dialog)
priv->current_page = -1;
priv->page_setup = gtk_page_setup_new ();
priv->page_setup_set = FALSE;
g_signal_connect (dialog,
"destroy",
@ -1440,6 +1442,20 @@ selected_printer_changed (GtkTreeSelection *selection,
if (printer != NULL)
{
if (!priv->page_setup_set)
{
/* if no explicit page setup has been set, use the printer default */
GtkPageSetup *page_setup;
page_setup = gtk_printer_get_default_page_size (printer);
if (!page_setup)
page_setup = gtk_page_setup_new ();
g_object_unref (priv->page_setup);
priv->page_setup = page_setup;
}
priv->printer_capabilities = gtk_printer_get_capabilities (printer);
priv->options = _gtk_printer_get_options (printer,
priv->initial_settings,
@ -2650,6 +2666,8 @@ gtk_print_unix_dialog_set_page_setup (GtkPrintUnixDialog *dialog,
g_object_unref (priv->page_setup);
priv->page_setup = g_object_ref (page_setup);
priv->page_setup_set = TRUE;
g_object_notify (G_OBJECT (dialog), "page-setup");
}
}

View File

@ -136,6 +136,7 @@ static void cups_printer_prepare_for_print (GtkPrinter
GtkPrintSettings *settings,
GtkPageSetup *page_setup);
static GList * cups_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * cups_printer_get_default_page_size (GtkPrinter *printer);
static void cups_printer_request_details (GtkPrinter *printer);
static void cups_request_default_printer (GtkPrintBackendCups *print_backend);
static void cups_request_ppd (GtkPrinter *printer);
@ -255,6 +256,7 @@ gtk_print_backend_cups_class_init (GtkPrintBackendCupsClass *class)
backend_class->printer_get_settings_from_options = cups_printer_get_settings_from_options;
backend_class->printer_prepare_for_print = cups_printer_prepare_for_print;
backend_class->printer_list_papers = cups_printer_list_papers;
backend_class->printer_get_default_page_size = cups_printer_get_default_page_size;
backend_class->printer_get_hard_margins = cups_printer_get_hard_margins;
backend_class->printer_get_capabilities = cups_printer_get_capabilities;
}
@ -1437,6 +1439,8 @@ cups_request_ppd_cb (GtkPrintBackendCups *print_backend,
/* let ppdOpenFd take over the ownership of the open file */
g_io_channel_seek_position (data->ppd_io, 0, G_SEEK_SET, NULL);
data->printer->ppd_file = ppdOpenFd (dup (g_io_channel_unix_get_fd (data->ppd_io)));
ppdMarkDefaults (data->printer->ppd_file);
gtk_printer_set_has_details (printer, TRUE);
g_signal_emit_by_name (printer, "details-acquired", TRUE);
@ -3121,16 +3125,52 @@ cups_printer_prepare_for_print (GtkPrinter *printer,
print_job->rotate_to_orientation = TRUE;
}
static GtkPageSetup *
create_page_setup (ppd_file_t *ppd_file,
ppd_size_t *size)
{
char *display_name;
GtkPageSetup *page_setup;
GtkPaperSize *paper_size;
ppd_option_t *option;
ppd_choice_t *choice;
display_name = NULL;
option = ppdFindOption (ppd_file, "PageSize");
if (option)
{
choice = ppdFindChoice (option, size->name);
if (choice)
display_name = ppd_text_to_utf8 (ppd_file, choice->text);
}
if (display_name == NULL)
display_name = g_strdup (size->name);
page_setup = gtk_page_setup_new ();
paper_size = gtk_paper_size_new_from_ppd (size->name,
display_name,
size->width,
size->length);
gtk_page_setup_set_paper_size (page_setup, paper_size);
gtk_paper_size_free (paper_size);
gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS);
gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS);
gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS);
gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS);
g_free (display_name);
return page_setup;
}
static GList *
cups_printer_list_papers (GtkPrinter *printer)
{
ppd_file_t *ppd_file;
ppd_size_t *size;
char *display_name;
GtkPageSetup *page_setup;
GtkPaperSize *paper_size;
ppd_option_t *option;
ppd_choice_t *choice;
GList *l;
int i;
@ -3142,33 +3182,9 @@ cups_printer_list_papers (GtkPrinter *printer)
for (i = 0; i < ppd_file->num_sizes; i++)
{
size = &ppd_file->sizes[i];
size = &ppd_file->sizes[i];
display_name = NULL;
option = ppdFindOption (ppd_file, "PageSize");
if (option)
{
choice = ppdFindChoice (option, size->name);
if (choice)
display_name = ppd_text_to_utf8 (ppd_file, choice->text);
}
if (display_name == NULL)
display_name = g_strdup (size->name);
page_setup = gtk_page_setup_new ();
paper_size = gtk_paper_size_new_from_ppd (size->name,
display_name,
size->width,
size->length);
gtk_page_setup_set_paper_size (page_setup, paper_size);
gtk_paper_size_free (paper_size);
gtk_page_setup_set_top_margin (page_setup, size->length - size->top, GTK_UNIT_POINTS);
gtk_page_setup_set_bottom_margin (page_setup, size->bottom, GTK_UNIT_POINTS);
gtk_page_setup_set_left_margin (page_setup, size->left, GTK_UNIT_POINTS);
gtk_page_setup_set_right_margin (page_setup, size->width - size->right, GTK_UNIT_POINTS);
g_free (display_name);
page_setup = create_page_setup (ppd_file, size);
l = g_list_prepend (l, page_setup);
}
@ -3176,6 +3192,24 @@ cups_printer_list_papers (GtkPrinter *printer)
return g_list_reverse (l);
}
static GtkPageSetup *
cups_printer_get_default_page_size (GtkPrinter *printer)
{
ppd_file_t *ppd_file;
ppd_size_t *size;
ppd_option_t *option;
ppd_file = gtk_printer_cups_get_ppd (GTK_PRINTER_CUPS (printer));
if (ppd_file == NULL)
return NULL;
option = ppdFindOption (ppd_file, "PageSize");
size = ppdPageSize (ppd_file, option->defchoice);
return create_page_setup (ppd_file, size);
}
static void
cups_printer_get_hard_margins (GtkPrinter *printer,
gdouble *top,

View File

@ -104,6 +104,7 @@ static cairo_surface_t * file_printer_create_cairo_surface (GtkPrinter
GIOChannel *cache_io);
static GList * file_printer_list_papers (GtkPrinter *printer);
static GtkPageSetup * file_printer_get_default_page_size (GtkPrinter *printer);
static void
gtk_print_backend_file_register_type (GTypeModule *module)
@ -182,6 +183,7 @@ gtk_print_backend_file_class_init (GtkPrintBackendFileClass *class)
backend_class->printer_get_settings_from_options = file_printer_get_settings_from_options;
backend_class->printer_prepare_for_print = file_printer_prepare_for_print;
backend_class->printer_list_papers = file_printer_list_papers;
backend_class->printer_get_default_page_size = file_printer_get_default_page_size;
}
/* return N_FORMATS if no explicit format in the settings */
@ -697,3 +699,11 @@ file_printer_list_papers (GtkPrinter *printer)
return g_list_reverse (result);
}
static GtkPageSetup *
file_printer_get_default_page_size (GtkPrinter *printer)
{
GtkPageSetup *result = NULL;
return result;
}