1 /* 2 * %kadu copyright begin% 3 * Copyright 2012, 2014 Bartosz Brachaczek (b.brachaczek@gmail.com) 4 * Copyright 2012, 2013, 2014 Rafał Przemysław Malinowski (rafal.przemyslaw.malinowski@gmail.com) 5 * %kadu copyright end% 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License as 9 * published by the Free Software Foundation; either version 2 of 10 * the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #pragma once 22 23 #include <QtCore/QFutureWatcher> 24 #include <QtCore/QPointer> 25 #include <QtWidgets/QWidget> 26 #include <injeqt/injeqt.h> 27 28 #include "misc/memory.h" 29 30 class QDate; 31 class QSplitter; 32 class QTreeView; 33 34 class FormattedStringFactory; 35 class HistoryQueryResult; 36 class HistoryQueryResultsModel; 37 class HistoryQueryResultsProxyModel; 38 class PluginInjectedFactory; 39 class MessageManager; 40 class Message; 41 class SearchBar; 42 class SortedMessages; 43 class WaitOverlay; 44 class WebkitMessagesViewFactory; 45 class WebkitMessagesView; 46 class WebViewHighlighter; 47 48 /** 49 * @addtogroup History 50 * @{ 51 */ 52 53 /** 54 * @class TimelineChatMessagesView 55 * @author Rafał 'Vogel' Malinowski 56 * @short Widget that provides chat message view with timeline. 57 * 58 * This widgets mixes list of dates with chat message view in vertical layout. It is used in history window. 59 * Search bar is attached to message view and can be invoked by Ctrl+F shortcut. 60 */ 61 class TimelineChatMessagesView : public QWidget 62 { 63 Q_OBJECT 64 65 QPointer<FormattedStringFactory> m_formattedStringFactory; 66 QPointer<PluginInjectedFactory> m_pluginInjectedFactory; 67 QPointer<WebkitMessagesViewFactory> m_webkitMessagesViewFactory; 68 69 WaitOverlay *TimelineWaitOverlay; 70 WaitOverlay *MessagesViewWaitOverlay; 71 72 QSplitter *Splitter; 73 QTreeView *Timeline; 74 HistoryQueryResultsModel *ResultsModel; 75 HistoryQueryResultsProxyModel *ResultsProxyModel; 76 WebViewHighlighter *Highlighter; 77 owned_qptr<WebkitMessagesView> MessagesView; 78 SearchBar *MessagesSearchBar; 79 80 QFutureWatcher<QVector<HistoryQueryResult> > *ResultsFutureWatcher; 81 QFutureWatcher<SortedMessages> *MessagesFutureWatcher; 82 83 void createGui(); 84 85 private slots: 86 INJEQT_SET void setFormattedStringFactory(FormattedStringFactory *formattedStringFactory); 87 INJEQT_SET void setPluginInjectedFactory(PluginInjectedFactory *pluginInjectedFactory); 88 INJEQT_SET void setMessageManager(MessageManager *messageManager); 89 INJEQT_SET void setWebkitMessagesViewFactory(WebkitMessagesViewFactory *webkitMessagesViewFactory); 90 INJEQT_INIT void init(); 91 92 void futureResultsAvailable(); 93 void futureResultsCanceled(); 94 95 void futureMessagesAvailable(); 96 void futureMessagesCanceled(); 97 98 void newMessage(const Message &message); 99 100 public: 101 /** 102 * @author Rafał 'Vogel' Malinowski 103 * @short Creates new TimelineChatMessagesView. 104 * @param parent parent widget 105 */ 106 explicit TimelineChatMessagesView(QWidget *parent = nullptr); 107 virtual ~TimelineChatMessagesView(); 108 109 /** 110 * @author Rafał 'Vogel' Malinowski 111 * @short Returns timeline widget. 112 * @return timeline widget 113 * 114 * Timeline widget is simple QTreeView with grid display of dates with messages count and 115 * optional title for each item. 116 */ timeline()117 QTreeView * timeline() const { return Timeline; } 118 119 /** 120 * @author Rafał 'Vogel' Malinowski 121 * @short Returns chat messages view widget. 122 * @return chat messages view widget 123 */ messagesView()124 WebkitMessagesView * messagesView() const { return MessagesView.get(); } 125 126 /** 127 * @author Rafał 'Vogel' Malinowski 128 * @short Returns highlighter for chat messages view widget. 129 * @return highlighter for chat messages view widget 130 */ highlighter()131 WebViewHighlighter * highlighter() const { return Highlighter; } 132 133 /** 134 * @author Rafał 'Vogel' Malinowski 135 * @short Returns chat messages view search bar widget. 136 * @return chat messages view search bar widget 137 */ searchBar()138 SearchBar * searchBar() const { return MessagesSearchBar; } 139 140 /** 141 * @author Rafał 'Vogel' Malinowski 142 * @short Returns currently selected date on timeline. 143 * @return currently selected date on timeline 144 * 145 * If no data is seleted then returned value is invalid. 146 */ 147 QDate currentDate() const; 148 149 /** 150 * @author Rafał 'Vogel' Malinowski 151 * @short Sets list of dates to display in timeline. 152 * @param dates dates to display in timeline 153 * 154 * This methods sets list of dates to display in timeline. If list is not empty, 155 * last date is selected and displayForDate() is called with that date. IF not, 156 * displayForDate() is called with invalid date to ensure that view is cleared. 157 */ 158 void setResults(const QVector<HistoryQueryResult> &results); 159 160 /** 161 * @author Rafał 'Vogel' Malinowski 162 * @short Sets future list of dates to display in timeline. 163 * @param futureDates future dates to display in timeline 164 * 165 * This methods sets list of future dates to display in timeline. Timeline view will 166 * be blocked by WaitOverlay until dates are available. If received list will be not empty 167 * last date will be selected and displayForDate() will be called with that date. 168 * If received list will be empty, displayForDate() will be called with invalid date to ensure 169 * that view is cleared. 170 */ 171 void setFutureResults(const QFuture<QVector<HistoryQueryResult>> &futureResults); 172 173 /** 174 * @author Rafał 'Vogel' Malinowski 175 * @short Sets messages to display in message view widget. 176 * @param messages future messages of dates to display in message view widget 177 * 178 * This methods sets list of messages to display in message view widget. 179 */ 180 void setMessages(const SortedMessages &messages); 181 182 /** 183 * @author Rafał 'Vogel' Malinowski 184 * @short Sets future messages to display in message view widget. 185 * @param futureMessages future messages of dates to display in message view widget 186 * 187 * This methods sets list of future messages to display in message view widget. This widget will 188 * be blocked by WaitOverlay until messages are available. 189 */ 190 void setFutureMessages(const QFuture<SortedMessages> &futureMessages); 191 192 /** 193 * @author Rafał 'Vogel' Malinowski 194 * @short Show wait overlay over timeline widget. 195 */ 196 void showTimelineWaitOverlay(); 197 198 /** 199 * @author Rafał 'Vogel' Malinowski 200 * @short Hide wait overlay over timeline widget. 201 */ 202 void hideTimelineWaitOverlay(); 203 204 /** 205 * @author Rafał 'Vogel' Malinowski 206 * @short Show wait overlay over messages view widget. 207 */ 208 void showMessagesViewWaitOverlay(); 209 210 /** 211 * @author Rafał 'Vogel' Malinowski 212 * @short Hide wait overlay over messages view widget. 213 */ 214 void hideMessagesViewWaitOverlay(); 215 216 /** 217 * @author Rafał 'Vogel' Malinowski 218 * @short Decide if talkable name should be displayed in timeline widget. 219 * @param talkableVisible set to true if talkable name should be displayed in timeline widget 220 */ 221 void setTalkableVisible(const bool talkableVisible); 222 223 /** 224 * @author Rafał 'Vogel' Malinowski 225 * @short Decide if title should be displayed in timeline widget. 226 * @param titleVisible set to true if title should be displayed in timeline widget 227 */ 228 void setTitleVisible(const bool titleVisible); 229 230 /** 231 * @author Rafał 'Vogel' Malinowski 232 * @short Set header to talkable column. 233 * @param talkableHeader header for talkable column 234 */ 235 void setTalkableHeader(const QString &talkableHeader); 236 237 /** 238 * @author Rafał 'Vogel' Malinowski 239 * @short Set header to length column. 240 * @param lengthHeader header for length column 241 */ 242 void setLengthHeader(const QString &lengthHeader); 243 244 /** 245 * @author Rafał 'Vogel' Malinowski 246 * @short Returns heights of timeline and message view widgets. 247 * @return heights of timeline and message view widgets 248 * 249 * First value in list contains height of timeline widget. Second one contains height 250 * of chat message view widget. This method always returns list of size 2. 251 */ 252 QList<int> sizes() const; 253 254 /** 255 * @author Rafał 'Vogel' Malinowski 256 * @short Sets heights of timeline and message view widgets. 257 * @param newSizes new heights of timeline and message view widgets 258 * 259 * First value in list contains new height of timeline widget. Second one contains new height 260 * of chat message view widget. If size of parameter is different that 2 assertion is thrown. 261 */ 262 void setSizes(const QList<int> &newSizes); 263 264 signals: 265 /** 266 * @author Rafał 'Vogel' Malinowski 267 * @short Signal emited when selected date changes. 268 */ 269 void currentDateChanged(); 270 271 /** 272 * @author Rafał 'Vogel' Malinowski 273 * @short Signal emited when all messages are displayed. 274 */ 275 void messagesDisplayed(); 276 277 }; 278 279 /** 280 * @} 281 */ 282