[gbrainy] Inform of the result of the PDF export operation + catch errors + localizable default name for PDF



commit 65b6c7769781b1787edcfffff6aba616618dccf8
Author: Jordi Mas <jmas softcatala org>
Date:   Sun Nov 28 16:52:06 2010 +0100

    Inform of the result of the PDF export operation + catch errors + localizable default name for PDF

 src/Clients/Classical/Dialogs/PdfExportDialog.cs |   18 +++++++++++++-
 src/Core/Main/PdfExporter.cs                     |   27 +++++++++++++++------
 2 files changed, 35 insertions(+), 10 deletions(-)
---
diff --git a/src/Clients/Classical/Dialogs/PdfExportDialog.cs b/src/Clients/Classical/Dialogs/PdfExportDialog.cs
index dba30db..f81e4d4 100644
--- a/src/Clients/Classical/Dialogs/PdfExportDialog.cs
+++ b/src/Clients/Classical/Dialogs/PdfExportDialog.cs
@@ -65,7 +65,8 @@ namespace gbrainy.Clients.Classical.Dialogs
 			string def_file;
 			def_file = System.IO.Path.Combine (
 				Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments),
-				"games.pdf");
+				// Translators: default file name used when exporting PDF files (keep the pdf extension please)
+				Catalog.GetString ("games.pdf"));
 
 			file = new BrowseFile (hbox_file, def_file, true);
 
@@ -147,6 +148,8 @@ namespace gbrainy.Clients.Classical.Dialogs
 		{
 			Game [] games;
 			GameManager gm;
+			string msg;
+			MessageType msg_type;
 
 			games = new Game [num_games];
 			gm = new GameManager ();
@@ -160,7 +163,18 @@ namespace gbrainy.Clients.Classical.Dialogs
 				 games [n] = gm.GetPuzzle ();
 			}
 
-			PdfExporter.GeneratePdf (games, gamespage, filename);
+			if (PdfExporter.GeneratePdf (games, gamespage, filename) == true) {
+				msg = Catalog.GetString ("The PDF file has been exported correctly.");
+				msg_type = MessageType.Info;
+			} else {
+				msg = Catalog.GetString ("There was a problem generating the PDF file. The file has not be created.");
+				msg_type = MessageType.Error;
+			}
+
+			// Notify operation result
+			MessageDialog md = new MessageDialog (this, DialogFlags.Modal, msg_type, ButtonsType.Ok, msg);
+			md.Run ();
+			md.Destroy ();
 		}
 
 		static public void ComboBoxCellFunc (CellLayout cell_layout, CellRenderer cell, TreeModel tree_model, TreeIter iter)
diff --git a/src/Core/Main/PdfExporter.cs b/src/Core/Main/PdfExporter.cs
index 0d324d1..60847ad 100644
--- a/src/Core/Main/PdfExporter.cs
+++ b/src/Core/Main/PdfExporter.cs
@@ -39,7 +39,7 @@ namespace gbrainy.Core.Main
 			get { return pages_side; }
 		}
 
-		static public void GeneratePdf (Game [] games, int games_page, string file)
+		static public bool GeneratePdf (Game [] games, int games_page, string file)
 		{
 			int columns, rows;
 			switch (games_page) {
@@ -59,15 +59,26 @@ namespace gbrainy.Core.Main
 				throw new InvalidOperationException ("Invalid games per page value");
 			}
 
-			PdfSurface pdf = new PdfSurface (file, page_width * columns, page_height * rows);
-			CairoContextEx cr = new CairoContextEx (pdf, "sans 12", 72);
+			try {
 
-			GenerateQuestions (cr, games, columns, rows);
-			GenerateAnswers (cr, games, columns, rows);
+				PdfSurface pdf = new PdfSurface (file, page_width * columns, page_height * rows);
 
-			pdf.Finish ();
-			((IDisposable)cr).Dispose();
-			return;
+				if (pdf.Status != Status.Success)
+					return false;
+
+				CairoContextEx cr = new CairoContextEx (pdf, "sans 12", 72);
+
+				GenerateQuestions (cr, games, columns, rows);
+				GenerateAnswers (cr, games, columns, rows);
+
+				pdf.Finish ();
+				((IDisposable)cr).Dispose();
+				return true;
+			}
+			catch (Exception e)
+			{
+				return false;
+			}
 		}
 
 		static void GenerateQuestions (CairoContextEx cr, Game [] games, int columns, int rows)



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