diff options
author | Alexander Larsson <alexl@redhat.com> | 2006-05-24 10:50:57 +0000 |
---|---|---|
committer | Alexander Larsson <alexl@src.gnome.org> | 2006-05-24 10:50:57 +0000 |
commit | 70376f280a6735551404ad583eb9efd8afcc7cc3 (patch) | |
tree | de5dd5dc1df73c718f4dd5c4db22e55392901386 /gtk | |
parent | 27f2b1d95a164b5a48d5bb402fb13c99423f5305 (diff) | |
download | gtk+-70376f280a6735551404ad583eb9efd8afcc7cc3.tar.gz |
Add gtk_print_unix_dialog_set_manual_capabilities that controls what
2006-05-24 Alexander Larsson <alexl@redhat.com>
* gtk/gtk.symbols:
* gtk/gtkprintunixdialog.[ch]:
Add gtk_print_unix_dialog_set_manual_capabilities that controls
what widgets to enable in the dialog depending on the apps
capabilities.
* gtk/gtkprintbackend.[ch]:
* gtk/gtkprinter-private.h:
* gtk/gtkprinter.c:
* gtk/gtkprintjob.h:
Add printer_get_capabilities to backend.
Move some fallback calls to the printbackend base class.
* gtk/gtkprintoperation-unix.c:
Set manual capabilities
* modules/printbackends/cups/gtkprintbackendcups.c:
Implement get_capabilities
* modules/printbackends/lpr/gtkprintbackendlpr.c:
* modules/printbackends/pdf/gtkprintbackendpdf.c:
Move some methods to baseclass.
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtk.symbols | 1 | ||||
-rw-r--r-- | gtk/gtkprintbackend.c | 56 | ||||
-rw-r--r-- | gtk/gtkprintbackend.h | 1 | ||||
-rw-r--r-- | gtk/gtkprinter-private.h | 1 | ||||
-rw-r--r-- | gtk/gtkprinter.c | 8 | ||||
-rw-r--r-- | gtk/gtkprintjob.h | 11 | ||||
-rw-r--r-- | gtk/gtkprintoperation-unix.c | 7 | ||||
-rw-r--r-- | gtk/gtkprintunixdialog.c | 133 | ||||
-rw-r--r-- | gtk/gtkprintunixdialog.h | 3 |
9 files changed, 185 insertions, 36 deletions
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 675103857c..d68fe751cb 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -2806,6 +2806,7 @@ gtk_print_unix_dialog_set_settings gtk_print_unix_dialog_get_settings gtk_print_unix_dialog_get_selected_printer gtk_print_unix_dialog_add_custom_tab +gtk_print_unix_dialog_set_manual_capabilities #endif #endif #endif diff --git a/gtk/gtkprintbackend.c b/gtk/gtkprintbackend.c index 9bd1069a92..68c90981a3 100644 --- a/gtk/gtkprintbackend.c +++ b/gtk/gtkprintbackend.c @@ -303,6 +303,17 @@ gtk_print_backend_load_modules () 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, + double *top, + double *bottom, + double *left, + double *right); +static GList * fallback_printer_list_papers (GtkPrinter *printer); +static GtkPrintCapabilities fallback_printer_get_capabilities (GtkPrinter *printer); + static void gtk_print_backend_class_init (GtkPrintBackendClass *class) { @@ -313,8 +324,13 @@ gtk_print_backend_class_init (GtkPrintBackendClass *class) object_class->dispose = gtk_print_backend_dispose; + class->printer_request_details = fallback_printer_request_details; + 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_capabilities = fallback_printer_get_capabilities; + g_type_class_add_private (class, sizeof (GtkPrintBackendPrivate)); - signals[PRINTER_LIST_CHANGED] = g_signal_new ("printer-list-changed", @@ -392,6 +408,44 @@ gtk_print_backend_dispose (GObject *object) static void +fallback_printer_request_details (GtkPrinter *printer) +{ +} + +static gboolean +fallback_printer_mark_conflicts (GtkPrinter *printer, + GtkPrinterOptionSet *options) +{ + return FALSE; +} + +static void +fallback_printer_get_hard_margins (GtkPrinter *printer, + double *top, + double *bottom, + double *left, + double *right) +{ + *top = 0; + *bottom = 0; + *left = 0; + *right = 0; +} + +static GList * +fallback_printer_list_papers (GtkPrinter *printer) +{ + return NULL; +} + +static GtkPrintCapabilities +fallback_printer_get_capabilities (GtkPrinter *printer) +{ + return 0; +} + + +static void printer_hash_to_sorted_active_list (const gchar *key, gpointer value, GList **out_list) diff --git a/gtk/gtkprintbackend.h b/gtk/gtkprintbackend.h index 7f688ae0fc..e8d9711ea8 100644 --- a/gtk/gtkprintbackend.h +++ b/gtk/gtkprintbackend.h @@ -103,6 +103,7 @@ struct _GtkPrintBackendClass double *bottom, double *left, double *right); + GtkPrintCapabilities (*printer_get_capabilities) (GtkPrinter *printer); /* Signals */ void (*printer_list_changed) (GtkPrintBackend *backend); diff --git a/gtk/gtkprinter-private.h b/gtk/gtkprinter-private.h index c6757d0386..798ec0835e 100644 --- a/gtk/gtkprinter-private.h +++ b/gtk/gtkprinter-private.h @@ -55,6 +55,7 @@ void _gtk_printer_get_hard_margins (GtkPrinter gdouble *left, gdouble *right); GHashTable * _gtk_printer_get_custom_widgets (GtkPrinter *printer); +GtkPrintCapabilities _gtk_printer_get_capabilities (GtkPrinter *printer); /* GtkPrintJob private methods: */ diff --git a/gtk/gtkprinter.c b/gtk/gtkprinter.c index 429d577b97..3367abe206 100644 --- a/gtk/gtkprinter.c +++ b/gtk/gtkprinter.c @@ -726,6 +726,14 @@ _gtk_printer_get_hard_margins (GtkPrinter *printer, backend_class->printer_get_hard_margins (printer, top, bottom, left, right); } +GtkPrintCapabilities +_gtk_printer_get_capabilities (GtkPrinter *printer) +{ + GtkPrintBackendClass *backend_class = GTK_PRINT_BACKEND_GET_CLASS (printer->priv->backend); + + return backend_class->printer_get_capabilities (printer); +} + gint gtk_printer_compare (GtkPrinter *a, GtkPrinter *b) { diff --git a/gtk/gtkprintjob.h b/gtk/gtkprintjob.h index 328ddb411c..96b668eb22 100644 --- a/gtk/gtkprintjob.h +++ b/gtk/gtkprintjob.h @@ -34,6 +34,14 @@ G_BEGIN_DECLS #define GTK_IS_PRINT_JOB_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_PRINT_JOB)) #define GTK_PRINT_JOB_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_PRINT_JOB, GtkPrintJobClass)) +typedef enum +{ + GTK_PRINT_CAPABILITY_PAGE_SET = 1 << 0, + GTK_PRINT_CAPABILITY_COPIES = 1 << 1, + GTK_PRINT_CAPABILITY_COLLATE = 1 << 2, + GTK_PRINT_CAPABILITY_REVERSE = 1 << 3, + GTK_PRINT_CAPABILITY_SCALE = 1 << 4 +} GtkPrintCapabilities; typedef struct _GtkPrintJob GtkPrintJob; typedef struct _GtkPrintJobClass GtkPrintJobClass; @@ -57,12 +65,13 @@ struct _GtkPrintJob GtkPrintPages print_pages; GtkPageRange *page_ranges; int num_page_ranges; + gboolean rotate_to_orientation; + GtkPageSet page_set; int num_copies; gboolean collate; gboolean reverse; double scale; - gboolean rotate_to_orientation; }; struct _GtkPrintJobClass diff --git a/gtk/gtkprintoperation-unix.c b/gtk/gtkprintoperation-unix.c index cc48bdcb60..77e98c4118 100644 --- a/gtk/gtkprintoperation-unix.c +++ b/gtk/gtkprintoperation-unix.c @@ -183,6 +183,13 @@ get_print_dialog (GtkPrintOperation *op, pd = gtk_print_unix_dialog_new (NULL, parent); + gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (pd), + GTK_PRINT_CAPABILITY_PAGE_SET | + GTK_PRINT_CAPABILITY_COPIES | + GTK_PRINT_CAPABILITY_COLLATE | + GTK_PRINT_CAPABILITY_REVERSE | + GTK_PRINT_CAPABILITY_SCALE); + if (priv->print_settings) gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd), priv->print_settings); diff --git a/gtk/gtkprintunixdialog.c b/gtk/gtkprintunixdialog.c index 5988e71dc4..641dfeb7aa 100644 --- a/gtk/gtkprintunixdialog.c +++ b/gtk/gtkprintunixdialog.c @@ -56,32 +56,36 @@ #define GTK_PRINT_UNIX_DIALOG_GET_PRIVATE(o) \ (G_TYPE_INSTANCE_GET_PRIVATE ((o), GTK_TYPE_PRINT_UNIX_DIALOG, GtkPrintUnixDialogPrivate)) -static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog); -static void gtk_print_unix_dialog_finalize (GObject *object); -static void gtk_print_unix_dialog_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void gtk_print_unix_dialog_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); -static void gtk_print_unix_dialog_style_set (GtkWidget *widget, - GtkStyle *previous_style); -static void populate_dialog (GtkPrintUnixDialog *dialog); -static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog); -static void selected_printer_changed (GtkTreeSelection *selection, - GtkPrintUnixDialog *dialog); -static void clear_per_printer_ui (GtkPrintUnixDialog *dialog); -static void printer_added_cb (GtkPrintBackend *backend, - GtkPrinter *printer, - GtkPrintUnixDialog *dialog); -static void printer_removed_cb (GtkPrintBackend *backend, - GtkPrinter *printer, - GtkPrintUnixDialog *dialog); -static void printer_status_cb (GtkPrintBackend *backend, - GtkPrinter *printer, - GtkPrintUnixDialog *dialog); +static void gtk_print_unix_dialog_destroy (GtkPrintUnixDialog *dialog); +static void gtk_print_unix_dialog_finalize (GObject *object); +static void gtk_print_unix_dialog_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec); +static void gtk_print_unix_dialog_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec); +static void gtk_print_unix_dialog_style_set (GtkWidget *widget, + GtkStyle *previous_style); +static void populate_dialog (GtkPrintUnixDialog *dialog); +static void unschedule_idle_mark_conflicts (GtkPrintUnixDialog *dialog); +static void selected_printer_changed (GtkTreeSelection *selection, + GtkPrintUnixDialog *dialog); +static void clear_per_printer_ui (GtkPrintUnixDialog *dialog); +static void printer_added_cb (GtkPrintBackend *backend, + GtkPrinter *printer, + GtkPrintUnixDialog *dialog); +static void printer_removed_cb (GtkPrintBackend *backend, + GtkPrinter *printer, + GtkPrintUnixDialog *dialog); +static void printer_status_cb (GtkPrintBackend *backend, + GtkPrinter *printer, + GtkPrintUnixDialog *dialog); +static void update_collate_icon (GtkToggleButton *toggle_button, + GtkPrintUnixDialog *dialog); +static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog); +static gboolean dialog_get_reverse (GtkPrintUnixDialog *dialog); enum { PROP_0, @@ -108,6 +112,9 @@ struct GtkPrintUnixDialogPrivate GtkWidget *notebook; GtkWidget *printer_treeview; + + GtkPrintCapabilities manual_capabilities; + GtkPrintCapabilities printer_capabilities; GtkTreeModel *printer_list; GtkTreeModelFilter *printer_list_filter; @@ -1004,6 +1011,28 @@ update_dialog_from_settings (GtkPrintUnixDialog *dialog) } static void +update_dialog_from_capabilities (GtkPrintUnixDialog *dialog) +{ + GtkPrintCapabilities caps; + GtkPrintUnixDialogPrivate *priv = dialog->priv; + + caps = priv->manual_capabilities | priv->printer_capabilities; + + gtk_widget_set_sensitive (priv->page_set_combo, + caps & GTK_PRINT_CAPABILITY_PAGE_SET); + gtk_widget_set_sensitive (priv->copies_spin, + caps & GTK_PRINT_CAPABILITY_COPIES); + gtk_widget_set_sensitive (priv->collate_check, + caps & GTK_PRINT_CAPABILITY_COLLATE); + gtk_widget_set_sensitive (priv->reverse_check, + caps & GTK_PRINT_CAPABILITY_REVERSE); + gtk_widget_set_sensitive (priv->scale_spin, + caps & GTK_PRINT_CAPABILITY_PAGE_SET); + + update_collate_icon (NULL, dialog); +} + +static void mark_conflicts (GtkPrintUnixDialog *dialog) { GtkPrintUnixDialogPrivate *priv = dialog->priv; @@ -1215,11 +1244,14 @@ selected_printer_changed (GtkTreeSelection *selection, g_object_unref (priv->current_printer); } + priv->printer_capabilities = 0; + gtk_dialog_set_response_sensitive (GTK_DIALOG (dialog), GTK_RESPONSE_OK, TRUE); priv->current_printer = printer; if (printer != NULL) { + priv->printer_capabilities = _gtk_printer_get_capabilities (printer); priv->options = _gtk_printer_get_options (printer, priv->initial_settings, priv->page_setup); @@ -1228,7 +1260,9 @@ selected_printer_changed (GtkTreeSelection *selection, } update_dialog_from_settings (dialog); + update_dialog_from_capabilities (dialog); } + static void update_collate_icon (GtkToggleButton *toggle_button, GtkPrintUnixDialog *dialog) @@ -1281,7 +1315,6 @@ draw_collate_cb (GtkWidget *widget, GdkEventExpose *event, GtkPrintUnixDialog *dialog) { - GtkPrintUnixDialogPrivate *priv = dialog->priv; GtkSettings *settings; cairo_t *cr; gint size; @@ -1289,8 +1322,8 @@ draw_collate_cb (GtkWidget *widget, gboolean collate, reverse, rtl; gint text_x; - collate = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->collate_check)); - reverse = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->reverse_check)); + collate = dialog_get_collate (dialog); + reverse = dialog_get_reverse (dialog); rtl = (gtk_widget_get_direction (GTK_WIDGET (widget)) == GTK_TEXT_DIR_RTL); settings = gtk_widget_get_settings (widget); @@ -1648,7 +1681,10 @@ dialog_set_print_pages (GtkPrintUnixDialog *dialog, GtkPrintPages pages) static gdouble dialog_get_scale (GtkPrintUnixDialog *dialog) { - return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin)); + if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->scale_spin)) + return gtk_spin_button_get_value (GTK_SPIN_BUTTON (dialog->priv->scale_spin)); + else + return 100.0; } static void @@ -1661,7 +1697,10 @@ dialog_set_scale (GtkPrintUnixDialog *dialog, static GtkPageSet dialog_get_page_set (GtkPrintUnixDialog *dialog) { - return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo)); + if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->page_set_combo)) + return (GtkPageSet)gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->page_set_combo)); + else + return GTK_PAGE_SET_ALL; } static void @@ -1675,7 +1714,9 @@ dialog_set_page_set (GtkPrintUnixDialog *dialog, static gint dialog_get_n_copies (GtkPrintUnixDialog *dialog) { - return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin)); + if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->copies_spin)) + return gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (dialog->priv->copies_spin)); + return 1; } static void @@ -1689,7 +1730,9 @@ dialog_set_n_copies (GtkPrintUnixDialog *dialog, static gboolean dialog_get_collate (GtkPrintUnixDialog *dialog) { - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check)); + if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->collate_check)) + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->collate_check)); + return FALSE; } static void @@ -1703,7 +1746,9 @@ dialog_set_collate (GtkPrintUnixDialog *dialog, static gboolean dialog_get_reverse (GtkPrintUnixDialog *dialog) { - return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check)); + if (GTK_WIDGET_IS_SENSITIVE (dialog->priv->reverse_check)) + return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->reverse_check)); + return FALSE; } static void @@ -2648,6 +2693,26 @@ gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog, gtk_widget_show (tab_label); } +/** + * gtk_print_unix_dialog_set_manual_capabilities: + * @dialog: a #GtkPrintUnixDialog + * @capabilites: the printing capabilities of your application + * + * This lets you specify the printing capabilities your application + * supports. For instance, if you can handle scaling the output then + * you pass #GTK_PRINT_CAPABILITY_SCALE. If you don't pass that, then + * the dialog will only let you select the scale if the printing + * system automatically handles scaling. + * + * Since: 2.10 + */ +void +gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog, + GtkPrintCapabilities capabilities) +{ + dialog->priv->manual_capabilities = capabilities; + update_dialog_from_capabilities (dialog); +} #define __GTK_PRINT_UNIX_DIALOG_C__ #include "gtkaliasdef.c" diff --git a/gtk/gtkprintunixdialog.h b/gtk/gtkprintunixdialog.h index 46a925e946..b6ad921a4e 100644 --- a/gtk/gtkprintunixdialog.h +++ b/gtk/gtkprintunixdialog.h @@ -21,6 +21,7 @@ #include <gtk/gtkdialog.h> #include <gtk/gtkprinter.h> +#include <gtk/gtkprintjob.h> #include <gtk/gtkprintsettings.h> #include <gtk/gtkpagesetup.h> @@ -77,6 +78,8 @@ GtkPrinter * gtk_print_unix_dialog_get_selected_printer (GtkPrintUnixDialog void gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog, GtkWidget *child, GtkWidget *tab_label); +void gtk_print_unix_dialog_set_manual_capabilities (GtkPrintUnixDialog *dialog, + GtkPrintCapabilities capabilities); G_END_DECLS |