1 /*
2  * %kadu copyright begin%
3  * Copyright 2009, 2011 Piotr Galiszewski (piotr.galiszewski@kadu.im)
4  * Copyright 2009 Wojciech Treter (juzefwt@gmail.com)
5  * Copyright 2011 Piotr Dąbrowski (ultr@ultr.pl)
6  * Copyright 2009 Michał Podsiadlik (michal@kadu.net)
7  * Copyright 2011, 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 #pragma once
26 
27 #include "buddies/buddy-list.h"
28 #include "chat/chat.h"
29 #include "exports.h"
30 
31 #include "protocols/services/account-service.h"
32 
33 #include <QtCore/QPointer>
34 #include <injeqt/injeqt.h>
35 
36 class FormattedString;
37 class Message;
38 class RawMessageTransformerService;
39 
40 /**
41  * @addtogroup Protocol
42  * @{
43  */
44 
45 /**
46  * @class ChatService
47  * @short Chat service allows sending and receiving messages.
48  * @author Rafał 'Vogel' Malinowski
49  *
50  * This service allows sending and receiving messages. Each message can be modified before sending or after
51  * receiving to allow protocol-independent encryption and filtering.
52  *
53  * One method must be reimplemented by derivered sevices: sendMessage().
54  */
55 class KADUAPI ChatService : public AccountService
56 {
57 	Q_OBJECT
58 
59 protected:
60 	explicit ChatService(Account account, QObject *parent = nullptr);
61 	virtual ~ChatService();
62 
63 public:
64 	/**
65 	 * @short Return raw message transformer service of this service.
66 	 * @author Rafał 'Vogel' Malinowski
67 	 * @return raw message transformer service of this service
68 	 */
69 	RawMessageTransformerService * rawMessageTransformerService() const;
70 
71 	/**
72 	 * @short Return max message length for this implementation.
73 	 * @author Rafał 'Vogel' Malinowski
74 	 * @return max message length for this implementation
75 	 */
76 	virtual int maxMessageLength() const = 0;
77 
78 public slots:
79 	/**
80 	 * @short Send new message to given chat.
81 	 * @param message message to be sent
82 	 *
83 	 * This methods sends a message. Service is allowed to ignore this requst and to ignore any formatting
84 	 * that is present in message.
85 	 *
86 	 * Message can be altered by RawMessageTransformerService to allow any encryption on any protocol.
87 	 */
88 	virtual bool sendMessage(const Message &message) = 0;
89 
90 	/**
91 	 * @short Send raw message to given chat.
92 	 * @param chat chat for the message
93 	 * @param message message to be sent
94 	 * @param transform is message should be transformed by RawMessageTransformerService
95 	 *
96 	 * This methods sends a message. Service is allowed to ignore this requst.
97 	 *
98 	 * This message won't be altered by RawMessageTransformerService.
99 	 */
100 	virtual bool sendRawMessage(const Chat &chat, const QByteArray &rawMessage) = 0;
101 
102 	/**
103 	 * @short Leave @p chat.
104 	 *
105 	 * Use to leave chats in GG and room chats in XMPP. In current implemntations does nothing for single
106 	 * contact chats in XMPP. May change in future.
107 	 */
108 	virtual void leaveChat(const Chat &chat) = 0;
109 
110 signals:
111 	/**
112 	 * @short Signal emitted when sent message status has changed.
113 	 * @param message message with changed status
114 	 *
115 	 * This signal is emitted every time a protocol learns about delivery status of sent message.
116 	 */
117 	void sentMessageStatusChanged(const Message &message);
118 
119 	/**
120 	 * @author Rafał 'Vogel' Malinowski
121 	 * @short Signal emitted when message was sent.
122 	 * @param message sent message
123 	 *
124 	 * This signal is emited every time a message is sent trought one of registered acocunts.
125 	 */
126 	void messageSent(const Message &message);
127 
128 	/**
129 	 * @short Signal emitted when message is received.
130 	 * @param message received message
131 	 *
132 	 * This signal is emitted every message is received and not ignored.
133 	 */
134 	void messageReceived(const Message &message);
135 
136 private:
137 	QPointer<RawMessageTransformerService> m_rawMessageTransformerService;
138 
139 private slots:
140 	/**
141 	 * @short Set raw message transformer service for this service.
142 	 * @author Rafał 'Vogel' Malinowski
143 	 * @param rawMessageTransformerService raw message transformer service for this service
144 	 */
145 	INJEQT_SET void setRawMessageTransformerService(RawMessageTransformerService *rawMessageTransformerService);
146 
147 };
148 
149 /**
150  * @}
151  */
152