summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);