[gnome-games/wip/exalm/rebrand: 83/124] media: Add id and title
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/rebrand: 83/124] media: Add id and title
- Date: Sat, 19 Jun 2021 14:37:45 +0000 (UTC)
commit c88c9c26ba84b75e58f341a32f6b5679bf7d03e7
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Mar 30 14:45:05 2021 +0500
media: Add id and title
This will help us to get rid of unique code in PlayStationGameFactory.
.../playstation/src/playstation-game-factory.vala | 2 +-
src/core/media.vala | 28 +++++++++++++---------
src/core/runner.vala | 2 +-
3 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/plugins/playstation/src/playstation-game-factory.vala
b/plugins/playstation/src/playstation-game-factory.vala
index ed3d635d..5d0cd23d 100644
--- a/plugins/playstation/src/playstation-game-factory.vala
+++ b/plugins/playstation/src/playstation-game-factory.vala
@@ -103,7 +103,7 @@ public class Games.PlayStationGameFactory : Object, UriGameFactory {
assert (!media_for_disc_id.contains (new_disc_id));
var title = new GameinfoDiscIdDiscTitle (gameinfo, new_disc_id);
- var media = new Media (title);
+ var media = new Media (new_disc_id, title);
new_medias_array += media;
new_medias[new_disc_id] = media;
}
diff --git a/src/core/media.vala b/src/core/media.vala
index c6e1d36e..101fbbe8 100644
--- a/src/core/media.vala
+++ b/src/core/media.vala
@@ -1,11 +1,13 @@
// This file is part of GNOME Games. License: GPL-3.0+.
public class Games.Media : Object {
- public Title? title { get; private set; }
+ public string id { get; private set; }
+ public Title title { get; private set; }
private Uri[] uris;
- public Media (Title? title = null) {
+ public Media (string id, Title title) {
+ this.id = id;
this.title = title;
this.uris = {};
}
@@ -13,12 +15,13 @@ public class Games.Media : Object {
public Media.parse (Variant variant) {
assert (get_variant_type ().equal (variant.get_type ()));
- var title_child = variant.get_child_value (0);
- var uris_child = variant.get_child_value (1);
+ int child_index = 0;
+ var id_child = variant.get_child_value (child_index++);
+ var title_child = variant.get_child_value (child_index++);
+ var uris_child = variant.get_child_value (child_index++);
- var maybe_title = title_child.get_maybe ();
- if (maybe_title != null)
- title = new GenericTitle (maybe_title.get_string ());
+ id = id_child.get_string ();
+ title = new GenericTitle (title_child.get_string ());
uris = {};
for (int i = 0; i < uris_child.n_children (); i++) {
@@ -36,13 +39,14 @@ public class Games.Media : Object {
}
public Variant serialize () {
- Variant? title_variant = null;
+ string title_string = null;
if (title != null)
try {
- title_variant = new Variant.string (title.get_title ());
+ title_string = title.get_title ();
}
catch (Error e) {
critical ("Couldn't get title: %s", e.message);
+ title_string = "";
}
Variant[] uri_variants = {};
@@ -50,14 +54,16 @@ public class Games.Media : Object {
uri_variants += new Variant.string (uri.to_string ());
return new Variant.tuple ({
- new Variant.maybe (VariantType.STRING, title_variant),
+ new Variant.string (id),
+ new Variant.string (title_string),
new Variant.array (VariantType.STRING, uri_variants)
});
}
public static VariantType get_variant_type () {
return new VariantType.tuple ({
- new VariantType.maybe (VariantType.STRING),
+ VariantType.STRING,
+ VariantType.STRING,
new VariantType.array (VariantType.STRING)
});
}
diff --git a/src/core/runner.vala b/src/core/runner.vala
index 6179e182..c1a0c785 100644
--- a/src/core/runner.vala
+++ b/src/core/runner.vala
@@ -80,7 +80,7 @@ public class Games.Runner : Object {
_media_set = game.media_set;
if (media_set == null && game.uri != null) {
- var media = new Media ();
+ var media = new Media (game.uid.to_string (), game.title);
media.add_uri (game.uri);
_media_set = new MediaSet ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]