diff options
author | Niels De Graef <nielsdegraef@gmail.com> | 2023-03-01 08:53:54 +0100 |
---|---|---|
committer | Niels De Graef <nielsdegraef@gmail.com> | 2023-03-02 07:31:29 +0000 |
commit | 0abbc2883e0c570ef84246aa3c8b735ba2a8eea2 (patch) | |
tree | 14d1c8f9f0e2702c64803817b99a76597a756a2a /src | |
parent | e594ee436db947725d6aab8ecb40117bcbced10b (diff) | |
download | gnome-contacts-0abbc2883e0c570ef84246aa3c8b735ba2a8eea2.tar.gz |
addresses-chunk: properly notify is-empty
We weren't sending out a property notification for `is-empty` when the
underlying `Folks.PostalAddress` changed, which meant that editing a
contact would only allows for a single address.
Also add a test to make sure we're not regressing on this.
Diffstat (limited to 'src')
-rw-r--r-- | src/core/contacts-addresses-chunk.vala | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/src/core/contacts-addresses-chunk.vala b/src/core/contacts-addresses-chunk.vala index bcdf508..b4a2c85 100644 --- a/src/core/contacts-addresses-chunk.vala +++ b/src/core/contacts-addresses-chunk.vala @@ -52,39 +52,42 @@ public class Contacts.AddressesChunk : BinChunk { public class Contacts.Address : BinChunkChild { - public PostalAddress address { - get { return this._address; } - set { - if (this._address.equal (value)) - return; - - bool was_empty = this._address.is_empty (); - this._address = value; - notify_property ("address"); - if (was_empty != value.is_empty ()) - notify_property ("is-empty"); - } - } - private PostalAddress _address = new PostalAddress ("", "", "", "", "", "", "", "", ""); + public PostalAddress address { get; construct; } public override bool is_empty { - get { return this.address.is_empty (); } + get { return this._is_empty; } } + private bool _is_empty = true; public override string icon_name { get { return "mark-location-symbolic"; } } + construct { + update_on_address (); + this.address.notify.connect ((obj, pspec) => { update_on_address (); }); + } + public Address () { + Object (address: new PostalAddress ("", "", "", "", "", "", "", "", "")); + this.parameters = new Gee.HashMultiMap<string, string> (); this.parameters["type"] = "HOME"; } public Address.from_field_details (PostalAddressFieldDetails address_field) { - this.address = address_field.value; + Object (address: address_field.value); + this.parameters = address_field.parameters; } + private void update_on_address () { + if (this.is_empty != this.address.is_empty ()) { + this._is_empty = this.address.is_empty (); + notify_property ("is-empty"); + } + } + protected override int compare_internal (BinChunkChild other) requires (other is Address) { var this_types = this.parameters["type"]; |