[Commits] poppler_viewer.c 1.1.2.98 1.1.2.99

mones at claws-mail.org mones at claws-mail.org
Mon Aug 27 12:49:41 CEST 2012


Update of /home/claws-mail/plugins/pdf_viewer/src
In directory srv:/tmp/cvs-serv13832/src

Modified Files:
      Tag: gtk2
	poppler_viewer.c 
Log Message:
2012-08-27 [mones]	0.9.2cvs1

	* configure.ac
	* src/poppler_viewer.c
		Don't require gs for building and do the check at runtime,
		allowing plugin to work in PDF-only mode if not available. 

Index: poppler_viewer.c
===================================================================
RCS file: /home/claws-mail/plugins/pdf_viewer/src/Attic/poppler_viewer.c,v
retrieving revision 1.1.2.98
retrieving revision 1.1.2.99
diff -u -d -r1.1.2.98 -r1.1.2.99
--- poppler_viewer.c	31 Mar 2012 01:20:42 -0000	1.1.2.98
+++ poppler_viewer.c	27 Aug 2012 10:49:38 -0000	1.1.2.99
@@ -1240,7 +1240,8 @@
 			stock_pixbuf_gdk(viewer->hbox, 
 					STOCK_PIXMAP_MIME_PS, 
 					&viewer->icon_pixbuf);
-		gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), viewer->icon_pixbuf);
+			gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type),
+									viewer->icon_pixbuf);
 		} 
 		else if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF) {
 			stock_pixbuf_gdk(viewer->hbox, 
@@ -1263,32 +1264,41 @@
 
 		GTK_EVENTS_FLUSH();
 
-		if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) 
-		{
+		if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
 			gchar *cmdline = NULL, *tmp = NULL;
 			gint result = 0;
-			/* convert postscript to pdf */
-			tmpfile = get_tmp_file();
-			cmdline = g_strdup_printf(
-				"gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
-				  "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
-				tmpfile, viewer->filename);
-			result = execute_command_line(cmdline, FALSE);
-			if (result == 0) {
-				tmp = g_filename_to_uri(tmpfile, NULL, NULL);
-				viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
-				g_free(tmp);
-			} 
+
+			if (g_find_program_in_path("gs") != NULL) {
+				/* convert postscript to pdf */
+				tmpfile = get_tmp_file();
+				cmdline = g_strdup_printf(
+					"gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
+					  "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
+					tmpfile, viewer->filename);
+				result = execute_command_line(cmdline, FALSE);
+				if (result == 0) {
+					tmp = g_filename_to_uri(tmpfile, NULL, NULL);
+					viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
+					g_free(tmp);
+				} 
+				else {
+					g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
+					tmp = g_strdup_printf("gs: err %d", result);
+					gtk_label_set_text(GTK_LABEL(viewer->doc_label), tmp);
+					g_free(tmp);
+				}
+	
+				g_free(cmdline);
+				claws_unlink(tmpfile);
+				g_free(tmpfile);
+			}
 			else {
-				g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
-				tmp = g_strdup_printf("gs: err %d", result);
-				gtk_label_set_text(GTK_LABEL(viewer->doc_label), tmp);
-				g_free(tmp);
+				g_warning("gs conversion disabled: gs binary was not found\n");
+				gtk_label_set_text(GTK_LABEL(viewer->doc_label),
+					_("PostScript view disabled: required gs program not found"));
+				result = 1;
+					
 			}
-			
-			g_free(cmdline);
-			claws_unlink(tmpfile);
-			g_free(tmpfile);
 			if (result != 0) {
 				main_window_cursor_normal(mainwindow_get_mainwindow());
 				return;
@@ -1322,7 +1332,6 @@
 		main_window_cursor_normal(mainwindow_get_mainwindow());
 	} 
 	if (viewer->pdf_doc == NULL) {
-	
 		strretchomp(error->message);
 		stock_pixbuf_gdk(viewer->hbox, 
 				STOCK_PIXMAP_MIME_APPLICATION, 
@@ -1382,7 +1391,8 @@
 		if (viewer->last_rect && viewer->last_page_result &&
 		    viewer->last_page_result->page_num == page_num) {
 			pdf_viewer_render_selection(viewer, viewer->last_rect, viewer->last_page_result);
-		} else {
+		}
+		else {
 			pdf_viewer_render_page(viewer->pdf_page, viewer->pdf_view, viewer->width, 
 									viewer->height, viewer->zoom, viewer->rotate);
 
@@ -2023,12 +2033,22 @@
 	msg = g_strdup_printf(_("This plugin enables the viewing of PDF and PostScript "
 				"attachments using the Poppler %s Lib and the gs tool.\n\n"
 				"Any feedback is welcome: iwkse at claws-mail.org"
-				),poppler_get_version());
+				), poppler_get_version());
 
 	bind_textdomain_codeset(TEXTDOMAIN, "UTF-8");
 
 	if (!check_plugin_version(MAKE_NUMERIC_VERSION(3,7,10,41),
 		    VERSION_NUMERIC, _("PDF Viewer"), error)) return -1;
+
+	if (g_find_program_in_path("gs") == NULL) {
+		gchar *pmsg = msg;
+		msg = g_strdup_printf(_("Warning: could not find ghostscript binary (gs) required "
+					"for %s plugin to process PostScript attachments, only PDF "
+					"attachments will be displayed. To enable PostScript "
+					"support please install gs program.\n\n%s"
+					), _("PDF Viewer"), pmsg);
+		g_free(pmsg);
+	}
 	
 	mimeview_register_viewer_factory(&pdf_viewer_factory);
 	return 0;
@@ -2074,3 +2094,4 @@
 		  {PLUGIN_NOTHING, NULL} };
 	return features;
 }
+



More information about the Commits mailing list