=?utf-8?q?=5Bfolks=5D_eds=3A_Tie_favourite_status_to_=E2=80=9CStarred_in_?= =?utf-8?q?Android=E2=80=9D_group_for_Google_Contacts?=
- From: Philip Withnall <pwithnall src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [folks] eds: Tie favourite status to âStarred in Androidâ group for Google Contacts
- Date: Mon, 19 Mar 2012 18:54:27 +0000 (UTC)
commit dcf663dd9100b1ef1e52fdc6e2decdaf21a1332b
Author: Philip Withnall <philip tecnocode co uk>
Date: Mon Jan 9 13:18:56 2012 +0000
eds: Tie favourite status to âStarred in Androidâ group for Google Contacts
Link is-favourite to whether a âStarred in Androidâ group exists on a contact
(and vice-versa) if the contact is from a Google Contacts address book.
Closes: https://bugzilla.gnome.org/show_bug.cgi?id=661490
NEWS | 2 +
backends/eds/lib/edsf-persona-store.vala | 50 +++++++++++++++++++++++++++
backends/eds/lib/edsf-persona.vala | 54 ++++++++++++++++++++++++++++++
3 files changed, 106 insertions(+), 0 deletions(-)
---
diff --git a/NEWS b/NEWS
index d95725a..737cc35 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@ Bugs fixed:
* Bug 672381 â invalid uninstantiatable type `<invalid>' in cast to
`FolksIndividual'
* Bug 670347 â Check for null birthday strings
+* Bug 661490 â Should mark contacts from the "Starred in Android" group as
+ Favorites
Overview of changes from libfolks 0.6.6 to libfolks 0.6.7
=============================================================
diff --git a/backends/eds/lib/edsf-persona-store.vala b/backends/eds/lib/edsf-persona-store.vala
index 8290652..1ac7da3 100644
--- a/backends/eds/lib/edsf-persona-store.vala
+++ b/backends/eds/lib/edsf-persona-store.vala
@@ -48,6 +48,12 @@ public class Edsf.PersonaStore : Folks.PersonaStore
* haven't received a property change notification for it. */
private const uint _property_change_timeout = 30; /* seconds */
+ /* Translators: This should be translated to the name of the âStarred in
+ * Androidâ group in Google Contacts for your language. If Google have not
+ * localised the group for your language, or Google Contacts isn't available
+ * in your language, please *do not* translate this string. */
+ internal const string android_favourite_group_name = N_("Starred in Android");
+
/**
* The type of persona store this is.
*
@@ -1442,6 +1448,23 @@ public class Edsf.PersonaStore : Folks.PersonaStore
yield this._set_contact_is_favourite (persona.contact, is_favourite);
yield this._commit_modified_property (persona, "is-favourite");
+
+ /* If this is a Google Contacts address book, change the user's membership
+ * of the âStarred in Androidâ group accordingly. See: bgo#661490. */
+ if (this._is_google_contacts_address_book ())
+ {
+ try
+ {
+ yield persona.change_group (this.android_favourite_group_name,
+ is_favourite);
+ }
+ catch (GLib.Error e1)
+ {
+ /* We know this will always be a PropertyError. */
+ assert (e1 is PropertyError);
+ throw (PropertyError) e1;
+ }
+ }
}
private async void _set_contact_is_favourite (E.Contact contact,
@@ -1923,6 +1946,15 @@ public class Edsf.PersonaStore : Folks.PersonaStore
yield this._set_contact_groups (persona.contact, groups);
yield this._commit_modified_property (persona, "groups");
+
+ /* If this is a Google Contacts address book and the user's changing
+ * membership of the âStarred in Androidâ group, change our favourite
+ * status accordingly. See: bgo#661490. */
+ if (this._is_google_contacts_address_book ())
+ {
+ yield persona.change_is_favourite (
+ this.android_favourite_group_name in groups);
+ }
}
private async void _set_contact_groups (E.Contact contact, Set<string> groups)
@@ -2136,6 +2168,24 @@ public class Edsf.PersonaStore : Folks.PersonaStore
error_in.message);
}
+ /* Try and work out whether this address book is Google Contacts. If so, we
+ * can enable things like setting favourite status based on Android groups. */
+ internal bool _is_google_contacts_address_book ()
+ {
+ unowned SourceGroup? group = (SourceGroup?) this.source.peek_group ();
+ if (group != null)
+ {
+ var base_uri = ((!) group).peek_base_uri ();
+ /* base_uri should be google:// for Google Contacts address books */
+ if (base_uri.has_prefix ("google:"))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
private bool _is_in_source_list ()
{
/* Should only ever be called from a callback from the source list itself,
diff --git a/backends/eds/lib/edsf-persona.vala b/backends/eds/lib/edsf-persona.vala
index 0e1bbdb..5e6d935 100644
--- a/backends/eds/lib/edsf-persona.vala
+++ b/backends/eds/lib/edsf-persona.vala
@@ -1445,24 +1445,49 @@ public class Edsf.Persona : Folks.Persona,
}
}
+ var old_is_favourite = this._is_favourite;
+ var store = (Edsf.PersonaStore) this.store;
+
/* Make the changes to this._groups and emit signals. */
foreach (var category_name in removed_categories)
{
+ /* We link the âStarred in Androidâ group to Google Contacts address
+ * books. See: bgo#661490. */
+ if (store._is_google_contacts_address_book () &&
+ category_name == Edsf.PersonaStore.android_favourite_group_name)
+ {
+ this._is_favourite = false;
+ }
+
this.group_changed (category_name, false);
this._groups.remove (category_name);
}
foreach (var category_name in added_categories)
{
+ if (store._is_google_contacts_address_book () &&
+ category_name == Edsf.PersonaStore.android_favourite_group_name)
+ {
+ this._is_favourite = true;
+ }
+
this._groups.add (category_name);
this.group_changed (category_name, true);
}
/* Notify if anything's changed. */
+ this.freeze_notify ();
+
if (added_categories.size != 0 || removed_categories.size != 0)
{
this.notify_property ("groups");
}
+ if (this._is_favourite != old_is_favourite)
+ {
+ this.notify_property ("is-favourite");
+ }
+
+ this.thaw_notify ();
}
/**
@@ -1656,10 +1681,39 @@ public class Edsf.Persona : Folks.Persona,
}
}
+ var store = (Edsf.PersonaStore) this.store;
+
+ if (store._is_google_contacts_address_book ())
+ {
+ is_fav = is_fav ||
+ (Edsf.PersonaStore.android_favourite_group_name in this._groups);
+ }
+
if (is_fav != this._is_favourite)
{
this._is_favourite = is_fav;
+
+ var groups_changed = false;
+
+ if (store._is_google_contacts_address_book () &&
+ !(Edsf.PersonaStore.android_favourite_group_name in this._groups))
+ {
+ this._groups.add (Edsf.PersonaStore.android_favourite_group_name);
+ this.group_changed (
+ Edsf.PersonaStore.android_favourite_group_name, true);
+ groups_changed = true;
+ }
+
+ this.freeze_notify ();
+
+ if (groups_changed == true)
+ {
+ this.notify_property ("groups");
+ }
+
this.notify_property ("is-favourite");
+
+ this.thaw_notify ();
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]