1 /*
2  * %kadu copyright begin%
3  * Copyright 2010, 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2012 Wojciech Treter (juzefwt@gmail.com)
5  * Copyright 2010 Piotr Dąbrowski (ultr@ultr.pl)
6  * Copyright 2011, 2012, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
7  * Copyright 2010, 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
8  * %kadu copyright end%
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #pragma once
25 
26 #include "accounts/account.h"
27 #include "buddies/buddy.h"
28 #include "contacts/contact.h"
29 #include "message/message.h"
30 
31 #include <QtCore/QMap>
32 #include <QtCore/QObject>
33 #include <injeqt/injeqt.h>
34 
35 class AccountManager;
36 class Buddy;
37 class BuddySet;
38 class ChatWidgetRepository;
39 class Contact;
40 class ContactSet;
41 
42 class KADUAPI BuddyPreferredManager : public QObject
43 {
44 	Q_OBJECT
45 
46 public:
47 	Q_INVOKABLE explicit BuddyPreferredManager(QObject *parent = nullptr);
48 	virtual ~BuddyPreferredManager();
49 
50 	Contact preferredContact(const Buddy &buddy, const Account &account, bool includechats = true);
51 	Contact preferredContact(const Buddy &buddy, bool includechats = true);
52 
53 	Contact preferredContact2(const Buddy &buddy);
54 	ContactSet preferredContacts(const BuddySet &buddies);
55 
56 	Account preferredAccount(const Buddy &buddy, bool includechats = true);
57 
58 	Contact preferredContactByPriority(const Buddy &buddy, const Account &account = Account::null);
59 	Contact preferredContactByUnreadMessages(const Buddy &buddy, const Account &account = Account::null);
60 	Contact preferredContactByChatWidgets(const Buddy &buddy, const Account &account = Account::null);
61 	Contact preferredContactByStatus(const Buddy &buddy, const Account &account = Account::null);
62 	Contact morePreferredContactByStatus(const Contact & c1, const Contact & c2, const Account &account = Account::null);
63 
64 	//void updatePreferred(Buddy buddy);
65 
66 signals:
67 	void buddyUpdated(const Buddy &buddy);
68 
69 private:
70 	QPointer<AccountManager> m_accountManager;
71 	QPointer<ChatWidgetRepository> m_chatWidgetRepository;
72 
73 	bool isAccountCommon(const Account &account, const BuddySet &buddies);
74 	Account getCommonAccount(const BuddySet &buddies);
75 
76 private slots:
77 	INJEQT_SET void setAccountManager(AccountManager *accountManager);
78 	INJEQT_SET void setChatWidgetRepository(ChatWidgetRepository *chatWidgetRepository);
79 
80 };
81