[gnome-sudoku/vala-port] Patch which enables 'markasPlayedToggle' and 'includeOldGamesToggle' options in multiple print dialo
- From: Michael Catanzaro <mcatanzaro src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-sudoku/vala-port] Patch which enables 'markasPlayedToggle' and 'includeOldGamesToggle' options in multiple print dialo
- Date: Tue, 13 May 2014 15:55:42 +0000 (UTC)
commit 8c40c27117e30ddb0ad1ec6830adeb42c5118ab3
Author: Parin Porecha <parinporecha gmail com>
Date: Thu May 8 06:57:00 2014 -0500
Patch which enables 'markasPlayedToggle' and 'includeOldGamesToggle' options in multiple print dialog
https://bugzilla.gnome.org/show_bug.cgi?id=633464
TODO | 3 ---
data/print-games.ui | 4 ++--
src/gnome-sudoku.vala | 4 ++--
src/sudoku-board.vala | 9 +++++++++
src/sudoku-printer.vala | 11 +++++++----
src/sudoku-saver.vala | 18 ++++++++++--------
src/sudoku-store.vala | 9 ++++++---
7 files changed, 36 insertions(+), 22 deletions(-)
---
diff --git a/TODO b/TODO
index 2188932..eaabb78 100644
--- a/TODO
+++ b/TODO
@@ -31,9 +31,6 @@ mcatanzaro: Too confusing in general:
mouse over the text to see anything, and even then there's no explanation of
what it is.
-enable the options -
- 'MarkAsPlayedToggle' and 'includeOldGamesToggle' in data/print_games.ui (for multiple print dialog)
-
Currently we only read sudokus from data files:
We need to complete the port of SudokuGenerator class to be able to generate sudokus as desired.
diff --git a/data/print-games.ui b/data/print-games.ui
index 695e492..5f72451 100644
--- a/data/print-games.ui
+++ b/data/print-games.ui
@@ -309,7 +309,7 @@
<object class="GtkCheckButton" id="markAsPlayedToggle">
<property name="label" translatable="yes">_Mark games as played once you've printed
them.</property>
<property name="visible">True</property>
- <property name="sensitive">False</property>
+ <property name="sensitive">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
@@ -325,7 +325,7 @@
<object class="GtkCheckButton" id="includeOldGamesToggle">
<property name="label" translatable="yes">_Include games you've already played in
list of games to print</property>
<property name="visible">True</property>
- <property name="sensitive">False</property>
+ <property name="sensitive">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
<property name="use_underline">True</property>
diff --git a/src/gnome-sudoku.vala b/src/gnome-sudoku.vala
index 171b3a0..e7b90c7 100644
--- a/src/gnome-sudoku.vala
+++ b/src/gnome-sudoku.vala
@@ -273,7 +273,7 @@ public class Sudoku : Gtk.Application
}
}
- saver.add_game_to_finished (game);
+ saver.add_game_to_finished (game, true);
var dialog = new MessageDialog(null, DialogFlags.DESTROY_WITH_PARENT, MessageType.INFO,
ButtonsType.NONE, "Well done, you completed the puzzle in %f seconds", time);
@@ -487,7 +487,7 @@ public class Sudoku : Gtk.Application
public void print_multiple_cb ()
{
- var printer = new GamePrinter (sudoku_store, ref window);
+ var printer = new GamePrinter (sudoku_store, saver, ref window);
printer.run_dialog ();
}
diff --git a/src/sudoku-board.vala b/src/sudoku-board.vala
index 95f6ba1..f909b75 100644
--- a/src/sudoku-board.vala
+++ b/src/sudoku-board.vala
@@ -513,6 +513,15 @@ public class SudokuBoard
}
return possibilities;
}
+
+ public bool is_finished ()
+ {
+ var board_string = this.to_string (true) + ".save";
+ var finishgame_file = Path.build_path (Path.DIR_SEPARATOR_S, SudokuSaver.finishgame_dir,
board_string);
+ var file = File.new_for_path (finishgame_file);
+
+ return file.query_exists ();
+ }
}
public enum House {
diff --git a/src/sudoku-printer.vala b/src/sudoku-printer.vala
index df61712..58e23ce 100644
--- a/src/sudoku-printer.vala
+++ b/src/sudoku-printer.vala
@@ -243,6 +243,7 @@ public class SudokuPrinter : GLib.Object {
public class GamePrinter: GLib.Object {
private SudokuStore store;
+ private SudokuSaver saver;
private ApplicationWindow window;
private GLib.Settings settings;
private Gtk.Dialog dialog;
@@ -250,9 +251,10 @@ public class GamePrinter: GLib.Object {
private SpinButton sudokusToPrintSpinButton;
private SpinButton sudokusPerPageSpinButton;
- public GamePrinter (SudokuStore store, ref ApplicationWindow window)
+ public GamePrinter (SudokuStore store, SudokuSaver saver, ref ApplicationWindow window)
{
this.store = store;
+ this.saver = saver;
this.window = window;
this.settings = new GLib.Settings ("org.gnome.gnome-sudoku");
this.options_map = new HashMap<string, CheckButton> ();
@@ -339,7 +341,7 @@ public class GamePrinter: GLib.Object {
levels += DifficultyCatagory.VERY_HARD;
var boards = new ArrayList<SudokuBoard> ();
- boards = store.get_assorted_boards (nsudokus, levels);
+ boards = store.get_assorted_boards (nsudokus, levels, !options_map.get
("includeOldGamesToggle").get_active ());
SudokuBoard[] sorted_boards = {};
@@ -351,9 +353,10 @@ public class GamePrinter: GLib.Object {
if (result == PrintOperationResult.APPLY)
{
- // In future when 'markAsPlayedToggle' is made sensitive,
- // copy the 'Tracker' portion of code from printing.py here.
dialog.hide ();
+ if (options_map.get ("markAsPlayedToggle").get_active ())
+ foreach (SudokuBoard i in sorted_boards)
+ saver.add_game_to_finished (new SudokuGame (i));
}
}
diff --git a/src/sudoku-saver.vala b/src/sudoku-saver.vala
index 19c662e..08ff4c4 100644
--- a/src/sudoku-saver.vala
+++ b/src/sudoku-saver.vala
@@ -4,8 +4,8 @@ using Gee;
public class SudokuSaver
{
- private string savegame_file;
- private string finishgame_dir;
+ public static string savegame_file { get; private set; default = ""; }
+ public static string finishgame_dir { get; private set; default = ""; }
public SudokuSaver() {
try {
@@ -43,22 +43,24 @@ public class SudokuSaver
create_file_for_game (game, savegame_file);
}
- public void add_game_to_finished (SudokuGame game)
+ public void add_game_to_finished (SudokuGame game, bool delete_savegame = false)
{
var file_name = game.board.to_string (true) + ".save";
var file_path = Path.build_path (Path.DIR_SEPARATOR_S, finishgame_dir, file_name);
create_file_for_game (game, file_path);
- // Delete savegame file
- var file = File.new_for_path (savegame_file);
- if (file.query_exists ())
- file.delete ();
+ if (delete_savegame)
+ {
+ // Delete savegame file
+ var file = File.new_for_path (savegame_file);
+ if (file.query_exists ())
+ file.delete ();
+ }
}
private void create_file_for_game (SudokuGame game, string file_name)
{
var json_str = serialize_game_to_json (game);
- var file = File.new_for_path (file_name);
try {
FileUtils.set_contents (file_name, json_str);
diff --git a/src/sudoku-store.vala b/src/sudoku-store.vala
index 29447ff..f0d2e59 100644
--- a/src/sudoku-store.vala
+++ b/src/sudoku-store.vala
@@ -109,7 +109,7 @@ public class SudokuStore
assert_not_reached();
}
- public ArrayList<SudokuBoard> get_assorted_boards(int n, owned DifficultyCatagory[] levels)
+ public ArrayList<SudokuBoard> get_assorted_boards(int n, owned DifficultyCatagory[] levels, bool
exclude_finished = false)
{
var boards = new ArrayList<SudokuBoard> ();
int i = 0;
@@ -119,8 +119,11 @@ public class SudokuStore
while (i < n)
{
- // In future, modify this while loop to accomodate 'exclude' and 'new' parameters
- boards.add (get_random_board ((DifficultyCatagory) levels[i++ % levels.length]));
+ var board = get_random_board ((DifficultyCatagory) levels[i % levels.length]);
+ if (exclude_finished && board.is_finished ())
+ continue;
+ boards.add (board);
+ i++;
}
CompareDataFunc<SudokuBoard> CompareDifficultyRatings = (a, b) => {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]