Merge the gtk-printing branch. For more detailed ChangeLog entries, see
2006-04-21 Alexander Larsson <alexl@redhat.com> Merge the gtk-printing branch. For more detailed ChangeLog entries, see the branch. * .cvsignore: * Makefile.am: * configure.in: * docs/tools/widgets.c: * gtk+-unix-print-2.0.pc.in: * gtk/Makefile.am: * gtk/gen-paper-names.c: * gtk/gtk.h: * gtk/gtk.symbols: * gtk/gtkenums.h: * gtk/gtkiconfactory.c: * gtk/gtkmarshalers.list: * gtk/gtkpagesetup.[ch]: * gtk/gtkpagesetupunixdialog.[ch]: * gtk/gtkpapersize.[ch]: * gtk/gtkprint-win32.[ch]: * gtk/gtkprintbackend.[ch]: * gtk/gtkprintcontext.[ch]: * gtk/gtkprinter-private.h: * gtk/gtkprinter.[ch]: * gtk/gtkprinteroption.[ch]: * gtk/gtkprinteroptionset.[ch]: * gtk/gtkprinteroptionwidget.[ch]: * gtk/gtkprintjob.[ch]: * gtk/gtkprintoperation-private.h: * gtk/gtkprintoperation-unix.c: * gtk/gtkprintoperation-win32.c: * gtk/gtkprintoperation.[ch]: * gtk/gtkprintsettings.[ch]: * gtk/gtkprintunixdialog.[ch]: * gtk/paper_names.c: * gtk/paper_names_offsets.c: Platform independent printing API and implementations for unix and windows. * gtk/gtkstock.h: * gtk/stock-icons/24/gtk-orientation-landscape.png: * gtk/stock-icons/24/gtk-orientation-portrait.png: * gtk/stock-icons/24/gtk-orientation-reverse-landscape.png: Add stock icons for page orientation. * modules/Makefile.am: * modules/printbackends/Makefile.am: * modules/printbackends/cups/Makefile.am: * modules/printbackends/cups/gtkcupsutils.[ch]: * modules/printbackends/cups/gtkprintbackendcups.[ch]: * modules/printbackends/cups/gtkprintercups.[ch]: Cups printing backend for unix. * modules/printbackends/lpr/Makefile.am: * modules/printbackends/lpr/gtkprintbackendlpr.[ch]: lpr printing backend for unix. * modules/printbackends/pdf/Makefile.am: * modules/printbackends/pdf/gtkprintbackendpdf.[ch]: print-to-pdf printing backend for unix. * tests/.cvsignore: * tests/Makefile.am: * tests/print-editor.c: Test application for printing. * gdk/gdk.symbols: * gdk/win32/gdkevents-win32.c: * gdk/win32/gdkwin32.h: Add gdk_win32_set_modal_dialog_libgtk_only so that we can pump the mainloop while displaying a win32 common dialog. * gdk/directfb/Makefile.am: Whitespace cleanup.
This commit is contained in:
committed by
Alexander Larsson
parent
ea32742b93
commit
27f746fbd0
243
gtk/gtkprintoperation-unix.c
Normal file
243
gtk/gtkprintoperation-unix.c
Normal file
@ -0,0 +1,243 @@
|
||||
/* GTK - The GIMP Toolkit
|
||||
* gtkprintoperation-unix.c: Print Operation Details for Unix and Unix like platforms
|
||||
* Copyright (C) 2006, Red Hat, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gtkprintoperation-private.h"
|
||||
#include "gtkmarshal.h"
|
||||
#include "gtkmessagedialog.h"
|
||||
|
||||
#include "gtkprintunixdialog.h"
|
||||
#include "gtkpagesetupunixdialog.h"
|
||||
#include "gtkprintbackend.h"
|
||||
#include "gtkprinter.h"
|
||||
#include "gtkprintjob.h"
|
||||
#include "gtkalias.h"
|
||||
|
||||
typedef struct {
|
||||
GtkPrintJob *job; /* the job we are sending to the printer */
|
||||
gulong job_status_changed_tag;
|
||||
GtkWindow *parent; /* parent window just in case we need to throw error dialogs */
|
||||
} GtkPrintOperationUnix;
|
||||
|
||||
static void
|
||||
unix_start_page (GtkPrintOperation *op,
|
||||
GtkPrintContext *print_context,
|
||||
GtkPageSetup *page_setup)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
unix_end_page (GtkPrintOperation *op,
|
||||
GtkPrintContext *print_context)
|
||||
{
|
||||
cairo_t *cr;
|
||||
|
||||
cr = gtk_print_context_get_cairo (print_context);
|
||||
cairo_show_page (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
op_unix_free (GtkPrintOperationUnix *op_unix)
|
||||
{
|
||||
if (op_unix->job)
|
||||
{
|
||||
g_signal_handler_disconnect (op_unix->job,
|
||||
op_unix->job_status_changed_tag);
|
||||
g_object_unref (op_unix->job);
|
||||
}
|
||||
|
||||
g_free (op_unix);
|
||||
}
|
||||
|
||||
static void
|
||||
unix_finish_send (GtkPrintJob *job,
|
||||
void *user_data,
|
||||
GError *error)
|
||||
{
|
||||
GtkPrintOperationUnix *op_unix;
|
||||
GtkWindow *parent;
|
||||
|
||||
op_unix = (GtkPrintOperationUnix *) user_data;
|
||||
|
||||
parent = op_unix->parent;
|
||||
|
||||
if (error != NULL)
|
||||
{
|
||||
GtkWidget *edialog;
|
||||
edialog = gtk_message_dialog_new (parent,
|
||||
GTK_DIALOG_DESTROY_WITH_PARENT,
|
||||
GTK_MESSAGE_ERROR,
|
||||
GTK_BUTTONS_CLOSE,
|
||||
"Error printing: %s",
|
||||
error->message);
|
||||
|
||||
gtk_dialog_run (GTK_DIALOG (edialog));
|
||||
gtk_widget_destroy (edialog);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
unix_end_run (GtkPrintOperation *op)
|
||||
{
|
||||
GtkPrintOperationUnix *op_unix = op->priv->platform_data;
|
||||
|
||||
/* TODO: Check for error */
|
||||
gtk_print_job_send (op_unix->job,
|
||||
unix_finish_send,
|
||||
op_unix, NULL,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
job_status_changed_cb (GtkPrintJob *job, GtkPrintOperation *op)
|
||||
{
|
||||
_gtk_print_operation_set_status (op, gtk_print_job_get_status (job), NULL);
|
||||
}
|
||||
|
||||
GtkPrintOperationResult
|
||||
_gtk_print_operation_platform_backend_run_dialog (GtkPrintOperation *op,
|
||||
GtkWindow *parent,
|
||||
gboolean *do_print,
|
||||
GError **error)
|
||||
{
|
||||
GtkWidget *pd;
|
||||
GtkPrintOperationResult result;
|
||||
GtkPageSetup *page_setup;
|
||||
|
||||
result = GTK_PRINT_OPERATION_RESULT_CANCEL;
|
||||
|
||||
if (op->priv->default_page_setup)
|
||||
page_setup = gtk_page_setup_copy (op->priv->default_page_setup);
|
||||
else
|
||||
page_setup = gtk_page_setup_new ();
|
||||
|
||||
pd = gtk_print_unix_dialog_new (NULL, parent);
|
||||
|
||||
if (op->priv->print_settings)
|
||||
gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (pd),
|
||||
op->priv->print_settings);
|
||||
|
||||
gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (pd), page_setup);
|
||||
|
||||
*do_print = FALSE;
|
||||
if (gtk_dialog_run (GTK_DIALOG (pd)) == GTK_RESPONSE_OK)
|
||||
{
|
||||
GtkPrintOperationUnix *op_unix;
|
||||
GtkPrinter *printer;
|
||||
GtkPrintSettings *settings;
|
||||
|
||||
result = GTK_PRINT_OPERATION_RESULT_APPLY;
|
||||
|
||||
printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (pd));
|
||||
if (printer == NULL)
|
||||
goto out;
|
||||
|
||||
*do_print = TRUE;
|
||||
|
||||
settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (pd));
|
||||
gtk_print_operation_set_print_settings (op, settings);
|
||||
|
||||
op_unix = g_new0 (GtkPrintOperationUnix, 1);
|
||||
op_unix->job = gtk_print_job_new (op->priv->job_name,
|
||||
printer,
|
||||
settings,
|
||||
page_setup);
|
||||
g_object_unref (settings);
|
||||
|
||||
op->priv->surface = gtk_print_job_get_surface (op_unix->job, error);
|
||||
if (op->priv->surface == NULL)
|
||||
{
|
||||
*do_print = FALSE;
|
||||
op_unix_free (op_unix);
|
||||
result = GTK_PRINT_OPERATION_RESULT_ERROR;
|
||||
goto out;
|
||||
}
|
||||
|
||||
_gtk_print_operation_set_status (op, gtk_print_job_get_status (op_unix->job), NULL);
|
||||
op_unix->job_status_changed_tag =
|
||||
g_signal_connect (op_unix->job, "status_changed",
|
||||
G_CALLBACK (job_status_changed_cb), op);
|
||||
|
||||
op_unix->parent = parent;
|
||||
|
||||
op->priv->dpi_x = 72;
|
||||
op->priv->dpi_y = 72;
|
||||
|
||||
op->priv->platform_data = op_unix;
|
||||
op->priv->free_platform_data = (GDestroyNotify) op_unix_free;
|
||||
|
||||
op->priv->print_pages = op_unix->job->print_pages;
|
||||
op->priv->page_ranges = op_unix->job->page_ranges;
|
||||
op->priv->num_page_ranges = op_unix->job->num_page_ranges;
|
||||
|
||||
op->priv->manual_num_copies = op_unix->job->num_copies;
|
||||
op->priv->manual_collation = op_unix->job->collate;
|
||||
op->priv->manual_reverse = op_unix->job->reverse;
|
||||
op->priv->manual_page_set = op_unix->job->page_set;
|
||||
op->priv->manual_scale = op_unix->job->scale;
|
||||
op->priv->manual_orientation = op_unix->job->rotate_to_orientation;
|
||||
}
|
||||
|
||||
op->priv->start_page = unix_start_page;
|
||||
op->priv->end_page = unix_end_page;
|
||||
op->priv->end_run = unix_end_run;
|
||||
|
||||
out:
|
||||
g_object_unref (page_setup);
|
||||
|
||||
gtk_widget_destroy (pd);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GtkPageSetup *
|
||||
gtk_print_run_page_setup_dialog (GtkWindow *parent,
|
||||
GtkPageSetup *page_setup,
|
||||
GtkPrintSettings *settings)
|
||||
{
|
||||
GtkWidget *dialog;
|
||||
GtkPageSetup *new_page_setup;
|
||||
|
||||
dialog = gtk_page_setup_unix_dialog_new (NULL, parent);
|
||||
if (page_setup)
|
||||
gtk_page_setup_unix_dialog_set_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
|
||||
page_setup);
|
||||
gtk_page_setup_unix_dialog_set_print_settings (GTK_PAGE_SETUP_UNIX_DIALOG (dialog),
|
||||
settings);
|
||||
gtk_dialog_run (GTK_DIALOG (dialog));
|
||||
|
||||
new_page_setup = gtk_page_setup_unix_dialog_get_page_setup (GTK_PAGE_SETUP_UNIX_DIALOG (dialog));
|
||||
|
||||
gtk_widget_destroy (dialog);
|
||||
|
||||
return new_page_setup;
|
||||
}
|
||||
|
||||
|
||||
#define __GTK_PRINT_OPERATION_UNIX_C__
|
||||
#include "gtkaliasdef.c"
|
||||
Reference in New Issue
Block a user