gedit r6081 - branches/printing/gedit



Author: pborelli
Date: Sat Jan 12 21:20:39 2008
New Revision: 6081
URL: http://svn.gnome.org/viewvc/gedit?rev=6081&view=rev

Log:
first cut at integrating print-job in gedit-tab


Modified:
   branches/printing/gedit/gedit-commands-file-print.c
   branches/printing/gedit/gedit-print-job.c
   branches/printing/gedit/gedit-print-job.h
   branches/printing/gedit/gedit-tab.c
   branches/printing/gedit/gedit-tab.h

Modified: branches/printing/gedit/gedit-commands-file-print.c
==============================================================================
--- branches/printing/gedit/gedit-commands-file-print.c	(original)
+++ branches/printing/gedit/gedit-commands-file-print.c	Sat Jan 12 21:20:39 2008
@@ -347,8 +347,14 @@
 _gedit_cmd_file_print (GtkAction   *action,
 		       GeditWindow *window)
 {
+	GeditTab *tab;
+
 	gedit_debug (DEBUG_COMMANDS);
 
-	do_print_or_preview (window, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
+	tab = gedit_window_get_active_tab (window);
+	if (tab == NULL)
+		return;
+
+	_gedit_tab_print (tab);
 }
 

Modified: branches/printing/gedit/gedit-print-job.c
==============================================================================
--- branches/printing/gedit/gedit-print-job.c	(original)
+++ branches/printing/gedit/gedit-print-job.c	Sat Jan 12 21:20:39 2008
@@ -34,13 +34,6 @@
 #endif
 
 #include <glib/gi18n.h>
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <string.h>	/* For strlen */
-
 #include <gtksourceview/gtksourceprintcompositor.h>
 
 #include "gedit-print-job.h"
@@ -338,6 +331,7 @@
 GtkPrintOperationResult	 
 gedit_print_job_print (GeditPrintJob            *job,
 		       GtkPrintOperationAction   action,
+		       GtkWindow                *parent,
 		       GError                  **error)
 {
 	gchar            *job_name;
@@ -391,8 +385,11 @@
 */
 
 	// TODO
-	
-	return GTK_PRINT_OPERATION_RESULT_ERROR;
+
+	return 	gtk_print_operation_run (job->priv->operation, 
+					 action,
+					 parent,
+					 error);
 }
 
 static void

Modified: branches/printing/gedit/gedit-print-job.h
==============================================================================
--- branches/printing/gedit/gedit-print-job.h	(original)
+++ branches/printing/gedit/gedit-print-job.h	Sat Jan 12 21:20:39 2008
@@ -112,6 +112,7 @@
 								 
 GtkPrintOperationResult	 gedit_print_job_print			(GeditPrintJob            *job,
 								 GtkPrintOperationAction   action,
+								 GtkWindow                *parent,
 								 GError                  **error);
 
 void			 gedit_print_job_cancel                 (GeditPrintJob            *job);

Modified: branches/printing/gedit/gedit-tab.c
==============================================================================
--- branches/printing/gedit/gedit-tab.c	(original)
+++ branches/printing/gedit/gedit-tab.c	Sat Jan 12 21:20:39 2008
@@ -42,8 +42,8 @@
 #include "gedit-utils.h"
 #include "gedit-message-area.h"
 #include "gedit-io-error-message-area.h"
-//#include "gedit-print.h"
-//#include "gedit-print-job-preview.h"
+#include "gedit-print-job.h"
+#include "gedit-print-preview.h"
 #include "gedit-progress-message-area.h"
 #include "gedit-debug.h"
 #include "gedit-prefs-manager-app.h"
@@ -64,7 +64,7 @@
 	GtkWidget	       *message_area;
 	GtkWidget	       *print_preview;
 
-//	GeditPrintJob          *print_job;
+	GeditPrintJob          *print_job;
 
 	/* tmp data for saving */
 	gchar		       *tmp_save_uri;
@@ -230,16 +230,14 @@
 {
 	GeditTab *tab = GEDIT_TAB (object);
 
-#if 0
 	if (tab->priv->print_job != NULL)
 	{
 		gedit_debug_message (DEBUG_TAB, "Cancelling printing");
-		
-		gtk_source_print_job_cancel (GTK_SOURCE_PRINT_JOB (tab->priv->print_job));
+
+		gedit_print_job_cancel (tab->priv->print_job);
 		g_object_unref (tab->priv->print_job);
 	}
-#endif
-	
+
 	if (tab->priv->timer != NULL)
 		g_timer_destroy (tab->priv->timer);
 
@@ -2172,8 +2170,11 @@
 	}	
 }
 
