[libgames-support] scores: Replace category-request signal with a delegate



commit 26955df5f56d8ee9061371976d930a25d2ee3312
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sat Sep 19 17:36:17 2015 -0500

    scores: Replace category-request signal with a delegate

 games/scores/context.vala |   18 +++++-------------
 tests/test-scores.vala    |    8 +++++++-
 2 files changed, 12 insertions(+), 14 deletions(-)
---
diff --git a/games/scores/context.vala b/games/scores/context.vala
index a99b898..a09a37b 100644
--- a/games/scores/context.vala
+++ b/games/scores/context.vala
@@ -54,12 +54,14 @@ public class Context : Object
         return str_equal (a.name, b.name);
     };
 
-    /* A signal that asks the game to provide the Category given the category key. This is mainly used to 
fetch category names. */
-    public signal Category? category_request (string category_key);
+    /* A function provided by the game that converts the category key to a category. */
+    public delegate Category CategoryRequestFunc (string category_key);
+    private CategoryRequestFunc category_request;
 
-    public Context (string app_name, string dialog_label, Gtk.Window? game_window, Style style)
+    public Context (string app_name, string dialog_label, Gtk.Window? game_window, CategoryRequestFunc 
category_request, Style style)
     {
         this.game_window = game_window;
+        this.category_request = category_request;
         this.style = style;
 
         if (style == Style.PLAIN_DESCENDING || style == Style.TIME_DESCENDING)
@@ -221,16 +223,6 @@ public class Context : Object
         {
             var category_key = file_info.get_name ();
             var category = category_request (category_key);
-
-            if (category == null)
-            {
-                error ("GamesScoresContext requested a GamesScoresCategory for the " +
-                       "category %s, but the application did not supply any " +
-                       "GamesScoresCategory. Scores will not be loaded. You should " +
-                       "connect to GamesScoresContext::category-request to supply " +
-                       "a GamesScoresCategory.", category_key);
-            }
-
             var filename = Path.build_filename (user_score_dir, category_key);
             var scores_of_single_category = new Gee.PriorityQueue<Score> ((owned) scorecmp);
             var file = File.new_for_path (filename);
diff --git a/tests/test-scores.vala b/tests/test-scores.vala
index b9c3286..2200768 100644
--- a/tests/test-scores.vala
+++ b/tests/test-scores.vala
@@ -21,11 +21,17 @@
 namespace Games {
 namespace Scores {
 
+private Category category_request (string category_key)
+{
+    // TODO: This isn't tested....
+    return new Category("test", "test");
+}
+
 private void create_scores ()
 {
     try
     {
-        Context context = new Context ("libgames-scores-test", "Games Type", null, Style.PLAIN_DESCENDING);
+        Context context = new Context ("libgames-scores-test", "Games Type", null, category_request, 
Style.PLAIN_DESCENDING);
         Category cat = new Category ("cat1", "cat1");
         context.add_score (101, cat);
         context.add_score (102, cat);


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