]> www.fi.muni.cz Git - evince.git/commitdiff
Added ev-print-job.c.
authorMartin Kretzschmar <martink@src.gnome.org>
Sat, 8 Jan 2005 19:02:48 +0000 (19:02 +0000)
committerMartin Kretzschmar <martink@src.gnome.org>
Sat, 8 Jan 2005 19:02:48 +0000 (19:02 +0000)
* POTFILES.in: Added ev-print-job.c.

* shell/ev-print-job.c (ev_print_job_finalize)
(ev_print_job_set_property, ev_print_job_get_property)
(ev_print_job_set_gnome_print_job, ev_print_job_set_document)
(ev_print_job_use_print_dialog_settings, idle_print_handler)
(print_closure_finalize, ev_print_job_print): implement
printing (for backends with EvPsExporter)

* shell/ev-window.c (ev_window_print): unref print job after
printing.

ChangeLog
po/ChangeLog
po/POTFILES.in
shell/ev-print-job.c
shell/ev-print-job.h
shell/ev-window.c

index a0f4499de0df6716d22be4c3fcfbc37c2483b8fa..995300f469a058d0cb4a895234667f66b05871b9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2005-01-08  Martin Kretzschmar  <martink@gnome.org>
 
+       * shell/ev-print-job.c (ev_print_job_finalize)
+       (ev_print_job_set_property, ev_print_job_get_property)
+       (ev_print_job_set_gnome_print_job, ev_print_job_set_document)
+       (ev_print_job_use_print_dialog_settings, idle_print_handler)
+       (print_closure_finalize, ev_print_job_print): implement
+       printing (for backends with EvPsExporter)
+
+       * shell/ev_print_job.h: update prototypes.
+
+       * shell/ev-window.c (ev_window_print): unref print job after
+       printing.
+
        * shell/ev-view.c (ev_view_set_document): don't connect to "found"
        unless the document implements the EvDocumentFind interface.
 
index d512088117d2337117c602cfae9a962ae973fce5..ac8930ddc4c2acddf084bc92e78bf940a92c97ca 100644 (file)
@@ -1,3 +1,7 @@
+2005-01-08  Martin Kretzschmar  <martink@gnome.org>
+
+       * POTFILES.in: Added ev-print-job.c.
+
 2005-01-08  Satoru SATOH <ss@gnome.gr.jp>
 
        * ja.po: Added Japanese translation.
index cc08656da2ee19a9459a0ac031cdeb6f42350e40..dfa6f5278b811e2d739c547b0f73208182500f79 100644 (file)
@@ -7,6 +7,7 @@ ps/ps-document.c
 shell/eggfindbar.c
 shell/ev-application.c
 shell/ev-page-action.c
+shell/ev-print-job.c
 shell/ev-view.c
 shell/ev-window.c
 shell/main.c
index ea261c3808e41b51d47935a732df342cdc5aadd9..0c66b81a2e175d1e67ad29352f14828e555a90c9 100644 (file)
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
  */
 
+#include <config.h>
+
+#include <unistd.h>
+
 #include <glib.h>
+#include <glib/gi18n.h>
 #include <glib-object.h>
 
+/* for gnome_print_job_set_file */
+#define GNOME_PRINT_UNSTABLE_API
+#include <libgnomeprint/gnome-print-job.h>
+
+#include "ev-ps-exporter.h"
 #include "ev-print-job.h"
 
 #define EV_PRINT_JOB_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), EV_PRINT_JOB, EvPrintJobClass))
 
 struct _EvPrintJob {
        GObject parent_instance;
+
+       EvDocument *document;
+       GnomePrintJob *gnome_print_job;
+       double width; /* FIXME unused */
+       double height; /* FIXME unused */
+       gboolean duplex; /* FIXME unused */
+       int copies; /* FIXME unused */
+       int collate; /* FIXME unsued */
+
+       int fd;
+       char *temp_file;
+       guint idle_id;
+       gboolean printing;
+       int next_page;
 };
 
 struct _EvPrintJobClass {
        GObjectClass parent_class;
 };
 
+enum {
+       PROP_0,
+       PROP_GNOME_PRINT_JOB,
+       PROP_DOCUMENT,
+       PROP_PRINT_DIALOG
+};
 
 G_DEFINE_TYPE (EvPrintJob, ev_print_job, G_TYPE_OBJECT);
 
