gedit r6083 - branches/printing/gedit



Author: paolo
Date: Sun Jan 13 14:46:30 2008
New Revision: 6083
URL: http://svn.gnome.org/viewvc/gedit?rev=6083&view=rev

Log:
Track print progress in the tab message area.



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

Modified: branches/printing/gedit/gedit-print-job.c
==============================================================================
--- branches/printing/gedit/gedit-print-job.c	(original)
+++ branches/printing/gedit/gedit-print-job.c	Sun Jan 13 14:46:30 2008
@@ -126,7 +126,15 @@
 {
 	GeditPrintJob *job = GEDIT_PRINT_JOB (object);
 
+	g_debug ("Finalize.");
+	
 	g_free (job->priv->status_string);
+	
+	if (job->priv->compositor != NULL)
+		g_object_unref (job->priv->compositor);
+
+	if (job->priv->operation != NULL)
+		g_object_unref (job->priv->operation);
 
 	G_OBJECT_CLASS (gedit_print_job_parent_class)->finalize (object);
 }
@@ -295,7 +303,7 @@
 						    page_nr + 1,
 						    n_pages);
 	
-	job->priv->progress = (double)page_nr / (double)n_pages + 0.5;
+	job->priv->progress = page_nr / (2.0 * n_pages) + 0.5;
 	
 	g_signal_emit (job, print_job_signals[PRINTING], 0, job->priv->status);
 		
@@ -307,10 +315,52 @@
 	      GtkPrintContext   *context,
 	      GeditPrintJob     *job)
 {
+	g_debug ("end_print_cb");
 	g_object_unref (job->priv->compositor);
 	job->priv->compositor = NULL;
 }
 
+static void
+done_cb (GtkPrintOperation       *operation,
+	 GtkPrintOperationResult  result,
+	 GeditPrintJob           *job)
+{
+	GError *error = NULL;
+	GeditPrintJobResult print_result;
+
+	g_debug ("done_cb");
+	
+	switch (result) 
+	{
+		case GTK_PRINT_OPERATION_RESULT_CANCEL:
+			print_result = GEDIT_PRINT_JOB_RESULT_CANCEL;
+			break;
+		
+		case GTK_PRINT_OPERATION_RESULT_APPLY:
+			print_result = GEDIT_PRINT_JOB_RESULT_OK;
+			// TODO: save settings
+			break;
+			
+		case GTK_PRINT_OPERATION_RESULT_ERROR:
+			print_result = GEDIT_PRINT_JOB_RESULT_ERROR;
+			gtk_print_operation_get_error (operation, &error);
+			break;
+			
+		default:
+			g_return_if_reached ();
+	}
+	
+	/* Avoid job is destroyed in the handler of the "done" message */
+	g_object_ref (job);
+	
+	g_signal_emit (job, print_job_signals[DONE], 0, print_result, error);
+	
+	g_object_unref (operation);
+	job->priv->operation = NULL;
+	
+	g_object_unref (job);
+}
+	      
 static GtkPrintSettings *
 get_print_settings (GeditPrintJob  *job,
 		    GError        **error)
@@ -377,12 +427,11 @@
 			  "end-print", 
 			  G_CALLBACK (end_print_cb),
 			  job);
-/*
+
 	g_signal_connect (job->priv->operation,
 			  "done", 
 			  G_CALLBACK (done_cb),
 			  job);			  
-*/
 
 	// TODO
 
@@ -421,6 +470,24 @@
 {
 	g_return_if_fail (GEDIT_IS_PRINT_JOB (job));
 
-	/* TODO */
+	gtk_print_operation_cancel (job->priv->operation);
 }
 
+const gchar *
+gedit_print_job_get_status_string (GeditPrintJob *job)
+{
+	g_return_val_if_fail (GEDIT_IS_PRINT_JOB (job), NULL);
+	g_return_val_if_fail (job->priv->status_string != NULL, NULL);
+	
+	return job->priv->status_string;
+}
+
+gdouble
+gedit_print_job_get_progress (GeditPrintJob *job)
+{
+	g_return_val_if_fail (GEDIT_IS_PRINT_JOB (job), 0.0);
+
+	return job->priv->progress;
+}
+
+

Modified: branches/printing/gedit/gedit-print-job.h
==============================================================================
--- branches/printing/gedit/gedit-print-job.h	(original)
+++ branches/printing/gedit/gedit-print-job.h	Sun Jan 13 14:46:30 2008
@@ -117,7 +117,7 @@
 
 void			 gedit_print_job_cancel                 (GeditPrintJob            *job);
 
-GeditView		*gedit_print_job_get_view		(GeditPrintJob            *job);
+// GeditView		*gedit_print_job_get_view		(GeditPrintJob            *job);
 								 
 const gchar		*gedit_print_job_get_status_string      (GeditPrintJob            *job);
 

Modified: branches/printing/gedit/gedit-tab.c
==============================================================================
--- branches/printing/gedit/gedit-tab.c	(original)
+++ branches/printing/gedit/gedit-tab.c	Sun Jan 13 14:46:30 2008
@@ -230,6 +230,7 @@
 {
 	GeditTab *tab = GEDIT_TAB (object);
 
+/* FIXME
 	if (tab->priv->print_job != NULL)
 	{
 		gedit_debug_message (DEBUG_TAB, "Cancelling printing");
@@ -237,7 +238,7 @@
 		gedit_print_job_cancel (tab->priv->print_job);
 		g_object_unref (tab->priv->print_job);
 	}
-
+*/
 	if (tab->priv->timer != NULL)
 		g_timer_destroy (tab->priv->timer);
 
@@ -2144,6 +2145,55 @@
 	gedit_document_save_as (doc, uri, encoding, tab->priv->save_flags);
 }
 
