[OpenDocString] kdeconnect-kde (cpp)
connectivity_reportplugin.cpp
ConnectivityReportPlugin::ConnectivityReportPlugin(QObject *parent, const QVariantList &args)
    : KdeConnectPlugin(parent, args)
{
}
Constructs a KdeConnectPlugin object and assigns its connectivity to its parent object.
QString ConnectivityReportPlugin::cellularNetworkType() const
{
    return m_cellularNetworkType;
}
Returns the cellular network type as a QString.
int ConnectivityReportPlugin::cellularNetworkStrength() const
{
    return m_cellularNetworkStrength;
}
Returns the cellular network strength value in the internal list.
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);
}
This sends a network packet that tells the plugin that it is connected.
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);
            }
        }
    }

    return true;
}
It receives a NetworkPacket object np and retrieves its data. If the packet type is CONNECTIVITY_REPORT it gets the signal strength of the first network entry in the map, and updates the values of the member variables. Then it emits a signal of the type and strength changed signal. If the packet type is CONNECTIVITY_REPORT it emits a signal of the type and strength changed signal. If the packet type is DISCONNECTIVITY_REPORT it returns true. Otherwise it returns false.
QString ConnectivityReportPlugin::dbusPath() const
{
    return QStringLiteral("/modules/kdeconnect/devices/") + device()->id() + QStringLiteral("/connectivity_report");
}
Returns the dbus path as a QString.