1 /*
2  * %kadu copyright begin%
3  * Copyright 2009, 2010, 2011, 2012 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 2010, 2011, 2013, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com)
8  * Copyright 2009, 2010, 2011, 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com)
9  * %kadu copyright end%
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
25 #ifndef CHAT_H
26 #define CHAT_H
27 
28 #include "chat/chat-shared.h"
29 #include "storage/shared-base.h"
30 #include "exports.h"
31 
32 class Account;
33 class ContactSet;
34 class ChatDetails;
35 class ChatType;
36 class StoragePoint;
37 
38 class QString;
39 
40 /**
41  * @addtogroup Chat
42  * @{
43  */
44 
45 /**
46  * @class Chat
47  * @author Rafal 'Vogel' Malinowski
48  * @short Access object for chat data.
49  *
50  * This class allows to access to chat data defined in @link ChatShared @endlink class.
51  */
52 class KADUAPI Chat : public SharedBase<ChatShared>
53 {
54 	KaduSharedBaseClass(Chat)
55 
56 public:
57 	static Chat null;
58 
59 	Chat();
60 	Chat(ChatShared *data);
61 	explicit Chat(QObject *data);
62 	Chat(const Chat &copy);
63 
64 	virtual ~Chat();
65 
66 	bool showInAllGroup() const;
67 	bool isInGroup(Group group) const;
68 	void addToGroup(Group group) const;
69 	void removeFromGroup(Group group) const;
70 
71 	KaduSharedBase_PropertyRead(ContactSet, contacts, Contacts)
72 	KaduSharedBase_PropertyRead(QString, name, Name)
73 
74 	/**
75 	* @author Rafal 'Vogel' Malinowski
76 	* @short Details object for this chat.
77 	*
78 	* When ChatType for this chat is loaded and registered in ChatTypeManager
79 	* this field contains ChatDetails object that holds detailed information
80 	* about this chat.
81 	*/
82 	KaduSharedBase_PropertyRead(ChatDetails *, details, Details)
83 
84 	/**
85 	* @author Rafal 'Vogel' Malinowski
86 	* @short Account of this chat.
87 	*
88 	* Every chat is assigned to account. All contacts in every chat must
89 	* belong to the same account as chat.
90 	*/
91 	KaduSharedBase_PropertyCRW(Account, chatAccount, ChatAccount)
92 
93 	/**
94 	 * @author Rafal 'Vogel' Malinowski
95 	 * @short Name of chat type.
96 	 *
97 	 * Name of chat type. @link ChatType @endlink object with the same name must be loaded
98 	 * and registered in @link ChatTypeManager @endlink to allow this chat object to
99 	 * be fully functional and used. Example chat types are: 'contact' (for one-to-one chats)
100 	 * and 'contact-set' (for on-to-many chats). Other what types could be: 'irc-room' (for irc room
101 	 * chats).
102 	 */
103 	KaduSharedBase_PropertyCRW(QString, type, Type)
104 
105 	KaduSharedBase_PropertyCRW(QString, display, Display)
106 	KaduSharedBase_PropertyBool(IgnoreAllMessages)
107 	KaduSharedBase_PropertyCRW(QSet<Group>, groups, Groups)
108 	KaduSharedBase_Property(quint16, unreadMessagesCount, UnreadMessagesCount)
109 
110 	/**
111 	 * @author Rafal 'Vogel' Malinowski
112 	 * @short Return true when chat is connected.
113 	 * @return true when chat is connected
114 	 *
115 	 * Chat messages can only be send to/received from connected chat.
116 	 * Chat connection depends on chat type and is implemented in @link ChatDetails @endlink subclasses.
117 	 *
118 	 * For example, simple Contact and ContactSet chats are connected when an account is connected.
119 	 * MUC chats in XMPP are connected when account is connected and given group chat is joined.
120 	 */
121 	bool isConnected() const;
122 
123 	/**
124 	 * @author Rafal 'Vogel' Malinowski
125 	 * @short Get value of Open property.
126 	 * @return true when chat is open
127 	 *
128 	 * Chat is open when an associated chat widget is open.
129 	 */
130 	bool isOpen() const;
131 
132 	/**
133 	 * @author Rafal 'Vogel' Malinowski
134 	 * @short Set value of open property.
135 	 * @param open new value of Open property
136 	 *
137 	 * Changing value of Open property may result in emiting of @link opened() @endlink or @link closed() @endlink
138 	 * singals.
139 	 */
140 	void setOpen(bool open);
141 
142 };
143 
144 KADUAPI QString title(const Chat &chat);
145 
146 /**
147  * @}
148  */
149 
150 Q_DECLARE_METATYPE(Chat)
151 
152 #endif // CHAT_H
153