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, 2013, 2014 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-list.h"
25 #include "contacts/contact-manager.h"
26 #include "contacts/contact-set.h"
27 
28 #include "buddy-set.h"
29 
BuddySet()30 BuddySet::BuddySet()
31 {
32 }
33 
BuddySet(Buddy buddy)34 BuddySet::BuddySet(Buddy buddy)
35 {
36 	insert(buddy);
37 }
38 
isAllAnonymous() const39 bool BuddySet::isAllAnonymous() const
40 {
41 	foreach (const Buddy &buddy, *this)
42 		if (!buddy.isAnonymous())
43 			return false;
44 
45 	return true;
46 }
47 
isAnyTemporary() const48 bool BuddySet::isAnyTemporary() const
49 {
50 	for (auto &&buddy : *this)
51 		if (buddy.isTemporary())
52 			return true;
53 
54 	return false;
55 }
56 
toBuddyList() const57 BuddyList BuddySet::toBuddyList() const
58 {
59 	return toList();
60 }
61 
toBuddy() const62 Buddy BuddySet::toBuddy() const
63 {
64 	if (count() != 1)
65 		return Buddy::null;
66 
67 	return *constBegin();
68 }
69 
getAllContacts() const70 QVector<Contact> BuddySet::getAllContacts() const
71 {
72 	QVector<Contact> allContacts;
73 	foreach (const Buddy &buddy, *this)
74 		foreach (const Contact &contact, buddy.contacts())
75 			allContacts.append(contact);
76 
77 	return allContacts;
78 }
79 
qHash(const BuddySet & buddySet)80 uint qHash(const BuddySet &buddySet)
81 {
82 	uint hash = 0;
83 	foreach (const Buddy &buddy, buddySet)
84 		hash = hash ^ qHash(buddy);
85 
86 	return hash;
87 }
88