[gnome-games/wip/exalm/cache2: 1/20] developer-view: Rework developer loading
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/cache2: 1/20] developer-view: Rework developer loading
- Date: Sat, 6 Oct 2018 17:25:27 +0000 (UTC)
commit af8b92286748e9038d457deb8ad35142d5436b66
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 | 76 ++++++++++++++++++++---------------------
2 files changed, 37 insertions(+), 40 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..8df6bb64 100644
--- a/src/ui/developers-view.vala
+++ b/src/ui/developers-view.vala
@@ -1,68 +1,66 @@
// This file is part of GNOME Games. License: GPL-3.0+.
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 GenericSet<Developer> shown_developers;
+
+ private uint unknown_games;
+ private DeveloperListItem unknown_item;
construct {
- shown_developers = new List<Developer> ();
- all_developers = new List<Developer> ();
+ shown_developers = new GenericSet<Developer> (Developer.hash, Developer.equal);
+ 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 && developer.get_developer () != "")
+ show_developer (developer);
+ else {
+ show_unknown ();
+ developer.notify["has-loaded"].connect (invalidate_developer);
+ }
}
- private bool show_developer (Developer developer) {
- var not_shown = shown_developers.find_custom (developer, Developer.compare) == null;
- if (not_shown) {
- shown_developers.append (developer);
+ private void show_developer (Developer developer) {
+ var shown = shown_developers.contains (developer);
+ if (!shown) {
+ shown_developers.add (developer);
list_box.add (new DeveloperListItem (developer));
var selected_row = list_box.get_selected_row ();
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.add (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]