summaryrefslogtreecommitdiff
path: root/src/core/contacts-nickname-chunk.vala
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2022-09-06 22:09:25 +0200
committerNiels De Graef <nielsdegraef@gmail.com>2023-03-02 07:31:29 +0000
commitd455b34b76a25b116b7fa82d4cb5fcf862546bfa (patch)
treee41be2b1469648334a4f2c581b38747fe2ddc1e6 /src/core/contacts-nickname-chunk.vala
parent99af58107b2e49ad1b5a7fc91d290126fb8636ee (diff)
downloadgnome-contacts-d455b34b76a25b116b7fa82d4cb5fcf862546bfa.tar.gz
Move GVariant serialization into Chunk
Rather than building a big if-else block in the `Contacts.Io` namespace, it's much more interesting to move the GVariant serialization into the `Contacts.Chunk` objects themselves. That allows us to keep the serialization logic for a specific field in one place and makes sure we don't forget about any properties as they're not part of that big if-else block that checks on property name. This commit also make sure a lot of the functionality here is now unit tested, to make sure we're not accidentally regressing.
Diffstat (limited to 'src/core/contacts-nickname-chunk.vala')
-rw-r--r--src/core/contacts-nickname-chunk.vala17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/core/contacts-nickname-chunk.vala b/src/core/contacts-nickname-chunk.vala
index 81cf1d9..5dd7f79 100644
--- a/src/core/contacts-nickname-chunk.vala
+++ b/src/core/contacts-nickname-chunk.vala
@@ -68,4 +68,21 @@ public class Contacts.NicknameChunk : Chunk {
yield ((NameDetails) this.persona).change_nickname (this.nickname);
}
+
+ public override Variant? to_gvariant () {
+ if (this.nickname == "")
+ return null;
+ return new Variant.string (this.nickname);
+ }
+
+ public override void apply_gvariant (Variant variant,
+ bool mark_dirty = true)
+ requires (variant.get_type ().equal (VariantType.STRING)) {
+
+ unowned string nickname = variant.get_string ();
+ if (!mark_dirty) {
+ this.original_nickname = nickname;
+ }
+ this.nickname = nickname;
+ }
}