Skip to content

Commit

Permalink
printing: Get covers for each printer individually
Browse files Browse the repository at this point in the history
Since we combine Avahi browsed printers and
printers of local CUPS in one backend we need to
get covers for each printer separately.

https://bugzilla.gnome.org/show_bug.cgi?id=743323
  • Loading branch information
MarekKasik committed Feb 25, 2015
1 parent 7fa9089 commit 979a4c1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
51 changes: 25 additions & 26 deletions modules/printbackends/cups/gtkprintbackendcups.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ struct _GtkPrintBackendCups
GtkCupsConnectionTest *cups_connection_test;
gint reading_ppds;

char **covers;
int number_of_covers;

GList *requests;
GHashTable *auth;
gchar *username;
Expand Down Expand Up @@ -811,9 +808,6 @@ gtk_print_backend_cups_init (GtkPrintBackendCups *backend_cups)
backend_cups->auth = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, overwrite_and_free);
backend_cups->authentication_lock = FALSE;

backend_cups->covers = NULL;
backend_cups->number_of_covers = 0;

backend_cups->default_printer_poll = 0;
backend_cups->cups_connection_test = NULL;

Expand Down Expand Up @@ -857,9 +851,6 @@ gtk_print_backend_cups_finalize (GObject *object)
g_free (backend_cups->default_printer);
backend_cups->default_printer = NULL;

g_strfreev (backend_cups->covers);
backend_cups->number_of_covers = 0;

gtk_cups_connection_test_free (backend_cups->cups_connection_test);
backend_cups->cups_connection_test = NULL;

Expand Down Expand Up @@ -1987,8 +1978,18 @@ typedef struct
gboolean media_margin_default_set;
gchar *sides_default;
GList *sides_supported;
char **covers;
int number_of_covers;
} PrinterSetupInfo;

static void
printer_setup_info_free (PrinterSetupInfo *info)
{
g_free (info->state_msg);
g_strfreev (info->covers);
g_slice_free (PrinterSetupInfo, info);
}

static void
get_ipp_version (const char *ipp_version_string,
guchar *ipp_version_major,
Expand Down Expand Up @@ -2143,14 +2144,11 @@ cups_printer_handle_attribute (GtkPrintBackendCups *cups_backend,
}
else if (strcmp (ippGetName (attr), "job-sheets-supported") == 0)
{
if (cups_backend->covers == NULL)
{
cups_backend->number_of_covers = ippGetCount (attr);
cups_backend->covers = g_new (char *, cups_backend->number_of_covers + 1);
for (i = 0; i < cups_backend->number_of_covers; i++)
cups_backend->covers[i] = g_strdup (ippGetString (attr, i, NULL));
cups_backend->covers[cups_backend->number_of_covers] = NULL;
}
info->number_of_covers = ippGetCount (attr);
info->covers = g_new (char *, info->number_of_covers + 1);
for (i = 0; i < info->number_of_covers; i++)
info->covers[i] = g_strdup (ippGetString (attr, i, NULL));
info->covers[info->number_of_covers] = NULL;
}
else if (strcmp (ippGetName (attr), "job-sheets-default") == 0)
{
Expand Down Expand Up @@ -2641,6 +2639,8 @@ cups_request_printer_info_cb (GtkPrintBackendCups *cups_backend,
GTK_PRINTER_CUPS (printer)->supports_copies = info->supports_copies;
GTK_PRINTER_CUPS (printer)->supports_collate = info->supports_collate;
GTK_PRINTER_CUPS (printer)->supports_number_up = info->supports_number_up;
GTK_PRINTER_CUPS (printer)->number_of_covers = info->number_of_covers;
GTK_PRINTER_CUPS (printer)->covers = g_strdupv (info->covers);
status_changed = gtk_printer_set_job_count (printer, info->job_count);
status_changed |= gtk_printer_set_location (printer, info->location);
status_changed |= gtk_printer_set_description (printer, info->description);
Expand Down Expand Up @@ -2683,8 +2683,7 @@ cups_request_printer_info_cb (GtkPrintBackendCups *cups_backend,
set_default_printer (cups_backend, cups_backend->avahi_default_printer);
}

g_free (info->state_msg);
g_slice_free (PrinterSetupInfo, info);
printer_setup_info_free (info);

gdk_threads_leave ();
}
Expand Down Expand Up @@ -2829,8 +2828,7 @@ create_cups_printer_from_avahi_data (AvahiConnectionTestData *data)
g_object_unref (printer);
}

g_free (info->state_msg);
g_slice_free (PrinterSetupInfo, info);
printer_setup_info_free (info);
}

