Commit 7560c542 authored by Jeremy Whiting's avatar Jeremy Whiting
Browse files

core: Added emit_notification parameter to _update methods.

telepathy: Added emit_notification parameter to lazy load _update methods.
eds: Added emit_notification parameter to lazy load _update methods.

Fixes bug https://bugzilla.gnome.org/show_bug.cgi?id=683267
parent af500a4b
......@@ -19,6 +19,7 @@ Bugs fixed:
• Bug 683452 — gnome-contacts starts up with an empty address book
• Bug 681476 — folks-inspect could use some methods to set values
• Bug 683390 — Individuals sometimes not removed when disabling their Telepathy account
• Bug 683267 — Warning when starting in non group mode
API changes:
• Add PropertyError.UNAVAILABLE
......
......@@ -238,7 +238,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_addresses (true);
this._update_addresses (true, false);
return this._postal_addresses_ro;
}
set { this.change_postal_addresses.begin (value); }
......@@ -269,7 +269,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_phones (true);
this._update_phones (true, false);
return this._phone_numbers_ro;
}
set { this.change_phone_numbers.begin (value); }
......@@ -299,7 +299,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_emails (true);
this._update_emails (true, false);
return this._email_addresses_ro;
}
set { this.change_email_addresses.begin (value); }
......@@ -330,7 +330,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_notes (true);
this._update_notes (true, false);
return this._notes_ro;
}
set { this.change_notes.begin (value); }
......@@ -505,7 +505,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_urls (true);
this._update_urls (true, false);
return this._urls_ro;
}
set { this.change_urls.begin (value); }
......@@ -564,7 +564,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_groups (true);
this._update_groups (true, false);
return this._groups_ro;
}
set { this.change_groups.begin (value); }
......@@ -673,7 +673,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_roles (true);
this._update_roles (true, false);
return this._roles_ro;
}
set { this.change_roles.begin (value); }
......@@ -702,7 +702,7 @@ public class Edsf.Persona : Folks.Persona,
{
get
{
this._update_groups (true); /* also checks for favourites */
this._update_groups (true, false); /* also checks for favourites */
return this._is_favourite;
}
set { this.change_is_favourite.begin (value); }
......@@ -1027,13 +1027,16 @@ public class Edsf.Persona : Folks.Persona,
}
}
private void _update_roles (bool create_if_not_exist)
private void _update_roles (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for roles. */
if (this._roles == null && create_if_not_exist == false)
{
this.notify_property ("roles");
if (emit_notification)
{
this.notify_property ("roles");
}
return;
}
else if (this._roles == null)
......@@ -1110,7 +1113,10 @@ public class Edsf.Persona : Folks.Persona,
{
this._roles = new_roles;
this._roles_ro = new_roles.read_only_view;
this.notify_property ("roles");
if (emit_notification)
{
this.notify_property ("roles");
}
}
}
......@@ -1196,13 +1202,16 @@ public class Edsf.Persona : Folks.Persona,
}
}
private void _update_emails (bool create_if_not_exist)
private void _update_emails (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for e-mail addresses. */
if (this._email_addresses == null && create_if_not_exist == false)
{
this.notify_property ("email-addresses");
if (emit_notification)
{
this.notify_property ("email-addresses");
}
return;
}
else if (this._email_addresses == null)
......@@ -1234,19 +1243,25 @@ public class Edsf.Persona : Folks.Persona,
if (!Folks.Internal.equal_sets<EmailFieldDetails> (new_email_addresses,
this._email_addresses))
{
this._email_addresses = new_email_addresses;
this._email_addresses_ro = new_email_addresses.read_only_view;
this.notify_property ("email-addresses");
this._email_addresses = new_email_addresses;
this._email_addresses_ro = new_email_addresses.read_only_view;
if (emit_notification)
{
this.notify_property ("email-addresses");
}
}
}
private void _update_notes (bool create_if_not_exist)
private void _update_notes (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for notes. */
if (this._notes == null && create_if_not_exist == false)
{
this.notify_property ("notes");
if (emit_notification)
{
this.notify_property ("notes");
}
return;
}
else if (this._notes == null)
......@@ -1272,7 +1287,10 @@ public class Edsf.Persona : Folks.Persona,
{
this._notes = new_notes;
this._notes_ro = this._notes.read_only_view;
this.notify_property ("notes");
if (emit_notification)
{
this.notify_property ("notes");
}
}
}
......@@ -1417,13 +1435,16 @@ public class Edsf.Persona : Folks.Persona,
}
}
private void _update_urls (bool create_if_not_exist)
private void _update_urls (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for URIs. */
if (this._urls == null && create_if_not_exist == false)
{
this.notify_property ("urls");
if (emit_notification)
{
this.notify_property ("urls");
}
return;
}
else if (this._urls == null)
......@@ -1475,7 +1496,10 @@ public class Edsf.Persona : Folks.Persona,
{
this._urls = new_urls;
this._urls_ro = new_urls.read_only_view;
this.notify_property ("urls");
if (emit_notification)
{
this.notify_property ("urls");
}
}
}
......@@ -1583,13 +1607,16 @@ public class Edsf.Persona : Folks.Persona,
}
}
private void _update_groups (bool create_if_not_exist)
private void _update_groups (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for groups. */
if (this._groups == null && create_if_not_exist == false)
{
this.notify_property ("groups");
if (emit_notification)
{
this.notify_property ("groups");
}
return;
}
else if (this._groups == null)
......@@ -1690,18 +1717,22 @@ public class Edsf.Persona : Folks.Persona,
/* Notify if anything's changed. */
this.freeze_notify ();
if (added_categories.size != 0 || removed_categories.size != 0)
if ((added_categories.size != 0 || removed_categories.size != 0) &&
emit_notification)
{
this.notify_property ("groups");
}
if (this._is_favourite != old_is_favourite)
if (this._is_favourite != old_is_favourite && emit_notification)
{
this.notify_property ("is-favourite");
}
if (in_google_personal_group != this._in_google_personal_group)
{
this._in_google_personal_group = in_google_personal_group;
this.notify_property ("in-google-personal-group");
if (emit_notification)
{
this.notify_property ("in-google-personal-group");
}
}
this.thaw_notify ();
......@@ -1739,7 +1770,7 @@ public class Edsf.Persona : Folks.Persona,
return retval;
}
private void _update_phones (bool create_if_not_exist)
private void _update_phones (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for phone numbers. */
......@@ -1779,7 +1810,10 @@ public class Edsf.Persona : Folks.Persona,
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
this.notify_property ("phone-numbers");
if (emit_notification)
{
this.notify_property ("phone-numbers");
}
}
}
......@@ -1843,13 +1877,16 @@ public class Edsf.Persona : Folks.Persona,
* are the same and if so instantiate only one PostalAddress
* (with the given types).
*/
private void _update_addresses (bool create_if_not_exist)
private void _update_addresses (bool create_if_not_exist, bool emit_notification = true)
{
/* See the comments in Folks.Individual about the lazy instantiation
* strategy for addresses. */
if (this._postal_addresses == null && create_if_not_exist == false)
{
this.notify_property ("postal-addresses");
if (emit_notification)
{
this.notify_property ("postal-addresses");
}
return;
}
else if (this._postal_addresses == null)
......@@ -1884,7 +1921,10 @@ public class Edsf.Persona : Folks.Persona,
{
this._postal_addresses = new_postal_addresses;
this._postal_addresses_ro = new_postal_addresses.read_only_view;
this.notify_property ("postal-addresses");
if (emit_notification)
{
this.notify_property ("postal-addresses");
}
}
}
......
......@@ -365,7 +365,7 @@ public class Tpf.Persona : Folks.Persona,
{
get
{
this._contact_notify_contact_info (true);
this._contact_notify_contact_info (true, false);
return this._email_addresses_ro;
}
set { this.change_email_addresses.begin (value); }
......@@ -661,7 +661,7 @@ public class Tpf.Persona : Folks.Persona,
{
get
{
this._contact_notify_contact_info (true);
this._contact_notify_contact_info (true, false);
return this._phone_numbers_ro;
}
set { this.change_phone_numbers.begin (value); }
......@@ -907,7 +907,7 @@ public class Tpf.Persona : Folks.Persona,
}
}
private void _contact_notify_contact_info (bool create_if_not_exists)
private void _contact_notify_contact_info (bool create_if_not_exists, bool emit_notification = true)
{
assert ((
(this._email_addresses == null) &&
......@@ -926,9 +926,12 @@ public class Tpf.Persona : Folks.Persona,
* function is called identically for all of them. */
if (this._urls == null && create_if_not_exists == false)
{
this.notify_property ("email-addresses");
this.notify_property ("phone-numbers");
this.notify_property ("urls");
if (emit_notification)
{
this.notify_property ("email-addresses");
this.notify_property ("phone-numbers");
this.notify_property ("urls");
}
return;
}
else if (this._urls == null)
......@@ -1032,7 +1035,10 @@ public class Tpf.Persona : Folks.Persona,
!this._birthday.equal (d.to_utc ())))
{
this._birthday = d.to_utc ();
this.notify_property ("birthday");
if (emit_notification)
{
this.notify_property ("birthday");
}
changed = true;
}
}
......@@ -1047,7 +1053,10 @@ public class Tpf.Persona : Folks.Persona,
if (this._birthday != null)
{
this._birthday = null;
this.notify_property ("birthday");
if (emit_notification)
{
this.notify_property ("birthday");
}
changed = true;
}
}
......@@ -1057,14 +1066,20 @@ public class Tpf.Persona : Folks.Persona,
{
this._email_addresses = new_email_addresses;
this._email_addresses_ro = new_email_addresses.read_only_view;
this.notify_property ("email-addresses");
if (emit_notification)
{
this.notify_property ("email-addresses");
}
changed = true;
}
if (new_full_name != this._full_name)
{
this._full_name = new_full_name;
this.notify_property ("full-name");
if (emit_notification)
{
this.notify_property ("full-name");
}
changed = true;
}
......@@ -1073,7 +1088,10 @@ public class Tpf.Persona : Folks.Persona,
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
this.notify_property ("phone-numbers");
if (emit_notification)
{
this.notify_property ("phone-numbers");
}
changed = true;
}
......@@ -1081,7 +1099,10 @@ public class Tpf.Persona : Folks.Persona,
{
this._urls = new_urls;
this._urls_ro = new_urls.read_only_view;
this.notify_property ("urls");
if (emit_notification)
{
this.notify_property ("urls");
}
changed = true;
}
......
......@@ -504,7 +504,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_urls (true);
this._update_urls (true, false);
return this._urls_ro;
}
set { this.change_urls.begin (value); } /* not writeable */
......@@ -521,7 +521,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_phone_numbers (true);
this._update_phone_numbers (true, false);
return this._phone_numbers_ro;
}
set { this.change_phone_numbers.begin (value); } /* not writeable */
......@@ -538,7 +538,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_email_addresses (true);
this._update_email_addresses (true, false);
return this._email_addresses_ro;
}
set { this.change_email_addresses.begin (value); } /* not writeable */
......@@ -555,7 +555,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_roles (true);
this._update_roles (true, false);
return this._roles_ro;
}
set { this.change_roles.begin (value); } /* not writeable */
......@@ -572,7 +572,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_local_ids (true);
this._update_local_ids (true, false);
return this._local_ids_ro;
}
set { this.change_local_ids.begin (value); } /* not writeable */
......@@ -613,7 +613,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_notes (true);
this._update_notes (true, false);
return this._notes_ro;
}
set { this.change_notes.begin (value); } /* not writeable */
......@@ -630,7 +630,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_postal_addresses (true);
this._update_postal_addresses (true, false);
return this._postal_addresses_ro;
}
set { this.change_postal_addresses.begin (value); } /* not writeable */
......@@ -733,7 +733,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_groups (true);
this._update_groups (true, false);
return this._groups_ro;
}
set { this.change_groups.begin (value); }
......@@ -810,7 +810,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_im_addresses (true);
this._update_im_addresses (true, false);
return this._im_addresses;
}
set { this.change_im_addresses.begin (value); } /* not writeable */
......@@ -827,7 +827,7 @@ public class Folks.Individual : Object,
{
get
{
this._update_web_service_addresses (true);
this._update_web_service_addresses (true, false);
return this._web_service_addresses;
}
/* Not writeable: */
......@@ -1429,7 +1429,8 @@ public class Folks.Individual : Object,
*/
private void _update_multi_valued_property (string prop_name,
bool create_if_not_exist, PropertyIsNull prop_is_null,
CollectionCreator create_collection, MultiValuedPropertySetter setter)
CollectionCreator create_collection, MultiValuedPropertySetter setter,
bool emit_notification = true)
{
/* If the set of values doesn't exist, and we're not meant to lazily
* create it, then simply emit a notification (since the set might've
......@@ -1440,7 +1441,10 @@ public class Folks.Individual : Object,
/* Notify and return. */
if (create_if_not_exist == false)
{
this.notify_property (prop_name);
if (emit_notification)
{
this.notify_property (prop_name);
}
return;
}
......@@ -1450,13 +1454,13 @@ public class Folks.Individual : Object,
/* Re-populate the collection as the union of the values in the
* individual's personas. */
if (setter () == true)
if (setter () == true && emit_notification)
{
this.notify_property (prop_name);
}
}
private void _update_groups (bool create_if_not_exist)
private void _update_groups (bool create_if_not_exist, bool emit_notification = true)
{
/* If the set of groups doesn't exist, and we're not meant to lazily
* create it, then simply emit a notification (since the set might've
......@@ -1464,7 +1468,10 @@ public class Folks.Individual : Object,
* return. */
if (this._groups == null && create_if_not_exist == false)
{
this.notify_property ("groups");
if (emit_notification)
{
this.notify_property ("groups");
}
return;
}
......@@ -1497,7 +1504,7 @@ public class Folks.Individual : Object,
foreach (var group in new_groups)
{
if (this._groups.add (group))
if (this._groups.add (group) && emit_notification)
{
this.group_changed (group, true);
}
......@@ -1515,7 +1522,10 @@ public class Folks.Individual : Object,
{
unowned string group = (string) l;
this._groups.remove (group);
this.group_changed (group, false);
if (emit_notification)
{
this.group_changed (group, false);
}
});
}
......@@ -1683,7 +1693,7 @@ public class Folks.Individual : Object,
this.trust_level = trust_level;
}
private void _update_im_addresses (bool create_if_not_exist)
private void _update_im_addresses (bool create_if_not_exist, bool emit_notification = true)
{
this._update_multi_valued_property ("im-addresses",
create_if_not_exist, () => { return this._im_addresses == null; },
......@@ -1727,10 +1737,10 @@ public class Folks.Individual : Object,
}
return false;
});
}, emit_notification);
}
private void _update_web_service_addresses (bool create_if_not_exist)
private void _update_web_service_addresses (bool create_if_not_exist, bool emit_notification = true)
{
this._update_multi_valued_property ("web-service-addresses",
create_if_not_exist,
......@@ -1779,7 +1789,7 @@ public class Folks.Individual : Object,
}
return false;
});
}, emit_notification);
}
private void _connect_to_persona (Persona persona)
......@@ -2022,7 +2032,7 @@ public class Folks.Individual : Object,
});
}
private void _update_urls (bool create_if_not_exist)
private void _update_urls (bool create_if_not_exist, bool emit_notification = true)
{
this._update_multi_valued_property ("urls", create_if_not_exist,
() => { return this._urls == null; },
......@@ -2076,10 +2086,10 @@ public class Folks.Individual : Object,
}
return false;
});
}, emit_notification);
}
private void _update_phone_numbers (bool create_if_not_exist)
private void _update_phone_numbers (bool create_if_not_exist, bool emit_notification = true)
{
this._update_multi_valued_property ("phone-numbers", create_if_not_exist,
() => { return this._phone_numbers == null; },
......@@ -2133,10 +2143,10 @@ public class Folks.Individual : Object,
}
return false;
});
}, emit_notification);
}
private void _update_email_addresses (bool create_if_not_exist)
private void _update_email_addresses (bool create_if_not_exist, bool emit_notification = true)
{
this._update_multi_valued_property ("email-addresses",
create_if_not_exist, () => { return this._email_addresses == null; },
......@@ -2191,10 +2201,10 @@ public class Folks.Individual : Object,
}
return false;
});
}, emit_notification);
}
private void _update_roles (bool create_if_not_exist)
private void _update_roles (bool create_if_not_exist, bool emit_notification = true)