1 /* 2 * %kadu copyright begin% 3 * Copyright 2010, 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im) 4 * Copyright 2010 Piotr Dąbrowski (ultr@ultr.pl) 5 * Copyright 2009 Bartłomiej Zimoń (uzi18@o2.pl) 6 * Copyright 2011, 2012 Bartosz Brachaczek (b.brachaczek@gmail.com) 7 * Copyright 2009, 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 "buddies/buddy-list.h" 27 #include "buddies/buddy.h" 28 #include "storage/simple-manager.h" 29 #include "exports.h" 30 31 #include <QtCore/QMap> 32 #include <QtCore/QObject> 33 #include <QtCore/QPointer> 34 #include <QtCore/QUuid> 35 #include <injeqt/injeqt.h> 36 37 class Account; 38 class BuddyStorage; 39 class ConfigurationApi; 40 class ConfigurationManager; 41 class Configuration; 42 class ContactManager; 43 44 class KADUAPI BuddyManager : public SimpleManager<Buddy> 45 { 46 Q_OBJECT 47 48 public: 49 Q_INVOKABLE explicit BuddyManager(QObject *parent = nullptr); 50 virtual ~BuddyManager(); 51 storageNodeName()52 virtual QString storageNodeName() override { return QStringLiteral("Buddies"); } storageNodeItemName()53 virtual QString storageNodeItemName() override { return QStringLiteral("Buddy"); } 54 55 BuddyList buddies(Account account, bool includeAnonymous = false); 56 void mergeBuddies(Buddy destination, Buddy source); 57 58 Buddy byDisplay(const QString &display, NotFoundAction action); 59 Buddy byId(Account account, const QString &id, NotFoundAction action); 60 Buddy byContact(Contact contact, NotFoundAction action); 61 Buddy byUuid(const QUuid &uuid); 62 63 void removeBuddyIfEmpty(Buddy buddy, bool checkOnlyForContacts = false); 64 void clearOwnerAndRemoveEmptyBuddy(Contact contact, bool checkBuddyOnlyForOtherContacts = false); 65 66 protected: 67 virtual void load() override; 68 virtual Buddy loadStubFromStorage(const std::shared_ptr<StoragePoint> &storagePoint) override; 69 70 virtual void itemAboutToBeAdded(Buddy buddy) override; 71 virtual void itemAdded(Buddy buddy) override; 72 virtual void itemAboutToBeRemoved(Buddy buddy) override; 73 virtual void itemRemoved(Buddy buddy) override; 74 75 signals: 76 void buddyAboutToBeAdded(const Buddy &buddy); 77 void buddyAdded(const Buddy &buddy); 78 void buddyAboutToBeRemoved(const Buddy &buddy); 79 void buddyRemoved(const Buddy &buddy); 80 81 void buddyContactAboutToBeAdded(const Buddy &buddy, const Contact &contact); 82 void buddyContactAdded(const Buddy &buddy, const Contact &contact); 83 void buddyContactAboutToBeRemoved(const Buddy &buddy, const Contact &contact); 84 void buddyContactRemoved(const Buddy &buddy, const Contact &contact); 85 86 void buddyUpdated(const Buddy &buddy); 87 void buddySubscriptionChanged(const Buddy &buddy); 88 89 private: 90 QPointer<BuddyStorage> m_buddyStorage; 91 QPointer<ConfigurationManager> m_configurationManager; 92 QPointer<Configuration> m_configuration; 93 QPointer<ContactManager> m_contactManager; 94 95 QString mergeValue(const QString &destination, const QString &source) const; 96 97 private slots: 98 INJEQT_SET void setBuddyStorage(BuddyStorage *buddyStorage); 99 INJEQT_SET void setConfigurationManager(ConfigurationManager *configurationManager); 100 INJEQT_SET void setConfiguration(Configuration *configuration); 101 INJEQT_SET void setContactManager(ContactManager *contactManager); 102 INJEQT_INIT void init(); 103 INJEQT_DONE void done(); 104 105 void buddyDataUpdated(); 106 void buddySubscriptionChanged(); 107 108 void buddyContactAboutToBeAdded(const Contact &contact); 109 void buddyContactAdded(const Contact &contact); 110 void buddyContactAboutToBeRemoved(const Contact &contact); 111 void buddyContactRemoved(const Contact &contact); 112 113 }; 114