[gnome-games] collection: Introduce CollectionModel



commit 1454599f3a2288ac8137c70498825969d8be0ee0
Author: Neville <nevilleantony98 gmail com>
Date:   Thu Jun 18 21:26:05 2020 +0530

    collection: Introduce CollectionModel
    
    This is a ListModel which will be bound to the CollectionPage's
    flowbox.

 src/collection/collection-model.vala | 35 +++++++++++++++++++++++++++++++++++
 src/meson.build                      |  1 +
 2 files changed, 36 insertions(+)
---
diff --git a/src/collection/collection-model.vala b/src/collection/collection-model.vala
new file mode 100644
index 00000000..e82fc678
--- /dev/null
+++ b/src/collection/collection-model.vala
@@ -0,0 +1,35 @@
+// This file is part of GNOME Games. License: GPL-3.0+.
+
+private class Games.CollectionModel : Object, ListModel {
+       public signal void collection_added (Collection collection);
+
+       private Sequence<Collection> sequence;
+       private int n_collections;
+
+       construct {
+               sequence = new Sequence<Collection> ();
+               n_collections = 0;
+       }
+
+       public Object? get_item (uint position) {
+               var iter = sequence.get_iter_at_pos ((int) position);
+
+               return iter.get ();
+       }
+
+       public Type get_item_type () {
+               return typeof (Collection);
+       }
+
+       public uint get_n_items () {
+               return n_collections;
+       }
+
+       public void add_collection (Collection collection) {
+               var iter = sequence.append (collection);
+               n_collections++;
+
+               items_changed (iter.get_position (), 0, 1);
+               collection_added (collection);
+       }
+}
diff --git a/src/meson.build b/src/meson.build
index 73d40620..eeff67df 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -12,6 +12,7 @@ c_args = [
 
 vala_sources = [
   'collection/collection.vala',
+  'collection/collection-model.vala',
   'collection/favorites-collection.vala',
 
   'command/command-error.vala',


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]