]> www.fi.muni.cz Git - evince.git/commitdiff
Set up a print dialog for "PostScript injection" method.
authorMartin Kretzschmar <martink@src.gnome.org>
Wed, 22 Dec 2004 22:00:20 +0000 (22:00 +0000)
committerMartin Kretzschmar <martink@src.gnome.org>
Wed, 22 Dec 2004 22:00:20 +0000 (22:00 +0000)
* shell/ev-window.c (ev_window_cmd_file_print, ev_window_print)
(using_postscript_printer): Set up a print dialog for "PostScript
injection" method.

* shell/ev-print-job.h, shell/ev-print-job.c: stub classes for
EvPrintJob.

* shell/Makefile.am (evince_SOURCES): add ev-print-job.[ch]

ChangeLog
shell/Makefile.am
shell/ev-print-job.c [new file with mode: 0644]
shell/ev-print-job.h [new file with mode: 0644]
shell/ev-window.c

index fd3264709ba75378a19be1f937a4164c4c5bcf7c..ecff394bda6b789c6f66313b1af725f1bf76f8a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2004-12-22  Martin Kretzschmar  <martink@gnome.org>
+
+       * shell/ev-window.c (ev_window_cmd_file_print, ev_window_print)
+       (using_postscript_printer): Set up a print dialog for "PostScript
+       injection" method.
+
+       * shell/ev-print-job.h, shell/ev-print-job.c: stub classes for
+       EvPrintJob.
+
+       * shell/Makefile.am (evince_SOURCES): add ev-print-job.[ch]
+
 2004-12-22  Marco Pesenti Gritti  <marco@gnome.org>
 
        * ps/gtkgs.c: (gtk_gs_init), (set_up_page),
index 4740485202543da039d814cd98349a1396e36cf1..33e748321ddbd5ff2c666aaf5abd6f419c667fd4 100644 (file)
@@ -23,6 +23,8 @@ evince_SOURCES=                               \
        ev-application.h                \
        ev-marshal.c                    \
        ev-marshal.h                    \
+       ev-print-job.c                  \
+       ev-print-job.h                  \
        ev-view.c                       \
        ev-view.h                       \
        ev-window.c                     \
diff --git a/shell/ev-print-job.c b/shell/ev-print-job.c
new file mode 100644 (file)
index 0000000..ea261c3
--- /dev/null
@@ -0,0 +1,62 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2004 Martin Kretzschmar
+ *
+ *  Author:
+ *    Martin Kretzschmar <martink@gnome.org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include <glib.h>
+#include <glib-object.h>
+
+#include "ev-print-job.h"
+
+#define EV_PRINT_JOB_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), EV_PRINT_JOB, EvPrintJobClass))
+#define EV_IS_PRINT_JOB_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), EV_PRINT_JOB))
+#define EV_PRINT_JOB_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), EV_PRINT_JOB, EvPrintJobClass))
+
+struct _EvPrintJob {
+       GObject parent_instance;
+};
+
+struct _EvPrintJobClass {
+       GObjectClass parent_class;
+};
+
+
+G_DEFINE_TYPE (EvPrintJob, ev_print_job, G_TYPE_OBJECT);
+
+static void
+ev_print_job_class_init (EvPrintJobClass *ev_print_job_class)
+{
+       GObjectClass *g_object_class;
+
+       g_object_class = G_OBJECT_CLASS (ev_print_job_class);
+}
+
+static void
+ev_print_job_init (EvPrintJob *ev_print_job)
+{
+}
+
+void
+ev_print_job_print (EvPrintJob *job, GtkWindow *parent)
+{
+       g_return_if_fail (EV_IS_PRINT_JOB (job));
+       /* FIXME */
+       g_printerr ("Printing...\n");
+}
diff --git a/shell/ev-print-job.h b/shell/ev-print-job.h
new file mode 100644 (file)
index 0000000..0b5dc2a
--- /dev/null
@@ -0,0 +1,43 @@
+/* this file is part of evince, a gnome document viewer
+ *
+ *  Copyright (C) 2004 Martin Kretzschmar
+ *
+ *  Author:
+ *    Martin Kretzschmar <martink@gnome.org>
+ *
+ * Evince is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Evince 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef EV_PRINT_JOB_H
+#define EV_PRINT_JOB_H
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+typedef struct _EvPrintJob EvPrintJob;
+typedef struct _EvPrintJobClass EvPrintJobClass;
+
+#define EV_TYPE_PRINT_JOB              (ev_print_job_get_type())
+#define EV_PRINT_JOB(object)           (G_TYPE_CHECK_INSTANCE_CAST((object), EV_TYPE_PRINT_JOB, EvPrintJob))
+#define EV_IS_PRINT_JOB(object)                (G_TYPE_CHECK_INSTANCE_TYPE((object), EV_TYPE_PRINT_JOB))
+
+GType          ev_print_job_get_type           (void);
+void           ev_print_job_print              (EvPrintJob *job, GtkWindow *parent);
+
+G_END_DECLS
+
+#endif /* !EV_PRINT_JOB_H */
index 4e1cc65008d6a503f58a4e411971fff9e3ca90b6..0ca5df0b7473168dbf362a488bac40377aaf9dd0 100644 (file)
@@ -33,6 +33,7 @@
 #include "ev-sidebar-bookmarks.h"
 #include "ev-sidebar-thumbnails.h"
 #include "ev-view.h"
