[gnome-games] collection: Introduce CollectionManager
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] collection: Introduce CollectionManager
- Date: Thu, 16 Jul 2020 14:50:43 +0000 (UTC)
commit 64eb88bc59de2976b79f08bf905a45dbbc2064f6
Author: Neville <nevilleantony98 gmail com>
Date: Thu Jun 18 21:29:45 2020 +0530
collection: Introduce CollectionManager
CollectionManager will be used to handle the creation and management
of collections. It consists of a HashTable which stores all the
discovered collections, a FavoriteCollection which is a non-user
collection for managing favorite games.
Provides a toggle_favorite() which adds and removes a game depending
on the list of games
src/collection/collection-manager.vala | 46 ++++++++++++++++++++++++++++++++++
src/meson.build | 1 +
2 files changed, 47 insertions(+)
---
diff --git a/src/collection/collection-manager.vala b/src/collection/collection-manager.vala
new file mode 100644
index 00000000..93657250
--- /dev/null
+++ b/src/collection/collection-manager.vala
@@ -0,0 +1,46 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.CollectionManager : Object {
+ public signal void collection_added (Collection collection);
+ public signal void collection_removed (Collection collection);
+
+ private HashTable<string, Collection> collections;
+ private Database database;
+
+ private FavoritesCollection favorites_collection;
+
+ public CollectionManager (Database database) {
+ this.database = database;
+ collections = new HashTable<string, Collection> (str_hash, str_equal);
+
+ add_favorites_collection ();
+
+ collections.foreach ((key, val) => {
+ val.load ();
+ });
+ }
+
+ public void toggle_favorite (Game[] games) {
+ var is_all_favorite = true;
+ foreach (var game in games) {
+ if (!game.is_favorite) {
+ is_all_favorite = false;
+ break;
+ }
+ }
+
+ if (is_all_favorite)
+ favorites_collection.remove_games (games);
+ else
+ favorites_collection.add_games (games);
+ }
+
+ private void add_favorites_collection () {
+ favorites_collection = new FavoritesCollection (database);
+ collections[favorites_collection.get_id ()] = favorites_collection;
+ Idle.add (() => {
+ collection_added (favorites_collection);
+ return Source.REMOVE;
+ });
+ }
+}
diff --git a/src/meson.build b/src/meson.build
index 71610442..8a0c05ae 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -14,6 +14,7 @@ vala_sources = [
'collection/collection.vala',
'collection/collection-model.vala',
'collection/favorites-collection.vala',
+ 'collection/collection-manager.vala',
'command/command-error.vala',
'command/command-runner.vala',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]