File indexing completed on 2024-04-28 16:51:32
0001 /* 0002 SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de> 0003 SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org> 0004 0005 SPDX-License-Identifier: MIT 0006 */ 0007 0008 #include "abstractbrowserplugin.h" 0009 #include "connection.h" 0010 #include "settings.h" 0011 0012 AbstractBrowserPlugin::AbstractBrowserPlugin::AbstractBrowserPlugin(const QString &subsystemId, int protocolVersion, QObject *parent) 0013 : QObject(parent) 0014 , m_subsystem(subsystemId) 0015 , m_protocolVersion(protocolVersion) 0016 { 0017 } 0018 0019 void AbstractBrowserPlugin::handleData(const QString &event, const QJsonObject &data) 0020 { 0021 Q_UNUSED(event); 0022 Q_UNUSED(data); 0023 } 0024 0025 QJsonObject AbstractBrowserPlugin::handleData(int serial, const QString &event, const QJsonObject &data) 0026 { 0027 Q_UNUSED(serial); 0028 Q_UNUSED(event); 0029 Q_UNUSED(data); 0030 return QJsonObject(); 0031 } 0032 0033 void AbstractBrowserPlugin::sendData(const QString &action, const QJsonObject &payload) 0034 { 0035 QJsonObject data; 0036 data[QStringLiteral("subsystem")] = m_subsystem; 0037 data[QStringLiteral("action")] = action; 0038 if (!payload.isEmpty()) { 0039 data[QStringLiteral("payload")] = payload; 0040 } 0041 Connection::self()->sendData(data); 0042 } 0043 0044 void AbstractBrowserPlugin::sendReply(int requestSerial, const QJsonObject &payload) 0045 { 0046 QJsonObject data{ 0047 {QStringLiteral("replyToSerial"), requestSerial}, 0048 }; 0049 0050 if (!payload.isEmpty()) { 0051 data.insert(QStringLiteral("payload"), payload); 0052 } 0053 0054 Connection::self()->sendData(data); 0055 } 0056 0057 bool AbstractBrowserPlugin::onLoad() 0058 { 0059 return true; 0060 } 0061 0062 bool AbstractBrowserPlugin::onUnload() 0063 { 0064 return true; 0065 } 0066 0067 void AbstractBrowserPlugin::onSettingsChanged(const QJsonObject &newSettings) 0068 { 0069 Q_UNUSED(newSettings); 0070 } 0071 0072 QJsonObject AbstractBrowserPlugin::status() const 0073 { 0074 return {}; 0075 } 0076 0077 QDebug AbstractBrowserPlugin::debug() const 0078 { 0079 auto d = qDebug(); 0080 QDebugStateSaver saver(d); 0081 d.nospace().noquote() << m_subsystem << ":"; 0082 return d; 0083 } 0084 0085 QString AbstractBrowserPlugin::subsystem() const 0086 { 0087 return m_subsystem; 0088 } 0089 0090 int AbstractBrowserPlugin::protocolVersion() const 0091 { 0092 return m_protocolVersion; 0093 } 0094 0095 bool AbstractBrowserPlugin::isLoaded() const 0096 { 0097 return m_loaded; 0098 } 0099 0100 void AbstractBrowserPlugin::setLoaded(bool loaded) 0101 { 0102 m_loaded = loaded; 0103 } 0104 0105 QJsonObject AbstractBrowserPlugin::settings() const 0106 { 0107 return Settings::self().settingsForPlugin(m_subsystem); 0108 }