[gnome-games/wip/exalm/rebrand: 84/124] media-set: Add id and title




commit b30f4a7ee4e055f0704dd2a5bff744d1df0211dc
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Tue Mar 30 14:56:03 2021 +0500

    media-set: Add id and title

 .../playstation/src/playstation-game-factory.vala  |  2 +-
 src/core/media-set/media-set.vala                  | 27 ++++++++++++++++++++--
 src/core/runner.vala                               |  2 +-
 3 files changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-game-factory.vala 
b/plugins/playstation/src/playstation-game-factory.vala
index 5d0cd23d..09a859ce 100644
--- a/plugins/playstation/src/playstation-game-factory.vala
+++ b/plugins/playstation/src/playstation-game-factory.vala
@@ -111,7 +111,7 @@ public class Games.PlayStationGameFactory : Object, UriGameFactory {
                var media = new_medias.lookup (disc_id);
                media.add_uri (uri);
 
-               var media_set = new MediaSet ();
+               var media_set = new MediaSet (disc_set_id, new GameinfoDiscIdGameTitle (gameinfo, 
disc_set_id));
                foreach (var game_media in new_medias_array)
                        media_set.add_media (game_media);
                media_set.icon_name = ICON_NAME;
diff --git a/src/core/media-set/media-set.vala b/src/core/media-set/media-set.vala
index 0088d3d3..86e0fd62 100644
--- a/src/core/media-set/media-set.vala
+++ b/src/core/media-set/media-set.vala
@@ -4,16 +4,27 @@ public class Games.MediaSet : Object {
        public delegate void MediaCallback (Media media);
 
        public int selected_media_number { get; set; default = 0; }
+       public string id { get; private set; }
+       public Title title { get; private set; }
        public string icon_name { get; set; }
 
        private Media[] medias;
 
+       public MediaSet (string id, Title? title = null) {
+               this.id = id;
+               this.title = title;
+       }
+
        public MediaSet.parse (Variant variant) {
                assert (get_variant_type ().equal (variant.get_type ()));
 
-               var icon_child = variant.get_child_value (0);
-               var medias_child = variant.get_child_value (1);
+               var id_child = variant.get_child_value (0);
+               var title_child = variant.get_child_value (1);
+               var icon_child = variant.get_child_value (2);
+               var medias_child = variant.get_child_value (3);
 
+               id = id_child.get_string ();
+               title = new GenericTitle (title_child.get_string ());
                icon_name = icon_child.get_string ();
 
                medias = {};
@@ -53,7 +64,17 @@ public class Games.MediaSet : Object {
                        media_variants += media.serialize ();
                });
 
+               string title_string = null;
+               try {
+                       title_string = title.get_title ();
+               } catch (Error e) {
+                       critical ("Couldn't get title: %s", e.message);
+                       title_string = "";
+               }
+
                return new Variant.tuple ({
+                       new Variant.string (id),
+                       new Variant.string (title_string),
                        new Variant.string (icon_name),
                        new Variant.array (Media.get_variant_type (), media_variants)
                });
@@ -61,6 +82,8 @@ public class Games.MediaSet : Object {
 
        public static VariantType get_variant_type () {
                return new VariantType.tuple ({
+                       VariantType.STRING,
+                       VariantType.STRING,
                        VariantType.STRING,
                        new VariantType.array (Media.get_variant_type ())
                });
diff --git a/src/core/runner.vala b/src/core/runner.vala
index c1a0c785..38a256e4 100644
--- a/src/core/runner.vala
+++ b/src/core/runner.vala
@@ -83,7 +83,7 @@ public class Games.Runner : Object {
                        var media = new Media (game.uid.to_string (), game.title);
                        media.add_uri (game.uri);
 
-                       _media_set = new MediaSet ();
+                       _media_set = new MediaSet (game.uid.to_string (), game.title);
                        _media_set.add_media (media);
                }
 


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