+/* FIXME: show the message area only if the operation will be "long" */
+static void
+printing_cb (GeditPrintJob       *job,
+	     GeditPrintJobStatus  status,
+	     GeditTab            *tab)
+{	
+	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));	
+	
+	gtk_widget_show (tab->priv->message_area);
+	
+	gedit_progress_message_area_set_text (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
+					      gedit_print_job_get_status_string (job));
+
+	gedit_progress_message_area_set_fraction (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
+						  gedit_print_job_get_progress (job));
+}
+
+static void
+done_printing_cb (GeditPrintJob       *job,
+		  GeditPrintJobResult  result,
+		  const GError        *error,
+		  GeditTab            *tab)
+{
+	GeditView *view;
+	
+	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
+
+	set_message_area (tab, NULL); /* destroy the message area */
+
+	// TODO: check status and error
+
+#if 0
+	if (tab->priv->print_preview != NULL)
+	{
+		/* If we were printing while showing the print preview,
+		   see bug #352658 */
+		gtk_widget_destroy (tab->priv->print_preview);
+		g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
+	}
+#endif
+
+	gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
+
+	view = gedit_tab_get_view (tab);
+	gtk_widget_grab_focus (GTK_WIDGET (view));
+	
+ 	g_object_unref (tab->priv->print_job);
+}
+
 static void
 print_preview_destroyed (GtkWidget *preview,
 			 GeditTab  *tab)
@@ -2198,38 +2248,6 @@
 			  tab);
 }
 
-#define MIN_PAGES 15
-
-static void
-print_page_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
-{
-	gchar *str;
-	gint page_num;
-	gint total;
-
-	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));	
-
-	total = gtk_source_print_job_get_page_count (pjob);
-	
-	if (total < MIN_PAGES)
-		return;
-
-	page_num = gtk_source_print_job_get_page (pjob);
-			
-	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));	
-	
-	gtk_widget_show (tab->priv->message_area);
-	
-	str = g_strdup_printf (_("Rendering page %d of %d..."), page_num, total);
-
-	gedit_progress_message_area_set_text (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
-					      str);
-	g_free (str);
-	
-	gedit_progress_message_area_set_fraction (GEDIT_PROGRESS_MESSAGE_AREA (tab->priv->message_area),
-						  1.0 * page_num / total);
-}
-
 static void
 preview_finished_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
 {
@@ -2252,38 +2270,7 @@
 	gedit_tab_set_state (tab, GEDIT_TAB_STATE_SHOWING_PRINT_PREVIEW);
 }
 
-static void
-print_finished_cb (GtkSourcePrintJob *pjob, GeditTab *tab)
-{
-	GnomePrintJob *gjob;
-	GeditView *view;
-
-	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
 
-	set_message_area (tab, NULL); /* destroy the message area */
-
-	gjob = gtk_source_print_job_get_print_job (pjob);
-
-	gnome_print_job_print (gjob);
- 	g_object_unref (gjob);
-
-	gedit_print_job_save_config (GEDIT_PRINT_JOB (pjob));
-
-	g_object_unref (pjob);
-
-	if (tab->priv->print_preview != NULL)
-	{
-		/* If we were printing while showing the print preview,
-		   see bug #352658 */
-		gtk_widget_destroy (tab->priv->print_preview);
-		g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
-	}
-
-	gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
-
-	view = gedit_tab_get_view (tab);
-	gtk_widget_grab_focus (GTK_WIDGET (view));
-}
 #endif
 
 static void
@@ -2296,22 +2283,7 @@
 	g_return_if_fail (GEDIT_IS_PROGRESS_MESSAGE_AREA (tab->priv->message_area));
 
 	gedit_print_job_cancel (tab->priv->print_job);
-	g_object_unref (tab->priv->print_job);
-
-	set_message_area (tab, NULL); /* destroy the message area */
-
-	if (tab->priv->print_preview != NULL)
-	{
-		/* If we were printing while showing the print preview,
-		   see bug #352658 */        	
-		gtk_widget_destroy (tab->priv->print_preview);
-		g_return_if_fail (tab->priv->state == GEDIT_TAB_STATE_PRINTING);
-	}
-
-	gedit_tab_set_state (tab, GEDIT_TAB_STATE_NORMAL);
-
-	view = gedit_tab_get_view (tab);
-	gtk_widget_grab_focus (GTK_WIDGET (view));
+	g_debug ("print_cancelled");
 }
 
 static void
@@ -2358,8 +2330,8 @@
 
 	show_printing_message_area (tab, is_preview);
 
-//	g_signal_connect (pjob, "begin_page", (GCallback) print_page_cb, tab);
-//	g_signal_connect (pjob, "finished", (GCallback) preview_finished_cb, tab);
+	g_signal_connect (tab->priv->print_job, "printing", (GCallback) printing_cb, tab);
+	g_signal_connect (tab->priv->print_job, "done", (GCallback) done_printing_cb, tab);
 
 	if (is_preview)
 		gedit_tab_set_state (tab, GEDIT_TAB_STATE_PRINT_PREVIEWING);
@@ -2371,6 +2343,7 @@
 				     GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (tab))),
 				     &error);
 
+	// TODO: manage res in the correct way
 	if (res == GTK_PRINT_OPERATION_RESULT_ERROR)
 	{
 		/* FIXME: go in error state */



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