File indexing completed on 2024-04-21 04:56:45
0001 /** 0002 * SPDX-FileCopyrightText: 2013 Albert Vaca <albertvaka@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 #include "kdeconnectplugin.h" 0008 0009 #include "core_debug.h" 0010 0011 struct KdeConnectPluginPrivate { 0012 Device *m_device; 0013 QString m_pluginName; 0014 QSet<QString> m_outgoingCapabilties; 0015 KdeConnectPluginConfig *m_config = nullptr; 0016 QString iconName; 0017 }; 0018 0019 KdeConnectPlugin::KdeConnectPlugin(QObject *parent, const QVariantList &args) 0020 : QObject(parent) 0021 , d(new KdeConnectPluginPrivate) 0022 { 0023 Q_ASSERT(args.length() == 4); 0024 d->m_device = qvariant_cast<Device *>(args.at(0)); 0025 d->m_pluginName = args.at(1).toString(); 0026 0027 const QStringList cap = args.at(2).toStringList(); 0028 d->m_outgoingCapabilties = QSet(cap.begin(), cap.end()); 0029 d->iconName = args.at(3).toString(); 0030 } 0031 0032 KdeConnectPluginConfig *KdeConnectPlugin::config() const 0033 { 0034 // Create on demand, because not every plugin will use it 0035 if (!d->m_config) { 0036 d->m_config = new KdeConnectPluginConfig(d->m_device->id(), d->m_pluginName); 0037 } 0038 return d->m_config; 0039 } 0040 0041 KdeConnectPlugin::~KdeConnectPlugin() 0042 { 0043 delete d->m_config; 0044 } 0045 0046 const Device *KdeConnectPlugin::device() 0047 { 0048 return d->m_device; 0049 } 0050 0051 Device const *KdeConnectPlugin::device() const 0052 { 0053 return d->m_device; 0054 } 0055 0056 bool KdeConnectPlugin::sendPacket(NetworkPacket &np) const 0057 { 0058 if (!d->m_outgoingCapabilties.contains(np.type())) { 0059 qCWarning(KDECONNECT_CORE) << metaObject()->className() << "tried to send an unsupported packet type" << np.type() 0060 << ". Supported:" << d->m_outgoingCapabilties; 0061 return false; 0062 } 0063 // qCWarning(KDECONNECT_CORE) << metaObject()->className() << "sends" << np.type() << ". Supported:" << d->mOutgoingTypes; 0064 return d->m_device->sendPacket(np); 0065 } 0066 0067 QString KdeConnectPlugin::dbusPath() const 0068 { 0069 return {}; 0070 } 0071 0072 void KdeConnectPlugin::receivePacket(const NetworkPacket &np) 0073 { 0074 qCWarning(KDECONNECT_CORE) << metaObject()->className() << "received a packet of type" << np.type() << "but doesn't implement receivePacket"; 0075 } 0076 QString KdeConnectPlugin::iconName() const 0077 { 0078 return d->iconName; 0079 } 0080 0081 #include "moc_kdeconnectplugin.cpp"