Files
08dde7f79a add: Cellular Network support (rebase of #2765) (#3096)
* feat: add cellular support

* fix(settings): resolve cellular tab index collision

* fix: address review feedback for cellular support

Bump the network API version, drop the deleted term freeze file,
regenerate the settings search index, and reuse existing translation
terms where they already cover the new cellular UI.

* fix: do not assign readonly userPreference when switching network type

Assigning SettingsData.networkPreference through the readonly alias
threw on click, so the Cellular segment in Control Center did nothing.

* fix: make Cellular selectable and the modem row clickable

The Control Center type switcher was bound only to preference, so
Cellular snapped back to Ethernet. The settings modem row highlighted
on hover but had no click handler. Show the modem as a connect target
when no APN profiles exist.

* fix: create a GSM profile when connecting cellular with none saved

Clicking Mobile broadband only activated an existing profile, so a
modem with no APN did nothing useful. Fall back to AddAndActivate
like ethernet connect.

* fix: address second round of cellular review feedback

- Guard cellularDevices map with devMutex via snapshot/by-iface/set/remove
  helpers, mirroring the existing ethernet and wifi accessors
- Regenerate mocks with mockery v3 instead of hand-editing mock_Backend.go
- Reuse refreshCellularState() in SetCellularEnabled, DisconnectCellular,
  DisconnectCellularDevice, ActivateCellularConnection and device removal
- Wrap retryErr rather than the first error when the auto-config retry fails
- Use Theme.surfaceTextSecondary/primaryHover/primaryHoverLight in the
  cellular-off state instead of hand-rolled Qt.rgba values
- Drop the duplicate "No devices found" label so it can no longer render
  twice with no modem and no saved config

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* fix: address remaining cellular review comments

- Toast "Failed to toggle cellular" instead of always "enable"
- Remove unused enableCellularRadio() wrappers
- Store Control Center network type as a value, not a list index

* fix: pass nmcli connection selector as separate argument

`nmcli con mod uuid:<UUID>` is not valid syntax -- nmcli expects the
selector keyword as its own argument, so every priority update failed
with "no such connection profile". Because practically every NM profile
has a UUID, this silently disabled autoconnect-priority and route-metric
updates for ethernet and WiFi as well as cellular.

Also fix the Cellular settings status text, which said "Connecting..."
for a flag that only tracks radio enable/disable, and add the seven
cellular terms that were missing from the translation catalogs.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* apply review comments

* fix lints

* update debug doc

* fix style inconsistencies

---------

Co-authored-by: Yechiel Worenklein <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Co-authored-by: bbedward <[email protected]>
2026-08-29 15:37:36 -04:00

323 lines
16 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import qs.Common
import qs.Modules.Settings.Widgets
import qs.Services
import qs.Widgets
Item {
id: networkCellularTab
LayoutMirroring.enabled: I18n.isRtl
LayoutMirroring.childrenInherit: true
Component.onCompleted: NetworkService.addRef()
Component.onDestruction: NetworkService.removeRef()
DankFlickable {
anchors.fill: parent
clip: true
contentHeight: mainColumn.height + Theme.spacingXL
contentWidth: width
Column {
id: mainColumn
topPadding: 4
width: Math.min(600, parent.width - Theme.spacingL * 2)
anchors.horizontalCenter: parent.horizontalCenter
spacing: Theme.spacingL
SettingsCard {
id: root
title: I18n.tr("Cellular")
iconName: "network_cell"
settingKey: "networkCellular"
tags: ["cellular", "mobile", "modem", "wwan", "lte", "gsm", "cdma", "network"]
width: parent.width
Column {
width: parent.width
spacing: Theme.spacingM
Row {
width: parent.width
spacing: Theme.spacingM
StyledText {
text: {
if (!NetworkService.cellularHardwareEnabled)
return I18n.tr("Unavailable");
if (NetworkService.cellularToggling)
return NetworkService.cellularEnabled ? I18n.tr("Disabling cellular...") : I18n.tr("Enabling cellular...");
if (!NetworkService.cellularEnabled)
return I18n.tr("Disabled");
const devices = NetworkService.cellularDevices || [];
const connected = devices.filter(d => d.connected).length;
if (devices.length === 0)
return I18n.tr("No devices found");
if (connected === 0)
return I18n.tr("Disconnected");
return I18n.tr("%1 connected").arg(connected);
}
font.pixelSize: Theme.fontSizeSmall
color: NetworkService.cellularConnected ? Theme.primary : Theme.surfaceVariantText
width: parent.width - cellularControls.width - Theme.spacingM
horizontalAlignment: Text.AlignLeft
anchors.verticalCenter: parent.verticalCenter
}
Row {
id: cellularControls
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingS
DankToggle {
checked: NetworkService.cellularEnabled
enabled: NetworkService.cellularHardwareEnabled && !NetworkService.cellularToggling
onToggled: NetworkService.toggleCellularRadio()
}
}
}
Rectangle {
width: parent.width
height: 1
color: Theme.outlineStrong
}
Column {
width: parent.width
spacing: 4
visible: NetworkService.cellularEnabled && (NetworkService.cellularDevices?.length ?? 0) > 0
StyledText {
text: I18n.tr("Adapters")
font.pixelSize: Theme.fontSizeMedium
font.weight: Font.Medium
color: Theme.surfaceText
width: parent.width
horizontalAlignment: Text.AlignLeft
}
Repeater {
model: NetworkService.cellularDevices || []
delegate: Rectangle {
id: modemDelegate
required property var modelData
readonly property bool isConnected: modelData.connected || false
width: parent.width
height: 56
radius: Theme.cornerRadius
color: modemMouseArea.containsMouse ? Theme.primaryHoverLight : Theme.surfaceLight
border.width: isConnected ? 2 : 0
border.color: Theme.primary
Row {
anchors.left: parent.left
anchors.leftMargin: Theme.spacingM
anchors.right: modemActions.left
anchors.rightMargin: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingS
DankIcon {
name: "network_cell"
size: 20
color: modemDelegate.isConnected ? Theme.primary : Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
Column {
anchors.verticalCenter: parent.verticalCenter
spacing: 2
width: parent.width - 20 - Theme.spacingS
StyledText {
text: modelData.name || I18n.tr("Unknown")
font.pixelSize: Theme.fontSizeMedium
color: modemDelegate.isConnected ? Theme.primary : Theme.surfaceText
font.weight: modemDelegate.isConnected ? Font.Medium : Font.Normal
elide: Text.ElideRight
width: parent.width
horizontalAlignment: Text.AlignLeft
}
StyledText {
text: {
const state = modelData.state || I18n.tr("Unknown");
const ip = modelData.ip || "";
return ip.length > 0 ? state + " • " + ip : state;
}
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
elide: Text.ElideRight
width: parent.width
horizontalAlignment: Text.AlignLeft
}
}
}
Row {
id: modemActions
anchors.right: parent.right
anchors.rightMargin: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingXS
Rectangle {
width: 28
height: 28
radius: 14
color: modemActionBtn.containsMouse ? (modemDelegate.isConnected ? Theme.errorHover : Theme.primaryHover) : "transparent"
DankIcon {
anchors.centerIn: parent
name: modemDelegate.isConnected ? "link_off" : "link"
size: 18
color: modemActionBtn.containsMouse ? (modemDelegate.isConnected ? Theme.error : Theme.primary) : Theme.surfaceVariantText
}
MouseArea {
id: modemActionBtn
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (modemDelegate.isConnected)
NetworkService.disconnectCellularDevice(modelData.name);
else
NetworkService.connectCellular();
}
}
}
}
MouseArea {
id: modemMouseArea
anchors.fill: parent
anchors.rightMargin: modemActions.width + Theme.spacingM
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (modemDelegate.isConnected)
NetworkService.disconnectCellularDevice(modelData.name);
else
NetworkService.connectCellular();
}
}
}
}
}
}
}
SettingsCard {
title: I18n.tr("Saved Configurations")
iconName: "sim_card"
settingKey: "networkCellularProfiles"
tags: ["cellular", "mobile", "profile", "apn", "sim"]
width: parent.width
visible: NetworkService.cellularEnabled && (NetworkService.cellularConnections?.length ?? 0) > 0
Column {
width: parent.width
spacing: 4
Repeater {
model: NetworkService.cellularConnections || []
delegate: Rectangle {
id: profileDelegate
required property var modelData
readonly property bool isActive: modelData.isActive || false
width: parent.width
height: 56
radius: Theme.cornerRadius
color: profileMouseArea.containsMouse ? Theme.primaryHoverLight : Theme.surfaceLight
border.color: isActive ? Theme.primary : Theme.outlineLight
border.width: isActive ? 2 : 1
Row {
anchors.left: parent.left
anchors.leftMargin: Theme.spacingM
anchors.right: profileAction.left
anchors.rightMargin: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
spacing: Theme.spacingS
DankIcon {
name: "sim_card"
size: 20
color: profileDelegate.isActive ? Theme.primary : Theme.surfaceText
anchors.verticalCenter: parent.verticalCenter
}
Column {
anchors.verticalCenter: parent.verticalCenter
width: parent.width - 20 - Theme.spacingS
spacing: 2
StyledText {
text: modelData.id || I18n.tr("Unknown")
font.pixelSize: Theme.fontSizeMedium
color: profileDelegate.isActive ? Theme.primary : Theme.surfaceText
font.weight: profileDelegate.isActive ? Font.Medium : Font.Normal
elide: Text.ElideRight
width: parent.width
horizontalAlignment: Text.AlignLeft
}
StyledText {
text: profileDelegate.isActive ? I18n.tr("Connected") : (modelData.type || I18n.tr("Available"))
font.pixelSize: Theme.fontSizeSmall
color: Theme.surfaceVariantText
width: parent.width
horizontalAlignment: Text.AlignLeft
}
}
}
DankActionButton {
id: profileAction
anchors.right: parent.right
anchors.rightMargin: Theme.spacingS
anchors.verticalCenter: parent.verticalCenter
iconName: profileDelegate.isActive ? "link_off" : "link"
buttonSize: 28
iconSize: 18
iconColor: profileDelegate.isActive ? Theme.error : Theme.primary
onClicked: {
if (profileDelegate.isActive)
NetworkService.toggleNetworkConnection("cellular");
else
NetworkService.connectToSpecificCellularConfig(modelData.uuid);
}
}
MouseArea {
id: profileMouseArea
anchors.fill: parent
anchors.rightMargin: profileAction.width + Theme.spacingS
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (!profileDelegate.isActive)
NetworkService.connectToSpecificCellularConfig(modelData.uuid);
}
}
}
}
}
}
}
}
}