Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2018 by Savoir-faire Linux * |
| 3 | * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.com> * |
| 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 3 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
| 17 | **************************************************************************/ |
| 18 | |
| 19 | #pragma once |
| 20 | |
| 21 | #include <QDebug> |
| 22 | #include <QWebEngineView> |
| 23 | |
| 24 | #include "api/conversationmodel.h" |
| 25 | |
| 26 | class PrivateBridging : public QObject |
| 27 | { |
| 28 | Q_OBJECT |
| 29 | public: |
| 30 | explicit PrivateBridging(QObject* parent = nullptr) : QObject(parent) {}; |
| 31 | ~PrivateBridging() {}; |
| 32 | |
| 33 | // exposed to JS through QWebChannel |
| 34 | Q_INVOKABLE int deleteInteraction(const QString& arg); |
| 35 | Q_INVOKABLE int retryInteraction(const QString& arg); |
| 36 | Q_INVOKABLE int openFile(const QString& arg); |
| 37 | Q_INVOKABLE int acceptFile(const QString& arg); |
| 38 | Q_INVOKABLE int refuseFile(const QString& arg); |
| 39 | Q_INVOKABLE int sendMessage(const QString & arg); |
| 40 | Q_INVOKABLE int sendFile(); |
| 41 | Q_INVOKABLE int log(const QString& arg); |
Sébastien Blin | 942d102 | 2018-12-13 09:49:03 -0500 | [diff] [blame] | 42 | Q_INVOKABLE int acceptInvitation(); |
| 43 | Q_INVOKABLE int refuseInvitation(); |
| 44 | Q_INVOKABLE int blockConversation(); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 45 | }; |
| 46 | |
| 47 | class MessageWebView : public QWebEngineView |
| 48 | { |
| 49 | Q_OBJECT |
| 50 | public: |
| 51 | explicit MessageWebView(QWidget* parent = nullptr); |
| 52 | ~MessageWebView(); |
| 53 | |
| 54 | void buildView(); |
| 55 | |
| 56 | void insertStyleSheet(const QString &name, const QString &source); |
| 57 | void removeStyleSheet(const QString &name); |
| 58 | |
| 59 | void clear(); |
| 60 | void setDisplayLinks(bool display); |
| 61 | void printNewInteraction(lrc::api::ConversationModel& conversationModel, |
| 62 | uint64_t msgId, |
| 63 | const lrc::api::interaction::Info& interaction); |
| 64 | void updateInteraction(lrc::api::ConversationModel& conversationModel, |
| 65 | uint64_t msgId, |
| 66 | const lrc::api::interaction::Info& interaction); |
| 67 | void removeInteraction(uint64_t interactionId); |
| 68 | void printHistory(lrc::api::ConversationModel& conversationModel, |
| 69 | const std::map<uint64_t, |
| 70 | lrc::api::interaction::Info> interactions); |
| 71 | void setSenderImage(const std::string& sender, |
| 72 | const std::string& senderImage); |
Sébastien Blin | 942d102 | 2018-12-13 09:49:03 -0500 | [diff] [blame] | 73 | void setInvitation(bool show, const std::string& contactUri, const std::string& contactId); |
Andreas Traczyk | 43c0823 | 2018-10-31 13:42:09 -0400 | [diff] [blame] | 74 | void hideMessages(); |
| 75 | |
| 76 | private slots: |
| 77 | void slotLoadFinished(); |
| 78 | |
| 79 | private: |
| 80 | QWebChannel* webChannel_; |
| 81 | PrivateBridging* jsBridge_; |
| 82 | |
| 83 | }; |