+#include "ev-print-job.h"
 #include "eggfindbar.h"
 
 #include "pdf-document.h"
@@ -42,6 +43,7 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 #include <libgnomevfs/gnome-vfs-mime-utils.h>
+#include <libgnomeprintui/gnome-print-dialog.h>
 
 #include <string.h>
 
@@ -300,11 +302,97 @@ ev_window_cmd_file_open (GtkAction *action, EvWindow *ev_window)
        ev_application_open (EV_APP, NULL);
 }
 
+static gboolean
+using_postscript_printer (GnomePrintConfig *config)
+{
+       const guchar *driver;
+       const guchar *transport;
+
+       driver = gnome_print_config_get (
+               config, (const guchar *)"Settings.Engine.Backend.Driver");
+       
+       transport = gnome_print_config_get (
+               config, (const guchar *)"Settings.Transport.Backend");
+       
+       if (driver) {
+               if (!strcmp ((const gchar *)driver, "gnome-print-ps"))
+                       return TRUE;
+               else 
+                       return FALSE;
+       } else  if (transport) {
+               if (!strcmp ((const gchar *)transport, "CUPS"))
+                       return TRUE;
+       }
+       
+       return FALSE;
+}
+
 static void
-ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
+ev_window_print (EvWindow *ev_window)
 {
+       GnomePrintConfig *config;
+       GnomePrintJob *job;
+       GtkWidget *print_dialog;
+       EvPrintJob *print_job = NULL;
+
         g_return_if_fail (EV_IS_WINDOW (ev_window));
-        /* FIXME */
+       g_return_if_fail (ev_window->priv->document != NULL);
+
+       config = gnome_print_config_default ();
+       job = gnome_print_job_new (config);
+
+       print_dialog = gnome_print_dialog_new (job, _("Print"),
+                                              (GNOME_PRINT_DIALOG_RANGE |
+                                               GNOME_PRINT_DIALOG_COPIES));
+       gtk_dialog_set_response_sensitive (GTK_DIALOG (print_dialog),
+                                          GNOME_PRINT_DIALOG_RESPONSE_PREVIEW,
+                                          FALSE);
+       
+       while (TRUE) {
+               int response;
+               response = gtk_dialog_run (GTK_DIALOG (print_dialog));
+               
+               if (response != GNOME_PRINT_DIALOG_RESPONSE_PRINT)
+                       break;
+
+               /* FIXME: Change this when we have the first backend
+                * that can print more than postscript
+                */
+               if (!using_postscript_printer (config)) {
+                       GtkWidget *dialog;
+                       
+                       dialog = gtk_message_dialog_new (
+                               GTK_WINDOW (print_dialog), GTK_DIALOG_MODAL,
+                               GTK_MESSAGE_ERROR, GTK_BUTTONS_OK,
+                               _("Printing is not supported on this printer."));
+                       gtk_message_dialog_format_secondary_text (
+                               GTK_MESSAGE_DIALOG (dialog),
+                               _("You were trying to print to a printer using the \"%s\" driver. This program requires a PostScript printer driver."),
+                               gnome_print_config_get (
+                                       config, "Settings.Engine.Backend.Driver"));
+                       gtk_dialog_run (GTK_DIALOG (dialog));
+                       gtk_widget_destroy (dialog);
+
+                       continue;
+               }
+
+               print_job = g_object_new (EV_TYPE_PRINT_JOB,
+                                         "document", ev_window->priv->document,
+                                         "print-dialog", print_dialog,
+                                         NULL);
+               break;
+       }
+                               
+       gtk_widget_destroy (print_dialog);
+
+       if (print_job != NULL)
+               ev_print_job_print (print_job, GTK_WINDOW (ev_window));
+}
+
+static void
+ev_window_cmd_file_print (GtkAction *action, EvWindow *ev_window)
+{
+       ev_window_print (ev_window);
 }
 
 static void