Remove request packets from Battery and Connectivity Report plugins
We already send updates right after connecting and once there's a change, so this was redundant.
This commit is contained in:
parent
619904b317
commit
2a1c751ef4
6 changed files with 39 additions and 58 deletions
|
@ -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<Solid::Device> 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<Solid::Device> 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<bool>(QStringLiteral("isCharging"), false);
|
||||
m_charge = np.get<int>(QStringLiteral("currentCharge"), -1);
|
||||
const int thresholdEvent = np.get<int>(QStringLiteral("thresholdEvent"), (int)ThresholdNone);
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#include <core/kdeconnectplugin.h>
|
||||
|
||||
#define PACKET_TYPE_BATTERY QStringLiteral("kdeconnect.battery")
|
||||
#define PACKET_TYPE_BATTERY_REQUEST QStringLiteral("kdeconnect.battery.request")
|
||||
|
||||
class BatteryPlugin : public KdeConnectPlugin
|
||||
{
|
||||
|
|
|
@ -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"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -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<QVariantMap>(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<QVariantMap>(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;
|
||||
}
|
||||
|
||||
|
|
|
@ -32,13 +32,6 @@
|
|||
*/
|
||||
#define PACKET_TYPE_CONNECTIVITY_REPORT QStringLiteral("kdeconnect.connectivity_report")
|
||||
|
||||
/**
|
||||
* Packet sent to request the current connectivity state
|
||||
* <p>
|
||||
* The request packet shall contain no body
|
||||
*/
|
||||
#define PACKET_TYPE_CONNECTIVITY_REPORT_REQUEST QStringLiteral("kdeconnect.connectivity_report.request")
|
||||
|
||||
class ConnectivityReportPlugin : public KdeConnectPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -129,9 +129,7 @@
|
|||
],
|
||||
"Version": "1.0"
|
||||
},
|
||||
"X-KdeConnect-OutgoingPacketType": [
|
||||
"kdeconnect.connectivity_report.request"
|
||||
],
|
||||
"X-KdeConnect-OutgoingPacketType": [],
|
||||
"X-KdeConnect-SupportedPacketType": [
|
||||
"kdeconnect.connectivity_report"
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue