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
|
/*
* Copyright (C) 2018 Niels De Graef <nielsdegraef@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using Folks;
using Gee;
using Gtk;
/**
* A parent class for the {@link ContactEditor} and the {@link ContactSheet}.
*
* This exploits the common structure of both widgets: they both display a
* (possibly empty) contact, starting with a header and subsequently iterating
* over the several {@link Folks.Persona}s, displaying their properties.
*/
public abstract class Contacts.ContactForm : Grid {
protected const string[] SORTED_PROPERTIES = {
"email-addresses",
"phone-numbers",
"im-addresses",
"urls",
"nickname",
"birthday",
"postal-addresses",
"notes"
};
protected Contact? contact;
protected Store store;
protected int last_row = 0;
protected string[] sort_persona_properties (string[] props) {
CompareDataFunc<string> compare_properties = (a, b) => {
foreach (var prop in SORTED_PROPERTIES) {
if (a == prop)
return (b == prop)? 0 : -1;
if (b == prop)
return 1;
}
return 0;
};
var sorted_props = new ArrayList<string> ();
foreach (var s in props)
sorted_props.add (s);
sorted_props.sort ((owned) compare_properties);
return sorted_props.to_array ();
}
protected Label create_persona_store_label (Persona p) {
var store_name = new Label("");
store_name.set_markup (Markup.printf_escaped ("<span font='16px bold'>%s</span>",
Contact.format_persona_store_name_for_contact (p)));
store_name.set_halign (Align.START);
store_name.xalign = 0.0f;
store_name.margin_start = 6;
return store_name;
}
}
|