2021-03-12 23:27:16 +00:00
|
|
|
/**
|
|
|
|
* SPDX-FileCopyrightText: 2021 David Shlemayev <david.shlemayev@gmail.com>
|
2024-06-30 23:03:57 +01:00
|
|
|
* SPDX-FileCopyrightText: 2024 ivan tkachenko <me@ratijas.tk>
|
2021-03-12 23:27:16 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
|
|
|
*/
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
pragma ComponentBehavior: Bound
|
|
|
|
|
2023-11-30 23:41:36 +00:00
|
|
|
import QtQuick
|
2021-03-12 23:27:16 +00:00
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
import org.kde.kdeconnect as KDEConnect
|
2021-03-12 23:27:16 +00:00
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
QtObject {
|
2021-03-12 23:27:16 +00:00
|
|
|
id: root
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
required property KDEConnect.DeviceDbusInterface device
|
|
|
|
|
2021-03-12 23:27:16 +00:00
|
|
|
readonly property alias available: checker.available
|
|
|
|
|
2024-06-30 23:03:57 +01:00
|
|
|
readonly property KDEConnect.PluginChecker pluginChecker: KDEConnect.PluginChecker {
|
2021-03-12 23:27:16 +00:00
|
|
|
id: checker
|
|
|
|
pluginName: "connectivity_report"
|
2024-06-30 23:03:57 +01:00
|
|
|
device: root.device
|
2021-03-12 23:27:16 +00:00
|
|
|
}
|
|
|
|
|
2021-07-14 04:30:25 +01:00
|
|
|
/**
|
|
|
|
* Reports a string indicating the network type. Possible values:
|
|
|
|
* 5G
|
|
|
|
* LTE
|
|
|
|
* HSPA
|
|
|
|
* UMTS
|
|
|
|
* CDMA2000
|
|
|
|
* EDGE
|
|
|
|
* GPRS
|
|
|
|
* GSM
|
|
|
|
* CDMA
|
|
|
|
* iDEN
|
|
|
|
*
|
|
|
|
* The parsing from Android values into these strings is handled in the
|
|
|
|
* [ConnectivityReportPlugin.networkTypeToString method](https://invent.kde.org/network/kdeconnect-android/-/blob/master/src/org/kde/kdeconnect/Plugins/ConnectivityReportPlugin/ConnectivityReportPlugin.java#L82)
|
|
|
|
*/
|
2024-06-30 23:03:57 +01:00
|
|
|
readonly property string networkType: connectivity?.cellularNetworkType ?? i18n("Unknown")
|
2021-07-14 04:30:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reports a value between 0 and 4 (inclusive) which represents the strength of the cellular connection
|
|
|
|
*/
|
2024-06-30 23:03:57 +01:00
|
|
|
readonly property int signalStrength: connectivity?.cellularNetworkStrength ?? -1
|
|
|
|
|
|
|
|
readonly property string displayString: {
|
|
|
|
if (connectivity !== null) {
|
2021-03-12 23:27:16 +00:00
|
|
|
return `${networkType} ${signalStrength}/4`;
|
|
|
|
} else {
|
|
|
|
return i18n("No signal");
|
|
|
|
}
|
|
|
|
}
|
2024-06-30 23:03:57 +01:00
|
|
|
|
|
|
|
property KDEConnect.ConnectivityReportDbusInterface connectivity
|
2021-03-12 23:27:16 +00:00
|
|
|
|
2021-07-14 04:30:25 +01:00
|
|
|
/**
|
|
|
|
* Suggests an icon name to use for the current signal level
|
|
|
|
*
|
|
|
|
* Returns names which correspond to Plasma Framework's network.svg:
|
|
|
|
* https://invent.kde.org/frameworks/plasma-framework/-/blob/master/src/desktoptheme/breeze/icons/network.svg
|
|
|
|
*/
|
|
|
|
readonly property string iconName: {
|
|
|
|
// Firstly, get the name prefix which represents the signal strength
|
2024-06-30 23:03:57 +01:00
|
|
|
const signalStrengthIconName =
|
|
|
|
(signalStrength < 0 || connectivity === null) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
// As long as the signal strength is nonsense or the plugin reports as non-ready,
|
|
|
|
// show us as disconnected
|
|
|
|
"network-mobile-off" :
|
2024-06-30 23:03:57 +01:00
|
|
|
(signalStrength === 0) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
"network-mobile-0" :
|
2024-06-30 23:03:57 +01:00
|
|
|
(signalStrength === 1) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
"network-mobile-20" :
|
2024-06-30 23:03:57 +01:00
|
|
|
(signalStrength === 2) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
"network-mobile-60" :
|
2024-06-30 23:03:57 +01:00
|
|
|
(signalStrength === 3) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
"network-mobile-80" :
|
2024-06-30 23:03:57 +01:00
|
|
|
(signalStrength === 4) ?
|
2021-07-14 04:30:25 +01:00
|
|
|
"network-mobile-100" :
|
|
|
|
// Since all possible values are enumerated above, this default case should never be hit.
|
|
|
|
// However, I need it in order for my ternary syntax to be valid!
|
2024-06-30 23:03:57 +01:00
|
|
|
"network-mobile-available";
|
2021-07-14 04:30:25 +01:00
|
|
|
|
|
|
|
// If we understand the network type, append to the icon name to show the type
|
2024-06-30 23:03:57 +01:00
|
|
|
const networkTypeSuffix =
|
2021-07-14 04:30:25 +01:00
|
|
|
(networkType === "5G") ?
|
|
|
|
// No icon for this case!
|
|
|
|
"" :
|
|
|
|
(networkType === "LTE") ?
|
|
|
|
"-lte" :
|
|
|
|
(networkType === "HSPA") ?
|
|
|
|
"-hspa" :
|
|
|
|
(networkType === "UMTS") ?
|
|
|
|
"-umts" :
|
|
|
|
(networkType === "CDMA2000") ?
|
|
|
|
// GSconnect just uses the 3g icon
|
|
|
|
// No icon for this case!
|
|
|
|
"" :
|
|
|
|
(networkType === "EDGE") ?
|
|
|
|
"-edge" :
|
|
|
|
(networkType === "GPRS") ?
|
|
|
|
"-gprs" :
|
|
|
|
(networkType === "GSM") ?
|
|
|
|
// GSconnect just uses the 2g icon
|
|
|
|
// No icon for this case!
|
|
|
|
"" :
|
|
|
|
(networkType === "CDMA") ?
|
|
|
|
// GSconnect just uses the 2g icon
|
|
|
|
// No icon for this case!
|
|
|
|
"" :
|
|
|
|
(networkType === "iDEN") ?
|
|
|
|
// GSconnect just uses the 2g icon
|
|
|
|
// No icon for this case!
|
|
|
|
"" :
|
2024-06-30 23:03:57 +01:00
|
|
|
""; // We didn't recognize the network type. Don't append anything.
|
|
|
|
|
|
|
|
return signalStrengthIconName + networkTypeSuffix;
|
2021-07-14 04:30:25 +01:00
|
|
|
}
|
|
|
|
|
2021-03-12 23:27:16 +00:00
|
|
|
onAvailableChanged: {
|
|
|
|
if (available) {
|
2024-06-30 23:03:57 +01:00
|
|
|
connectivity = KDEConnect.DeviceConnectivityReportDbusInterfaceFactory.create(device.id());
|
2021-03-12 23:27:16 +00:00
|
|
|
} else {
|
2024-06-30 23:03:57 +01:00
|
|
|
connectivity = null;
|
2021-03-12 23:27:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|