[gnome-contacts] Contacts: fix changing a Google Other contact into a My Contact
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts] Contacts: fix changing a Google Other contact into a My Contact
- Date: Mon, 12 Nov 2012 11:45:24 +0000 (UTC)
commit 21b814ae2c73dcf4e8191d04f724ef7c1af7584f
Author: Giovanni Campagna <gcampagna src gnome org>
Date: Sun Oct 28 18:23:48 2012 +0100
Contacts: fix changing a Google Other contact into a My Contact
Previously, clicking on the Add to My Contacts button for a Google
Other contact would attempt a link operation with nothing, that
would end up creating a new scratch contact to link into, which
by chance would also have the magic in-google-personal-group bit set.
Instead, use the new API in Folks to change it directly, to avoid
creating a duplicate contact.
https://bugzilla.gnome.org/show_bug.cgi?id=687049
src/contacts-contact-pane.vala | 123 +++++++++++++++++++++++++---------------
1 files changed, 77 insertions(+), 46 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index 511d8a5..5e5ced5 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -1250,8 +1250,9 @@ class Contacts.AddressFieldSet : FieldSet {
public class Contacts.PersonaSheet : Grid {
public ContactPane pane;
public Persona persona;
- FieldRow header;
+ FieldRow? header;
FieldRow footer;
+ int sheet_nr;
static Type[] field_set_types = {
typeof(LinkFieldSet),
@@ -1268,9 +1269,10 @@ public class Contacts.PersonaSheet : Grid {
};
FieldSet? field_sets[8]; // This is really the size of field_set_types
- public PersonaSheet(ContactPane pane, Persona persona, int sheet_nr) {
+ public PersonaSheet(ContactPane pane, Persona persona, int _sheet_nr) {
assert (field_sets.length == field_set_types.length);
+ this.sheet_nr = _sheet_nr;
this.pane = pane;
this.persona = persona;
@@ -1284,50 +1286,8 @@ public class Contacts.PersonaSheet : Grid {
Contact.persona_has_writable_property (persona, "postal-addresses");
if (!Contact.persona_is_main (persona) || sheet_nr > 0) {
- header = new FieldRow (pane.row_group, pane);
-
- Label label;
- var grid = header.pack_header_in_grid (Contact.format_persona_store_name_for_contact (persona), out label);
-
- if (!editable) {
- var image = new Image.from_icon_name ("changes-prevent-symbolic", IconSize.MENU);
-
- label.set_hexpand (false);
- image.get_style_context ().add_class ("dim-label");
- image.set_hexpand (true);
- image.set_halign (Align.START);
- image.set_valign (Align.CENTER);
- grid.add (image);
- }
-
- if (sheet_nr == 0) {
- var b = new Button.with_label(_("Add to My Contacts"));
- grid.add (b);
-
- b.clicked.connect ( () => {
- link_contacts.begin (pane.contact, null, (obj, result) => {
- link_contacts.end (result);
- /* TODO: Support undo */
- });
- });
- } else if (pane.contact.individual.personas.size > 1) {
- var b = new Button.with_label(_("Unlink"));
- grid.add (b);
-
- b.clicked.connect ( () => {
- unlink_persona.begin (pane.contact, persona, (obj, result) => {
- unlink_persona.end (result);
- /* TODO: Support undo */
- /* TODO: Ensure we don't get suggestion for this linkage again */
- });
- });
- }
-
- this.attach (header, 0, row_nr++, 1, 1);
-
- header.clicked.connect ( () => {
- this.pane.enter_edit_mode (header);
- });
+ this.build_header ();
+ row_nr = 1;
}
for (int i = 0; i < field_set_types.length; i++) {
@@ -1356,6 +1316,65 @@ public class Contacts.PersonaSheet : Grid {
persona.notify.disconnect(persona_notify_cb);
}
+ private void build_header () {
+ bool editable = Contact.persona_has_writable_property (persona, "email-addresses") &&
+ Contact.persona_has_writable_property (persona, "phone-numbers") &&
+ Contact.persona_has_writable_property (persona, "postal-addresses");
+
+ header = new FieldRow (pane.row_group, pane);
+
+ Label label;
+ var grid = header.pack_header_in_grid (Contact.format_persona_store_name_for_contact (persona), out label);
+
+ if (!editable) {
+ var image = new Image.from_icon_name ("changes-prevent-symbolic", IconSize.MENU);
+
+ label.set_hexpand (false);
+ image.get_style_context ().add_class ("dim-label");
+ image.set_hexpand (true);
+ image.set_halign (Align.START);
+ image.set_valign (Align.CENTER);
+ grid.add (image);
+ }
+
+ if (sheet_nr == 0) {
+ var b = new Button.with_label(_("Add to My Contacts"));
+ grid.add (b);
+
+ if (persona.store.is_primary_store) {
+ // Google Other contact (otherwise it wouldn't be non-main while
+ // being in the primary store)
+ b.clicked.connect ( () => {
+ (persona as Edsf.Persona).in_google_personal_group = true;
+ });
+ } else {
+ b.clicked.connect ( () => {
+ link_contacts.begin (pane.contact, null, (obj, result) => {
+ link_contacts.end (result);
+ /* TODO: Support undo */
+ });
+ });
+ }
+ } else if (pane.contact.individual.personas.size > 1) {
+ var b = new Button.with_label(_("Unlink"));
+ grid.add (b);
+
+ b.clicked.connect ( () => {
+ unlink_persona.begin (pane.contact, persona, (obj, result) => {
+ unlink_persona.end (result);
+ /* TODO: Support undo */
+ /* TODO: Ensure we don't get suggestion for this linkage again */
+ });
+ });
+ }
+
+ this.attach (header, 0, 0, 1, 1);
+
+ header.clicked.connect ( () => {
+ this.pane.enter_edit_mode (header);
+ });
+ }
+
private void add_detail () {
pane.exit_edit_mode (true);
var title = _("Select detail to add to %s").printf (pane.contact.display_name);
@@ -1441,6 +1460,18 @@ public class Contacts.PersonaSheet : Grid {
field_set.refresh_from_persona ();
}
}
+
+ if (name == "in-google-personal-group") {
+ bool is_main = Contact.persona_is_main (persona);
+
+ if ((!is_main || sheet_nr > 0) &&
+ header == null) {
+ this.build_header ();
+ } else if (is_main && sheet_nr == 0 && header != null) {
+ header.destroy();
+ header = null;
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]