+#if 0
+
 static void
-set_print_preview (GeditTab  *tab, GtkWidget *print_preview)
+set_print_preview (GeditTab  *tab,
+		   GtkWidget *print_preview)
 {
 	if (tab->priv->print_preview == print_preview)
 		return;
@@ -2199,8 +2200,6 @@
 
 #define MIN_PAGES 15
 
-#if 0
-
 static void
 print_page_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
 {
@@ -2285,6 +2284,7 @@
 	view = gedit_tab_get_view (tab);
 	gtk_widget_grab_focus (GTK_WIDGET (view));
 }
+#endif
 
 static void
 print_cancelled (GeditMessageArea *area,
@@ -2294,8 +2294,8 @@
 	GeditView *view;
 
 	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
-	
-	gtk_source_print_job_cancel (GTK_SOURCE_PRINT_JOB (tab->priv->print_job));
+
+	gedit_print_job_cancel (tab->priv->print_job);
 	g_object_unref (tab->priv->print_job);
 
 	set_message_area (tab, NULL); /* destroy the message area */
@@ -2315,11 +2315,10 @@
 }
 
 static void
-show_printing_message_area (GeditTab      *tab,
-			    gboolean       preview)
+show_printing_message_area (GeditTab *tab, gboolean preview)
 {
 	GtkWidget *area;
-	
+
 	if (preview)
 		area = gedit_progress_message_area_new (GTK_STOCK_PRINT_PREVIEW,
 							"",
@@ -2328,7 +2327,6 @@
 		area = gedit_progress_message_area_new (GTK_STOCK_PRINT,
 							"",
 							TRUE);
-	
 
 	g_signal_connect (area,
 			  "response",
@@ -2337,104 +2335,66 @@
 	  
 	set_message_area (tab, area);
 }
-#endif
 
-void 
-_gedit_tab_print (GeditTab      *tab,
-		  gpointer       print_job,
-		  GtkTextIter   *start, 
-		  GtkTextIter   *end)
+static void
+gedit_tab_print_or_print_preview (GeditTab                *tab,
+				  GtkPrintOperationAction  print_action)
 {
-#if 0
-	GeditPrintJob *pjob;
-	GeditDocument *doc;
-
-	pjob = (GeditPrintJob *) print_job;
+	GeditView *view;
+	gboolean is_preview;
+	GtkPrintOperationResult res;
+	GError *error = NULL;
 
-	g_return_if_fail (GEDIT_IS_TAB (tab));
-	g_return_if_fail (GEDIT_IS_PRINT_JOB (pjob));
-	g_return_if_fail (start != NULL);
-	g_return_if_fail (end != NULL);	
-		
-	doc = GEDIT_DOCUMENT (gtk_source_print_job_get_buffer (GTK_SOURCE_PRINT_JOB (pjob)));
-	g_return_if_fail (doc != NULL);
-	g_return_if_fail (gedit_tab_get_document (tab) == doc);
-	g_return_if_fail (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc));
-	g_return_if_fail (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc));	
-	
 	g_return_if_fail (tab->priv->print_job == NULL);
-	g_return_if_fail ((tab->priv->state == GEDIT_TAB_STATE_NORMAL) ||
-			  (tab->priv->state == GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW));
-	
-	g_object_ref (pjob);
-	tab->priv->print_job = pjob;
-	g_object_add_weak_pointer (G_OBJECT (pjob), 
+	g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_NORMAL);
+
+	view = gedit_tab_get_view (tab);
+
+	is_preview = (print_action == GTK_PRINT_OPERATION_ACTION_PREVIEW);
+
+	tab->priv->print_job = gedit_print_job_new (view);
+	g_object_add_weak_pointer (G_OBJECT (tab->priv->print_job), 
 				   (gpointer *) &tab->priv->print_job);
-	
-	show_printing_message_area (tab, FALSE);
 
-	g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
-	g_signal_connect (pjob, "finished", (GCallback) print_finished_cb, tab);
+	show_printing_message_area (tab, is_preview);
 
-	gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINTING);
-	
-	if (!gtk_source_print_job_print_range_async (GTK_SOURCE_PRINT_JOB (pjob), start, end))
+//	g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
+//	g_signal_connect (pjob, "finished", (GCallback) preview_finished_cb, tab);
+
+	if (is_preview)
+		gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINT_PREVIEWING);
+	else
+		gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINTING);
+
+	res = gedit_print_job_print (tab->priv->print_job,
+				     print_action,
+				     GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
+				     &error);
+
+	if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
 	{
 		/* FIXME: go in error state */
-		gtk_text_view_set_editable (GTK_TEXT_VIEW (tab->priv->view), 
-					    !tab->priv->not_editable);
-		g_warning ("Async print preview failed");
-		g_object_unref (pjob);
+		gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+		g_warning ("Async print preview failed (%s)", error->message);
+		g_object_unref (tab->priv->print_job);
+		g_error_free (error);
 	}
