[gnome-chess] Validate input when opening files



commit 0fbed8df94bdc827744b13b0c6903dbc4ab71fc9
Author: Sahil Sareen <sahil sareen hotmail com>
Date:   Tue Apr 21 19:41:19 2015 +0530

    Validate input when opening files
    
    Add input validation for loading saved PGN games.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704990

 src/gnome-chess.vala |   26 ++++++++++++++++++++++++--
 1 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 9cf21ad..fd81274 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -2142,6 +2142,19 @@ public class ChessApplication : Gtk.Application
         about_dialog.show ();
     }
 
+    private void run_invalid_pgn_dialog ()
+    {
+        var invalid_pgn_dialog = new Gtk.MessageDialog (window,
+                                                       Gtk.DialogFlags.MODAL,
+                                                       Gtk.MessageType.ERROR,
+                                                       Gtk.ButtonsType.NONE,
+                                                       _("This does not look like a valid PGN game."));
+        invalid_pgn_dialog.add_button (_("_OK"), Gtk.ResponseType.OK);
+
+        invalid_pgn_dialog.run ();
+        invalid_pgn_dialog.destroy ();
+    }
+
     private void about_response_cb (int response_id)
     {
         about_dialog.destroy ();
@@ -2416,8 +2429,17 @@ public class ChessApplication : Gtk.Application
         var pgn = new PGN.from_file (file);
         pgn_game = pgn.games.nth_data (0);
 
-        game_file = file;
-        start_game ();
+        if (pgn_game == null)
+        {
+            run_invalid_pgn_dialog ();
+            pgn_game = new PGNGame ();
+            game_file = null;
+        }
+        else
+        {
+            game_file = file;
+            start_game ();
+        }
     }
 
     private void enable_window_action (string name)


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