1 /*
2  * %kadu copyright begin%
3  * Copyright 2010, 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2009 Bartłomiej Zimoń (uzi18@o2.pl)
5  * Copyright 2011 Bartosz Brachaczek (b.brachaczek@gmail.com)
6  * Copyright 2009, 2010, 2011 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
7  * %kadu copyright end%
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License as
11  * published by the Free Software Foundation; either version 2 of
12  * the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include "accounts/account-manager.h"
24 #include "buddies/buddy-set.h"
25 #include "contacts/contact-manager.h"
26 
27 #include "contact-set.h"
28 
ContactSet()29 ContactSet::ContactSet()
30 {
31 }
32 
ContactSet(const Contact & contact)33 ContactSet::ContactSet(const Contact &contact)
34 {
35 	insert(contact);
36 }
37 
toContactVector() const38 QVector<Contact> ContactSet::toContactVector() const
39 {
40 	QVector<Contact> result;
41 	result.reserve(size());
42 	foreach (const Contact &contact, *this)
43 		result.append(contact);
44 
45 	return result;
46 }
47 
toBuddySet() const48 BuddySet ContactSet::toBuddySet() const
49 {
50 	BuddySet buddies;
51 	foreach (const Contact &contact, *this)
52 		if (contact.ownerBuddy())
53 			buddies.insert(contact.ownerBuddy());
54 
55 	return buddies;
56 }
57 
toContact() const58 Contact ContactSet::toContact() const
59 {
60 	if (count() != 1)
61 		return Contact::null;
62 
63 	return *constBegin();
64 }
65