-#endif
 }
 
-void
-_gedit_tab_print_preview (GeditTab      *tab,
-			  gpointer       print_job,
-			  GtkTextIter   *start, 
-			  GtkTextIter   *end)
+void 
+_gedit_tab_print (GeditTab *tab)
 {
-#if 0
-	GeditPrintJob *pjob;
-	GeditDocument *doc;
+	g_return_if_fail (GEDIT_IS_TAB (tab));
 
-	pjob = (GeditPrintJob *) print_job;
+	gedit_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG);
+}
 
+void
+_gedit_tab_print_preview (GeditTab *tab)
+{
 	g_return_if_fail (GEDIT_IS_TAB (tab));
-	g_return_if_fail (GEDIT_IS_PRINT_JOB (pjob));
-	g_return_if_fail (start != NULL);
-	g_return_if_fail (end != NULL);	
-		
-	doc = GEDIT_DOCUMENT (gtk_source_print_job_get_buffer (GTK_SOURCE_PRINT_JOB (pjob)));
-	g_return_if_fail (doc != NULL);
-	g_return_if_fail (gedit_tab_get_document (tab) == doc);
-	g_return_if_fail (gtk_text_iter_get_buffer (start) == GTK_TEXT_BUFFER (doc));
-	g_return_if_fail (gtk_text_iter_get_buffer (end) == GTK_TEXT_BUFFER (doc));	
-	
-	g_return_if_fail (tab->priv->print_job == NULL);
-	g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_NORMAL);
-	
-	g_object_ref (pjob);
-	tab->priv->print_job = pjob;
-	g_object_add_weak_pointer (G_OBJECT (pjob), 
-				   (gpointer *) &tab->priv->print_job);
-	
-	show_printing_message_area (tab, TRUE);
-
-	g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
-	g_signal_connect (pjob, "finished", (GCallback) preview_finished_cb, tab);
 
-	gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINT_PREVIEWING);
-	
-	if (!gtk_source_print_job_print_range_async (GTK_SOURCE_PRINT_JOB (pjob), start, end))
-	{
-		/* FIXME: go in error state */
-		gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
-		g_warning ("Async print preview failed");
-		g_object_unref (pjob);
-	}
-#endif
+	gedit_tab_print_or_print_preview (tab, GTK_PRINT_OPERATION_ACTION_PREVIEW);
 }
 
 void 

Modified: branches/printing/gedit/gedit-tab.h
==============================================================================
--- branches/printing/gedit/gedit-tab.h	(original)
+++ branches/printing/gedit/gedit-tab.h	Sat Jan 12 21:20:39 2008
@@ -146,16 +146,9 @@
 						 const gchar         *uri,
 						 const GeditEncoding *encoding);
 
-/* print_job is a gpointer instead of GeditPrintJob because gedit-print is
- * is not public so it cannot be included in this header */
-void		 _gedit_tab_print		(GeditTab            *tab,
-						 gpointer             print_job,
-						 GtkTextIter         *start, 
-			  			 GtkTextIter         *end);
-void		 _gedit_tab_print_preview	(GeditTab            *tab,
-						 gpointer             print_job,
-						 GtkTextIter         *start, 
-			  			 GtkTextIter         *end);
+void		 _gedit_tab_print		(GeditTab            *tab);
+void		 _gedit_tab_print_preview	(GeditTab            *tab);
+
 void		 _gedit_tab_mark_for_closing	(GeditTab	     *tab);
 
 gboolean	 _gedit_tab_can_close		(GeditTab	     *tab);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]