+static void
+ev_print_job_finalize (GObject *object)
+{
+       EvPrintJob *job = EV_PRINT_JOB (object);
+
+       if (job && job->document) {
+               g_object_unref (job->document);
+               job->document = NULL;
+       }
+
+       if (job && job->gnome_print_job) {
+               g_object_unref (job->gnome_print_job);
+               job->gnome_print_job = NULL;
+       }
+
+       G_OBJECT_CLASS (ev_print_job_parent_class)->finalize (object);
+}
+
+static void
+ev_print_job_set_property (GObject *object, guint prop_id,
+                          const GValue *value, GParamSpec *pspec)
+{
+       EvPrintJob *job;
+
+       job = EV_PRINT_JOB (object);
+
+       switch (prop_id) {
+       case PROP_GNOME_PRINT_JOB:
+               ev_print_job_set_gnome_print_job (
+                       job, GNOME_PRINT_JOB (g_value_get_object (value)));
+               break;
+       case PROP_DOCUMENT:
+               ev_print_job_set_document (job, EV_DOCUMENT (g_value_get_object (value)));
+               break;
+       case PROP_PRINT_DIALOG:
+               ev_print_job_use_print_dialog_settings (
+                       job, GNOME_PRINT_DIALOG (g_value_get_object (value)));
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+
+}
+
+static void
+ev_print_job_get_property (GObject *object, guint prop_id,
+                          GValue *value, GParamSpec *pspec)
+{
+       EvPrintJob *job;
+
+       job = EV_PRINT_JOB (object);
+
+       switch (prop_id) {
+       case PROP_GNOME_PRINT_JOB:
+               g_value_set_object (value, job->gnome_print_job);
+               break;
+       case PROP_DOCUMENT:
+               g_value_set_object (value, job->document);
+               break;
+       default:
+               G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+               break;
+       }
+}
+
+
 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);
