[gnome-games/wip/aplazas/781334-refactor-game-sources: 20/27] ui: Add games when found by the GenericUriGameSource



commit 232726535714c7ad1cb41e4809e8f3222e778973
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Fri May 5 20:50:40 2017 +0200

    ui: Add games when found by the GenericUriGameSource
    
    Connect to the GenericUriGameSource.game_added() signal to add games to
    the collection directly when they are found by the generic URI game
    source.

 src/ui/application.vala |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
---
diff --git a/src/ui/application.vala b/src/ui/application.vala
index a9e47b4..d4e9263 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -4,6 +4,7 @@ private extern const string VERSION;
 
 public class Games.Application : Gtk.Application {
        private ListStore collection;
+       private GenericSet<Game> games;
        private ApplicationWindow window;
        private bool game_list_loaded;
 
@@ -140,6 +141,7 @@ public class Games.Application : Gtk.Application {
                Gtk.StyleContext.add_provider_for_screen (screen, provider, 600);
 
                collection = new ListStore (typeof (Game));
+               games = new GenericSet<Game> (direct_hash, direct_equal);
                load_game_list.begin ();
 
                window = new ApplicationWindow (collection);
@@ -173,6 +175,7 @@ public class Games.Application : Gtk.Application {
                }
 
                uri_game_source = new GenericUriGameSource ();
+               uri_game_source.game_added.connect ((game) => add_game (game));
                if (tracker_uri_source != null)
                        uri_game_source.add_source (tracker_uri_source);
 
@@ -238,7 +241,11 @@ public class Games.Application : Gtk.Application {
        }
 
        private void add_game (Game game) {
+               if (games.contains (game))
+                       return;
+
                collection.append (game);
+               games.add (game);
        }
 
        private void preferences () {


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