[gnome-games/wip/exalm/db: 3/9] media-set: Serialize with GVariant
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/db: 3/9] media-set: Serialize with GVariant
- Date: Mon, 10 Feb 2020 17:18:58 +0000 (UTC)
commit e22c6b86cabd2b5e2ec97e431cb32aeb4428f618
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Mon Feb 10 19:29:22 2020 +0500
media-set: Serialize with GVariant
This will be used to store media sets in the database in a simple way.
src/core/media-set/media-set.vala | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
---
diff --git a/src/core/media-set/media-set.vala b/src/core/media-set/media-set.vala
index cb86e401..139a103a 100644
--- a/src/core/media-set/media-set.vala
+++ b/src/core/media-set/media-set.vala
@@ -8,6 +8,21 @@ public class Games.MediaSet : Object {
private Media[] medias;
+ 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);
+
+ icon_name = icon_child.get_string ();
+
+ medias = {};
+ for (int i = 0; i < medias_child.n_children (); i++) {
+ var media = medias_child.get_child_value (i);
+ medias += new Media.parse (media);
+ }
+ }
+
public void add_media (Media media) {
medias += media;
}
@@ -31,4 +46,23 @@ public class Games.MediaSet : Object {
return medias[index];
}
+
+ public Variant serialize () {
+ Variant[] media_variants = {};
+ foreach_media (media => {
+ media_variants += media.serialize ();
+ });
+
+ return new Variant.tuple ({
+ new Variant.string (icon_name),
+ new Variant.array (Media.get_variant_type (), media_variants)
+ });
+ }
+
+ public static VariantType get_variant_type () {
+ return new VariantType.tuple ({
+ VariantType.STRING,
+ new VariantType.array (Media.get_variant_type ())
+ });
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]