[gnome-games/wip/exalm/tnum: 8/24] collection-manager: Add support for user collections
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/tnum: 8/24] collection-manager: Add support for user collections
- Date: Wed, 19 Aug 2020 18:22:23 +0000 (UTC)
commit 37f0c1c7f02453a00a76e66ec1bb8171047c5111
Author: Neville <nevilleantony98 gmail com>
Date: Thu Aug 6 23:47:25 2020 +0530
collection-manager: Add support for user collections
src/collection/collection-manager.vala | 79 ++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
---
diff --git a/src/collection/collection-manager.vala b/src/collection/collection-manager.vala
index f26f7c99f..15c776306 100644
--- a/src/collection/collection-manager.vala
+++ b/src/collection/collection-manager.vala
@@ -11,12 +11,16 @@ private class Games.CollectionManager : Object {
private FavoritesCollection favorites_collection;
private RecentlyPlayedCollection recently_played_collection;
+ public uint n_user_collections { get; private set; }
+
public CollectionManager (Database database) {
this.database = database;
collections = new HashTable<string, Collection> (str_hash, str_equal);
add_favorites_collection ();
add_recently_played_collection ();
+ add_user_collections ();
+ add_new_collection_placeholder ();
collections.foreach ((key, val) => {
val.load ();
@@ -38,6 +42,72 @@ private class Games.CollectionManager : Object {
favorites_collection.add_games (games);
}
+ public UserCollection? create_user_collection (string title) {
+ var uuid = Uuid.string_random ();
+ var user_collection = new UserCollection (uuid, title, database);
+
+ try {
+ if (!database.add_user_collection (user_collection))
+ return null;
+
+ collections[uuid] = user_collection;
+ n_user_collections++;
+ Idle.add (() => {
+ collection_added (user_collection);
+ return Source.REMOVE;
+ });
+
+ return user_collection;
+ }
+ catch (Error e) {
+ critical ("%s", e.message);
+
+ return null;
+ }
+ }
+
+ public bool remove_user_collection (UserCollection collection) {
+ try {
+ if (!database.remove_user_collection (collection))
+ return false;
+
+ collections.remove (collection.get_id ());
+ n_user_collections--;
+ collection_removed (collection);
+ return true;
+ }
+ catch (Error e) {
+ critical ("%s", e.message);
+
+ return false;
+ }
+ }
+
+ public bool does_collection_title_exist (string title) {
+ foreach (var collection in collections.get_values ())
+ if (collection.get_title () == title)
+ return true;
+
+ return false;
+ }
+
+ private void add_user_collections () {
+ try {
+ var user_collections = database.get_user_collections ();
+ user_collections.foreach ((collection) => {
+ collections[collection.get_id ()] = collection;
+ n_user_collections++;
+ Idle.add (() => {
+ collection_added (collection);
+ return Source.REMOVE;
+ });
+ });
+ }
+ catch (Error e) {
+ critical ("Failed to load user collections: %s", e.message);
+ }
+ }
+
private void add_favorites_collection () {
favorites_collection = new FavoritesCollection (database);
favorites_collection.notify["is-empty"].connect (() => {
@@ -67,4 +137,13 @@ private class Games.CollectionManager : Object {
return Source.REMOVE;
});
}
+
+ private void add_new_collection_placeholder () {
+ var placeholder = new DummyAddCollection ();
+ collections[placeholder.get_id ()] = placeholder;
+ Idle.add (() => {
+ collection_added (placeholder);
+ return Source.REMOVE;
+ });
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]