static void
Expand Down Expand Up @@ -3453,6 +3451,8 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,
GTK_PRINTER_CUPS (printer)->supports_copies = info->supports_copies;
GTK_PRINTER_CUPS (printer)->supports_collate = info->supports_collate;
GTK_PRINTER_CUPS (printer)->supports_number_up = info->supports_number_up;
GTK_PRINTER_CUPS (printer)->number_of_covers = info->number_of_covers;
GTK_PRINTER_CUPS (printer)->covers = g_strdupv (info->covers);
status_changed = gtk_printer_set_job_count (printer, info->job_count);
status_changed |= gtk_printer_set_location (printer, info->location);
status_changed |= gtk_printer_set_description (printer,
Expand All @@ -3471,8 +3471,7 @@ cups_request_printer_list_cb (GtkPrintBackendCups *cups_backend,

/* The ref is held by GtkPrintBackend, in add_printer() */
g_object_unref (printer);
g_free (info->state_msg);
g_slice_free (PrinterSetupInfo, info);
printer_setup_info_free (info);

if (attr == NULL)
break;
Expand Down Expand Up @@ -5244,7 +5243,7 @@ cups_printer_get_options (GtkPrinter *printer,
g_object_unref (option);
}

num_of_covers = backend->number_of_covers;
num_of_covers = cups_printer->number_of_covers;
cover = g_new (char *, num_of_covers + 1);
cover[num_of_covers] = NULL;
cover_display = g_new (char *, num_of_covers + 1);
Expand All @@ -5254,15 +5253,15 @@ cups_printer_get_options (GtkPrinter *printer,

for (i = 0; i < num_of_covers; i++)
{
cover[i] = g_strdup (backend->covers[i]);
cover[i] = g_strdup (cups_printer->covers[i]);
value = NULL;
for (j = 0; j < G_N_ELEMENTS (cover_default); j++)
if (strcmp (cover_default[j], cover[i]) == 0)
{
value = cover_display_default[j];
break;
}
cover_display[i] = (value != NULL) ? g_strdup (value) : g_strdup (backend->covers[i]);
cover_display[i] = (value != NULL) ? g_strdup (value) : g_strdup (cups_printer->covers[i]);
}

for (i = 0; i < num_of_covers; i++)
Expand Down
4 changes: 4 additions & 0 deletions modules/printbackends/cups/gtkprintercups.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ gtk_printer_cups_init (GtkPrinterCups *printer)
printer->media_margin_default_set = FALSE;
printer->sides_default = NULL;
printer->sides_supported = NULL;
printer->number_of_covers = 0;
printer->covers = NULL;
}

static void
Expand Down Expand Up @@ -176,6 +178,8 @@ gtk_printer_cups_finalize (GObject *object)
g_free (printer->avahi_domain);
#endif

g_strfreev (printer->covers);

if (printer->ppd_file)
ppdClose (printer->ppd_file);

Expand Down
2 changes: 2 additions & 0 deletions modules/printbackends/cups/gtkprintercups.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ struct _GtkPrinterCups
gboolean supports_copies;
gboolean supports_collate;
gboolean supports_number_up;
char **covers;
int number_of_covers;
};

struct _GtkPrinterCupsClass
Expand Down

0 comments on commit 979a4c1

Please sign in to comment.