diff --git a/plugins/battery/batteryplugin.cpp b/plugins/battery/batteryplugin.cpp index 12bd38bc4..587b920e4 100644 --- a/plugins/battery/batteryplugin.cpp +++ b/plugins/battery/batteryplugin.cpp @@ -19,31 +19,12 @@ K_PLUGIN_CLASS_WITH_JSON(BatteryPlugin, "kdeconnect_battery.json") +const auto batteryDevice = Solid::DeviceInterface::Type::Battery; +const auto primary = Solid::Battery::BatteryType::PrimaryBattery; + BatteryPlugin::BatteryPlugin(QObject *parent, const QVariantList &args) : KdeConnectPlugin(parent, args) { -} - -int BatteryPlugin::charge() const -{ - return m_charge; -} - -bool BatteryPlugin::isCharging() const -{ - return m_isCharging; -} - -void BatteryPlugin::connected() -{ - // We've just connected. Request battery information from the remote device... - NetworkPacket np(PACKET_TYPE_BATTERY_REQUEST, {{QStringLiteral("request"), true}}); - sendPacket(np); - - // ...and then figure out whether we have any batteries - const auto batteryDevice = Solid::DeviceInterface::Type::Battery; - const auto primary = Solid::Battery::BatteryType::PrimaryBattery; - QList batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary)); if (batteries.isEmpty()) { @@ -59,7 +40,20 @@ void BatteryPlugin::connected() connect(chosen, &Solid::Battery::chargeStateChanged, this, &BatteryPlugin::slotChargeChanged); connect(chosen, &Solid::Battery::chargePercentChanged, this, &BatteryPlugin::slotChargeChanged); +} +int BatteryPlugin::charge() const +{ + return m_charge; +} + +bool BatteryPlugin::isCharging() const +{ + return m_isCharging; +} + +void BatteryPlugin::connected() +{ // Explicitly send the current charge slotChargeChanged(); } @@ -73,9 +67,6 @@ void BatteryPlugin::slotChargeChanged() int batteryQuantity = 0; int cumulativeCharge = 0; - const auto batteryDevice = Solid::DeviceInterface::Type::Battery; - const auto primary = Solid::Battery::BatteryType::PrimaryBattery; - QList batteries = Solid::Device::listFromQuery(Solid::Predicate(batteryDevice, QStringLiteral("type"), primary)); for (auto device : batteries) { @@ -117,6 +108,10 @@ void BatteryPlugin::slotChargeChanged() bool BatteryPlugin::receivePacket(const NetworkPacket &np) { + if (PACKET_TYPE_BATTERY != np.type()) { + return false; + } + m_isCharging = np.get(QStringLiteral("isCharging"), false); m_charge = np.get(QStringLiteral("currentCharge"), -1); const int thresholdEvent = np.get(QStringLiteral("thresholdEvent"), (int)ThresholdNone); diff --git a/plugins/battery/batteryplugin.h b/plugins/battery/batteryplugin.h index 969608799..728cdd833 100644 --- a/plugins/battery/batteryplugin.h +++ b/plugins/battery/batteryplugin.h @@ -10,7 +10,6 @@ #include #define PACKET_TYPE_BATTERY QStringLiteral("kdeconnect.battery") -#define PACKET_TYPE_BATTERY_REQUEST QStringLiteral("kdeconnect.battery.request") class BatteryPlugin : public KdeConnectPlugin { diff --git a/plugins/battery/kdeconnect_battery.json b/plugins/battery/kdeconnect_battery.json index bb44edd10..fedc6f6dc 100644 --- a/plugins/battery/kdeconnect_battery.json +++ b/plugins/battery/kdeconnect_battery.json @@ -134,11 +134,9 @@ "Website": "https://albertvaka.wordpress.com" }, "X-KdeConnect-OutgoingPacketType": [ - "kdeconnect.battery", - "kdeconnect.battery.request" + "kdeconnect.battery" ], "X-KdeConnect-SupportedPacketType": [ - "kdeconnect.battery", - "kdeconnect.battery.request" + "kdeconnect.battery" ] } diff --git a/plugins/connectivity-report/connectivity_reportplugin.cpp b/plugins/connectivity-report/connectivity_reportplugin.cpp index 168eb2643..90c73ef85 100644 --- a/plugins/connectivity-report/connectivity_reportplugin.cpp +++ b/plugins/connectivity-report/connectivity_reportplugin.cpp @@ -32,30 +32,28 @@ int ConnectivityReportPlugin::cellularNetworkStrength() const void ConnectivityReportPlugin::connected() { - // We've just connected. Request connectivity_report information from the remote device... - NetworkPacket np(PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST, {{QStringLiteral("request"), true}}); - sendPacket(np); } bool ConnectivityReportPlugin::receivePacket(const NetworkPacket &np) { - if (np.type() == PACKET_TYPE_CONNECTIVITY_REPORT) { - auto subscriptions = np.get(QStringLiteral("signalStrengths"), QVariantMap()); - if (!subscriptions.isEmpty()) { - auto networkInfo = subscriptions.first().toMap(); - - const auto oldCellularNetworkType = m_cellularNetworkType; - const auto oldNetworkStrength = m_cellularNetworkStrength; - - m_cellularNetworkType = networkInfo.value(QStringLiteral("networkType")).toString(); - m_cellularNetworkStrength = networkInfo.value(QStringLiteral("signalStrength")).toInt(); - - if (oldCellularNetworkType != m_cellularNetworkType || oldNetworkStrength != m_cellularNetworkStrength) { - Q_EMIT refreshed(m_cellularNetworkType, m_cellularNetworkStrength); - } - } + if (PACKET_TYPE_CONNECTIVITY_REPORT != np.type()) { + return false; } + auto subscriptions = np.get(QStringLiteral("signalStrengths"), QVariantMap()); + if (!subscriptions.isEmpty()) { + auto networkInfo = subscriptions.first().toMap(); + + const auto oldCellularNetworkType = m_cellularNetworkType; + const auto oldNetworkStrength = m_cellularNetworkStrength; + + m_cellularNetworkType = networkInfo.value(QStringLiteral("networkType")).toString(); + m_cellularNetworkStrength = networkInfo.value(QStringLiteral("signalStrength")).toInt(); + + if (oldCellularNetworkType != m_cellularNetworkType || oldNetworkStrength != m_cellularNetworkStrength) { + Q_EMIT refreshed(m_cellularNetworkType, m_cellularNetworkStrength); + } + } return true; } diff --git a/plugins/connectivity-report/connectivity_reportplugin.h b/plugins/connectivity-report/connectivity_reportplugin.h index f7f2f2222..92d26bebb 100644 --- a/plugins/connectivity-report/connectivity_reportplugin.h +++ b/plugins/connectivity-report/connectivity_reportplugin.h @@ -32,13 +32,6 @@ */ #define PACKET_TYPE_CONNECTIVITY_REPORT QStringLiteral("kdeconnect.connectivity_report") -/** - * Packet sent to request the current connectivity state - *

- * The request packet shall contain no body - */ -#define PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST QStringLiteral("kdeconnect.connectivity_report.request") - class ConnectivityReportPlugin : public KdeConnectPlugin { Q_OBJECT diff --git a/plugins/connectivity-report/kdeconnect_connectivity_report.json b/plugins/connectivity-report/kdeconnect_connectivity_report.json index 0c5468946..d163a8cd4 100644 --- a/plugins/connectivity-report/kdeconnect_connectivity_report.json +++ b/plugins/connectivity-report/kdeconnect_connectivity_report.json @@ -129,9 +129,7 @@ ], "Version": "1.0" }, - "X-KdeConnect-OutgoingPacketType": [ - "kdeconnect.connectivity_report.request" - ], + "X-KdeConnect-OutgoingPacketType": [], "X-KdeConnect-SupportedPacketType": [ "kdeconnect.connectivity_report" ]