[OpenDocString] kdeconnect-kde (cpp)
connectivity_action.cpp
ConnectivityAction::ConnectivityAction(DeviceDbusInterface *device)
    : QAction(nullptr)
    , m_connectivityiface(device->id())
{
    setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
    setCellularNetworkType(m_connectivityiface.cellularNetworkType());

    connect(&m_connectivityiface, &ConnectivityReportDbusInterface::refreshedProxy, this, [this] {
        setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
        setCellularNetworkType(m_connectivityiface.cellularNetworkType());
    });

    setIcon(QIcon::fromTheme(QStringLiteral("network-wireless")));

    ConnectivityAction::update();
}
This constructor builds a ConnectivityAction object from a DeviceDbusInterface object. It sets the cellular network strength and type of the device and connects to the refresh proxy. It also sets the icon to network - wireless.
void ConnectivityAction::update()
{
    if (m_cellularNetworkStrength < 0) {
        setText(i18nc("The fallback text to display in case the remote device does not have a cellular connection", "No Cellular Connectivity"));
    } else {
        setText(i18nc("Display the cellular connection type and an approximate percentage of signal strength",
                      "%1  | ~%2%",
                      m_cellularNetworkType,
                      m_cellularNetworkStrength * 25));
    }

    // set icon name

    QString iconName = QStringLiteral("network-mobile");

    if (m_cellularNetworkStrength < 0) {
        iconName += QStringLiteral("-off");
    } else {
        int signalStrength;
        switch (m_cellularNetworkStrength) {
        case 0:
            signalStrength = 0;
            break;
        case 1:
            signalStrength = 20;
            break;
        case 2:
            signalStrength = 60;
            break;
        case 3:
            signalStrength = 80;
            break;
        default:
            signalStrength = 100;
            break;
        }
        iconName += QStringLiteral("-") + QString::number(signalStrength);
    }

    if (connectivity_action::networkTypesWithIcons.contains(m_cellularNetworkType)) {
        iconName += QStringLiteral("-") + m_cellularNetworkType.toLower();
    }

    setIcon(QIcon::fromTheme(iconName));
}
Sets the text and icon for the action.
void ConnectivityAction::setCellularNetworkStrength(int cellularNetworkStrength)
{
    m_cellularNetworkStrength = cellularNetworkStrength;
    update();
}
Sets the cellular network strength in the internal list.
void ConnectivityAction::setCellularNetworkType(QString cellularNetworkType)
{
    m_cellularNetworkType = cellularNetworkType;
    update();
}
Sets the cellular network type by storing it in the m_cellularNetworkType variable. Then it updates the internal state of the component.