1 /*
2  * %kadu copyright begin%
3  * Copyright 2009, 2010, 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2009 Wojciech Treter (juzefwt@gmail.com)
5  * Copyright 2009 Michał Podsiadlik (michal@kadu.net)
6  * Copyright 2009 Bartłomiej Zimoń (uzi18@o2.pl)
7  * Copyright 2011, 2012, 2013 Bartosz Brachaczek (b.brachaczek@gmail.com)
8  * Copyright 2009 Dawid Stawiarski (neeo@kadu.net)
9  * Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
10  * %kadu copyright end%
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program. If not, see <http://www.gnu.org/licenses/>.
24  */
25 
26 #pragma once
27 
28 #include "contacts/contact.h"
29 #include "message/message.h"
30 #include "storage/simple-manager.h"
31 #include "exports.h"
32 
33 #include <QtCore/QMap>
34 #include <QtCore/QObject>
35 #include <QtCore/QUuid>
36 #include <injeqt/injeqt.h>
37 
38 class Account;
39 class BuddyStorage;
40 class ConfigurationManager;
41 class Configuration;
42 class ContactStorage;
43 class Myself;
44 class Parser;
45 class UnreadMessageRepository;
46 
47 class KADUAPI ContactManager : public SimpleManager<Contact>
48 {
49 	Q_OBJECT
50 
51 public:
52 	enum AnonymousInclusion
53 	{
54 		IncludeAnonymous,
55 		ExcludeAnonymous
56 	};
57 
58 	Q_INVOKABLE explicit ContactManager(QObject *parent = nullptr);
59 	virtual ~ContactManager();
60 
storageNodeName()61 	virtual QString storageNodeName() override { return QStringLiteral("Contacts"); }
storageNodeItemName()62 	virtual QString storageNodeItemName() override { return QStringLiteral("Contact"); }
63 
64 	Contact byId(Account account, const QString &id, NotFoundAction action);
65 	QVector<Contact> contacts(Account account, AnonymousInclusion inclusion = IncludeAnonymous);
66 
67 signals:
68 	void contactAboutToBeAdded(Contact contact);
69 	void contactAdded(Contact contact);
70 	void contactAboutToBeRemoved(Contact contact);
71 	void contactRemoved(Contact contact);
72 
73 	void contactUpdated(const Contact &contact);
74 
75 protected:
76 	virtual void loaded() override;
77 	virtual Contact loadStubFromStorage(const std::shared_ptr<StoragePoint> &storagePoint) override;
78 
79 	virtual void itemAboutToBeAdded(Contact item) override;
80 	virtual void itemAdded(Contact item) override;
81 	virtual void itemAboutToBeRemoved(Contact item) override;
82 	virtual void itemRemoved(Contact item) override;
83 
84 private:
85 	QPointer<BuddyStorage> m_buddyStorage;
86 	QPointer<ConfigurationManager> m_configurationManager;
87 	QPointer<Configuration> m_configuration;
88 	QPointer<ContactStorage> m_contactStorage;
89 	QPointer<Myself> m_myself;
90 	QPointer<Parser> m_parser;
91 	QPointer<UnreadMessageRepository> m_unreadMessageRepository;
92 
93 private slots:
94 	INJEQT_SET void setBuddyStorage(BuddyStorage *buddyStorage);
95 	INJEQT_SET void setConfigurationManager(ConfigurationManager *configurationManager);
96 	INJEQT_SET void setConfiguration(Configuration *configuration);
97 	INJEQT_SET void setContactStorage(ContactStorage *contactStorage);
98 	INJEQT_SET void setMyself(Myself *myself);
99 	INJEQT_SET void setParser(Parser *parser);
100 	INJEQT_SET void setUnreadMessageRepository(UnreadMessageRepository *unreadMessageRepository);
101 	INJEQT_INIT void init();
102 	INJEQT_DONE void done();
103 
104 	void removeDuplicateContacts();
105 
106 	void contactDataUpdated();
107 
108 	void unreadMessageAdded(const Message &message);
109 	void unreadMessageRemoved(const Message &message);
110 
111 };
112