1 /*************************************************************************** 2 * Copyright (C) 2010 by David Edmundson <kde@davidedmundson.co.uk> * 3 * * 4 * This program is free software; you can redistribute it and/or modify * 5 * it under the terms of the GNU General Public License as published by * 6 * the Free Software Foundation; either version 2 of the License, or * 7 * (at your option) any later version. * 8 * * 9 * This program is distributed in the hope that it will be useful, * 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 12 * GNU General Public License for more details. * 13 * * 14 * You should have received a copy of the GNU General Public License * 15 * along with this program; if not, write to the * 16 * Free Software Foundation, Inc., * 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * 18 ***************************************************************************/ 19 20 #ifndef ADIUMTHEMEVIEW_H 21 #define ADIUMTHEMEVIEW_H 22 23 #include <QWebEngineView> 24 25 #include "adium-theme-header-info.h" 26 #include "adium-theme-content-info.h" 27 28 #include <KEmoticons> 29 30 #include <KTp/message.h> 31 32 #include "ktpchat_export.h" 33 34 class AdiumThemeContentInfo; 35 class AdiumThemeHeaderInfo; 36 class AdiumThemeStatusInfo; 37 class ChatWindowStyle; 38 class ChatWidget; 39 40 class QContextMenuEvent; 41 42 class QAction; 43 44 class KDE_TELEPATHY_CHAT_EXPORT AdiumThemePage : public QWebEnginePage 45 { 46 Q_OBJECT 47 public: 48 AdiumThemePage(QObject *parent = 0); 49 50 protected: 51 virtual bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType navigationType, bool isMainFrame); 52 53 Q_SIGNALS: 54 void nextConversation(); 55 void prevConversation(); 56 }; 57 58 class KDE_TELEPATHY_CHAT_EXPORT AdiumThemeView : public QWebEngineView 59 { 60 Q_OBJECT 61 friend class ChatWidget; 62 public: 63 64 enum ChatType { 65 GroupChat, 66 SingleUserChat 67 }; 68 69 enum AppendMode { 70 AppendModeError = 0, 71 AppendMessageWithScroll, 72 AppendNextMessageWithScroll, 73 AppendMessage, 74 AppendNextMessage, 75 AppendMessageNoScroll, 76 AppendNextMessageNoScroll, 77 ReplaceLastMessage 78 }; 79 80 explicit AdiumThemeView(QWidget *parent = 0); 81 82 /** Loads the Theme data*/ 83 void load(ChatType chatType); 84 85 /** Starts populating the HTML into the view*/ 86 void initialise(const AdiumThemeHeaderInfo&); 87 88 const QString variantPath() const; 89 const QString variantName() const; 90 void setVariant(const QString& variant); 91 ChatWindowStyle* chatStyle() const; 92 93 /** Set the theme to use. Display will only change once initialise() is called.*/ 94 void setChatStyle(ChatWindowStyle *chatStyle); 95 void setUseCustomFont(bool); 96 QString fontFamily(); 97 int fontSize(); 98 void setFontFamily(QString fontFamily); 99 void setFontSize(int fontSize); 100 bool isCustomFont() const; 101 bool isHeaderDisplayed() const; 102 /** Set whether a header is displayed at the top of the window. 103 * Output will only change once initialise() is called. */ 104 void setHeaderDisplayed(bool); 105 /* .. font, backgrounds, everything else.*/ 106 107 void setShowPresenceChanges(bool showPresenceChanges); 108 bool showPresenceChanges() const; 109 void setShowJoinLeaveChanges(bool showJoinLeaveChanges); 110 bool showJoinLeaveChanges() const; 111 112 void clear(); 113 114 public Q_SLOTS: 115 void addMessage(const KTp::Message &message); 116 void addStatusMessage(const QString &text, 117 const QString &sender=QString(), 118 const QDateTime &time=QDateTime::currentDateTime()); 119 120 void addAdiumContentMessage(const AdiumThemeContentInfo&); 121 void addAdiumStatusMessage(const AdiumThemeStatusInfo&); 122 void viewLoadFinished(bool ok); 123 124 protected: 125 virtual void contextMenuEvent(QContextMenuEvent *event); 126 virtual void wheelEvent(QWheelEvent *event); 127 virtual void mouseReleaseEvent(QMouseEvent *event); 128 129 Q_SIGNALS: 130 void zoomFactorChanged(qreal zoomFactor); 131 void textPasted(); 132 void viewReady(); 133 134 private: 135 ChatWindowStyle *m_chatStyle; 136 QString m_variantPath; 137 QString m_variantName; 138 bool m_useCustomFont; 139 QString m_fontFamily; 140 int m_fontSize; 141 bool m_showPresenceChanges; 142 bool m_showJoinLeaveChanges; 143 144 QString appendScript(AppendMode mode); 145 AppendMode appendMode(const AdiumThemeMessageInfo &message, 146 bool consecutive, 147 bool willAddMoreContentObjects, 148 bool replaceLastContent); 149 void appendMessage(QString &htmlMessage, const QString &script, AppendMode mode); 150 151 QString replaceHeaderKeywords(QString htmlTemplate, const AdiumThemeHeaderInfo&); 152 QString replaceContentKeywords(QString& htmlTemplate, const AdiumThemeContentInfo&); 153 QString replaceStatusKeywords(QString& htmlTemplate, const AdiumThemeStatusInfo&); 154 QString replaceMessageKeywords(QString& htmlTemplate, const AdiumThemeMessageInfo&); 155 156 QString formatTime(const QString&, const QDateTime&); 157 158 QString m_defaultAvatar; 159 AdiumThemeContentInfo m_lastContent; 160 bool m_displayHeader; 161 162 QString m_service; 163 QString m_serviceIconPath; 164 }; 165 166 #endif // ADIUMTHEMEVIEW_H 167 168 169