File: chat-widget.h

package info (click to toggle)
ktp-text-ui 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,680 kB
  • ctags: 1,142
  • sloc: cpp: 9,451; sh: 15; makefile: 9
file content (213 lines) | stat: -rw-r--r-- 7,402 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/***************************************************************************
 *   Copyright (C) 2010 by David Edmundson <kde@davidedmundson.co.uk>      *
 *   Copyright (C) 2011 by Francesco Nwokeka <francesco.nwokeka@gmail.com> *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
 ***************************************************************************/

#ifndef CHATWIDGET_H
#define CHATWIDGET_H

#include "ktpchat_export.h"

#include <QtCore/QString>
#include <QtGui/QWidget>
#include <QtWebKit/QWebPage>

#include <KIcon>
#include <KColorScheme>
#include <KShortcut>

#include <TelepathyQt/ReceivedMessage>

#include <KTp/presence.h>
#include <KTp/message.h>

class ChatSearchBar;
class ChatWidgetPrivate;
class QShowEvent;
class QKeyEvent;

class KDE_TELEPATHY_CHAT_EXPORT ChatWidget : public QWidget
{
    Q_OBJECT

public:
    explicit ChatWidget(const Tp::TextChannelPtr &channel, const Tp::AccountPtr &account, QWidget *parent = 0);
    virtual ~ChatWidget();

    /** Returns pointer to account used for chat */
    Tp::AccountPtr account() const;

    /** Returns a pointer to the Chatwidget's search bar */
    ChatSearchBar* chatSearchBar() const;

    /** Returns the icon of this chat window */
    KIcon icon() const;

    /** Returns the icon for the account used in this chat window */
    KIcon accountIcon() const;

    /** returns whether the chat is considered a group chat */
    bool isGroupChat() const;

    /** invalidates the use of the chat.
     * @param enable flag to validate/invalidate chatWidget
     */
    void setChatEnabled(bool enable);

    /** Sets textchannel to given one */
    void setTextChannel(const Tp::TextChannelPtr &newTextChannelPtr);

    /** Returns the text channel pointer of the chatWidget */
    Tp::TextChannelPtr textChannel() const;

    /** Returns the name of this chat window */
    QString title() const;

    /** Returns the suggested color for the title of the window */
    QColor titleColor() const;

    int unreadMessageCount() const;

    QString spellDictionary() const;

    void setSpellDictionary(const QString &dict);

    void addEmoticonToChat(const QString &emoticon);

    /** Returns the chat state of remote contact */
    Tp::ChannelChatState remoteChatState();

    bool previousConversationAvailable();

    void clear();

    qreal zoomFactor() const;

    void setZoomFactor(qreal zoomFactor);

    /** Is this widget visible and in the active window */
    virtual bool isOnTop() const;

public Q_SLOTS:
    /** toggle the search bar visibility */
    void toggleSearchBar() const;

    /** Mark that the following messages have been seen by the user.
      */
    void acknowledgeMessages();

    void updateSendMessageShortcuts(const KShortcut &shortcuts);

    void reloadTheme();

protected:
    void changeEvent(QEvent *e);
    void resizeEvent(QResizeEvent *);
    void keyPressEvent(QKeyEvent *e);
    virtual void dropEvent(QDropEvent *e);
    virtual void dragEnterEvent(QDragEnterEvent *e);

protected Q_SLOTS:
    /** Show the received message in the chat window*/
    void handleIncomingMessage(const Tp::ReceivedMessage &message, bool alreadyNotified = false);

    /** Show the message sent in the chat window*/
    void handleMessageSent(const Tp::Message &message,
                           Tp::MessageSendingFlags flags,
                           const QString &sentMessageToken);

    /** send the text in the text area widget to the client handler*/
    void sendMessage();

    void onChatStatusChanged(const Tp::ContactPtr &contact, Tp::ChannelChatState state);

    void onContactBlockStatusChanged(const Tp::ContactPtr &contact, bool blocked);

    void onContactPresenceChange(const Tp::ContactPtr &contact, const KTp::Presence &presence);

    void onContactAliasChanged(const Tp::ContactPtr &contact, const QString &alias);

    void onChannelInvalidated();

    void onInputBoxChanged();

    void chatViewReady();

Q_SIGNALS:
    /** Emitted whenever the title for the chat changes, normally the name of the contact or a topic*/
    void titleChanged(const QString &title);

    /** Emmitted if the icon for this channel changes*/
    void iconChanged(const KIcon &icon);

    /** Emmited whenever a message is received in this channel. It is up to the parent application to acknowledge these messages*/
    void messageReceived(const Tp::ReceivedMessage &message);

    /** emitted when searching for text */
    void searchTextComplete(bool found);

    /** Emitted when another contact in the channel starts/stops typing (if supported by the protocol)*/
    void userTypingChanged(Tp::ChannelChatState);

    /** Emitted when a contact is blocked or unblocked */
    void contactBlockStatusChanged(bool blocked);

    void contactPresenceChanged(KTp::Presence presence);

    void unreadMessagesChanged();

    /** Emitted when a notification for the chat window has been activated*/
    void notificationClicked();

    /** Emitted when zoom level in chat view changes */
    void zoomFactorChanged(qreal zoomFactor);

private Q_SLOTS:
    /** received when user changes search criteria or when searching for text */
    void findTextInChat(const QString &text, QWebPage::FindFlags flags);
    void findNextTextInChat(const QString &text, QWebPage::FindFlags flags);
    void findPreviousTextInChat(const QString &text, QWebPage::FindFlags flags);
    void onHistoryFetched(const QList<KTp::Message> &messages);
    void onChatPausedTimerExpired();
    void currentPresenceChanged(const Tp::Presence &presence);

    void temporaryFileTransferChannelCreated(Tp::PendingOperation *operation);
    void temporaryFileTransferStateChanged(Tp::FileTransferState, Tp::FileTransferStateChangeReason);

private:
    /** connects necessary signals for the channel */
    void setupChannelSignals();

    /** connects necessary signals for the contactModel */
    void setupContactModelSignals();

    /** Saves pair <target Id,language option selected> in a file */
    void saveSpellCheckingOption();

    /** Loads language option for specified target Id */
    void loadSpellCheckingOption();

    /** Loads theme into the the AdiumThemeView */
    void initChatArea();

    bool m_previousConversationAvailable;

    ChatWidgetPrivate * const d;
};

#endif // CHATWIDGET_H