2 * Copyright (C) 2011 Collabora Ltd.
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 2.1 of the License, or
7 * (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library. If not, see <http://www.gnu.org/licenses/>.
18 * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
19 * Travis Reitter <travis.reitter@collabora.co.uk>
26 * This interface represents the role a {@link Persona} and {@link Individual}
27 * have in a given Organisation.
31 public class Folks.Role : Object
34 * The name of the organisation in which the role is held.
36 public string organisation_name { get; set; }
39 * The title of the position held.
41 * For example: “Director, Ministry of Silly Walks”
43 public string title { get; set; }
46 * The role of the position.
48 * For example: “Programmer”
52 public string role { get; set; }
55 * The UID that distinguishes this role.
57 public string uid { get; set; }
60 * Default constructor.
62 * @param title title of the position
63 * @param organisation_name organisation where the role is hold
64 * @param uid a Unique ID associated to this Role
69 public Role (string? title = null,
70 string? organisation_name = null, string? uid = null)
77 if (organisation_name == null)
79 organisation_name = "";
89 organisation_name: organisation_name);
93 * Compare if two roles are equal. Roles are equal if their titles and
94 * organisation names are equal.
96 * @param a a role to compare
97 * @param b another role to compare
98 * @return `true` if the roles are equal, `false` otherwise
100 public static bool equal (Role a, Role b)
102 return (a.title == b.title) &&
103 (a.role == b.role) &&
104 (a.organisation_name == b.organisation_name);
108 * Hash function for the class. Suitable for use as a hash table key.
110 * @param r a role to hash
111 * @return hash value for the role instance
113 public static uint hash (Role r)
115 return r.organisation_name.hash () ^ r.title.hash () ^ r.role.hash ();
119 * Formatted version of this role.
123 public string to_string ()
125 var str = _("Title: %s, Organisation: %s, Role: %s");
126 return str.printf (this.title, this.organisation_name, this.role);
131 * Object representing details of a contact in an organisation which can have
132 * some parameters associated with it.
134 * See {@link Folks.AbstractFieldDetails}.
138 public class Folks.RoleFieldDetails : AbstractFieldDetails<Role>
141 * Create a new RoleFieldDetails.
143 * @param value the {@link Role} of the field
144 * @param parameters initial parameters. See
145 * {@link AbstractFieldDetails.parameters}. A `null` value is equivalent to an
146 * empty map of parameters.
148 * @return a new RoleFieldDetails
152 public RoleFieldDetails (Role value,
153 MultiMap<string, string>? parameters = null)
156 if (parameters != null)
157 this.parameters = parameters;
165 public override bool equal (AbstractFieldDetails<string> that)
167 var that_fd = that as RoleFieldDetails;
172 return Role.equal (this.value, that_fd.value);
180 public override uint hash ()
182 return str_hash (this.value.to_string ());
187 * This interfaces represents the list of roles a {@link Persona} and
188 * {@link Individual} might have.
192 public interface Folks.RoleDetails : Object
195 * The roles of the contact.
199 public abstract Set<RoleFieldDetails> roles { get; set; }