2 * Copyright 2015-2016, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
16 PersonName(BNode
& node
)
19 node
.ReadAttrString("META:name", &fullName
);
26 AddPersonAddresses(BNode
& node
, BStringList
& addresses
)
29 if (node
.ReadAttrString("META:email", &email
) != B_OK
|| email
.IsEmpty())
34 // Support for 3rd-party People apps
35 for (int i
= 2; i
< 99; i
++) {
37 snprintf(attr
, sizeof(attr
), "META:email%d", i
);
39 if (node
.ReadAttrString(attr
, &email
) != B_OK
)
48 AddPersonGroups(BNode
& node
, BStringList
& groups
)
51 if (node
.ReadAttrString("META:group", &groupString
) != B_OK
52 || groupString
.IsEmpty()) {
57 while (first
< groupString
.Length()) {
58 int end
= groupString
.FindFirst(',', first
);
60 end
= groupString
.Length();
63 groupString
.CopyInto(group
, first
, end
- first
);
72 // #pragma mark - Person
75 Person::Person(const entry_ref
& ref
)
78 if (node
.InitCheck() != B_OK
)
81 fName
= PersonName(node
);
82 AddPersonAddresses(node
, fAddresses
);
83 AddPersonGroups(node
, fGroups
);
93 Person::IsInGroup(const char* group
) const
95 for (int32 index
= 0; index
< CountGroups(); index
++) {
96 if (GroupAt(index
) == group
)
103 // #pragma mark - PersonList
106 PersonList::PersonList(QueryList
& query
)
111 fQueryList
.AddListener(this);
115 PersonList::~PersonList()
117 fQueryList
.RemoveListener(this);
122 PersonList::EntryCreated(QueryList
& source
, const entry_ref
& ref
, ino_t node
)
124 BAutolock
locker(this);
126 Person
* person
= new Person(ref
);
127 fPersons
.AddItem(person
);
128 fPersonMap
.insert(std::make_pair(node_ref(ref
.device
, node
), person
));
133 PersonList::EntryRemoved(QueryList
& source
, const node_ref
& nodeRef
)
135 BAutolock
locker(this);
137 PersonMap::iterator found
= fPersonMap
.find(nodeRef
);
138 if (found
!= fPersonMap
.end()) {
139 Person
* person
= found
->second
;
140 fPersonMap
.erase(found
);
141 fPersons
.RemoveItem(person
);
146 // #pragma mark - GroupList
149 GroupList::GroupList(QueryList
& query
)
153 fQueryList
.AddListener(this);
157 GroupList::~GroupList()
159 fQueryList
.RemoveListener(this);
164 GroupList::EntryCreated(QueryList
& source
, const entry_ref
& ref
, ino_t _node
)
167 if (node
.InitCheck() != B_OK
)
170 BAutolock
locker(this);
173 AddPersonGroups(node
, groups
);
175 for (int32 index
= 0; index
< groups
.CountStrings(); index
++) {
176 BString group
= groups
.StringAt(index
);
178 StringCountMap::iterator found
= fGroupMap
.find(group
);
179 if (found
!= fGroupMap
.end())
182 fGroupMap
[group
] = 1;
192 GroupList::EntryRemoved(QueryList
& source
, const node_ref
& nodeRef
)