1/*
2 * Copyright 2015, Axel D��rfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef PEOPLE_H
6#define PEOPLE_H
7
8
9#include <map>
10
11#include <Locker.h>
12#include <ObjectList.h>
13#include <String.h>
14#include <StringList.h>
15
16#include "QueryList.h"
17
18
19class Person {
20public:
21								Person(const entry_ref& ref);
22	virtual						~Person();
23
24			const BString&		Name() const
25									{ return fName; }
26
27			int32				CountAddresses() const
28									{ return fAddresses.CountStrings(); }
29			BString				AddressAt(int32 index) const
30									{ return fAddresses.StringAt(index); }
31
32			int32				CountGroups() const
33									{ return fGroups.CountStrings(); }
34			BString				GroupAt(int32 index) const
35									{ return fGroups.StringAt(index); }
36			bool				IsInGroup(const char* group) const;
37
38private:
39			BString				fName;
40			BStringList			fAddresses;
41			BStringList			fGroups;
42};
43
44
45class PersonList : public QueryListener, public BLocker {
46public:
47								PersonList(QueryList& query);
48								~PersonList();
49
50			int32				CountPersons() const
51									{ return fPersons.CountItems(); }
52			const Person*		PersonAt(int32 index) const
53									{ return fPersons.ItemAt(index); }
54
55	virtual	void				EntryCreated(QueryList& source,
56									const entry_ref& ref, ino_t node);
57	virtual	void				EntryRemoved(QueryList& source,
58									const node_ref& nodeRef);
59
60private:
61	typedef std::map<node_ref, Person*> PersonMap;
62
63			QueryList&			fQueryList;
64			BObjectList<Person>	fPersons;
65			PersonMap			fPersonMap;
66};
67
68
69class GroupList : public QueryListener, public BLocker {
70public:
71								GroupList(QueryList& query);
72								~GroupList();
73
74			int32				CountGroups() const
75									{ return fGroups.CountStrings(); }
76			BString				GroupAt(int32 index) const
77									{ return fGroups.StringAt(index); }
78
79	virtual	void				EntryCreated(QueryList& source,
80									const entry_ref& ref, ino_t node);
81	virtual	void				EntryRemoved(QueryList& source,
82									const node_ref& nodeRef);
83
84private:
85	typedef std::map<BString, int> StringCountMap;
86
87			QueryList&			fQueryList;
88			BStringList			fGroups;
89			StringCountMap		fGroupMap;
90};
91
92
93#endif // ADDRESS_TEXT_CONTROL_H
94
95