[gnome-games/wip/exalm/rebrand: 64/102] Merge GameUriAdapter into GenericGameUriFactory




commit e09526c4ed45a7889d5ccfb7a1bd6580c44fa313
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Mar 30 04:10:13 2021 +0500

    Merge GameUriAdapter into GenericGameUriFactory

 plugins/dreamcast/src/dreamcast-plugin.vala        |  5 +--
 plugins/game-cube/src/game-cube-plugin.vala        |  4 +--
 plugins/mame/src/mame-plugin.vala                  |  4 +--
 plugins/ms-dos/src/ms-dos-plugin.vala              |  4 +--
 plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala  |  5 +--
 plugins/nintendo-64/src/nintendo-64-plugin.vala    |  4 +--
 plugins/nintendo-ds/src/nintendo-ds-plugin.vala    |  4 +--
 plugins/sega-cd/src/sega-cd-plugin.vala            | 12 ++-----
 plugins/sega-saturn/src/sega-saturn-plugin.vala    |  5 +--
 .../turbografx-cd/src/turbografx-cd-plugin.vala    |  4 +--
 plugins/virtual-boy/src/virtual-boy-plugin.vala    |  4 +--
 plugins/wii/src/wii-plugin.vala                    |  4 +--
 src/core/game-uri-adapter.vala                     |  5 ---
 src/generic/generic-uri-game-factory.vala          | 37 +++++++++++++++-------
 src/meson.build                                    |  2 --
 src/retro/retro-simple-game-uri-adapter.vala       | 30 ------------------
 src/ui/application.vala                            |  5 +--
 17 files changed, 40 insertions(+), 98 deletions(-)
---
diff --git a/plugins/dreamcast/src/dreamcast-plugin.vala b/plugins/dreamcast/src/dreamcast-plugin.vala
index 1bf5e9fb..e811a600 100644
--- a/plugins/dreamcast/src/dreamcast-plugin.vala
+++ b/plugins/dreamcast/src/dreamcast-plugin.vala
@@ -21,10 +21,7 @@ private class Games.DreamcastPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               foreach (var mime_type in MIME_TYPES)
-                       factory.add_mime_type (mime_type);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/game-cube/src/game-cube-plugin.vala b/plugins/game-cube/src/game-cube-plugin.vala
index 00892eab..3009ae31 100644
--- a/plugins/game-cube/src/game-cube-plugin.vala
+++ b/plugins/game-cube/src/game-cube-plugin.vala
@@ -18,9 +18,7 @@ private class Games.GameCubePlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/mame/src/mame-plugin.vala b/plugins/mame/src/mame-plugin.vala
index 2d613258..08cd74a4 100644
--- a/plugins/mame/src/mame-plugin.vala
+++ b/plugins/mame/src/mame-plugin.vala
@@ -20,9 +20,7 @@ private class Games.MamePlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (SEARCHED_MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/ms-dos/src/ms-dos-plugin.vala b/plugins/ms-dos/src/ms-dos-plugin.vala
index a3e49841..6305488e 100644
--- a/plugins/ms-dos/src/ms-dos-plugin.vala
+++ b/plugins/ms-dos/src/ms-dos-plugin.vala
@@ -18,9 +18,7 @@ private class Games.MsDosPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala 
b/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
index 626e8f63..df1df36b 100644
--- a/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
+++ b/plugins/nintendo-3ds/src/nintendo-3ds-plugin.vala
@@ -20,10 +20,7 @@ private class Games.Nintendo3DsPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               foreach (var mime_type in MIME_TYPES)
-                       factory.add_mime_type (mime_type);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/nintendo-64/src/nintendo-64-plugin.vala b/plugins/nintendo-64/src/nintendo-64-plugin.vala
index ec232fc3..15ec72fa 100644
--- a/plugins/nintendo-64/src/nintendo-64-plugin.vala
+++ b/plugins/nintendo-64/src/nintendo-64-plugin.vala
@@ -19,9 +19,7 @@ private class Games.Nintendo64Plugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
index dcc1c05e..f3acadbc 100644
--- a/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
+++ b/plugins/nintendo-ds/src/nintendo-ds-plugin.vala
@@ -20,9 +20,7 @@ private class Games.NintendoDsPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/sega-cd/src/sega-cd-plugin.vala b/plugins/sega-cd/src/sega-cd-plugin.vala
index 0489ae22..19d04996 100644
--- a/plugins/sega-cd/src/sega-cd-plugin.vala
+++ b/plugins/sega-cd/src/sega-cd-plugin.vala
@@ -32,16 +32,8 @@ private class Games.SegaCDPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var sega_cd_adapter = new RetroSimpleGameUriAdapter (platform_sega_cd);
-               var sega_cd_factory = new GenericUriGameFactory (sega_cd_adapter);
-               sega_cd_factory.add_mime_type (CUE_MIME_TYPE);
-               sega_cd_factory.add_mime_type (SEGA_CD_MIME_TYPE);
-
-               var sega_cd_32x_adapter = new RetroSimpleGameUriAdapter (platform_sega_cd_32x);
-               var sega_cd_32x_factory = new GenericUriGameFactory (sega_cd_32x_adapter);
-               sega_cd_32x_factory.add_mime_type (CUE_MIME_TYPE);
-               sega_cd_32x_factory.add_mime_type (SEGA_CD_MIME_TYPE);
-               sega_cd_32x_factory.add_mime_type (32X_MIME_TYPE);
+               var sega_cd_factory = new GenericUriGameFactory (platform_sega_cd);
+               var sega_cd_32x_factory = new GenericUriGameFactory (platform_sega_cd_32x);
 
                return { sega_cd_factory, sega_cd_32x_factory };
        }
