Commit 8b9eb873 authored by Jan Grulich's avatar Jan Grulich
Browse files

Wired setting: improve handling of link negotiation

Summary:
Adds option to ignore link-negotiation, also uses a combobox, similar to what
nm-connection-editor is using, to give a choice only with sane values for speed.

BUG: 413211

Test Plan:
I tried to configure all possible combinations, all of them were saved correctly and loaded afterwards.

Screenshot of updated wired setting:
{F7648938}

Reviewers: #plasma, #vdg, davidedmundson

Reviewed By: #plasma, #vdg, davidedmundson

Subscribers: davidedmundson, devurandom, ngraham, dvalter, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D24866
parent 7b32a67e
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>401</width>
<height>217</height>
<width>437</width>
<height>232</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout">
......@@ -27,16 +27,6 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Cloned MAC address:</string>
</property>
<property name="buddy">
<cstring>clonedMacAddress</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="HwAddrComboBox" name="macAddress">
<property name="sizePolicy">
......@@ -51,6 +41,16 @@ permanent MAC address entered here. Example: 00:11:22:33:44:55</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Cloned MAC address:</string>
</property>
<property name="buddy">
<cstring>clonedMacAddress</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
......@@ -124,13 +124,23 @@ into multiple Ethernet frames</string>
<property name="text">
<string>Speed:</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="duplexLabel">
<property name="text">
<string>Duplex:</string>
</property>
<property name="buddy">
<cstring>speed</cstring>
<cstring>duplex</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="speed">
<item row="5" column="1">
<widget class="KComboBox" name="duplex">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -138,40 +148,35 @@ into multiple Ethernet frames</string>
</sizepolicy>
</property>
<property name="toolTip">
<string>Request that the device use only the specified speed. In MBit/s, example 100 == 100Mbit/s</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="specialValueText">
<string/>
</property>
<property name="suffix">
<string> Mbit/s</string>
<string>Request that the device use the specified duplex mode. Either &quot;half&quot; or &quot;full&quot;</string>
</property>
<property name="minimum">
<property name="currentIndex">
<number>1</number>
</property>
<property name="maximum">
<number>9999</number>
</property>
<property name="value">
<number>100</number>
</property>
<item>
<property name="text">
<string>Half</string>
</property>
</item>
<item>
<property name="text">
<string>Full</string>
</property>
</item>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="duplexLabel">
<property name="text">
<string>Duplex:</string>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="toolTip">
<string/>
</property>
<property name="buddy">
<cstring>duplex</cstring>
<property name="text">
<string>Link negotiation:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="KComboBox" name="duplex">
<item row="3" column="1">
<widget class="QComboBox" name="linkNegotiation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -179,22 +184,31 @@ into multiple Ethernet frames</string>
</sizepolicy>
</property>
<property name="toolTip">
<string>Request that the device use the specified duplex mode. Either &quot;half&quot; or &quot;full&quot;</string>
<string>Device link negotiation. If “Manual” is chosen, “Speed” and “Duplex” values will be forced without checking
the device compatibility. If unsure, leave here “Ignore” or pick “Automatic”.</string>
</property>
<item>
<property name="text">
<string>Full</string>
<string>Ignore</string>
</property>
</item>
<item>
<property name="text">
<string>Half</string>
<string>Automatic</string>
</property>
</item>
<item>
<property name="text">
<string>Manual</string>
</property>
</item>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="autonegotiate">
<item row="4" column="1">
<widget class="QComboBox" name="speed">
<property name="enabled">
<bool>false</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
......@@ -202,17 +216,31 @@ into multiple Ethernet frames</string>
</sizepolicy>
</property>
<property name="toolTip">
<string>Allow auto-negotiation of port speed and duplex mode</string>
</property>
<property name="text">
<string>Allow auto-negotiation</string>
</property>
<property name="checked">
<bool>true</bool>
<string>Request that the device use only the specified speed.</string>
</property>
<property name="tristate">
<bool>false</bool>
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>10 Mb/s</string>
</property>
</item>
<item>
<property name="text">
<string>100 Mb/s</string>
</property>
</item>
<item>
<property name="text">
<string>1 Gb/s</string>
</property>
</item>
<item>
<property name="text">
<string>10 Gb/s</string>
</property>
</item>
</widget>
</item>
</layout>
......@@ -239,74 +267,8 @@ into multiple Ethernet frames</string>
<tabstop>clonedMacAddress</tabstop>
<tabstop>btnRandomMacAddr</tabstop>
<tabstop>mtu</tabstop>
<tabstop>speed</tabstop>
<tabstop>duplex</tabstop>
</tabstops>
<resources/>
<connections>
<connection>
<sender>autonegotiate</sender>
<signal>toggled(bool)</signal>
<receiver>speedLabel</receiver>
<slot>setHidden(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>80</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>81</x>
<y>117</y>
</hint>
</hints>
</connection>
<connection>
<sender>autonegotiate</sender>
<signal>toggled(bool)</signal>
<receiver>speed</receiver>
<slot>setHidden(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>80</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
<y>118</y>
</hint>
</hints>
</connection>
<connection>
<sender>autonegotiate</sender>
<signal>toggled(bool)</signal>
<receiver>duplexLabel</receiver>
<slot>setHidden(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>80</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>81</x>
<y>147</y>
</hint>
</hints>
</connection>
<connection>
<sender>autonegotiate</sender>
<signal>toggled(bool)</signal>
<receiver>duplex</receiver>
<slot>setHidden(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>80</x>
<y>290</y>
</hint>
<hint type="destinationlabel">
<x>298</x>
<y>143</y>
</hint>
</hints>
</connection>
</connections>
<connections/>
</ui>
......@@ -32,10 +32,6 @@ WiredConnectionWidget::WiredConnectionWidget(const NetworkManager::Setting::Ptr
qsrand(QTime::currentTime().msec());
m_widget->setupUi(this);
m_widget->speedLabel->setHidden(true);
m_widget->speed->setHidden(true);
m_widget->duplexLabel->setHidden(true);
m_widget->duplex->setHidden(true);
connect(m_widget->btnRandomMacAddr, &QPushButton::clicked, this, &WiredConnectionWidget::generateRandomClonedMac);
......@@ -43,10 +39,12 @@ WiredConnectionWidget::WiredConnectionWidget(const NetworkManager::Setting::Ptr
watchChangedSetting();
// Connect for validity check
connect(m_widget->autonegotiate, &QCheckBox::stateChanged, this, &WiredConnectionWidget::slotWidgetChanged);
connect(m_widget->clonedMacAddress, &KLineEdit::textChanged, this, &WiredConnectionWidget::slotWidgetChanged);
connect(m_widget->macAddress, &HwAddrComboBox::hwAddressChanged, this, &WiredConnectionWidget::slotWidgetChanged);
connect(m_widget->speed, QOverload<int>::of(&QSpinBox::valueChanged), this, &WiredConnectionWidget::slotWidgetChanged);
connect(m_widget->linkNegotiation, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [this] (int index) {
m_widget->duplex->setEnabled(index == LinkNegotiation::Manual);
m_widget->speed->setEnabled(index == LinkNegotiation::Manual);
});
KAcceleratorManager::manage(this);
......@@ -74,19 +72,33 @@ void WiredConnectionWidget::loadConfig(const NetworkManager::Setting::Ptr &setti
m_widget->mtu->setValue(wiredSetting->mtu());
}
if (!wiredSetting->autoNegotiate()) {
m_widget->autonegotiate->setChecked(false);
if (wiredSetting->autoNegotiate()) {
m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Automatic);
} else if (wiredSetting->speed() && wiredSetting->duplexType() != NetworkManager::WiredSetting::UnknownDuplexType) {
m_widget->linkNegotiation->setCurrentIndex(LinkNegotiation::Manual);
}
if (wiredSetting->speed()) {
m_widget->speed->setValue(wiredSetting->speed());
if (wiredSetting->speed()) {
switch(wiredSetting->speed()) {
case 10:
m_widget->speed->setCurrentIndex(0);
break;
case 100:
m_widget->speed->setCurrentIndex(1);
break;
case 1000:
m_widget->speed->setCurrentIndex(2);
break;
case 10000:
m_widget->speed->setCurrentIndex(3);
break;
}
}
// Default to "Full" duplex when duplex type is not set
if (wiredSetting->duplexType() == NetworkManager::WiredSetting::Full || wiredSetting->duplexType() == NetworkManager::WiredSetting::UnknownDuplexType) {
m_widget->duplex->setCurrentIndex(0);
} else {
m_widget->duplex->setCurrentIndex(1);
}
if (wiredSetting->duplexType() != NetworkManager::WiredSetting::Half) {
m_widget->duplex->setCurrentIndex(Duplex::Full);
} else {
m_widget->duplex->setCurrentIndex(Duplex::Half);
}
}
......@@ -104,21 +116,35 @@ QVariantMap WiredConnectionWidget::setting() const
wiredSetting.setMtu(m_widget->mtu->value());
}
if (m_widget->autonegotiate->isChecked()) {
wiredSetting.setAutoNegotiate(true);
if (m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic || m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Ignore) {
wiredSetting.setDuplexType(NetworkManager::WiredSetting::UnknownDuplexType);
wiredSetting.setSpeed(0);
} else {
wiredSetting.setAutoNegotiate(false);
wiredSetting.setSpeed(m_widget->speed->value());
switch (m_widget->speed->currentIndex()) {
case 0:
wiredSetting.setSpeed(10);
break;
case 1:
wiredSetting.setSpeed(100);
break;
case 2:
wiredSetting.setSpeed(1000);
break;
case 3:
wiredSetting.setSpeed(10000);
break;
}
if (m_widget->duplex->currentIndex() == 0) {
if (m_widget->duplex->currentIndex() == Duplex::Full) {
wiredSetting.setDuplexType(NetworkManager::WiredSetting::Full);
} else {
wiredSetting.setDuplexType(NetworkManager::WiredSetting::Half);
}
}
wiredSetting.setAutoNegotiate(m_widget->linkNegotiation->currentIndex() == LinkNegotiation::Automatic);
return wiredSetting.toMap();
}
......@@ -150,11 +176,5 @@ bool WiredConnectionWidget::isValid() const
}
}
if (!m_widget->autonegotiate->isChecked()) {
if (!m_widget->speed->value()) {
return false;
}
}
return true;
}
......@@ -35,6 +35,17 @@ class Q_DECL_EXPORT WiredConnectionWidget : public SettingWidget
Q_OBJECT
public:
enum LinkNegotiation {
Ignore = 0,
Automatic,
Manual
};
enum Duplex {
Half = 0,
Full
};
explicit WiredConnectionWidget(const NetworkManager::Setting::Ptr &setting, QWidget* parent = nullptr, Qt::WindowFlags f = {});
~WiredConnectionWidget() override;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment