2021-05-18 09:34:43 +01:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2016 Aleix Pol Gonzalez <aleixpol@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2020 Piyush Aggarwal <piyushaggarwal002@gmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "connectivity_action.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
ConnectivityAction::ConnectivityAction(DeviceDbusInterface *device)
|
2021-05-18 09:34:43 +01:00
|
|
|
: QAction(nullptr)
|
|
|
|
, m_connectivityiface(device->id())
|
|
|
|
{
|
|
|
|
setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
|
|
|
|
setCellularNetworkType(m_connectivityiface.cellularNetworkType());
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
connect(&m_connectivityiface, &ConnectivityReportDbusInterface::refreshedProxy, this, [this] {
|
2021-05-18 09:34:43 +01:00
|
|
|
setCellularNetworkStrength(m_connectivityiface.cellularNetworkStrength());
|
|
|
|
setCellularNetworkType(m_connectivityiface.cellularNetworkType());
|
|
|
|
});
|
|
|
|
|
|
|
|
setIcon(QIcon::fromTheme(QStringLiteral("network-wireless")));
|
|
|
|
|
|
|
|
ConnectivityAction::update();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 {
|
2022-09-10 22:23:52 +01:00
|
|
|
setText(i18nc("Display the cellular connection type and an approximate percentage of signal strength",
|
|
|
|
"%1 | ~%2%",
|
|
|
|
m_cellularNetworkType,
|
|
|
|
m_cellularNetworkStrength * 25));
|
2021-05-18 09:34:43 +01:00
|
|
|
}
|
2021-06-13 10:44:12 +01:00
|
|
|
|
|
|
|
// set icon name
|
|
|
|
|
|
|
|
QString iconName = QStringLiteral("network-mobile");
|
|
|
|
|
|
|
|
if (m_cellularNetworkStrength < 0) {
|
|
|
|
iconName += QStringLiteral("-off");
|
|
|
|
} else {
|
|
|
|
int signalStrength;
|
2022-09-10 22:23:52 +01:00
|
|
|
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;
|
2021-06-13 10:44:12 +01:00
|
|
|
}
|
|
|
|
iconName += QStringLiteral("-") + QString::number(signalStrength);
|
|
|
|
}
|
|
|
|
|
2021-07-13 18:53:58 +01:00
|
|
|
if (connectivity_action::networkTypesWithIcons.contains(m_cellularNetworkType)) {
|
|
|
|
iconName += QStringLiteral("-") + m_cellularNetworkType.toLower();
|
2021-06-13 10:44:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
setIcon(QIcon::fromTheme(iconName));
|
2021-05-18 09:34:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectivityAction::setCellularNetworkStrength(int cellularNetworkStrength)
|
|
|
|
{
|
|
|
|
m_cellularNetworkStrength = cellularNetworkStrength;
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ConnectivityAction::setCellularNetworkType(QString cellularNetworkType)
|
|
|
|
{
|
|
|
|
m_cellularNetworkType = cellularNetworkType;
|
|
|
|
update();
|
|
|
|
}
|