[gnome-games] developers-view: Rewrite file
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] developers-view: Rewrite file
- Date: Sun, 26 Aug 2018 18:07:08 +0000 (UTC)
commit cb83df80f0f3e7e2b3e655d6e9ddea5e1ddffcbb
Author: theawless <theawless gmail com>
Date: Sat Aug 25 23:38:45 2018 +0530
developers-view: Rewrite file
Remove the special case required for grilo developers, track changes for
developers that send a changed signal, and fix selection of default row
and use list item's compare function.
src/ui/developers-view.vala | 82 +++++++++++++++++++++++++++++++--------------
1 file changed, 57 insertions(+), 25 deletions(-)
---
diff --git a/src/ui/developers-view.vala b/src/ui/developers-view.vala
index 454d0109..d7250761 100644
--- a/src/ui/developers-view.vala
+++ b/src/ui/developers-view.vala
@@ -1,34 +1,69 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private class Games.DevelopersView : SidebarView {
- private GenericSet<Developer> developers = new GenericSet<Developer> (Developer.hash,
Developer.equal);
- private ulong developer_changed_id;
-
- private void invalidate_developer (Developer developer){
- if (!developers.contains (developer)) {
- developers.add (developer);
- var developer_list_item = new DeveloperListItem (developer);
- list_box.add (developer_list_item);
- }
+ // 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;
+
+ construct {
+ shown_developers = new List<Developer> ();
+ all_developers = new List<Developer> ();
}
protected override void game_added (Game game) {
var developer = game.get_developer ();
- developer_changed_id = developer.changed.connect ((source) => {
- invalidate_developer (source);
- });
+ all_developers.append (developer);
+ show_developer (developer);
+ developer.changed.connect (invalidate_developer);
+ }
- // FIXME: Currently developers are fetched in sync and there is
- // a need to check non GriloDeveloper objects, update this function
- // if necessary.
- if (!(developer is GriloDeveloper)) {
- if (developers.contains (developer))
- return;
+ private bool show_developer (Developer developer) {
+ var not_shown = shown_developers.find_custom (developer, Developer.compare) == null;
+ if (not_shown) {
+ shown_developers.append (developer);
+ list_box.add (new DeveloperListItem (developer));
- developers.add (developer);
- var listbox_item = new DeveloperListItem (developer);
- list_box.add (listbox_item);
+ 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;
+
+ foreach (var item in list_box.get_children ()) {
+ var row = item as Gtk.ListBoxRow;
+ var list_item = row.get_child () as DeveloperListItem;
+
+ if (Developer.equal (list_item.developer, developer)) {
+ if (first_occurence != null) {
+ if (row == list_box.get_selected_row ())
+ list_box.select_row (first_occurence);
+
+ row.destroy ();
+
+ break;
+ }
+ else {
+ first_occurence = row;
+ first_occurence.changed ();
+ }
+ }
+ }
+ }
+
+ 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);
}
}
@@ -42,9 +77,6 @@ private class Games.DevelopersView : SidebarView {
var item1 = row1.get_child () as DeveloperListItem;
var item2 = row2.get_child () as DeveloperListItem;
- assert (item1 != null);
- assert (item2 != null);
-
- return item1.label.collate (item2.label);
+ return DeveloperListItem.compare (item1, item2);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]