1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
/* contact.vala
*
* Copyright (C) 2008 Johann Prieur <johann.prieur@gmail.com>
* Copyright (C) 2008 Ali Sabil <ali.sabil@gmail.com>
*
* 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
using Core.Container;
using Core.Async;
namespace People.Backend {
[Flags]
public enum ContactFieldFlags {
NONE = 0,
WRITABLE = 1 << 0,
MANDATORY = 1 << 1
}
/**
* A ContactFieldSpec object contains a description for a {@link Contact}
* field.
*/
public class ContactFieldSpec : Object {
/**
* A combination of {@link ContactFieldFlags}.
*/
public uint flags {
construct;
get;
}
private Set<string> _annotations;
/**
* The annotations set, which contains the different annotations
* attributed to the specified {@link Contact} field.
* <p>
* An annotation provides an extra semantic information to a
* field. Some use cases can be found there :
* <ul>
* <li>If the annotation set of the field contains "country",
* the UI can provide the user a comprehensive list of
* countries to help him with the input
* <li>If the annotation set of the field contains "phone", the
* UI can combine it with localization data to provide the
* right entry pattern for a phone number
* </ul>
*/
public Set<string> annotations {
construct {
if (value != null)
_annotations = value;
else
_annotations = new HashSet<string> (str_hash, str_equal);
}
}
/**
* ContactFieldSpec constructor.
*
* @param flags a combination of {@see ContactFieldFlags}
* @param annotations a {@see Set} of annotations
*/
public ContactFieldSpec(uint flags, Set<string>?# annotations=null) {
this.flags = flags;
this.annotations = annotations;
}
/**
* Returns the annotations for the field specified by this
* ContactFieldSpec.
*
* @return a read-only {@link Set} of annotations
*/
public ReadOnlySet<string> get_annotations() {
return new ReadOnlySet<string> (_annotations);
}
/**
* Determines if this ContactFieldSpec specifies the given annotation.
*
* @param annotation the annotation string to look for
* @return <code>true</code> if the field contains the given
* annotation
*/
public bool has_annotation(string annotation) {
return _annotations.contains (annotation);
}
}
[Flags]
public enum ContactFlags {
NONE = 0,
EDITABLE = 1 << 0,
DELETABLE = 1 << 1
}
/**
* This interface defines base methods and properties to be implemented by
* Contact objects manipulated in the {@link ContactSource}.
*/
public interface Contact : Object {
/**
* A combination of {@link ContactFlags}.
*/
public abstract ContactFlags flags {
get;
protected set;
default = ContactFlags.NONE;
}
/**
* An unique identifier across the {@link ContactSource} for this
* Contact.
*/
public abstract string? id {
get;
protected set;
default = null;
}
/**
* Returns the set of fields defined for this Contact.
*
* @return an {@link AsyncResult} to be completed with a {@link Set}
* of field names
*/
public abstract AsyncResult<Set<string>> get_defined_fields();
/**
* Returns the set of definable sets for this Contact.
* <p>
* If the contact is able to store any field, then a <code>null</code>
* value is returned.
*
* @return <code>null</code> or an {@link AsyncResult} to be
* completed with a {@link Set} of field names
*/
public abstract AsyncResult<Set<string>> get_definable_fields();
/**
* Returns the set of mandatory fields for this Contact.
*
* @return an {@link AsyncResult} to be completed with a {@link Set}
* of field names
*/
public abstract AsyncResult<Set<string>> get_mandatory_fields();
/**
* Returns the {@link ContactFieldSpec} associated with the given field,
* or <code>null</code> if the field is not allowed for this Contact.
*
* @param field_name a string field name
* @return an {@link AsyncResult} to be completed with a
* {@link ContactFieldSpec} for the field
*/
public abstract AsyncResult<ContactFieldSpec> get_field_spec(string field_name);
/**
* Returns a {@link Map} of associations between the given {@link Set}
* of fields name and their values defined for this Contact.
*
* @param fields a Set of field names
* @return an {@link AsyncResult} to be completed with a Map
* between the fields and their associated values
*/
public abstract AsyncResult<Map<string, string>> get_fields(Set<string> fields);
/**
* Sets the values for the fields of this Contact as defined in the
* given {@link Map}.
*
* @param fields a Map between the fields names and the associated
* values
* @return an {@link AsyncResult} to be completed with a Set
* of actually updated fields
*/
public abstract AsyncResult<Set<string>> set_fields(Map<string, string> fields);
/**
* Marks a contact for deletion.
*
* @result an {@link AsyncResult} to be completed with
* <code>true</code> if the deletion went well, else
* <code>false</code>
*/
public abstract AsyncResult<bool> @delete();
}
}
|