Initial commit
[tietoopcom] / include / TocUi / tocchatwidget.h
1 /** \file TocChatWidget.h
2  * \brief Declaration of TocChatWidget class
3  * 
4  * Tieto Open Communicator - Client for the Telepathy communications framework.
5  * Copyright (c) 2010, Tieto Corporation
6  *
7  * All rights reserved.
8  * Redistribution and use in source and binary forms, with or without modification,
9  * are permitted provided that the following conditions are met:
10  *
11  *      Redistributions of source code must retain the above copyright notice,
12  *      this list of conditions and the following disclaimer.
13  *      Redistributions in binary form must reproduce the above copyright notice,
14  *      this list of conditions and the following disclaimer in the documentation
15  *      and/or other materials provided with the distribution.
16  *      Neither the name of the Tieto Corporation nor the names of its contributors 
17  *      may be used to endorse or promote products derived from this software without
18  *      specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23  * IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  * 
30  */
31
32 #ifndef TOCCHATWIDGET_H
33 #define TOCCHATWIDGET_H
34
35 #include <QWidget>
36
37 #include "defs.h"
38
39 class Ui_TocChatWidgetClass;
40
41 QT_BEGIN_NAMESPACE
42
43 /** \brief TocChatWidget class
44  * 
45  * Widget used as a conversation window. Enables sending of messages
46  * and notifies about presence changes of the contact by textual information
47  * and conversion window border color.
48  */
49 class TocChatWidget : public QWidget
50 {
51         Q_OBJECT
52
53 public:
54         
55         /**
56          * Public Constructor
57          */
58         TocChatWidget( const QString& uid, const QString& name, Presence presence, QWidget * parent = 0, const Message& message = Message() );
59
60         /**
61          * Destructor
62          */
63         ~TocChatWidget();
64         
65         /** \brief Used to read uid property
66          * 
67          * @return ID of the Contact for which the chat was created   
68          */
69         QString uid() const { return _uid; }
70         
71         /** \brief Used to read name property
72          * 
73          * @return Name of the Contact for which the chat was created   
74          */
75         QString name() const { return _name; }
76         
77         /** \brief Used to set name property
78          * 
79          * @param New name of the Contact   
80          */
81         void onDisplayedNameChange(const QString& newName) { _name = newName; }
82         
83         /** \brief Used to handle contact's presence change
84          * 
85          * This method is used when status of the Contact has changed.
86          * It gives textual and graphical notification to the user.
87          * 
88          * @param presence New contact's presence
89          * @param description New contact's presence description
90          */
91         void onContactPresenceUpdate(Presence presence, const QString& description);
92
93         /** \brief Used to update contact's presence
94          * 
95          * This is used when the chat window was closed and did not
96          * recieved Contact Presence Updates, so it can show the current status properly.
97          */
98         void updateContactPresence(Presence presence);
99         
100         /** \brief Used to handle incoming message
101          * 
102          * @param message Message to be displayed in chat
103          */
104         void appendMessage(const Message& message);
105         
106 protected:
107         
108         /** \brief Used to filter incoming events
109          * 
110          * This method is used to filter keyboards event. 
111          * If Enter key is pressed, typed message is send (as pressing Send button).
112          * If Enter key is pressed with Shift key modifier new line in entered.
113          * 
114          * @param *object Pointer to the object on which an event appears.
115          * @param *event Pointer to the event.
116          * 
117          * @return If the event is a key event Enter without Shift modifier 
118          * method returns true, otherwise false.
119          *  
120          */     
121         bool eventFilter(QObject *object, QEvent *event);
122
123         /** \brief Reimplemented from QWidget
124          * 
125          */
126         virtual void showEvent(QShowEvent* event);
127
128 signals:
129
130         /** \brief Emited when new message is ready to be sent
131          *
132          * This signal is emited when user want's to send a prepared message.
133          * 
134          * @param uid Contact's ID
135          * @param message Message to be sent
136          */ 
137         void newMessageReady(const QString& uid, Message message);
138
139         /** \brief Emited Smile button clicked.
140          *
141          * This signal is emited when user clicks on Smile button in Chat view,
142          * to choose emoticon.
143          * 
144          */
145         void smileButtonClicked();
146
147 private slots:
148
149         /** \brief Send message slot
150         *
151         * Invoked when message from chatWidget needs to be sent.
152         * It composes a message, emits a signal and wipes out a text from messageTextEdit.  
153         * 
154         */
155         void pressedSendButton();
156         /** \brief Shows emoticons dialog window.
157         *
158         */      
159         void showEmoticonsDialog();
160         
161
162 private: // Methods
163
164         /** \brief Returns a human readable string for the given error type
165          * 
166          * @param error Error id
167          * @return Human readable error description
168          */
169         QString errorString(MessageDeliveryError error);
170
171         /** \brief Appends new message to the chat dialog edit with parsed emoticons
172          * 
173          */
174         /** \brief Inserts emoticons.
175          * 
176          * Checks user message text for emoticons aliases and replace them with 
177          * corresponding inage. 
178          *  
179          * @param message Message from user message text edit box.
180          * 
181          */     
182         void insertEmoticons(const QString& message);
183
184 private: // Members
185         
186         QString _uid;                           /// User ID.
187         QString _name;                          /// User name.
188         
189         Ui_TocChatWidgetClass* ui;      /// Pointer to the TocChatWidgetClass form.
190 };
191
192 QT_END_NAMESPACE
193
194 #endif // TOCCHATWIDGET_H