1 /*
2  * %kadu copyright begin%
3  * Copyright 2010, 2011, 2012 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2009 Wojciech Treter (juzefwt@gmail.com)
5  * Copyright 2009 Bartłomiej Zimoń (uzi18@o2.pl)
6  * Copyright 2010, 2011, 2014 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 "contacts/contact.h"
27 #include "storage/shared.h"
28 
29 #include <QtCore/QPointer>
30 #include <QtCore/QSet>
31 #include <injeqt/injeqt.h>
32 
33 class AccountManager;
34 class Account;
35 class BuddySet;
36 class ChatDetails;
37 class ChatManager;
38 class ChatTypeManager;
39 class Chat;
40 class Configuration;
41 class ContactSet;
42 class GroupManager;
43 class Group;
44 
45 /**
46  * @addtogroup Chat
47  * @{
48  */
49 
50 /**
51  * @class ChatShared
52  * @author Rafal 'Vogel' Malinowski
53  * @short Chat data describing object.
54  *
55  * This class contains standard data that are common to all chat types used in application.
56  * Data specific to given chat type is stored in classes derivered from @link ChatDetails @endlink..
57  */
58 class KADUAPI ChatShared : public Shared
59 {
60 	Q_OBJECT
61 
62 	QPointer<AccountManager> m_accountManager;
63 	QPointer<ChatManager> m_chatManager;
64 	QPointer<ChatTypeManager> m_chatTypeManager;
65 	QPointer<Configuration> m_configuration;
66 	QPointer<GroupManager> m_groupManager;
67 
68 	Account *ChatAccount;
69 	ChatDetails *Details;
70 
71 	QString Display;
72 	QString Type;
73 	bool IgnoreAllMessages;
74 	QSet<Group> Groups;
75 	quint16 UnreadMessagesCount;
76 	bool Open;
77 
78 	void loadDetails();
79 	bool doAddToGroup(const Group &group);
80 	bool doRemoveFromGroup(const Group &group);
81 
82 private slots:
83 	INJEQT_SET void setAccountManager(AccountManager *accountManager);
84 	INJEQT_SET void setChatManager(ChatManager *chatManager);
85 	INJEQT_SET void setChatTypeManager(ChatTypeManager *chatTypeManager);
86 	INJEQT_SET void setConfiguration(Configuration *configuration);
87 	INJEQT_SET void setGroupManager(GroupManager *groupManager);
88 	INJEQT_INIT void init();
89 
90 	void groupAboutToBeRemoved();
91 
92 protected:
93 	virtual void load();
94 	virtual void store();
95 	virtual bool shouldStore();
96 
97 public:
98 	explicit ChatShared(const QUuid &uuid = QUuid::createUuid());
99 	virtual ~ChatShared();
100 
101 	virtual StorableObject * storageParent();
102 	virtual QString storageNodeName();
103 
104 	virtual void aboutToBeRemoved();
105 
details()106 	ChatDetails * details() const { return Details; }
107 
108 	ContactSet contacts();
109 	QString name();
110 
111 	KaduShared_PropertyRead(const QSet<Group> &, groups, Groups)
112 	void setGroups(const QSet<Group> &groups);
113 	bool showInAllGroup();
114 	bool isInGroup(const Group &group);
115 	void addToGroup(const Group &group);
116 	void removeFromGroup(const Group &group);
117 
118 	/**
119 	 * @author Rafal 'Vogel' Malinowski
120 	 * @short Account of this chat.
121 	 *
122 	 * Every chat is assigned to account. All contacts in every chat must
123 	 * belong to the same account as chat.
124 	 */
125 	KaduShared_PropertyDeclCRW(Account, chatAccount, ChatAccount)
126 
127 	KaduShared_Property(const QString &, display, Display)
128 
129 	/**
130 	 * @author Rafal 'Vogel' Malinowski
131 	 * @short Name of chat type.
132 	 *
133 	 * Name of chat type. @link ChatType @endlink object with the same name must be loaded
134 	 * and registered in @link ChatTypeManager @endlink to allow this chat object to
135 	 * be fully functional and used. Example chat types are: 'contact' (for one-to-one chats)
136 	 * and 'contact-set' (for on-to-many chats). Other what types could be: 'irc-room' (for irc room
137 	 * chats).
138 	 */
139 	KaduShared_PropertyWriteDecl(const QString &, type, Type)
140 	KaduShared_PropertyRead(const QString &, type, Type)
141 
142 	// temporary, not stored, lost after program close
143 	KaduShared_PropertyBool(IgnoreAllMessages)
144 
145 	KaduShared_Property(quint16, unreadMessagesCount, UnreadMessagesCount)
146 
147 	/**
148 	 * @author Rafal 'Vogel' Malinowski
149 	 * @short Return true when chat is connected.
150 	 * @return true when chat is connected
151 	 *
152 	 * Chat messages can only be send to/received from connected chat.
153 	 * Chat connection depends on chat type and is implemented in @link ChatDetails @endlink subclasses.
154 	 *
155 	 * For example, simple Contact and ContactSet chats are connected when an account is connected.
156 	 * MUC chats in XMPP are connected when account is connected and given group chat is joined.
157 	 */
158 	bool isConnected() const;
159 
160 	/**
161 	 * @author Rafal 'Vogel' Malinowski
162 	 * @short Get value of Open property.
163 	 * @return true when chat is open
164 	 *
165 	 * Chat is open when an associated chat widget is open.
166 	 */
167 	bool isOpen() const;
168 
169 	/**
170 	 * @author Rafal 'Vogel' Malinowski
171 	 * @short Set value of open property.
172 	 * @param open new value of Open property
173 	 *
174 	 * Changing value of Open property may result in emiting of @link opened() @endlink or @link closed() @endlink
175 	 * singals.
176 	 */
177 	void setOpen(bool open);
178 
179 signals:
180 	/**
181 	 * @author Rafal 'Vogel' Malinowski
182 	 * @short Signal emited when given chat has connected.
183 	 *
184 	 * Chat messages can only be send to/received from connected chat.
185 	 */
186 	void connected();
187 
188 	/**
189 	 * @author Rafal 'Vogel' Malinowski
190 	 * @short Signal emited when given chat has disconnected.
191 	 *
192 	 * Chat messages can only be send to/received from connected chat.
193 	 */
194 	void disconnected();
195 
196 	/**
197 	 * @author Rafal 'Vogel' Malinowski
198 	 * @short Signal emited when given chat has been opened.
199 	 */
200 	void opened();
201 
202 	/**
203 	 * @author Rafal 'Vogel' Malinowski
204 	 * @short Signal emited when given chat has been closed.
205 	 */
206 	void closed();
207 
208 	/**
209 	 * @author Rafal 'Vogel' Malinowski
210 	 * @short Signal emited just before a new contact is added to this Chat.
211 	 * @param contact added contact
212 	 */
213 	void contactAboutToBeAdded(const Contact &contact);
214 
215 	/**
216 	 * @author Rafal 'Vogel' Malinowski
217 	 * @short Signal emited when a new contact was added to this Chat.
218 	 * @param contact just added contact
219 	 */
220 	void contactAdded(const Contact &contact);
221 
222 	/**
223 	 * @author Rafal 'Vogel' Malinowski
224 	 * @short Signal emited just before a contact is removed from this Chat.
225 	 * @param contact removed contact
226 	 */
227 	void contactAboutToBeRemoved(const Contact &contact);
228 
229 	/**
230 	 * @author Rafal 'Vogel' Malinowski
231 	 * @short Signal emited when a contact was removed from this Chat.
232 	 * @param contact just removed contact
233 	 */
234 	void contactRemoved(const Contact &contact);
235 
236 	void updated();
237 
238 };
239 
240 /**
241  * @}
242  */
243