[gnome-games] ui: Use MIME types and factories froom plugins



commit 4a7eeca714f4293a79a558720f0b5d1fdcb029c6
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Thu May 4 15:26:49 2017 +0200

    ui: Use MIME types and factories froom plugins
    
    Use the MIME types and URI game factories provided by plugins in the
    application to search for game resources and to build games.
    
    This will be used in the next commits to allow plugins to stop providing
    game sources, helping to split the conerns of looking for game resources
    and building games from them.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781334

 src/ui/application.vala |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/src/ui/application.vala b/src/ui/application.vala
index ea4d6a6..6328bf6 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -134,7 +134,23 @@ public class Games.Application : Gtk.Application {
        }
 
        internal async void load_game_list () {
-               GameSource[] sources = {};
+               TrackerUriSource tracker_uri_source = null;
+               try {
+                       var connection = Tracker.Sparql.Connection.@get ();
+                       tracker_uri_source = new TrackerUriSource (connection);
+               }
+               catch (Error e) {
+                       debug (e.message);
+               }
+
+               var uri_game_source = new GenericUriGameSource ();
+               if (tracker_uri_source != null)
+                       uri_game_source.add_source (tracker_uri_source);
+
+               GameSource[] sources = {
+                       uri_game_source,
+               };
+               var mime_types = new GenericSet<string> (str_hash, str_equal);
 
                var register = PluginRegister.get_register ();
                register.foreach_plugin_registrar ((plugin_registrar) => {
@@ -143,6 +159,22 @@ public class Games.Application : Gtk.Application {
                                var source = plugin.get_game_source ();
                                if (source != null)
                                        sources += source;
+
+                               if (tracker_uri_source != null)
+                                       foreach (var mime_type in plugin.get_mime_types ()) {
+                                               if (mime_types.contains (mime_type))
+                                                       continue;
+
+                                               mime_types.add (mime_type);
+                                               var query = new MimeTypeTrackerUriQuery (mime_type);
+                                               tracker_uri_source.add_query (query);
+                                       }
+
+                               foreach (var uri_source in plugin.get_uri_sources ())
+                                       uri_game_source.add_source (uri_source);
+
+                               foreach (var factory in plugin.get_uri_game_factories ())
+                                       uri_game_source.add_factory (factory);
                        }
                        catch (Error e) {
                                debug ("Error: %s", e.message);


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