diff --git a/plugins/sega-saturn/src/sega-saturn-plugin.vala b/plugins/sega-saturn/src/sega-saturn-plugin.vala
index bf5e9492..ebe69e2e 100644
--- a/plugins/sega-saturn/src/sega-saturn-plugin.vala
+++ b/plugins/sega-saturn/src/sega-saturn-plugin.vala
@@ -20,10 +20,7 @@ private class Games.SegaSaturnPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (CUE_MIME_TYPE);
-               factory.add_mime_type (SEGA_SATURN_MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala 
b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
index 5a434ee8..a01f1572 100644
--- a/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
+++ b/plugins/turbografx-cd/src/turbografx-cd-plugin.vala
@@ -21,9 +21,7 @@ private class Games.TurboGrafxCDPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (CUE_MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/virtual-boy/src/virtual-boy-plugin.vala b/plugins/virtual-boy/src/virtual-boy-plugin.vala
index f57ac3b2..1da8f4e0 100644
--- a/plugins/virtual-boy/src/virtual-boy-plugin.vala
+++ b/plugins/virtual-boy/src/virtual-boy-plugin.vala
@@ -18,9 +18,7 @@ private class Games.VirtualBoyPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/plugins/wii/src/wii-plugin.vala b/plugins/wii/src/wii-plugin.vala
index e6655cca..7020882b 100644
--- a/plugins/wii/src/wii-plugin.vala
+++ b/plugins/wii/src/wii-plugin.vala
@@ -18,9 +18,7 @@ private class Games.WiiPlugin : Object, Plugin {
        }
 
        public UriGameFactory[] get_uri_game_factories () {
-               var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-               var factory = new GenericUriGameFactory (game_uri_adapter);
-               factory.add_mime_type (MIME_TYPE);
+               var factory = new GenericUriGameFactory (platform);
 
                return { factory };
        }
diff --git a/src/generic/generic-uri-game-factory.vala b/src/generic/generic-uri-game-factory.vala
index ce4b9277..bd538c32 100644
--- a/src/generic/generic-uri-game-factory.vala
+++ b/src/generic/generic-uri-game-factory.vala
@@ -1,23 +1,17 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 public class Games.GenericUriGameFactory : Object, UriGameFactory {
-       private GameUriAdapter game_uri_adapter;
+       private Platform platform;
        private HashTable<Uri, Game> game_for_uri;
-       private string[] mime_types;
        private unowned GameCallback game_added_callback;
 
-       public GenericUriGameFactory (GameUriAdapter game_uri_adapter) {
-               this.game_uri_adapter = game_uri_adapter;
+       public GenericUriGameFactory (Platform platform) {
+               this.platform = platform;
                game_for_uri = new HashTable<Uri, Game> (Uri.hash, Uri.equal);
-               mime_types = {};
        }
 
        public string[] get_mime_types () {
-               return mime_types;
-       }
-
-       public void add_mime_type (string mime_type) {
-               mime_types += mime_type;
+               return platform.get_mime_types ();
        }
 
        public void add_uri (Uri uri) {
@@ -25,7 +19,7 @@ public class Games.GenericUriGameFactory : Object, UriGameFactory {
                        return;
 
                try {
-                       var game = game_uri_adapter.game_for_uri (uri);
+                       var game = get_game_for_uri (uri);
                        game_for_uri[uri] = game;
 
                        if (game_added_callback != null)
@@ -52,4 +46,25 @@ public class Games.GenericUriGameFactory : Object, UriGameFactory {
        public void set_game_added_callback (GameCallback game_callback) {
                game_added_callback = game_callback;
        }
+
+       private Game get_game_for_uri (Uri uri) throws Error {
+               var parser = Object.new (platform.parser_type, platform: platform, uri: uri) as GameParser;
+
+               parser.parse ();
+
+               var uid = new Uid (parser.get_uid ());
+               var title = parser.get_title ();
+               var media = new GriloMedia (title, platform.get_presentation_mime_type ());
+               var cover = new CompositeCover ({
+                       new LocalCover (uri),
+                       new GriloCover (media, uid)});
+               var icon = parser.get_icon ();
+
+               var game = new Game (uid, uri, title, platform);
+               game.set_cover (cover);
+               if (icon != null)
+                       game.set_icon (icon);
+
+               return game;
+       }
 }
diff --git a/src/meson.build b/src/meson.build
index eb48490e..8db861e7 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -30,7 +30,6 @@ vala_sources = [
   'core/game-collection.vala',
   'core/game-model.vala',
   'core/game-parser.vala',
-  'core/game-uri-adapter.vala',
   'core/icon.vala',
   'core/input-capabilities.vala',
   'core/input-mode.vala',
@@ -101,7 +100,6 @@ vala_sources = [
   'retro/retro-gamepad.vala',
   'retro/retro-input-manager.vala',
   'retro/retro-options.vala',
-  'retro/retro-simple-game-uri-adapter.vala',
   'retro/retro-simple-type.vala',
   'retro/retro-simple-types.vala',
 
diff --git a/src/ui/application.vala b/src/ui/application.vala
index c76bd4ed..6d8c25af 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -454,10 +454,7 @@ public class Games.Application : Gtk.Application {
                        var platform = new Platform (simple_type.platform, platform_name, 
simple_type.mime_type, simple_type.prefix);
                        platform_register.add_platform (platform);
 
-                       var game_uri_adapter = new RetroSimpleGameUriAdapter (platform);
-                       var factory = new GenericUriGameFactory (game_uri_adapter);
-                       factory.add_mime_type (simple_type.mime_type);
-
+                       var factory = new GenericUriGameFactory (platform);
                        game_collection.add_factory (factory);
                }
 


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