2 * Copyright (C) 2011 Collabora Ltd.
3 * Copyright (C) 2011 Philip Withnall
5 * This library is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 2.1 of the License, or
8 * (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Marco Barisione <marco.barisione@collabora.co.uk>
20 * Raul Gutierrez Segales <raul.gutierrez.segales@collabora.co.uk>
21 * Philip Withnall <philip@tecnocode.co.uk>
27 * Object for a full name split in its constituent parts (given name,
28 * family name, etc.). This structure corresponds to the "N" field in
29 * VCards. The parts of the name are never null, an empty string
30 * indicates that a property is not set.
34 public class Folks.StructuredName : Object
36 private string _family_name = "";
40 * The family name (also known as surname or last name) of a contact.
44 public string family_name
46 get { return this._family_name; }
47 construct set { this._family_name = value != null ? value : ""; }
50 private string _given_name = "";
54 * The family name (also known as first name) of a contact.
58 public string given_name
60 get { return this._given_name; }
61 construct set { this._given_name = value != null ? value : ""; }
64 private string _additional_names = "";
68 * The additional names of a contact, for instance the contact's
73 public string additional_names
75 get { return this._additional_names; }
76 construct set { this._additional_names = value != null ? value : ""; }
79 private string _prefixes = "";
81 * The prefixes of a name.
83 * The prefixes used in front of the name (for instance "Mr", "Mrs",
84 * "Doctor" or honorific titles).
88 public string prefixes
90 get { return this._prefixes; }
91 construct set { this._prefixes = value != null ? value : ""; }
94 private string _suffixes = "";
96 * The suffixes of a name.
98 * The suffixes used after a name (for instance "PhD" or "Junior").
102 public string suffixes
104 get { return this._suffixes; }
105 construct set { this._suffixes = value != null ? value : ""; }
109 * Create a StructuredName.
111 * You can pass `null` if a component is not set.
113 * @param family_name the family (last) name
114 * @param given_name the given (first) name
115 * @param additional_names additional names
116 * @param prefixes prefixes of the name
117 * @param suffixes suffixes of the name
118 * @return a new StructuredName
122 public StructuredName (string? family_name, string? given_name,
123 string? additional_names, string? prefixes, string? suffixes)
125 Object (family_name: family_name,
126 given_name: given_name,
127 additional_names: additional_names,
133 * Create a StructuredName.
135 * Shorthand for the common case of just having the family and given
136 * name of a contact. It's equivalent to calling
137 * {@link StructuredName.StructuredName} and passing `null` for all
138 * the other components.
140 * @param family_name the family (last) name
141 * @param given_name the given (first) name
142 * @return a new StructuredName
146 public StructuredName.simple (string? family_name, string? given_name)
148 Object (family_name: family_name,
149 given_name: given_name);
153 * Whether none of the components is set.
155 * @return `true` if all the components are the empty string, `false`
160 public bool is_empty ()
162 return this._family_name == "" &&
163 this._given_name == "" &&
164 this._additional_names == "" &&
165 this._prefixes == "" &&
166 this._suffixes == "";
170 * Whether two StructuredNames are the same.
172 * @param other the other structured name to compare with
173 * @return `true` if all the components are the same, `false`
178 public bool equal (StructuredName other)
180 return this._family_name == other.family_name &&
181 this._given_name == other.given_name &&
182 this._additional_names == other.additional_names &&
183 this._prefixes == other.prefixes &&
184 this._suffixes == other.suffixes;
188 * Formatted version of the structured name.
192 public string to_string ()
194 /* Translators: format for the formatted structured name.
195 * Parameters (in order) are: prefixes (for the name), given name,
196 * family name, additional names and (name) suffixes */
197 var str = "%s, %s, %s, %s, %s";
198 return str.printf (this.prefixes,
201 this.additional_names,
207 * Interface for classes which represent contacts with names, such as
208 * {@link Persona} and {@link Individual}.
212 public interface Folks.NameDetails : Object
215 * The contact name split in its constituent parts.
217 * Note that most of the time the structured name is not set (i.e.
218 * it's `null`) or just some of the components are set.
219 * The components are immutable. To get notification of changes of
220 * the structured name, you just have to connect to the `notify` signal
225 public abstract StructuredName? structured_name { get; set; }
228 * Change the contact's structured name.
230 * It's preferred to call this rather than setting
231 * {@link NameDetails.structured_name} directly, as this method gives error
232 * notification and will only return once the name has been written to the
233 * relevant backing store (or the operation's failed).
235 * @param name the structured name (`null` to unset it)
236 * @throws PropertyError if setting the structured name failed
239 public virtual async void change_structured_name (StructuredName? name)
242 /* Default implementation. */
243 throw new PropertyError.NOT_WRITEABLE (
244 _("Structured name is not writeable on this contact."));
248 * The full name of the contact.
250 * The full name is the name of the contact written in the way the contact
251 * prefers. For instance for English names this is usually the given name
252 * followed by the family name, but Chinese names are usually the family
253 * name followed by the given name.
254 * The full name could or could not contain additional names (like a
255 * middle name), prefixes or suffixes.
257 * The full name must not be `null`: the empty string represents an unset full
262 public abstract string full_name { get; set; }
265 * Change the contact's full name.
267 * It's preferred to call this rather than setting
268 * {@link NameDetails.full_name} directly, as this method gives error
269 * notification and will only return once the name has been written to the
270 * relevant backing store (or the operation's failed).
272 * @param full_name the full name (empty string to unset it)
273 * @throws PropertyError if setting the full name failed
276 public virtual async void change_full_name (string full_name)
279 /* Default implementation. */
280 throw new PropertyError.NOT_WRITEABLE (
281 _("Full name is not writeable on this contact."));
285 * The nickname of the contact.
287 * The nickname is the name that the contact chose for himself. This is
288 * different from {@link AliasDetails.alias} as aliases can be chosen by
289 * the user and not by the contacts themselves.
291 * Consequently, setting the nickname only makes sense in the context of an
292 * address book when updating the information a contact has specified about
295 * The nickname must not be `null`: the empty string represents an unset
300 public abstract string nickname { get; set; }
303 * Change the contact's nickname.
305 * It's preferred to call this rather than setting
306 * {@link NameDetails.nickname} directly, as this method gives error
307 * notification and will only return once the name has been written to the
308 * relevant backing store (or the operation's failed).
310 * @param nickname the nickname (empty string to unset it)
311 * @throws PropertyError if setting the nickname failed
314 public virtual async void change_nickname (string nickname)
317 /* Default implementation. */
318 throw new PropertyError.NOT_WRITEABLE (
319 _("Nickname is not writeable on this contact."));