[gnome-games] collection: Add is_empty property
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] collection: Add is_empty property
- Date: Fri, 31 Jul 2020 11:25:46 +0000 (UTC)
commit 13b3abbda90985042709a7887237758e2d9f02ae
Author: Neville <nevilleantony98 gmail com>
Date: Thu Jul 30 20:45:24 2020 +0530
collection: Add is_empty property
This property will be listened to invalidate CollectionMainPage's
flowbox filter, so that empty collections can be hidden.
src/collection/collection.vala | 2 ++
src/collection/favorites-collection.vala | 19 +++++++++++++++++++
src/collection/recently-played-collection.vala | 19 +++++++++++++++++++
3 files changed, 40 insertions(+)
---
diff --git a/src/collection/collection.vala b/src/collection/collection.vala
index 73b692b4c..9cbbaf01b 100644
--- a/src/collection/collection.vala
+++ b/src/collection/collection.vala
@@ -3,6 +3,8 @@
private interface Games.Collection : Object {
public signal void games_changed ();
+ public abstract bool is_empty { get; }
+
public abstract void load ();
public abstract string get_id ();
diff --git a/src/collection/favorites-collection.vala b/src/collection/favorites-collection.vala
index b611a64b6..ee3f5e2da 100644
--- a/src/collection/favorites-collection.vala
+++ b/src/collection/favorites-collection.vala
@@ -6,6 +6,11 @@ private class Games.FavoritesCollection : Object, Collection {
private Database database;
private GenericSet<Uid> favorite_game_uids;
+ private bool _is_empty = true;
+ public bool is_empty {
+ get { return _is_empty; }
+ }
+
private ulong idle_id = 0;
construct {
@@ -16,12 +21,26 @@ private class Games.FavoritesCollection : Object, Collection {
game_model = new GameModel ();
game_model.always_replace = true;
+ game_model.game_added.connect (() => {
+ set_is_empty (false);
+ });
+ game_model.game_removed.connect (() => {
+ set_is_empty (game_model.get_n_items () == 0);
+ });
}
public FavoritesCollection (Database database) {
this.database = database;
}
+ private void set_is_empty (bool value) {
+ if (is_empty == value)
+ return;
+
+ _is_empty = value;
+ notify_property ("is-empty");
+ }
+
public string get_id () {
return "Favorites";
}
diff --git a/src/collection/recently-played-collection.vala b/src/collection/recently-played-collection.vala
index 95a9891c7..c9240e490 100644
--- a/src/collection/recently-played-collection.vala
+++ b/src/collection/recently-played-collection.vala
@@ -6,6 +6,11 @@ private class Games.RecentlyPlayedCollection : Object, Collection {
private Database database;
private GenericSet<Uid> game_uids;
+ private bool _is_empty = true;
+ public bool is_empty {
+ get { return _is_empty; }
+ }
+
public RecentlyPlayedCollection (Database database) {
this.database = database;
@@ -17,6 +22,20 @@ private class Games.RecentlyPlayedCollection : Object, Collection {
game_model = new GameModel ();
game_model.always_replace = true;
game_model.sort_type = GameModel.SortType.BY_LAST_PLAYED;
+ game_model.game_added.connect (() => {
+ set_is_empty (false);
+ });
+ game_model.game_removed.connect (() => {
+ set_is_empty (game_model.get_n_items () == 0);
+ });
+ }
+
+ private void set_is_empty (bool value) {
+ if (is_empty == value)
+ return;
+
+ _is_empty = value;
+ notify_property ("is-empty");
}
public string get_id () {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]