[gnome-games] ui: Register game types from the application



commit f87355042bd81825a3f1af162e300b5c3fa3ff1e
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 25 14:22:20 2017 +0200

    ui: Register game types from the application
    
    Make the application register simple game types from the constant
    RETRO_SIMPLE_GAME_TYPES array.
    
    This will allow to replace many plugins by a few lines in this array.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783111

 src/Makefile.am                   |    1 +
 src/retro/retro-simple-types.vala |    6 ++++++
 src/ui/application.vala           |   18 ++++++++++++++++++
 3 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile.am b/src/Makefile.am
index 184efe1..d769481 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -102,6 +102,7 @@ gnome_games_SOURCES = \
        retro/retro-runner.vala \
        retro/retro-simple-game-uri-adapter.vala \
        retro/retro-simple-type.vala \
+       retro/retro-simple-types.vala \
        \
        tracker/mime-type-tracker-uri-query.vala \
        tracker/tracker-error.vala \
diff --git a/src/retro/retro-simple-types.vala b/src/retro/retro-simple-types.vala
new file mode 100644
index 0000000..73ed56c
--- /dev/null
+++ b/src/retro/retro-simple-types.vala
@@ -0,0 +1,6 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+namespace Games {
+       private const RetroSimpleType[] RETRO_SIMPLE_TYPES = {
+       };
+}
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 874735a..e5e988e 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -203,6 +203,24 @@ public class Games.Application : Gtk.Application {
 
                var mime_types = new GenericSet<string> (str_hash, str_equal);
 
+               /* Register simple Libretro-based game types */
+               foreach (var simple_type in RETRO_SIMPLE_TYPES) {
+                       assert (!mime_types.contains (simple_type.mime_type));
+
+                       if (simple_type.search_mime_type && tracker_uri_source != null) {
+                               mime_types.add (simple_type.mime_type);
+                               var query = new MimeTypeTrackerUriQuery (simple_type.mime_type);
+                               tracker_uri_source.add_query (query);
+                       }
+
+                       var game_uri_adapter = new RetroSimpleGameUriAdapter (simple_type);
+                       var factory = new GenericUriGameFactory (game_uri_adapter);
+                       factory.add_mime_type (simple_type.mime_type);
+
+                       game_collection.add_factory (factory);
+               }
+
+               /* Register game types from the plugins */
                var register = PluginRegister.get_register ();
                foreach (var plugin_registrar in register) {
                        try {


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