[gnome-games/wip/exalm/cache2: 48/52] developer-view: Rework developer loading



commit 13ff9eb1c806e69b483c8665178bb4c4507d2584
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Sun Sep 30 18:12:19 2018 +0500

    developer-view: Rework developer loading
    
    Make use of newly added 'has-loaded' property to handle already loaded
    developers (such as GenericDeveloper) immediately and and special-case
    DummyDeveloper row.
    
    Also stop updating DeveloperListItem label, because it's not used anymore.

 src/ui/developer-list-item.vala |  1 -
 src/ui/developers-view.vala     | 64 ++++++++++++++++++++---------------------
 2 files changed, 32 insertions(+), 33 deletions(-)
---
diff --git a/src/ui/developer-list-item.vala b/src/ui/developer-list-item.vala
index 23871e8b..ebf066ad 100644
--- a/src/ui/developer-list-item.vala
+++ b/src/ui/developer-list-item.vala
@@ -9,7 +9,6 @@ private class Games.DeveloperListItem: Gtk.ListBoxRow {
                set {
                        _developer = value;
                        update_label ();
-                       value.changed.connect (update_label);
                }
        }
 
diff --git a/src/ui/developers-view.vala b/src/ui/developers-view.vala
index 0cce1477..8cc25114 100644
--- a/src/ui/developers-view.vala
+++ b/src/ui/developers-view.vala
@@ -4,22 +4,27 @@ private class Games.DevelopersView : SidebarView {
        // This is a List because Developer objects are mutable,
        // and can't be stored in a GenericSet without breaking.
        private List<Developer> shown_developers;
-       private List<Developer> all_developers;
+
+       private uint unknown_games;
+       private DeveloperListItem unknown_item;
 
        construct {
                shown_developers = new List<Developer> ();
-               all_developers = new List<Developer> ();
+               unknown_games = 0;
        }
 
        protected override void game_added (Game game) {
                var developer = game.get_developer ();
 
-               all_developers.append (developer);
-               show_developer (developer);
-               developer.changed.connect (invalidate_developer);
+               if (developer.has_loaded)
+                       show_developer (developer);
+               else {
+                       show_unknown ();
+                       developer.notify["has-loaded"].connect (invalidate_developer);
+               }
        }
 
-       private bool show_developer (Developer developer) {
+       private void show_developer (Developer developer) {
                var not_shown = shown_developers.find_custom (developer, Developer.compare) == null;
                if (not_shown) {
                        shown_developers.append (developer);
@@ -29,40 +34,35 @@ private class Games.DevelopersView : SidebarView {
                        if (selected_row != null)
                                invalidate (selected_row);
                }
-
-               return not_shown;
        }
 
-       private void hide_developer (Developer developer) {
-               Gtk.ListBoxRow? first_occurence = null;
+       private void show_unknown () {
+               unknown_games++;
 
-               foreach (var row in list_box.get_children ()) {
-                       var list_item = row as DeveloperListItem;
+               if (unknown_item != null)
+                       return;
 
-                       if (Developer.equal (list_item.developer, developer)) {
-                               if (first_occurence != null) {
-                                       if (row == list_box.get_selected_row ())
-                                               list_box.select_row (first_occurence);
+               var developer = new DummyDeveloper ();
+               shown_developers.append (developer);
 
-                                       row.destroy ();
+               unknown_item = new DeveloperListItem (developer);
 
-                                       break;
-                               }
-                               else {
-                                       first_occurence = list_item;
-                                       first_occurence.changed ();
-                               }
-                       }
-               }
+               list_box.add (unknown_item);
        }
 
-       private void invalidate_developer (Developer developer) {
-               if (!show_developer (developer)) {
-                       // If already shown, this developer's list item gets updated,
-                       // hence try to show developers that are now not represented,
-                       // and hide the developers that are now multiply represented.
-                       all_developers.foreach ((item) => show_developer (item));
-                       hide_developer (developer);
+       private void invalidate_developer (Object object, ParamSpec param) {
+               var developer = object as Developer;
+
+               if (developer.has_loaded)
+                       show_developer (developer);
+
+               unknown_games--;
+               collection_view.invalidate_filter ();
+
+               if (unknown_games == 0) {
+                       list_box.remove (unknown_item);
+                       unknown_item = null;
+                       select_default_row ();
                }
        }
 


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