[gnome-games] platform-model: Sync with GameModel when creating



commit 59cd471ccea828c40fd5d95465b56dfa23eddd34
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Feb 11 13:35:39 2020 +0500

    platform-model: Sync with GameModel when creating
    
    If GameModel already has some games added, we need to immediately create
    platforms for them.

 src/core/platform-model.vala | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
---
diff --git a/src/core/platform-model.vala b/src/core/platform-model.vala
index c07a088c..142077ea 100644
--- a/src/core/platform-model.vala
+++ b/src/core/platform-model.vala
@@ -12,6 +12,23 @@ private class Games.PlatformModel : Object, ListModel {
                n_platforms = 0;
                n_games = new HashTable<Platform, uint> (Platform.hash, Platform.equal);
 
+               uint n = game_model.get_n_items ();
+               for (uint i = 0; i < n; i++) {
+                       var game = game_model.get_item (i) as Game;
+                       var platform = game.get_platform ();
+
+                       if (n_games[platform] == 0) {
+                               sequence.append (platform);
+                               n_platforms++;
+                       }
+
+                       n_games[platform] = n_games[platform] + 1;
+               }
+
+               sequence.sort (compare_func);
+
+               items_changed (0, get_n_items (), 0);
+
                game_model.game_added.connect (game_added);
                game_model.game_removed.connect (game_removed);
        }


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