+
+       g_object_class->finalize = ev_print_job_finalize;
+       g_object_class->set_property = ev_print_job_set_property;
+       g_object_class->get_property = ev_print_job_get_property;
+
+       g_object_class_install_property (g_object_class,
+                                        PROP_GNOME_PRINT_JOB,
+                                        g_param_spec_object ("gnome_print_job",
+                                                             "GnomePrintJob",
+                                                             "GnomePrintJob",
+                                                             GNOME_TYPE_PRINT_JOB,
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (g_object_class,
+                                        PROP_DOCUMENT,
+                                        g_param_spec_object ("document",
+                                                             "Document object",
+                                                             "Document from which to print",
+                                                             G_TYPE_OBJECT, /* EV_TYPE_DOCUMENT, */
+                                                             G_PARAM_READWRITE));
+       g_object_class_install_property (g_object_class,
+                                        PROP_PRINT_DIALOG,
+                                        g_param_spec_object ("print_dialog",
+                                                             "GnomePrintDialog",
+                                                             "GnomePrintDialog with user settings",
+                                                             GNOME_TYPE_PRINT_DIALOG,
+                                                             G_PARAM_WRITABLE));
+
 }
 
 static void
@@ -53,10 +177,128 @@ ev_print_job_init (EvPrintJob *ev_print_job)
 {
 }
 
+void
+ev_print_job_set_gnome_print_job (EvPrintJob *job, GnomePrintJob *gpj)
+{
+       g_return_if_fail (EV_IS_PRINT_JOB (job));
+
+       if (job->gnome_print_job == gpj)
+               return;
+
+       if (job->gnome_print_job)
+               g_object_unref (job->gnome_print_job);
+       
+       if (gpj)
+               g_object_ref (gpj);
+
+       job->gnome_print_job = gpj;
+}
+
+void
+ev_print_job_set_document (EvPrintJob *job, EvDocument *document)
+{
+       g_return_if_fail (EV_IS_PRINT_JOB (job));
+
+       if (job->document == document)
+               return;
+
+       if (job->document)
+               g_object_ref (job->document);
+
+       if (document)
+               g_object_ref (document);
+       
+       job->document = document;
+}
+
+void
+ev_print_job_use_print_dialog_settings (EvPrintJob *job, GnomePrintDialog *dialog)
+{
+       GnomePrintConfig *print_config;
+
+       g_return_if_fail (EV_IS_PRINT_JOB (job));
+       g_return_if_fail (GNOME_IS_PRINT_DIALOG (dialog));
+
+       print_config = gnome_print_dialog_get_config (dialog);
+       gnome_print_dialog_get_copies (dialog, &job->copies, &job->collate);
+       gnome_print_config_get_page_size (print_config,
+                                         &job->width, &job->height);
+       gnome_print_config_get_boolean (print_config,
+                                       GNOME_PRINT_KEY_DUPLEX, &job->duplex);
+       gnome_print_config_unref (print_config);
+}
+
+static gboolean
+idle_print_handler (EvPrintJob *job)
+{
+       if (!job->printing) {
+               ev_ps_exporter_begin (EV_PS_EXPORTER (job->document),
+                                     job->temp_file);
+               job->next_page = 1; /* FIXME use 0-based page numbering? */
+               job->printing = TRUE;
+               return TRUE;
+       }
+
+       if (job->next_page <= ev_document_get_n_pages (job->document)) {
+#if 0
+               g_printerr ("Printing page %d\n", job->next_page);
+#endif
+               ev_ps_exporter_do_page (EV_PS_EXPORTER (job->document),
+                                       job->next_page);
+               job->next_page++;
+               return TRUE;
+       } else { /* no more pages */
+               ev_ps_exporter_end (EV_PS_EXPORTER (job->document));
+
+               close (job->fd);
+               job->fd = 0;
+
+               gnome_print_job_print (job->gnome_print_job);
+
+               unlink (job->temp_file);
+               g_free (job->temp_file);
+
+               g_object_unref (job->gnome_print_job);
+               job->gnome_print_job = NULL;
+
+               job->printing = FALSE;
+               job->idle_id = 0;
+               return FALSE;
+       }
+}
+
+static void
+print_closure_finalize (EvPrintJob *job, GClosure *closure)
+{
+       g_object_unref (job);
+}
+
 void
 ev_print_job_print (EvPrintJob *job, GtkWindow *parent)
 {
+       GClosure *closure;
+       GSource *idle_source;
+
        g_return_if_fail (EV_IS_PRINT_JOB (job));
-       /* FIXME */
+       g_return_if_fail (job->document != NULL);
+       g_return_if_fail (EV_IS_PS_EXPORTER (job->document));
+#if 0
        g_printerr ("Printing...\n");
+#endif
+
+       job->fd = g_file_open_tmp ("evince_print.ps.XXXXXX", &job->temp_file, NULL);
+       if (job->fd <= -1)
+               return; /* FIXME use GError */
+
+       gnome_print_job_set_file (job->gnome_print_job, job->temp_file);
+
+       g_object_ref (job);
+       closure = g_cclosure_new (G_CALLBACK (idle_print_handler), job, NULL);
+       g_closure_add_finalize_notifier (
+               closure, job, (GClosureNotify)print_closure_finalize);
+
+       idle_source = g_idle_source_new ();
+       g_source_set_closure (idle_source, closure);
+       job->idle_id = g_source_attach (idle_source, NULL);
+       g_source_unref (idle_source);
 }
index 0b5dc2add9eddb4a6722eda03df3ac720b30f033..30a1430a7dc20a6e1ba0a4cae2f2f1dc9a45342a 100644 (file)
@@ -25,6 +25,9 @@
 
 #include <glib-object.h>
 #include <gtk/gtk.h>
+#include <libgnomeprintui/gnome-print-dialog.h>
+
+#include "ev-document.h"
 
 G_BEGIN_DECLS
 
@@ -35,8 +38,11 @@ typedef struct _EvPrintJobClass EvPrintJobClass;
 #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);
+GType          ev_print_job_get_type                   (void);
+void           ev_print_job_set_gnome_print_job        (EvPrintJob *job, GnomePrintJob *gpj);
+void           ev_print_job_set_document               (EvPrintJob *job, EvDocument *document);
+void           ev_print_job_use_print_dialog_settings  (EvPrintJob *job, GnomePrintDialog *dialog);
+void           ev_print_job_print                      (EvPrintJob *job, GtkWindow *parent);
 
 G_END_DECLS
 
index 8f01111b89f93d4112674febcb1a19958d39376c..ff4c5d2417bd1c1fe786a56d63cdcab7acdc3b6a 100644 (file)
@@ -545,8 +545,10 @@ ev_window_print (EvWindow *ev_window)
                                
        gtk_widget_destroy (print_dialog);
 
-       if (print_job != NULL)
+       if (print_job != NULL) {
                ev_print_job_print (print_job, GTK_WINDOW (ev_window));
+               g_object_unref (print_job);
+       }
 }
 
 static void