summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiels De Graef <nielsdegraef@gmail.com>2023-03-01 08:53:54 +0100
committerNiels De Graef <nielsdegraef@gmail.com>2023-03-02 07:31:29 +0000
commit0abbc2883e0c570ef84246aa3c8b735ba2a8eea2 (patch)
tree14d1c8f9f0e2702c64803817b99a76597a756a2a
parente594ee436db947725d6aab8ecb40117bcbced10b (diff)
downloadgnome-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.
-rw-r--r--src/core/contacts-addresses-chunk.vala35
-rw-r--r--tests/core/test-addresses-chunk.vala5
2 files changed, 24 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"];
diff --git a/tests/core/test-addresses-chunk.vala b/tests/core/test-addresses-chunk.vala
index 83ebb61..685c6bd 100644
--- a/tests/core/test-addresses-chunk.vala
+++ b/tests/core/test-addresses-chunk.vala
@@ -44,9 +44,14 @@ private void test_is_empty () {
assert_true (address.is_empty);
assert_true (chunk.is_empty);
+ // Make sure that the notify works correctly for the address too
+ bool notified = false;
+ address.notify["is-empty"].connect ((o, p) => { notified = true; });
+
address.address.street = "Yellow brick road";
assert_false (address.is_empty);
assert_false (chunk.is_empty);
+ assert_true (notified);
address.address.street = "";
assert_true (address.is_empty);