Commit 47568e34 authored by Raul Gutierrez Segales's avatar Raul Gutierrez Segales Committed by Travis Reitter
Browse files

Move SetComparator into folks/utils so it can be used by other backends

Helps: https://bugzilla.gnome.org/show_bug.cgi?id=657602
parent c1c79509
......@@ -29,7 +29,6 @@ libfolks_eds_la_vala.stamp:
folks_eds_valasources = \
edsf-persona.vala \
edsf-persona-store.vala \
edsf-util.vala \
memory-icon.vala \
$(NULL)
......
......@@ -1481,8 +1481,7 @@ public class Edsf.PersonaStore : Folks.PersonaStore
_("Roles are not writeable on this contact."));
}
var comp = new Edsf.SetComparator<RoleFieldDetails> ();
if (comp.equal (roles, persona.roles))
if (Folks.PersonaStore.equal_sets<RoleFieldDetails> (roles, persona.roles))
return;
yield this._set_contact_roles (persona.contact, roles);
......
......@@ -938,8 +938,7 @@ public class Edsf.Persona : Folks.Persona,
new_roles.add (role_fd);
}
var comp = new Edsf.SetComparator<RoleFieldDetails> ();
if (!comp.equal (new_roles, this._roles))
if (!Folks.PersonaStore.equal_sets<RoleFieldDetails> (new_roles, this._roles))
{
this._roles = new_roles;
this._roles_ro = new_roles.read_only_view;
......@@ -1035,8 +1034,8 @@ public class Edsf.Persona : Folks.Persona,
new_email_addresses.add (email_fd);
}
var comp = new Edsf.SetComparator<EmailFieldDetails> ();
if (!comp.equal (new_email_addresses, this._email_addresses))
if (!Folks.PersonaStore.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;
......@@ -1057,8 +1056,7 @@ public class Edsf.Persona : Folks.Persona,
new_notes.add (note);
}
var comp = new Edsf.SetComparator<NoteFieldDetails> ();
if (!comp.equal (new_notes, this._notes))
if (!Folks.PersonaStore.equal_sets<NoteFieldDetails> (new_notes, this._notes))
{
this._notes = new_notes;
this._notes_ro = this._notes.read_only_view;
......@@ -1414,8 +1412,8 @@ public class Edsf.Persona : Folks.Persona,
new_phone_numbers.add (phone_fd);
}
var comp = new Edsf.SetComparator<PhoneFieldDetails> ();
if (!comp.equal (new_phone_numbers, this._phone_numbers))
if (!Folks.PersonaStore.equal_sets<PhoneFieldDetails> (new_phone_numbers,
this._phone_numbers))
{
this._phone_numbers = new_phone_numbers;
this._phone_numbers_ro = new_phone_numbers.read_only_view;
......@@ -1498,8 +1496,9 @@ public class Edsf.Persona : Folks.Persona,
new_postal_addresses.add (pa_fd);
}
var comp = new Edsf.SetComparator<PostalAddressFieldDetails> ();
if (!comp.equal (new_postal_addresses, this._postal_addresses))
if (!Folks.PersonaStore.equal_sets<PostalAddressFieldDetails> (
new_postal_addresses,
this._postal_addresses))
{
this._postal_addresses = new_postal_addresses;
this._postal_addresses_ro = new_postal_addresses.read_only_view;
......@@ -1527,8 +1526,7 @@ public class Edsf.Persona : Folks.Persona,
/* Make sure it includes our local id */
new_local_ids.add (this.iid);
var comp = new Edsf.SetComparator<string> ();
if (!comp.equal (new_local_ids, this.local_ids))
if (!Folks.PersonaStore.equal_sets<string> (new_local_ids, this.local_ids))
{
this._local_ids = new_local_ids;
this._local_ids_ro = this._local_ids.read_only_view;
......
/*
* Copyright (C) 2011 Collabora Ltd.
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Authors:
* Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
*/
using Gee;
internal class Edsf.SetComparator<G> : GLib.Object {
internal bool equal (Set<G> a,
Set<G> b)
{
if (a.size != b.size)
return false;
foreach (var a_elem in a)
{
if (!b.contains (a_elem))
return false;
}
return true;
}
}
......@@ -658,4 +658,18 @@ public abstract class Folks.PersonaStore : Object
* @since 0.6.3
*/
public bool is_user_set_default { get; internal set; default = false; }
public static bool equal_sets<G> (Set<G> a, Set<G> b)
{
if (a.size != b.size)
return false;
foreach (var a_elem in a)
{
if (!b.contains (a_elem))
return false;
}
return true;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment