messagewebview.h 3.65 KB
Newer Older
1
/***************************************************************************
2
 * Copyright (C) 2019-2019 by Savoir-faire Linux                                *
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
 * Author: Andreas Traczyk <andreas.traczyk@savoirfairelinux.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 3 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, see <http://www.gnu.org/licenses/>.   *
 **************************************************************************/

#pragma once

#include <QDebug>
#include <QWebEngineView>

#include "api/conversationmodel.h"

class PrivateBridging : public QObject
{
    Q_OBJECT
public:
    explicit PrivateBridging(QObject* parent = nullptr) : QObject(parent) {};
    ~PrivateBridging() {};

    // exposed to JS through QWebChannel
    Q_INVOKABLE int deleteInteraction(const QString& arg);
    Q_INVOKABLE int retryInteraction(const QString& arg);
    Q_INVOKABLE int openFile(const QString& arg);
    Q_INVOKABLE int acceptFile(const QString& arg);
    Q_INVOKABLE int refuseFile(const QString& arg);
    Q_INVOKABLE int sendMessage(const QString & arg);
    Q_INVOKABLE int sendFile();
    Q_INVOKABLE int log(const QString& arg);
42 43 44
    Q_INVOKABLE int acceptInvitation();
    Q_INVOKABLE int refuseInvitation();
    Q_INVOKABLE int blockConversation();
Andreas Traczyk's avatar
Andreas Traczyk committed
45 46
    Q_INVOKABLE int emitMessagesCleared();
    Q_INVOKABLE int emitMessagesLoaded();
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
};

class MessageWebView : public QWebEngineView
{
    Q_OBJECT
public:
    explicit MessageWebView(QWidget* parent = nullptr);
    ~MessageWebView();

    void buildView();

    void insertStyleSheet(const QString &name, const QString &source);
    void removeStyleSheet(const QString &name);

    void clear();
    void setDisplayLinks(bool display);
    void printNewInteraction(lrc::api::ConversationModel& conversationModel,
                             uint64_t msgId,
                             const lrc::api::interaction::Info& interaction);
    void updateInteraction(lrc::api::ConversationModel& conversationModel,
                           uint64_t msgId,
                           const lrc::api::interaction::Info& interaction);
    void removeInteraction(uint64_t interactionId);
    void printHistory(lrc::api::ConversationModel& conversationModel,
                      const std::map<uint64_t,
Andreas Traczyk's avatar
Andreas Traczyk committed
72
                      lrc::api::interaction::Info> interactions);
73 74
    void setSenderImage(const std::string& sender,
                        const std::string& senderImage);
75 76 77
    void setInvitation(bool show,
                       const std::string& contactUri = "",
                       const std::string& contactId = "");
78 79
    void setMessagesVisibility(bool visible);

80 81
signals:
    void conversationRemoved();
82
    void messagesCleared();
Andreas Traczyk's avatar
Andreas Traczyk committed
83
    void messagesLoaded();
84

85 86 87 88 89 90 91 92
private slots:
    void slotLoadFinished();

private:
    QWebChannel* webChannel_;
    PrivateBridging* jsBridge_;

};