[gnome-games/wip/aplazas/run-uri: 1/4] core: Add UriTest



commit db46f30d5ee58f70b730104163c246cebc0e0092
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Wed Apr 12 06:37:51 2017 +0200

    core: Add UriTest
    
    Replace the barely used UriTest delegate by an interface serving the
    same purpose.
    
    This will be used in the next commits to better test URIs of potential
    games.

 src/Makefile.am                           |    1 +
 src/core/uri-test.vala                    |    5 +++++
 src/generic/generic-uri-game-factory.vala |   10 ++++++----
 3 files changed, 12 insertions(+), 4 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 69126be..eee5500 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -53,6 +53,7 @@ gnome_games_SOURCES = \
        core/title.vala \
        core/uid.vala \
        core/uri-game-factory.vala \
+       core/uri-test.vala \
        \
        dummy/dummy-cover.vala \
        dummy/dummy-game.vala \
diff --git a/src/core/uri-test.vala b/src/core/uri-test.vala
new file mode 100644
index 0000000..a67b3b2
--- /dev/null
+++ b/src/core/uri-test.vala
@@ -0,0 +1,5 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+public interface Games.UriTest : Object {
+       public abstract bool is_uri_valid (string uri);
+}
diff --git a/src/generic/generic-uri-game-factory.vala b/src/generic/generic-uri-game-factory.vala
index b6da6be..b118248 100644
--- a/src/generic/generic-uri-game-factory.vala
+++ b/src/generic/generic-uri-game-factory.vala
@@ -1,21 +1,23 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 public class Games.GenericUriGameFactory : Object, UriGameFactory {
-       public delegate bool UriTest (string uri);
        private const uint HANDLED_URIS_PER_CYCLE = 5;
 
        private GameUriAdapter game_uri_adapter;
        private UriTest? uri_validity_test;
        private string[] uris;
 
-       public GenericUriGameFactory (GameUriAdapter game_uri_adapter, owned UriTest? uri_validity_test = 
null) {
+       public GenericUriGameFactory (GameUriAdapter game_uri_adapter, UriTest? uri_validity_test = null) {
                this.game_uri_adapter = game_uri_adapter;
-               this.uri_validity_test = (owned) uri_validity_test;
+               this.uri_validity_test = uri_validity_test;
                this.uris = {};
        }
 
        public bool is_uri_valid (string uri) {
-               return uri_validity_test == null ? true : uri_validity_test (uri);
+               if (uri_validity_test == null)
+                       return true;
+
+               return uri_validity_test.is_uri_valid (uri);
        }
 
        public void add_uri (string uri) {


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