[gtk+/gtk-2-24] Set file GtkPrinter accepts_pdf/ps based on selected format
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2-24] Set file GtkPrinter accepts_pdf/ps based on selected format
- Date: Thu, 6 Jan 2011 17:53:52 +0000 (UTC)
commit 0c6d327a25d23b8e09bc471ff5a61ff6fbd91d1a
Author: Adrian Johnson <ajohnson redneon com>
Date: Wed Dec 29 16:04:49 2010 +1030
Set file GtkPrinter accepts_pdf/ps based on selected format
gtk/gtkprintbackend.h | 4 ++
gtk/gtkprinter.c | 18 ++++++
modules/printbackends/file/gtkprintbackendfile.c | 63 ++++++++++++++++++++--
3 files changed, 80 insertions(+), 5 deletions(-)
---
diff --git a/gtk/gtkprintbackend.h b/gtk/gtkprintbackend.h
index e19193f..b23220a 100644
--- a/gtk/gtkprintbackend.h
+++ b/gtk/gtkprintbackend.h
@@ -172,6 +172,10 @@ GtkPrinter *gtk_printer_new (const char *name,
GtkPrintBackend *backend,
gboolean is_virtual);
gboolean gtk_printer_is_new (GtkPrinter *printer);
+void gtk_printer_set_accepts_pdf (GtkPrinter *printer,
+ gboolean val);
+void gtk_printer_set_accepts_ps (GtkPrinter *printer,
+ gboolean val);
void gtk_printer_set_is_new (GtkPrinter *printer,
gboolean val);
void gtk_printer_set_is_active (GtkPrinter *printer,
diff --git a/gtk/gtkprinter.c b/gtk/gtkprinter.c
index 0f0541f..ccc2b18 100644
--- a/gtk/gtkprinter.c
+++ b/gtk/gtkprinter.c
@@ -779,6 +779,15 @@ gtk_printer_accepts_pdf (GtkPrinter *printer)
return printer->priv->accepts_pdf;
}
+void
+gtk_printer_set_accepts_pdf (GtkPrinter *printer,
+ gboolean val)
+{
+ g_return_if_fail (GTK_IS_PRINTER (printer));
+
+ printer->priv->accepts_pdf = val;
+}
+
/**
* gtk_printer_accepts_ps:
* @printer: a #GtkPrinter
@@ -798,6 +807,15 @@ gtk_printer_accepts_ps (GtkPrinter *printer)
return printer->priv->accepts_ps;
}
+void
+gtk_printer_set_accepts_ps (GtkPrinter *printer,
+ gboolean val)
+{
+ g_return_if_fail (GTK_IS_PRINTER (printer));
+
+ printer->priv->accepts_ps = val;
+}
+
gboolean
gtk_printer_is_new (GtkPrinter *printer)
{
diff --git a/modules/printbackends/file/gtkprintbackendfile.c b/modules/printbackends/file/gtkprintbackendfile.c
index 2731fea..20d157d 100644
--- a/modules/printbackends/file/gtkprintbackendfile.c
+++ b/modules/printbackends/file/gtkprintbackendfile.c
@@ -506,17 +506,63 @@ gtk_print_backend_file_init (GtkPrintBackendFile *backend)
gtk_print_backend_set_list_done (GTK_PRINT_BACKEND (backend));
}
+typedef struct {
+ GtkPrinter *printer;
+ GtkPrinterOptionSet *set;
+} _OutputFormatChangedData;
+
+static void
+set_printer_format_from_option_set (GtkPrinter *printer,
+ GtkPrinterOptionSet *set)
+{
+ GtkPrinterOption *format_option;
+ const gchar *value;
+ gint i;
+
+ format_option = gtk_printer_option_set_lookup (set, "output-file-format");
+ if (format_option && format_option->value)
+ {
+ value = format_option->value;
+ if (value)
+ {
+ for (i = 0; i < N_FORMATS; ++i)
+ if (strcmp (value, formats[i]) == 0)
+ break;
+
+ g_assert (i < N_FORMATS);
+
+ switch (i)
+ {
+ case FORMAT_PDF:
+ gtk_printer_set_accepts_pdf (printer, TRUE);
+ gtk_printer_set_accepts_ps (printer, FALSE);
+ break;
+ case FORMAT_PS:
+ gtk_printer_set_accepts_pdf (printer, FALSE);
+ gtk_printer_set_accepts_ps (printer, TRUE);
+ break;
+ case FORMAT_SVG:
+ default:
+ gtk_printer_set_accepts_pdf (printer, FALSE);
+ gtk_printer_set_accepts_ps (printer, FALSE);
+ break;
+ }
+ }
+ }
+}
+
static void
file_printer_output_file_format_changed (GtkPrinterOption *format_option,
- GtkPrinterOptionSet *set)
+ gpointer user_data)
{
GtkPrinterOption *uri_option;
gchar *base = NULL;
+ _OutputFormatChangedData *data = (_OutputFormatChangedData *) user_data;
if (! format_option->value)
return;
- uri_option = gtk_printer_option_set_lookup (set,
+ uri_option = gtk_printer_option_set_lookup (data->set,
"gtk-main-page-custom-input");
if (uri_option && uri_option->value)
@@ -556,6 +602,8 @@ file_printer_output_file_format_changed (GtkPrinterOption *format_option,
g_free (tmp);
g_free (base);
}
+
+ set_printer_format_from_option_set (data->printer, data->set);
}
static GtkPrinterOptionSet *
@@ -575,6 +623,7 @@ file_printer_get_options (GtkPrinter *printer,
OutputFormat format;
gchar *uri;
gint current_format = 0;
+ _OutputFormatChangedData *format_changed_data;
format = format_from_settings (settings);
@@ -659,9 +708,13 @@ file_printer_get_options (GtkPrinter *printer,
gtk_printer_option_set (option, supported_formats[current_format]);
gtk_printer_option_set_add (set, option);
- g_signal_connect (option, "changed",
- G_CALLBACK (file_printer_output_file_format_changed),
- set);
+ set_printer_format_from_option_set (printer, set);
+ format_changed_data = g_new (_OutputFormatChangedData, 1);
+ format_changed_data->printer = printer;
+ format_changed_data->set = set;
+ g_signal_connect_data (option, "changed",
+ G_CALLBACK (file_printer_output_file_format_changed),
+ format_changed_data, (GClosureNotify)g_free, 0);
g_object_unref (option);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]